You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See: Uniswap/v3-sdk#182
for full breakdown of the issue. What it boils down to is token0Price and token1Price are incorrectly calculated. I've had a look through, and located the main problem.
let Q192 = 2 ** 192 type is number, when it should be BigInt or BigDecimal. A lot of precision is lost due to it being a number. It is converted to a BigDecimal within the function but it the precision is already lost by this point. This causes the resulting prices to be incorrect.
This is the most glaring problem, there is a couple of other minor things too. The resulting prices are rounded to 34 significant digits. This is obviously necessary for prices that are small, with a lot of decimal places, but this does mean that large integer prices often have trailing zeros. e.g. 340256786836388081269117234195560700000. I know this isn't the biggest deal as 34 digits of precision is quite a lot, but it seems like this is implicitly happening and not explicitly.
And finally, I've noticed that the token prices are sometimes "0". This is because the prices are only updated in handleSwap ()
The text was updated successfully, but these errors were encountered:
@NoUJoe , I believe that the variables token0Price and token1Price are intended for tracking token prices on an hourly or daily basis.
To obtain the prices for newly added pools, you can derive them by performing calculations based on the supplied liquidity token amounts. There are other approaches as well that you can get the token price - something like fetching the price from the smart contract or you can use Oracle Library.
See: Uniswap/v3-sdk#182
for full breakdown of the issue. What it boils down to is token0Price and token1Price are incorrectly calculated. I've had a look through, and located the main problem.
v3-subgraph/src/utils/pricing.ts
Lines 47 to 48 in bf03f94
let Q192 = 2 ** 192
type isnumber
, when it should beBigInt
orBigDecimal
. A lot of precision is lost due to it being a number. It is converted to aBigDecimal
within the function but it the precision is already lost by this point. This causes the resulting prices to be incorrect.This is the most glaring problem, there is a couple of other minor things too. The resulting prices are rounded to 34 significant digits. This is obviously necessary for prices that are small, with a lot of decimal places, but this does mean that large integer prices often have trailing zeros. e.g.
340256786836388081269117234195560700000
. I know this isn't the biggest deal as 34 digits of precision is quite a lot, but it seems like this is implicitly happening and not explicitly.And finally, I've noticed that the token prices are sometimes "0". This is because the prices are only updated in
handleSwap ()
The text was updated successfully, but these errors were encountered: