MaverickAdapter
Extends: BaseAdapter
The MaverickAdapter
is designed to interact with the Maverick Protocol.
This adapter enables users to harness the power of Maverick's AMM features and integrate them into their financial strategies.
Custom Errors
WRONG_OPERATION
Raised when an invalid operation is requested.
WRONG_ADDRESS
Raised when an invalid address is provided.
WRONG_LENGTH
Raised when array input arguments do not match the expected length required for the respective operation.
WRONG_AMOUNT
Raised when the amount specified in input or output token compositions is wrong with respect to the requested operation.
This can include situations where the amount is either 0 or exceeds MAX_UINT128 value.
Enums
DepositOperation
Defines the actions available with respect to Deposit Operation:
GET_OR_CREATE_POOL_AND_ADD_LIQUIDITY
: Add liquidity to an existing pool or create a new pool & add liquidity to itADD_LIQUIDITY_TO_POOL
: Add liquidity to an existing poolADD_LIQUIDITY_WITH_TICK_LIMITS
: Add liquidity to an existing pool with active tick limitsCREATE_POOL_POSITION_AND_ADD_LIQUIDITY
: Create a new pool position (PP) and add liquidity to itADD_LIQUIDITY_TO_POOL_POSITION_WITH_ADD_PARAMS
: Add liquidity to an existing pool position (PP) with values computed offchainADD_LIQUIDITY_TO_POOL_POSITION
: Add liquidity to an existing pool position (PP)
WithdrawOperation
Defines the actions available with respect to Withdraw Operation:
REMOVE_LIQUIDITY
: Remove liquidity from a pool and receive WETH if one of the tokens is WETHREMOVE_LIQUIDITY_FROM_POOL_POSITION
: Remove liquidity from a pool position (PP)
SwapOperation
Defines the actions available with respect to Swap Operation:
EXACT_INPUT
: Perform a multi-hop swap along a specified path, exchanging a designated amount of one token into the maximum possible amount of another tokenEXACT_OUTPUT
: Perform a reverse multi-hop swap along a specified path, exchanging the smallest possible quantity of one token for a designated amount of another tokenEXACT_INPUT_SINGLE
: Swap a designated amount of one token for the maximum possible amount of another tokenEXACT_OUTPUT_SINGLE
: Swap as little as possible of one token for a designated amount of another token
Structs
DepositExtraData
Used to indicate the appropriate action of a Deposit Operation.
Members
Name | Type | Description |
---|---|---|
depositOperation | DepositOperation | The action to conduct |
extraDepositData | GeneralDepositData | Extra data required for the action |
GeneralDepositData
Defines the necessary data required for performing deposit-wise actions such as:
- Creating a pool and adding liquidity
- Adding liquidity to a pool
- Creating a pool position and adding liqudity
- Adding liquidity to an existing pool position
Members
Name | Type | Description |
---|---|---|
tokenAAmount | uint256 | The amount of tokenA to add as liquidity |
tokenBAmount | uint256 | The amount of tokenB to add as liquidity |
deadline | uint256 | The deadline epoch timestamp (in seconds) until which the action can be executed |
operationData | bytes | Additional ABI encoded data related to the operation ( a , b , c , d , e , f ) |
GetOrCreatePoolAndAddLiquidityData
Defines the necessary data for invoking the getOrCreatePoolAndAddLiquidity()
function of the Router contract, used for interacting with Maverick's AMM Pools. It encapsulates the necessary data for creating a new pool or adding liquidity to an existing one.
Note: This structure serves as the non-encoded operation data within the broader GeneralDepositData struct.
Members
Name | Type | Description |
---|---|---|
tokenId | uint256 | The ID of NFT LP token that holds the lp balance. Use 0 to mint a new LP token. |
poolParams | IRouter.PoolParams | Parameters defining the properties and characteristics of the pool, such as fees and associated tokens |
addParams | IPool.AddLiquidityParams[] | Parameters of liquidity addition |
AddLiquidityToPoolData
Defines the necessary data for invoking the addLiquidityToPool()
function of the Router contract, used for interacting with Maverick's AMM Pools. It encapsulates the necessary data for adding liquidity to a specific pool.
Note: This structure serves as the non-encoded operation data within the broader GeneralDepositData struct.
Members
Name | Type | Description |
---|---|---|
tokenId | uint256 | The ID of NFT LP token that holds the lp balance. Use 0 to mint a new LP token. |
pool | IPool | The pool to which liquidity will be added |
addParams | IPool.AddLiquidityParams[] | Parameters for each bin that will get new liquidity |
AddLiquidityWithTickLimitsData
Defines the necessary data for invoking the addLiquidityWTickLimits()
function of the Router contract, used for interacting with Maverick's AMM Pools. It encapsulates the necessary data for adding liquidity to a specific pool with active tick limits.
Note: This structure serves as the non-encoded operation data within the broader GeneralDepositData struct.
Members
Name | Type | Description |
---|---|---|
tokenId | uint256 | The ID of NFT LP token that holds the lp balance. Use 0 to mint a new LP token. |
pool | IPool | The pool to which liquidity will be added |
minActiveTick | int32 | Lowest activeTick (inclusive) of the pool that will permit the transaction |
maxActiveTick | int32 | Highest activeTick (inclusive) of the pool that will permit the transaction |
addParams | IPool.AddLiquidityParams[] | Parameters for each bin that will get new liquidity |
CreatePoolPositionAndAddLiquidityData
Defines the necessary data for invoking the createPoolPositionAndAddLiquidity()
function of the PoolPositionManager contract. It encapsulates the necessary data for creating a pool position and adding liquidity to it.
Note: This structure serves as the non-encoded operation data within the broader GeneralDepositData struct.
Members
Name | Type | Description |
---|---|---|
pool | IPool | Pool factory used to create position |
isStatic | bool | True if all bins in the Pool Position (PP) are static, false otherwise |
stakeInReward | bool | True to stake new pool position in reward contract, false otherwise |
addParams | IPool.AddLiquidityParams[] | Parameters of liquidity addition |
AddLiquidityToPoolPositionWithAddParamsData
Defines the necessary data for invoking the addLiquidityToPoolPositionWithAddParams()
function of the PoolPositionManager contract. It encapsulates the necessary data for adding liquidity to an existing pool position with values computed offchain.
Note: This structure serves as the non-encoded operation data within the broader GeneralDepositData struct.
Members
Name | Type | Description |
---|---|---|
poolPositionContract | IPoolPositionSlim | The Pool Position (PP) to which liquidity will be added |
minLpTokenAmount | uint256 | The miniumum accepted amount of ERC-20 PP LP tokens to mint |
stakeInReward | bool | True to stake pool position in reward contract, false otherwise |
bin0LpAmount | uint256 | The bin0 LP amount used for minting. Amount minted is the minimum of bin0LpAmount and the amount added to bin zero |
addParams | IPool.AddLiquidityParams[] | Parameters of liquidity addition |
AddLiquidityToPoolPositionData
Defines the necessary data for invoking the addLiquidityToPoolPosition()
function of the PoolPositionManager contract. It encapsulates the necessary data for adding liquidity to an existing pool position.
Note: This structure serves as the non-encoded operation data within the broader GeneralDepositData struct.
Members
Name | Type | Description |
---|---|---|
poolPositionContract | IPoolPositionSlim | The Pool Position (PP) to which liquidity will be added |
desiredLpTokenAmount | uint256 | The target amount of ERC-20 PP LP tokens to mint |
minLpTokenAmount | uint256 | The miniumum accepted amount of ERC-20 PP LP tokens to mint |
stakeInReward | bool | True to stake pool position in reward contract, false otherwise |
WithdrawExtraData
Used to indicate the appropriate action of a Withdraw Operation.
Members
Name | Type | Description |
---|---|---|
withdrawOperation | WithdrawOperation | The action to conduct |
extraWithdrawData | GeneralWithdrawData | Extra data required for the action |
GeneralWithdrawData
Defines the necessary data required for performing withdrawal-wise actions such as:
- Decreasing liquidity from a pool
- Decreasing liquidity from a pool position
Members
Name | Type | Description |
---|---|---|
deadline | uint256 | The deadline epoch timestamp (in seconds) until which the action can be executed |
operationData | bytes | Additional ABI encoded data related to the operation ( a ) |
RemoveLiquidityData
Defines the necessary data for invoking the removeLiquidity()
function of the Router contract, used for interacting with Maverick's AMM Pools. It encapsulates the necessary data for removing liquidity from a specific pool.
Note: This structure serves as the non-encoded operation data within the broader GeneralWithdrawData struct.
Members
Name | Type | Description |
---|---|---|
pool | address | The address of the target pool to remove liquidity from |
tokenId | uint256 | The ID of position NFT that holds liquidity |
binIds | uint128[] | Array with the target bin IDs |
SwapExtraData
Used to indicate the appropriate action of a Swap Operation.
Members
Name | Type | Description |
---|---|---|
swapOperation | SwapOperation | The action to conduct |
extraSwapData | GeneralSwapData | Extra data required for the action |
GeneralSwapData
Defines the necessary data required for performing swap-wise actions such as:
- exactInputSingle
- exactOutputSingle
- exactInput
Members
Name | Type | Description |
---|---|---|
deadline | uint256 | The deadline epoch timestamp (in seconds) until which the swap can be executed |
operationData | bytes | Additional ABI encoded data related to the operation ( a , b , c ) |
ExactInputSingleData
Defines the necessary data for invoking the exactInputSingle()
function of the Router contract, used for interacting with Maverick's AMM Pools. It encapsulates the necessary data for performing the exactInputSingle swap.
Note: This structure serves as the non-encoded operation data within the broader GeneralSwapData struct.
Members
Name | Type | Description |
---|---|---|
pool | IPool | The target pool to perform the swap against |
sqrtPriceLimitD18 | uint256 | The square root of the price limit for the swap, represented with 18 decimal places |
ExactOutputSingleData
Defines the necessary data for invoking the exactOutputSingle()
function of the Router contract, used for interacting with Maverick's AMM Pools. It encapsulates the necessary data for performing the exactOutputSingle swap.
Note: This structure serves as the non-encoded operation data within the broader GeneralSwapData struct.
Members
Name | Type | Description |
---|---|---|
pool | IPool | The target pool to perform the swap against |
ExactData
Defines the necessary data for invoking the exactInput()
and exactOutput()
functions of the Router contract, used for interacting with Maverick's AMM Pools. It encapsulates the necessary data for performing multi-hop path-specific swaps.
Note: This structure serves as the non-encoded operation data within the broader GeneralSwapData struct.
Members
Name | Type | Description |
---|---|---|
path | bytes | A bytes string representing the path of tokens to swap |
OperateExtraData
Defines the necessary data for invoking the migrateBinsUpstack()
function of the Router contract, used for interacting with Maverick's AMM Pools.
Members
Name | Type | Description |
---|---|---|
pool | IPool | The taget pool |
binIds | uint128[] | Array of bin IDs to migrate |
maxRecursion | uint32 | Maximum recursion depth before returning, 0 indicates no limit |
deadline | uint256 | The deadline epoch timestamp (in seconds) until which the migration can be executed |
CollectExtraData
Defines the necessary data for invoking the overloaded getReward()
function of a Reward contract.
Members
Name | Type | Description |
---|---|---|
rewardContract | IReward | The target Reward contract from which rewards will be collected |
rewardTokenIndices | uint8[] | Array with the indices of reward tokens to collect. If the array is a singleton, then the single one is invoked, otherwise the multiple one is invoked. |
Layout
Used to store crucial data for the Adapter's functionality in a specific storage slot.
Members
Name | Type | Description |
---|---|---|
router | IRouter | The interface representing the Router contract instance |
poolPositionManager | IPoolPositionManager | The interface representing the PoolPositionManager contract instance |
nativeToken | address | The address of the wrapped native token address |
State Variables
MAX_UINT128
Defines the maximum amount for adding/removing liquidity in Maverick's AMMs.
STORAGE_SLOT
Unique identifier for the storage slot where the Layout struct is stored.
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.MaverickAdapter
string literal - The address of this contract (MaverickAdapter)
Functions
initialize
Initializes the Adapter.
Parameters
Name | Type | Description |
---|---|---|
initData_ | bytes | The ABI encoded Layout data |
_deposit
Internal function for handling Deposit Operations.
This function is responsible for adding liquidity into Maverick protocol.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive (LP tokens). To guarantee that a minimum quantity of LP tokens is received, the LP token address and the desired minimum amount should be included in this parameter. Subsequently, this information will be verified by the BaseAdapter. |
extraData | bytes | ABI encoded data of type DepositExtraData indicating the action. All data needed for the deposit operations are included in this parameter. |
_withdraw
Internal function for handling Withdraw Operations.
This function is responsible for removing liquidity from Maverick protocol.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (LP tokens) |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive (tokenA & tokenB). The length of the array must equal to 2, else the function raises a WRONG_LENGTH error. In this array : - expectedIn[0] should include the address and minimum amount for tokenA - expectedIn[1] should include the address and minimum amount for tokenB |
extraData | bytes | ABI encoded data of type WithdrawExtraData indicating the action |
_swap
Internal function for handling Swap Operations.
This function facilitates the swapping of assets into the Maverick protocol.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. The length of the array must equal to 1, else the function raises a WRONG_LENGTH error. For exactInput and exactInputSingle actions, it should contain the amount to be provided. For exactOutput and exactOutputSingle actions, it should contain the maximum amount to be provided. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. The length of the array must equal to 1, else the function raises a WRONG_LENGTH error. For exactInput and exactInputSingle actions, it should contain the minimum amount to be received. For exactOutput and exactOutputSingle actions, it should contain the specific amount to be received. |
extraData | bytes | ABI encoded data of type SwapExtraData indicating the action |
_operate
Internal function for handling Operate Operations.
This function is used for migrating bins within the Maverick Protocol.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
<none> | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. Not used in this context. |
<none> | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. Not used in this context. |
extraData | bytes | ABI encoded data of type OperateExtraData |
_collect
Internal function for handling Collect Operations.
This function is employed to retrieve rewards from Reward contracts associated with boosted positions.
Called by executeAction function.
Parameters
Name | Type | Description |
---|---|---|
<none> | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. Not used in this context. |
<none> | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. Not used in this context. |
extraData | bytes | ABI encoded data of type CollectExtraData |
_getOrCreatePoolAndAddLiquidity
Adds liquidity to an existing pool or creates a new pool and adds liquidity to it.
Called by _deposit function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (tokenA & tokenB) |
data | GeneralDepositData | Operation data required for the action |
_addLiquidityToPool
Adds liquidity to an existing pool.
Called by _deposit function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (tokenA & tokenB) |
data | GeneralDepositData | Operation data required for the action |
_addLiquidityWTickLimits
Adds liquidity to an existing pool with active tick limits.
Called by _deposit function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (tokenA & tokenB) |
data | GeneralDepositData | Operation data required for the action |
_createPoolPositionAndAddLiquidity
Creates a new pool position and adds liquidity to it.
Called by _deposit function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (tokenA & tokenB) |
data | GeneralDepositData | Operation data required for the action |
_addLiquidityToPoolPositionWithAddParams
Adds liquidity to an existing pool position with values computed offchain.
Called by _deposit function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (tokenA & tokenB) |
data | GeneralDepositData | Operation data required for the action |
_addLiquidityToPoolPosition
Adds liquidity to an existing pool position.
Called by _deposit function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (tokenA & tokenB) |
data | GeneralDepositData | Operation data required for the action |
_removeLiquidity
Removes liquidity from a pool and receives WETH if one of the tokens (tokenA or tokenB) is WETH.
Called by _withdraw function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (LP tokens to burn) |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected minimum amount of token compositions (tokenA & tokenB) to receive |
data | GeneralWithdrawData | Operation data required for the action |
_removeLiquidityFromPoolPosition
Removes liquidity from a Pool Position (PP).
Called by _withdraw function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send (PP LP token to burn) |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive (tokenA & tokenB) |
data | GeneralWithdrawData | Operation data required for the action |
_swapExactInputSingle
Swaps a designated amount of one token for the maximum possible amount of another token.
Called by _swap function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. The length of the array must equal to 1 and contain the address and the exact amount to be exchanged. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. The length of the array must equal to 1 and contain the address and the minimum expected amount to be received. |
data | GeneralSwapData | Operation data required for the action |
_swapExactOutputSingle
Swaps as little as possible of one token for a designated amount of another token.
Called by _swap function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. The length of the array must equal to 1 and contain the address and the maximum amount to be exchanged. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. The length of the array must equal to 1 and contain the address and the exact amount to be received. |
data | GeneralSwapData | Operation data required for the action |
_swapExactInput
Performs a multi-hop swap along a specified path, exchanging a designated amount of one token into the maximum possible amount of another token.
Called by _swap function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. The length of the array must equal to 1 and contain the address and the exact amount to be exchanged. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. The length of the array must equal to 1 and contain the address and the minimum amount to be received. |
data | GeneralSwapData | Operation data required for the action |
_swapExactOutput
Performs a reverse multi-hop swap along a specified path, exchanging the smallest possible quantity of one token for a designated amount of another token.
Called by _swap function.
Parameters
Name | Type | Description |
---|---|---|
out | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the token compositions to send. The length of the array must equal to 1 and contain the address and the maximum amount to be exchanged. |
expectedIn | IAdapter.TokenAmount[] | Array of TokenAmount structs defining the expected token compositions to receive. The length of the array must equal to 1 and contain the address and the exact amount to be received. |
data | GeneralSwapData | Operation data required for the action |
_checkAndApprove
Internal helper function responsible for checking and setting allowances for token transfers to a designated receiver.
Called by the following functions:
- _getOrCreatePoolAndAddLiquidity
- _addLiquidityToPool
- _addLiquidityWTickLimits
- _createPoolPositionAndAddLiquidity
- _addLiquidityToPoolPositionWithAddParams
- _addLiquidityToPoolPosition
- _removeLiquidityFromPoolPosition
- _swapExactInputSingle
- _swapExactOutputSingle
- _swapExactInput
- _swapExactOutput
Parameters
Name | Type | Description |
---|---|---|
token | address | The address of the token for which the allowance is being set. |
receiver | address | The address of the receiver to whom the allowance is granted. |
layout
Retrieves a reference to the Layout struct stored at a specified storage slot.