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!
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.
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: