Nexera-FiAdapters & DeFi ProtocolsIdleCurve 3Pool

Curve 3Pool

Overview

The Curve 3Pool, commonly known as the 3Pool, is an integral component of the Curve protocol, a decentralized finance (DeFi) platform distinguished for its plain pools, which pair two or more stablecoins. As a plain pool, the 3Pool specializes in stablecoin exchange, combining DAI, USDC, and USDT to create a balanced pool, ensuring efficient trading, swapping, and liquidity provision while reducing slippage and transaction costs.

Users can become Liquidity Providers (LPs) by supplying the associated stablecoins to the 3Pool. By doing so, they receive LP tokens that represent their share of the pool's liquidity. These LP tokens entitle users to a portion of the trading fees generated within the 3Pool, rewarding them for their contribution to the platform's liquidity.

The Nexera-Fi CurveFiAdapter_3pool interacts with and utilizes the following two integral components of 3Pool:

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

Note: Curve develops its smart contracts in Vyper, a Python-based programming language. For convenience, we'll present the method interfaces in both Vyper and Solidity syntax.

Interactions with CurveFiAdapter_3pool

The CurveFiAdapter_3pool interacts with Curve's 3Pool by calling the methods presented in the diagram below. Each method serves a specific purpose within the Adapter, enabling strategies to seamlessly integrate deposits, withdrawals, and swaps of the associated stablecoins in the 3Pool.


graph LR; style Nexera_Fi fill:#8453ed; style Curve.Fi fill:#11a66f; style Plain_Pools fill:#12C96f; style LP_Tokens fill:#5ab3aa; subgraph Nexera_Fi A[<b> CurveFiAdapter_3pool </b>] end subgraph Curve.Fi subgraph Plain_Pools B["<b>..."] C["<b>StableSwap3Pool</b> <br/> <i>(3Pool)<i/>"] D["<b>..."] end subgraph LP_Tokens E["<b>..."] F["<b>CurveTokenV2</b> <br/> <i>(LP token for 3Pool)</i>"] G["<b>..."] end end A --> |<b>coins</b>: <i>Retrieve the addresses <br/> of the pool's stablecoins</i>| C A --> |<b>add_liquidity</b>: <i>Deposit stablecoins to the pool</i>| C A --> |<b>remove_liquidity_one_coin</b>: <i>Withdraw a specific stablecoin from the pool</i>| C A --> |<b>remove_liquidity</b>: <i>Withdraw stablecoins from the pool</i>| C A --> |<b>remove_liquidity_imbalance</b>: <i>Withdraw stablecoins from the pool in an imbalanced amount</i>| C A --> |<b>exchange</b>: <i>Perform an exchange between two stablecoins of the pool</i>| C C -.-> |<b>mint</b>: <i>LP tokens to Adapter <br/> on liquidity provision</i>| F C -.-> |<b>burnFrom</b>: <i>LP tokens from Adapter <br/> on liquidity deprivation</i>| F

StableSwap3Pool

The StableSwap3Pool is the contract that implements Curve's AMM stablecoin plain pool of DAI, USDC and USDT, commonly known as 3Pool or Tri-Pool. Through its interface, users can deposit, withdraw and exchange between the supported stablecoins.

In the context of the Nexera-Fi CurveFiAdapter_3pool, these six methods come into play:

  1. coins: Retrieves the addresses of the stablecoins (DAI, USDC, USDT) in the pool.
  2. add_liquidity: Deposits stablecoins to the pool and mints the associated amount of LP tokens in return.
  3. remove_liquidity_one_coin: Withdraws a single specific stablecoin from the pool.
  4. remove_liquidity: Withdraws stablecoins from the pool.
  5. remove_liquidity_imbalance: Withdraws stablecoins from the pool in an imbalanced amount.
  6. exchange: Performs an exchange between two stablecoins of the pool.

Methods

coins

Retrieves the address of the stablecoin specified by its index (0 for DAI, 1 for USDC, and 2 for USDT).

Vyper syntax:

@external
@view
def coins(i: uint256) -> address

