Nexera-FiAdapters & DeFi ProtocolsIdleCurve TriCrypto2

CurveFiAdapter_tricrypto2

Git Source

Extends: BaseAdapter

The CurveFiAdapter_tricrypto2 is designed to interact with the Curve.fi USDT/WBTC/ETH Pool.

This adapter enables users to harness the power of Curve.fi USDT/WBTC/ETH trading capabilities and integrate them into their financial strategies.

Structs

InitializeData

Defines the necessary data for initializing the Adapter.

struct InitializeData {
    address pool;
}

Members

NameTypeDescription
pooladdressThe address of the Curve.fi USDT/WBTC/ETH Pool

Layout

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

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

Members

NameTypeDescription
poolICurveFi_tricrypto2The interface representing the Curve.fi USDT/WBTC/ETH Pool instance
lpTokenaddressThe address of the associated LP token (represents liquidity ownership in the Pool)
coinsaddress[]The addresses of the assets in the Pool (USDT/WBTC/ETH)

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 assets (USDT/WBTC/ETH) that Curve.fi Pool 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_tricrypto2 string literal
  • The address of this contract (CurveFiAdapter_tricrypto2)
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 USDT/WBTC/ETH Pool, via invoking the add_liquidity method of the Pool.

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 USDT/WBTC/ETH Pool.

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)
extraDatabytesExtra data parameter. Not used in this context.

_withdrawOne

Helper function for withdrawing liquidity from the Curve.fi USDT/WBTC/ETH Pool when only a single expectedIn token is provided.

This function invokes the remove_liquidity_one_coin method of the Pool.

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 (USDT, or WBTC, or ETH)

_withdrawPoolProportions

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

This function invokes the remove_liquidity method of the Pool.

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

_swap

Internal function for handling Swap Operations.

This function is responsible for performing single-token swaps within the Curve.fi USDT/WBTC/ETH Pool via invoking the exchange method of the Pool.

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 USDT/WBTC/ETH Pool.

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 the Curve.fi USDT/WBTC/ETH Pool.

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 the Curve.fi USDT/WBTC/ETH Pool.

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 the assets supported within the Curve.fi USDT/WBTC/ETH Pool.

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 assets (USDT, WBTC, ETH)

_findTokenIndex

Private helper function used to find the index of a given token within the array of the assets' addresses (USDT, WBTC, ETH) that the _poolTokenAddreses function returns.

Reverts if token is not one of the supported assets : USDT, WBTC, ETH.

Called by withdrawOne and _swap functions.

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

Parameters

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

Returns

NameTypeDescription
<none>uint256The 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);

On this page