A decentralized prediction market protocol built on Solana that allows users to bet on price movements of cryptocurrencies using real-time price feeds from Pyth Network.
PythPredict enables users to create binary prediction markets where participants can bet YES or NO on whether an asset's price will move within a specified timeframe. The protocol uses Pyth Network's high-fidelity price oracles to ensure fair and transparent market resolution.
- Real-Time Price Feeds: Integration with Pyth Network for accurate BTC/USD and ETH/USD price data
- Binary Markets: Simple YES/NO betting on price movements
- Automated Resolution: Markets resolve automatically based on oracle prices at settlement time
- Fee System: 1% platform fee on all bets
- Fair Payout Distribution: Winners receive proportional shares of the total pool
- Token Conservation: Guaranteed token conservation with no loss of funds
- Node.js v16+ and Yarn
- Rust 1.70+
- Solana CLI tools 1.17+
- Anchor Framework 0.31.1
- Clone the repository
git clone https://github.com/TrebuchetNetwork/PythPredict
cd PythPredict- Install dependencies
yarn install- Build the Solana program
anchor build- Set up local validator (optional for local testing)
./scripts/setup-local.shThe project includes a comprehensive test suite (master-test.ts) that validates all core functionality.
anchor testThe master test suite (tests/master-test.ts) performs extensive testing across 5 main sections:
- Creates prediction markets with correct parameters
- Places bets and validates fee calculations (1% fee)
- Updates odds based on bet distribution
- Resolves markets after settlement time
- Distributes winnings proportionally to winners
- Prevents double-claiming of winnings
- Handles minimum bet amounts
- Maintains perfect token conservation (no tokens lost)
- Resolves empty markets with no bets
- Creates and manages multiple concurrent markets
- Places randomized bets across markets
- Fetches real BTC price from Pyth Network mainnet
- Creates market at actual BTC price (~$118,829 in example)
- Simulates different trading strategies
- Monitors price movement for 20 seconds
- Resolves based on actual price changes
📊 TEST SUITE FINAL REPORT
============================================================
📈 Test Results:
Total Tests: 15
Passed: 15 (100.0%)
Failed: 0
💰 Token Conservation:
Initial Supply: 3500.00 tokens
User Balances: 2922.18 tokens
✅ EXCELLENT: All critical tests passed!
# Build the program
anchor build
# Run tests
anchor test
# Deploy to devnet
anchor deploy --provider.cluster devnet
# Monitor test coverage
./coverage.shprograms/pythpredict/
├── src/
│ ├── lib.rs # Program entry point
│ ├── instructions.rs # Core instruction handlers
│ ├── state.rs # Account structures
│ └── errors.rs # Error definitions
- Market Account: Stores market parameters, pools, and resolution data
- Position Account: Tracks user bets and payouts
- Vault Accounts: Hold YES/NO pools and fees
- Oracle Integration: Pyth price feeds for resolution
initialize_market: Create a new prediction marketplace_bet: Place a YES or NO betresolve_market: Resolve using oracle priceresolve_with_external_price: Resolve with manual price (testing)claim_winnings: Claim payouts after resolution
- Program ID:
J7TLVPzbd47RpiHV8BBPLQuixU53P5qijkrwkvN4u98W - Default cluster: Localnet
- Test script:
yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/master-test.ts
Test wallets are stored in .wallets/ directory:
- alice, bob, charlie, dave, eve (test participants)
- Each funded with SOL and test tokens
- Market Creation: Creator sets initial price, settlement time, and oracle feed
- Betting Phase: Users bet YES (price will move) or NO (price stays same)
- Price Monitoring: Oracle prices tracked in real-time
- Resolution: At settlement, compare final vs initial price
- Payout: Winners share the total pool proportionally
User Payout = (User Stake / Winning Pool) * Total Pool
Example: If YES pool has 100 tokens, NO pool has 50 tokens, and YES wins:
- YES bettors share 150 tokens proportionally
- Each receives their stake + proportional share of losing pool
- PDA-based account derivation
- Signer verification for all critical operations
- Overflow protection with checked math
- Time-based settlement enforcement
- Oracle confidence validation
MIT
Contributions are welcome! Please read our contributing guidelines before submitting PRs.
For issues, questions, or suggestions, please open an issue on GitHub.