Ethers JS

You are referring to the Legacy version of KyberSwap docs.

For the most updated information, please refer to:

Introduction

This guide will walk you through on how you can interact with our protocol implementation using the ethers.js library. You may also use the Web3 library, with some syntax changes. The most common group of users that can benefit from this guide are wallets or vendors who want to use their own UI.

Risk Mitigation

There are some risks when utilising Kyber. To safeguard users, we kindly ask that you refer to the Slippage Rates Protection and Price Feed Security sections on what these risks are, and how to mitigate them.

Overview

We break this guide into 2 sections:

  1. Trading Tokens - The section covers what contract interfaces to import, and functions to call to fetch rates and perform a simple trade.

  2. Reserve Routing - This section covers the reserve routing feature to include / exclude reserves, or to split trades amongst multiple reserves.

Things to note

  1. If the source token is not ETH (ie. an ERC20 token), the user is required to first call the ERC20 approve function to give an allowance to the kyber proxy contract.

  2. To prevent front running, the contract limits the gas price trade transactions can have. The transaction will be reverted if the limit is exceeded. To query for the maximum gas limit, check the public variable maxGasPrice.

// DISCLAIMER: Code snippets in this guide are just examples and you
// should always do your own testing. If you have questions, visit our
// https://t.me/KyberDeveloper.

let maxGasPrice = await KyberNetworkProxyContract.maxGasPrice();

Trading Tokens

Suppose we want to convert 100 KNC to DAI tokens on Ropsten, which is a token to token conversion. In addition, we want to charge a platform fee of 0.25%. Note that ETH is used as the base pair i.e. KNC -> ETH -> DAI.

The code example will also work for token -> ether and ether -> token conversions.

Import Relevant Packages

  • We use ethers for connecting to the Ethereum blockchain

  • ethers includes a BN utils library for BigNumber variables, which we shall also instantiate for convenience

  • The node-fetch module is used for making API queries

// Importing the relevant packages
const ethers = require('ethers');
const BN = ethers.BigNumber;
const fetch = require('node-fetch');

Connect to an Ethereum Node

ethers provides a very simple method getDefaultProvider to easily connect to the Ethereum blockchain. While not necessary, it is recommended to provide an API key for the various providers offered (Eg. Alchemy, Infura and Etherscan).

// Connecting to a provider
const NETWORK = 'ropsten';
const PROJECT_ID = 'INFURA_PROJECT_ID'; // Replace this with your own Project ID
const provider = new ethers.getDefaultProvider(NETWORK, { infura: PROJECT_ID });

Define Constants and Trade Details

Next, we will define the constants that we will be using for this scenario.

Universal Constants

  • ETH_ADDRESS used by Kyber to represent Ether

  • ZERO_BN: BigNumber instance of 0

  • MAX_UINT256: BigNumber instance of 2**256 - 1

  • EMPTY_HINT: The hint parameter is used for [reserve routing]. In this case, an empty hint would be 0x.

const ETH_ADDRESS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
const ZERO_BN = ethers.constants.Zero;
const MAX_UINT256 = ethers.constants.MaxUint256;
const EMPTY_HINT = '0x';

Tokens and Source Quantity

We define the source and destination tokens, as well as the source quantity to be used for the trade.

// Tokens and srcQty
const SRC_TOKEN_ADDRESS = '0x7b2810576aa1cce68f2b118cef1f36467c648f92'; // Ropsten KNC address
const DEST_TOKEN_ADDRESS = '0xad6d458402f60fd3bd25163575031acdce07538d'; // Ropsten DAI address
const SRC_DECIMALS = new BN.from(18);
const SRC_QTY = BN.from(100).mul(BN.from(10).pow(SRC_DECIMALS)); // 100 KNC

Contract ABIs and Proxy Address

The following ABIs are imported for these functionalities:

