
I went down a rabbit hole: how do you build on-chain (DeFi) trading infrastructure you can actually trust? The answer became a portfolio I call Trading Lab · Control Room — six small building blocks, each solving one real problem in DeFi trading, wired into a single evidence room you can open in your browser and replay yourself. No wallet, no real money, just recorded scenarios you can inspect step by step.
The five engines, plus the lab that ties them together:
- RFQ Quote & Risk Engine: quotes bid/ask, tracks inventory and exposure, and survives a crash without losing fills or double-counting (C++20 core, SQLite journaling).
- DEX Execution Simulator: picks a swap route by net proceeds after gas, not the biggest gross number. In one case the direct route wins (96.8 vs 95.3 USD) even though the 2-hop looks bigger on paper.
- Chain State Replay: keeps DEX pool state correct when the RPC serves stale or duplicate data, or when the chain reorgs (it rewinds and re-syncs from a trusted anchor).
- RWA Market Guard: tokenized stocks follow real market hours; it blocks or caps quotes when NYSE is closed (weekends, holidays) so settlement doesn’t break.
- Trading Reliability Bench: injects faults (slow, timeout, 429, stale, disconnect) and reports honestly: real success rate and p95 across all outcomes, not a vanity 99% uptime. A stale-but-fast provider gets rejected, not chosen.
- Onchain Trading Lab: ties all five together, records 46 end-to-end scenarios with SHA256 provenance, and plays them back in a bilingual Control Room.
The whole thing runs on one principle: evidence, not assumptions. Every decision is recorded, replayable, and downloadable as JSON, so you can see exactly why a quote was rejected after a reorg, or why an order was blocked on a Friday close.
Under the hood: C++20 + Python + TypeScript, SQLite (WAL) for crash recovery, Uniswap V2/V3 math validated against an Ethereum mainnet fork, 100+ automated tests, CI on Windows + Linux. MIT-licensed.
Honest scope: this is paper trading. The focus is correctness, recovery, and auditability, not live execution or real settlement. The limits are written down openly, on purpose.
source: blockchain.setyadi.com
my other side: ivo.blogspot.com
Leave a Reply