Program ID (Devnet): 7TeV1Vdps9eaMv8mfcXJgNsEzWBJwNi4kHfqaVkEu95u
Arcium MPC: Integrated for encrypted balance updates
A Hyperliquid-inspired perpetual futures exchange with privacy-first architecture using Arcium MPC and encrypted storage.
Traditional Perps Exchanges:
- β All trades visible on-chain
- β Position sizes public
- β Easy to front-run large orders
- β Whale tracking is trivial
ZEC Dark Perps:
- β Encrypted Balances via Arcium Multi-Party Computation (MPC)
- β Private Order Details with AES-256-GCM encryption
- β Hyperliquid-Style Mechanics (position lifecycle, mark price, margin system)
- β Zcash Bridge for private collateral deposits (in development)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β MATCHING ENGINE (Off-Chain) β
β β’ Order Matching & Position Tracking β
β β’ AES-256-GCM Encrypted Storage (Supabase) β
β β’ Mark Price & Real-Time PnL β
β β’ Margin Checks (10x Leverage) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β SOLANA PROGRAM (On-Chain) β
β β’ Encrypted Margin Accounts (Arcium MPC) β
β β’ Privacy-Preserving Trade Settlement β
β β’ Zcash Bridge (wZEC Minting) β
ββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ARCIUM MPC CLUSTER β
β β’ Encrypted Balance Updates β
β β’ Zero-Knowledge Computations β
β β’ Decentralized Privacy Layer β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
On-Chain (Arcium MPC):
- β
Margin account balances (
encrypted_collateral,encrypted_debt) - β Trade settlement values (computed in MPC, re-encrypted)
Off-Chain (AES-256-GCM):
- β Exact order sizes and prices
- β User public keys (hashed with SHA-256)
- β Position details (size, entry price, PnL)
- β Trade details (buyer/seller, exact amounts)
For Trading:
- Order side (long/short)
- Size buckets ('0-1', '1-10', '10-100', '100+')
- Price levels (rounded to nearest $1)
For Safety:
- Liquidation flags (liquidators need to identify risky accounts)
- Transaction existence (Solana requirement)
For Transparency:
- Aggregated metrics (total volume, open interest, trade count)
# Install dependencies
node --version # v18+
npm --version # v9+
# Solana CLI
solana --version # v1.18+
# Anchor
anchor --version # v0.30+cd services/matching-engine
npm install
npm run build
npm startExpected Output:
π ZEC Dark Perps Matching Engine
================================
π‘ Server listening on http://localhost:3001
π Orderbook API: http://localhost:3001/api/orderbook
π Submit orders: POST http://localhost:3001/api/orders
================================
β
Database connected
π¦ Restoring orderbook from database...
β
Restored 0 orders from database
π Starting matching loop (200ms interval)
# Place a LONG order
curl -X POST http://localhost:3001/api/orders \
-H "Content-Type: application/json" \
-d '{
"userPubkey": "CyViyEZCjHBJPKzCYZ7sSDm2e3YCdgxrjbCj3PLyvT8i",
"side": "long",
"size": 0.5,
"price": 50.0
}'
# Place a SHORT order (will match!)
curl -X POST http://localhost:3001/api/orders \
-H "Content-Type: application/json" \
-d '{
"userPubkey": "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin",
"side": "short",
"size": 0.5,
"price": 50.0
}'What Happens:
- β Orders encrypted and stored in Supabase
- β Matching engine finds the match
- β Trade created with encrypted details
- β Positions updated (weighted average entry price)
- β Mark price updated for real-time PnL
- β MPC settlement queued to Arcium π
# Check orderbook (bucketed data - public)
curl http://localhost:3001/api/orderbook | jq
# View user positions (decrypted server-side)
curl http://localhost:3001/api/positions/CyViyEZCjHBJPKzCYZ7sSDm2e3YCdgxrjbCj3PLyvT8i | jq
# Check platform metrics
curl http://localhost:3001/api/metrics | jq
# View mark price
curl http://localhost:3001/api/mark-price | jq
# Check margin account
curl http://localhost:3001/api/account/CyViyEZCjHBJPKzCYZ7sSDm2e3YCdgxrjbCj3PLyvT8i | jqπ― Match found!
Buyer: CyViyEZC... (0.5 @ $50)
Seller: 9xQeWvG8... (0.5 @ $50)
πΎ Trade saved to database (encrypted)
π Mark price updated: $50.00
π Position updated for CyViyEZC... (LONG 0.5 @ $50.00)
π Position updated for 9xQeWvG8... (SHORT 0.5 @ $50.00)
π Queuing MPC settlement to Arcium...
Buyer margin: CyViyEZC...
Seller margin: 9xQeWvG8...
Trade value: $25.00
β³ Waiting for Arcium MPC callback...
# Show the architecture
cat README.md | grep -A 20 "Architecture"
# Explain privacy model
echo "Traditional exchanges expose everything on-chain."
echo "ZEC Dark Perps encrypts balances, orders, and positions."
echo "Using Arcium MPC for zero-knowledge computations."# Terminal 1: Start matching engine
cd services/matching-engine
npm start
# Show it's connected to Supabase and ready# Terminal 2: Place LONG order
curl -X POST http://localhost:3001/api/orders \
-H "Content-Type: application/json" \
-d '{"userPubkey":"CyViyEZCjHBJPKzCYZ7sSDm2e3YCdgxrjbCj3PLyvT8i","side":"long","size":0.5,"price":50.0}'
# Show orderbook (bucketed - privacy preserved)
curl http://localhost:3001/api/orderbook | jq
# Explain: "Notice the size is bucketed as '0-1', not exact 0.5"
# Explain: "User pubkey is hashed, not visible"
# Place SHORT order to trigger match
curl -X POST http://localhost:3001/api/orders \
-H "Content-Type: application/json" \
-d '{"userPubkey":"9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin","side":"short","size":0.5,"price":50.0}'# Terminal 1 will show:
# - Match found
# - Trade encrypted and saved
# - Positions updated
# - MPC settlement queued to Arcium
# - Waiting for callback
# Explain: "The matching engine queues encrypted balance updates to Arcium MPC"
# Explain: "Only the MPC cluster can decrypt and update balances"
# Explain: "This prevents anyone (including us) from seeing exact balances"# Check user position
curl http://localhost:3001/api/positions/CyViyEZCjHBJPKzCYZ7sSDm2e3YCdgxrjbCj3PLyvT8i | jq
# Explain the output:
# - Position side: LONG
# - Size: 0.5
# - Entry price: $50.00
# - Current PnL: calculated using mark price
# - Leverage: 10x
# Place another order to show position increase
curl -X POST http://localhost:3001/api/orders \
-H "Content-Type: application/json" \
-d '{"userPubkey":"CyViyEZCjHBJPKzCYZ7sSDm2e3YCdgxrjbCj3PLyvT8i","side":"long","size":0.3,"price":52.0}'
curl -X POST http://localhost:3001/api/orders \
-H "Content-Type: application/json" \
-d '{"userPubkey":"9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin","side":"short","size":0.3,"price":52.0}'
# Check position again - weighted average entry price
curl http://localhost:3001/api/positions/CyViyEZCjHBJPKzCYZ7sSDm2e3YCdgxrjbCj3PLyvT8i | jq
# Explain: "Position increased from 0.5 to 0.8"
# Explain: "Entry price is weighted average: (50*0.5 + 52*0.3)/0.8 = $50.75"# Check account margin
curl http://localhost:3001/api/account/CyViyEZCjHBJPKzCYZ7sSDm2e3YCdgxrjbCj3PLyvT8i | jq
# Explain the output:
# - Margin Balance: $1,000 (mock for demo)
# - Equity: Balance + Unrealized PnL
# - Total Notional: Position size * mark price
# - Leverage: Actual leverage being used
# - Margin Used: Notional / 10
# - Margin Available: What's left for new orders
# Try to place order that exceeds margin
curl -X POST http://localhost:3001/api/orders \
-H "Content-Type: application/json" \
-d '{"userPubkey":"CyViyEZCjHBJPKzCYZ7sSDm2e3YCdgxrjbCj3PLyvT8i","side":"long","size":200,"price":50.0}'
# Should get rejected with:
# "Insufficient margin. Required: $X, Available: $Y"# View aggregated metrics
curl http://localhost:3001/api/metrics | jq
# Explain:
# - Total Volume (24h): Sum of all trades
# - Open Interest: Total position notional
# - Total Trades: Number of matches
# - Active Traders: Unique users
# - All calculated from encrypted data!# Show Supabase schema
cat services/matching-engine/supabase/schema.sql | grep -A 10 "CREATE TABLE orders"
# Explain:
# - user_hash: SHA-256 hashed pubkey
# - size_bucket: '0-1', '1-10', etc (not exact)
# - price_level: Rounded to $1
# - encrypted_details: AES-256-GCM encrypted exact data
# Show encryption code
cat services/matching-engine/src/crypto.ts | grep -A 15 "export function encrypt"
# Explain:
# - AES-256-GCM authenticated encryption
# - Random IV per encryption
# - Auth tag for integrity- Order placement with encryption
- Order matching (FIFO, price-time priority)
- Trade execution with encrypted storage
- Position lifecycle (open/increase/reduce/close/flip)
- Mark price tracking (last trade price)
- Real-time unrealized PnL calculation
- AES-256-GCM encryption for sensitive data
- SHA-256 hashing for user identifiers
- Size bucketing and price rounding
- Arcium MPC integration (queue_settle_trade)
- Encrypted margin accounts on-chain
- Initial margin checks (10x leverage)
- Account equity calculation
- Order rejection when insufficient margin
- Maintenance margin calculation (for liquidations)
- Platform metrics (volume, open interest, trades)
- User position tracking
- Trade history
- Mark price API
On-Chain:
- Solana (Devnet)
- Anchor Framework v0.30
- Arcium MPC for encrypted computations
- SPL Token (wZEC)
Off-Chain:
- Node.js + TypeScript
- Supabase (PostgreSQL)
- AES-256-GCM encryption
- Express.js REST API
Frontend:
- Next.js 14
- Solana Wallet Adapter
- TailwindCSS + shadcn/ui
- Recharts for analytics
Matching Engine:
- Matching interval: 200ms (5 matches/sec)
- Database latency: ~50-100ms
- Order encryption: <1ms
On-Chain:
- MPC settlement: 5-30 seconds (Arcium devnet)
- Transaction cost: ~0.001 SOL
- Confirmation time: ~400ms (Solana)
Encryption:
- AES-256-GCM for database (authenticated encryption)
- Arcium MPC for on-chain balances (zero-knowledge)
- Random IV per encryption (prevents pattern analysis)
Privacy:
- User pubkeys hashed with salt
- Order sizes bucketed
- Prices rounded
- Exact details only in encrypted fields
Risk Management:
- Initial margin: 10% (10x leverage)
- Maintenance margin: 5%
- Liquidation monitoring (to be implemented)
- Order matching engine
- Position lifecycle
- Mark price system
- Margin checks
- Encrypted storage
- Arcium MPC integration
- Hashed identifiers
- On-chain bridge instructions
- Zcash bridge daemon
- Deposit monitoring
- Withdrawal processing
- Signature verification (security)
- Liquidation bot
- Oracle integration (Pyth)
- Funding rates
- Multiple markets
- SYSTEM_ARCHITECTURE.md - Complete system design and privacy model
- PERPS_ANALYSIS.md - Analysis of architecture decisions
- ARCIUM_COMPLETE_IMPLEMENTATION.md - MPC integration guide
- ZCASH_BRIDGE_COMPLETE_GUIDE.md - Bridge implementation
- Privacy-First: Only perps exchange with encrypted balances via MPC
- Hyperliquid Mechanics: Professional trading with position lifecycle
- Zcash Integration: Private collateral deposits (unique in DeFi)
- Hybrid Model: Balance privacy with operational transparency
This is a research project exploring privacy-preserving DeFi. Contributions welcome!
This is experimental software on devnet. Not audited. Not for production use. Educational purposes only.
Built with β€οΈ for privacy-preserving DeFi
Status: MVP - Core trading functional, bridge in development