I'm trying to figure out how to convert a uniswap ratio into wei (and eventually ether).
The uniswap docs commonly mention
A Fixed point Q64.96 number representing the sqrt of the ratio of the two assets (token1/token0)
However, I can't figure out how to convert it into wei (and eventually ether).
Here is my C# Code:
BigInteger sqrRtPrice = BigInteger.Parse("1407006288156847466476392762276105"); var tt = (sqrRtPrice * sqrRtPrice) * (BigInteger)(1e18) / (BigInteger)(1e18) / BigInteger.Pow(((BigInteger)2), 192); var eth = Nethereum.Util.UnitConversion.Convert.FromWei(tt);
In this example,
0.000000000315379099 which is close to what Uniswap says
0.000315432, but I don't understand why mine is off by 6 decimal places. Both tokens in the pool I'm looking at (WETH-DAI) are 18 decimals long. I'm trying to convert Uniswap
sqrtPriceX96 to the price I see on the Uniswap display, but I don't understand why I'm a few decimal places off.