MaverickV2LiquidityManager

Inherits: Checks, ExactOutputSlim, ArgPacker, IMaverickV2LiquidityManager

Maverick liquidity management contract that provides helper functions for minting either NFT liquidity positions or boosted positions which are fungible positions in a Maverick V2 pool. While this contract does have public payment callback functions, these are access controlled so that they can only be called by a factory pool; so it is safe to approve this contract to spend a caller's tokens. This contract inherits "Check" functions that can be multicalled with liquidity management functions to create slippage and deadline constraints on transactions.

This contract has a multicall interface and all public functions are payable which facilitates multicall combinations of both payable interactions and non-payable interactions.

addLiquidity parameters are specified as a lookup table of prices where the caller specifies packedSqrtPriceBreaks and packedArgs. During the add operation, this contract queries the pool for its current sqrtPrice and then looks up this price relative to the price breaks array (the array is packed as bytes using the conventions in the inherited ArgPacker contract to save calldata space). If the current pool sqrt price is in between the N and N+1 elements of the packedSqrtPriceBreaks array, then the add parameters from the Nth element of the packedArgs array are used in the add liquidity call.

This lookup table approach provides a flexible way for callers to manage price slippage between the time they submit their transaction and the time it is executed. The MaverickV2PoolLens contract provides a number of helper function to create this slippage lookup table.

State Variables

position

Maverick V2 NFT position contract that tracks NFT-based liquditiy positions.

IMaverickV2Position public immutable position;

boostedPositionFactory

Maverick V2 BP factory contract.

IMaverickV2BoostedPositionFactory public immutable boostedPositionFactory;

Functions

constructor

constructor(
    IMaverickV2Factory _factory,
    IWETH9 _weth,
    IMaverickV2Position _position,
    IMaverickV2BoostedPositionFactory _boostedPositionFactory
) State(_factory, _weth);

createPool

Create Maverick V2 pool. Function is a pass through to the pool factory and is provided here so that is can be assembled as part of a multicall transaction.

function createPool(
    uint64 fee,
    uint16 tickSpacing,
    uint32 lookback,
    IERC20 tokenA,
    IERC20 tokenB,
    int32 activeTick,
    uint8 kinds
) public payable returns (IMaverickV2Pool pool);

createPool

Create Maverick V2 pool. Function is a pass through to the pool factory and is provided here so that is can be assembled as part of a multicall transaction.

function createPool(
    uint64 feeAIn,
    uint64 feeBIn,
    uint16 tickSpacing,
    uint32 lookback,
    IERC20 tokenA,
    IERC20 tokenB,
    int32 activeTick,
    uint8 kinds
) public payable returns (IMaverickV2Pool pool);

addLiquidity

Add Liquidity to a Maverick V2 pool. Function is a pass through to the pool and is provided here so that is can be assembled as part of a multicall transaction. Users can add liquidity to the Position NFT contract or a BP as part of a multicall in order to mint NFT/BP positions.

Liquidity is specified as bytes that represent a lookup table of add parameters. This allows an adder to specify what liquidity amounts they wish to add conditional on the price of the pool when their transaction is executed. With this, users have fine-grain control of how price slippage affects the amount of liquidity they add. The MaverickV2PoolLens contract has helper view functions that can be used to easily create a combination of price breaks and packed arguments.

function addLiquidity(
    IMaverickV2Pool pool,
    address recipient,
    uint256 subaccount,
    bytes memory packedSqrtPriceBreaks,
    bytes[] memory packedArgs
) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds);

addPositionLiquidityToSenderByTokenIndex

Add Liquidity position NFT for msg.sender by specifying msg.sender's token index.

Token index is different from tokenId. On the Position NFT contract a user can own multiple NFT tokenIds and these are indexes by an enumeration index which is the index input here. See addLiquidity for a description of the add params.

function addPositionLiquidityToSenderByTokenIndex(
    IMaverickV2Pool pool,
    uint256 index,
    bytes memory packedSqrtPriceBreaks,
    bytes[] memory packedArgs
) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds);

addPositionLiquidityToRecipientByTokenIndex

Add Liquidity position NFT for msg.sender by specifying recipient's token index.

Token index is different from tokenId. On the Position NFT contract a user can own multiple NFT tokenIds and these are indexes by an enumeration index which is the index input here. See addLiquidity for a description of the add params.

function addPositionLiquidityToRecipientByTokenIndex(
    IMaverickV2Pool pool,
    address recipient,
    uint256 index,
    bytes memory packedSqrtPriceBreaks,
    bytes[] memory packedArgs
) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds);

mintPositionNft

Mint new tokenId in the Position NFT contract. Both mints an NFT and adds liquidity to the pool that is held by the NFT.

Caller must approve this LiquidityManager contract to spend the caller's token A/B in order to fund the liquidity position. See addLiquidity for a description of the add params.

function mintPositionNft(
    IMaverickV2Pool pool,
    address recipient,
    bytes memory packedSqrtPriceBreaks,
    bytes[] memory packedArgs
) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId);

mintPositionNftToSender

Mint new tokenId in the Position NFt contract to msg.sender. Both mints an NFT and adds liquidity to the pool that is held by the NFT.

function mintPositionNftToSender(IMaverickV2Pool pool, bytes memory packedSqrtPriceBreaks, bytes[] memory packedArgs)
    public
    payable
    returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId);

migrateBoostedPosition

Pass through function to the BP bin migration.

