IMaverickV2PoolLens

Functions

getAddLiquidityParams

Converts add parameter slippage specification into add parameters. The return values are given in both raw format and as packed values that can be used in the LiquidityManager contract.

function getAddLiquidityParams(AddParamsViewInputs memory params)
    external
    view
    returns (
        bytes memory packedSqrtPriceBreaks,
        bytes[] memory packedArgs,
        uint88[] memory sqrtPriceBreaks,
        IMaverickV2Pool.AddLiquidityParams[] memory addParams,
        IMaverickV2PoolLens.TickDeltas[] memory tickDeltas
    );

getAddLiquidityParamsForBoostedPosition

Converts add parameter slippage specification for a boosted position into add parameters. The return values are given in both raw format and as packed values that can be used in the LiquidityManager contract.

function getAddLiquidityParamsForBoostedPosition(
    IMaverickV2BoostedPosition boostedPosition,
    AddParamsSpecification memory addSpec
)
    external
    view
    returns (
        bytes memory packedSqrtPriceBreaks,
        bytes[] memory packedArgs,
        uint88[] memory sqrtPriceBreaks,
        IMaverickV2Pool.AddLiquidityParams[] memory addParams,
        IMaverickV2PoolLens.TickDeltas[] memory tickDeltas
    );

getCreateBoostedPositionParams

Converts add parameter slippage specification and boosted position specification into add parameters. The return values are given in both raw format and as packed values that can be used in the LiquidityManager contract.

function getCreateBoostedPositionParams(
    BoostedPositionSpecification memory bpSpec,
    AddParamsSpecification memory addSpec
)
    external
    view
    returns (
        bytes memory packedSqrtPriceBreaks,
        bytes[] memory packedArgs,
        uint88[] memory sqrtPriceBreaks,
        IMaverickV2Pool.AddLiquidityParams[] memory addParams,
        IMaverickV2PoolLens.TickDeltas[] memory tickDeltas
    );

getCreatePoolAtPriceAndAddLiquidityParams

Converts add parameter slippage specification and new pool specification into CreateAndAddParamsInputs parameters that can be used in the LiquidityManager contract.

function getCreatePoolAtPriceAndAddLiquidityParams(
    CreateAndAddParamsViewInputs memory params,
    IMaverickV2Factory factory
) external view returns (CreateAndAddParamsInputs memory output);

getTicksAroundActive

View function that provides information about pool ticks within a tick radius from the activeTick.

function getTicksAroundActive(IMaverickV2Pool pool, int32 tickRadius)
    external
    view
    returns (int32[] memory ticks, IMaverickV2Pool.TickState[] memory tickStates);

getTicks

View function that provides information about pool ticks within a range.

function getTicks(IMaverickV2Pool pool, int32 tickStart, int32 tickEnd)
    external
    view
    returns (int32[] memory ticks, IMaverickV2Pool.TickState[] memory tickStates);

getFullPoolState

View function that provides pool state information.

function getFullPoolState(IMaverickV2Pool pool, uint32 binStart, uint32 binEnd)
    external
    view
    returns (PoolState memory poolState);

getTickSqrtPriceAndL

View function that provides price and liquidity of a given tick.

function getTickSqrtPriceAndL(IMaverickV2Pool pool, int32 tick)
    external
    view
    returns (uint256 sqrtPrice, uint256 liquidity);

getPoolSqrtPrice

Pool sqrt price.

function getPoolSqrtPrice(IMaverickV2Pool pool) external view returns (uint256 sqrtPrice);

getPoolPrice

Pool price.

function getPoolPrice(IMaverickV2Pool pool) external view returns (uint256 price);

tokenScales

Token scale of two tokens in a pool.

function tokenScales(IMaverickV2Pool pool) external view returns (uint256 tokenAScale, uint256 tokenBScale);

Errors

LensTargetPriceOutOfBounds

error LensTargetPriceOutOfBounds(uint256 targetSqrtPrice, uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice);

LensTooLittleLiquidity

error LensTooLittleLiquidity(uint256 relativeLiquidityAmount, uint256 deltaA, uint256 deltaB);

LensTargetingTokenWithNoDelta

error LensTargetingTokenWithNoDelta(bool targetIsA, uint256 deltaA, uint256 deltaB);

Structs

AddParamsViewInputs

Add liquidity slippage parameters for a distribution of liquidity.

struct AddParamsViewInputs {
    IMaverickV2Pool pool;
    uint8 kind;
    int32[] ticks;
    uint128[] relativeLiquidityAmounts;
    AddParamsSpecification addSpec;
}

Properties

Name
Type
Description

pool

IMaverickV2Pool

Pool where liquidity is being added.

kind

uint8

Bin kind; all bins must have the same kind in a given call to addLiquidity.

ticks

int32[]

Array of tick values to add liquidity to.

relativeLiquidityAmounts

uint128[]

Relative liquidity amounts for the specified ticks. Liquidity in this case is not bin LP balance, it is the bin liquidity as defined by liquidity = deltaA / (sqrt(upper) - sqrt(lower)) or deltaB = liquidity / sqrt(lower) - liquidity / sqrt(upper).

addSpec

AddParamsSpecification

Slippage specification.

AddParamsSpecification

Multi-price add param specification.

struct AddParamsSpecification {
    uint256 slippageFactorD18;
    uint256 numberOfPriceBreaksPerSide;
    uint256 targetAmount;
    bool targetIsA;
}

