Why Privacy Matters in Trading
Traditional orderbooks expose sensitive information:| Exposed Data | Privacy Risk |
|---|---|
| Order prices | Front-running attacks |
| Order quantities | Position size exposure |
| Trade history | Trading strategy leakage |
Architecture Overview
Key Features
Encrypted Orders
Prices and quantities are encrypted client-side before submission
Private Matching
Orders matched using FHE comparisons - no plaintext exposure
Minimal Storage
Only 32-byte hash references stored on-chain
Authorization Control
PDAs control who can decrypt match results
Data Flow
Program Structure
Account Sizes
The orderbook uses minimal account space by storing only hash references:| Account | Size | Contents |
|---|---|---|
Order | 106 bytes | owner, price_ref, qty_ref, side, status, order_id |
Orderbook | 56 bytes | authority, next_order_id, counters |
MatchResult | 88 bytes | order IDs, fill_price_ref, fill_qty_ref, match_id |
Instructions
| Instruction | Description |
|---|---|
Initialize | Create orderbook with authority |
SubmitOrder | Submit buy/sell order with encrypted price and quantity |
MatchOrders | Match a buy and sell order using FHE |
CancelOrder | Cancel an open order (owner only) |
Next Steps
State Structures
Learn about Order, Orderbook, and MatchResult
Instructions
See instruction implementations
Matching Logic
Understand FHE comparison and min
Client Usage
Integrate with frontend