Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bigz/random-daily-request #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion programs/drift-competitions/src/state/competitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::state::CompetitionRoundStatus;
pub enum CompetitorStatus {
Active,
Disqualified,
RequestedSpinRandomness,
}

impl Default for CompetitorStatus {
Expand Down Expand Up @@ -55,7 +56,9 @@ pub struct Competitor {
pub bonus_score: u64, // this can be used to claim raffle w/o purchase

pub status: CompetitorStatus,
pub padding: [u8; 31],
pub padding1: u64,
pub last_action_ts: i64,
pub padding: [u8; 15],
}

impl Size for Competitor {
Expand Down Expand Up @@ -124,6 +127,44 @@ impl Competitor {
Ok(())
}

pub fn claim_entry_spinner_request(&mut self) -> CompetitionResult {
validate!(
self.status == CompetitorStatus::Active,
ErrorCode::CompetitorUpdateInvalid
)?;
self.status = CompetitorStatus::RequestedSpinRandomness;

Ok(())
}

pub fn claim_entry_spinner_response(&mut self, random_number: u64, now: i64) -> CompetitionResult {
let entry_bonus: u64 = if random_number <= 5000 {
if random_number >= 4_999 {
5_000_000
} else if random_number >= 4_950 {
1_000_000
} else if random_number >= 4_900 {
500_000
} else if random_number >= 4_000 {
1_000
} else if random_number >= 2_500 {
500
} else if random_number >= 1_000 {
250
} else {
10
};
} else {
1 // invalid configuration
};

self.bonus_score = self.bonus_score.saturating_add(entry_bonus);
self.status = CompetitorStatus::Active;
self.last_action_ts = now;

Ok(())
}

pub fn claim_winnings(
&mut self,
competition: &mut Competition,
Expand Down