Skip to content

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 ​

solidity
int24 MIN_TICK

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

MAX_TICK ​

solidity
int24 MAX_TICK

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

FACTOR00 ​

solidity
uint256 FACTOR00

FACTOR01 ​

solidity
uint256 FACTOR01

FACTOR02 ​

solidity
uint256 FACTOR02

FACTOR03 ​

solidity
uint256 FACTOR03

FACTOR04 ​

solidity
uint256 FACTOR04

FACTOR05 ​

solidity
uint256 FACTOR05

FACTOR06 ​

solidity
uint256 FACTOR06

FACTOR07 ​

solidity
uint256 FACTOR07

FACTOR08 ​

solidity
uint256 FACTOR08

FACTOR09 ​

solidity
uint256 FACTOR09

FACTOR10 ​

solidity
uint256 FACTOR10

FACTOR11 ​

solidity
uint256 FACTOR11

FACTOR12 ​

solidity
uint256 FACTOR12

FACTOR13 ​

solidity
uint256 FACTOR13

FACTOR14 ​

solidity
uint256 FACTOR14

FACTOR15 ​

solidity
uint256 FACTOR15

MIN_RATIOX96 ​

solidity
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 ​

solidity
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 ​

solidity
uint256 ZERO_TICK_SCALED_RATIO

_1E26 ​

solidity
uint256 _1E26

getRatioAtTick ​

solidity
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 ​

solidity
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