// Contract ABIs and proxy address
const IERC20_ABI = [
  {
    anonymous: false,
    inputs: [
      {
        indexed: true,
        internalType: 'address',
        name: '_owner',
        type: 'address',
      },
      {
        indexed: true,
        internalType: 'address',
        name: '_spender',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'uint256',
        name: '_value',
        type: 'uint256',
      },
    ],
    name: 'Approval',
    type: 'event',
  },
  {
    inputs: [
      { internalType: 'address', name: '_owner', type: 'address' },
      { internalType: 'address', name: '_spender', type: 'address' },
    ],
    name: 'allowance',
    outputs: [{ internalType: 'uint256', name: 'remaining', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'address', name: '_spender', type: 'address' },
      { internalType: 'uint256', name: '_value', type: 'uint256' },
    ],
    name: 'approve',
    outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function',
  },
  {
    inputs: [{ internalType: 'address', name: '_owner', type: 'address' }],
    name: 'balanceOf',
    outputs: [{ internalType: 'uint256', name: 'balance', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [],
    name: 'decimals',
    outputs: [{ internalType: 'uint8', name: 'digits', type: 'uint8' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [],
    name: 'totalSupply',
    outputs: [{ internalType: 'uint256', name: 'supply', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'address', name: '_to', type: 'address' },
      { internalType: 'uint256', name: '_value', type: 'uint256' },
    ],
    name: 'transfer',
    outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'address', name: '_from', type: 'address' },
      { internalType: 'address', name: '_to', type: 'address' },
      { internalType: 'uint256', name: '_value', type: 'uint256' },
    ],
    name: 'transferFrom',
    outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function',
  },
];
const IKyberNetworkProxy_ABI = [
  {
    anonymous: false,
    inputs: [
      {
        indexed: true,
        internalType: 'address',
        name: 'trader',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'contract IERC20',
        name: 'src',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'contract IERC20',
        name: 'dest',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'address',
        name: 'destAddress',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'uint256',
        name: 'actualSrcAmount',
        type: 'uint256',
      },
      {
        indexed: false,
        internalType: 'uint256',
        name: 'actualDestAmount',
        type: 'uint256',
      },
      {
        indexed: false,
        internalType: 'address',
        name: 'platformWallet',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'uint256',
        name: 'platformFeeBps',
        type: 'uint256',
      },
    ],
    name: 'ExecuteTrade',
    type: 'event',
  },
  {
    inputs: [],
    name: 'enabled',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'contract ERC20', name: 'src', type: 'address' },
      { internalType: 'contract ERC20', name: 'dest', type: 'address' },
      { internalType: 'uint256', name: 'srcQty', type: 'uint256' },
    ],
    name: 'getExpectedRate',
    outputs: [
      { internalType: 'uint256', name: 'expectedRate', type: 'uint256' },
      { internalType: 'uint256', name: 'worstRate', type: 'uint256' },
    ],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'contract IERC20', name: 'src', type: 'address' },
      { internalType: 'contract IERC20', name: 'dest', type: 'address' },
      { internalType: 'uint256', name: 'srcQty', type: 'uint256' },
      { internalType: 'uint256', name: 'platformFeeBps', type: 'uint256' },
      { internalType: 'bytes', name: 'hint', type: 'bytes' },
    ],
    name: 'getExpectedRateAfterFee',
    outputs: [
      { internalType: 'uint256', name: 'expectedRate', type: 'uint256' },
    ],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [],
    name: 'maxGasPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'contract IERC20', name: 'src', type: 'address' },
      { internalType: 'uint256', name: 'srcAmount', type: 'uint256' },
      { internalType: 'contract IERC20', name: 'dest', type: 'address' },
      { internalType: 'address payable', name: 'destAddress', type: 'address' },
      { internalType: 'uint256', name: 'maxDestAmount', type: 'uint256' },
      { internalType: 'uint256', name: 'minConversionRate', type: 'uint256' },
      {
        internalType: 'address payable',
        name: 'platformWallet',
        type: 'address',
      },
    ],
    name: 'trade',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'payable',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'contract ERC20', name: 'src', type: 'address' },
      { internalType: 'uint256', name: 'srcAmount', type: 'uint256' },
      { internalType: 'contract ERC20', name: 'dest', type: 'address' },
      { internalType: 'address payable', name: 'destAddress', type: 'address' },
      { internalType: 'uint256', name: 'maxDestAmount', type: 'uint256' },
      { internalType: 'uint256', name: 'minConversionRate', type: 'uint256' },
      { internalType: 'address payable', name: 'walletId', type: 'address' },
      { internalType: 'bytes', name: 'hint', type: 'bytes' },
    ],
    name: 'tradeWithHint',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'payable',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'contract IERC20', name: 'src', type: 'address' },
      { internalType: 'uint256', name: 'srcAmount', type: 'uint256' },
      { internalType: 'contract IERC20', name: 'dest', type: 'address' },
      { internalType: 'address payable', name: 'destAddress', type: 'address' },
      { internalType: 'uint256', name: 'maxDestAmount', type: 'uint256' },
      { internalType: 'uint256', name: 'minConversionRate', type: 'uint256' },
      {
        internalType: 'address payable',
        name: 'platformWallet',
        type: 'address',
      },
      { internalType: 'uint256', name: 'platformFeeBps', type: 'uint256' },
      { internalType: 'bytes', name: 'hint', type: 'bytes' },
    ],
    name: 'tradeWithHintAndFee',
    outputs: [{ internalType: 'uint256', name: 'destAmount', type: 'uint256' }],
    stateMutability: 'payable',
    type: 'function',
  },
];

