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.

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 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.

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

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.

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 updated