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

Order Lifecycle Sequence

Compute Network Architecture

Two-Tier Gateway Architecture

Two-Tier Gateway Architecture

GoDark uses a two-tier gateway architecture to optimize for both latency and security:

ComponentEdge GatewaysSequencer Gateway
LocationDeployed near traders (multiple regions)Co-located with MPC nodes
ScalingHorizontal — scales to handle any number of connectionsSingle instance with hot standby
RoleTLS termination, authentication, rate limiting, WebSocket managementSequence number assignment, parallel fanout to 5 nodes
Order privacy at gatewayEncrypted session framing before MPC fanoutSequence 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

StepComponentDescription
1. Order submissionClient → Edge GatewayOrder sent via REST (POST /dex-trading) or WebSocket over TLS-encrypted connection.
2. Edge processingEdge GatewayHandles authentication, rate limiting, and input validation. Order payloads are encrypted in transit before MPC fanout.
3. SequencingSequencer GatewayAssigns a global sequence number, ensuring deterministic ordering, and fans the order to all 5 MPC nodes simultaneously.
4. Secret sharingMPC CommitteeThe 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. AcknowledgmentMPC → ClientYou receive an acknowledgment once 3 of 5 nodes confirm the operation.
6. Trade confirmationMPC → ClientFill events pushed via WebSocket order_updates channel (filled, partially_filled).
7. Batch settlementSettlement RelayerTrades batched (configurable: 1–2s default). Net position deltas computed per user. 3-of-5 committee signature required.
8. On-chain finalitySolanaSettlement transaction updates shielded-pool commitments and finalizes aggregate collateral state.