Conversation
johnwhitton
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
nit:
| 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; |
There was a problem hiding this comment.
nit:
| IPool public immutable POOL; | |
| IPool public immutable AAVE_V3_POOL; |
| 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 | ||
| ); | ||
| } |
There was a problem hiding this comment.
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
TODO:
Resolves #315