Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK prepares data for old router #28

Open
just2102 opened this issue May 17, 2024 · 1 comment
Open

SDK prepares data for old router #28

just2102 opened this issue May 17, 2024 · 1 comment

Comments

@just2102
Copy link

just2102 commented May 17, 2024

This has already been reported here in the old repo:
Uniswap/v3-sdk#199
here I'll provide a more detailed explanation of the bug because it literally took me a whole day to figure this out (thanks @allush for the issue)

The current SDK version ("@uniswap/v3-sdk": "^3.11.2") does not allow swaps for Router 2 because it does not allow to construct correct swapCallParameters.

Steps to reproduce:

import { abi as SWAP_ROUTER_ABI } from "@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json";
    const options: SwapOptions = {
      slippageTolerance: new Percent(50, 10_000), // 50 bips, or 0.50%
      deadline: Math.floor(Date.now() / 1000) + 60 * 20, // 20 minutes from the current Unix time
      recipient: address,
    };
   const methodParameters = SwapRouter.swapCallParameters([uncheckedTrade], options);
    const tuple = {
      tokenIn: fromToken.address,
      tokenOut: toToken.address,
      fee: poolFee,
      recipient: address,
      amountIn: fromReadableAmount(amountIn, fromToken.decimals),
      deadline: options.deadline,
      amountOutMinimum: 0,
      sqrtPriceLimitX96: 0,
    };

    const customCalldata = encodeFunctionData({
      abi: SWAP_ROUTER_ABI,
      functionName: "exactInputSingle",
      args: [tuple],
    });
import { SWAP_ROUTER_02_ADDRESSES } from "@uniswap/sdk-core";
 const swapRouterAddress = SWAP_ROUTER_02_ADDRESSES(chainId);

    const result = await sendTransaction(wagmiConfig, {
      account: address,
      to: swapRouterAddress,
      value: BigInt(methodParameters.value),
      data: customCalldata,
    });

I use wagmi in this example, but it doesn't matter.
The fix to this would be to use the old SwapRouter (https://docs.uniswap.org/contracts/v3/reference/deployments/ethereum-deployments)
I didn't manage to get it working with the new SwapRouter 2 because of this error:
image

Versions used:
"@uniswap/sdk-core": "^5.0.0",
"@uniswap/v3-sdk": "^3.11.2",

@wade-liwei
Copy link

hey bro

Could you please give me an example about how to use the sdks universal router?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants