Uniswap / v3-sdk

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

TickMath.getSqrtRatioAtTick not reporting same value as slot0 onchain #93

Closed hmmdeif closed 2 years ago

hmmdeif commented 2 years ago

When using the SDK I get slightly different values for sqrtPriceX96 when using the SDK helper function than the reported onchain slot0 for the pool (on mainnet and rinkeby).

Pool address on mainnet 0xcB0C5d9D92f4F2F80cce7aa271a1E148c226e19D (as an example) For tick 11026, slot0 reports 137503933239637586571196885609. Using the sdk for tick 11026 I get 137497297140448246835764898549.

However Wolfram Alpha says that the sdk math is actually the correct value so how come slot0 is reporting something different? Should I expect this to be the same value? The discrepancy is large enough to be affecting slippage calculations on low slippage levels so I'm unsure how to handle this.

NoahZinsmeister commented 2 years ago

in the contract, sqrtPriceX96 can be any value at or above the price of the current tick (until the next tick), so this is expected