GMXGasMonitor
Documentation for eth_defi.gmx.gas_monitor.GMXGasMonitor Python class.
- class GMXGasMonitor
Bases:
objectGas monitoring for GMX trading operations.
Provides balance checking, gas estimation, and logging for GMX trades. Integrates with GMX oracle for USD price calculations.
- Parameters
web3 – Web3 instance connected to the blockchain
chain – Chain name (‘arbitrum’, ‘avalanche’, ‘arbitrum_sepolia’)
config – Optional gas monitor configuration
Initialise the gas monitor.
- Parameters
web3 – Web3 instance connected to the blockchain
chain – Chain name (e.g., ‘arbitrum’, ‘avalanche’)
config – Gas monitoring configuration (uses defaults if None)
Attributes summary
Lazy-load oracle prices client.
Methods summary
__init__(web3, chain[, config])Initialise the gas monitor.
check_gas_balance(wallet_address)Check wallet gas balance against configured thresholds.
estimate_transaction_gas(tx, from_addr)Estimate gas for a transaction with safety buffer.
Fetch the native token (ETH/AVAX) price from GMX oracle.
log_gas_check_warning(gas_check)Log a warning for low gas balance.
log_gas_estimate(estimate, operation)Log gas estimate details for an operation.
log_gas_usage(receipt, native_price_usd, ...)Log actual gas used after transaction confirmation.
- __init__(web3, chain, config=None)
Initialise the gas monitor.
- Parameters
web3 (web3.main.Web3) – Web3 instance connected to the blockchain
chain (str) – Chain name (e.g., ‘arbitrum’, ‘avalanche’)
config (eth_defi.gmx.gas_monitor.GasMonitorConfig | None) – Gas monitoring configuration (uses defaults if None)
- property oracle_prices
Lazy-load oracle prices client.
- get_native_token_price_usd()
Fetch the native token (ETH/AVAX) price from GMX oracle.
- Returns
Price in USD, or None if unavailable
- Return type
float | None
- check_gas_balance(wallet_address)
Check wallet gas balance against configured thresholds.
- Parameters
wallet_address (Union[eth_typing.evm.HexAddress, str]) – Address to check balance for
- Returns
GasCheckResult with status and balance information
- Return type
- estimate_transaction_gas(tx, from_addr)
Estimate gas for a transaction with safety buffer.
- Parameters
tx (web3.types.TxParams) – Transaction parameters
from_addr (Union[eth_typing.evm.HexAddress, str]) – Address that will send the transaction
- Returns
GasEstimate with raw and buffered values
- Return type
- log_gas_estimate(estimate, operation)
Log gas estimate details for an operation.
- Parameters
estimate (eth_defi.gmx.gas_monitor.GasEstimate) – Gas estimate to log
operation (str) – Description of the operation (e.g., ‘GMX order’)
- Return type
None
- log_gas_usage(receipt, native_price_usd, operation, estimated_gas=None)
Log actual gas used after transaction confirmation.
- Parameters
- Returns
Tuple of (gas_cost_native, gas_cost_usd)
- Return type
tuple[decimal.Decimal, float | None]
- log_gas_check_warning(gas_check)
Log a warning for low gas balance.
- Parameters
gas_check (eth_defi.gmx.gas_monitor.GasCheckResult) – The gas check result to log
- Return type
None