Nexera-FiAdapters & DeFi ProtocolsConvex

ConvexAdapter

Git Source

Extends: BaseAdapter

Custom Errors

WRONG_BOOSTER_ADDRESS

Raised when zero address is provided for Booster in the initialize function.

error WRONG_BOOSTER_ADDRESS();

WRONG_TOKEN_COUNT

Raised when the length of expectedIn & out parameters, defining token compositions, do not match the expected length required for an operation.

error WRONG_TOKEN_COUNT();

WRONG_TOKEN_ADDRESS

Raised when an invalid address is provided for a token.

error WRONG_TOKEN_ADDRESS();

WRONG_TOKEN_AMOUNT

Raised when the amount specified in input or output token compositions is wrong with respect to the requested operation.

error WRONG_TOKEN_AMOUNT();

UNKNOWN_OPERATE_OPERATION

Raised when an enum key not defined in OperateOperation is provided as the operation code for _operate function.

error UNKNOWN_OPERATE_OPERATION();

Enums

OperateOperation

Defines the actions available with respect to Operate Operations:

  • STAKE: Stake a convex tokenized deposit
  • UNSTAKE: Unstake to a convex tokenized deposit
enum OperateOperation{ STAKE, UNSTAKE }

Structs

DepositExtraData

Defines the necessary data required for performing deposit actions.

struct DepositExtraData {
    uint256 poolId;
    bool stake;
}

Members

NameTypeDescription
poolIduint256The ID of the target pool to supply liquidity via Convex
stakeboolA flag to indicate whether to stake the convex tokenized deposit (true), or not (false)

WithdrawExtraData

Defines the necessary data required for performing withdraw actions.

struct WithdrawExtraData {
    uint256 poolId;
    bool claimRewards;
}

Members

NameTypeDescription
poolIduint256The ID of the target pool to withdraw liquidity via Convex
claimRewardsboolA flag indicating whether to claim rewards when withdrawing a staked convex tokenized deposit

CollectExtraData

Defines the necessary data required for performing collect actions.

struct CollectExtraData {
    uint256 poolId;
}

Members

NameTypeDescription
poolIduint256The ID of the target pool to claim rewards via Convex

OperateExtraData

Used to indicate the appropriate action of an Operate Operation.

struct OperateExtraData {
    OperateOperation operateOperation;
    uint256 poolId;
    bool claimRewards;
}

Members

NameTypeDescription
operateOperationOperateOperationThe action to conduct
poolIduint256The ID of the target pool
claimRewardsboolA flag to indicate whether to claim rewards on UNSTAKE (irrelevant for STAKE)

Layout

Used to store crucial data for the Adapter's functionality in a specific storage slot.

struct Layout {
    IBooster booster;
}

Members

NameTypeDescription
boosterIBoosterThe address of Convex's Booster contract

State Variables

STORAGE_SLOT

Unique identifier for the storage slot where the Layout struct is stored.

bytes32 internal immutable STORAGE_SLOT;

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.ConvexAdapter string literal
  • The address of this contract (ConvexAdapter)
constructor();

Functions

initialize

Initializes the Adapter.

function initialize(bytes calldata initData_) external override;

Parameters

NameTypeDescription
initData_bytesThe ABI encoded Layout data

_swap

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

Called by executeAction function.

function _swap(
    IAdapter.TokenAmount[] calldata /*out*/,
    IAdapter.TokenAmount[] calldata /*expectedIn*/,
    bytes calldata /*extraData*/
) internal virtual override;

_deposit

Internal function for handling Deposit Operations.

This function is responsible for depositing LP tokens of a protocol (e.g. Curve) to Convex.

Called by executeAction function.

function _deposit(
    IAdapter.TokenAmount[] calldata out,
    IAdapter.TokenAmount[] calldata expectedIn,
    bytes calldata extraData
) internal virtual 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 target pool's underlying token (i.e. the pool's LP token).
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive. Note: - The token field should hold either the address of the tokenized deposit if no stake is applied, or the reward token if stake is applied (see extraData.stake). - The amount field should match the amount defined in the out token composition as the tokenized deposit represents the LP deposit at a 1:1 ratio.
extraDatabytesABI encoded data of type DepositExtraData indicating the target pool, and whether to stake the convex tokenized deposit

_withdraw

Internal function for handling Withdraw Operations.

This function is responsible for withdrawing LP tokens of an underlying protocol (e.g. Curve) from Convex.

Called by executeAction function.

function _withdraw(
    IAdapter.TokenAmount[] calldata out,
    IAdapter.TokenAmount[] calldata expectedIn,
    bytes calldata extraData
) internal virtual 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 either match the target pool's convex tokenized deposit if deposit was not staked, or the target pool's reward contract if deposit was staked.
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive. Note: - The token fields should hold the address of the LP token, and the reward tokens (if rewards are to be claimed).
extraDatabytesABI encoded data of type WithdrawExtraData indicating the target pool, and whether to claim rewards

_collect

Internal function for handling Collect Operations.

This function is responsible for collecting rewards from staked tokenized liquidity.

Called by executeAction function.

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

Parameters

NameTypeDescription
outIAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to send. Notes: - Should be zero-length array (nothing is deposited)
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive. Note: - The token fields should hold the address of the expected reward tokens
extraDatabytesABI encoded data of type CollectExtraData indicating the target pool

_operate

Internal function for handling Operate Operations.

This function is used for:

  • Staking a convex tokenized deposit
  • Unstaking to a convex tokenized deposit

Called by executeAction function.

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

Parameters

NameTypeDescription
outIAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to send. Notes:If STAKE:- The token field should hold the address of the convex tokenized deposit -If UNSTAKE:The token field should hold the address of the target pool's reward contract
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive. Notes:If STAKE:- The token field should hold the address of the target pool's reward contractIf UNSTAKE: - The token field should hold the address of the convex tokenized deposit
extraDatabytesABI encoded data of type OperateExtraData indicating the action to conduct (i.e. stake or unstake), the target pool, and whether to claim rewards on unstake

_stake

Internal helper function for staking a convex tokenized deposit, by invoking the stake function of the respective Convex Reward contract.

Called by _operate function.

function _stake(
    IAdapter.TokenAmount[] calldata out,
    IAdapter.TokenAmount[] calldata expectedIn,
    uint256 poolId    
) internal virtual;

Parameters

NameTypeDescription
outIAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to send. Notes: - The token field should hold the address of the convex tokenized deposit
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive. Notes:- The token field should hold the address of the target pool's reward contract
poolIduint256The ID of the target pool

_unstake

Internal helper function for unstaking to a convex tokenized deposit, by invoking the withdraw function of the respective Convex Reward contract.

Called by _operate function.

function _unstake(
    IAdapter.TokenAmount[] calldata out,
    IAdapter.TokenAmount[] calldata expectedIn,
    uint256 poolId,
    bool claimRewards   
) internal virtual;

Parameters

NameTypeDescription
outIAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to send. Notes:The token field should hold the address of the target pool's reward contract
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive. Notes: - The token field should hold the address of the convex tokenized deposit
poolIduint256The ID of the target pool
claimRewardsboolA flag indicating whether to claim rewards

layout

Retrieves a reference to the Layout struct stored at the storage slot specified by STORAGE_SLOT.

function layout() internal view returns (Layout storage l);