Nexera-FiAdapters & DeFi ProtocolsConvex

Convex Protocol

Overview

Convex Finance is a DeFi protocol designed to enhance yields for CRV token holders and Curve liquidity providers. The protocol offers two reward-boosting strategies: staking CRV tokens for cvxCRV, and staking Curve LP tokens. Stakers receive additional rewards, including CVX tokens, while liquidity providers benefit from boosted incentives. Functioning as a bridge to Curve Finance, Convex facilitates user access to liquidity, trading fee earnings, and automated reward harvesting by integrating seamlessly with Curve's stablecoin pools.

The Nexera-Fi ConvexAdapter interacts with and utilizes the following two components of Convex:

In the following sections, we'll provide an overview of these contracts and their methods that Nexera-Fi ConvexAdapter interacts with.

Interactions with ConvexAdapter

The ConvexAdapter interacts with Convex protocol by calling the methods presented in the diagram below. Each method serves a specific purpose within the Adapter, enabling strategies to seamlessly integrate liquidity provision, liquidity withdrawal, and staking/unstaking functionality via Convex.


graph LR; style Nexera_Fi fill:#8453ed style Convex fill:#32a885; style Booster fill:#d0d96a; style Rewards fill:#68a6f2; subgraph Nexera_Fi A[<b> ConvexAdapter </b>] end subgraph Convex subgraph Booster end subgraph Rewards B["<b>...</b>"] C["<b>BaseRewardPool instance</b>"] D["<b>...</b>"] end end A --> |<b>poolInfo</b>: <i>Retrieve pools' details</i>| Booster A --> |<b>deposit</b>: <i>Deposit Curve LP tokens to Convex</i>| Booster A --> |<b>withdraw</b>: <i>Withdraw Curve LP tokens from Convex</i>| Booster A --> |<b>getReward</b>: <i>Claim rewards</i>| Rewards A --> |<b>stake</b>: <i>Stake a convex tokenized deposit</i>| Rewards A --> |<b>withdraw</b>: <i>Unstake to a convex tokenized deposit</i>| Rewards A --> |<b>withdrawAndUnwrap</b>: <i>Unstake directly to curve LP token</i>| Rewards

Booster

The Booster serves as the central deposit contract for LP tokens and it is essentially the entry point for Convex pools. Through its interface users can deposit Curve LP tokens and receive convex tokenized deposit shares at a 1:1 ratio, or retrieve their Curve LP tokens by burning these deposit shares.

In the context of the Nexera-Fi ConvexAdapter, these three methods come into play:

  1. poolInfo
  2. deposit
  3. withdraw

Methods

poolInfo

Retrieve information for the pool specified by _pid.

struct PoolInfo {
    address lptoken;    // the underlying token (Curve LP token)
    address token;      // the convex deposit token (a 1:1 token representing an LP deposit).
    address gauge;      // the Curve "gauge" or staking contract used by the pool
    address crvRewards; // Address of reward contract
    address stash;      // contract used to hold extra rewards (e.g. snx)
    bool shutdown;      // a shutdown flag of the pool
}
 
function poolInfo(uint256 _pid) external returns (PoolInfo memory);

This method is invoked by the following ConvexAdapter functions:

These functions leverage the poolInfo method of the Booster contract to retrieve key details related to a targeted pool identified by the poolId within the respective Deposit, Withdraw, Collect and Operate ExtraData structs. Each function performs dedicated verification steps against the acquired pool information and the provided input to ensure consistency between the involved assets and the associated rewards contract. This validation process helps maintain the integrity of the operations, ensuring accurate interactions with the Convex protocol.


deposit

Deposit Curve LP tokens into Convex, receive a tokenized deposit, and optionally immediately stake the tokenized deposit.

function deposit(uint256 _pid, uint256 _amount, bool _stake) external returns (bool);

This method is invoked by the following ConvexAdapter function:

This function invokes the deposit method of the Booster contract to deposit the LP tokens specified in out input parameter. The poolId and stake fields within extraData input parameter (ABI encoded DepositExtraData struct) indicate the targeted pool and whether to stake the received convex tokenized deposit.


withdraw

Withdraw deposited Curve LP tokens by burning the convex tokenized deposit _amount.

function withdraw(uint256 _pid, uint256 _amount) external returns (bool);

This method is invoked by the following ConvexAdapter function:

This function invokes the withdraw method of the Booster contract when the claimRewards field within the extraData input parameter (ABI encoded WithdrawExtraData struct) is set to false. The LP tokens to be withdrawn are specified in expectedIn input parameter and the convex tokenized deposit to burn is specified in the out input parameter. The poolId field within extraData indicates the targeted pool.

BaseRewardPool

Convex employes the Synthetix BaseRewardPool as the implementation reward contract for all LP pools.

Each LP pool is associated with a certain BaseRewardPool instance where the asset-to-share ratio is maintained at 1:1, ensuring that users' assets are closely aligned with their share in the pool. The chosen "asset" within such instances is a corresponding convex tokenized deposit, which represents a user's share of assets in the associated pool.

In the context of the Nexera-Fi ConvexAdapter, these four methods come into play:

  1. getReward
  2. stake
  3. withdraw
  4. withdrawAndUnwrap

Methods

getReward

Claim accrued rewards from staked tokenized liquidity.

function getReward() external returns (bool);

This method is invoked by the following ConvexAdapter function:

This function invokes the getReward method of the BaseRewardPool instance associated with the convex pool specified by poolId field within extraData input parameter (ABI encoded CollectExtraData struct).


stake

Stake a convex tokenized deposit.

function stake(uint256 _amount) external returns (bool);

This method is invoked by the following ConvexAdapter function:

This function invokes the stake method of the BaseRewardPool instance associated with the convex pool specified by poolId input parameter. It is triggered within the context of the Adapter's _operate function when OperateOperation is configured as STAKE,


withdraw

Unstake to a convex tokenized deposit, and optionally claim accrued rewards.

function withdraw(uint256 _amount, bool _claim) external returns (bool);

This method is invoked by the following ConvexAdapter function:

This function invokes the withdraw method of the BaseRewardPool instance associated with the convex pool specified by poolId input parameter. It is triggered within the context of the Adapter's _operate function when OperateOperation is configured as UNSTAKE,


withdrawAndUnwrap

Unstake directly to curve LP token, and optionally claim accrued rewards.

function withdrawAndUnwrap(uint256 _amount, bool _claim) external returns (bool);

This method is invoked by the following ConvexAdapter function:

This function invokes the withdrawAndUnwrap method of the BaseRewardPool instance associated with the convex pool specified by poolId field within extraData input parameter (ABI encoded WithdrawExtraData struct). The execution occurs when the token specified in the out input parameter aligns with the reward contract of the targeted pool.


Please note: For detailed information about Convex protocol, consult the official Convex documentation.

On this page