BTB
/

GMX

Derivativeswebsite
Decentralized perpetuals and spot-style swaps on GMX V2. An agent can supply liquidity to GM and GLV pools, withdraw them, and open, change or close leveraged positions through the ExchangeRouter. Orders are executed later by keepers, not in the same transaction.

What you can do

add-liquidity-gmDeposit tokens into a GM market pool and receive GM tokensapprove the Router for the long or short token, then ExchangeRouter.multicall([sendWnt(DepositVault, executionFee), sendTokens(token, DepositVault, amount), createDeposit(params)]) with msg.value = executionFee. A keeper executes the deposit and mints GM to receiver. Check getDeposit or the order status later. minMarketTokens protects against slippage.
remove-liquidity-gmRedeem GM tokens for the pool's underlying tokensapprove the Router for GM, then ExchangeRouter.multicall([sendWnt(WithdrawalVault, executionFee), sendTokens(gmToken, WithdrawalVault, amount), createWithdrawal(params)]). A keeper pays out the underlying tokens to receiver.
add-liquidity-glvDeposit GM or market tokens into a GLV vaultapprove the Router for the token, then GlvRouter.multicall([sendWnt(GlvVault, executionFee), sendTokens(token, GlvVault, amount), createGlvDeposit(params)]) with msg.value = executionFee.
remove-liquidity-glvRedeem GLV tokensapprove the Router for the GLV token, then GlvRouter.multicall([sendWnt(GlvVault, executionFee), sendTokens(glv, GlvVault, amount), createGlvWithdrawal(params)]).
open-or-change-positionOpen, increase, decrease or close a leveraged position, or make a limit or stop ordertransfer collateral to the OrderVault with sendTokens and the execution fee with sendWnt, then createOrder(params) in the same multicall. Use orderType and isLong to set the direction. Size is in USD with 30 decimals. Read the market and prices from the REST API or Reader before sizing.
cancel-orderCancel a pending order or depositExchangeRouter.cancelOrder(key), cancelDeposit(key) or cancelWithdrawal(key) with the bytes32 key from the creation event
check-positionsRead open positions and pool marketsReader.getAccountPositions(DataStore, account, 0, n) and Reader.getMarkets(DataStore, 0, n) on the chain's Reader address
Orders and deposits are not final when the user transaction is sent. Keepers execute them shortly after. Prices can move in between, so set minimum output and acceptable price fields.
Pool liquidity providers take the opposite side of traders, so GM and GLV value can fall when traders win.
Leveraged positions can be liquidated. Keep collateral well above the maintenance margin.
Execution fees are paid in the native token and are refunded only if an order is cancelled or fails.

Contracts

