1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use crate::state::auction_pda;
5use super::OilAccount;
6
7#[repr(C)]
9#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
10pub struct Auction {
11 pub halving_period_seconds: u64,
13
14 pub last_halving_time: u64,
16
17 pub base_mining_rates: [u64; 4],
19
20 pub auction_duration_seconds: u64,
22
23 pub starting_prices: [u64; 4],
25
26 pub buffer_a: Numeric,
28
29 pub buffer_b: u64,
31
32 pub buffer_c: u64,
34
35 pub buffer_d: u64,
37}
38
39impl Auction {
40 pub fn pda() -> (Pubkey, u8) {
41 auction_pda()
42 }
43
44 pub fn next_halving_time(&self) -> u64 {
46 if self.last_halving_time == 0 {
47 return self.halving_period_seconds;
48 }
49 self.last_halving_time + self.halving_period_seconds
50 }
51
52 pub fn should_apply_halving(&self, current_time: u64) -> u64 {
54 if self.last_halving_time == 0 {
55 if current_time >= self.halving_period_seconds {
57 return 1;
58 }
59 return 0;
60 }
61
62 if current_time < self.last_halving_time {
63 return 0; }
65
66 let time_since_last_halving = current_time - self.last_halving_time;
68 let halvings_to_apply = time_since_last_halving / self.halving_period_seconds;
69
70 halvings_to_apply
71 }
72}
73
74account!(OilAccount, Auction);
75