HyperTrade

⚡ Real-time on-chain quant trading powered by Envio HyperSync — fast, live, and data-driven

HyperTrade

Created At

ETHOnline 2025

Project Description

HyperTrade — Real-time On-Chain Copy/Follow Trading (TUI) on Envio HyperSync

What it is HyperTrade is a terminal-native (TUI) prototype that turns Envio HyperSync’s ultra-fast Ethereum log streams into instant trading signals on the Uniswap v3 ETH/USDC (0.3%) pool, then runs a paper-trading engine to open/close positions automatically. The TUI shows a live “tape” of blocks and swaps, current position with countdown & unrealized PnL, and an account summary with win-rate and realized PnL — all updating in real time so judges can feel the speed.

Why HyperSync (and how we use it) • Low-latency stream of on-chain data. We subscribe to Swap logs for the target pool and request only the minimal fields (fieldSelection) to reduce payload and speed up processing. • Transaction join = fewer round trips. Using JoinTransactions gives us tx.from alongside logs, enabling “smart wallet” mirroring without extra RPC calls. • Simple, robust cursoring. The stream/batching API with nextBlock lets us stay close to the tip or fast-catch up over the last N blocks.

Result: event→signal latency is visible in the UI, and the app stays responsive even when scanning thousands of recent blocks.

What it does (end-to-end) 1. Ingest & Decode (HyperSync): • Filter to Uniswap v3 Swap events for the ETH/USDC 0.3% pool. • Decode amount0/amount1/sqrtPriceX96 to infer direction (buy/sell ETH), size, and a live price estimate. • Read tx.from (joined transaction) to identify “smart wallets”. 2. Signals (no heavy aggregation): • Smart Wallet Copy: If the swap is initiated by a whitelisted “smart wallet”, mirror its direction. • (Demo mode) Follow sizeable BUY trades even if they’re not from the whitelist (great for live demos). • All signals print to the live tape immediately, with event→signal latency (ms). 3. Paper Trading Engine: • Opens a position (LONG on buy, SHORT on sell), holds for N seconds, or flat/flip on a detected opposite signal. • Computes unrealized and realized PnL from live sqrtPriceX96 price. • Tracks a simple in-memory “account” (starting balance, trade history, win rate, realized PnL). • No external execution — safe by design for demo and judging. 4. TUI Experience (beautiful terminal UI): • Header bar: current mode (Smart-Wallet / Demo), sync status (LIVE / NEAR-LIVE / SYNCING), tip block, and live balance. • Live Feed (left): auto-scrolling tape of blocks, swaps, detections, signals, opens/closes, and errors. • Position Panel (top-right): side/entry/size, countdown to auto-close, and unrealized PnL in USD and %. • Account Summary (bottom-right): total trades, win rate, cumulative PnL, and the 10 most recent trades. • Hotkeys: d toggle demo mode; arrow keys/PageUp/PageDown scroll; g/G to top/bottom; a/z scroll summary; q quit.

Under the hood (key implementation details) • Stack: Node.js + TypeScript + HyperSync client + blessed (TUI). • Selective data: BlockField.Timestamp/Number, LogField.Address/Data/Topic0..3/TransactionHash/BlockNumber, TransactionField.From/Hash. • Decoding: Uses the Swap event signature to parse amount0/amount1/sqrtPriceX96. • Price math: Derives ETH/USDC from sqrtPriceX96 (sufficient for PnL visualization in a PoC). • State model (in-memory): current position, last price, trade history (also saved to a tiny JSON file so a crash doesn’t lose the demo history). • Resilience: Batch processing with friendly error messages and back-off on network issues; shows “NEAR-LIVE” while catching up, “LIVE” at tip.

