Nexera-FiAdapters & DeFi ProtocolsMaverick

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:

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.


graph LR; style Nexera_Fi fill:#8453ed style Maverick fill:#5429f0; style Pools fill:#57deca; style PP fill:#3cc7a5; style Reward_Contracts fill:#68a6f2; subgraph Nexera_Fi A[<b> MaverickAdapter </b>] end subgraph Maverick C["<b>PoolPositionManager</b>"] B["<b>Router</b>"] subgraph PP G["<b>...</b>"] H["<b>PP Instance</b>"] I["<b>...</b>"] end subgraph Pools D["<b>...</b>"] E["<b>Pool Instance</b>"] F["<b>...</b>"] end subgraph Reward_Contracts J["<b>...</b>"] K["<b>Reward Instance</b>"] L["<b>...</b>"] end end A --> |<b>Deposit Op Actions</b>: <i>Create or Add Liquidity to existing Pools</i>| B A --> |<b>Withdraw Op Action</b>: <i>Remove Liquidity from Pools</i>| B A --> |<b>Swap Op Actions</b>: <i>Token Swaps against Pools</i>| B A --> |<b>Operate Op Action</b>: <i>Migrate bins within Pools</i>| B A --> |<b>refundETH</b>: <i>Refund excess ETH</i>| B A --> |<b>Deposit Op Actions</b>: <i>Create or Join Pool Positions</i>| C A --> |<b>Withdraw Op Action</b>: <i>Remove Liquidity from Pool Positions</i>| C A --> |"<b>Collect Op Actions</b>: <i>Collect reward token(s)</i>"| Reward_Contracts B -.- |"<b> Add/Remove Liquidity<b/>"| Pools B -.- |"<b>Token Swaps<b/>"| Pools C -.- |"<b> Add/Remove Liquidity<b/>"| PP

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:

  1. getOrCreatePoolAndAddLiquidity
  2. addLiquidityToPool
  3. addLiquidityWTickLimits
  4. removeLiquidity
  5. exactInputSingle
  6. exactOutputSingle
  7. exactInput
  8. exactOutput
  9. migrateBinsUpStack
  10. refundETH
  11. position

Methods

getOrCreatePoolAndAddLiquidity

Adds liquidity to an existing pool or creates a new pool and adds liquidity to it.

function getOrCreatePoolAndAddLiquidity(
  PoolParams calldata poolParams,
  uint256 tokenId,
  IPool.AddLiquidityParams[] calldata addParams,
  uint256 minTokenAAmount,
  uint256 minTokenBAmount,
  uint256 deadline
) external
  payable
  returns (
    uint256 receivingTokenId,
    uint256 tokenAAmount,
    uint256 tokenBAmount,
    IPool.BinDelta[] memory binDeltas
  );

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.

function addLiquidityToPool(
  IPool pool,
  uint256 tokenId,
  IPool.AddLiquidityParams[] calldata params,
  uint256 minTokenAAmount,
  uint256 minTokenBAmount,
  uint256 deadline
) external
  payable
  returns (
    uint256 receivingTokenId,
    uint256 tokenAAmount,
    uint256 tokenBAmount,
    IPool.BinDelta[] memory binDeltas
  );

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.

function addLiquidityWTickLimits(
  IPool pool,
  uint256 tokenId,
  IPool.AddLiquidityParams[] calldata params,
  uint256 minTokenAAmount,
  uint256 minTokenBAmount,
  int32 minActiveTick,
  int32 maxActiveTick,
  uint256 deadline
) external
  payable
  returns (
    uint256 receivingTokenId,
    uint256 tokenAAmount,
    uint256 tokenBAmount,
    IPool.BinDelta[] memory binDeltas
  );

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).

function removeLiquidity(
  IPool pool,
  address recipient,
  uint256 tokenId,
  IPool.RemoveLiquidityParams[] calldata params,
  uint256 minTokenAAmount,
  uint256 minTokenBAmount,
  uint256 deadline
) external
  returns (
    uint256 tokenAAmount,
    uint256 tokenBAmount,
    IPool.BinDelta[] memory binDeltas
  );

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.

