A fully functional prediction market platform demonstrating Polymarket-style trading on Aptos blockchain. Features sub-second finality, parallel transaction execution, and real-time HFT bot visualization.
Target: 30,000+ TPS with distributed workers
# Step 1: Deploy latest code to all workers
./scripts/orchestrator.sh deploy
# Step 2: Start all workers in STANDBY mode (no auto-trading)
./scripts/orchestrator.sh standby
# Step 3: Start frontend
npm run dev
# Step 4: Open browser β ARM β LAUNCH
# http://localhost:5173/demo-day| Mode | Command | TPS | Duration | Use Case |
|---|---|---|---|---|
| Standby | ./scripts/orchestrator.sh standby |
- | - | Wait for UI launch (recommended) |
| Dry Run | ./scripts/orchestrator.sh dryrun |
~100 | 5 sec | Quick test |
| Full Demo | ./scripts/orchestrator.sh demo |
~30K | 60 sec | Auto-start demo |
Pre-flight check: Run ./scripts/pre-demo-checklist.sh before the demo!
Perfect for testing the full UI flow without burning APT.
# Terminal 1: Start dry run server
./scripts/orchestrator.sh dryrun
# Terminal 2: Watch the logs
./scripts/dryrun-view.sh
# Terminal 3: Start frontend
npm run devThen in your browser:
- Go to http://localhost:5173/polymarket
- Click "Start Demo" β TPS Dashboard
- Click ARM SYSTEM β Pre-flight checks
- Click LAUNCH DEMO β 3... 2... 1...
- Watch ~10 TPS for 5 seconds (minimal APT usage)
The real deal. 25 accounts across 3 cloud VMs.
# Terminal 1: Start all workers
./scripts/orchestrator.sh demo
# Terminal 2: Sexy 3-pane log viewer
./scripts/demo-view.sh
# Terminal 3: Start frontend
npm run devThen in your browser:
- Go to http://localhost:5173/polymarket
- Click "Start Demo" β TPS Dashboard
- Click ARM SYSTEM β Pre-flight checks pass β
- Click LAUNCH DEMO β 3... 2... 1... π
- Watch 30K+ TPS with whale trades making the chart spike!
The demo viewers show beautiful real-time logs:
12:34:56.789 0x1bd17a β148/150 1523 TPS 12ms 99%
12:34:56.891 0xe1da81 π150 ~1650 TPS 91ms
12:34:56.995 0x2acdcd β147/150 1489 TPS 11ms 98%
β‘ HFT STATS β‘
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
TPS: 28,450 Peak: 31,200 Avg: 27,890
Trades: 1,245,000 Success: 99.2% Latency: 12ms
Elapsed: 45s Accounts: 9/9 Clients: 1
Prices: Vance: 18% Rubio: 15% Trump: 42% DeSantis: 12%
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
./scripts/orchestrator.sh status # Check all infrastructure
./scripts/orchestrator.sh dryrun # Quick 100 TPS test (5 sec)
./scripts/orchestrator.sh demo # Full 30K TPS demo (60 sec)
./scripts/orchestrator.sh demo 30 # Custom duration (30 sec)
./scripts/orchestrator.sh stop # Stop all workers| Worker | IP | Accounts | Role |
|---|---|---|---|
| Worker 1 | 178.128.177.88 | 0-1666 (1667) | Primary |
| Worker 2 | 167.99.164.45 | 1667-3333 (1667) | Secondary |
| Worker 3 | 138.68.0.124 | 3334-4999 (1666) | Secondary |
| Total | 5000 |
Run npx tsx scripts/audit-accounts.ts for full breakdown.
| Category | Count | Balance |
|---|---|---|
| Trading Accounts (in orchestrator) | 25 | 121,068 APT |
| Contract Account | 1 | 749 APT |
| Other Accounts | 13 | ~0 APT |
| Total Available | ~122,000 APT |
| Component | IP/URL | Purpose |
|---|---|---|
| Aptos Fullnode | aptos.cash.trading:8080 | Low-latency RPC (unlimited) |
| QuickNode | polished-evocative-borough... | Primary RPC (50 RPS) |
| Aptos Labs | fullnode.testnet.aptoslabs.com | Fallback RPC |
The HFT server supports 5 modes with escalating TPS targets:
| Mode | Command | Target TPS | Batch | Delay | Use Case |
|---|---|---|---|---|---|
dryrun |
npx tsx server/hft-ultra-server.ts dryrun 30 |
~10 | 1 | 100ms | UI testing |
normal |
npx tsx server/hft-ultra-server.ts normal 60 |
~1,000 | 10 | 50ms | Light demo |
turbo |
npx tsx server/hft-ultra-server.ts turbo 60 |
~3,000 | 30 | 40ms | Medium |
ultra |
npx tsx server/hft-ultra-server.ts ultra 60 |
~10,000 | 80 | 30ms | High intensity |
quantum |
npx tsx server/hft-ultra-server.ts quantum 60 |
~30,000+ | 150 | 20ms | DEMO DAY |
The orchestrator uses quantum mode for ./scripts/orchestrator.sh demo.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β YOUR LAPTOP β
β ββββββββββββββββββββ β
β β React Frontend ββββββ WebSocket βββββ β
β β - Market UI β β β
β β - TPS Dashboard β β β
β β - Trade Stream β β β
β ββββββββββββββββββββ β β
ββββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββΌββββββββββββββββββββββββββββββ
β CLOUD VMs β
β β
β βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ β
β β Worker 1 β β Worker 2 β β Worker 3 β β
β β 178.128.177.88 β β 167.99.164.45 β β 138.68.0.124 β β
β β 1667 accounts β β 1667 accounts β β 1666 accounts β β
β β ~1K TPS β β ~1K TPS β β ~1K TPS β β
β ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ β
β β β β β
ββββββββββββββΌβββββββββββββββββββββΌβββββββββββββββββββββΌβββββββββββββ
β β β
ββββββββββββββββββββββΌβββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β YOUR FULLNODE (Optional) β
β aptos.cash.trading:8080 β
β Low latency, no rate limits β
βββββββββββββββββββ¬ββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββ
β APTOS TESTNET β
β Multi-outcome prediction β
β market with Aggregator V2 β
β ~160K TPS network capacity β
βββββββββββββββββββββββββββββββββββ
For the highest TPS using the 2000-account demo script, run AMM-only full mode:
./scripts/demo.sh full 60Mermaid flow of how scripts/demo.sh ties into the codebase and the execution path:
flowchart TD
A["Run ./scripts/demo.sh full 60"] --> B["cmd_full"]
subgraph Local["Local Machine"]
B --> C["cmd_preflight"]
C --> C1["Load SEED_MNEMONIC"]
C --> C2["SSH health check"]
C --> C3["Check VFN RPC"]
B --> D["cmd_standby"]
D --> D1["SSH to workers"]
D1 --> D2["Export env vars"]
D2 --> D3["Start AMM server"]
B --> E["cmd_launch"]
E --> E1["POST /start to workers"]
E --> E2["Optional transfer server"]
B --> F["cmd_collect"]
F --> F1["SCP tx results"]
F1 --> F2["Merge JSON files"]
B --> G["cmd_analyze"]
G --> G1["auto-analyze.ts"]
G1 --> G2["analyze-submitted-txns.ts"]
G1 --> G3["deep-tps-analysis.ts"]
G1 --> G4["analyze-tps.ts"]
end
subgraph WorkerVM["Worker VM x3"]
S["hft-piscina-server.ts"]
S --> S1["Express HTTP API"]
S --> S2["WebSocket broadcast"]
S --> S3["Spawn worker threads"]
S --> S4["Aggregate stats"]
S4 --> S5["Write results to disk"]
end
subgraph TradingWorkers["Worker Threads"]
W1["trading-worker.ts"]
W1 --> W2["Derive accounts"]
W2 --> W3["Trading loop"]
W3 --> W4["Build payloads"]
W4 --> W5["Build transactions"]
W5 --> W6["Sign locally"]
W6 --> W7["Submit to chain"]
W7 --> W8["Backoff on errors"]
W7 --> W9["Record tx hashes"]
W9 --> W10["Report to main"]
end
S3 --> W1
W10 --> S4
subgraph Chain["Aptos Testnet"]
RPC["Internal VFN RPC"]
Contracts["Move Contracts"]
end
W7 --> RPC --> Contracts
subgraph UI["Frontend"]
UI1["HFTDemoPage.tsx"]
UI2["HFTLaunchControl.tsx"]
UI3["useHFTConnection.ts"]
end
UI1 --> UI3
UI2 --> S1
UI3 --> S2
subgraph Monitoring["Monitoring"]
L1["live-feed.ts"]
L2["GET /stats"]
end
L1 --> L2 --> S1
Notes:
--dualsplits accounts between AMM and USD1 transfers; AMM-only maximizes TPS.cmd_deploysyncsserver/to/opt/aptos-hfton each worker if you changed server code.
To create visual impact (chart spikes) while conserving APT:
| Chance | Size | Effect |
|---|---|---|
| 0.1% | 8-15 APT | π³ MEGA WHALE - massive spike! |
| 0.5% | 2-6 APT | π Whale - big jump |
| 2% | 0.3-1 APT | Large - noticeable |
| 5% | 0.1-0.3 APT | Medium |
| 15% | 0.03-0.1 APT | Small |
| 77.4% | 0.005-0.03 APT | Micro |
Trump emerges as frontrunner (~40-50%) through weighted trading strategy.
| Type | Address |
|---|---|
| Contract (v3 - Full Aggregators) | 0xa2e5e47aab07fed78a3bcf95135ee2dad20c547499c94cb16a3e047859ffa7e1 |
| Production Market (2028 GOP) | 0xfefd1b67818ee4ef12a7953852c83f0efb411a9b92c518a52ba92555e4abdd96 |
npm installnpm run dev- Main App: http://localhost:5173
- Breaking Page: http://localhost:5173/polymarket
- TPS Dashboard: http://localhost:5173/demo-day
| Optimization | Description | Impact |
|---|---|---|
| Orderless Transactions (AIP-123) | Random nonces instead of sequence numbers | No sequence bottleneck |
| Aggregator V2 (AIP-47) | Parallel-safe reserve updates | True parallel contract execution |
| Multi-RPC Load Balancing | Round-robin across 5+ RPC endpoints | Bypass rate limits |
| Fire-and-Forget (98%) | Don't wait for tx confirmation | Maximum submission speed |
| Large Batch Size (150) | More txns per submission cycle | Higher throughput |
| Mode | Batch Size | Delay | Sample Rate | Use |
|---|---|---|---|---|
dryrun |
10 | 100ms | 50% | Quick test |
normal |
150 | 0ms | 0.3% | Full demo |
Complete Sets model with CPMM pricing for 2-20 outcomes.
How it works:
- 1 APT buys a complete set (1 of each outcome token)
- Individual outcome tokens trade via CPMM
- Arbitrage keeps prices summing to ~100%
- Winning tokens redeem for 1 APT each
Entry Functions:
public entry fun mint_complete_set(user: &signer, market: address, amount: u64)
public entry fun redeem_complete_set(user: &signer, market: address, amount: u64)
public entry fun buy_outcome(buyer: &signer, market: address, outcome_index: u64, amount: u64, min_out: u64)
public entry fun sell_outcome(seller: &signer, market: address, outcome_index: u64, tokens: u64, min_out: u64)
public entry fun resolve(resolver: &signer, market: address, winning_outcome: u64)
public entry fun redeem_winnings(user: &signer, market: address)aptos-polymarket/
βββ contracts/
β βββ sources/
β βββ prediction_market.move # Binary YES/NO markets
β βββ multi_outcome_market.move # Multi-outcome markets (v3)
βββ server/
β βββ hft-ultra-server.ts # Maximum TPS server
βββ scripts/
β βββ orchestrator.sh # Main demo orchestrator
β βββ demo-view.sh # 3-worker log viewer
β βββ dryrun-view.sh # Single worker log viewer
β βββ ...
βββ src/
β βββ polymarket/ # Polymarket-style UI
β β βββ BreakingPage.tsx # Main page with demo button
β β βββ HFTDemoPage.tsx # TPS Dashboard
β β βββ HFTLaunchControl.tsx # ARM β LAUNCH UI
β β βββ ...
β βββ hooks/
β βββ useHFTConnection.ts # WebSocket to HFT server
βββ package.json
| Feature | Aptos | Polygon | Ethereum |
|---|---|---|---|
| Finality | ~400ms | 2-5 sec | 12+ sec |
| Peak TPS | 160,000+ | ~7,000 | ~30 |
| Parallel Execution | Yes (Block-STM) | No | No |
| Avg Fee | <$0.001 | $0.01-0.10 | $1-50 |
| Orderless Txns | Yes (AIP-123) | No | No |
# Check infrastructure status
./scripts/orchestrator.sh status./scripts/orchestrator.sh stopcurl -s -X POST "https://fullnode.testnet.aptoslabs.com/v1/view" \
-H "Content-Type: application/json" \
-d '{
"function": "0xa2e5e47aab07fed78a3bcf95135ee2dad20c547499c94cb16a3e047859ffa7e1::multi_outcome_market::get_all_prices",
"arguments": ["0xfefd1b67818ee4ef12a7953852c83f0efb411a9b92c518a52ba92555e4abdd96"]
}' | jq .MIT