// Kyber Network Proxy Contract Address
const IKyberNetworkProxy_ADDRESS = '0xa16Fc6e9b5D359797999adA576F7f4a4d57E8F75';

Sender

Replace the PRIVATE_KEY with a private key (including the 0x prefix) of the sender of the transaction. There are other import methods that ethers.js support, such as reading from Metamask, and mnemonic phrases.

// User Details
const PRIVATE_KEY = 'PRIVATE_KEY'; // Eg. 0x40ddbce3c7df9ab8d507d6b4af3861d224711b35299470ab7a217f780fe696cd
const USER_WALLET = new ethers.Wallet(PRIVATE_KEY, provider);

Platform Wallet and Fees

Find out more about platform fees here.

// Platform fees
const PLATFORM_WALLET = 'PLATFORM_WALLET'; // Eg. 0x483C5100C3E544Aef546f72dF4022c8934a6945E
const PLATFORM_FEE = 25; // 0.25%

Instantiate Contracts

Note that we fix USER_WALLET as the sender of any transactions made here to these contracts.

// Instantiate contracts, using USER_WALLET as sender of txns
const KyberNetworkProxyContract = new ethers.Contract(
  IKyberNetworkProxy_ADDRESS,
  IKyberNetworkProxy_ABI,
  USER_WALLET,
);
const srcTokenContract = new ethers.Contract(
  SRC_TOKEN_ADDRESS,
  IERC20_ABI,
  USER_WALLET,
);

Core Steps For Trade Execution

Now that we have defined the trade details, we break down the process into a number of steps.

Step 1: Checking Token Allowance

We first check if there is sufficient allowance given to the proxy contract for the trade. Should it be insufficient, we will call the approve function of the source token contract.

async function checkAndApproveTokenForTrade(
  srcTokenContract,
  userAddress,
  srcQty,
) {
  if (srcTokenContract.address == ETH_ADDRESS) {
    return;
  }

  // check existing allowance given to proxy contract
  let existingAllowance = await srcTokenContract.allowance(
    userAddress,
    IKyberNetworkProxy_ADDRESS,
  );

  // if zero allowance, just set to MAX_UINT256
  if (existingAllowance.eq(ZERO_BN)) {
    console.log('Approving KNP contract to max allowance');
    await srcTokenContract.approve(IKyberNetworkProxy_ADDRESS, MAX_UINT256);
  } else if (existingAllowance.lt(srcQty)) {
    // if existing allowance is insufficient, reset to zero, then set to MAX_UINT256
    console.log('Approving KNP contract to zero, then max allowance');
    await srcTokenContract.approve(IKyberNetworkProxy_ADDRESS, ZERO_BN);
    await srcTokenContract.approve(IKyberNetworkProxy_ADDRESS, MAX_UINT256);
  }
  return;
}

