A prediction market smart contract on Solana. Create and trade YES/NO outcome tokens, then migrate completed markets to Raydium. Built with Anchor for the Solana prediction market ecosystem.
This repo provides an on-chain prediction market smart contract that runs on Solana. Market creators launch binary (YES/NO) markets; traders swap SOL for outcome tokens and back. When a market completes, liquidity can be migrated to Raydium. Use it as a foundation for a Solana prediction market app or integrate the program into your own frontend.
- Create prediction markets with YES and NO outcome tokens
- Swap SOL ↔ YES/NO tokens (buy and sell) on a bonding curve
- Creator claims and fee distribution
- Migrate completed markets to Raydium
- Admin config for fees and launch parameters
Install Rust, Solana, and Anchor (AVM): https://solana.com/docs/intro/installation
Use Anchor v0.30.1:
avm install 0.30.1
avm use 0.30.1anchor run buildIf you use a custom CARGO_TARGET_DIR (e.g. $HOME/.cargo/target), link the built program into the deploy folder:
ln -s $HOME/.cargo/target/sbf-solana-solana/release/takesfun.so $PWD/target/deploy/takesfun.soRun tests without a local network:
anchor test --provider.cluster LocalnetConfigure for localhost and start a validator:
solana config set -ul
solana config set -k ./keys/EgBcC7KVQTh1QeU3qxCFsnwZKYMMQkv6TzgEDkKvSNLv.json
# Start validator with metadata program for tokens
solana-test-validator -r --bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s spl-programs/metadata.soDeploy the prediction market program:
anchor deploy --provider.cluster LocalnetRun tests against localnet:
anchor run test --provider.cluster Localnet
anchor run test --provider.cluster Localnet -- "'correctly configured'"Set the cluster in Anchor.toml to your devnet RPC, then:
anchor deployCall the configure instruction (admin only) to set global config: fee amounts and allowed launch parameters for the prediction market smart contract.
yarn script configyarn script launchyarn script swap -t <TOKEN_MINT> -a <SWAP_AMOUNT> -s <SWAP_DIRECTION>TOKEN_MINT: YES or NO token mint (from launch output)SWAP_AMOUNT: Amount in SOL or tokens to swapSWAP_DIRECTION:0= Buy,1= Sell
After the curve is completed, migrate the market to Raydium:
yarn script migrate -t <TOKEN_MINT>TOKEN_MINT: mint address of the market token to migrate.
Keywords: prediction market, prediction market smart contract, Solana prediction market, binary outcome market, YES NO tokens, Solana Anchor.