gmx.config

Documentation for eth_defi.gmx.config Python module.

GMX Configuration Module.

This module provides the production-ready configuration management system for GMX protocol integration, implementing automatic network detection, secure wallet abstraction, and comprehensive authentication strategy support. It represents the mature, stable implementation used in production trading systems and financial applications.

Production Configuration Architecture

This implementation focuses on reliability, security, and operational simplicity for production environments. Automatic network detection eliminates configuration errors, while sophisticated wallet abstraction provides universal compatibility without compromising security or performance characteristics of individual wallet implementations.

Key Production Features

  • Automatic Chain Detection: Eliminates network configuration errors

  • Universal Wallet Support: Compatible with all BaseWallet implementations

  • Security Isolation: Strict separation between read and write operations

  • Production Stability: Thoroughly tested patterns for reliable operation

  • Backward Compatibility: Preserves legacy interfaces for existing systems

Security-First Design

The production configuration implements defense-in-depth security patterns where sensitive operations are isolated into separate configuration contexts. Read-only configurations provide safe data access, while write configurations implement comprehensive validation and secure credential delegation.

Operational Reliability

Production systems require configuration management that never fails unexpectedly. This implementation includes comprehensive error handling, automatic validation, and clear diagnostic information to prevent and resolve operational issues quickly.

Multi-Environment Support

The configuration system automatically adapts to different blockchain networks while maintaining consistent interfaces and operational patterns. This enables the same application code to work seamlessly across Arbitrum, Avalanche, and other supported networks.

Example:

# Basic configuration
from web3 import Web3
from eth_defi.gmx.config import GMXConfig

# Configuration with automatic network detection
web3 = Web3(Web3.HTTPProvider("https://arb1.arbitrum.io/rpc"))

# Read-only configuration
config = GMXConfig(web3)
assert config.get_chain() == "arbitrum"

# Configuration with wallet address for transaction building
config_with_address = GMXConfig(web3, user_wallet_address="0x...")
assert config_with_address.has_write_capability()

# Get configuration manager for GMX protocol classes
gmx_config_manager = config.get_config()
print(f"Connected to {gmx_config_manager.chain} (ID: {gmx_config_manager.chain_id})")

Design Philosophy

The production configuration embodies the principle of “secure by default” where the safest operational mode is also the most convenient. Automatic detection reduces human error, while security isolation prevents accidental exposure of sensitive operations.

Note

This is the recommended configuration implementation for production deployments where reliability and security are paramount considerations.

Warning

Production configurations with write capabilities enable real financial transactions. Ensure proper security procedures and testing before deployment in environments with significant financial exposure.

Classes

GMXConfig

Production-grade configuration management system for secure GMX protocol integration.

GMXConfigManager

GMX protocol configuration manager.

class GMXConfigManager

Bases: object

GMX protocol configuration manager.

Manages configuration parameters for GMX protocol operations including blockchain network details and user addresses. Follows the transaction-building pattern where transactions are prepared separately from signing.

Variables
  • chain – Blockchain network name

  • chain_id – Blockchain network ID

  • user_wallet_address – Wallet address for operations

Initialize configuration manager.

Parameters
  • chain – Blockchain network name (e.g., ‘arbitrum’, ‘avalanche’)

  • chain_id – Blockchain network ID

  • user_wallet_address – Wallet address for operations

  • web3 – Web3 instance for blockchain connectivity

__init__(chain, chain_id, user_wallet_address=None, web3=None)

Initialize configuration manager.

Parameters
  • chain (str) – Blockchain network name (e.g., ‘arbitrum’, ‘avalanche’)

  • chain_id (int) – Blockchain network ID

  • user_wallet_address (Optional[str]) – Wallet address for operations

  • web3 (Optional[web3.main.Web3]) – Web3 instance for blockchain connectivity

get_web3_connection()

Get Web3 connection instance.

Required for gmx_python_sdk compatibility.

Returns

Web3 instance

Raises

ValueError – If Web3 instance is not configured

Return type

web3.main.Web3

class GMXConfig

Bases: object

Production-grade configuration management system for secure GMX protocol integration.

