CompoundAdapter
Extends: BaseAdapter
The CompoundAdapter
is designed to interact with the Compound v2 Protocol.
This adapter enables users to harness the power of Compound v2 lending and borrowing capabilities and integrate them into their financial strategies.
Enums
DepositOperation
Defines the actions available with respect to Deposit Operations:
MINT
: Depositing assets in return for cTokensREPAY_BORROW
: Depositing borrowed assets for reducing the outstanding debt (partially of fully)
WithdrawOperation
Defines the actions available with respect to Withdraw Operations:
BORROW
: Withdraw assets as a loanREDEEM
: Withdraw assets converted from cTokensREDEEM_UNDERLYING
: Withdraw underlying assets accrued based on position
CollectOperation
Defines the actions for collecting rewards (Collect Operation) from the Compound protocol:
CLAIM_COMP
: Claim COMP tokens from specific markets as rewardsCLAIM_COMP_ALL
: Claim all available COMP tokens as rewards
OperateOperation
Defines the actions available for interacting with Compound markets:
ENTER_MARKETS
: Entering one or more Compound markets, which enables supply and borrowing of assetsEXIT_MARKETS
: Exiting one or more Compound markets, which may introduce restrictions with respect to supplying or borrowing certain assets
Structs
DepositExtraData
Used to indicate the appropriate action of a Deposit Operation.
Members
Name | Type | Description |
---|---|---|
depositOperation | DepositOperation | The action to conduct |
WithdrawExtraData
Used to indicate the appropriate action of a Withdraw Operation.
Members
Name | Type | Description |
---|---|---|
withdrawOperation | WithdrawOperation | The action to conduct |
CollectExtraData
Used to indicate the appropriate action of a Collect Operation.
Members
Name | Type | Description |
---|---|---|
collectOperation | CollectOperation | The action to conduct |
OperateExtraData
Used to indicate the appropriate action of an Operate Operation.
Members
Name | Type | Description |
---|---|---|
operateOperation | OperateOperation | The action to conduct |
Layout
Used to store the address of the Compound Comptroller contract in a specific storage slot.
This approach ensures data consistency across different contract versions (in case of upgrades).
Members
Name | Type | Description |
---|---|---|
comptroller | address | The address of the Comptroller contract |
State Variables
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored.
Constructor
Sets the value of the STORAGE_SLOT state variable.
The value is computed as the keccak256 hash of the abi encoding of:
- The
Nexera-FI.CompoundAdapter
string literal - The address of this contract (CompoundAdapter)
Functions
initialize
Initializes the Adapter by setting the address of the Comptroller contract.
Parameters
Name | Type | Description |
---|---|---|
initData_ | bytes | The ABI encoded Comptroller contract address |
_deposit
Internal function for handling Deposit Operations.
This function is used for minting or repaying borrow actions within the Compound protocol.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. For both minting and repaying borrow actions, expectedIn should only include the addresses of the cToken markets with an amount equal to 0. |
extraData | bytes | ABI encoded data of type DepositExtraData indicating the action (either MINT or REPAY_BORROW) |
_withdraw
Internal function for handling Withdraw Operations.
This function is used for borrowing or redeeming actions within the Compound protocol.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. - In the case of borrowing and redeeming underlying assets, it should contain only the address of the cToken. - In the case of redeeming, it should include the address of the cToken and the amount of cTokens to be provided. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. - For borrowing and redeeming, it should contain the addresses of the assets to be borrowed or redeemed respectively. - For redeeming underlying assets, it should contain the addresses and the amounts of the underlying assets to be redeemed. |
extraData | bytes | ABI encoded data of type WithdrawExtraData indicating the action (BORROW, REDEEM or REDEEM_UNDERLYING) |
_collect
Internal function for handling Collect Operations.
This function is used for claiming rewards (COMP Tokens) within the Compound protocol.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. - In the case of CLAIM_COMP, it should contain the addresses of cToken markets from which to claim COMP. - In the case of CLAIM_COMP_ALL, no TokenAmount arguments are needed. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. For both actions (CLAIM_COMP or CLAIM_COMP_ALL), it should contain the address of the COMP token |
extraData | bytes | ABI encoded data of type CollectExtraData indicating the action (CLAIM_COMP or CLAIM_COMP_ALL) |
_operate
Internal function for handling Operate Operations.
This function is used for interacting with markets within the Compound protocol by either entering or exiting them.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. For both actions (ENTER_MARKETS or EXIT_MARKETS), it should contain the cToken addresses of the markets to enter or exit respectively |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. Should be empty as this parameter is not used in this context. |
extraData | bytes | ABI encoded data of type OperateExtraData indicating the action (ENTER_MARKETS or EXIT_MARKETS) |
_mint
Internal function for handling Minting actions within a Deposit Operation.
This function is responsible for minting new cTokens when assets (ERC20 or Ether) are supplied into the respective market via interacting with Compound's:
Called by _deposit function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
length | uint256 | The length of the out and expectedIn arrays (should have same length as every market cToken is associated with a respective underlying asset) |
_repayBorrow
Internal function for handling RepayBorrow actions within a Deposit Operation.
Called by _deposit function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
length | uint256 | The length of the out and expectedIn arrays (should have same length as every market cToken is associated with a respective underlying asset) |
_checkRevertsOnDeposit
Internal function for checking potential reverts on Deposit Operations.
Called by _repayBorrow and _mint functions.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount | A TokenAmount struct defining the token (address & amount) to send |
expectedIn | IAdapter.TokenAmount | A TokenAmount struct defining the expected token (address & amount) to receive |
_approveOnDeposit
Internal function for approving token allowances on Deposit Operations.
Called by _repayBorrow and _mint functions.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount | A TokenAmount struct defining the token (address & amount) to send |
expectedIn | IAdapter.TokenAmount[] | A TokenAmount struct defining the expected token (address & amount) to receive |
_borrow
Internal function for handling Borrow actions within a Withdraw Operation.
Called by _withdraw function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
length | uint256 | The length of the out and expectedIn arrays (should have same length as every market cToken is associated with a respective underlying asset) |
_redeem
Internal function for handling REDEEM actions within a Withdraw Operation.
Called by _withdraw function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
length | uint256 | The length of the out and expectedIn arrays (should have same length as every market cToken is associated with a respective underlying asset) |
_redeem_underlying
Internal function for handling REDEEM_UNDERLYING actions within a Withdraw Operation.
Called by _withdraw function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive |
length | uint256 | The length of the out and expectedIn arrays (should have same length as every market cToken is associated with a respective underlying asset) |
_checkRevertsOnWithdrawal
Internal function for checking potential reverts on Withdraw Operations.
Called by _borrow, _redeem and _redeem_underlying functions.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount | A TokenAmount struct defining the token (address & amount) to send |
expectedIn | IAdapter.TokenAmount | A TokenAmount struct defining the expected token (address & amount) to receive |
amountToCheck | uint256 | The token amount defined in expectedIn |
_claim_comp
Internal function for handling CLAIM_COMP actions within a Collect Operation.
Called by _collect function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
comptroller | address | The address of the Comptroller contract |
_claim_comp_all
Internal function for handling CLAIM_COMP_ALL actions within a Collect Operation.
Called by _collect function.
Parameters
Name | Type | Description |
---|---|---|
comptroller | address | The address of the Comptroller contract |
_enter_markets
Internal function for handling ENTER_MARKETS actions within a Operate Operation.
Called by _operate function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
comptroller | address | The address of the Comptroller contract |
_exit_markets
Internal function for handling EXIT_MARKETS actions within a Operate Operation.
Called by _operate function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
comptroller | address | The address of the Comptroller contract |
_checkRevertsOnOperate
Internal function for checking potential reverts on Operate Operations.
Called by _enter_markets and _exit_markets functions.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
_swap
This function always raises the OPERATION_NOT_SUPPORTED error, as Swap is not an action supported within the Compound protocol.
Called by executeAction function.
layout
Retrieves a reference to the Layout struct stored at a specified storage slot.