Devpost project story

Inspiration

Every day people carry risk on events they can't control: a price drop before they sell, a heatwave on the day of an event, a result that decides their week. The odds on those events are already priced, live, on prediction markets. What was missing was a way to turn those odds into protection anyone can buy in one click. While brainstorming with Grok we landed on a simple question: what if a prediction market could act as both the price oracle and the reinsurer for onchain cover? Backstop is the answer to that question.

What it does

Backstop sells parametric event cover in USDC on Arc. You pick an outcome to be protected against (a crypto price, a commodity, the temperature in a city, a game result) and a payout N. Backstop quotes a premium from Gemini's live odds, premium = N × (ask + spread), and you buy the policy in one transaction. The contract locks the full payout, the backend immediately buys N matching contracts on Gemini as the hedge, and when Gemini resolves the market the contract pays you N USDC if your outcome happened. If the hedge can't be filled, the premium is refunded automatically.

On top runs a Grok agent with its own wallet. You can chat with it ("protect my ETH against a drop in the next hour") or let it run on autopilot: it screens every live market and the chain every 30 seconds, values a portfolio at Gemini spot, and decides to buy or hold cover, with a short, numbers-based reason for every decision. Its purchases are real Arc transactions with no human signature, and every decision is logged with its reason in the app's activity feed. You stay in control: you write Grok's instructions in plain English, set a max payout per policy and a daily budget, and can switch the autopilot off at any time, while the server enforces its own hard caps underneath. Policies have already paid out onchain, including one that Grok's autopilot bought on its own: it covered its BTC against a drop, BTC closed below the strike, and the contract paid the agent 6 USDC for a 2.58 USDC premium.

How we built it

  • Smart contract: Backstop.sol in Solidity with Foundry and OpenZeppelin, deployed and verified on Arc testnet. Quotes are EIP-712 signed, single-use and short-lived; the contract checks caps and liquidity, locks payouts, settles, refunds, and gives buyers a self-service refund if the operator disappears. 28 tests, including a fuzz test of the liquidity accounting.
  • Backend: Node and TypeScript (Fastify, viem, SQLite). It prices quotes from the Gemini Prediction Markets API, indexes contract events, places fill-or-kill hedge orders through Gemini's trading API (sandbox), reads Gemini's resolution and settles onchain.
  • Grok agent: the xAI API with tool calling for the chat (screen markets, read its status on Arc, buy cover, start watches) and structured outputs for the autopilot. The server values the user's holdings (up to six assets) at Gemini spot, builds the candidate hedges, and checks every pick against explicit risk rules and the user's own guardrails (max payout per policy, daily budget) before any money moves. Chat replies follow a fixed, receipt-style layout so every answer reads like a broker's confirmation.
  • Web app: Next.js, wagmi and Tailwind: live markets with odds, sparklines and a ticker tape, a receipt-style premium breakdown, a parcel-tracking view of each policy, and the agent's chat, jobs and activity feed.
  • Hosting: Vercel for the web app, Railway (Docker) for the backend.

Challenges we ran into

  • Arc's USDC works differently under the hood. On Arc, USDC is both the gas token and an ERC-20, backed by a system precompile. Foundry's local simulation can't execute those calls, so we moved treasury operations to transactions against the live node and documented the pattern for other Arc builders.
  • Gemini's 64-bit order IDs. Order IDs exceed JavaScript's safe-integer range and get silently rounded, which would make cancels target the wrong order. We kept IDs as strings end to end and verified cancels against the real API.
  • Matching quotes to hedges. Quotes are priced from Gemini's production markets, while our test hedges go to Gemini's sandbox, which has its own order books. We designed the hedger around one rule, only sell cover you can hedge, and built the routing so the same code places real orders in live mode and keeps every market buyable on testnet.
  • Pricing from live data, safely. A hedging product must never sell cover at a stale price. We added a background-refreshed market cache and made quotes fail closed: if a live price can't be confirmed, the quote is refused rather than mispriced.
  • Making an AI agent financially disciplined. A language model on its own tends to chase cheap contracts rather than the side that actually offsets a risk, and natural-language instructions are easy to misread. So we split the work: the server values the portfolio at Gemini spot and computes strike vs spot, cost per $1, implied odds and position size, and only sound candidates reach Grok. Grok makes the call and explains it, and the server re-checks direction, size, budget and live price before any money moves. Buying in the chat requires an explicit instruction.

Accomplishments that we're proud of

  • A new DeFi primitive that works end to end on Arc testnet with real Gemini sandbox orders: payouts, expiries, automatic refunds, and an autonomous Grok purchase whose Gemini hedge filled and then paid out, all with transactions linked in the README.
  • An AI agent that moves real (testnet) money on its own and explains every decision with concrete numbers, inside guardrails the user sets (instructions, max payout per policy, daily budget) and hard limits the server enforces.
  • Four categories of real-world events (crypto, commodities, weather and sports) behind one simple "pay X, get Y if it happens" interface.
  • Safety by construction: premiums below payout, payouts locked at purchase, every policy hedged, failed hedges refunded automatically, and a buyer escape hatch if the operator disappears.

What we learned

  • Prediction markets are a powerful pricing and risk-transfer layer; packaging them as cover makes them useful to people who will never trade them directly.
  • With USDC as gas, the whole product is denominated in dollars, which makes small, short-dated cover practical.
  • An AI agent with a wallet needs the same discipline as a trading desk: the model proposes, but deterministic rules, budgets and price checks decide whether money moves, and every decision should be logged with its reason.
  • Testing against real venues early surfaces the details that matter, like order-book depth and 64-bit order IDs.

What's next for Backstop

  • Trust-minimised resolution: multiple quote signers and resolvers, or a zkTLS proof of Gemini's resolution, so the contract doesn't trust a single relayer.
  • Composable cover: policies as ERC-721/1155 tokens that other protocols can hold or use as collateral.
  • Cross-chain buyers with CCTP: pay from any chain, get paid on Arc or back home.
  • Agent-to-agent cover: Circle Wallets for the agent, and an x402 endpoint so other AI agents can buy cover per request.
  • Production mode: live Gemini orders, depth-aware quotes for larger sizes, and automated treasury rebalancing between Gemini settlements and the onchain USDC float.

Built With

Share this project:

Updates

Submission history