Fee

How to calculate fee rate?

Fee means the coin used to pay the protocol fee rate during the transaction differs from the gas consumed by the execution of the smart contract. Different pools has different fee rate. Each tick spacing corresponds to a specific fee rate.

tick spacingfee rate

2

0.0001

10

0.0005

60

0.0025

200

0.01

  1. For a single pathway, the fee is equal to the input amount multiplied by the fee rate.

  2. In the case of multiple pathways or paths involving intermediary coins, we need to calculate the input amount multiplied by the fee rate for each individual swap. Then, convert all these amounts to the corresponding quantity in the input coin and sum them up.

In SDK, we provide sdk.Swap.calculateSwapFee() method.

Example

    const res = await sdk.RouterV2.getBestRouter(USDT, USDC, 100000000, true, 5, '', undefined, true, false)

    const fee =  sdk.Swap.calculateSwapFee(res.result.splitPaths)
    console.log('fee: ', fee)

Last updated