← Protocols
Gains Network (gTrade)
01Description

Synthetic leveraged trading on Arbitrum, Polygon and Base. Trade crypto, forex, stocks and commodities up to 150x against a single DAI/USDC/WETH gToken vault, with a multi-collateral diamond contract handling all pairs.

02Best for
  • 01leveraged trading frontends across asset classes
  • 02synthetic FX / stocks / commodities exposure
  • 03trader rewards and referral integrations
  • 04vault-style LP yield (gToken)
  • 05multi-collateral perps without orderbook complexity
03Install
  • pnpm add @gainsnetwork/sdk viem
04Environment variables
VariableScopeDescription
NEXT_PUBLIC_GAINS_NETWORKClient`arbitrum`, `polygon`, or `base` — each has its own GNSMultiCollatDiamond deployment.
NEXT_PUBLIC_RPC_URLClientRPC URL for the chosen network.
05Prompt snippet
Use the `@gainsnetwork/sdk` package with viem. All trade actions go through the central `GNSMultiCollatDiamond` contract (Arbitrum mainnet `0xFF162c694eAA571f685030649814282eA457f169`). Open a trade with `openTrade({ trader, pairIndex, index, leverage, long, isOpen, collateralIndex, positionSizeCollateral, openPrice, tp, sl, tradeType, slippageP })`, close with `closeTradeMarket(pairIndex, index)`, modify SL/TP via `updateSl`/`updateTp`. Use `transformGlobalTradingVariables` from the SDK to read pair fees, max leverages and OI utilization. Pair indices are stable (BTC = 0, ETH = 1, etc.) — fetch via `pairsStorage()`.
06Gotchas
  • Prices come from a custom oracle network (DON / Chainlink low-latency feeds). A trade reverts if the requested `openPrice` deviates from oracle by more than `slippageP` — use a generous slippage in volatile conditions.
  • Vaults (gDAI, gUSDC, gWETH) are the counterparty to all trades. Trader PnL above a threshold mints/burns gTokens, so extreme winning streaks can briefly throttle new trades when collateralization ratio drops.
  • Funding/borrowing is replaced by a per-pair rollover fee + funding fee that compounds while the position is open. UIs must call `getTradeBorrowingFee` and `getTradeFundingFee` to display real PnL — `currentPnL` from the contract excludes them until close.
  • Liquidation triggers when `(collateral + pnl - fees) / collateral` falls below the per-pair liquidation threshold (typically 90%). The liquidator earns a small bounty; partial liquidations are NOT supported — the entire position closes.
  • Each collateral has its own indexed array of trades (`collateralIndex`). Don't share trade indices across collaterals — `index` is per (trader, pair, collateral).
  • v9/v10 contracts use the diamond-standard storage layout — always import the latest ABI from `@gainsnetwork/sdk` rather than hand-rolling, or selectors will collide on facet upgrades.
07Alternatives