Agentic MarketAgentic Market Docs
AI Agents & API

Backend Architecture

How the ElysiaJS + Bun + Viem Agent Read Layer indexes assembly log3 events, mirrors BinaryEngine BigInt math, and enforces zero-custody isolation.

The app/ workspace is designed as a stateless, horizontally scalable public read layer with zero private keys in its environment and exact mathematical parity with the Solidity smart contracts.


Architectural Components

Module (app/src/)Responsibility
app.ts & index.tsComposes ElysiaJS routes, CORS, @elysiajs/openapi (Scalar /docs), and per-IP rate limiters (createApp() exported separately for socket-free testing).
indexer/sync.ts & store.tsLive Viem event indexer decoding BinaryEngine's assembly log3 MarketCreated events alongside Trade, MarketPaused, MarketProposed, MarketDisputed, MarketFinalized, Swept, and Redeemed.
indexer/event-bus.tsIn-memory pub/sub fanning out market.created, price.updated, market.paused, market.proposed, market.disputed, market.finalized, and market.voided over SSE.
lib/math.tsExact 6-decimal BigInt implementation of Complete-Set FPMM buy/sell, ceilDiv dynamic & opening fees, and INV-4 TWAP Void payout capping—verified unit-for-unit against live Cancun Anvil in test/integration/anvil-e2e.test.ts.
lib/calldata.tsEncodes unsigned buy, sell, redeem, redeemVoid, redeemBatch, and USDT.approve calldata targeting BinaryEngine directly (zero Router contract).
lib/price-feed.tsSupplies strictly-increasing OHLC candles (1m|5m|15m) anchored to on-chain Chainlink marketKey.startPrice (targetPrice) with deltaUsd and deltaPercent.
lib/rate-limit.tsIn-memory sliding-window per-IP rate limiters (120 req/min indexed reads, 60 req/min fresh-RPC quote/build/MCP) and concurrent SSE cap (3 streams per IP).

Zero-Key Process Isolation

  • app/ NEVER holds KEEPER_PRIVATE_KEY, GUARDIAN_PRIVATE_KEY, RESOLVER_PRIVATE_KEY, or user keys.
  • All privileged on-chain automation runs in the separate workers/ workspace with single-role key isolation.
  • Automated CI compliance checks fail any PR that imports private-key account signers, wallet-request RPC hooks, or raw transaction-broadcasting primitives inside app/src/.