Skip to main content

getNaiveEstimatedGasBySwapCount

This module provides a utility function for calculating estimated gas costs based on the number of swaps in a transaction.

Methods

This module exports a single function, available from @gmx-io/sdk/utils/fees.

getNaiveEstimatedGasBySwapCount

getNaiveEstimatedGasBySwapCount(
singleSwap: GasLimitsConfig["singleSwap"],
swapsCount: number
): bigint

Returns singleSwap × swapsCount. Use this to estimate the swap portion of an order's gas limit when building a quick pre-check or a UI estimate. Pass gasLimits.singleSwap as the first argument.

import { getNaiveEstimatedGasBySwapCount } from "@gmx-io/sdk/utils/fees";

// 2-hop swap path: USDC → WETH → WBTC
const swapGas = getNaiveEstimatedGasBySwapCount(gasLimits.singleSwap, 2);
// swapGas = gasLimits.singleSwap * 2n