-
Notifications
You must be signed in to change notification settings - Fork 129
Open
Description
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:
Versions used:
"@uniswap/sdk-core": "^5.0.0",
"@uniswap/v3-sdk": "^3.11.2",
Metadata
Metadata
Assignees
Labels
No labels