Uniswap / interface

🦄 Open source interfaces for the Uniswap protocol
https://app.uniswap.org
GNU General Public License v3.0
4.95k stars 5.01k forks source link

multicall problem with v2 / v3 token #5342

Open ubuntutest opened 1 year ago

ubuntutest commented 1 year ago

currently this code works fine if I try to swap V3 tokens like UNI or USDC and WETH in the Goerli testnet:

..
const swapRouterContract = new ethers.Contract(
    V3SwapRouterAddress,
    V3SwapRouterABI.concat(PeripheryPaymentsABI).concat(MulticallABI)
)
..

     const params2 = {
        tokenIn: WETHAddress,
        tokenOut: ZETAAddress,
        fee: 3000,
        recipient: WALLET_ADDRESS,
        deadline: expiryDate,
        amountIn: ethers.utils.parseEther('0.0001'),
        amountOutMinimum: 0,
        sqrtPriceLimitX96: 0,
    }
    const encData2 = swapRouterContract.interface.encodeFunctionData("exactInputSingle", [params2])

    const calls = [encData2]
    const encMultiCall = swapRouterContract.interface.encodeFunctionData("multicall", [calls])

    const txArgs = {
        to: V3SwapRouterAddress,
        from: WALLET_ADDRESS,
        data: encMultiCall
    }

    const tx = await signer.sendTransaction(txArgs)
    console.log('tx', tx)
    const receipt = await tx.wait()
    console.log('receipt', receipt) 

If I try with smart contracts like ZETA I get the following error:

reason: 'execution reverted',
 code: 'UNPREDICTABLE_GAS_LIMIT',

I also use the getPool() function and with both UNI and ZETA it gives me the correct pairPool

ubuntutest commented 1 year ago

i'm trying with another function:

const swapRouterContract = new ethers.Contract(
    V3SwapRouterAddress,
    V3SwapRouterABI.concat(PeripheryPaymentsABI).concat(V2Router02ABI).concat(MulticallABI)
)

 const params3 = {
        amountOut: ethers.utils.parseEther('0.0001'),
        path: ["0x..08d6","0x..9195"],
        to: "0x..398b",
        deadline: expiryDate,
    }

    const encData2 = swapRouterContract.interface.encodeFunctionData("swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)", [params3])

    const calls = [encData2]
    const encMultiCall = swapRouterContract.interface.encodeFunctionData("multicall(bytes[] data)", [calls])

    const txArgs = {
        to: V3SwapRouterAddress,
        data: encMultiCall,
        gasLimit: 40000,
        gasPrice: ethers.utils.parseUnits("100", "gwei"),
        value: ethers.utils.parseEther('0.0001'),
    }

    const tx = await signer.sendTransaction(txArgs)
    console.log('tx', tx)
    const receipt = await tx.wait()
    console.log('receipt', receipt)  

I keep getting this error:

   reason: 'types / values length mismatch',
   code: 'INVALID_ARGUMENT',
   count: {types: 4, values: 1},
   value: {
     types: [[ParamType], [ParamType], [ParamType], [ParamType]],
     values: [[Object]]
  }
tsarbuig commented 1 year ago

If you find a solution I'm interested bro... I followed the same Youtube tutorial as you and I'm stuck too ;)