Inspiration
On prediction markets with few sellers, the price often moves, or the shares sell out while you're still deciding. I realized a bet is only a small part of the work required to maintain shares at your and the market's conviction level. You need to be able to hold a price independent of the market; the same way an options market would allow for equities markets, and DeriBit for crypto.
How we built it
I wrote the smart contract in Rust with Anchor. The program holds the locked shares itself, so only its rules can move them, and payment and delivery happen in the same transaction. The frontend is Next.js 15, React 19, and Tailwind. Prices from Gemini Predictions are shown next to each market for reference. I tested it with 23 integration tests on a local validator, and wrote a Python script that replays simulated price moves to compare locking against buying right away.
Challenges I ran into
The biggest one was finding out my main idea was wrong. I assumed a price lock would always help buyers, but my replay showed a normal buy with a max price does just as well unless prices are moving fast. I had to rethink the product around that.
On the contract side, I had to close loopholes I didn't see at first. The seller could block a purchase by closing their own account, so I moved payments into a vault the program owns. Markets could be resolved while a lock was still active, so now they have to close first. And I had to make sure the moment a lock expires can't count as both "still valid" and "expired" at once.
Accomplishments that I am proud of
- The guarantee is enforced by the program, not by a server. Once you lock a price, nobody can take it from you.
- Receipts can be checked by anyone against chain data.
- In markets with few sellers, the lock cut unfilled shares from 1.62 to 0.39 per order.
What I learned
A price lock is basically an option. It moves value between the buyer and the seller; it doesn't create any. What it really gives you is certainty that your order fills. I also learned how much Solana makes this practical: a purchase confirms in about a second for a fraction of a cent, so a 30-second lock is actually usable.
What's next for Held
- Price the lock fee based on how fast the market is moving, instead of a flat rate
- Use a real resolution source instead of my test admin key
- Lock down the contract's upgrade key with a multisig
- Let outside market makers run their own pools
- Move from devnet to mainnet
Built With
- anchor
- chai
- gemini-api
- mocha
- next.js
- node.js
- python
- react
- rust
- solana
- solana-wallet-adapter
- solana-web3.js
- spl-token
- tailwind-css
- typescript