AI autonomous vault trading Polymarket BTC 5-min markets via Arc, Hedera HCS, and ENS identity.
PolyAgents is an AI-powered autonomous trading vault that trades Polymarket BTC "Up or Down" 5-minute binary markets using a passive market-making strategy. The agent places $0.01 limit bids on both YES and NO sides simultaneously, and when either side fills, it flips the position at $0.02 to capture the $0.01 spread. AI direction analysis from Gemini 2.0 Flash Lite (via Vercel AI Gateway) informs confidence each cycle, but the core edge is the spread capture, the agent profits whether BTC goes up or down.
The system runs a continuous 13-step trading cycle every 5 seconds: discover the active BTC 5-min market from Polymarket's Gamma API, get an AI trade decision (direction, confidence, reasoning), place simulated or real limit orders, detect fills via a deterministic fill simulator against real Polymarket order book data, sell coverage for held inventory, calculate PnL, and log every step to Hedera Consensus Service (HCS) for full on-chain auditability. Before each AI inference, the agent sends HBAR proportional to the previous call's actual token usage to a payment recipient, demonstrating autonomous agent payments on Hedera.
Vault strategy parameters are cryptographically committed as keccak256 hashes stored on ENS text records under vault subnames (e.g., vault-id.polyagents.eth), enabling anyone to verify that the agent follows its declared policy. Live agent stats (PnL, cycles, flips, mode) are pushed as ENS text records every cycle.
The project integrates three sponsor chains:
The frontend is a complete Next.js 16 dashboard with real-time PnL sparklines, live order book visualization, AI reasoning display, engine cycle logs, ENS verification panel, and a full audit trail.
Deployed proofs:
Frontend: Next.js 16.2 App Router with React 19, TypeScript strict mode, Tailwind CSS 4 with a custom dark theme, shadcn/ui components, Recharts for PnL sparklines and audit charts, sonner for toasts, and lucide-react for icons. All pages are client components with localStorage persistence, no API routes, no database. Authentication via Privy for multi-chain wallet creation (email, social, wallet connect).
Trading Engine: A modular step-based architecture under actions/engine/ with 13 discrete steps orchestrated by trading-cycle.ts: discover-market, ai-analysis, place-bets, check-fills, sell-coverage, handle-expiry, reconcile, log-hedera, update-ens, mirror-arc, ensure-polygon-liquidity, plus bridge steps. The fill simulator (lib/engine/strategy/fill-simulator.ts) uses deterministic rules against real Polymarket CLOB order book data -- fills BUY when bestAsk <= our price, fills SELL when bestBid >= our price. Three operating modes via POLYMARKET_LIVE env var: false (ReadOnlyClobAdapter -- simulated orders, real market data), demo (real CLOB, no bridges), true (fully live with Circle bridge). The engine store was originally fs-based but converted to in-memory to work on Vercel's read-only serverless filesystem.
AI Analysis: Vercel AI SDK with Gemini 2.0 Flash Lite via Vercel AI Gateway. Each cycle, the engine sends market context (current price, order book depth, time to expiry) and receives a structured trade decision (shouldTrade, direction, confidence, reasoning). The cost is metered and paid in HBAR to the Hedera payment recipient proportional to actual token usage.
Arc Integration: PolyAgentsMarket.sol deployed on Arc Testnet -- a Solidity contract with Ownable, Pausable, and ReentrancyGuard for binary prediction market creation, USDC betting, resolution, and claim flows with a 0.5% protocol fee. viem client for contract interaction. Circle Bridge Kit integration code written for USDC liquidity bridging between Polygon and Arc. Arc has no mainnet yet, so all contract interactions are testnet-only -- there is no way to route real Polymarket trades through Arc via CCIP at this time.
Hedera Integration: @hashgraph/sdk for native Hedera services with zero Solidity on Hedera. HTS for vault token creation with custom fee schedules and non-transferable operator tokens. HCS for per-step audit logging with 7 event types (MARKET_DISCOVERED, AI_DECISION, ORDERS_PLACED, FILLS_DETECTED, SELLS_PLACED, RECONCILIATION, PNL_UPDATE) via logEngineStep(). HCS-14 for on-chain agent identity with a Universal Agent ID. HBAR micropayments per cycle proportional to actual LLM token usage, sent to a designated payment recipient. Scheduled transactions for future-dated operations. Mirror Node queries for audit trail retrieval. In the frontend demo, HCS logs and HBAR payments are simulated with setTimeout; the real SDK calls are implemented in lib/hedera/ and actions/hedera/.
ENS Integration: viem on Sepolia for ENS subname creation (vault-id.polyagents.eth), keccak256 policy hash commitment as text records (policy.commitment), live agent stats as queryable text records (agent.pnl, agent.flips, agent.cycles, agent.mode, agent.engineState, agent.inventory, agent.lastTrade), ENSIP-25 agent identity records (ai.agent.hcs14-uaid, ai.agent.capabilities, ai.agent.network), and a custom SimpleTextResolver.sol deployed on Sepolia for gas-efficient text record reads. Policy verification UI compares on-chain hash with locally computed hash to prove agent integrity. ENS writes are simulated in the demo; the real Sepolia transaction code exists in lib/ens/.