This class provides the stable, production-ready implementation of configuration management that powers real trading systems and financial applications. It implements automatic network detection, universal wallet compatibility, and comprehensive security controls while maintaining the simplicity and reliability required for production deployment.

The production implementation prioritizes operational reliability, security isolation, and automatic error prevention. Network parameters are detected automatically to eliminate configuration errors, wallet integration uses secure adapter patterns to preserve individual security models, and comprehensive validation prevents common operational pitfalls.

The configuration system implements strict security boundaries between read and write operations. Read configurations provide safe data access without any exposure to sensitive credentials, while write configurations implement secure credential delegation through validated adapter interfaces.

Production systems require configuration management that operates predictably under all conditions. This implementation includes comprehensive error handling, automatic parameter validation, and clear diagnostic information to enable rapid troubleshooting and reliable operation.

Modern financial applications must support diverse wallet implementations to accommodate different security requirements and operational preferences. The configuration system provides seamless integration with any BaseWallet- compatible implementation while preserving the unique capabilities of each wallet type.

Variables
  • web3 (Web3) – Web3 instance providing blockchain connectivity and network context

  • chain (str) – Automatically detected blockchain network identifier

Initialize GMX configuration with automatic network detection.

Automatically detects blockchain network parameters from Web3 connections. Follows the transaction-building pattern where transactions are prepared separately from signing.

Parameters
  • web3 – Web3 instance connected to the target blockchain network

  • user_wallet_address – Optional wallet address for operations

  • wallet – Optional HotWallet instance for transaction signing (used by CCXT wrapper)

Raises

AssertionError – When the Web3 connection targets an unsupported blockchain network or automatic network detection fails due to connectivity issues

__init__(web3, user_wallet_address=None, wallet=None)

Initialize GMX configuration with automatic network detection.

Automatically detects blockchain network parameters from Web3 connections. Follows the transaction-building pattern where transactions are prepared separately from signing.

Parameters
  • web3 (web3.main.Web3) – Web3 instance connected to the target blockchain network

  • user_wallet_address (Optional[str]) – Optional wallet address for operations

  • wallet – Optional HotWallet instance for transaction signing (used by CCXT wrapper)

Raises

AssertionError – When the Web3 connection targets an unsupported blockchain network or automatic network detection fails due to connectivity issues

get_config()

Get the configuration manager for GMX operations.

Returns the configuration manager that can be used with GMX protocol classes for transaction preparation and data access.

Returns

GMXConfigManager instance configured for the current chain

Return type

eth_defi.gmx.config.GMXConfigManager

has_write_capability()

Check if a wallet address is configured.

Since transaction signing is handled separately, this simply checks if a user wallet address has been provided for transaction building.

Returns

True if wallet address is configured, False otherwise

Return type

bool

get_chain()

Retrieve the automatically detected blockchain network identifier.

This method returns the network name that was automatically detected from the Web3 connection during configuration initialization. Automatic detection ensures operational consistency and eliminates network configuration errors in production deployments.

Automatic network detection prevents configuration mismatches that could cause operational failures or financial losses in production trading systems and financial applications.

Returns

Blockchain network identifier automatically detected from Web3 connection, ensuring operational consistency and reliability

Return type

str

get_wallet_address()

Retrieve the wallet address associated with this configuration.

This method returns the Ethereum address that will be used for transaction operations when write capabilities are available. The address may be explicitly specified or automatically derived from wallet implementations using production-tested resolution logic.

The configuration system implements reliable address resolution that prioritizes explicit specifications while providing secure fallbacks to wallet-derived addresses when appropriate for production operation.

Returns

Ethereum wallet address in standard format, or None when the configuration operates in read-only mode without transaction capabilities

Return type

Optional[str]

get_network_info()

Provide comprehensive network configuration information for operational monitoring.

This method returns detailed information about blockchain network configuration including automatically detected parameters, connectivity details, and validation status. The information supports operational monitoring, debugging, and validation in production environments.

The network information includes all parameters necessary for operational monitoring systems to validate connectivity, track network status, and diagnose operational issues in production deployments.

Returns

Dictionary containing comprehensive network configuration including automatically detected chain identifier, RPC endpoint information, and blockchain-specific parameters

Return type

dict[str, Any]