Skip to main content

chains

This module provides chain configuration constants, types, and utilities for the GMX protocol. It includes chain IDs, names, gas configurations, execution fee settings, and helper functions for working with different blockchain networks supported by GMX.

Types

ContractsChainId

Type representing chain IDs where GMX contracts are deployed.

type ContractsChainId = typeof ARBITRUM | typeof AVALANCHE | typeof AVALANCHE_FUJI | typeof BOTANIX | typeof ARBITRUM_SEPOLIA;

ContractsChainIdProduction

Type representing production chain IDs where GMX contracts are deployed, excluding testnets.

type ContractsChainIdProduction = Exclude<ContractsChainId, typeof AVALANCHE_FUJI | typeof ARBITRUM_SEPOLIA>;

SettlementChainId

Type representing chain IDs used for settlement operations.

type SettlementChainId = typeof ARBITRUM_SEPOLIA | typeof ARBITRUM | typeof AVALANCHE;

SourceChainId

Type representing source chain IDs for cross-chain operations.

type SourceChainId = typeof SOURCE_OPTIMISM_SEPOLIA | typeof SOURCE_SEPOLIA | typeof SOURCE_BASE_MAINNET | typeof SOURCE_BSC_MAINNET;

AnyChainId

Union type representing any supported chain ID.

type AnyChainId = ContractsChainId | SettlementChainId | SourceChainId;

ChainName

Type representing human-readable chain names.

type ChainName = "Arbitrum" | "Avalanche" | "Avalanche Fuji" | "Arbitrum Sepolia" | "Optimism Sepolia" | "Sepolia" | "Botanix" | "Base" | "BNB";

Constants

  • AVALANCHE: number - Avalanche mainnet chain ID
  • AVALANCHE_FUJI: number - Avalanche Fuji testnet chain ID
  • ARBITRUM: number - Arbitrum mainnet chain ID
  • BOTANIX: number - Botanix mainnet chain ID
  • ETH_MAINNET: number - Ethereum mainnet chain ID
  • ARBITRUM_SEPOLIA: number - Arbitrum Sepolia testnet chain ID
  • SOURCE_OPTIMISM_SEPOLIA: number - Optimism Sepolia source chain ID
  • SOURCE_SEPOLIA: number - Sepolia source chain ID
  • SOURCE_BASE_MAINNET: number - Base mainnet source chain ID
  • SOURCE_BSC_MAINNET: number - BSC mainnet source chain ID
import { ARBITRUM, AVALANCHE, SOURCE_BSC_MAINNET } from "@gmx-ui/sdk/configs/chains";

console.log(ARBITRUM); // 42161
console.log(AVALANCHE); // 43114
console.log(SOURCE_BSC_MAINNET); // 56
  • CONTRACTS_CHAIN_IDS: ContractsChainId[] - Array of production chain IDs where contracts are deployed
  • CONTRACTS_CHAIN_IDS_DEV: ContractsChainId[] - Array of chain IDs including development/testnet chains
import { CONTRACTS_CHAIN_IDS, CONTRACTS_CHAIN_IDS_DEV } from "@gmx-ui/sdk/configs/chains";

console.log(CONTRACTS_CHAIN_IDS); // [42161, 43114, 3636]
console.log(CONTRACTS_CHAIN_IDS_DEV); // [42161, 43114, 3636, 43113, 421614]
  • CHAIN_NAMES_MAP: Record<AnyChainId, ChainName> - Mapping of chain IDs to human-readable names
import { CHAIN_NAMES_MAP, ARBITRUM } from "@gmx-ui/sdk/configs/chains";

console.log(CHAIN_NAMES_MAP[ARBITRUM]); // "Arbitrum"
  • CHAIN_SLUGS_MAP: Record<ContractsChainId, string> - Mapping of chain IDs to URL-friendly slugs
import { CHAIN_SLUGS_MAP, ARBITRUM } from "@gmx-ui/sdk/configs/chains";

console.log(CHAIN_SLUGS_MAP[ARBITRUM]); // "arbitrum"
  • HIGH_EXECUTION_FEES_MAP: Record<ContractsChainId, number> - High execution fee thresholds in USD per chain
  • EXCESSIVE_EXECUTION_FEES_MAP: Partial<Record<ContractsChainId, number>> - Excessive execution fee thresholds in USD per chain
  • MAX_FEE_PER_GAS_MAP: Record<number, bigint> - Maximum fee per gas values for EIP-1559 transactions
  • GAS_PRICE_PREMIUM_MAP: Record<number, bigint> - Gas price premiums applied to execution fee calculations
  • MAX_PRIORITY_FEE_PER_GAS_MAP: Record<ContractsChainId, bigint | undefined> - Maximum priority fee per gas values
  • MIN_EXECUTION_FEE_USD: Partial<Record<ContractsChainId, bigint | undefined>> - Minimum execution fees in USD equivalent
  • GAS_PRICE_BUFFER_MAP: Record<number, bigint> - Gas price buffers for non-EIP-1559 transactions
  • botanix: Chain - Viem chain configuration for Botanix network
  • EXECUTION_FEE_CONFIG_V2: Record<ContractsChainId, object> - Execution fee configuration per chain
  • GAS_LIMITS_STATIC_CONFIG: Record<ContractsChainId, StaticGasLimitsConfig> - Static gas limits configuration per chain

Methods

getChainName

  • getChainName(chainId: number): ChainName

Returns the human-readable name for a given chain ID.

import { getChainName, ARBITRUM } from "@gmx-ui/sdk/configs/chains";

const chainName = getChainName(ARBITRUM);
console.log(chainName); // "Arbitrum"

getViemChain

  • getViemChain(chainId: number): Chain

Returns the Viem chain configuration for a given chain ID.

import { getViemChain, ARBITRUM } from "@gmx-ui/sdk/configs/chains";

const viemChain = getViemChain(ARBITRUM);
console.log(viemChain.name); // "Arbitrum One"

getHighExecutionFee

  • getHighExecutionFee(chainId: number): number

Returns the high execution fee threshold in USD for a given chain ID.

import { getHighExecutionFee, ARBITRUM } from "@gmx-ui/sdk/configs/chains";

const highFee = getHighExecutionFee(ARBITRUM);
console.log(highFee); // 5

getExcessiveExecutionFee

  • getExcessiveExecutionFee(chainId: number): number

Returns the excessive execution fee threshold in USD for a given chain ID.

import { getExcessiveExecutionFee, ARBITRUM } from "@gmx-ui/sdk/configs/chains";

const excessiveFee = getExcessiveExecutionFee(ARBITRUM);
console.log(excessiveFee); // 10

isContractsChain

  • isContractsChain(chainId: number, dev?: boolean): chainId is ContractsChainId

Parameters

  • chainId: number - The chain ID to check
  • dev?: boolean - Whether to include development/testnet chains (optional, defaults to false)

Checks if a chain ID is a valid contracts chain where GMX contracts are deployed.

import { isContractsChain, ARBITRUM, AVALANCHE_FUJI } from "@gmx-ui/sdk/configs/chains";

console.log(isContractsChain(ARBITRUM)); // true
console.log(isContractsChain(AVALANCHE_FUJI)); // false
console.log(isContractsChain(AVALANCHE_FUJI, true)); // true

isTestnetChain

  • isTestnetChain(chainId: number): boolean

Checks if a chain ID represents a testnet chain.

import { isTestnetChain, ARBITRUM, ARBITRUM_SEPOLIA } from "@gmx-ui/sdk/configs/chains";

console.log(isTestnetChain(ARBITRUM)); // false
console.log(isTestnetChain(ARBITRUM_SEPOLIA)); // true