TickMath
this library is used in Fluid Vault protocol for optimiziation.
"tick" supports between -32767 and 32767. "ratioX96" supports between 37075072 and 169307877264527972847801929085841449095838922544595
State Variables
MIN_TICK
The minimum tick that can be passed in getRatioAtTick. 1.0015**-32767
int24 internal constant MIN_TICK = -32767;
MAX_TICK
The maximum tick that can be passed in getRatioAtTick. 1.0015**32767
int24 internal constant MAX_TICK = 32767;
FACTOR00
uint256 internal constant FACTOR00 = 0x100000000000000000000000000000000;
FACTOR01
uint256 internal constant FACTOR01 = 0xff9dd7de423466c20352b1246ce4856f;
FACTOR02
uint256 internal constant FACTOR02 = 0xff3bd55f4488ad277531fa1c725a66d0;
FACTOR03
uint256 internal constant FACTOR03 = 0xfe78410fd6498b73cb96a6917f853259;
FACTOR04
uint256 internal constant FACTOR04 = 0xfcf2d9987c9be178ad5bfeffaa123273;
FACTOR05
uint256 internal constant FACTOR05 = 0xf9ef02c4529258b057769680fc6601b3;
FACTOR06
uint256 internal constant FACTOR06 = 0xf402d288133a85a17784a411f7aba082;
FACTOR07
uint256 internal constant FACTOR07 = 0xe895615b5beb6386553757b0352bda90;
FACTOR08
uint256 internal constant FACTOR08 = 0xd34f17a00ffa00a8309940a15930391a;
FACTOR09
uint256 internal constant FACTOR09 = 0xae6b7961714e20548d88ea5123f9a0ff;
FACTOR10
uint256 internal constant FACTOR10 = 0x76d6461f27082d74e0feed3b388c0ca1;
FACTOR11
uint256 internal constant FACTOR11 = 0x372a3bfe0745d8b6b19d985d9a8b85bb;
FACTOR12
uint256 internal constant FACTOR12 = 0x0be32cbee48979763cf7247dd7bb539d;
FACTOR13
uint256 internal constant FACTOR13 = 0x8d4f70c9ff4924dac37612d1e2921e;
FACTOR14
uint256 internal constant FACTOR14 = 0x4e009ae5519380809a02ca7aec77;
FACTOR15
uint256 internal constant FACTOR15 = 0x17c45e641b6e95dee056ff10;
MIN_RATIOX96
The minimum value that can be returned from getRatioAtTick. Equivalent to getRatioAtTick(MIN_TICK). ~ Equivalent to (1 << 96) * (1.0015**-32767)
uint256 internal constant MIN_RATIOX96 = 37075072;
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
uint256 internal constant MAX_RATIOX96 = 169307877264527972847801929085841449095838922544595;
ZERO_TICK_SCALED_RATIO
uint256 internal constant ZERO_TICK_SCALED_RATIO = 0x1000000000000000000000000;
_1E26
uint256 internal constant _1E26 = 1e26;
Functions
getRatioAtTick
ratioX96 = (1.0015^tick) * 2^96
Throws if |tick| > max tick
function getRatioAtTick(int256 tick) internal pure returns (uint256 ratioX96);
Parameters
Name | Type | Description |
---|---|---|
tick | int256 | The input tick for the above formula |
Returns
Name | Type | Description |
---|---|---|
ratioX96 | uint256 | ratio = (debt amount/collateral amount) |
getTickAtRatio
ratioX96 = (1.0015^tick) * 2^96
Throws if ratioX96 > max ratio || ratioX96 < min ratio
function getTickAtRatio(uint256 ratioX96) internal pure returns (int256 tick, uint256 perfectRatioX96);
Parameters
Name | Type | Description |
---|---|---|
ratioX96 | uint256 | The input ratio; ratio = (debt amount/collateral amount) |
Returns
Name | Type | Description |
---|---|---|
tick | int256 | The 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 |
perfectRatioX96 | uint256 | perfect ratio for the above tick |