┌─────────────────────────────────────────────────────────────────────┐
│ Frontend Layer │
│ ┌────────────────────┐ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Trading Interface │ │ Order Entry UI │ │ Portfolio View │ │
│ │ (React + Vite) │ │ (Orderly UI) │ │ (Charts) │ │
│ └────────────────────┘ └─────────────────┘ └─────────────────┘ │
│ ↕ WebSocket (ws://localhost:8081) + REST API │
└─────────────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────────┐
│ API Gateway Layer │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ Axum Web Framework (Port 8080) │ │
│ │ - REST API Endpoints (/api/v1/*) │ │
│ │ - WebSocket Server (Port 8081) │ │
│ │ - 3-Layer Risk Control (User/System/Market) │ │
│ │ - JWT Authentication & Authorization │ │
│ │ - Rate Limiting (100 req/min/user) │ │
│ │ - Request Validation & Error Handling │ │
│ └──────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────────┐
│ Core Services Layer │
│ │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ Matching Engine (peak-pilot) - Lock-free OrderBook │ │
│ │ - Price-Time Priority Matching │ │
│ │ - SIMD Price Search (5.79x speedup) │ │
│ │ - Memory Pool (337K orders/sec) │ │
│ │ - Batch Processing (7.16M TPS) │ │
│ │ - Rayon Parallel (396K TPS) │ │
│ │ - Advanced Order Types (Iceberg, PostOnly, TrailingStop) │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │
│ ┌────────────────┐ ┌────────────────┐ ┌─────────────────────┐ │
│ │ Settlement │ │ Liquidation │ │ Oracle Adapter │ │
│ │ Engine │ │ Keeper │ │ (Pyth Network) │ │
│ │ - Batch │ │ - 150% Warn │ │ - Price Feeds │ │
│ │ - Retry+DLQ │ │ - 110% Liq │ │ - 1s Update │ │
│ │ - Rollback │ │ - Concurrent │ │ - Multi-source │ │
│ └────────────────┘ └────────────────┘ └─────────────────────┘ │
│ │
│ ┌────────────────────────────────────────────────────────────────┐│
│ │ Event Listener (Chain Event Monitor) ││
│ │ - Deposit/Withdrawal Events ││
│ │ - Settlement Confirmations ││
│ │ - Redis Pub/Sub Broadcasting ││
│ └────────────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────────┐
│ Data Layer │
│ │
│ ┌──────────────────┐ ┌──────────────────┐ ┌─────────────────┐ │
│ │ PostgreSQL 16 │ │ Redis 7 │ │ TimescaleDB │ │
│ │ ───────────────│ │ ───────────────│ │ ───────────────│ │
│ │ - Users │ │ - OrderBook │ │ - OHLCV │ │
│ │ - Orders │ │ - Cache (TTL) │ │ - Trades │ │
│ │ - Positions │ │ - Sessions │ │ - Funding │ │
│ │ - Balances │ │ - Pub/Sub │ │ - Analytics │ │
│ │ - Trades │ │ - Leaderboard │ │ │ │
│ │ - Settlements │ │ │ │ │ │
│ └──────────────────┘ └──────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────────┐
│ Blockchain Layer (Solana) │
│ │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ Smart Contracts (Anchor Framework) │ │
│ │ - Program ID: [deployed on Devnet] │ │
│ │ ─────────────────────────────────────────────────────────── │ │
│ │ Instructions: │ │
│ │ • initialize - 初始化交易所 │ │
│ │ • deposit - 存入资金 (SOL/USDC) │ │
│ │ • withdraw - 提取资金 │ │
│ │ • open_position - 开仓 │ │
│ │ • close_position - 平仓 │ │
│ │ • liquidate - 清算 │ │
│ │ • batch_settlement - 批量结算 │ │
│ │ │ │
│ │ Accounts: │ │
│ │ • Exchange - 全局配置 │ │
│ │ • UserAccount - 用户账户 │ │
│ │ • Position - 仓位信息 │ │
│ │ • MarketAccount - 市场配置 │ │
│ └──────────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────────────────────────────────────┐ │
│ │ Event Logs (Program Events) │ │
│ │ - DepositEvent, WithdrawEvent │ │
│ │ - PositionOpenedEvent, PositionClosedEvent │ │
│ │ - LiquidationEvent, SettlementEvent │ │
│ └──────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────────────────┐
│ External Services │
│ ┌──────────────────┐ ┌──────────────────┐ ┌─────────────────┐ │
│ │ Pyth Network │ │ Solana RPC │ │ Helius RPC │ │
│ │ - Price Feeds │ │ - devnet/main │ │ (Enhanced RPC) │ │
│ └──────────────────┘ └──────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