use anchor_lang::prelude::*;
pub const CALLER_PROGRAM_ID: Pubkey = gmsol_programs::gmsol_store::ID_CONST;
#[constant]
pub const COMPETITION_SEED: &[u8] = b"competition";
#[constant]
pub const PARTICIPANT_SEED: &[u8] = b"participant";
#[constant]
pub const MAX_LEADERBOARD_LEN: u8 = 5;
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, Default, PartialEq, Eq, InitSpace)]
#[cfg_attr(feature = "debug", derive(Debug))]
pub struct LeaderEntry {
pub address: Pubkey,
pub volume: u128,
}
#[account]
#[derive(InitSpace)]
#[cfg_attr(feature = "debug", derive(Debug))]
pub struct Competition {
pub bump: u8,
pub authority: Pubkey,
pub start_time: i64,
pub end_time: i64,
#[max_len(MAX_LEADERBOARD_LEN)]
pub leaderboard: Vec<LeaderEntry>,
pub volume_threshold: u128,
pub extension_duration: i64,
pub extension_cap: i64,
pub extension_triggerer: Option<Pubkey>,
pub only_count_increase: bool,
pub volume_merge_window: i64,
}
impl Competition {
pub fn is_ongoing(&self, now: i64) -> bool {
now >= self.start_time && now <= self.end_time
}
}
#[account]
#[derive(InitSpace)]
#[cfg_attr(feature = "debug", derive(Debug))]
pub struct Participant {
pub bump: u8,
pub competition: Pubkey,
pub trader: Pubkey,
pub volume: u128,
pub last_updated_at: i64,
pub merged_volume: u128,
}