TickMath

Computes sqrt price for ticks of size 1.0001, i.e. sqrt(1.0001^tick) as fixed point Q64.96 numbers. Supports prices between 2**-128 and 2**128

MIN_TICK

int24 MIN_TICK

The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128

MAX_TICK

int24 MAX_TICK

The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128

MIN_SQRT_RATIO

uint160 MIN_SQRT_RATIO

The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK)

MAX_SQRT_RATIO

uint160 MAX_SQRT_RATIO

The maximum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK)

getSqrtRatioAtTick

function getSqrtRatioAtTick(int24 tick) internal pure returns (uint160 sqrtPriceX96)

Calculates sqrt(1.0001^tick) * 2^96

Throws if |tick| > max tick

Parameters

NameTypeDescription
tickint24The input tick for the above formula

Return Values

NameTypeDescription
sqrtPriceX96uint160A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0) at the given tick

getTickAtSqrtRatio

function getTickAtSqrtRatio(uint160 sqrtPriceX96) internal pure returns (int24 tick)

Calculates the greatest tick value such that getRatioAtTick(tick) <= ratio

Throws in case sqrtPriceX96 < MIN_SQRT_RATIO, as MIN_SQRT_RATIO is the lowest value getRatioAtTick may ever return.

Parameters

NameTypeDescription
sqrtPriceX96uint160The sqrt ratio for which to compute the tick as a Q64.96

Return Values

NameTypeDescription
tickint24The greatest tick for which the ratio is less than or equal to the input ratio