TickMath

this library is used in Fluid Vault protocol for optimiziation.

"tick" supports between -32767 and 32767. "ratioX96" supports between 37075072 and 169307877264527972847801929085841449095838922544595

MIN_TICK

int24 MIN_TICK

The minimum tick that can be passed in getRatioAtTick. 1.0015**-32767

MAX_TICK

int24 MAX_TICK

The maximum tick that can be passed in getRatioAtTick. 1.0015**32767

FACTOR00

uint256 FACTOR00

FACTOR01

uint256 FACTOR01

FACTOR02

uint256 FACTOR02

FACTOR03

uint256 FACTOR03

FACTOR04

uint256 FACTOR04

FACTOR05

uint256 FACTOR05

FACTOR06

uint256 FACTOR06

FACTOR07

uint256 FACTOR07

FACTOR08

uint256 FACTOR08

FACTOR09

uint256 FACTOR09

FACTOR10

uint256 FACTOR10

FACTOR11

uint256 FACTOR11

FACTOR12

uint256 FACTOR12

FACTOR13

uint256 FACTOR13

FACTOR14

uint256 FACTOR14

FACTOR15

uint256 FACTOR15

MIN_RATIOX96

uint256 MIN_RATIOX96

The minimum value that can be returned from getRatioAtTick. Equivalent to getRatioAtTick(MIN_TICK). ~ Equivalent to (1 << 96) * (1.0015**-32767)

MAX_RATIOX96

uint256 MAX_RATIOX96

The maximum value that can be returned from getRatioAtTick. Equivalent to getRatioAtTick(MAX_TICK). ~ Equivalent to (1 << 96) * (1.0015**32767), rounding etc. leading to minor difference

ZERO_TICK_SCALED_RATIO

uint256 ZERO_TICK_SCALED_RATIO

_1E26

uint256 _1E26

getRatioAtTick

function getRatioAtTick(int256 tick) internal pure returns (uint256 ratioX96)

ratioX96 = (1.0015^tick) * 2^96

Throws if |tick| > max tick

Parameters

NameTypeDescription
tickint256The input tick for the above formula

Return Values

NameTypeDescription
ratioX96uint256ratio = (debt amount/collateral amount)

getTickAtRatio

function getTickAtRatio(uint256 ratioX96) internal pure returns (int256 tick, uint256 perfectRatioX96)

ratioX96 = (1.0015^tick) * 2^96

Throws if ratioX96 > max ratio || ratioX96 < min ratio

Parameters

NameTypeDescription
ratioX96uint256The input ratio; ratio = (debt amount/collateral amount)

Return Values

NameTypeDescription
tickint256The output tick for the above formula. Returns in round down form. if tick is 123.23 then 123, if tick is -123.23 then returns -124
perfectRatioX96uint256perfect ratio for the above tick