Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uniswap V3 sqrtPrice for ETH/DAI and ETH/USDT, ETH/USDC vastly different [closed]

I use IUniswapV3PoolState.slot0 to return sqrtPriceX96 and tick for different pairs in Uniswap V3. The results are very reasonable for ETH/DAI, but it's quite different for ETH/USDT and ETH/USDC.

This is not because of the order of the tokens, but rather the final result of price (after taking care of square root and Q96) differ by 10^(-12). So I would get ETH/DAI around $3200, while ETH/USDT and ETH/USDC will give $3200*10^(-12). Is there anything I'm missing? Thank you!

like image 216
Tian L Avatar asked Oct 13 '25 08:10

Tian L


1 Answers

EVM compatible blockchains use fixed-point math. The floating point values that you see in the UI are abstractions, technically everything is an integer; a specific number of digits reserved to represent the decimals. Different ERC-20 tokens reserve a different number of decimals.

  • WETH and DAI have 18 decimals
  • USDT and USDC have 6 decimals.

If you have asset X that has 6 and an asset Y that has 18 decimals, then the price of Y in terms of X has to be corrected for this fact.

Lets use price = y/x, then the price adjusted for the amount of decimals is going to be price_adjusted = y/x * 10^(-12). To see why refer to Section 3.3.2 here:

Price adjusted for decimal equation

like image 56
kfx Avatar answered Oct 16 '25 08:10

kfx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!