Swap

Here are 3 cases of swapping in Pangea's pool via router :

1. ERC20 --> ERC20

  • Before the swap request, you need to make an approve request to the router for the input token.

poolRouter.exactInputSingle({
          tokenIn: tokenInAddress, // input token address
          amountIn: BigNumber.from(amountIn), // amount of input token to swap
          amountOutMinimum: BigNumber.from(amountOutMinimum), // slippage
          pool: PoolAddress, // pool address
          to: recipient,     // recipient address
          unwrap: false      // always "false" for erc20 tokens
        });

2. ERC20 --> KLAY

  • Before the swap request, you need to make an approve request to the router for the input token.

poolRouter.exactInputSingle({
          tokenIn: tokenInAddress, // input token address
          amountIn: BigNumber.from(amountIn), // amount of input token to swap
          amountOutMinimum: BigNumber.from(amountOutMinimum), // slippage
          pool: PoolAddress, // pool address
          to: recipient,     // recipient address
          unwrap: true      // always "false" for erc20 tokens
        });

3. KLAY --> ERC20

poolRouter.exactInputSingle({
          // if input token is KLAY, set token address to 0 address
          tokenIn: "0x0000000000000000000000000000000000000000", 
          amountIn: BigNumber.from(amountIn),
          amountOutMinimum: BigNumber.from(amountOutMinimum),
          pool: PoolAddress,
          to: recipient,
          unwrap: false
        }, {
           // amount of KLAY to sent should be input like below
           value: BigNumber.from(amountIn)
        });

Last updated