Set Documentation
Search…
AaveLeverageModule
Note: Currently margin trading is in Beta and the AaveLeverageModule is only initializable by allowed Sets. If you wish to create a SetToken that utilizes margin, please contact us on Discord.
The AaveLeverageModule is a smart contract that enables leverage trading using Aave as the lending protocol. This module is paired with a debt issuance module that will call functions on this module to keep interest accrual and liquidation state updated. This does not allow borrowing of assets from Aave alone. Each asset is leveraged when using this module.
Integrations mappings to specify the exchange to trade on is stored in the IntegrationRegistry​
Note: Do not use this module in conjunction with other debt modules that allow Aave debt positions as it could lead to double counting of debt when borrowed assets are the same.

Select Methods

lever()

function lever(ISetToken _setToken, IERC20 _borrowAsset, IERC20 _collateralAsset, uint256 _borrowQuantity, uint256 _minReceiveQuantity, string memory _tradeAdapterName, bytes memory _tradeData)
Manager only. Increases leverage for a given collateral position using an enabled borrow asset. Borrows _borrowAsset from Aave. Performs a DEX trade, exchanging the _borrowAsset for _collateralAsset. Deposits _collateralAsset to Aave and mints corresponding aToken. Note: Both collateral and borrow assets need to be enabled, and they must not be the same asset
Parameter Name
Type
Description
_setToken
ISetToken
Instance of the SetToken
_borrowAsset
address
Address of the token being borrowed and sent to the exchange
_collateralAsset
address
Address of the token that will be received from the exchange and deposited into Compound after the trade
_borrowQuantity
uint256
Borrow quantity of asset in position units
_minReceiveQuantity
uint256
Min receive quantity of collateral asset to receive post-trade in position units
_tradeAdapterName
string
Human readable name of the exchange in the integrations registry. Conforms to same interfaces as TradeModule
_tradeData
bytes
Arbitrary data for trade

delever()

function delever(ISetToken _setToken, IERC20 _collateralAsset, IERC20 _repayAsset, uint256 _redeemQuantity, uint256 _minRepayQuantity, string memory _tradeAdapterName, bytes memory _tradeData)
Manager only. Decrease leverage for a given collateral position using an enabled borrow asset. Withdraws _collateralAsset from Aave. Performs a DEX trade, exchanging the _collateralAsset for _repayAsset. Repays _repayAsset to Aave and burns corresponding debt tokens. Note: Both collateral and borrow assets need to be enabled, and they must not be the same asset.
Parameter Name
Type
Description
_setToken
ISetToken
Instance of the SetToken
_collateralAsset
address
Address of collateral asset (underlying of cToken)
_repayAsset
address
Address of asset being repaid
_redeemQuantity
uint256
Quantity of collateral asset to delever
_minRepayQuantity
uint256
Minimum amount of repay asset to receive post trade
_tradeAdapterName
string
Human readable name of the exchange in the integrations registry. Conforms to same interfaces as TradeModule
_tradeData
bytes
Arbitrary data for trade

deleverToZeroBorrowBalance()

function deleverToZeroBorrowBalance(ISetToken _setToken, IERC20 _collateralAsset, IERC20 _repayAsset, uint256 _redeemQuantity, string memory _tradeAdapterName, bytes memory _tradeData)
Manager only. Pays down the borrow asset to 0 selling off a given amount of collateral asset. Withdraws _collateralAsset from Aave. Performs a DEX trade, exchanging the _collateralAsset for _repayAsset. Minimum receive amount for the DEX trade is set to the current variable debt balance of the borrow asset. Repays received _repayAsset to Aave which burns corresponding debt tokens. Any extra received borrow asset is updated as equity. No protocol fee is charged.
Note: Both collateral and borrow assets need to be enabled, and they must not be the same asset. The function reverts if not enough collateral asset is redeemed to buy the required minimum amount of _repayAsset.
Parameter Name
Type
Description
_setToken
ISetToken
Instance of the SetToken
_collateralAsset
address
Address of collateral asset (underlying of cToken)
_repayAsset
address
Address of asset being repaid
_redeemQuantity
uint256
Quantity of collateral asset to delever
_tradeAdapterName
string
Human readable name of the exchange in the integrations registry. Conforms to same interfaces as TradeModule
_tradeData
bytes
Arbitrary data for trade

sync()

function sync(ISetToken _setToken)
Anyone callable. Sync Set positions with ALL enabled Aave collateral and borrow positions. For collateral assets, update aToken default position. For borrow assets, update external borrow position.
    Collateral assets may come out of sync when interest is accrued or a position is liquidated
    Borrow assets may come out of sync when interest is accrued or position is liquidated and borrow is repaid
Note: In Aave, both collateral and borrow interest is accrued in each block by increasing the balance of aTokens and debtTokens for each user, and 1 aToken = 1 variableDebtToken = 1 underlying.
Parameter Name
Type
Description
_setToken
ISetToken
Address of the SetToken

initialize()

function initialize(ISetToken _setToken, IERC20[] memory _collateralAssets, IERC20[] memory _borrowAssets)
Manager only. Initializes this module to the SetToken. Only callable by the SetToken's manager. Note: managers can enable collateral and borrow assets that don't exist as positions on the SetToken
Note: Currently margin trading is in Beta and the CompoundLeverageModule is only initializable by allowed Sets. If you wish to create a SetToken that utilizes margin, please contact us on Discord.
Parameter Name
Type
Description
_setToken
ISetToken
Address of the SetToken
_collateralAssets
IERC20[]
Underlying tokens to be enabled as collateral in the SetToken
_borrowAssets
IERC20[]
Underlying tokens to be enabled as borrow in the SetToken
​
Last modified 29d ago