GMX V2 on Arbitrum
GMX V2 is the dominant perpetuals DEX on Arbitrum. TheGmxV2Adapter provides full lifecycle management for perpetual positions:
Open
Open long or short positions with configurable leverage and collateral.
Monitor
Track mark price, PnL, and liquidation price in real time via Chainlink feeds.
Close
Close positions entirely or partially with market decrease orders.
Supported Markets
Each GMX V2 market is an isolated pool with its own liquidity and risk parameters.| Market | Index Token | Collateral | Max Leverage |
|---|---|---|---|
| ETH/USDC | ETH | USDC | 100x |
| BTC/USDC | WBTC | USDC | 50x |
| ARB/USDC | ARB | USDC | 50x |
| LINK/USDC | LINK | USDC | 50x |
All positions use USDC as collateral. The agent automatically handles the market address lookup based on the asset you mention in your prompt.
How Positions Work
Opening a Position
When you request a leveraged position, the agent:- Selects the market based on the asset you mention (e.g., “go long ETH” maps to the ETH/USDC market)
- Fetches the current index price from the Chainlink price feed for that market
- Calculates the acceptable price with your slippage tolerance applied (higher for longs, lower for shorts)
- Computes the position size in USD with 30 decimals:
collateral * leverage * 10^12 - Submits a MarketIncrease order to the GMX ExchangeRouter
The keeper execution model means your order fills at the next-block price, not the price at submission time. The
acceptablePrice parameter protects you from excessive slippage between submission and execution.Price Feeds
The adapter reads real-time index prices from Chainlink AggregatorV3 oracles deployed on Arbitrum:| Market | Chainlink Feed |
|---|---|
| ETH/USDC | 0x639Fe6ab55C921f74e7fac1ee960C0B6293ba612 |
| BTC/USDC | 0x6ce185860a4963106506C203335A2910413708e9 |
| ARB/USDC | 0xb2A824043730FE05F3DA2efaFa1CBbe83fa548D6 |
| LINK/USDC | 0x86E53CF1B870786351Da77A57575e79CB55812CB |
10^22.
Closing a Position
To close a position, the agent:- Reads the current position from the GMX Reader contract using the position key
- Submits a MarketDecrease order for the full position size
- Sets the acceptable price to the extreme (0 for longs, max uint256 for shorts) to ensure the close executes
Position Monitoring
The agent can fetch detailed position data at any time:| Field | Description |
|---|---|
size | Position size in USD (30 decimals) |
collateral | Collateral amount in token decimals |
entryPrice | Average entry price |
markPrice | Current mark price from Chainlink |
pnl | Unrealized profit/loss in USD (30 decimals) |
liquidationPrice | Estimated price at which the position liquidates |
Liquidation Price Calculation
The adapter approximates the liquidation price using the maintenance margin (1% of position size):Position Key
GMX V2 identifies positions by a deterministic key:Slippage and Risk
Default Slippage
0.50% (50 basis points). Adjustable per trade via your prompt.
Execution Fee
GMX keepers require a small ETH execution fee (paid on order creation) to process your order.
Example Prompts
SDK Reference
The perpetuals adapter is in the@arb-agent/adapters package as GmxV2Adapter.
openPosition(params)
Opens a leveraged position. Accepts OpenGmxPositionParams:
| Field | Type | Required | Description |
|---|---|---|---|
side | string | Yes | "long" or "short" |
collateralToken | Address | Yes | Collateral token address (typically USDC) |
collateralAmount | bigint | Yes | Amount of collateral in token decimals |
leverage | number | Yes | Leverage multiplier (1-100) |
market | Address | No | GMX market address (default: ETH/USDC) |
slippageBps | number | No | Slippage tolerance (default: 50) |
closePosition(market, isLong)
Closes an entire position for the given market and direction.
getPosition(market, isLong)
Returns the current position details or null if no position exists.