gmx.whitelist
Documentation for eth_defi.gmx.whitelist Python module.
GMX market whitelisting for Lagoon vaults.
This module provides utilities for fetching and whitelisting GMX markets in Lagoon vault Guard contracts. It enables programmatic management of which GMX perpetual markets are allowed for trading through a Lagoon vault.
Getting a list of GMX markets
To fetch all available GMX markets on a chain:
from web3 import Web3
from eth_defi.gmx.whitelist import fetch_all_gmx_markets
web3 = Web3(Web3.HTTPProvider("https://arb1.arbitrum.io/rpc"))
markets = fetch_all_gmx_markets(web3)
for address, info in markets.items():
print(f"{info.market_symbol}: {address}")
Using the CLI script:
export JSON_RPC_ARBITRUM="https://..."
python scripts/gmx/list-gmx-markets.py
# For Python-pasteable output
python scripts/gmx/list-gmx-markets.py --python
Whitelisting markets in Guard contract
Markets must be whitelisted individually by the vault owner (Safe). After vault deployment, impersonate or execute through the Safe to whitelist:
# Direct call (only works if caller is Guard owner)
guard.functions.whitelistGMXMarket(
"0x70d95587d40A2caf56bd97485aB3Eec10Bee6336", # ETH/USD market
"ETH/USD perpetuals",
).transact({"from": safe_address})
Or use the helper function for batch whitelisting:
from eth_defi.gmx.whitelist import whitelist_gmx_markets
tx_hashes = whitelist_gmx_markets(
guard=guard_contract,
markets=[ETH_USD_MARKET, BTC_USD_MARKET],
owner=safe_address,
)
GMX deployment configuration
When deploying a new Lagoon vault with GMX support, use the GMXDeployment
dataclass to configure all GMX-related whitelisting:
from eth_defi.gmx.whitelist import GMXDeployment
# create_arbitrum() dynamically fetches the latest GMX contract addresses
gmx_deployment = GMXDeployment.create_arbitrum(
markets=[
"0x70d95587d40A2caf56bd97485aB3Eec10Bee6336", # ETH/USD
"0x47c031236e19d024b42f8AE6780E44A573170703", # BTC/USD
],
)
# Pass to deployment function
deployment = deploy_automated_lagoon_vault(
...
gmx_deployment=gmx_deployment,
)
Security considerations
Never use anyAsset=True in production: This bypasses all market checks
Whitelist specific markets only: Restrict trading to known, liquid markets
Review markets before whitelisting: Verify the market address on Arbiscan
Markets can be removed: Use
removeGMXMarket()to revoke accessReceiver must be whitelisted: The Safe must be whitelisted as a receiver before GMX trading will work
See also
eth_defi.gmx.core.markets- Low-level market data fetchingeth_defi.erc_4626.vault_protocol.lagoon.deployment.deploy_automated_lagoon_vault()- Vault deployment with GMX supporteth_defi.gmx.lagoon.wallet- GMX trading through Lagoon wallet
Module Attributes
GMX contract addresses on Arbitrum mainnet. |
|
Popular GMX markets on Arbitrum with human-readable names |
Functions
|
Fetch all available GMX markets from the blockchain. |
Fetch current GMX contract addresses for Arbitrum mainnet. |
|
|
Get iterator of all GMX market addresses for a chain. |
|
Remove GMX markets from Guard whitelist. |
|
Set up complete GMX whitelisting on a Guard contract. |
|
Whitelist multiple GMX markets in a Guard contract. |
Classes
GMX deployment configuration for Guard whitelisting. |
- GMX_ARBITRUM_ADDRESSES: dict[str, eth_typing.evm.HexAddress] = {'exchange_router': '0x7C68C7866A64FA2160F78EEaE12217FFbf871fa8', 'order_vault': '0x31eF83a530Fde1B38EE9A18093A333D8Bbbc40D5', 'synthetics_router': '0x7452c558d45f8afC8c83dAe62C3f8A5BE19c71f6'}
GMX contract addresses on Arbitrum mainnet.
Warning
These addresses may become stale when GMX upgrades contracts. Prefer using
get_gmx_arbitrum_addresses()orGMXDeployment.create_arbitrum()which fetch addresses dynamically from the GMX contracts registry.These are the official GMX V2 contract addresses required for whitelisting GMX trading in a Guard contract.
- get_gmx_arbitrum_addresses()
Fetch current GMX contract addresses for Arbitrum mainnet.
Unlike
GMX_ARBITRUM_ADDRESSESwhich may become stale, this function dynamically fetches the latest addresses from the GMX contracts registry on GitHub.- Returns
Dictionary with keys
exchange_router,synthetics_router,order_vault.- Raises
ValueError – If addresses cannot be fetched from the GMX API.
- Return type
- GMX_POPULAR_MARKETS: dict[str, eth_typing.evm.HexAddress] = {'AAVE/USD': '0xbfAE4fd8c6C60a13f7717160C67111D744198D9C', 'ARB/USD': '0xC25cEf6061Cf5dE5eb761b50E4743c1F5D7E5407', 'AVAX/USD': '0xB7e69749E3d2EDd90ea59A4932EFEa2D41E245d7', 'BTC/USD': '0x47c031236e19d024b42f8AE6780E44A573170703', 'DOGE/USD': '0x6853EA96FF216fAb11D2d930CE3C508556A4bdc4', 'ETH/USD': '0x70d95587d40A2caf56bd97485aB3Eec10Bee6336', 'LINK/USD': '0x7f1fa204bb700853D36994DA19F830b6Ad18455C', 'NEAR/USD': '0x63Dc80EE90F26363B3FCD609F64CA3045b44199E', 'SOL/USD': '0x09400D9DB990D5ed3f35D7be61DfAEB900Af03C9'}
Popular GMX markets on Arbitrum with human-readable names
Use these addresses when whitelisting specific markets. For a full list, use
fetch_all_gmx_markets().
- class GMXDeployment
Bases:
objectGMX deployment configuration for Guard whitelisting.
This dataclass encapsulates all GMX-related configuration needed when deploying a Lagoon vault with GMX perpetuals trading support. Pass an instance to
deploy_automated_lagoon_vault()to automatically whitelist GMX contracts and markets during deployment.Example:
# Recommended: use factory method with dynamic address fetch gmx_deployment = GMXDeployment.create_arbitrum( markets=[ "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336", # ETH/USD "0x47c031236e19d024b42f8AE6780E44A573170703", # BTC/USD ], )- exchange_router: eth_typing.evm.HexAddress
GMX ExchangeRouter contract address
- synthetics_router: eth_typing.evm.HexAddress
GMX SyntheticsRouter contract address
- order_vault: eth_typing.evm.HexAddress
GMX OrderVault contract address
- markets: list[eth_typing.evm.HexAddress]
List of GMX market addresses to whitelist for trading
- tokens: list[eth_typing.evm.HexAddress] | None
Optional: specific tokens to whitelist as collateral If None, tokens are not explicitly whitelisted (use anyAsset or manual whitelisting)
- classmethod create_arbitrum(markets=None, tokens=None)
Create a GMXDeployment for Arbitrum mainnet with dynamically fetched addresses.
Fetches the latest GMX contract addresses from the GMX contracts registry on GitHub, ensuring addresses are always up-to-date even after GMX upgrades.
- Parameters
markets (list[eth_typing.evm.HexAddress] | None) – List of market addresses to whitelist. If None, no markets are whitelisted.
tokens (list[eth_typing.evm.HexAddress] | None) – List of token addresses to whitelist as collateral.
- Returns
GMXDeployment configured for Arbitrum mainnet.
- Raises
ValueError – If addresses cannot be fetched from the GMX API.
- Return type
- __init__(exchange_router, synthetics_router, order_vault, markets=<factory>, tokens=None)
- Parameters
exchange_router (eth_typing.evm.HexAddress) –
synthetics_router (eth_typing.evm.HexAddress) –
order_vault (eth_typing.evm.HexAddress) –
markets (list[eth_typing.evm.HexAddress]) –
tokens (list[eth_typing.evm.HexAddress] | None) –
- Return type
None
- fetch_all_gmx_markets(web3)
Fetch all available GMX markets from the blockchain.
This function queries the GMX Reader contract to get a complete list of all available perpetual markets with their metadata.
Example:
from web3 import Web3 from eth_defi.gmx.whitelist import fetch_all_gmx_markets web3 = Web3(Web3.HTTPProvider("https://arb1.arbitrum.io/rpc")) markets = fetch_all_gmx_markets(web3) for address, info in markets.items(): print(f"{info.market_symbol}: {address}")- Parameters
web3 (web3.main.Web3) – Web3 instance connected to Arbitrum or another GMX-supported chain.
- Returns
Dictionary mapping market addresses to MarketInfo objects.
- Return type
dict[eth_typing.evm.HexAddress, eth_defi.gmx.core.markets.MarketInfo]
- get_gmx_market_addresses(web3)
Get iterator of all GMX market addresses for a chain.
Convenience function for scripting and batch operations.
Example:
from web3 import Web3 from eth_defi.gmx.whitelist import get_gmx_market_addresses web3 = Web3(Web3.HTTPProvider("https://arb1.arbitrum.io/rpc")) for market_address in get_gmx_market_addresses(web3): print(market_address)- Parameters
web3 (web3.main.Web3) – Web3 instance connected to Arbitrum or another GMX-supported chain.
- Returns
Iterator of market addresses.
- Return type
- whitelist_gmx_markets(guard, markets, owner, notes_prefix='GMX market')
Whitelist multiple GMX markets in a Guard contract.
This function whitelists each market individually by calling
whitelistGMXMarket()on the Guard contract. The caller must be the Guard owner (typically the Safe).Example:
from eth_defi.gmx.whitelist import whitelist_gmx_markets tx_hashes = whitelist_gmx_markets( guard=guard_contract, markets=[ "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336", # ETH/USD "0x47c031236e19d024b42f8AE6780E44A573170703", # BTC/USD ], owner=safe_address, )- Parameters
guard (web3.contract.contract.Contract) – Guard contract instance (GuardV0).
markets (list[eth_typing.evm.HexAddress]) – List of GMX market addresses to whitelist.
owner (eth_typing.evm.HexAddress) – Address of the Guard owner (must have permission to whitelist).
notes_prefix (str) – Prefix for the notes string in each whitelist call.
- Returns
List of transaction hashes for each whitelist operation.
- Return type
list[hexbytes.main.HexBytes]
- remove_gmx_markets(guard, markets, owner, notes_prefix='Remove GMX market')
Remove GMX markets from Guard whitelist.
This function removes each market individually by calling
removeGMXMarket()on the Guard contract.- Parameters
guard (web3.contract.contract.Contract) – Guard contract instance (GuardV0).
markets (list[eth_typing.evm.HexAddress]) – List of GMX market addresses to remove.
owner (eth_typing.evm.HexAddress) – Address of the Guard owner (must have permission).
notes_prefix (str) – Prefix for the notes string in each remove call.
- Returns
List of transaction hashes for each remove operation.
- Return type
list[hexbytes.main.HexBytes]
- setup_gmx_whitelisting(guard, gmx_deployment, owner, safe_address)
Set up complete GMX whitelisting on a Guard contract.
This function performs all necessary whitelisting for GMX trading:
Whitelist GMX router contracts (ExchangeRouter, SyntheticsRouter, OrderVault)
Whitelist the Safe as a receiver
Whitelist all specified markets
Optionally whitelist collateral tokens
Example:
from eth_defi.gmx.whitelist import GMXDeployment, setup_gmx_whitelisting gmx = GMXDeployment.create_arbitrum( markets=["0x70d95587d40A2caf56bd97485aB3Eec10Bee6336"], ) tx_hashes = setup_gmx_whitelisting( guard=guard_contract, gmx_deployment=gmx, owner=safe_address, safe_address=safe_address, )- Parameters
guard (web3.contract.contract.Contract) – Guard contract instance (GuardV0).
gmx_deployment (eth_defi.gmx.whitelist.GMXDeployment) – GMX deployment configuration with router and market addresses.
owner (eth_typing.evm.HexAddress) – Address of the Guard owner (must have permission to whitelist).
safe_address (eth_typing.evm.HexAddress) – Safe address to whitelist as receiver.
- Returns
Dictionary with transaction hashes grouped by operation type.
- Return type