gmx.gas_utils

Documentation for eth_defi.gmx.gas_utils Python module.

GMX Gas Utilities

Functions

calculate_execution_fee(gas_limits, gas_price)

Calculate execution fee using GMX's formula.

clear_gas_limits_cache()

Clear the module-level gas limits cache.

decrease_order_gas_limit_key()

deposit_gas_limit_key()

execution_gas_fee_base_amount_key()

execution_gas_fee_base_amount_v2_1_key()

execution_gas_fee_multiplier_key()

execution_gas_fee_per_oracle_price_key()

get_gas_limits(datastore_object[, use_cache])

Given a Web3 contract object of the datastore, return a dictionary with the gas limits (as integers) that correspond to various operations used for execution fee calculation.

increase_order_gas_limit_key()

single_swap_gas_limit_key()

swap_order_gas_limit_key()

withdraw_gas_limit_key()

get_gas_limits(datastore_object, use_cache=True)

Given a Web3 contract object of the datastore, return a dictionary with the gas limits (as integers) that correspond to various operations used for execution fee calculation.

Uses module-level caching to avoid repeated RPC calls for the same datastore. Gas limits are cached per (chain_id, datastore_address) combination.

Parameters
  • datastore_object (web3.contract.Contract) – The connected contract instance

  • use_cache (bool) – Whether to use cached values. Default is True

Returns

Gas limit values for various operations

Return type

dict[str, int]

clear_gas_limits_cache()

Clear the module-level gas limits cache.

Call this if you need to refresh gas limit values from the contract.

calculate_execution_fee(gas_limits, gas_price, order_type='decrease_order', oracle_price_count=2)

Calculate execution fee using GMX’s formula.

GMX calculates minimum execution fee as:

adjustedGasLimit = baseGasLimit + (oracleCount * perOracleGas) + applyFactor(estimatedGasLimit, multiplierFactor) minExecutionFee = adjustedGasLimit * tx.gasprice

Where applyFactor(value, factor) = value * factor / 10^30

Parameters
  • gas_limits (dict[str, int]) – Gas limits dictionary from get_gas_limits()

  • gas_price (int) – Gas price in wei (should be maxFeePerGas for EIP-1559)

  • order_type (str) – Order type key: “increase_order”, “decrease_order”, “swap_order”, etc.

  • oracle_price_count (int) – Number of oracle prices needed (typically 2 for most orders)

Returns

Calculated execution fee in wei

Return type

int