0

I'm currently developing a smart contract with access to Uniswap V3's QuoterV2 contract. I'm interested in obtaining the most accurate price of tokenB in terms of tokenA:

quoter.quoteExactInputSingle(IQuoterV2.QuoteExactInputSingleParams(
            tokenA,
            tokenB, 
            amountA, 
            uint24(feeRate), 
            uint160(SQRT_PRICE_LIMIT_X96)));

All parameters are clear to me but as I know, there are 3 fee rates on Uniswap V3:

  • 0.05%
  • 0.30%
  • 1%

I can select any of these rates freely and I will get some exchange rate. How can I determine which of these rate is the most accurate? Does proper rate depend on the types of tokens (i.e. for stablecoins pair there will be a small fee rate of 0.05%, for pair like ETH-USDC there will be another, like 0.30% or 1%)?

1 Answer 1

2

All of them are accurate in the sense that they all reflect the particular pool's notion of price, which may or may not be similar to some external "oracle" price. Generally pools with deeper liquidity and smaller swap fee are arbitraged more frequently, so their price is more likely to be synced with external prices.

The best pool to use for trading is the one that returns the maximum output. The output depends on the pre-trade price in the pool, the pool fee, and the liquidity depth and distribution in the pool. To obtain the result, you'd need to simulate the swap, which is exactly what the quoter contract does.

If however you want to use Uniswap pool as an oracle: first, think again if that's really a good idea... If the answer is still "yes", then under no circumstances use the spot price, it's easy to manipulate. Read the documentation how to access the built-in TWAP oracle functionality instead.

1
  • Thank you for detailed answer! I'll change my price fetching mechanism.
    – strukovsky
    Commented Jul 1, 2023 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.