Maverick Protocol
Overview
Maverick Protocol is an influential force in the DeFi sector, offering a robust framework to elevate operational efficiency. At its core, the protocol employs a Dynamic Distribution Automated Market Maker (AMM), to empower users in maximizing their capital and creating a more streamlined and effective financial landscape.
The Nexera-Fi MaverickAdapter interacts with and utilizes the following three key components of Maverick:
- Router contract
- PoolPositionManager contract
- Reward contracts
In the following sections, we'll provide an overview of these contracts and their methods that Nexera-Fi MaverickAdapter interacts with.
Interactions with MaverickAdapter
The MaverickAdapter interacts with Maverick protocol by calling the methods presented in the diagram below. Each method serves a specific purpose within the Adapter, enabling strategies to seamlessly integrate liquidity provision, liquidity withdrawal, and token swaps in Maverick's AMM ecosystem.
Router
The Router contract is a core component of the Maverick protocol. Through its interface, users can interact with Maverick's AMM that supports token swaps for traders and liquidity provision for LPs.
In the context of the Nexera-Fi MaverickAdapter, these eleven methods come into play:
getOrCreatePoolAndAddLiquidity
addLiquidityToPool
addLiquidityWTickLimits
removeLiquidity
exactInputSingle
exactOutputSingle
exactInput
exactOutput
migrateBinsUpStack
refundETH
position
Methods
getOrCreatePoolAndAddLiquidity
Adds liquidity to an existing pool or creates a new pool and adds liquidity to it.
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the Router's getOrCreatePoolAndAddLiquidity
method.
It is triggered within the context of the Adapter's _deposit function when DepositOperation is configured as GET_OR_CREATE_POOL_AND_ADD_LIQUIDITY.
Its purpose encompasses both the creation of new pools and the addition of liquidity to existing ones.
This execution condition is contingent on the GeneralDepositData containing the encoded GetOrCreatePoolAndAddLiquidityData struct.
addLiquidityToPool
Adds liquidity to an existing pool.
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the Router's addLiquidityToPool
method.
It is triggered within the context of the Adapter's _deposit function when DepositOperation is configured as ADD_LIQUIDITY_TO_POOL.
This execution condition is based on the GeneralDepositData containing the encoded AddLiquidityToPoolData struct.
addLiquidityWTickLimits
Adds liquidity to an existing pool with active tick limits.
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the Router's addLiquidityWTickLimits
method.
It is triggered within the context of the Adapter's _deposit function when DepositOperation is configured as ADD_LIQUIDITY_WITH_TICK_LIMITS.
This execution condition is based on the GeneralDepositData containing the encoded AddLiquidityWithTickLimitsData struct.
removeLiquidity
Removes liquidity from a pool (receive WETH if one of the tokens is WETH).
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the Router's removeLiquidity
method.
It is triggered within the context of the Adapter's _withdraw function when WithdrawOperation is configured as REMOVE_LIQUIDITY.
This execution condition is based on the GeneralWithdrawData containing the encoded RemoveLiquidityData struct.
exactInputSingle
Swaps a designated amount of one token for the maximum possible amount of another token.
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the Router's exactInputSingle
method.
It is triggered within the context of the Adapter's _swap function when SwapOperation is configured as EXACT_INPUT_SINGLE.
This execution condition is based on the GeneralSwapData containing the encoded ExactInputSingleData struct.
exactOutputSingle
Swaps as little as possible of one token for a designated amount of another token.
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the Router's exactOutputSingle
method.
It is triggered within the context of the Adapter's _swap function when SwapOperation is configured as EXACT_OUTPUT_SINGLE.
This execution condition is based on the GeneralSwapData containing the encoded ExactOutputSingleData struct.
exactInput
Performs a multi-hop swap along a specified path, exchanging a designated amount of one token into the maximum possible amount of another token.
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the Router's exactInput
method.
It is triggered within the context of the Adapter's _swap function when SwapOperation is configured as EXACT_INPUT.
This execution condition is based on the GeneralSwapData containing the encoded ExactData struct.
exactOutput
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.
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the Router's exactOutput
method.
It is triggered within the context of the Adapter's _swap function when SwapOperation is configured as EXACT_OUTPUT.
This execution condition is based on the GeneralSwapData containing the encoded ExactData struct.
migrateBinsUpStack
Moves the head of input merged bins to the active bin.
This method is invoked by the following MaverickAdapter function:
This function triggers the execution of the Router's migrateBinsUpStack
method.
The execution configuration is determined by the contents of the OperateExtraData, which is encoded and provided as an argument to the extraData
parameter of the _operate
function.
refundETH
Refunds excess ETH (if any) held by the Router contract after increasing/decreasing liquidity and swap actions.
This method is invoked by the following MaverickAdapter functions:
In both the _swap
and _deposit
functions of the Adapter, the refundETH
method provided by the Router is invoked to ensure that any excess ETH sent during the transaction is returned to the Adapter.
This is a safety measure to prevent the loss of native currency in case it's not fully utilized during the operation.
position
Returns the address of the Position NFT.
This method is invoked by the following MaverickAdapter function:
The Router's position
method is employed within this function to approve the Router contract for the specified tokenId Position NFT.
This approval is essential to permit the Router to manage and process the withdrawal of assets associated with the NFT.
PoolPositionManager
The PoolPositionManager contract is a vital component of Maverick protocol. Through its interface, users can create, manage and join Pool Positions (PPs) where each PP represents a distribution of liquidity within the associated pool.
In the context of the Nexera-Fi MaverickAdapter, these four methods come into play:
createPoolPositionAndAddLiquidity
addLiquidityToPoolPositionWithAddParams
addLiquidityToPoolPosition
removeLiquidityFromPoolPosition
Methods
createPoolPositionAndAddLiquidity
Creates a new pool position (PP) and adds liquidity to it.
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the PoolPositionManager's createPoolPositionAndAddLiquidity
method.
It is triggered within the context of the Adapter's _deposit function when DepositOperation is configured as CREATE_POOL_POSITION_AND_ADD_LIQUIDITY.
This execution condition is based on the GeneralDepositData containing the encoded CreatePoolPositionAndAddLiquidityData struct.
addLiquidityToPoolPositionWithAddParams
Adds liquidity to an existing pool position (PP) with values computed offchain.
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the PoolPositionManager's addLiquidityToPoolPositionWithAddParams
method.
It is triggered within the context of the Adapter's _deposit function when DepositOperation is configured as ADD_LIQUIDITY_TO_POOL_POSITION_WITH_ADD_PARAMS.
This execution condition is based on the GeneralDepositData containing the encoded AddLiquidityToPoolPositionWithAddParamsData struct.
addLiquidityToPoolPosition
Adds liquidity to an existing pool position (PP).
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the PoolPositionManager's addLiquidityToPoolPosition
method.
It is triggered within the context of the Adapter's _deposit function when DepositOperation is configured as ADD_LIQUIDITY_TO_POOL_POSITION.
This execution condition is based on the GeneralDepositData containing the encoded AddLiquidityToPoolPositionData struct.
removeLiquidityFromPoolPosition
Removes liquidity from a pool position (PP).
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the PoolPositionManager's addLiquidityToPoolPosition
method.
It is triggered within the context of the Adapter's _withdraw function when WithdrawOperation is configured as REMOVE_LIQUIDITY_FROM_POOL_POSITION.
The decision and configuration of the execution is solely determined by the presence of GeneralWithdrawData, as there is no specific operation data associated with removeLiquidityFromPoolPosition
.
Reward
The Reward contract instances in Maverick protocol incentivize and reward participants for their contributions to the ecosystem. Each "Boosted" Position has its own Reward contract.
In the context of the Nexera-Fi MaverickAdapter, the following method comes into play:
Methods
getReward
Used for collecting rewards associated with provided liquidity.
Overloaded for targeting either a single reward token or multiple reward tokens.
For single reward token:
For multiple reward tokens:
This method is invoked by the following MaverickAdapter function:
This function initiates the execution of the Router's getReward
method.
The execution configuration is determined by the contents of the CollectExtraData, which is encoded and provided as an argument to the extraData
parameter of the _collect
function.
Please note: For detailed information about Maverick protocol, consult the official Maverick documentation.