struct ExactInputSingleParams {
  address tokenIn;
  address tokenOut;
  IPool pool;
  address recipient;
  uint256 deadline;
  uint256 amountIn;
  uint256 amountOutMinimum;
  uint256 sqrtPriceLimitD18;
}
    
 
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);

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.

struct ExactOutputSingleParams {
  address tokenIn;
  address tokenOut;
  IPool pool;
  address recipient;
  uint256 deadline;
  uint256 amountOut;
  uint256 amountInMaximum;
}
 
 
function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);

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.

struct ExactInputParams {
  bytes path;
  address recipient;
  uint256 deadline;
  uint256 amountIn;
  uint256 amountOutMinimum;
}
 
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);

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.

struct ExactOutputParams {
  bytes path;
  address recipient;
  uint256 deadline;
  uint256 amountOut;
  uint256 amountInMaximum;
}
 
function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);

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.

function migrateBinsUpStack(
  IPool pool,
  uint128[] calldata binIds,
  uint32 maxRecursion,
  uint256 deadline
) external;

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.

function refundETH() external payable;

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.

function position() external view returns (IPosition);

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:

  1. createPoolPositionAndAddLiquidity
  2. addLiquidityToPoolPositionWithAddParams
  3. addLiquidityToPoolPosition
  4. removeLiquidityFromPoolPosition

Methods

createPoolPositionAndAddLiquidity

Creates a new pool position (PP) and adds liquidity to it.

struct CreateLimits {
  uint256 minTokenAAmount;
  uint256 minTokenBAmount;
  uint256 deadline;
  bool stakeInReward;
}
 
function createPoolPositionAndAddLiquidity(
  IPool pool,
  address recipient,
  IPool.AddLiquidityParams[] calldata params,
  bool isStatic,
  CreateLimits calldata createLimits
) external
  payable
  returns (
    IPoolPositionSlim poolPosition,
    uint256 tokenAAmount,
    uint256 tokenBAmount,
    IPool.BinDelta[] memory binDeltas,
    uint256 mintedPoolPositionTokenAmount
  );

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.

struct AddLimits {
  uint256 maxTokenAAmount;
  uint256 maxTokenBAmount;
  uint256 deadline;
  bool stakeInReward;
}
 
function addLiquidityToPoolPositionWithAddParams(
  IPoolPositionSlim poolPosition,
  address recipient,
  uint256 minLpTokenAmount,
  AddLimits calldata addLimits,
  IPool.AddLiquidityParams[] memory addParams,
  uint256 bin0LpAmount
) external payable returns (uint256 mintedPoolPositionTokenAmount, uint256 tokenAAmount, uint256 tokenBAmount);

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).

struct AddLimits {
  uint256 maxTokenAAmount;
  uint256 maxTokenBAmount;
  uint256 deadline;
  bool stakeInReward;
}
 
function addLiquidityToPoolPosition(
  IPoolPositionSlim poolPosition,
  address recipient,
  uint256 desiredLpTokenAmount,
  uint256 minLpTokenAmount,
  AddLimits calldata addLimits
) external payable returns (uint256 mintedPoolPositionTokenAmount, uint256 tokenAAmount, uint256 tokenBAmount);

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).

function removeLiquidityFromPoolPosition(
  IPoolPositionSlim poolPosition,
  address recipient,
  uint256 lpTokenAmount,
  uint256 minTokenAAmount,
  uint256 minTokenBAmount,
  uint256 deadline
) external payable returns (uint256 tokenAAmount, uint256 tokenBAmount);

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:

function getReward(address recipient, uint8 rewardTokenIndex) external returns (uint256);

For multiple reward tokens:

function getReward(address recipient, uint8[] calldata rewardTokenIndices) external;

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.