oil_api/state/auction.rs
1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use crate::state::auction_pda;
5use super::OilAccount;
6
7/// Singleton auction configuration account
8#[repr(C)]
9#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
10pub struct Auction {
11 /// Halving period in seconds (28 days = 2,419,200 seconds)
12 /// Halvings occur every 28 days, reducing mining rates by 50%
13 pub halving_period_seconds: u64,
14
15 /// Timestamp of the last halving event (Unix timestamp in seconds)
16 /// Used to calculate when the next halving should occur
17 pub last_halving_time: u64,
18
19 /// Base mining rates per well (OIL per second, in atomic units)
20 /// OIL's rates: totaling 4.5 OIL/s (12.5% higher than Macaron's 4.0 OIL/s)
21 /// - Well 0 (Seep): 0.45 OIL/s = 45,000,000,000 atomic units/s
22 /// - Well 1 (Flow): 0.9 OIL/s = 90,000,000,000 atomic units/s
23 /// - Well 2 (Gusher): 1.35 OIL/s = 135,000,000,000 atomic units/s
24 /// - Well 3 (Blowout): 1.8 OIL/s = 180,000,000,000 atomic units/s
25 /// Total: 4.5 OIL/s (12.5% higher than Macaron's 4.0 OIL/s)
26 /// Balanced approach: slightly higher rewards with lower LP SOL (55 vs 60)
27 pub base_mining_rates: [u64; 4],
28
29 /// Auction duration in seconds (1 hour = 3600)
30 pub auction_duration_seconds: u64,
31
32 /// Starting prices per well (in lamports)
33 /// Scaled to match mining rate differentiation for strategic choices:
34 /// - Well 0 (Seep): 0.1 SOL = 100,000,000 lamports (lowest price, accessible)
35 /// - Well 1 (Flow): 0.2 SOL = 200,000,000 lamports (2x Well 0)
36 /// - Well 2 (Gusher): 0.3 SOL = 300,000,000 lamports (3x Well 0)
37 /// - Well 3 (Blowout): 0.4 SOL = 400,000,000 lamports (4x Well 0)
38 pub starting_prices: [u64; 4],
39
40 /// Buffer field (for future use)
41 pub buffer_a: Numeric,
42
43 /// Buffer field (for future use) - previously min_pool_contribution
44 pub buffer_b: u64,
45
46 /// Buffer field (for future use)
47 pub buffer_c: u64,
48
49 /// Buffer field (for future use)
50 pub buffer_d: u64,
51}
52
53impl Auction {
54 pub fn pda() -> (Pubkey, u8) {
55 auction_pda()
56 }
57
58 /// Get the timestamp when the next halving should occur
59 /// Halvings occur every halving_period_seconds (28 days)
60 pub fn next_halving_time(&self) -> u64 {
61 if self.last_halving_time == 0 {
62 // If never halved, next halving is period_seconds from now
63 // This should be set during initialization
64 return self.halving_period_seconds;
65 }
66 self.last_halving_time + self.halving_period_seconds
67 }
68
69 /// Check if halving should be applied based on current time
70 /// Returns number of halvings to apply (can be > 1 if multiple periods passed)
71 /// Each halving reduces rates by 50% (multiply by 0.5)
72 pub fn should_apply_halving(&self, current_time: u64) -> u64 {
73 if self.last_halving_time == 0 {
74 // First halving check - if current_time >= halving_period_seconds, apply one halving
75 if current_time >= self.halving_period_seconds {
76 return 1;
77 }
78 return 0;
79 }
80
81 if current_time < self.last_halving_time {
82 return 0; // Time hasn't reached last halving yet
83 }
84
85 // Calculate how many halving periods have passed
86 let time_since_last_halving = current_time - self.last_halving_time;
87 let halvings_to_apply = time_since_last_halving / self.halving_period_seconds;
88
89 halvings_to_apply
90 }
91}
92
93account!(OilAccount, Auction);
94