Uniswap / v3-sdk

🛠 An SDK for building applications on top of Uniswap V3
MIT License
547 stars 425 forks source link

How can Decode human readable format sqrtPriceX96? #95

Closed Cazs03 closed 2 years ago

Cazs03 commented 2 years ago

Property sqrtPriceX96 It is supposed to be the price of the token.

Reading the docs https://docs.uniswap.org/sdk/guides/fetching-prices And similar post https://github.com/Uniswap/v3-sdk/issues/40

I am trying to convert the value to human readable format. But I can't find documentation or references to do it with the etherjs library.

SOLVED:
var tokenPrice0 = sqrtPriceX96 2 / 2 192; //token0 var tokenPrice1 = 2 192 / sqrtPriceX96 2; // WETH