IdleAdapter
Extends: BaseAdapter
Custom Errors
WRONG_OPERATION
Raised when an enum key not defined in DepositOperation or WithdrawOperation is provided as the operation code for _deposit or _withdraw function respectively.
WRONG_INPUT
Raised in _deposit and _withdraw functions when invalid arguments are provided to the out
and/or expectedIn
input parameters (address zero for token
field and/or zero value for amount
field).
WRONG_LENGTH
Raised in _deposit and _withdraw functions when an invalid number of elements is provided for the out
or expectedIn
input parameters.
Enums
DepositOperation
Defines the actions available with respect to Deposit Operations:
MINT_IDLE_TOKEN
: Deposit underlying assets (e.g. DAI) in BY vaults & mint Idle LP tokens (e.g. idleDAI)DEPOSIT_AA_REF
: Deposit underlying assets (e.g. DAI) in YTs & mint AA (Senior) tranche tokens (e.g. AA_DAI)DEPOSIT_BB_REF
: Deposit underlying assets (e.g. DAI) in YTs & mint BB (Junior) tranche tokens (e.g. BB_DAI)
WithdrawOperation
Defines the actions available with respect to Withdraw Operations:
REDEEM_IDLE_TOKEN
: Burn Idle LP tokens (e.g. idleDAI) to redeem underlying asset (e.g. DAI) and/or accrued Governance tokens (i.e. IDLE)REDEEM_INTEREST_BEARING_TOKENS
: Burn Idle LP tokens (e.g. idleDAI) to redeem interest bearing tokens (e.g. aDAI, cDAI) and unlent underlying (e.g. DAI)WITHDRAW_AA
: Burn AA (Senior) tranche tokens (e.g. AA_DAI) to redeem underlying principal + interestsWITHDRAW_BB
: Burn BB (Junior) tranche tokens (e.g. BB_DAI) to redeem underlying principal + interests
Structs
DepositExtraData
Defines the necessary data required for performing deposit actions.
Members
Name | Type | Description |
---|---|---|
depositOperation | DepositOperation | The action to conduct. |
referral | address | The address of the referral. |
idleCDO | address | The address of the target Yield Tranche (YT) contract to deposit to.Note:- Not utilized for DepositOperation.MINT_IDLE_TOKEN |
WithdrawExtraData
Defines the necessary data required for performing withdraw actions.
Members
Name | Type | Description |
---|---|---|
withdrawOperation | WithdrawOperation | The action to conduct. |
idleCDO | address | The address of the target Yield Tranche (YT) contract to withdraw from.Note:- Not utilized for: WithdrawOperation.REDEEM_IDLE_TOKEN & WithdrawOperation.REDEEM_INTEREST_BEARING_TOKENS |
Functions
initialize
The initialize function has an empty body and serves as a structural requirement to comply with the BaseAdapter. It doesn't execute any specific actions.
_deposit
Internal function for handling Deposit Operations.
This function is used for:
- Depositing assets to Idle protocol to mint Idle tokens (Best Yield)
- Depositing assets to Idle protocol to mint AA (Senior) or BB (Junior) tranche tokens (Yield Tranches)
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. Notes: - The length of the array must equal one. - The token field should match the underlying asset address (e.g. DAI) of the target BY vault or YT.- The amount field should contain the amount to deposit. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. Notes: - The length of the array must equal one. - The token field should hold either the address of the target Best Yield vault (IdleToken instance), or the address of the target Yield Tranche (idleCDO instance) depending on the operation. |
extraData | bytes | ABI encoded data of type DepositExtraData indicating: - The operation to be performed. - The target YT (utilized only in YT related operations). - The referral address (if provided). |
_withdraw
Internal function for handling Withdraw Operations.
This function is used for:
- Withdrawal from Idle Best Yield vaults (underlying asset and/or interest bearing tokens)
- Withdrawal from Idle Yield Tranches (underlying asset principal + interests)
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. Notes: - The length of the array must equal one. - The token field should match either the address of the target Best Yield vault (IdleToken instance), or the address of the target Yield Tranche (idleCDO instance) depending on the operation.- The amount field should contain the amount to burn. |
<none> | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. Not used in this context. |
extraData | bytes | ABI encoded data of type WithdrawExtraData indicating: - The operation to be performed. - The target YT (utilized only in YT related operations). |
_swap
This function always raises the OPERATION_NOT_SUPPORTED error, as SWAP is not an action supported within Idle.
Called by executeAction function.
_collect
This function always raises the OPERATION_NOT_SUPPORTED error, as COLLECT is not an action supported within Idle.
Called by executeAction function.
_operate
This function always raises the OPERATION_NOT_SUPPORTED error, as OPERATE is not an action supported within Idle.
Called by executeAction function.
_mintIdleToken
Internal helper function for depositing assets into Idle and minting IdleTokens (ERC-20 shares) in return, by invoking the mintIdleToken
function on the Best Yield vault specified by idleToken
.
Called by _deposit function.
Parameters
Name | Type | Description |
---|---|---|
token | address | The asset to deposit (e.g. DAI) |
amount | uint256 | The amount of token to deposit |
idleToken | address | The address of the target Best Yield vault |
referral | address | The address of the referral |
_depositAARef
Internal helper function for depositing assets into Idle and minting AA (Senior) tranche tokens (ERC-20) in return, by invoking the depositAARef
function on the Yield Tranche (YT) specified by idleCDO
.
Called by _deposit function.
Parameters
Name | Type | Description |
---|---|---|
token | address | The asset to deposit (e.g. DAI) |
amount | uint256 | The amount of token to deposit |
idleCDO | address | The address of the target Yield Tranche |
referral | address | The address of the referral |
_depositBBRef
Internal helper function for depositing assets into Idle and minting BB (Junior) tranche tokens (ERC-20) in return, by invoking the depositBBRef
function on the Yield Tranche (YT) specified by idleCDO
.
Called by _deposit function.
Parameters
Name | Type | Description |
---|---|---|
token | address | The asset to deposit (e.g. DAI) |
amount | uint256 | The amount of token to deposit |
idleCDO | address | The address of the target Yield Tranche |
referral | address | The address of the referral |
_checkAndApprove
Internal helper function responsible for checking and setting allowances for token transfers to a designated receiver (e.g. a target BY vault or YT).
Called by the following functions:
Parameters
Name | Type | Description |
---|---|---|
token | address | The address of the token for which the allowance is being set |
amount | uint256 | The amount to set the allowance to |
receiver | address | The address of the receiver to whom the allowance is granted |
_redeemIdleToken
Internal helper function for withdrawing underlying assets by burning Idle LP tokens in return. This is achieved by invoking the redeemIdleToken
function on the Best Yield vault specified by idleToken
.
Notes:
- Any accrued governance tokens (i.e. IDLE) are also redeemed.
- Use zero
amount
to only redeem governance tokens, and maintain the position in Idle.
Called by _withdraw function.
Parameters
Name | Type | Description |
---|---|---|
idleToken | address | The address of the target Best Yield vault |
amount | uint256 | The amount of Idle LP tokens to burn |
_redeemInterestBearingTokens
Internal helper function for withdrawing interest-bearing tokens (e.g. aTokens from Aave, cTokens from Compound, ...) and unlent underlying assets by burning Idle LP tokens in return. This is achieved by invoking the redeemInterestBearingTokens
function on the Best Yield vault specified by idleToken
.
Note:
- The
redeemInterestBearingTokens
function can only be called in emergency situations when the BY vault is paused.
Called by _withdraw function.
Parameters
Name | Type | Description |
---|---|---|
idleToken | address | The address of the target Best Yield vault |
amount | uint256 | The amount of Idle LP tokens to burn |
_withdrawAA
Internal helper function for withdrawing principal underlying assets + interests by burning AA (Senior) tranche tokens in return. This is achieved by invoking the withdrawAA
function on the Yield Tranche specified by idleCDO
.
Notes:
- This is only possible when no emergency shutdown is in progress for the Yield Tranche.
Called by _withdraw function.
Parameters
Name | Type | Description |
---|---|---|
idleCDO | address | The address of the target Yield Tranche |
amount | uint256 | The amount of AA (Senior) tranche tokens to burn |
_withdrawBB
Internal helper function for withdrawing principal underlying assets + interests by burning BB (Junior) tranche tokens in return. This is achieved by invoking the withdrawBB
function on the Yield Tranche specified by idleCDO
.
Notes:
- This is only possible when no emergency shutdown is in progress for the Yield Tranche.
Called by _withdraw function.
Parameters
Name | Type | Description |
---|---|---|
idleCDO | address | The address of the target Yield Tranche |
amount | uint256 | The amount of BB (Junior) tranche tokens to burn |