PoolLib

Functions

uniqueOrderedTicksCheck

Check to ensure that the ticks are in ascending order and amount array is same length as tick array.

function uniqueOrderedTicksCheck(int32[] memory ticks, uint256 amountsLength) internal pure;

Parameters

NameTypeDescription

ticks

int32[]

An array of int32 values representing ticks to be checked.

amountsLength

uint256

Amount array length.

binReserves

Compute bin reserves assuming the bin is not merged; not accurate reflection of reserves for merged bins.

function binReserves(IMaverickV2Pool.BinState storage bin, IMaverickV2Pool.TickState memory tick)
    internal
    view
    returns (uint128 reserveA, uint128 reserveB);

Parameters

NameTypeDescription

bin

IMaverickV2Pool.BinState

The storage reference to the state for this bin.

tick

IMaverickV2Pool.TickState

The memory reference to the state for this tick.

Returns

NameTypeDescription

reserveA

uint128

The reserve amount for token A.

reserveB

uint128

The reserve amount for token B.

binReserves

Compute bin reserves assuming the bin is not merged; not accurate reflection of reserves for merged bins.

function binReserves(uint128 tickBalance, uint128 tickReserveA, uint128 tickReserveB, uint128 tickTotalSupply)
    internal
    pure
    returns (uint128 reserveA, uint128 reserveB);

Parameters

NameTypeDescription

tickBalance

uint128

Bin's balance in the tick.

tickReserveA

uint128

Tick's tokenA reserves.

tickReserveB

uint128

Tick's tokenB reserves.

tickTotalSupply

uint128

Tick total supply of bin balances.

reserveValue

Reserves of a bin in a tick.

function reserveValue(uint128 tickReserve, uint128 tickBalance, uint128 tickTotalSupply)
    internal
    pure
    returns (uint128 reserve);

Parameters

NameTypeDescription

tickReserve

uint128

Tick reserve amount in a given token.

tickBalance

uint128

Bin's balance in the tick.

tickTotalSupply

uint128

Tick total supply of bin balances.

deltaTickBalanceFromDeltaLpBalance

Calculate delta A, delta B, and delta Tick Balance based on delta LP balance and the Tick/Bin state.

function deltaTickBalanceFromDeltaLpBalance(
    uint256 binTickBalance,
    uint256 binTotalSupply,
    IMaverickV2Pool.TickState memory tickState,
    uint128 deltaLpBalance,
    AddLiquidityInfo memory addLiquidityInfo
) internal pure returns (uint256 deltaTickBalance);

_setRequiredDeltaReservesForEmptyTick

Calculates deltaA = liquidity * (sqrt(upper) - sqrt(lower))

Calculates deltaB = liquidity / sqrt(lower) - liquidity / sqrt(upper),

i.e., liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower))

we set liquidity = deltaLpBalance / (1.0001^(tick * tickspacing) - 1)

which simplifies the A/B amounts to:

deltaA = deltaLpBalance * sqrt(lower)

deltaB = deltaLpBalance / sqrt(upper)

function _setRequiredDeltaReservesForEmptyTick(uint128 deltaLpBalance, AddLiquidityInfo memory addLiquidityInfo)
    internal
    pure;

Structs

AddLiquidityInfo

struct AddLiquidityInfo {
    uint256 deltaA;
    uint256 deltaB;
    bool tickLtActive;
    uint256 tickSpacing;
    int32 tick;
}

Last updated