Execute your swap or call

We allow you to execute any on-chain or cross-chain swap and bridging process and a combination of both.

Executing a route requires a signer to be set up. How to set up a signer.

executeRoute

const tx = await squid.executeRoute({ signer, route, executionSettings })

const txReceipt = await tx.wait()

executionSettings

In addition to the first two parameters, executeRoute takes an optional executionSettings object as a third parameter.

type executionSettings?: {
    infiniteApproval?: boolean;
    setGasPrice: boolean;
};

infiniteApproval defaults totrue if not set by the user. This will set the SquidRouter contract's allowance of fromToken to max.

When infiniteApproval is false, the Squid SDK will approve only the amount necessary for this trade.

On some chains, you may need to set setGasPrice to true, since gas estimation is different across different EVMs.

Example code snippet

const signer = new ethers.Wallet(privateKey, provider)

const params = {
    fromChain: 5, // Goerli testnet
    fromToken: "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6", // WETH on Goerli
    fromAmount: "50000000000000000", // 0.05 WETH
    toChain: 43113, // Avalanche Fuji Testnet
    toToken: "0x57f1c63497aee0be305b8852b354cec793da43bb", // aUSDC on Avalanche Fuji Testnet
    fromAddress: signer.address, // transaction sender address
    toAddress: "0xAD3A87a43489C44f0a8A33113B2745338ae71A9D", // the recipient of the trade
    slippage: 3.00, // 3.00 = 3% max slippage across the entire route, acceptable value range is 1-99
    enableForecall: true, // instant execution service, defaults to true
    quoteOnly: false // optional, defaults to false
};

const { route } = await squid.getRoute(params)

const tx = await squid.executeRoute({
  signer,
  route
})

const txReceipt = await tx.wait()

console.log(txReceipt)

Last updated