Inspiration

Before this hackathon I was building a toy app for betting on LLM "horse races" with a parimutuel pot, mostly to learn web and smart-contract development. Parimutuel betting has properties that event-contract exchanges don't. There's no counterparty to wait for. Every outcome of a multi-way event, like a nominee race, lives in one pot instead of a separate yes/no order book per candidate. And the split of money between outcomes reads directly as implied odds.

It also has a flaw I couldn't stop thinking about: being early and right isn't rewarded. Every dollar that lands on your side after you dilutes your payout. If the outcome becomes obvious before the pool closes, late money floods in and pushes the early bettor toward break-even. And once you're in, you can't get out.

My first fix was to weight each bet by its share of the subpool at the moment it entered. Working through it, I found that splitting one bet into many small ones beats it: the weights 1, 1/2, 1/3, … form a harmonic sum that grows without limit. Further exploring solutions led me to David Pennock's dynamic parimutuel market (EC 2004). It solves exactly this problem. PariLayer builds it on Solana, opens every market at Gemini Predictions' prices, and settles on Gemini's results.

What it does

  • Markets mirror Gemini Predictions: binary contracts, multi-outcome events (the 2028 Republican nominee, 13 outcomes in one pool), and pair pools that combine two contracts into four joint outcomes.
  • Every market opens at Gemini's odds. The exchange seeds each pot with 500 USDC at Gemini's prices.
  • Buy: a share never costs more than 1 USDC, and if your outcome wins, each share pays at least 1 USDC, however much money arrives after you. Your floor is fixed when you buy.
  • Sell back: while a market is open, you can sell any number of shares back to the pool along the same price curve.
  • Pool vs. Gemini, side by side: every market page flags a gap of more than 5 points between the pool's odds and Gemini's.
  • Settlement: when Gemini settles, the relayer posts the result on Solana with an audit log, and winners redeem in one click.

What I learned

How a cost function prices a pool. With qᵢ shares of outcome i, the pot holds the length of the share vector:

$$C(q) = \lVert q \rVert_2 = \sqrt{\textstyle\sum_j q_j^2}, \qquad N = \lVert q \rVert_2$$

A trade costs the change in C. Buying stretches your side of the vector; selling shrinks it. The price of the next share and the implied probability are:

$$p_i = \frac{q_i}{N} \le 1, \qquad \pi_i = \frac{q_i^2}{N^2}$$

The vector is never shorter than any one side, so the pot always covers at least 1 USDC per winning share:

$$\text{payout}_i = \frac{M}{q_i} \ge \frac{N}{q_i} \ge 1$$

That's the whole guarantee. Early shares are cheap and late shares cost nearly 1 USDC. Late money still dilutes the payout per share, but only down to 1 USDC, so a small early buy at implied probability π keeps a return of at least

$$\frac{1}{\sqrt{\pi}}$$

A pool can promise a floor, not a fixed payout. An order-book contract pays exactly 1/π because a counterparty posts the other side's money when you trade. A pool has no counterparty, so it can't lock in your exact payout without a subsidy. It can guarantee the floor, though, and that turned out to be the honest version of what I wanted.

Price isn't probability here. At 600 A and 800 B shares, the prices are 0.60 and 0.80, which add up to more than 1. The probabilities are those prices squared: 36% and 64%. The site shows each outcome's probability as the current value of its shares divided by the pot, never as the share of money bet on it.

Someone has to pay to set the opening prices. The pool needs initial shares before any bet can be priced. That seed is a known, capped cost. Here the exchange's treasury pays it and trading fees refill it.

How I built it

I discussed the details of a spec first (the math, invariants, accounts, milestones and acceptance tests), then had an AI coding agent build it milestone by milestone while I reviewed the design.

  • Anchor program on Solana devnet. Every market is a PDA holding share counts and a pot. Outcomes are SPL mints; pots and the treasury are program-owned token accounts. Instructions: create, buy, sell, halt, resolve, void, redeem. The program re-checks M ≥ C(q) after every instruction.
  • The math in its own Rust crate, with no dependencies: closed-form buy and sell with one integer square root each, on u128, with every rounding going against the trader. Property tests run 1,000 random buys, whales included, and check every invariant after each one; separate property tests cover selling, including that a buy followed by an immediate sell costs exactly the two fees. Integration tests run the compiled program in LiteSVM.
  • A TypeScript SDK with a BigInt port of the math, checked against golden vectors generated by the Rust crate.
  • The relayer (Node, Fastify, SQLite, on Fly.io) is the only component that talks to Gemini's public API. It mirrors events, seeds markets at Gemini's mid prices, polls prices and settlements, posts results on-chain, indexes trades, and runs the devnet USDC faucet.
  • A Next.js frontend on Vercel. It works with any Solana wallet, or a one-click burner wallet for judges.

Challenges

  • Protecting early bettors without breaking anything. My timestamp idea fell to the splitting exploit. Integrating the weight fixed that, but pricing each outcome separately made every new bet overpriced. Pennock's design couples all outcomes in one cost function, so the implied probabilities always sum to 1. There's a real trade-off: if nobody buys after you, a plain parimutuel pot pays a little more (2.73× vs. 2.54× in the example on the site), but the pool's floor holds once late money arrives.
  • Exits. A buy-only pool makes you wait for another trader who wants your exact outcome. I designed a discreet trader-to-trader market (a request-for-quote prototype is in the repo) and looked at a liquidity-provider vault, which is Melee's approach. In the end I let the pool buy shares back along the same curve. A refund of C(q) − C(q − s·eᵢ) still leaves M ≥ C(q), so the floor survives any sale. A 2% sell fee stays in the pot, and selling halts when Gemini halts, so late exits can't easily drain the winners' upside.
  • Integer math. Rounding had to go against the trader in every path, yet a buy followed by an immediate sell had to cost exactly the two fees, to within one millionth of a USDC.
  • Gaps in Gemini's docs. Nothing documents whether an event's outcomes are mutually exclusive, what a void looks like, or how combos are priced. I wrote explicit rules for each and logged every gap.
  • Solana's limits. A 32-outcome market needs 32 mints, so they're created in batches. A buy on a 32-outcome market uses about 60,000 compute units.

What's next

  • A midpoint cross between traders: hidden orders matched at the midpoint of the pool's buy and sell prices, public after the fill, the way dark pools work.
  • An opening batch auction, so a market's first trades don't race each other.
  • A decentralized oracle in place of the trusted relayer.

Built With

Share this project:

Updates

Submission history