Nexera-FiAdapters & DeFi ProtocolsIdleCurve 3Pool

CurveFiAdapter_3pool

Git Source

Extends: BaseAdapter

The CurveFiAdapter_3pool is designed to interact with the Curve.fi 3Pool.

This adapter enables users to harness the power of Curve.fi 3Pool trading capabilities and integrate them into their financial strategies.

Structs

InitializeData

Defines the necessary data for initializing the Adapter.

struct InitializeData {
    address pool;
    address lpToken;
}

Members

NameTypeDescription
pooladdressThe address of the Curve.fi 3Pool (DAI/USDC/USDT) contract (StableSwap3Pool)
lpTokenaddressThe address of the associated LP token (represents liquidity ownership in the Pool)

WithdrawExtraData

Used to provide the necessary data when performing a Withdraw operation.

struct WithdrawExtraData {
    bool imbalance;
}

Members

NameTypeDescription
imbalanceboolA flag which influences the withdrawal. If true, the StableSwap3Pool:: remove_liquidity_imbalance method will be used to withdraw exact amounts while ensuring no more LP tokens are burned than the out amounts provided. If false, it burns out LP token amounts, withdrawing no less than the expectedIn amounts provided.

Layout

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

struct Layout {
    ICurveFi_3pool pool;
    address lpToken;
    address[] coins;
}

Members

NameTypeDescription
poolICurveFi_3poolThe interface representing the Curve.fi StableSwap3Pool contract instance
lpTokenaddressThe address of the associated LP token (represents liquidity ownership in the Pool)
coinsaddress[]The addresses of the stable coins in the Pool (DAI/USDC/USDT)

State Variables

STORAGE_SLOT

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

bytes32 internal immutable STORAGE_SLOT;

N_COINS

Constant value that defines the number of distinct stable coins (DAI, USDC, USDT) that Curve.fi 3Pool handles.

uint256 private constant N_COINS = 3;

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

Functions

initialize

Initializes the Adapter.

function initialize(bytes calldata initData_) external override;

Parameters

NameTypeDescription
initData_bytesThe ABI encoded InitializeData

_deposit

Internal function for handling Deposit Operations.

This function is responsible for adding liquidity to the Curve.fi 3Pool via invoking the add_liquidity of the StableSwap3Pool contract.

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 (up to N_COINS tokens)
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive. It can either be empty or have one token (LP token) which will be used as the minimum amount to mint.
extraDatabytesExtra data parameter. Not used in this context.

_withdraw

Internal function for handling Withdraw Operations.

This function is responsible for withdrawing liquidity from the Curve.fi 3Pool via interacting with StableSwap3Pool contract.

Called by executeAction function.

function _withdraw(
    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. Should only contain the LP token to burn.
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive (up to N_COINS tokens)
extraDatabytesABI encoded data of type WithdrawExtraData

_withdrawOne

Helper function for withdrawing liquidity from the Curve.fi 3Pool when only a single expectedIn token is provided.

This function invokes the remove_liquidity_one_coin method of the Pool (StableSwap3Pool).

Called by _withdraw function.

function _withdrawOne(
    IAdapter.TokenAmount[] calldata out,
    IAdapter.TokenAmount[] calldata expectedIn
) private;

Parameters

NameTypeDescription
outIAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to send. Should only contain the LP token to burn.
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive. Should only contain one token (DAI, or USDC, or USDT)

_withdrawPoolProportions

Helper function for withdrawing liquidity from the Curve.fi 3Pool when more than a single expectedIn token is provided.

This function invokes the remove_liquidity method of the Pool (StableSwap3Pool).

Called by _withdraw function.

function _withdrawPoolProportions(
    IAdapter.TokenAmount[] calldata out,
    IAdapter.TokenAmount[] calldata expectedIn
) private;

Parameters

NameTypeDescription
outIAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to send. Should only contain the LP token to burn.
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive (up to N_COINS tokens)

_withdrawImbalance

Helper function for withdrawing liquidity from the Curve.fi 3Pool when WithdrawExtraData.imbalance == true.

This function invokes remove_liquidity_imbalance method of the Pool (StableSwap3Pool).

Called by _withdraw function.

 function _withdrawImbalance(
    IAdapter.TokenAmount[] calldata out,
    IAdapter.TokenAmount[] calldata expectedIn
) private;

Parameters

NameTypeDescription
outIAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to send. Should only contain the LP token to burn.
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive (up to N_COINS tokens)

_swap

Internal function for handling Swap Operations.

This function is responsible for performing single-token swaps within the Curve.fi 3Pool via invoking the exchange method of the Pool (StableSwap3Pool).

function _swap(
    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. Should contain only the token to exchange from.
expectedInIAdapter.TokenAmount[]Array of TokenAmount structs defining the expected token compositions to receive. Should contain only the token to exchange to.
extraDatabytesExtra data parameter. Not used in this context.

_collect

This function always raises the OPERATION_NOT_SUPPORTED error, as Collect is not an action supported within the Curve.fi 3Pool.

Called by executeAction function.

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

_operate

This function always raises the OPERATION_NOT_SUPPORTED error, as Operate is not an action supported within the Curve.fi 3Pool.

Called by executeAction function.

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

_approveOutTransfers

Private helper function used to approve token transfers to the Curve.fi 3Pool.

Called by the following functions:

function _approveOutTransfers(IAdapter.TokenAmount[] calldata out) private;

Parameters

NameTypeDescription
outIAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to send

_fillAmountsArray

Private helper function used to extract the amount values of the provided token compositions.

Called by the following functions:

function _fillAmountsArray(IAdapter.TokenAmount[] calldata tokenAmounts)
    private
    view
    returns(uint256[N_COINS] memory amounts);

Parameters

NameTypeDescription
tokenAmountsIAdapter.TokenAmount[]Array of TokenAmount structs defining the token compositions to extract the respective amount values

Returns

NameTypeDescription
amountsuint256[N_COINS]Array of lenght N_COINS with the amount values

_poolTokenAddreses

Private helper function used to retrieve the addresses of all three stable coins supported within the Curve.fi 3Pool.

Called by _fillAmountsArray and _findTokenIndex functions.

function _poolTokenAddreses() private view returns(address[N_COINS] memory poolTokens);

Returns

NameTypeDescription
poolTokensaddress[N_COINS]Array of lenght N_COINS with the addresses of the stable coins (DAI, USDC & USDT)

_findTokenIndex

Private helper function used to find the index of a given token within the array of stable coin addresses (DAI, USDC, USDT) that the _poolTokenAddreses function returns.

Reverts if token is not one of the supported stable coins : DAI, USDC, USDT.

Called by withdrawOne and _swap functions.

function _findTokenIndex(address token) private view returns(int128);

Parameters

NameTypeDescription
tokenaddressThe address of the token for which the index needs to be found

Returns

NameTypeDescription
<none>int128The index of token within the array that _poolTokenAddreses returns

_findAmount

Private helper function responsible for returning the amount associated with a specific token within an array of TokenAmount structures.

Returns 0 if token is not present in the tokenAmounts array.

Called by _fillAmountsArray function.

function _findAmount(IAdapter.TokenAmount[] calldata tokenAmounts, address token)
    private
    pure
    returns(uint256);

Parameters

NameTypeDescription
tokenAmountsIAdapter.TokenAmount[]Array of TokenAmount structs with the token compositions to search
tokenaddressThe address of the token for which the associated amount needs to be found within the tokenAmounts array

Returns

NameTypeDescription
<none>uint256The amount associated with token within the tokenAmounts array, or 0 if token is not found within tokenAmounts

layout

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

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