Step 2: Hint

For simple trades, we can simply set the hint as the EMPTY_HINT. Otherwise, we can build hints to specify reserve routes.

let hint = EMPTY_HINT;

Step 3: Fetching Rates

Next, we fetch the expected rate for the trade, which we can set as the minimum conversion rate. Should the actual rate fall below this, the trade will revert. You may choose to add a buffer (reduce the fetched expected rate by some percentage).

let minConversionRate = await KyberNetworkProxyContract.getExpectedRateAfterFee(
  SRC_TOKEN_ADDRESS,
  DEST_TOKEN_ADDRESS,
  SRC_QTY,
  PLATFORM_FEE,
  hint,
);

Understanding the rate

Divide the rate by 10**18 to get a 'readable' rate. For example, if the rate returned from a query of 1 WBTC -> KNC is 7980824281140923034320, then 1 WBTC can be exchanged for 7980824281140923034320 / 1e18 ~= 7980.824 KNC.

Step 3: Gas Configurations

We next define the gas limit and price to be used for the trade. There are a number of ways to go about this. We give 2 possible methods to determine each parameter, but this is definitely customisable to suit your needs.

async function getGasConfig(
  KyberNetworkProxyContract,
  provider,
  srcTokenAddress,
  destTokenAddress,
  srcQty,
  destAddress,
  maxDestAmount,
  minConversionRate,
  platformWallet,
  platformFee,
  hint,
) {
  let gasConfig = { gasLimit: ZERO_BN, gasPrice: ZERO_BN };

  // Configure gas limit
  // Method 1: Use estimateGas function, add buffer
  let gasLimit =
    await KyberNetworkProxyContract.estimateGas.tradeWithHintAndFee(
      srcTokenAddress,
      srcQty,
      destTokenAddress,
      destAddress,
      maxDestAmount,
      minConversionRate,
      platformWallet,
      platformFee,
      hint,
    );

  gasConfig.gasLimit = gasLimit.mul(BN.from(110)).div(BN.from(100));

  // Method 2: Use /gasLimit API (only Ropsten and mainnet)
  // let gasLimitRequest = await fetch(
  //   `https://${NETWORK == "mainnet" ? "" : NETWORK + "-"}api.kyber.network/gas_limit?` +
  //   `source=${srcTokenAddress}&dest=${destTokenAddress}&amount=${srcQty}`
  //   );

  // let gasLimit = await gasLimitRequest.json();
  // if (gasLimit.error) {
  //   console.log(gasLimit);
  //   process.exit(0);
  // } else {
  //   gasConfig.gasLimit = BN.from(gasLimit.data);
  // }

  // Configure gas price
  let maxGasPrice = await KyberNetworkProxyContract.maxGasPrice();
  // Method 1: Fetch gasPrice
  let gasPrice = await provider.getGasPrice();

  //Method 2: Manual gasPrice input
  // let gasPrice = BN.from(30).mul((BN.from(10).mul(BN.from(9))));

  // Check against maxGasPrice
  gasConfig.gasPrice = gasPrice.gt(maxGasPrice) ? maxGasPrice : gasPrice;
  return gasConfig;
}

Step 4: Executing Trade

We can finally make a call to execute the trade.

let ethValue = SRC_TOKEN_ADDRESS == ETH_ADDRESS ? SRC_QTY : ZERO_BN;

await KyberNetworkProxyContract.tradeWithHintAndFee(
  SRC_TOKEN_ADDRESS,
  SRC_QTY,
  DEST_TOKEN_ADDRESS,
  USER_WALLET.address, // destAddress
  MAX_UINT256, // maxDestAmount: set to be arbitrarily large
  minConversionRate,
  PLATFORM_WALLET,
  PLATFORM_FEE,
  hint,
  {
    value: ethValue,
    gasLimit: gasConfig.gasLimit,
    gasPrice: gasConfig.gasPrice,
  },
);