Read any function, or build a write and sign it. Amounts are in base units (1 USDC = 1000000).
ExchangeRouterrouter on arbitrum0x1C3fa76e6E1088bCE750f23a5BFcffa1efEF6A41
write multicall(bytes[])
Run several ExchangeRouter calls in one transaction, for example sendWnt (execution fee), sendTokens (collateral into the vault) and createDeposit or createOrder. Pass the execution fee as msg.value. Each element is ABI-encoded calldata for one of the calls.
write sendTokens(address,address,uint256)
Move an ERC20 from the caller to a receiver (usually a DepositVault, WithdrawalVault or OrderVault) through the Router. Arguments: token, receiver, amount. Approve the Router contract (not ExchangeRouter) for the token first. Used inside multicall.
write sendWnt(address,uint256)
Send the native token (ETH on Arbitrum, AVAX on Avalanche) as WETH or WAVAX to a receiver, normally the DepositVault or OrderVault, to pay the keeper execution fee. Arguments: receiver, amount. Used inside multicall with msg.value.
write createDeposit(((address,address,address,address,address,address,address[],address[]),uint256,bool,uint256,uint256,bytes32[]))
Deposit into a GM market pool. Struct fields in order: receiver, callbackContract, uiFeeReceiver, market, initialLongToken, initialShortToken, longTokenSwapPath, shortTokenSwapPath; then minMarketTokens, shouldUnwrapNativeToken, executionFee, callbackGasLimit, dataList. The tokens must already be in the DepositVault (sendTokens) and the execution fee in WNT (sendWnt) in the same multicall. A keeper mints GM tokens to receiver later.
write createWithdrawal(((address,address,address,address,address[],address[]),uint256,uint256,bool,uint256,uint256,bytes32[]))
Redeem GM tokens for the pool's underlying tokens. Struct holds receiver, callback contract, UI fee receiver, market, and the long and short swap paths, then min long and short amounts, shouldUnwrapNativeToken, executionFee, callbackGasLimit and dataList. GM tokens must first be sent to the WithdrawalVault with sendTokens in the same multicall.
write createOrder(((address,address,address,address,address,address,address[]),(uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256),uint8,uint8,bool,bool,bool,bytes32,bytes32[]))
Open, increase, decrease or swap through a market, limit, stop-loss or take-profit order. The struct holds addresses (receiver, callback contract, UI fee receiver, market, initial collateral token, swap path), then eight numbers (size delta in USD with 30 decimals, collateral delta, trigger price, acceptable price, execution fee, callback gas limit, min output, valid-from time), then orderType, decreasePositionSwapType, three bool flags (including isLong), a referral code and dataList. Collateral goes to the OrderVault first with sendTokens, and the execution fee as WNT with sendWnt, in the same multicall.
write updateOrder(bytes32,uint256,uint256,uint256,uint256,uint256,bool)
Change a pending order's size, trigger price, acceptable price or min output. Arguments: order key, size delta, acceptable price, trigger price, min output, validFrom, autoCancel.
write cancelOrder(bytes32)
Cancel a pending order by its key. The execution fee and collateral are refunded after a short delay.
write cancelDeposit(bytes32)
Cancel a GM deposit that has not been executed yet by its key. Tokens return to the caller after the cancellation delay.
write cancelWithdrawal(bytes32)
Cancel a GM withdrawal that has not been executed yet by its key.
write claimFundingFees(address[],address[],address)
Claim accrued funding fees for a list of markets and tokens. Arguments: markets, tokens, receiver.
Router (token approval target)router on arbitrum0x7452c558d45f8afC8c83dAe62C3f8A5BE19c71f6
GlvRouterrouter on arbitrum0x7EAdEE2ca1b4D06a0d82fDF03D715550c26AA12F
write createGlvDeposit(((address,address,address,address,address,address,address,address[],address[]),uint256,uint256,uint256,bool,bool,bytes32[]))
Deposit a GM token into a GLV vault. Tokens and the execution fee go to the GlvVault in the same multicall. The struct holds the receiver, callback and UI fee addresses, the market and GLV addresses, the token addresses and swap paths, then minGlvTokens, executionFee, callbackGasLimit, two bool flags and dataList. Check the ABI field order before encoding.
write createGlvWithdrawal(((address,address,address,address,address,address[],address[]),uint256,uint256,bool,uint256,uint256,bytes32[]))
Redeem GLV tokens for underlying GM tokens or tokens. GLV tokens must first be sent to the GlvVault with sendTokens in the same multicall, along with the WNT execution fee. Struct holds the receiver, callback and UI fee addresses, GLV and market addresses, the swap paths, then min amounts, executionFee, callbackGasLimit and dataList.
write multicall(bytes[])
Batch GlvRouter calls (sendWnt, sendTokens, createGlvDeposit, createGlvWithdrawal) in one transaction. Each element is ABI-encoded calldata.
write cancelGlvDeposit(bytes32)
Cancel an unexecuted GLV deposit by its key.
write cancelGlvWithdrawal(bytes32)
Cancel an unexecuted GLV withdrawal by its key.
Readerother on arbitrum0x470fbC46bcC0f16532691Df360A07d8Bf5ee0789
read getMarkets(address,uint256,uint256)
List GM markets. Arguments: DataStore address (0xFD70de6b91282D8017aA4E741e9Ae325CAb992d8 on Arbitrum), start index, end index.
read getAccountPositions(address,address,uint256,uint256)
Open positions for an account. Arguments: DataStore, account, start index, end index.
read getPositionInfo(address,address,bytes32,((uint256,uint256),(uint256,uint256),(uint256,uint256)),uint256,address,bool)
Detailed data for one position key: PnL, fees, collateral and liquidation state. The second argument is the price struct (min and max oracle price for the index, long and short tokens). Read it from the Reader's own helpers or the REST API rather than guessing prices.
read getPosition(address,bytes32)
Raw position struct for a position key (size, collateral, borrowing and funding state).
read getDeposit(address,bytes32)
Pending or executed GM deposit by key. Use it to follow a deposit after createDeposit.
read getWithdrawal(address,bytes32)
Pending or executed GM withdrawal by key.
GlvReaderother on arbitrum0x2C670A23f1E798184647288072e84054938B5497
read getGlvs(address,uint256,uint256)
List GLV vaults. Arguments: DataStore, start index, end index.
read getGlvInfo(address,address)
Info for one GLV: its markets, balances and token value. Arguments: DataStore, GLV token address.
DataStoreother on arbitrum0xFD70de6b91282D8017aA4E741e9Ae325CAb992d8
ExchangeRouterrouter on avalanche0x8f550E53DFe96C055D5Bdb267c21F268fCAF63B2
write multicall(bytes[])
Run several ExchangeRouter calls in one transaction (sendWnt, sendTokens, createDeposit, createWithdrawal, createOrder). Pass the execution fee in AVAX as msg.value. Each element is ABI-encoded calldata.
write sendTokens(address,address,uint256)
Move an ERC20 from the caller to a receiver vault through the Router. Arguments: token, receiver, amount. Approve the Router contract (0x820F5FfC5b525cD4d88Cd91aCf2c28F16530Cc68) for the token first. Used inside multicall.
write sendWnt(address,uint256)
Send AVAX, wrapped as WAVAX, to a receiver vault to pay the keeper execution fee. Arguments: receiver, amount. Used inside multicall.
write createDeposit(((address,address,address,address,address,address,address[],address[]),uint256,bool,uint256,uint256,bytes32[]))
Deposit into a GM market pool on Avalanche. Same struct as Arbitrum: receiver, callbackContract, uiFeeReceiver, market, initialLongToken, initialShortToken, swap paths, then minMarketTokens, shouldUnwrapNativeToken, executionFee, callbackGasLimit, dataList. Tokens and execution fee must be sent to the DepositVault in the same multicall.
write createWithdrawal(((address,address,address,address,address[],address[]),uint256,uint256,bool,uint256,uint256,bytes32[]))
Redeem GM tokens on Avalanche. GM tokens must first be sent to the WithdrawalVault with sendTokens in the same multicall.
write createOrder(((address,address,address,address,address,address,address[]),(uint256,uint256,uint256,uint256,uint256,uint256,uint256,uint256),uint8,uint8,bool,bool,bool,bytes32,bytes32[]))
Open, increase, decrease or swap through a market, limit, stop-loss or take-profit order. The struct holds addresses (receiver, callback contract, UI fee receiver, market, initial collateral token, swap path), then eight numbers (size delta in USD with 30 decimals, collateral delta, trigger price, acceptable price, execution fee, callback gas limit, min output, valid-from time), then orderType, decreasePositionSwapType, three bool flags (including isLong), a referral code and dataList. Collateral goes to the OrderVault first with sendTokens, and the execution fee as WNT with sendWnt, in the same multicall.
write cancelOrder(bytes32)
Cancel a pending order by its key.
write updateOrder(bytes32,uint256,uint256,uint256,uint256,uint256,bool)
Change a pending order's size, prices or min output by key.
Router (token approval target)router on avalanche0x820F5FfC5b525cD4d88Cd91aCf2c28F16530Cc68
GlvRouterrouter on avalanche0x7E425c47b2Ff0bE67228c842B9C792D0BCe58ae6
write createGlvDeposit(((address,address,address,address,address,address,address,address[],address[]),uint256,uint256,uint256,bool,bool,bytes32[]))
Deposit a GM token into a GLV vault on Avalanche. Tokens and the AVAX execution fee go to the GlvVault in the same multicall. Struct layout as on Arbitrum.
write createGlvWithdrawal(((address,address,address,address,address,address[],address[]),uint256,uint256,bool,uint256,uint256,bytes32[]))
Redeem GLV tokens on Avalanche. GLV tokens go to the GlvVault first, in the same multicall.
Readerother on avalanche0x62Cb8740E6986B29dC671B2EB596676f60590A5B
read getMarkets(address,uint256,uint256)
List GM markets on Avalanche. Arguments: DataStore (0x2F0b22339414ADeD7D5F06f9D604c7fF5b2fe3f6), start index, end index.
read getAccountPositions(address,address,uint256,uint256)
Open positions for an account on Avalanche. Arguments: DataStore, account, start index, end index.
read getPosition(address,bytes32)
Raw position struct for a position key on Avalanche.
GlvReaderother on avalanche0x5C6905A3002f989E1625910ba1793d40a031f947
read getGlvs(address,uint256,uint256)
List GLV vaults on Avalanche. Arguments: DataStore, start index, end index.
DataStoreother on avalanche0x2F0b22339414ADeD7D5F06f9D604c7fF5b2fe3f6