What judges will see in the terminal • The header flips from SYNCING → NEAR-LIVE → LIVE as the app reaches the chain tip. • Swaps scroll in continuously; a smart-wallet or big BUY triggers Signal → [OPEN] almost immediately. • The position panel ticks down the hold timer; then [CLOSE] prints with PnL (USD and %). • The account summary updates: trade count, win rate, and cumulative PnL. • Throughout, the feed shows event→signal latency and small timing metrics to make the speed obvious.

Scope & decisions (purposefully small but compelling) • One pool only: Uniswap v3 ETH/USDC (0.3%) — keeps focus on latency and clarity. • No database, no web server: TUI first; all state in memory (plus a tiny JSON snapshot). • Signals by events, not ML: We use AI optionally as a “builder/assistant” in other variants, but not for price prediction. • Safety: Paper trading only; no custody or execution risk.

What’s novel / value • Turns raw on-chain events into actionable trading state in real time, right in the terminal. • Visually proves HyperSync’s speed with immediate, human-perceivable feedback (tape + countdown + latency). • Ultra-lean architecture that teams can read, run, and extend in minutes.

Future extensions (post-hackathon) • HyperIndex 1m/5m bars for backtests and richer analytics. • Multi-pool / multi-chain monitoring and routing. • Strategy library (liquidity pull squeeze, liquidation bounce), risk sizing, and slippage models. • Web dashboard twin (SSE/WS) mirroring the TUI for audiences who prefer browsers.

One-line pitch

HyperTrade converts HyperSync’s high-speed on-chain streams into instant copy/follow trading signals with a live, transparent PnL — all in a beautiful terminal UI.

How it's Made

Stack: Node.js + TypeScript + Envio HyperSync client + blessed (for Terminal UI). All logic runs in one process — no backend server, no database — to keep the PoC lightweight and show HyperSync’s speed directly in the terminal.

🧠 Architecture • HyperSync Data Stream: • Subscribes to Uniswap v3 ETH/USDC (0.3%) Swap logs. • Uses fieldSelection to fetch only needed fields and JoinTransactions to include tx.from in a single call. • This eliminates extra RPC requests and highlights HyperSync’s low latency. • Event Decoder: • Decodes amount0/amount1/sqrtPriceX96 → direction (BUY/SELL), trade size, and real-time price. • Trading Logic: • Smart-Wallet Copy Mode: mirrors trades from whitelisted wallets. • Demo Mode: follows any large BUY trade (for easy demo triggers). • Opens a position, holds for N seconds, auto-closes, and calculates PnL. • Paper Trader: • Tracks balance, trades, and win rate in memory (optionally saved to account_state.json). • PnL = (exit - entry)/entry or inverse for shorts.

💻 Terminal UI

Built entirely with blessed for a real-time “trading terminal” feel: • Header: shows mode (SMART-WALLET / DEMO), block height, status (LIVE / NEAR-LIVE), and balance. • Feed: continuously scrolls swaps, signals, and results — updated with HyperSync’s latest blocks. • Position & PnL Panel: displays countdown to auto-close, unrealized and realized PnL. • Hotkeys: d to toggle mode, arrow keys to scroll, q to quit.

All console logs are suppressed during runtime (a little hacky trick!) to prevent TUI corruption.

⚡ Why HyperSync matters

HyperTrade relies on HyperSync for: • Instant event-to-signal reaction (<1–2s typical latency). • Minimal payloads via fieldSelection. • Transaction join → smart-wallet mirroring without RPC delay. This makes the TUI visibly “real-time,” even when backfilling thousands of blocks.

🔧 Hacky but fun bits • Hijacked console.log to protect the TUI redraw. • Dynamic sleep (fast while catching up, slower when live). • In-memory state only — zero setup for judges, instant start.

🚀 Summary

HyperTrade is a one-file terminal app proving that HyperSync’s real-time data streams can drive instant copy-trading logic and PnL visualization — all with zero infrastructure, pure speed, and pure fun.

background image mobile

Join the mailing list

Get the latest news and updates

HyperTrade | ETHGlobal