Skip to content

Supporting Dex Protocols

Yuichiro Aoki edited this page Apr 19, 2022 · 2 revisions

Protocol

Protocol Protocol Name
0 Uniswap V3
1 Sushiswap
2 Quickswap
3 Jetswap
4 Polycat
5 Apeswap
6 Waultswap
8 DODO

Data

UniswapV2 Fork Dex

Input a router address for a uniswapV2 fork protocol to swap.

data: ethers.utils.defaultAbiCoder.encode(
	["address"],
	[findRouterFromProtocol(1)]
),

UniswapV3

Input a uniswapV3 router address and a pool fee of a uniswapV3 pool you swap tokens on.
Note: a pool fee has to be multiplied by 10,000.

data: ethers.utils.defaultAbiCoder.encode(
	["address", "uint24"],
	// 0.05 % => 500 (Input USDC/WETH pool fee)
	[findRouterFromProtocol(0), 500]
),

Examples

USDC - WETH (100% Sushiswap) -> WETH - USDC (100% UniswapV3)

  const tx = await Flashloan.dodoFlashLoan(
    {
      flashLoanPool: dodoV2Pool.WETH_USDC,
      loanAmount: getBigNumber(1000, 6),
      firstRoutes: [
        {
          hops: [
            {
              swaps: [
                {
                  // protocol number
                  protocol: 1,
                  // trading ratio (100% -> 10000, 1% -> 100)
                  part: 10000,
                  // byte data used for swapping
                  data: ethers.utils.defaultAbiCoder.encode(
                    ["address"],
                    [findRouterFromProtocol(1)]
                  ),
                },
              ],
              path: [erc20Address.USDC, erc20Address.WETH],
            },
          ],
          part: 10000,
        },
      ],
      secondRoutes: [
        {
          hops: [
            {
              swaps: [
                {
                  // UniswapV3
                  protocol: 0,
                  part: 10000,
                  data: ethers.utils.defaultAbiCoder.encode(
                    ["address", "uint24"],
                    // 0.05 % => 500 (Input USDC/WETH pool fee)
                    [findRouterFromProtocol(0), 500]
                  ),
                },
              ],
              path: [erc20Address.WETH, erc20Address.USDC],
            },
          ],
          part: 10000,
        },
      ],
    },
    {
      gasLimit: 1000000,
      // refer to https://polygonscan.com/gastracker
      gasPrice: ethers.utils.parseUnits("60", "gwei"),
    }
  );
Clone this wiki locally