Decentralized perpetuals and spot DEX on Arbitrum and Avalanche (with newer deployments on Botanix and MegaETH). v2 uses isolated GM markets, oracle-priced execution via keepers, and supports up to 100x leverage.
- 01perpetual futures (long/short with leverage)
- 02on-chain spot swaps against GM pools
- 03GLP/GM liquidity provision
- 04Arbitrum and Avalanche derivatives
- pnpm add @gmx-io/sdk viem
| Variable | Scope | Description |
|---|---|---|
| GMX_RPC_ARBITRUM | Server | Arbitrum One RPC URL used by the GMX SDK for on-chain reads and order submission. |
| GMX_RPC_AVALANCHE | Server | Avalanche C-Chain RPC URL used by the GMX SDK. |
| GMX_SUBSQUID_URL | Client | Optional Subsquid endpoint for trade history and market analytics (passed as `subsquidUrl` to `GmxSdk`). |
Use GMX v2 via `@gmx-io/sdk`. Construct: `const sdk = new GmxSdk({ chainId: 42161, rpcUrl, oracleUrl: 'https://arbitrum-api.gmxinfra.io', subsquidUrl, walletClient })`. Read markets/tokens with `sdk.markets.getMarketsInfo()` and `sdk.tokens.getTokensData()`. Place a position via `sdk.orders.createIncreaseOrder({ marketAddress, initialCollateralAddress, sizeDeltaUsd, leverage, isLong, ... })` which submits to the OrderHandler and is then executed by a GMX keeper using oracle prices. For read-only data, `GmxApiSdk` exposes REST wrappers (`fetchPositionsInfo`, `fetchOrders`, OHLCV, APY).
- ⚑Two-step execution: orders are submitted on-chain but executed by GMX keepers using oracle prices — there is a settlement delay (seconds), and execution price can differ from quote price within the keeper acceptable-price band.
- ⚑Slippage is enforced by `acceptablePrice` (and `acceptablePriceImpactBps`) — set it tight enough to protect against bad fills but loose enough that keepers can execute, or the order is canceled and execution fee is forfeited.
- ⚑Each order requires a non-trivial **execution fee** in native gas (ETH on Arbitrum, AVAX on Avalanche) paid to keepers — query `sdk.utils.getExecutionFee(...)` and pass it as `msg.value`; underpaying causes silent cancellation.
- ⚑v2 uses isolated **GM markets** (one per pair) with separate liquidity — a market may have insufficient OI/liquidity for your size; check `maxOpenInterest` and `availableLiquidity` before submitting.
- ⚑Chain coverage is narrow — GMX V2 is on Arbitrum, Avalanche, Botanix, and MegaETH. Other chains have third-party forks but are not GMX.
- ⚑Funding & borrow fees are continuous and asymmetric (long vs short) — perpetuals UIs must display funding rates and projected fees, not just leverage and PnL.
- ⚑v1 (GLP) and v2 (GM) are different systems with different contracts — do not mix v1 reader/router addresses with v2 SDK calls.