TickMath

Functions

tickSqrtPrices

Compute the lower and upper sqrtPrice of a tick.

function tickSqrtPrices(uint256 tickSpacing, int32 _tick)
    internal
    pure
    returns (uint256 sqrtLowerPrice, uint256 sqrtUpperPrice);

Parameters

Name
Type
Description

tickSpacing

uint256

The tick spacing used for calculations.

_tick

int32

The input tick value.

subTickIndex

Compute the base tick value from the pool tick and the tickSpacing. Revert if base tick is beyond the max tick boundary.

function subTickIndex(uint256 tickSpacing, int32 _tick) internal pure returns (uint32 subTick);

Parameters

Name
Type
Description

tickSpacing

uint256

The tick spacing used for calculations.

_tick

int32

The input tick value.

tickSqrtPrice

Calculate the square root price for a given tick and tick spacing.

function tickSqrtPrice(uint256 tickSpacing, int32 _tick) internal pure returns (uint256 _result);

Parameters

Name
Type
Description

tickSpacing

uint256

The tick spacing used for calculations.

_tick

int32

The input tick value.

Returns

Name
Type
Description

_result

uint256

The square root price.

getTickL

Calculate liquidity of a tick.

function getTickL(uint256 reserveA, uint256 reserveB, uint256 sqrtLowerTickPrice, uint256 sqrtUpperTickPrice)
    internal
    pure
    returns (uint256 liquidity);

Parameters

Name
Type
Description

reserveA

uint256

Tick reserve of token A.

reserveB

uint256

Tick reserve of token B.

sqrtLowerTickPrice

uint256

The square root price of the lower tick edge.

sqrtUpperTickPrice

uint256

The square root price of the upper tick edge.

getSqrtPrice

Calculate square root price of a tick. Returns left edge of the tick if the tick has no reserves.

function getSqrtPrice(
    uint256 reserveA,
    uint256 reserveB,
    uint256 sqrtLowerTickPrice,
    uint256 sqrtUpperTickPrice,
    uint256 liquidity
) internal pure returns (uint256 sqrtPrice);

Parameters

Name
Type
Description

reserveA

uint256

Tick reserve of token A.

reserveB

uint256

Tick reserve of token B.

sqrtLowerTickPrice

uint256

The square root price of the lower tick edge.

sqrtUpperTickPrice

uint256

The square root price of the upper tick edge.

liquidity

uint256

Returns

Name
Type
Description

sqrtPrice

uint256

The calculated square root price.

getTickSqrtPriceAndL

Calculate square root price of a tick. Returns left edge of the tick if the tick has no reserves.

function getTickSqrtPriceAndL(
    uint256 reserveA,
    uint256 reserveB,
    uint256 sqrtLowerTickPrice,
    uint256 sqrtUpperTickPrice
) internal pure returns (uint256 sqrtPrice, uint256 liquidity);

Parameters

Name
Type
Description

reserveA

uint256

Tick reserve of token A.

reserveB

uint256

Tick reserve of token B.

sqrtLowerTickPrice

uint256

The square root price of the lower tick edge.

sqrtUpperTickPrice

uint256

The square root price of the upper tick edge.

Returns

Name
Type
Description

sqrtPrice

uint256

The calculated square root price.

liquidity

uint256

The calculated liquidity.

Errors

TickMaxExceeded

error TickMaxExceeded(int256 tick);

Last updated