gmx.gas_utils
Documentation for eth_defi.gmx.gas_utils Python module.
GMX Gas Utilities
Functions
|
Apply the execution buffer multiplier to a base execution fee. |
|
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. |
|
|
|
|
|
|
|
Check the execution buffer value and log warnings if it is dangerously low. |
|
- 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
- validate_execution_buffer(execution_buffer)
Check the execution buffer value and log warnings if it is dangerously low.
This does not raise an exception — it only emits log messages so that the caller can proceed with the order while being informed of the risk.
- Parameters
execution_buffer (float) – The multiplier to validate. Values below
EXECUTION_BUFFER_CRITICAL_THRESHOLD(1.2) emit a critical error; values belowEXECUTION_BUFFER_WARNING_THRESHOLD(1.5) emit a warning.- Return type
None
- apply_execution_buffer(base_fee, execution_buffer, validate=True)
Apply the execution buffer multiplier to a base execution fee.
Multiplies the base fee by the given buffer to produce a fee high enough for GMX keepers to execute profitably. Any excess is refunded by GMX.
- Parameters
base_fee (int) – Raw execution fee in wei, typically
gas_limit * gas_price.execution_buffer (float) – Multiplier to apply. See
DEFAULT_EXECUTION_BUFFERfor the recommended default.validate (bool) – If
True(default), callvalidate_execution_buffer()before applying. Set toFalseto skip validation when the buffer has already been validated earlier in the call chain.
- Returns
The buffered execution fee in wei.
- Return type