Solidity syntax:

function coins(uint256 i) external view returns(address);

This method is invoked by the following CurveFiAdapter_3pool function:

The coins method is invoked within the initialize function to fetch the addresses of the stablecoins in the 3Pool and store them in the coins array of the storage layout.


add_liquidity

Adds liquidity to the pool by depositing stablecoins, and mints the associated amount of LP tokens in return.

Vyper syntax:

@external
def add_liquidity(amounts: uint256[N_COINS], min_mint_amount: uint256)

Solidity syntax:

function add_liquidity(uint256[N_COINS] calldata amounts, uint256 min_mint_amount) external;

This method is invoked by the following CurveFiAdapter_3pool function:

The add_liquidity method is called within the CurveFiAdapter_3pool's _deposit function, using the amounts and min_mint_amount arguments from the out and expectedIn input arguments, respectively.


remove_liquidity_one_coin

Withdraws a single stablecoin from the pool. Returns the amount of coin i received.

Vyper syntax:

@external
def remove_liquidity_one_coin(_token_amount: uint256, i: int128, min_amount: uint256)

Solidity syntax:

function remove_liquidity_one_coin(uint256 token_amount, int128 i, uint256 min_amount) external;

This method is invoked by the following CurveFiAdapter_3pool function:

This function triggers the remove_liquidity_one_coin method on the StableSwap3Pool contract with arguments as defined in the out and expectedIn input arguments. It is executed in the context of the Adapter's _withdraw function when the expectedIn input argument defines only a single token composition.


remove_liquidity

Withdraws stablecoins (up to N_COINS==3) from the pool.

Vyper syntax:

@external
def remove_liquidity(_amount: uint256, min_amounts: uint256[N_COINS])

Solidity syntax:

function remove_liquidity(
    uint256 amount,
    uint256[N_COINS] calldata min_amounts
) external;

This method is invoked by the following CurveFiAdapter_3pool function:

This function triggers the remove_liquidity method on the StableSwap3Pool contract with arguments as defined in the out and expectedIn input arguments. It is executed in the context of the Adapter's _withdraw function when the expectedIn input argument defines more (up to N_COINS == 3) than a single token composition.


remove_liquidity_imbalance

Reduces liquidity in the pool by withdrawing stablecoins (up to N_COINS==3) in an imbalanced amount.

Vyper syntax:

@external
def remove_liquidity_imbalance(amounts: uint256[N_COINS], max_burn_amount: uint256)

Solidity syntax:

function remove_liquidity_imbalance(uint256[N_COINS] calldata amounts, uint256 max_burn_amount) external;

This method is invoked by the following CurveFiAdapter_3pool function:

This function triggers the remove_liquidity_imbalance method on the StableSwap3Pool contract with arguments as defined in the out and expectedIn input arguments. It is executed in the context of the Adapter's _withdraw function when the imbalance property defined in WithdrawExtraData is set to true.


exchange

Performs an exchange between two stablecoins (i & j) against the pool.

Vyper syntax:

@external
def exchange(i: int128, j: int128, dx: uint256, min_dy: uint256)

Solidity syntax:

function exchange(int128 i, int128 j, uint256 dx, uint256 min_dy) external;

This method is invoked by the following CurveFiAdapter_3pool function:

The exchange method is called within the CurveFiAdapter_3pool's _swap function, with arguments as defined in the out and expectedIn input arguments, respectively.

CurveTokenV2

The CurveTokenV2 contract is the LP token associated with the 3Pool within the Curve protocol. It plays a crucial role in incentivizing and rewarding liquidity providers.

LP Token Minting

LP tokens are minted and allocated to the Adapter when liquidity is added to the 3Pool via the _deposit function. This allocation takes place when the add_liquidity method of the StableSwap3pool is invoked in the context of the Adapter's _deposit function.

LP Token Burning

When liquidity is withdrawn from the 3Pool via the _withdraw function, the associated amount of LP tokens is burnt. This takes place when the following methods of StableSwap3pool:

are respectively invoked in the context of the Adapter's _withdraw function.


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

On this page