Solana smart contract built with Anchor.
A feature-poor, tightly scoped smart contract for p2p betting.
- Makers offer bets, designating a settlement authority, posting all data onchain (bet is 'offered')
- Makers specify payouts, which can be asymmetrical, in native SOL
- Anyone takes any offered bet in (exactly) the size specified by the maker (bet is then 'live')
- On or after the settlement date, settlement authority decides the outcome (bet is then 'settled')
- On settlement, contract sends funds to the winner, cleans up bet state, and repays Solana blockspace rent to the maker
Directory structure lightly modified from anchor init --test-template rust
:
.
├── Anchor.toml # anchor framework config
├── Cargo.toml # rust workspace
├── app # front end code, eventually
├── cli # cli to offer, take, and settle bets
├── programs # smart contracts
│ └── bet # main program I'm working on
├── tests # tests that use LiteSVM (in process SVM)
Install Rust, Anchor, and the Solana CLI.
See the cli README for details.
Key setup*:
- Program keys are generated automatically by programs/build.rs, which
- generates a new keypair under ./keys/ if none exists
- writes it into the program source
- updates Anchor.toml to set the program address
* Unclear if this is misguided. The default is pretty cumbersome but I might just be misunderstanding the workflow.
Run tests:
anchor test