Inspiration

Every sports bar and café near campus has wanted to run "your order's free if the Spurs win." Almost none actually do. If the team wins, the shop owes every customer a refund, and one great night can wipe out a month of margin. So the promo that would pack the store is the one owners are scared to run.

Then I noticed the hedge already exists. Prediction markets sell contracts that pay $1 if an event happens. If a shop could buy exactly enough of those the moment each sale is made, the refund would already be paid for. Nobody had connected that to a checkout, so I did.

What it does

A shop owner signs in with Google, adds their menu and picks a game. Before launching they see the exact cost: "You pay 27.5% of each sale: $1.24 on a $4.50 latte, win or lose." One tap gives them a link and a printable QR sign.

Customers scan, order and pay on their phone. No app, no account, no crypto. Within about a second of each payment, my engine buys matching YES contracts on Gemini's prediction market and records that coverage on Solana. When the game ends, Gemini's result settles the promo. If the team won, every customer is refunded automatically. If they lost, nobody owes anything and the shop keeps every sale.

How the price works. For a refund \(r\) (in dollars), the market price \(a\) of a YES contract that pays $1, and my 10% fee \(m = 0.10\), the shop's cost per sale is

$$ \text{cost} = r \times a \times (1 + m) $$

So a free $4.50 latte on a team with a 25% chance costs

$$ 4.50 \times 0.25 \times 1.10 \approx 1.24 $$

which is $1.24, or 27.5% of the sale. To cover it, the engine buys

$$ n = \lceil r \rceil $$

$1 contracts (the refund in dollars, rounded up), so a $4.50 refund is backed by 5 contracts ($5.00 of protection). The cost is the same whether the team wins or loses, and that predictability is what a shop actually needs.

How I built it

  • Solana (Anchor program on devnet). Each purchase is a single instruction that splits the payment between the shop and the platform, records the refund owed, and mints the customer a Token-2022 refund claim (non-transferable, with a permanent delegate so the program can burn it on payout). The shop's risk cap is enforced on-chain: a sale is rejected if uncovered refunds would exceed the shop's limit, so nobody has to trust my server for that. Hedges are written on-chain with a fingerprint of the Gemini order ID, and payouts burn the claim and pay exactly once. Checkout uses Solana Pay with the platform as fee payer, so customers never need SOL.
  • Gemini Prediction Markets. Live market discovery, real signed orders on Gemini's sandbox (immediate-or-cancel limit buys, never above the shop's maximum price), positions and settled payouts. Gemini's own result decides the outcome, so the hedge and the refund always agree. A verify:orders tool checks every hedge against Gemini's order history and the fingerprint stored on Solana.
  • QuickNode Streams. A programs_with_logs stream on Solana devnet, filtered to my program, pushes every sale to the engine's webhook. Every delivery is checked against QuickNode's HMAC signature, timestamp and nonce. Each promo's public protection page shows the real timings: paid on Solana → delivered by QuickNode (+0.8 s) → bought on Gemini → recorded on Solana.
  • Privy. Google sign-in with an embedded Solana wallet the shop owner controls. Owners sign their own menus and launches. Customers can optionally sign in so their rewards follow them.
  • Next.js app on Vercel, a Node/Fastify engine with SQLite on Railway, and TypeScript end to end.

Challenges I ran into

  • Gemini's sandbox only has sellers about an hour before a game ends. Most of the day there's nothing to buy, so I built clearly labeled practice games for demos and a sales cutoff 12 minutes before close. Gemini stops trading about 10 minutes before and rejects limit prices far above the ask.
  • Gemini order IDs are 64-bit numbers, which silently lose digits as JavaScript numbers. A live order caught it, and I now keep them as strings end to end.
  • A real win almost went unpaid. After a price-ladder market settles, Gemini trims most strikes from the listing, and mine disappeared. The engine couldn't find the result, so a promo that actually won sat stuck. I now derive the outcome from Gemini's official settlement value, and only when that rule agrees with every strike Gemini still lists.
  • Two engines bought protection twice. During deployment, my local engine and the cloud one both reacted to the same sale within the same second. The program blocked any double payout, but it taught me that a hedging engine has to be a single writer.
  • QuickNode deliveries arrive without a Content-Type header, and the free plan stops streams that fall behind. I accept any content type and start streams at the chain tip.
  • Websocket confirmations on devnet were unreliable. Payments looked expired when they'd actually landed, so I switched to polling signature statuses.
  • Privy's SDK was most of the customer page's weight (1.9 MB of JavaScript on a QR scan). Customers rarely sign in, so I now load Privy only when someone taps "Sign in". The page dropped to 318 KB and keeps the cart intact.

Accomplishments that I'm proud of

  • A real end-to-end win on Gemini's sandbox: a sale, protection bought on Gemini, the market settled YES, Gemini paid out, and the customer was refunded on Solana 14 seconds after the market closed.
  • Payment to recorded protection in about a second, visible to anyone on the promo's public page.
  • Fully on-chain, but nothing about it feels like crypto: Google sign-in, tap to pay, order numbers.

What I learned

Prediction markets are an insurance layer hiding in plain sight. Pricing the risk turned out to be easy, since the market does it. The hard part was making the plumbing invisible: confirmations, settlement edge cases, rate limits and page weight. The shop just sees a number before launching, and the customer just gets their money back.

What's next for On the House

  • Register integrations (Square, Toast), so a promo is just a toggle at checkout.
  • Gemini-signed results posted on Solana, which would remove the one step where users trust the platform to move winnings into the refund pool.
  • Sports and weather markets as they come to Gemini.
  • Real USDC with a card on-ramp for customers and bank payouts for shops.

Built With

Share this project:

Updates

Submission history