gmx.gas_utils
Documentation for eth_defi.gmx.gas_utils Python module.
GMX Gas Utilities
Functions
|
Calculate execution fee using GMX's formula. |
Clear the module-level gas limits 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. |
|
|
|
|
|
|
|
- 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
- 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