Lev3x Aave Leverage

Lev3xAaveLeverageModule.sol

lever

MANAGER ONLY: Increases leverage for a given base (collateral) token using an enabled borrow asset (e.g. usdc in bull case). 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. Do this on Initialize.

Example:

lever(
     index.address,
     usdc.address,     // borrow asset
     weth.address,     // collateral asset 
     ether(800),       // quantityUnit = totalQuantityToBorrow/totalSupplyOfIndex
     ether(0.75),      // minQuantityUnit = totalQuantityToReceiveSwap/totalSupplyOfIndex
     "UNISWAP",
     "0x"
);
function lever(
    ISetToken _setToken,
    IERC20 _borrowAsset,
    IERC20 _collateralAsset,
    uint256 _borrowQuantityUnits,
    uint256 _minReceiveQuantityUnits,
    string memory _tradeAdapterName,
    bytes memory _tradeData
) external
  • _setToken Instance of the SetToken

  • _borrowAsset Address of underlying asset being borrowed for leverage

  • _collateralAsset Address of underlying collateral asset

  • _borrowQuantityUnits Borrow quantity of asset in position units

  • _minReceiveQuantityUnits Min receive quantity of collateral asset to receive post-trade in position units

  • _tradeAdapterName Name of trade adapter

  • _tradeData Arbitrary data for trade

delever

MANAGER ONLY: Decrease leverage for a given collateral (base) token using an enabled borrow asset. Withdraws _collateralAsset from Aave. Performs a DEX trade, exchanging the _collateralAsset for _repayAsset (i.e. borrowAsset). Repays _repayAsset to Aave and decreases leverage of index accordingly.

Note: Both collateral and borrow assets need to be enabled, and they must not be the same asset. Do this on initialize.

function delever(
    ISetToken _setToken,
    IERC20 _collateralAsset,
    IERC20 _repayAsset,
    uint256 _redeemQuantityUnits,
    uint256 _minRepayQuantityUnits,
    string memory _tradeAdapterName,
    bytes memory _tradeData
) external 
  • _setToken Instance of the SetToken

  • _collateralAsset Address of underlying collateral asset being withdrawn

  • _repayAsset Address of underlying borrowed asset being repaid

  • _redeemQuantityUnits Quantity of collateral asset to delever in position units

  • _minRepayQuantityUnits Minimum amount of repay asset to receive post trade in position units

  • _tradeAdapterName Name of trade adapter

  • _tradeData Arbitrary data for trade

autoLever

AUTHORIZED CALLER (BOT) ONLY: Increases leverage for a given base (collateral) token using an enabled borrow asset (e.g. usdc in bull case). 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. Do this on Initialize.

function autoLever(
    ISetToken _setToken,
    IERC20 _borrowAsset,
    IERC20 _collateralAsset,
    uint256 _borrowQuantityUnits,
    uint256 _minReceiveQuantityUnits,
    string memory _tradeAdapterName,
    bytes memory _tradeData
) external
  • _setToken Instance of the SetToken

  • _borrowAsset Address of underlying asset being borrowed for leverage

  • _collateralAsset Address of underlying collateral asset

  • _borrowQuantityUnits Borrow quantity of asset in position units

  • _minReceiveQuantityUnits Min receive quantity of collateral asset to receive post-trade in position units

  • _tradeAdapterName Name of trade adapter

  • _tradeData Arbitrary data for trade

autoLever

AUTHORIZED CALLER (BOT) ONLY: Decrease leverage for a given collateral (base) token using an enabled borrow asset. Withdraws _collateralAsset from Aave. Performs a DEX trade, exchanging the _collateralAsset for _repayAsset (i.e. borrowAsset). Repays _repayAsset to Aave and decreases leverage of index accordingly. Note: Both collateral and borrow assets need to be enabled, and they must not be the same asset. Do this on initialize.

Note: This is CRITICAL to be called if position health factor becomes low.

function autoDelever(
    ISetToken _setToken,
    IERC20 _collateralAsset,
    IERC20 _repayAsset,
    uint256 _redeemQuantityUnits,
    uint256 _minRepayQuantityUnits,
    string memory _tradeAdapterName,
    bytes memory _tradeData
)    external 
  • _setToken Instance of the SetToken

  • _collateralAsset Address of underlying collateral asset being withdrawn

  • _repayAsset Address of underlying borrowed asset being repaid

  • _redeemQuantityUnits Quantity of collateral asset to delever in position units

  • _minRepayQuantityUnits Minimum amount of repay asset to receive post trade in position units

  • _tradeAdapterName Name of trade adapter

  • _tradeData Arbitrary data for trade

initialize

MANAGER ONLY: Initializes this module to the SetToken. Either the SetToken needs to be on the allowed list or anySetAllowed needs to be true. Only callable by the SetToken's manager.

Note: Managers can enable collateral and borrow assets that don't exist as positions on the SetToken

function initialize(
    ISetToken _setToken,
    IERC20 _collateralAssets,
    IERC20 _borrowAssets
) external
  • _setToken Instance of the SetToken to initialize

  • _collateralAssets Underlying tokens to be enabled as collateral in the SetToken

  • _borrowAssets Underlying tokens to be enabled as borrow in the SetToken

registerToModule

MANAGER ONLY: Add registration of this module on the debt issuance module for the SetToken.

Note: if the debt issuance module is not added to SetToken before this module is initialized, then this function needs to be called if the debt issuance module is later added and initialized to prevent state inconsistencies

function registerToModule(ISetToken _setToken, IDebtIssuanceModule _debtIssuanceModule) external
  • _setToken Instance of the SetToken

  • _debtIssuanceModule Debt issuance module address to register

updateAllowedSetToken

GOVERNANCE ONLY: Enable/disable ability of a SetToken to initialize this module. Only callable by governance.

function updateAllowedSetToken(ISetToken _setToken, bool _status) external 
  • _setToken Instance of the SetToken

  • _status Bool indicating if _setToken is allowed to initialize this module

updateAnySetAllowed

GOVERNANCE ONLY: Toggle whether ANY SetToken is allowed to initialize this module. Only callable by governance.

function updateAnySetAllowed(bool _anySetAllowed) external
  • _anySetAllowed Bool indicating if ANY SetToken is allowed to initialize this module

Last updated