Skip to content

feat: aave lending adapter#314

Draft
fredwes wants to merge 6 commits intomainfrom
feat/aave-lending-adapter
Draft

feat: aave lending adapter#314
fredwes wants to merge 6 commits intomainfrom
feat/aave-lending-adapter

Conversation

@fredwes
Copy link
Copy Markdown
Contributor

@fredwes fredwes commented Feb 3, 2026

TODO:

  • Write tests
  • Re-run docgen for docs/

Resolves #315

Copy link
Copy Markdown

@johnwhitton johnwhitton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work 🔥
I left a couple of nit comments around versioning (we are on 3.6 and aave v4 is due out shortly).
Also for future work

  • when writing the CreateToken leverage Scripts for the AaveAdapter may want to add logic in to determine the best E mode at time of deployment
  • running slither . highlights a few informational errors, none of which looked critical but may want to review them again when writing tests.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want to name this AaveLendingAdapterV3.sol (to align with aave-v3-origin) as https://github.com/aave/aave-v4 is due to be released in the first half of 2026.

* @dev LeverageToken creators can configure their LeverageToken to use an AaveLendingAdapter
* to use Aave as the lending protocol for their LeverageToken.
*
* COMPATIBILITY: This adapter requires Aave v3.1+ (aave-v3-origin). It uses functions like
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want to update this to reflect that we are launching on Aave 3.6
https://github.com/aave-dao/aave-v3-origin/blob/main/docs/3.6/Aave-v3.6-features.md

// Calculate: (debt * debtPrice * 10^collateralDecimals) / (collateralPrice * 10^debtDecimals)
// Rounds up the value of debt
// Assumes collateralPriceInBase and debtPriceInBase are in the same base (e.g., 1e8)
return Math.mulDiv(
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be a slightly more robust implementation

uint256 numeratorScale = debtPriceInBase * (10 ** collateralDecimals);
uint256 denominatorScale = collateralPriceInBase * (10 ** debtDecimals);
return Math.mulDiv(debt, numeratorScale, denominatorScale, Math.Rounding.Ceil);

rare use case where this would overflow is when

debt = 1e60
debtPriceInBase = 1e18
debt * debtPriceInBase = 1e78 (overflow, revert)


/// @dev Returns the liquidation bonus for the collateral asset, accounting for e-mode
/// @return The liquidation bonus in basis points (e.g., 10500 = 105%)
function _getLiquidationBonus() internal view returns (uint256) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An edge case we may want to consider is when the collateral and debt reserves have a liquidation grace period set https://github.com/aave-dao/aave-v3-origin/blob/main/src/contracts/protocol/libraries/logic/ValidationLogic.sol#L325-L329. e.g. LT enters preliquidation threshold, but the position cannot be liquidated due to these thresholds being set, do we still want to allow a preliquidation rebalance bonus?

IMorpho public immutable morpho;

/// @inheritdoc IFlashLoanSimpleReceiver
IPoolAddressesProvider public immutable ADDRESSES_PROVIDER;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
IPoolAddressesProvider public immutable ADDRESSES_PROVIDER;
IPoolAddressesProvider public immutable AAVE_V3_ADDRESSES_PROVIDER;

/// @notice The Aave v3 Pool contract used for flash loans
/// @dev Required by IFlashLoanSimpleReceiver interface
/// @inheritdoc IFlashLoanSimpleReceiver
IPool public immutable POOL;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
IPool public immutable POOL;
IPool public immutable AAVE_V3_POOL;

Comment on lines +134 to +150
address debtAsset = address(leverageManager.getLeverageTokenDebtAsset(leverageToken));

if (flashLoanSource == FlashLoanSource.Morpho) {
morpho.flashLoan(
debtAsset,
flashLoanAmount,
abi.encode(FlashLoanCallbackData({action: LeverageRouterAction.Deposit, data: depositData}))
);
} else {
POOL.flashLoanSimple(
address(this),
debtAsset,
flashLoanAmount,
abi.encode(FlashLoanCallbackData({action: LeverageRouterAction.Deposit, data: depositData})),
0 // referralCode
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic for reading the debt asset and picking the flash loan method is duped a few times (deposit, redeem, redeemWithVelora), I think we can have a reusable internal func for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support new lending adapter for Aave

4 participants