Trade Flow
This section describes the end-to-end lifecycle of an order from submission to on-chain settlement using GoDark's MPC architecture.
Order-to-Settlement Lifecycle

Two-Tier Gateway Architecture

GoDark uses a two-tier gateway architecture to optimize for both latency and security:
| Component | Edge Gateways | Sequencer Gateway |
|---|---|---|
| Location | Deployed near traders (multiple regions) | Co-located with MPC nodes |
| Scaling | Horizontal — scales to handle any number of connections | Single instance with hot standby |
| Role | TLS termination, authentication, rate limiting, WebSocket management | Sequence number assignment, parallel fanout to 5 nodes |
| Order privacy at gateway | Encrypted session framing before MPC fanout | Sequence assignment only; no MPC plaintext |
Gateway encryption protects order contents from passive observers and from logs/traces. A compromised gateway is a separate trust boundary — see Encryption & Transport.
This means a trader in Tokyo connects to a local Edge Gateway with ~2ms TLS handshake (instead of 300ms to a distant datacenter), while the Sequencer Gateway focuses purely on ordering and distribution.
Step-by-Step Flow
| Step | Component | Description |
|---|---|---|
| 1. Order submission | Client → Edge Gateway | Order sent via REST (POST /dex-trading) or WebSocket over TLS-encrypted connection. |
| 2. Edge processing | Edge Gateway | Handles authentication, rate limiting, and input validation. Order payloads are encrypted in transit before MPC fanout. |
| 3. Sequencing | Sequencer Gateway | Assigns a global sequence number, ensuring deterministic ordering, and fans the order to all 5 MPC nodes simultaneously. |
| 4. Secret sharing | MPC Committee | The MPC committee secret-shares your order, matches it against the secret-shared orderbook, updates positions, and runs margin checks — all without any single node seeing the data. See Margin & Liquidation for how margin health and liquidation tiers work. |
| 5. Acknowledgment | MPC → Client | You receive an acknowledgment once 3 of 5 nodes confirm the operation. |
| 6. Trade confirmation | MPC → Client | Fill events pushed via WebSocket order_updates channel (filled, partially_filled). |
| 7. Batch settlement | Settlement Relayer | Trades batched (configurable: 1–2s default). Net position deltas computed per user. 3-of-5 committee signature required. |
| 8. On-chain finality | Solana | Settlement transaction updates shielded-pool commitments and finalizes aggregate collateral state. |