How It Works
Think of the matching engine as an auction house that runs continuously:- Traders submit bundles during the 500ms window
- Engine prioritizes by tip amount and submission time
- Top bundles execute atomically (all-or-nothing or configured)
- Markets update with new prices and filled orders
- Next auction begins immediately
What the Engine Tracks
Bundle Competition
During each auction window, traders can:- Submit one bundle (up to 256 operations)
- Amend their bundle to change operations or tip
- Bribe to increase their tip and jump ahead
- Cancel to withdraw from the auction
Execution Priority
Bundles execute in order:- Highest tip goes first
- Oldest submission breaks ties
- One per user - your latest bundle replaces earlier ones
Lazy Removal Trick
When you amend or bribe your bundle, the engine doesn’t remove your old entry from the queue (expensive operation). Instead:- Your new bundle gets added to the queue
- Your old bundle stays but becomes a “ghost”
- During execution, ghosts are skipped
User State Management
The engine tracks your state across all markets: Your balances:- Free USDC (available to trade)
- Locked USDC (in open buy orders)
- Free YES shares (available to sell/merge)
- Locked YES shares (in open sell orders)
- Free NO shares (available to sell/merge)
- Locked NO shares (in open sell orders)
- All active limit orders across markets
- Updated in real-time as they fill or cancel
Auction Close Process
When the 500ms window ends: 1. Load traders- Engine loads all users who have bundles
- Fast access via Redis cache
- New traders created automatically
- Process bundles from highest tip to lowest
- Each bundle either fully succeeds or fails
- Tips distributed to market makers who filled orders
- Failed bundle tips go to protocol liquidity fund
- Generate orderbook snapshots
- Broadcast new prices to all clients
- Clear auction state for next round
Why This Design?
For traders:- Fair competition based on value, not speed
- Predictable max latency (500ms)
- Can adjust strategy mid-auction (amend/bribe)
- Earn tips when filling orders
- Privacy protection (bundles don’t expose identity)
- Can’t be picked off by faster traders
- Failed tips fund liquidity during volatility
- Sustainable incentive structure
- Scales to thousands of concurrent traders
Real-Time Updates
After each auction, you receive:- Bundle result: Success or failure with details
- Balance updates: New USDC and share balances
- Order updates: Which orders filled, canceled, or placed
- Market data: Latest orderbook snapshots
Next Steps
- Learn how Batch Auctions create fair competition
- Understand OrderBook matching mechanics
- Explore Operations you can include in bundles