CurveFiAdapter_3pool
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.
Members
Name | Type | Description |
---|---|---|
pool | address | The address of the Curve.fi 3Pool (DAI/USDC/USDT) contract (StableSwap3Pool) |
lpToken | address | The address of the associated LP token (represents liquidity ownership in the Pool) |
WithdrawExtraData
Used to provide the necessary data when performing a Withdraw operation.
Members
Name | Type | Description |
---|---|---|
imbalance | bool | A 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.
Members
Name | Type | Description |
---|---|---|
pool | ICurveFi_3pool | The interface representing the Curve.fi StableSwap3Pool contract instance |
lpToken | address | The address of the associated LP token (represents liquidity ownership in the Pool) |
coins | address[] | 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.
N_COINS
Constant value that defines the number of distinct stable coins (DAI, USDC, USDT) that Curve.fi 3Pool handles.
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)
Functions
initialize
Initializes the Adapter.
Parameters
Name | Type | Description |
---|---|---|
initData_ | bytes | The 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.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (up to N_COINS tokens) |
expectedIn | IAdapter.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. |
extraData | bytes | Extra 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.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. Should only contain the LP token to burn. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive (up to N_COINS tokens) |
extraData | bytes | ABI 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.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. Should only contain the LP token to burn. |
expectedIn | IAdapter.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.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. Should only contain the LP token to burn. |
expectedIn | IAdapter.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.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. Should only contain the LP token to burn. |
expectedIn | IAdapter.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).
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. Should contain only the token to exchange from. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. Should contain only the token to exchange to. |
extraData | bytes | Extra 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.
_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.
_approveOutTransfers
Private helper function used to approve token transfers to the Curve.fi 3Pool.
Called by the following functions:
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.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:
Parameters
Name | Type | Description |
---|---|---|
tokenAmounts | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to extract the respective amount values |
Returns
Name | Type | Description |
---|---|---|
amounts | uint256[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.
Returns
Name | Type | Description |
---|---|---|
poolTokens | address[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.
Parameters
Name | Type | Description |
---|---|---|
token | address | The address of the token for which the index needs to be found |
Returns
Name | Type | Description |
---|---|---|
<none> | int128 | The 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.
Parameters
Name | Type | Description |
---|---|---|
tokenAmounts | IAdapter.TokenAmount[] | Array of TokenAmount structs with the token compositions to search |
token | address | The address of the token for which the associated amount needs to be found within the tokenAmounts array |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | The 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.