IntraCloud

Autonomous agent that analyzes Uniswap pools and deploys TWAP-resolved prediction markets on-chain.

IntraCloud

Created At

Open Agents

Project Description

IntraCloud is an autonomous prediction market protocol where a Llama-3.1 agent deployed on Cloudflare Workers continuously monitors and scores Uniswap v3/v4 pools to identify the most suitable trading pair for short-duration directional predictions.

The agent operates as a fully autonomous market-making actor: it ingests pool data from five distinct Uniswap integration layers — on-chain RPC (TWAP drift, oracle cardinality, liquidity depth), the Uniswap v3 SDK (tick-to-price math), the Uniswap v4 SDK (pool ID validation), the Uniswap Trade API (v3/v4 routing confidence and price impact diagnostics), and Uniswap subgraphs (candidate discovery and volume signals) — and produces a composite suitability score emphasizing stability, manipulation resistance, and profitability.

Once the highest-scoring pool is identified, the agent formulates a directional price thesis, calibrates round parameters (duration between 5–15 minutes, TWAP window between 30–300 seconds), and calls the IntraPredictionMarket smart contract on Sepolia to create a new prediction round. The contract captures a TWAP snapshot at round creation, and upon expiry, queries the Uniswap v3 oracle again to deterministically resolve the outcome — no external oracles, no multisig resolution, no off-chain dispute layer.

Users interact through a Next.js web application that surfaces the agent's latest analysis, displays the active prediction round with real-time Uniswap pool pricing, shows dynamic crowding ratios (so participants can assess implied odds and estimated payouts before committing), and handles wallet-native position entry and claiming. The platform stores no user data — only temporary round caches and permanent aggregate protocol metrics (volume, total rounds, participant count).

The result is a closed-loop system: an AI agent that reasons about DeFi liquidity conditions, acts on its analysis by deploying on-chain prediction rounds, and creates a transparent market for users to express views on short-term price direction — all settled trustlessly through Uniswap's native TWAP infrastructure.

How it's Made

IntraCloud is architected as four interconnected modules that form a closed autonomous loop from market intelligence to on-chain settlement.

Agent (Cloudflare Workers + Workers AI): The prediction agent runs as a serverless Cloudflare Worker using Workers AI with @cf/meta/llama-3.1-8b-instruct for natural language prediction generation. Pool discovery starts by indexing PoolCreated events from the Uniswap v3 Factory contract via RPC, augmented with subgraph-sourced candidates when deeper historical signals are needed. Each candidate is scored across multiple Uniswap-native dimensions: we call observe() on-chain for TWAP drift and oracle cardinality, use @uniswap/v3-sdk for tick-to-price conversion and drift quantification, probe the Uniswap Trade API for v3/v4 routing quality and price impact diagnostics, and validate v4 pool IDs with @uniswap/v4-sdk. This multi-source approach is critical — no single data layer gives sufficient signal for manipulation-resistant pool selection. State persistence uses Cloudflare KV (analysis summaries and round history) which the web app reads directly.

Contracts (Foundry + Solidity 0.8.24): The IntraPredictionMarket contract handles the full round lifecycle with Uniswap v3 TWAP as the sole resolution mechanism. This was a deliberate architectural choice: by querying observe() at round boundaries rather than relying on Chainlink or any external oracle, we keep the entire resolution path within the Uniswap ecosystem. The contract uses OpenZeppelin v5 (Ownable2Step, Pausable, ReentrancyGuard), enforces one active round per pool, supports configurable TWAP windows (30–300s), and implements pull-based claiming to eliminate payout loop gas griefing. previewBetQuote and previewClaim are exposed as view functions so the frontend can show exact crowding ratios and estimated payouts before any transaction.

Web App (Next.js + wagmi + viem): The trading interface connects to the contract via wagmi with viem as the transport layer. Real-time pool pricing streams directly from on-chain reads, and the agent's analysis is fetched from the KV-backed API endpoints. The UI surfaces crowding dynamics prominently — users see how each side's total value affects their estimated payout, making the odds transparent before commitment. No user data is stored; the only persisted state is platform-level aggregate metrics and a temporary cache of recent rounds.

Uniswap Integration (five layers): The notably hacky part of this build is how deeply we lean into Uniswap as both the intelligence source and the settlement layer. Rather than treating Uniswap as just a price feed, the agent treats the entire Uniswap stack — Factory events, SDK price math, Trade API routing, subgraph analytics, and on-chain TWAP oracles — as a unified sensing and settlement substrate. The Trade API integration is particularly interesting: we use v3/v4 quote routing not for trading but as a confidence signal, and cross-validate v4 pool IDs with the official SDK to ensure route integrity.

background image mobile

Join the mailing list

Get the latest news and updates

IntraCloud | ETHGlobal