i have this code vconst { AlphaRouter } = require('@uniswap/smart-order-router'); const…
- User
i have this code vconst { AlphaRouter } = require('@uniswap/smart-order-router'); const { Token, CurrencyAmount, Percent, TradeType } = require('@uniswap/sdk-core'); const { ethers, BigNumber } = require('ethers'); const { SwapRouter } = require('@uniswap/v3-sdk');
const SWAP_ROUTER_ADDRESS = '0xE592427A0AEce92De3Edee1F18E0157C05861564'; const WALLET_ADDRESS = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'; const WALLET_SECRET = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'; const INFURA_TEST_URL = 'https://mainnet.infura.io/v3/2d5bc62bb8d748cebfc64763e719cb4f';
const provider = new ethers.providers.JsonRpcProvider(INFURA_TEST_URL);
const chainId = 1; const router = new AlphaRouter({ chainId: chainId, provider: provider });
const token0 = new Token(chainId, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', 18, 'WETH', 'Wrapped Ether'); const token1 = new Token(chainId, '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984', 18, 'UNI', 'Uniswap Token');
async function main() { const inputAmount = CurrencyAmount.fromRawAmount(token0, ethers.utils.parseUnits('0.001', 18));
const bestRoute = await router.route(inputAmount, token1);
const route = await router.route(inputAmount, token1, TradeType.EXACT_INPUT, { recipient: WALLET_ADDRESS, slippageTolerance: new Percent(25, 100), deadline: Math.floor(Date.now() / 1000 + 1800), });
if (!bestRoute) console.log('No best route found!'); const swapRoute = bestRoute.route; const pools = swapRoute[0].poolAddresses[0]; console.log(pools); const quotedAmountOut = bestRoute.quote;
const methodParameters = SwapRouter.swapCallParameters(bestRoute.trade, { tradeType: bestRoute.trade.tradeType, });
const transaction = { to: SWAP_ROUTER_ADDRESS, data: methodParameters.calldata, value: BigNumber.from(route.methodParameters.value), from: WALLET_ADDRESS, gasPrice: BigNumber.from(route.gasPriceWei), gasLimit: ethers.utils.hexlify(1000000), };
// Sign and send the transaction const wallet = new ethers.Wallet(WALLET_SECRET, provider);
const signedTransaction = await wallet.signTransaction(transaction); const txResult = await provider.sendTransaction(signedTransaction);
console.log('Transaction sent! Waiting for confirmation...'); console.log(
Hash: ${txResult.hash});const receipt = await txResult.wait();
console.log(
Transaction confirmed in block ${receipt.blockNumber}); but i get this error C:\Users\lidor\Desktop\Trade Bot\node_modules@uniswap\smart-order-router\build\main\util\methodParameters.js:105 throw new Error(Unsupported swap type ${swapConfig}); ^Error: Unsupported swap type [object Object] at buildSwapMethodParameters (C:\Users\lidor\Desktop\Trade Bot\node_modules@uniswap\smart-order-router\build\main\util\methodParameters.js:105:11) at AlphaRouter.route (C:\Users\lidor\Desktop\Trade Bot\node_modules@uniswap\smart-order-router\build\main\routers\alpha-router\alpha-router.js:461:81) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async main (C:\Users\lidor\Desktop\Trade Bot\index.js:24:17)
- Assistant
It looks like the issue is in the method parameters for the SwapRouter.swapCallParameters function. The correct way to call the function is with an object that has
trade, andoptionsfields. However, you're currently passing the trade object directly in the method call. To fix the error, update the method parameters as follows:Replace this line:
- User
- Assistant