Nexera-FiAdapters & DeFi ProtocolsIdle

IdleAdapter

Git Source

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.

error WRONG_OPERATION();

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

error WRONG_INPUT();

WRONG_LENGTH

Raised in _deposit and _withdraw functions when an invalid number of elements is provided for the out or expectedIn input parameters.

error WRONG_LENGTH();

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)
enum DepositOperation {
    MINT_IDLE_TOKEN,
    DEPOSIT_AA_REF,
    DEPOSIT_BB_REF
}

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 + interests
  • WITHDRAW_BB: Burn BB (Junior) tranche tokens (e.g. BB_DAI) to redeem underlying principal + interests
enum WithdrawOperation {
    REDEEM_IDLE_TOKEN,
    REDEEM_INTEREST_BEARING_TOKENS,
    WITHDRAW_AA,
    WITHDRAW_BB
}

Structs

DepositExtraData

Defines the necessary data required for performing deposit actions.

struct DepositExtraData {
    DepositOperation depositOperation;
    address referral;
    address idleCDO;
}

Members

NameTypeDescription
depositOperationDepositOperationThe action to conduct.
referraladdressThe address of the referral.
idleCDOaddressThe 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.

struct WithdrawExtraData {
    WithdrawOperation withdrawOperation;
    address idleCDO;
}

Members

NameTypeDescription
withdrawOperationWithdrawOperationThe action to conduct.
idleCDOaddressThe 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.

function initialize(bytes calldata) external override;

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

function _deposit(
    IAdapter.TokenAmount[] calldata out,
    IAdapter.TokenAmount[] calldata expectedIn,
    bytes calldata extraData
) internal override;

Parameters

NameTypeDescription
outIAdapter.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.
expectedInIAdapter.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.
extraDatabytesABI 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.

function _withdraw(
    IAdapter.TokenAmount[] calldata out,
    IAdapter.TokenAmount[] calldata,
    bytes calldata extraData
) internal override;

Parameters

NameTypeDescription
outIAdapter.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.
extraDatabytesABI 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.

function _swap(
    IAdapter.TokenAmount[] calldata,
    IAdapter.TokenAmount[] calldata,
    bytes calldata
) internal virtual override;

_collect

This function always raises the OPERATION_NOT_SUPPORTED error, as COLLECT is not an action supported within Idle.

Called by executeAction function.

function _collect(
    IAdapter.TokenAmount[] calldata,
    IAdapter.TokenAmount[] calldata,
    bytes calldata
) internal virtual override;

_operate

This function always raises the OPERATION_NOT_SUPPORTED error, as OPERATE is not an action supported within Idle.

Called by executeAction function.

function _operate(
    IAdapter.TokenAmount[] calldata,
    IAdapter.TokenAmount[] calldata,
    bytes calldata
) internal virtual override;

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

function _mintIdleToken(
    address token,
    uint256 amount,
    address idleToken,
    address referral
) internal;

Parameters

NameTypeDescription
tokenaddressThe asset to deposit (e.g. DAI)
amountuint256The amount of token to deposit
idleTokenaddressThe address of the target Best Yield vault
referraladdressThe 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.

function _depositAARef(
    address token,
    uint256 amount,
    address idleCDO,
    address referral
) internal;

Parameters

NameTypeDescription
tokenaddressThe asset to deposit (e.g. DAI)
amountuint256The amount of token to deposit
idleCDOaddressThe address of the target Yield Tranche
referraladdressThe 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.

function _depositBBRef(
    address token,
    uint256 amount,
    address idleCDO,
    address referral
) internal;

Parameters

NameTypeDescription
tokenaddressThe asset to deposit (e.g. DAI)
amountuint256The amount of token to deposit
idleCDOaddressThe address of the target Yield Tranche
referraladdressThe 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:

function _checkAndApprove(address token, uint256 amount, address receiver) internal;

Parameters

NameTypeDescription
tokenaddressThe address of the token for which the allowance is being set
amountuint256The amount to set the allowance to
receiveraddressThe 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.

function _redeemIdleToken(address idleToken, uint256 amount) internal;

Parameters

NameTypeDescription
idleTokenaddressThe address of the target Best Yield vault
amountuint256The 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.

function _redeemInterestBearingTokens(
    address idleToken,
    uint256 amount
) internal;

Parameters

NameTypeDescription
idleTokenaddressThe address of the target Best Yield vault
amountuint256The 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.

function _withdrawAA(address idleCDO, uint256 amount) internal;

Parameters

NameTypeDescription
idleCDOaddressThe address of the target Yield Tranche
amountuint256The 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.

function _withdrawBB(address idleCDO, uint256 amount) internal;

Parameters

NameTypeDescription
idleCDOaddressThe address of the target Yield Tranche
amountuint256The amount of BB (Junior) tranche tokens to burn