GMXGasMonitor

Documentation for eth_defi.gmx.gas_monitor.GMXGasMonitor Python class.

class GMXGasMonitor

Bases: object

Gas 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

oracle_prices

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.

get_native_token_price_usd()

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

eth_defi.gmx.gas_monitor.GasCheckResult

estimate_transaction_gas(tx, from_addr)

Estimate gas for a transaction with safety buffer.

Parameters
Returns

GasEstimate with raw and buffered values

Return type

eth_defi.gmx.gas_monitor.GasEstimate

log_gas_estimate(estimate, operation)

Log gas estimate details for an operation.

Parameters
Return type

None

log_gas_usage(receipt, native_price_usd, operation, estimated_gas=None)

Log actual gas used after transaction confirmation.

Parameters
  • receipt (dict) – Transaction receipt

  • native_price_usd (float | None) – Current native token price in USD

  • operation (str) – Description of the operation

  • estimated_gas (int | None) – Original gas estimate for efficiency calculation

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