Inspiration
Austin runs on small businesses that live or die by a few days. A patio bar on Rainey St does a big share of its week on Friday and Saturday nights. If one of those nights hits 104°F, the patio stays empty. A food truck's best Saturday gets rained out. A sports bar loses half its game-night crowd when the Spurs lose. A caterer with four vans watches a fuel spike eat the margin on every job.
These losses are real, but they're too small and too specific for an insurer to write a policy for. The odd part is that prediction markets already price nearly all of these events: Gemini lists daily highs for Austin, Kalshi lists weekend rain and NBA games, and there are markets on oil and the Fed. But a taco-truck owner is never going to read an order book, work out which contract matches their risk, or decide how many contracts to buy.
So the question became: can an AI turn a prediction market into an insurance quote?
What it does
Hedgehog is an AI risk advisor with an onchain policy book.
- Describe the business. Pick an Austin preset or write one sentence: what you sell, where, when you're busy and your monthly budget.
- Risk map (AI). You get 3-5 "bad days", each with a trigger, an estimated dollar loss and the reasoning: "Over 98°F on a Saturday → patio traffic −40% → about \$1,100 lost."
- Market match. Code pulls live contracts from Gemini, Kalshi and Polymarket. The AI may only pick from those contract IDs.
- Quote. Each line shows the payout if it happens and the premium if it doesn't, sized to 25/50/100% of the loss and capped by the budget. Risks with no usable market are listed as uncovered, with the reason.
- Buy. "Cover all" buys every policy from the Solana program in one wallet approval. The premiums go into a public vault.
- Settle. When the venue resolves the market, a crank settles the policy onchain. A YES pays the owner from the vault.
How I built it
Stack: Next.js 15 + React 19 + TypeScript on the front end and API, an Anchor 0.31 program on Solana devnet, a Node worker for settlement, and a QuickNode Stream for the live feed.
The AI loop: creative where it helps, deterministic where it matters
Claude Sonnet 5.5 (with Gemini 2.5 Flash as fallback) does the parts that need judgment: building the risk map from a sentence and choosing which live contract best matches each risk. Everything that touches money is plain code:
- The AI can't invent markets. Every pick has to be a contract ID that code pulled from a live venue API. Side, date window and asset are re-checked in code. A heat risk must buy the side that pays when it's hot, and a copper risk can't get a gold contract.
- Sizing. Each contract pays \$1, so for coverage share \( c \) and estimated loss \( L \):
$$ n = \left\lceil \frac{c \cdot L}{\$1} \right\rceil, \qquad \text{premium} = \sum_{k=1}^{n} \text{ask}_k $$
where \( \text{ask}_k \) comes from walking the real order book, so a quote never assumes more depth than is visible. The ask is also the market's implied probability, \( p \approx \text{ask} \), so the owner sees "pay \$18 for \$100 if it's over 100°F (≈18% chance)."
- Budget. The total premium is capped by the monthly budget \( B \), and no single line can take more than 60% of it. When the budget binds, lines are funded in order of
$$ \text{priority} = L \cdot \sqrt{\frac{\text{payout}}{\text{premium}}} $$
so large losses with good payout per dollar are covered first.
- Routing. When the same contract trades on several venues, the cheapest one wins, and near-ties (within 1¢) go to Gemini, the primary venue.
- At most 4 LLM calls per quote, enforced by a test.
The onchain policy book (Solana)
The hedgehog_policy Anchor program is the insurer:
buy_policymust be co-signed by the quoter key, so the buyer can't set their own price.- The vault refuses any cover it can't pay in full:
$$ \text{payout} \le \text{vault balance} - \text{outstanding exposure} $$
settle_policypays the owner on YES and closes the policy on NO.expire_policycan be called by anyone after expiry if no result ever arrives, and it refunds the premium. The owner doesn't need to trust Hedgehog to get their money back.
Sold on Solana, hedged on Gemini
Hedgehog sells the risk on Solana, where the vault, the exposure and every payout are public. It offsets the risk on Gemini's regulated order book: every Gemini-priced sale records a matching backing order through the Trader API (HMAC-signed, IOC limit at ask + 2¢). In this build those orders are dry-run.
Live feed with QuickNode Streams
A QuickNode Stream on Solana devnet filters every block for transactions that touch the program, the attestor or the desk, and sends them to a signed webhook. The dashboard's "policy bought" and "policy settled" events come from the chain itself, not from our own API.
Proof it works
Policy #3 was written on Gemini's Austin daily-high market. Gemini resolved it YES, the crank settled it, and the vault paid the owner 3.00 test dollars onchain.
Challenges I ran into
- Stopping the AI from being confidently wrong. Early versions bought the wrong side of a contract (a "high under 90°F" contract to cover a heat wave), matched copper risks to gold, and gave a mortgage broker a gas-price hedge. I built an eval harness: 9 benchmark businesses, a frozen snapshot of 4,000+ live contracts, record/replay LLM caching and hand-graded relevance. I ran 5 improve-and-measure rounds. Validity went from 96% to 100%, and with the LLM switched off entirely, coverage still went from 72% to 83%.
- Security holes in my own program. A money-flow audit found two critical bugs in the deployed program. Anyone could buy a policy at any price they chose, and anyone could drain the vault through an underwriter they created themselves. I reproduced both against the deployed binary on a local validator, fixed them and upgraded the program in place, with tests.
- Settlement timing. I measured each venue's resolution lag from its own timestamps. Crypto settles in seconds, NBA games about 2.5 hours after tip-off, daily highs about 6 hours after midnight, and Kalshi weekend rain about 7.5 hours after close. One early policy would have been refunded before Kalshi settled it. Polymarket's API hides closed markets, so a winning policy would never have seen its result. Both are fixed, and an API error can no longer trigger a refund.
- Thin books. Many Gemini books are only a few hundred dollars deep, so quotes are sized strictly to visible depth. That keeps the cover honest, but small.
- Time. I built it solo in about 36 hours.
What I learned
- Let the LLM choose, and let code check. Restricting the model to a whitelist of real contract IDs and putting guards on side, asset and date made it trustworthy. The fallback path without an LLM became a real feature, not just an error handler.
- Basis risk is the honest core of parametric insurance. The market measures the airport, not your patio. Every line shows its mismatch note, and cover is a share of the estimated loss, not a promise to make you whole.
- Measure before you fix. The settlement-lag numbers and the eval scores changed what I built more than any design doc did.
- Onchain is worth it here for one reason: the owner can see the vault can pay, and can get a refund without asking us.
What's next
Live backing orders on a funded Gemini account, a multisig or oracle attestor in place of a single key, Kalshi outcome tokens on mainnet through DFlow, and pilots with a few Austin businesses to check the loss estimates against their actual books.
Built With
- anchor
- gemini-prediction-markets
- next.js
- quicknode
- rust
- solana
- typescript