Tying Everything Together

The main function will combine the different functions together to obtain the conversion rate and execute the trade.

async function main() {
  // Step 1: Check and approve allowance if needed
  await checkAndApproveTokenForTrade(
    srcTokenContract,
    USER_WALLET.address,
    SRC_QTY,
  );

  let hint = EMPTY_HINT; // build hint here (see section on reserve routing)
  // Step 2: Get rate for trade
  let minConversionRate =
    await KyberNetworkProxyContract.getExpectedRateAfterFee(
      SRC_TOKEN_ADDRESS,
      DEST_TOKEN_ADDRESS,
      SRC_QTY,
      PLATFORM_FEE,
      hint,
    );

  // Step 3: Get gas limit estimates and price
  let gasConfig = await getGasConfig(
    KyberNetworkProxyContract,
    provider,
    SRC_TOKEN_ADDRESS,
    DEST_TOKEN_ADDRESS,
    SRC_QTY,
    USER_WALLET.address,
    MAX_UINT256,
    minConversionRate,
    PLATFORM_WALLET,
    PLATFORM_FEE,
    hint,
  );

  // Step 4: Execute trade
  let ethValue = SRC_TOKEN_ADDRESS == ETH_ADDRESS ? SRC_QTY : ZERO_BN;

  console.log('Executing Trade...');
  await KyberNetworkProxyContract.tradeWithHintAndFee(
    SRC_TOKEN_ADDRESS,
    SRC_QTY,
    DEST_TOKEN_ADDRESS,
    USER_WALLET.address, // destAddress
    MAX_UINT256, // maxDestAmount: set to be arbitrarily large
    minConversionRate,
    PLATFORM_WALLET,
    PLATFORM_FEE,
    hint,
    {
      value: ethValue,
      gasLimit: gasConfig.gasLimit,
      gasPrice: gasConfig.gasPrice,
    },
  );

  // Quit the program
  process.exit(0);
}

Full code example

Before running this code example, the following fields need to be modified:

  1. Change INFURA_PROJECT_ID to your Infura Project ID.

  2. Change PRIVATE_KEY to the private key (with 0x prefix) of the Ethereum wallet holding Ether.

  3. Change PLATFORM_WALLET to a wallet address for platform fees.

// DISCLAIMER: Code snippets in this guide are just examples and you
// should always do your own testing. If you have questions, visit our
// https://t.me/KyberDeveloper.

const ethers = require('ethers');
const BN = ethers.BigNumber;
const fetch = require('node-fetch');

const NETWORK = 'ropsten';
const PROJECT_ID = 'INFURA_PROJECT_ID'; // Replace this with your own Project ID
const provider = new ethers.getDefaultProvider(NETWORK, { infura: PROJECT_ID });

// Universal Constants
const ETH_ADDRESS = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
const ZERO_BN = ethers.constants.Zero;
const MAX_UINT256 = ethers.constants.MaxUint256;
const EMPTY_HINT = '0x';

// Tokens and srcQty
const SRC_TOKEN_ADDRESS = '0x7b2810576aa1cce68f2b118cef1f36467c648f92'; // Ropsten KNC address
const DEST_TOKEN_ADDRESS = '0xad6d458402f60fd3bd25163575031acdce07538d'; // Ropsten DAI address
const SRC_DECIMALS = new BN.from(18);
const SRC_QTY = BN.from(100).mul(BN.from(10).pow(SRC_DECIMALS)); // 100 KNC