Properties

Name
Type
Description

slippageFactorD18

uint256

Max slippage allowed as a percent in D18 scale. e.g. 1% slippage is 0.01e18

numberOfPriceBreaksPerSide

uint256

Number of price break values on either side of current price.

targetAmount

uint256

Target token contribution amount in tokenA if targetIsA is true, otherwise this is the target amount for tokenB.

targetIsA

bool

Indicates if the target amount is for tokenA or tokenB

CreateBoostedPositionInputs

Boosted position creation specification and add parameters.

struct CreateBoostedPositionInputs {
    BoostedPositionSpecification bpSpec;
    bytes packedSqrtPriceBreaks;
    bytes[] packedArgs;
}

Properties

Name
Type
Description

bpSpec

BoostedPositionSpecification

Boosted position kind/binId/ratio information.

packedSqrtPriceBreaks

bytes

Array of sqrt price breaks packed into bytes. These breaks act as a lookup table for the packedArgs array to indicate to the Liquidity manager what add liquidity parameters from packedArgs to use depending on the price of the pool at add time.

packedArgs

bytes[]

Array of bytes arguments. Each array element is a packed version of addLiquidity paramters.

CreateAndAddParamsViewInputs

Specification for deriving create pool parameters. Creating a pool in the liquidity manager has several steps:

  • Deploy pool

  • Donate a small amount of initial liquidity in the activeTick

  • Execute a small swap to set the pool price to the desired value

  • Add liquidity In order to execute these steps, the caller must specify the parameters of each step. The PoolLens has helper function to derive the values used by the LiquidityManager, but this struct is the input to that helper function and represents the core intent of the pool creator.

struct CreateAndAddParamsViewInputs {
    uint64 feeAIn;
    uint64 feeBIn;
    uint16 tickSpacing;
    uint32 lookback;
    IERC20 tokenA;
    IERC20 tokenB;
    int32 activeTick;
    uint8 kinds;
    uint256 initialTargetB;
    uint256 sqrtPrice;
    uint8 kind;
    int32[] ticks;
    uint128[] relativeLiquidityAmounts;
    uint256 targetAmount;
    bool targetIsA;
}

Properties

Name
Type
Description

feeAIn

uint64

feeBIn

uint64

tickSpacing

uint16

Tick spacing of pool where 1.0001^tickSpacing is the bin width.

lookback

uint32

Pool lookback in second in D2 scale.

tokenA

IERC20

Address of tokenA.

tokenB

IERC20

Address of tokenB.

activeTick

int32

Tick position that contains the active bins.

kinds

uint8

1-15 number to represent the active kinds 0b0001 = static; 0b0010 = right; 0b0100 = left; 0b1000 = both. e.g. a pool with all 4 modes will have kinds = b1111 = 15

initialTargetB

uint256

Amount of B to be donated to the pool after pool create. This amount needs to be big enough to meet the minimum bin liquidity.

sqrtPrice

uint256

Target sqrt price of the pool.

kind

uint8

Bin kind; all bins must have the same kind in a given call to addLiquidity.

ticks

int32[]

Array of tick values to add liquidity to.

relativeLiquidityAmounts

uint128[]

Relative liquidity amounts for the specified ticks. Liquidity in this case is not bin LP balance, it is the bin liquidity as defined by liquidity = deltaA / (sqrt(upper) - sqrt(lower)) or deltaB = liquidity / sqrt(lower) - liquidity / sqrt(upper).

targetAmount

uint256

Target token contribution amount in tokenA if targetIsA is true, otherwise this is the target amount for tokenB.

targetIsA

bool

Indicates if the target amount is for tokenA or tokenB

Output

struct Output {
    uint256 deltaAOut;
    uint256 deltaBOut;
    uint256[] deltaAs;
    uint256[] deltaBs;
    uint128[] deltaLpBalances;
}

Reserves

struct Reserves {
    uint256 amountA;
    uint256 amountB;
}

BinPositionKinds

struct BinPositionKinds {
    uint128[4] values;
}

PoolState

struct PoolState {
    IMaverickV2Pool.TickState[] tickStateMapping;
    IMaverickV2Pool.BinState[] binStateMapping;
    BinPositionKinds[] binIdByTickKindMapping;
    IMaverickV2Pool.State state;
    Reserves protocolFees;
}

BoostedPositionSpecification

struct BoostedPositionSpecification {
    IMaverickV2Pool pool;
    uint32[] binIds;
    uint128[] ratios;
    uint8 kind;
}

CreateAndAddParamsInputs

struct CreateAndAddParamsInputs {
    uint64 feeAIn;
    uint64 feeBIn;
    uint16 tickSpacing;
    uint32 lookback;
    IERC20 tokenA;
    IERC20 tokenB;
    int32 activeTick;
    uint8 kinds;
    IMaverickV2Pool pool;
    IMaverickV2Pool.AddLiquidityParams donateParams;
    uint256 swapAmount;
    IMaverickV2Pool.AddLiquidityParams addParams;
    bytes[] packedAddParams;
    uint256 deltaAOut;
    uint256 deltaBOut;
}

TickDeltas

struct TickDeltas {
    uint256 deltaAOut;
    uint256 deltaBOut;
    uint256[] deltaAs;
    uint256[] deltaBs;
}

Last updated