← Blog

The Solana Deeds #8: A bet that nobody gets to settle in their own favour

An up-or-down price game on Solana devnet that starts and ends on signed Pyth prices. Why 'a fresh price' is the wrong rule for ending a round, what my own program refused from my own script, and the hole that let late joiners see ahead.

Nissan Dookeran7 min readSolanaCoding AgentsAgent Workflows

Picture two friends betting on the weather. Will it be warmer at noon than it was at eleven, or cooler? They each pick a side and put coins in a locked box that neither of them holds. At noon the box pays whoever was right.

The trouble is that a box can't read a thermometer. Someone has to bring it the reading. So the weather bureau writes every reading on a slip and stamps it, anyone can carry a slip to the box, and the box checks the stamp before it believes a word.

On Solana the box is a program and the bureau is a price service called Pyth. A service that brings outside facts to a program is called an oracle. For Deed #8 we built that box: two players stake SOL on whether a price will be higher or lower in a few minutes, and the round starts and ends on prices Pyth has signed. Deed #7 was about where idle dollars sit. This one is about how a program gets a price it can trust.

It runs on devnet, Solana's practice network, with test wallets and play money. The demo is about four minutes and the source is public.

Which price ends a round?

The plan said a round settles from "a fresh price update". That is the wrong rule, and Claude said so before writing the instruction.

Pyth is a pull oracle. It doesn't push prices onto Solana for you. Whoever wants a price fetches a signed one from Pyth's web service, which is called Hermes, and posts it on chain themselves. So if the rule is "any fresh price", the person who calls settle chooses the moment, and chooses which update to post. They would wait for one that suits their side.

So the program doesn't ask for a fresh price. It asks for the one update that covers the round's expiry: the first one published at or after that second, and no more than 60 seconds after it. Every Pyth update carries the publish time of the update before it. The rule is prev_publish_time < expiry <= publish_time, and only one update fits. Anyone can call settle, and it makes no difference who does.

That rule depends on a field behaving the way Pyth's code comments say. Pyth changed where its prices come from on 26 August 2026, and Hermes has needed an API key since then: a request without one got a 401. With my key, Claude could check. Hermes served one update a second, each naming the second before it, and asking twice for the same moment returned the same update. The rule held on live data.

The path from Pyth's price to the payout: Hermes, Pyth's price service, hands out a price with signatures. Pyth's programs on Solana check the signatures and write the price into an account. Players join a round with a stake while it has no starting price. The price_vault program locks the starting price the second joining closes, settles on the price the second the round expires, and pays out from the round's vault.

What if the right slip never turns up?

If only one update can end a round, a round whose update never arrives would lock its stakes for good. A stock feed at night has no update near midnight. A price can arrive with too wide a plus-or-minus.

So there are refunds. If nobody settles within an hour of the expiry, anyone can void the round and every stake goes back. The same happens if the price ends exactly where it started, or if nobody bet on the side that won.

The other checks on a price are short. The account must belong to Pyth's receiver program, so a copy of the right bytes in someone else's account is refused. It must be for the round's feed. Its confidence interval, the plus-or-minus Pyth publishes with every price, can be no wider than 0.5% of the price. And it must be fully verified, which turned out to matter.

Why did my own program refuse my own script?

Before spending anything on devnet, Claude ran the whole round on my laptop against copies of Pyth's real programs, with real prices from Hermes. It cost nothing and it found two faults that the unit tests could not have.

The script posted prices with a one-instruction shortcut in Pyth's receiver. The receiver accepted the update and marked it partially verified. The updates Hermes hands out carry three signatures, and that shortcut calls an update fully verified only at four of the five signers. The program, as built, refuses a partially verified price:

Error Code: PriceNotFullyVerified. Error Number: 6004.

The program was right. The script changed: it now has Pyth's own program check the signatures first, which is what gets the price marked fully verified. The second fault was smaller. Checking and posting together came to 1,283 bytes, and a Solana transaction holds 1,232. They became two transactions.

Could someone who joined late see ahead?

Yes, in the first version.

The round took its starting price when it opened, and players could join for a while after that. Anyone who joined late had already seen which way the price was heading. The payout is shared by stake, so a crowded side pays less, but the edge was real. It was written down as a known limit. The draft video came to me with a question: fix it, mention it, or leave it to the README?

I said fix it, before I narrated anything. Now a round opens with no price at all. When joining closes, anyone can lock the round on the one update that covers that second, by the same rule that ends it. Nobody choosing a side has a starting price to compare the market with.

The fix cost a recut. I had approved the video's first draft an hour earlier, and seven of its thirteen scenes described the old flow.

What did it do on devnet?

Four whole rounds ran on devnet, each with 27 checks read back from the chain after the transactions were final.

Two were before the fix. SOL went from $70.34 to $70.38 in one and the up wallet took the pool. In the other it went from $70.45 to $70.42 and down won.

Two were after. In the first the price when joining closed was $70.32 and at the expiry $70.41, so up won. The second ran from a fresh copy of the public source through the public devnet endpoint, with no private key for the network: $71.10 down to $71.00, and down won.

In each, two throwaway wallets staked 0.01 and 0.005 SOL. The winner received 0.015 and the loser nothing. The vault ended empty, and every deposit came back to the payer. A run cost about 0.0001 SOL in fees.

Locally, 47 tests run whole rounds and every refusal. In 52 runs, Claude removed one of the program's checks in a scratch copy and confirmed a test then failed. Two of those runs first reported "pattern not found" because the code formatter had wrapped the line being removed. They were fixed and run again, and I would sooner have a check that says it missed than one that counts a miss as a pass.

What is it not?

It is a devnet build with play money. It has not been audited. The deployed program can be replaced by whoever holds a shared devnet key. The refund paths were tested locally, not on devnet. Reproducing the devnet run needs a Pyth API key. And none of it is advice about betting on prices: think of it as a way to learn how programs get prices, not as a game to win.

One thing I didn't expect was the toolchain. The first build pinned the versions an earlier deed had proven together. Its tests then ran on a copy of Solana's runtime a major version behind devnet. I asked whether we should be on the latest, Claude tried the newest stable set in a scratch copy, it built and passed first time, and we moved. A test that passes on an old runtime proves less than it looks.