// Contract ABIs and proxy address
const IERC20_ABI = [
  {
    anonymous: false,
    inputs: [
      {
        indexed: true,
        internalType: 'address',
        name: '_owner',
        type: 'address',
      },
      {
        indexed: true,
        internalType: 'address',
        name: '_spender',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'uint256',
        name: '_value',
        type: 'uint256',
      },
    ],
    name: 'Approval',
    type: 'event',
  },
  {
    inputs: [
      { internalType: 'address', name: '_owner', type: 'address' },
      { internalType: 'address', name: '_spender', type: 'address' },
    ],
    name: 'allowance',
    outputs: [{ internalType: 'uint256', name: 'remaining', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'address', name: '_spender', type: 'address' },
      { internalType: 'uint256', name: '_value', type: 'uint256' },
    ],
    name: 'approve',
    outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function',
  },
  {
    inputs: [{ internalType: 'address', name: '_owner', type: 'address' }],
    name: 'balanceOf',
    outputs: [{ internalType: 'uint256', name: 'balance', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [],
    name: 'decimals',
    outputs: [{ internalType: 'uint8', name: 'digits', type: 'uint8' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [],
    name: 'totalSupply',
    outputs: [{ internalType: 'uint256', name: 'supply', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'address', name: '_to', type: 'address' },
      { internalType: 'uint256', name: '_value', type: 'uint256' },
    ],
    name: 'transfer',
    outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'address', name: '_from', type: 'address' },
      { internalType: 'address', name: '_to', type: 'address' },
      { internalType: 'uint256', name: '_value', type: 'uint256' },
    ],
    name: 'transferFrom',
    outputs: [{ internalType: 'bool', name: 'success', type: 'bool' }],
    stateMutability: 'nonpayable',
    type: 'function',
  },
];
const IKyberNetworkProxy_ABI = [
  {
    anonymous: false,
    inputs: [
      {
        indexed: true,
        internalType: 'address',
        name: 'trader',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'contract IERC20',
        name: 'src',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'contract IERC20',
        name: 'dest',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'address',
        name: 'destAddress',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'uint256',
        name: 'actualSrcAmount',
        type: 'uint256',
      },
      {
        indexed: false,
        internalType: 'uint256',
        name: 'actualDestAmount',
        type: 'uint256',
      },
      {
        indexed: false,
        internalType: 'address',
        name: 'platformWallet',
        type: 'address',
      },
      {
        indexed: false,
        internalType: 'uint256',
        name: 'platformFeeBps',
        type: 'uint256',
      },
    ],
    name: 'ExecuteTrade',
    type: 'event',
  },
  {
    inputs: [],
    name: 'enabled',
    outputs: [{ internalType: 'bool', name: '', type: 'bool' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'contract ERC20', name: 'src', type: 'address' },
      { internalType: 'contract ERC20', name: 'dest', type: 'address' },
      { internalType: 'uint256', name: 'srcQty', type: 'uint256' },
    ],
    name: 'getExpectedRate',
    outputs: [
      { internalType: 'uint256', name: 'expectedRate', type: 'uint256' },
      { internalType: 'uint256', name: 'worstRate', type: 'uint256' },
    ],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'contract IERC20', name: 'src', type: 'address' },
      { internalType: 'contract IERC20', name: 'dest', type: 'address' },
      { internalType: 'uint256', name: 'srcQty', type: 'uint256' },
      { internalType: 'uint256', name: 'platformFeeBps', type: 'uint256' },
      { internalType: 'bytes', name: 'hint', type: 'bytes' },
    ],
    name: 'getExpectedRateAfterFee',
    outputs: [
      { internalType: 'uint256', name: 'expectedRate', type: 'uint256' },
    ],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [],
    name: 'maxGasPrice',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'view',
    type: 'function',
  },
  {
    inputs: [
      { internalType: 'contract IERC20', name: 'src', type: 'address' },
      { internalType: 'uint256', name: 'srcAmount', type: 'uint256' },
      { internalType: 'contract IERC20', name: 'dest', type: 'address' },
      { internalType: 'address payable', name: 'destAddress', type: 'address' },
      { internalType: 'uint256', name: 'maxDestAmount', type: 'uint256' },
      { internalType: 'uint256', name: 'minConversionRate', type: 'uint256' },
      {
        internalType: 'address payable',
        name: 'platformWallet',
        type: 'address',
      },
    ],
    name: 'trade',
    outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
    stateMutability: 'payable',
    type: 'function',
  },
  {
    inputs