Uniswap / examples

107 stars 141 forks source link

execution reverted error when getting quote on Base #79

Closed jfbloom22 closed 1 month ago

jfbloom22 commented 2 months ago

With the Quoting example pointed to Base, I receive this error: {"code":-32000,"message":"execution reverted"

https://github.com/jfbloom22/uniswap-examples

I updated the example to use the latest Uniswap SKD. Got it working pointed to Eth Mainnet. I switched everything to Base, but I can't seem to figure out why I am not able to receive a quote.

I forked base mainnet and am running it locally with: anvil --fork-url https://base-mainnet.chainnodes.org/42e88809-380e-4bcb-8b89-f58ea28dfca0 --fork-block-number 14204436 --fork-chain-id 8453 --chain-id 8453

I pulled the Uniswap contracts from here: https://docs.uniswap.org/contracts/v3/reference/deployments/base-deployments

Any suggestions?

sutaiyi commented 1 month ago

I also encountered this problem https://cloudflare-ipfs.com/ipns/api.uniswap.org/v1/pools/v3/base-mainnet.json The request was redirected with status code 302 Found

Ask for help

jfbloom22 commented 1 month ago

I stumbled upon the root issue and am receiving quotes successfully now. The short of it is that I was trying to interact with the V2 Quoter contract, but the example is for V1.

Here are the important changes to the example:

import Quoter from '@uniswap/v3-periphery/artifacts/contracts/lens/QuoterV2.sol/QuoterV2.json'

const quoterContract = new ethers.Contract(
    QUOTER_CONTRACT_ADDRESS,
    Quoter.abi,
    getProvider()
  )

  const params = {
    tokenIn: CurrentConfig.tokens.in.address,
    tokenOut: CurrentConfig.tokens.out.address,
    amountIn: fromReadableAmount(
      CurrentConfig.tokens.amountIn,
      CurrentConfig.tokens.in.decimals
    ).toString(),
    fee: poolConstants.fee,
    sqrtPriceLimitX96: 0,
  }
  const quotedAmountOut = await quoterContract.quoteExactInputSingle.staticCall(
    params
  )

The main difference is that the previous version of the contact had you pass in values, this version has you pass in an object.

It makes sense that the SDK would have ABIs for both versions of the contract, but man was this confusing for someone working with the Uniswap SDK for the first time.