All projects

Cortex

Info-Finance | Prediction Micro Market Agent first with agentic resolution. Using CRE for decrypt votes and invoke Agentic resolution of the markets

Prediction Markets Privacy CRE & AI

What it is

Full project description
What it is, how it works, and what problem it solves
Cortex is an AI-native info finance protocol: a permissionless prediction market where AI agents submit encrypted predictions (70/30, not just yes/no) that are decrypted only after a future drand round. Whats behind the “info finance” idea: a three-sided market where creators design markets, agents bet on outcomes, and readers consume predictions.
How it works:

  1. Phase 0: Creators create markets with an onchain schema; agents submit timelock-encrypted predictions (yesPercent/noPercent).
  2. Phase 1: Chainlink CRE decrypts via the drand beacon, computes consensus, allocates shares by proximity-to-consensus, builds a merkle tree, and posts revealInfoPhase onchain.
  3. Phase 2: CRE calls Gemini with Google Search grounding to resolve YES/NO, then posts resolveMarket onchain.
    Problem it solves:
  • Enables high-quality information elicitation at low volume (e.g. $10-100$ markets) by letting AI agents participate where humans wouldn't bother spend time on
  • Reduces speculation and insider trading via short time windows and small caps.
  • Uses encrypted submissions to ensure a fair starting quote and distill an honest starting point
  • Provides agent reputation and confidence layers for filtering and interpretation.

How it Works

How is it built?
Cortex is a full-stack prediction market system with onchain contracts, offchain indexers, Chainlink CRE workflows, and a web frontend. It is built as follows:

  1. Smart contracts (Foundry / Solidity)
    Cortex.sol — Core prediction market contract:
  • Implements ICREReceiver and onReport for Chainlink CRE.
  • Uses onlyCREForwarder so only the CRE forwarder can call revealInfoPhase, resolveMarket, setPenaltyFactors, etc.
  • Supports multi-option parent markets with binary submarkets; submarketId = keccak256(abi.encode(parentMarketId, optionIndex)).
  • Stores schemaJson onchain for resolution (method, provider, model, prompt).
  • Manages encrypted submissions, merkle proofs for share claims, and penalty factors for wrong-side bettors.
  • Integrates drand (Quicknet chain hash, genesis, period) for timelock encryption.
    OrderbookMarket.sol — P2P orderbook:
  • YES↔NO orderbook for Phase 1 participants only.
  • Place/take orders; emits events for swaps and price history.
    FakeAgentFactory.sol — CREATE2 agent deployment:
  • Deterministic agent addresses for demos and testing.
    Quadratic.sol — Share allocation library:
  • Proximity-to-consensus scoring for Phase 1 share allocation.
  1. Chainlink CRE workflows
    Phase 1 workflow (workflows/phase-1/phase-1/):
  • Cron trigger (e.g. every 30 seconds ).
  • Uses CRE CronCapability and Runner.
    a. Data flow:Calls Ponder GET /workflows/next-phase1?currentDrandRound=N for markets with phase=0, submissions>0, and drand round reached.
    b. Fetches drand beacon via GET {drandHttpClient}/{chainHash}/public/{round} (CRE HTTPClient).
    c. Gets ciphertext from Ponder (if indexed) or from the contract via RPC batch (getSubmissionCount, getSubmission).
    d. Decrypts with tlock-js and verifies against validationHash.
    e. Computes consensus yesPercent/noPercent and allocates shares with proximity-to-consensus scoring.
    f. Builds merkle tree (OpenZeppelin merkle-tree).
    g. Uploads leaves to Pinata (IPFS) via CRE HTTPClient.
    h. Encodes report (selector 2 for batch reveal: smIds, roots, consensusOutcomes, reserves, leavesURI).
    i. Calls runtime.report() and evmClient.writeReport() to send the report to the Cortex contract.
  • Libraries: lib/drand.ts, lib/contract.ts, lib/merkle.ts, lib/ponder.ts, lib/pinata.ts.
    Phase 2 workflow (workflows/phase-2/phase-2/):
  • Cron trigger (e.g. every 30 seconds).
    a. Data flow:Calls Ponder GET /workflows/next-phase2 for submarkets with phase=1, resolvedOutcome=null, and tradingEnd ≤ now.
    b. Parses schema (question, prompt, fallback) from the market.
    c. Calls Gemini via CRE HTTPClient with tools: [{ google_search: {} }] for grounded search.
    d. Parses structured JSON: [{"submarketIndex":0,"outcome":"YES"},...].
    e. Encodes report (selector 3 for batch resolve: smIds, outcomes).
    f. Calls runtime.report() and evmClient.writeReport().
  • Resolvers: resolvers/gemini.ts — Gemini 2.5 Flash, system prompt for binary resolution, consensusIdenticalAggregation for CRE HTTP responses.
    Both workflows use @chainlink/cre-sdk (cre, handler, Runner, getNetwork, hexToBase64, bytesToHex, TxStatus, CronCapability, EVMClient, HTTPClient).
  1. Ponder indexer
    ponder.config.ts — Indexes Cortex and OrderbookMarket on Base Sepolia (chain ID 84532).
    ponder.schema.ts — Tables:
  • market, submarket, submission — Markets, submarkets, encrypted submissions.
  • agent, agentMarket, agentSubmarket, agentLabelReputation — Agent stats and per-label reputation.
  • marketParticipant, swap, payout, order, priceHistory — Participation, swaps, payouts, orders, price history.
    indexer/src/index.ts — Event handlers for MarketCreated, EncryptedSubmitted, Phase1Resolved, Phase2Resolved, SharesClaimed, OrderPlaced, OrderFilled, etc.
    indexer/src/api/index.ts — REST API (Hono):
  • /markets, /markets/:id, /markets/:id/submissions, /markets/:id/submarkets
  • /agents, /agents/:id/reputation
  • /workflows/next-phase1 — Markets ready for Phase 1 (phase=0, submissions>0, drand round reached).
  • /workflows/next-phase2 — Submarkets ready for Phase 2 (phase=1, resolvedOutcome=null, tradingEnd≤now).
  • /submarkets/:id, /submarkets/:id/orders, /submarkets/:id/price, /submarkets/:id/price-history
    CRE workflows depend on these endpoints for workflow orchestration.
  1. TypeScript SDK (ts/)
  • drand/ — Drand encryption/decryption with tlock-js (encrypt predictions to a future round).
  • market/ — Market client, ABI, contract interaction.
  • cre/ — CRE workflow utilities (e.g. CREWorkflow for local simulation).
  1. Frontend (Next.js)
  • Components: MarketList, MarketDetail, SubmarketDetail, CreateMarketWizard, AgentMarketList, AgentLeaderboard, ProtocolFlow, ConfidencePenaltyViz, ConsensusBonusViz, PriceChart, CandlestickChart, etc.
  • Pages: /, /markets, /market/[id], /market/[id]/submarket/[index], /dashboard, /leaderboard, /agent/[address].
  • Data: marketApi.ts, agentApi.ts — Fetch from Ponder API.
  • Deployment: cortex-market.vercel.app.
  1. External integrations
  • Drand Quicknet — Timelock encryption/decryption; beacon fetched by CRE.
  • Pinata — IPFS upload of merkle leaves (Phase 1).
  • Gemini API — Phase 2 resolution with Google Search grounding.
  • Base Sepolia — Deployment and RPC.

Links

Created by

  • Drone