I am trying to compute a Uniswap V3 pool token price in Solidity.
I can get the square root price of Q64.96 number as uint160
(e.g., 1234217676608908277512433764
- value of DAI/ETH pool (price at that time around 1 ETH for 4090 DAI)).
This can be retrieved via IUniswapV3PoolState.slot0()
As the function docstring says: "sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value"
How can I convert this number to uint256
?
The calculated price should suggest the value of 1 ETH for 4090 DAI
Is there any other way of getting the Uniswap V3 pair price?
The answer would preferably be in solidity, but other answers are also acceptable.
Unsuccessful attempt
I tried squaring the number 1234217676608908277512433764
and then shifting it by 96, but the result was 1.922666416729829e+25
which doesn't seem too be correct.
(1234217676608908277512433764^2) >> 96 = 1.922666416729829e+25