Smart Contract Documentation
Detailed technical documentation of the Solana prediction market program built with Anchor framework. This section covers account structures, instructions, PDA derivations, and error handling.
52eknYvAUeqtTkg9KQHkikSg2SQec2qQLFHmvAjsdF3AAccount Structures
The program uses three main account types to store state on-chain. All accounts are PDAs (Program Derived Addresses) for deterministic addressing.
PredictionMarket
Global state account storing market configuration and counters
["market"]160 bytes1 #[account] 2 pub struct PredictionMarket { 3 4 pub authority: Pubkey, 5 6 pub oracle_authority: Pubkey, 7 8 pub token_mint: Pubkey, 9 10 pub treasury: Pubkey, 11 12 pub total_predictions: u64, 13 14 pub creator_fee_bps: u16, 15 16 pub min_stake_amount: u64, 17 18 pub voting_duration: i64, 19 20 pub quorum_min_votes: u32, 21 22 pub bump: u8, 23 24 pub treasury_bump: u8, 25 }
Prediction
Individual prediction with voting data and resolution status
["prediction", market_pubkey, prediction_id]343 bytes1 #[account] 2 pub struct Prediction { 3 4 pub id: u64, 5 6 pub market: Pubkey, 7 8 pub token_mint: Pubkey, 9 10 pub prediction_type: PredictionType, 11 12 pub target_value: u64, 13 14 pub created_at: i64, 15 16 pub end_timestamp: i64, 17 18 pub status: PredictionStatus, 19 20 pub winning_side: Option<VoteSide>, 21 22 pub valid_stake_total: u64, 23 24 pub fud_stake_total: u64, 25 26 pub valid_vote_count: u32, 27 28 pub fud_vote_count: u32, 29 30 pub ai_confidence: u8, 31 32 pub metadata_uri: String, 33 34 pub bump: u8, 35 pub reward_pool_bump: u8, 36 }
UserStake
Tracks individual user's stake on a specific prediction
["stake", prediction_pubkey, user_pubkey]91 bytes1 #[account] 2 pub struct UserStake { 3 4 pub user: Pubkey, 5 6 pub prediction: Pubkey, 7 8 pub vote_side: VoteSide, 9 10 pub amount: u64, 11 12 pub claimed: bool, 13 14 pub timestamp: i64, 15 16 pub bump: u8, 17 }
Enum Types
PredictionType
VolumeThresholdVolume exceeds threshold in timeframe
PriceIncreasePrice increases by percentage in timeframe
MarketCapTargetMarket cap reaches target value
PredictionStatus
ActiveVoting is open (default state)
ResolvedPrediction resolved with a winner
CancelledCancelled due to insufficient quorum
VoteSide
ValidPrediction will come true
FudPrediction is FUD / won't happen
Instructions
The program exposes eight instructions for interacting with the prediction market. Each instruction has specific access control requirements.
| Instruction | Access | Description | Parameters |
|---|---|---|---|
initialize_market | Admin | Initialize the global prediction market with configuration | creator_fee_bps, min_stake_amount, voting_duration, quorum_min_votes |
create_prediction | Oracle | Create a new prediction for users to vote on | token_mint, prediction_type, target_value, ai_confidence, metadata_uri |
stake_vote | User | Stake tokens and vote on an active prediction | amount, vote_side |
resolve_prediction | Oracle | Resolve a prediction after voting period ends | winning_side |
claim_rewards | User | Claim rewards after being on the winning side | |
cancel_prediction | Oracle | Cancel prediction when quorum is not reached | |
refund_stake | User | Claim refund from a cancelled prediction | |
withdraw_treasury | Admin | Withdraw accumulated fees from treasury | amount |
PDA Derivation
All accounts are Program Derived Addresses (PDAs) with deterministic seeds. This enables trustless account verification and discovery.
| Account | Seeds |
|---|---|
| Market | ["market"] |
| Treasury | ["treasury", market_pubkey] |
| Prediction | ["prediction", market_pubkey, prediction_id_le_bytes] |
| Reward Pool | ["reward_pool", prediction_pubkey] |
| User Stake | ["stake", prediction_pubkey, user_pubkey] |
Error Codes
Custom error codes returned by the program for various failure conditions. Handle these in your client implementation.
| Code | Name | Description |
|---|---|---|
6000 | Unauthorized | Not authorized for this action |
6001 | PredictionNotActive | Prediction is not in active state |
6002 | VotingEnded | Voting period has ended |
6003 | VotingNotEnded | Voting period has not ended yet |
6004 | InsufficientStake | Stake amount below minimum |
6005 | CannotChangeVoteSide | Cannot switch vote sides after initial vote |
6006 | AlreadyClaimed | Rewards/refund already claimed |
6007 | NotWinner | Did not vote on the winning side |
6008 | QuorumNotReached | Minimum votes not reached |
6013 | PredictionNotResolved | Prediction not yet resolved |
6014 | PredictionNotCancelled | Prediction not cancelled |
6015 | InsufficientTreasuryBalance | Treasury balance too low |
6022 | NoWinners | No stakes on winning side |
6023 | QuorumReached | Cannot cancel - quorum was met |