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
| Check | Condition | User Message |
|---|---|---|
| Insufficient Balance | Order value > available balance | ”Insufficient USDC balance for this order” |
| Leverage Exceeds Limit | Selected leverage > market max | ”Maximum leverage for this market is Nx” |
| Position Size Limit | Notional > max position size | ”Order exceeds maximum position size” |
| Margin Requirement | Free collateral < initial margin | ”Insufficient margin — deposit more collateral or reduce size” |
| Price Deviation | Limit price > 10% from mark price | ”Limit price deviates significantly from mark price — confirm?” |
| Self-Trade | Order would match against own resting order | ”This order would trade against your existing order” |
Pre-Deposit Checks
| Check | Condition | User Message |
|---|---|---|
| Wrong Network | Wallet connected to unsupported chain | ”Please switch to Ethereum Mainnet or Arbitrum” |
| Token Approval | Insufficient allowance for bridge contract | ”Approve USDC spending before depositing” |
| Minimum Deposit | Amount < minimum deposit threshold | ”Minimum deposit is 10 USDC” |
| Gas Estimation | Wallet ETH balance < estimated gas | ”Insufficient ETH for gas fees” |
Pre-Withdrawal Checks
| Check | Condition | User Message |
|---|---|---|
| Open Positions | Withdrawal would cause liquidation | ”Close positions or reduce withdrawal amount” |
| Margin Impact | Post-withdrawal margin ratio < maintenance | ”This withdrawal would put your account below maintenance margin” |
| Pending Orders | Active orders would exceed post-withdrawal balance | ”Cancel open orders before withdrawing” |
| Cooldown Active | Unstaking cooldown in progress | ”Unstaking cooldown ends in X days” |
Staking Checks
| Check | Condition | User Message |
|---|---|---|
| Minimum Stake | Amount < minimum staking threshold | ”Minimum stake is 1,000 GX” |
| Cooldown Warning | User initiating unstake | ”Unstaking has a 7-day cooldown. You will not earn rewards during this period.” |
| Governance Lock | Tokens locked in active governance vote | ”Tokens are locked until the governance vote concludes” |
Governance Checks
| Check | Condition | User Message |
|---|---|---|
| Proposal Threshold | Staked GX < 100,000 | ”You need at least 100,000 staked GX to submit a proposal” |
| Duplicate Vote | User has already voted on this proposal | ”You have already voted on this proposal” |
| Voting Period | Vote 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