function migrateBoostedPosition(IMaverickV2BoostedPosition boostedPosition) public payable;

mintBoostedPosition

Mint BP LP tokens to recipient. This function does not add liquidity to the BP and is only useful in conjuction with addLiquidity as part of a multcall.

function mintBoostedPosition(IMaverickV2BoostedPosition boostedPosition, address recipient)
    public
    payable
    returns (uint256 mintedLpAmount);

addLiquidityAndMintBoostedPosition

Executes the multi-step process of minting BP LP positions by adding liqudiity to a pool in the BP liquidity distribution and then minting the BP to recipient.

Caller will need to approve this LiquidityManager contract to spend their token A/B in order to execute this function.

function addLiquidityAndMintBoostedPosition(
    address recipient,
    IMaverickV2BoostedPosition boostedPosition,
    bytes memory packedSqrtPriceBreaks,
    bytes[] memory packedArgs
) public payable virtual returns (uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount);

addLiquidityAndMintBoostedPositionToSender

Executes the multi-step process of minting BP LP positions by adding liquidity to a pool in the BP liquidity distribution and then minting the BP to msg.sender.

Caller will need to approve this LiquidityManager contract to spend their token A/B in order to execute this function.

function addLiquidityAndMintBoostedPositionToSender(
    IMaverickV2BoostedPosition boostedPosition,
    bytes memory packedSqrtPriceBreaks,
    bytes[] memory packedArgs
) public payable returns (uint256 mintedLpAmount, uint256 tokenAAmount, uint256 tokenBAmount);

createBoostedPositionAndAddLiquidityToSender

Deploy new BP contract from the BP factory and mint BP LP tokens to msg.sender.

Caller will need to approve this LiquidityManager contract to spend their token A/B in order to execute this function.

function createBoostedPositionAndAddLiquidityToSender(IMaverickV2PoolLens.CreateBoostedPositionInputs memory params)
    public
    payable
    returns (
        IMaverickV2BoostedPosition boostedPosition,
        uint256 mintedLpAmount,
        uint256 tokenAAmount,
        uint256 tokenBAmount
    );

createBoostedPositionAndAddLiquidity

Deploy new BP contract from the BP factory and mint BP LP tokens to the recipient.

Caller will need to approve this LiquidityManager contract to spend their token A/B in order to execute this function.

function createBoostedPositionAndAddLiquidity(
    address recipient,
    IMaverickV2PoolLens.CreateBoostedPositionInputs memory params
)
    public
    payable
    virtual
    returns (
        IMaverickV2BoostedPosition boostedPosition,
        uint256 mintedLpAmount,
        uint256 tokenAAmount,
        uint256 tokenBAmount
    );

donateLiquidity

Donates liquidity to a pool that is held by the position contract and will never be retrievable. Can be used to start a pool and ensure there will always be a base level of liquditiy in the pool.

function donateLiquidity(IMaverickV2Pool pool, IMaverickV2Pool.AddLiquidityParams memory args) public payable;

createPoolAtPriceAndAddLiquidityToSender

Creates a pool at a specified price and mints a Position NFT with liquidity to msg.sender.

function createPoolAtPriceAndAddLiquidityToSender(IMaverickV2PoolLens.CreateAndAddParamsInputs memory params)
    public
    payable
    returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId);

createPoolAtPriceAndAddLiquidity

Creates a pool at a specified price and mints a Position NFT with liquidity to the recipient.

A Maverick V2 pool has no native way to specify a starting price, only a starting activeTick. The initial pool price will be the left edge of the initial activeTick. In order to create a pool at a fixed price, this function dontes a small amount of liquidity to the pool, does a swap to the specified price, and then adds liquidity for the user.

function createPoolAtPriceAndAddLiquidity(address recipient, IMaverickV2PoolLens.CreateAndAddParamsInputs memory params)
    public
    payable
    returns (uint256 tokenAAmount, uint256 tokenBAmount, uint32[] memory binIds, uint256 tokenId);

removeLiquidityFromPositionNftAndSweepToSender

Remove liquidity from a Position NFT and send proceeds to msg.sender. This function will unwrap WETH to ETH before sending to user. A user can also remove liquidity using the Position contract if they do not need to unwrap WETH.

Caller will need to approve this LiquidityManager contract to access the caller's tokenId NFT.

function removeLiquidityFromPositionNftAndSweepToSender(
    uint256 tokenId,
    IMaverickV2Pool pool,
    IMaverickV2Pool.RemoveLiquidityParams memory params,
    uint256 tokenAAmountMin,
    uint256 tokenBAmountMin
) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount);

removeLiquidityFromBoostedPositionToSender

Burn a BP and send proceeds to msg.sender. This function will unwrap WETH to ETH before sending to user. A user can also burn their LP tokens using the BP contract if they do not need to unwrap WETH.

Caller will need to approve this LiquidityManager contract to access the caller's BP balance.

function removeLiquidityFromBoostedPositionToSender(
    IMaverickV2BoostedPosition boostedPosition,
    uint256 amount,
    uint256 tokenAAmountMin,
    uint256 tokenBAmountMin
) public payable returns (uint256 tokenAAmount, uint256 tokenBAmount);

maverickV2AddLiquidityCallback

function maverickV2AddLiquidityCallback(
    IERC20 tokenA,
    IERC20 tokenB,
    uint256 amountA,
    uint256 amountB,
    bytes calldata data
) public;

Last updated