Frontend Safety Checks

Overview

GX Exchange implements client-side safety checks to protect users from common errors before transactions are submitted on-chain. These checks run in the frontend and provide immediate feedback, preventing costly mistakes.

Frontend checks are a defense-in-depth layer. All critical validations are also enforced at the protocol level by the GX Core risk validator.

Pre-Trade Checks

CheckConditionUser Message
Insufficient BalanceOrder value > available balance”Insufficient USDC balance for this order”
Leverage Exceeds LimitSelected leverage > market max”Maximum leverage for this market is Nx”
Position Size LimitNotional > max position size”Order exceeds maximum position size”
Margin RequirementFree collateral < initial margin”Insufficient margin — deposit more collateral or reduce size”
Price DeviationLimit price > 10% from mark price”Limit price deviates significantly from mark price — confirm?”
Self-TradeOrder would match against own resting order”This order would trade against your existing order”

Pre-Deposit Checks

CheckConditionUser Message
Wrong NetworkWallet connected to unsupported chain”Please switch to Ethereum Mainnet or Arbitrum”
Token ApprovalInsufficient allowance for bridge contract”Approve USDC spending before depositing”
Minimum DepositAmount < minimum deposit threshold”Minimum deposit is 10 USDC”
Gas EstimationWallet ETH balance < estimated gas”Insufficient ETH for gas fees”

Pre-Withdrawal Checks

CheckConditionUser Message
Open PositionsWithdrawal would cause liquidation”Close positions or reduce withdrawal amount”
Margin ImpactPost-withdrawal margin ratio < maintenance”This withdrawal would put your account below maintenance margin”
Pending OrdersActive orders would exceed post-withdrawal balance”Cancel open orders before withdrawing”
Cooldown ActiveUnstaking cooldown in progress”Unstaking cooldown ends in X days”

Staking Checks

CheckConditionUser Message
Minimum StakeAmount < minimum staking threshold”Minimum stake is 1,000 GX”
Cooldown WarningUser initiating unstake”Unstaking has a 7-day cooldown. You will not earn rewards during this period.”
Governance LockTokens locked in active governance vote”Tokens are locked until the governance vote concludes”

Governance Checks

CheckConditionUser Message
Proposal ThresholdStaked GX < 100,000”You need at least 100,000 staked GX to submit a proposal”
Duplicate VoteUser has already voted on this proposal”You have already voted on this proposal”
Voting PeriodVote submitted outside voting window”Voting period has ended for this proposal”

Implementation Notes

  • All frontend checks use the same calculation logic as the on-chain risk validator to ensure consistency
  • Checks execute locally with zero latency — no network round-trips required
  • Price data for deviation checks is sourced from the WebSocket feed (real-time)
  • Failed checks display inline error messages and disable the submit button
  • Users can never bypass protocol-level checks, even if frontend checks are circumvented