Google Sheets Library for Uniswap V3 Math
Ported over code from github.com/jeiwan/uniswapv3-code.
Open a new Google Sheets document, open Extensions->AppScript and paste in the contents of Code.gs into Code.gs
. The following functions are thereafter available:
Returns MIN_TICK = -887272
Returns MAX_TICK = 887272
Returns Q96 = 2**96
Returns WAD = 10**18
Returns Uniswap v3 style square root
n.b.
Ticks are integers that can be positive and negative and, of course, they’re not infinite. Uniswap V3 stores
$\sqrt{P}$ as a fixed point Q64.96 number, which is a rational number that uses 64 bits for the integer part and 96 bits for the fractional part. Thus, prices (equal to the square of$\sqrt{P}$ ) are within the range:$[2^{-128}, 2^{128}]$ .
From Uniswap v3 Book
Returns the inverse conversion.
Returns the tick value to Q96 square root price.
Returns the UniMath liquidity of token0 between two prices.
Returns the UniMath liquidity of token1 between two prices.
Returns the amount of token0 for a given amount of liquidity between two prices.
Returns the amount of token1 for a given amount of liquidity between two prices
Calculate the amount of token0 coming out of a trade for a given amount of liquidity between two prices.
Calculate the maximum trade size that can settle for the given liquidity between two prices at a maximum slippage boundary.
Assumes the range is the only liquidity available.