I'm working on V3 of Uniswap for the first time, and am trying to get the current price of a pool.
I'm using this tutorial page https://docs.uniswap.org/sdk/guides/fetching-prices, which certainly seems to attempt what I wish.
Further, the comments in the method token0Price
states:
/**
* Returns the current mid-price of the pool in terms of token0, i.e. the ratio of token1 over token0
*/
However, when I call this function, what I receive is:
Price {
numerator: JSBI(8) [
445412081, 346709960,
584891573, 611262682,
360319882, 934240370,
1035473620, 1369,
sign: false
],
denominator: JSBI(7) [ 0, 0, 0, 0, 0, 0, 4096, sign: false ],
baseCurrency: Token {
chainId: 3,
decimals: 6,
symbol: 'USDC',
name: 'USD Coin',
isNative: false,
isToken: true,
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
},
quoteCurrency: Token {
chainId: 3,
decimals: 18,
symbol: 'WETH',
name: 'Wrapped Ether',
isNative: false,
isToken: true,
address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'
},
scalar: Fraction {
numerator: JSBI(1) [ 1000000, sign: false ],
denominator: JSBI(2) [ 660865024, 931322574, sign: false ]
}
}
How do I translate this Price objects JSBI arrays into an actual price of the pool?
Best Answer
These JSBI objects got a method
toSignificant
, use it to convert the big number into a number literal.will return a floating point number with precision of 6 digits.