3.1 Design Objectives
The Parallelshots matching engine is designed to satisfy four primary constraints: low-latency execution, deterministic ordering, strict risk pre-validation, and seamless on-chain settlement. Unlike AMM-based systems, where execution price is a function of pool state, Parallelshots enforces explicit price discovery through discrete orders, enabling tighter spreads, reduced slippage, and sophisticated trading strategies. The engine is logically off-chain for performance reasons, but economically and cryptographically subordinate to the on-chain protocol. All matches are considered provisional until finalized through on-chain settlement logic. This design ensures that execution speed does not come at the cost of trust assumptions around custody, balances, or margin enforcement.3.2 Order Representation
Each order is represented as a structured object with immutable and mutable fields:(market_id, price, timestamp) to enforce strict price-time priority. No discretionary reordering is permitted.
3.3 Pre-Trade Risk Validation
Before an order is admitted into the order book, the engine performs deterministic risk checks against the on-chain risk model:3.4 Matching Algorithm
The engine operates a continuous matching loop per market:3.5 Partial Fills and State Transitions
Orders may be partially filled across multiple matches. Each fill generates a discrete execution event that is later settled on-chain. State transitions are monotonic and irreversible:3.6 On-Chain Settlement Hook
Matched trades are batch-submitted to the settlement contract across chains:- Position size
- Average entry price
- Locked margin
- Unrealized PnL
3.7 Failure and Recovery Model
If the engine halts or disconnects:- Open orders remain valid
- On-chain state is unchanged
- No funds are at risk

