Accounts and Data Structures
// seeds = [authority_mint]
#[account]
pub struct Event {
pub name: String,
pub authority_mint: Pubkey,
pub points_mint: Pubkey,
pub event_participant_mint: Pubkey,
pub state: EventState,
pub contest_index: u64,
pub reward_index: u64,
pub max_participants: u64,
pub event_entry_fee: Option<EntryFee>,
pub event_token_gate: Option<TokenGate>,
}
// seeds = ['contest', event, index]
#[account]
pub struct Contest {
pub name: String,
pub event: Pubkey,
pub authority_mint: Pubkey,
pub points_mint: Pubkey,
pub contest_participant_mint: Pubkey,
pub state: ContestState,
pub index: u64,
pub max_participants: u64,
pub join_by_authority: bool,
pub contest_entry_fee: Option<EntryFee>,
pub contest_token_gate: Option<TokenGate>,
}
// seeds = ['reward', event, index]
#[account]
pub struct Reward {
pub event: Pubkey,
pub reward_mint: Pubkey,
pub reward_escrow: Pubkey,
pub reward_index: u64,
}
pub enum EventState {
Initializing, // Event has been created and participants may now enter
Started, // No more participants can enter the Event
Ended, // No more contests can be created
Finalized, // All rewards and revokes have been determined, Event becomes immutable
}
pub enum ContestState {
Initializing, // Contest has been created and participants may now enter
Started, // No more participants can enter the Contest
Ended, // Contest has completed, results are being finalized
Finalized, // Contest points have been distributed, Contest is now immutable
}
pub struct TokenGate {
pub mint: Pubkey,
pub amount: u64,
}
pub struct EntryFee {
pub mint: Pubkey,
pub vault: Pubkey,
pub amount: u64,
}
Errors are returned in hexadecimal format from the Solana Blockchain, convert to decimal then reference this page to determine the error. If the decimal returned is not a 6XXX number, then the error is a built-in error from the Solana blockchain, reference here to troubleshoot: https://docs.rs/anchor-lang/latest/anchor_lang/error/enum.ErrorCode.html
// Event Name Length too long
// 6000
NameTooLong
// Event has Ended
// 6001
EventEnded
// Contest has Ended
// 6002
ContestEnded
// Invalid Index
// 6003
InvalidIndex
// Event is Full, no more participants can join
// 6004
EventFull
// Contest is Full, no more participants can join
// 6005
ContestFull
// Event Entry Fee Not Paid, must be paid in same transcation as JoinEvent
// 6006
EventEntryFeeNotPaid
// Participant Failed Event Token Gate Validation
// 6007
EventTokenGateValidationFailed
// Contest Entry Fee Not Paid, must be paid in same transcation as JoinContest
// 6008
ContestEntryFeeNotPaid
// Participant Failed Contest Token Gate Validation
// 6009
ContestTokenGateValidationFailed
// Event Not Ended, cannot distribute rewards
// 6010
EventNotEnded
// Event has Already Started, no more participants can join
// 6011
EventAlreadyStarted
// Contest has Already Started, no more participants can join
// 6012
ContestAlreadyStarted
// Contest has not finished, cannot distribute points
// 6013
ContestNotEnded
// Event has been finalized, no more changes allowed
// 6014
EventFinalized
// Contest has been finalized, no more changes allowed
// 6015
ContestFinalized
// Token Gate Check Failed
// 6016
TokenGateFailed
// Insufficient Permissions to Join Contest
// 6017
InsufficientJoinPermission