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    pub halving_period_seconds: u64,
13    
14    /// Timestamp of the last halving event (Unix timestamp in seconds)
15    pub last_halving_time: u64,
16    
17    /// Base mining rates per well (OIL per second, in atomic units)
18    pub base_mining_rates: [u64; 4],
19    
20    /// Auction duration in seconds (1 hour = 3600)
21    pub auction_duration_seconds: u64,
22    
23    /// Starting prices per well (in lamports)
24    pub starting_prices: [u64; 4],
25    
26    /// Buffer field (for future use)
27    pub buffer_a: Numeric,
28    
29    /// Buffer field (for future use) - previously min_pool_contribution
30    pub buffer_b: u64,
31    
32    /// Buffer field (for future use)
33    pub buffer_c: u64,
34    
35    /// Buffer field (for future use)
36    pub buffer_d: u64,
37}
38
39impl Auction {
40    pub fn pda() -> (Pubkey, u8) {
41        auction_pda()
42    }
43
44    /// Get the timestamp when the next halving should occur
45    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    /// Check if halving should be applied based on current time    
53    pub fn should_apply_halving(&self, current_time: u64) -> u64 {
54        if self.last_halving_time == 0 {
55            // First halving check - if current_time >= halving_period_seconds, apply one halving
56            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; // Time hasn't reached last halving yet
64        }
65        
66        // Calculate how many halving periods have passed
67        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