← Protocols
MUX Protocol
01Description

Decentralized leveraged-trading aggregator on Arbitrum. Routes trader positions across MUX V3 elemental pools and integrated venues (MUX V1, GMX V1/V2, gTrade) for optimized fees, leverage and liquidity, with a universal P2Multi-Pool model.

02Best for
  • 01perps aggregation frontends
  • 02boosted leverage via universal liquidity
  • 03smart routing across MUX V3 / GMX / gTrade
  • 04MUXLP / MLP-style LP yield
  • 05Arbitrum-native trading UIs
03Install
  • pnpm add viem ethers
04Environment variables
VariableScopeDescription
NEXT_PUBLIC_MUX_NETWORKClientCurrently `arbitrum` — MUX aggregator is Arbitrum-only.
NEXT_PUBLIC_RPC_URLClientArbitrum RPC URL.
MUX_BROKER_API_URLClientMUX broker / off-chain order API base URL (signed quotes for aggregation routing).
05Prompt snippet
Use viem against the MUX `OrderBook` and `Aggregator` contracts on Arbitrum. To open an aggregated position, call `placePositionOrder` on the `MuxAggregator` with `{ subAccountId, collateralAmount, size, price, tpPrice, slPrice, expiration, flags }`. The aggregator decides between MUX V3 elemental pools and external venues (GMX V1/V2, gTrade) based on size/cost. Read pool state from `getAssets()` / `getSubAccount(subAccountId)` and stream order events from the MUX subgraph (`https://api.thegraph.com/subgraphs/name/mux-world/mux-arb`). LP into MUXLP via `MuxLpManager.addLiquidity(token, amount, minLp)`.
06Gotchas
  • MUX is Arbitrum-only — there is no Ethereum or other-L2 deployment of the aggregator. Trying to point it at another network silently fails contract resolution.
  • Subaccount IDs are packed bytes32 (`account || collateralId || assetId || isLong || padding`). Encode them carefully — wrong byte order yields a different subaccount and orphans collateral.
  • Smart routing means the same UI action can settle against MUX V3, MUX V1, GMX V1/V2 or gTrade — fee schedules and funding mechanics differ per venue. Always read the resolved venue from the order receipt before showing PnL.
  • Funding on MUX V3 elemental pools is paid continuously; routed external venues use their own funding (e.g. GMX V2's borrow + funding split). Backtests must use the venue-specific funding history, not a single MUX number.
  • Liquidation prices differ across the resolver venues — 'Liquidation Price' shown in UIs is an estimate; the actual liquidator and fee come from the executing venue, which may be different from where the position was originally opened due to position migrations.
  • MUXLP holders bear trader PnL and earn fees + ARB/MUX rewards. Withdrawing MUXLP has a cooldown period and a dynamic exit fee — surface both before submitting `removeLiquidity`.
07Alternatives