Compound Leverage Module
The CompoundLeverageModule is a smart contract that enables leverage trading using Compound v2 as the lending protocol. This module is paired with a Debt Issuance Module that will call functions on this contract to keep interest accrual and liquidation state updated. Each asset is leveraged when using this module (i.e. it is not built for simple lending). Integrations mappings to specify the exchange to trade on are stored in the IntegrationRegistry.
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 that is enabled. Performs a DEX trade, exchanging the borrow asset for collateral asset. Deposits _collateralAsset to Compound and mints corresponding aToken. Note: Both collateral and borrow assets need to be enabled, and they must not be the same asset.
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 Compound. Performs a DEX trade, exchanging the _collateralAsset for _repayAsset. Repays _repayAsset to Compound and burns corresponding debt tokens. Note: Both collateral and borrow assets need to be enabled, and they must not be the same asset.
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.
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.
Last updated