Skip to main content

oil_api/state/
share.rs

1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use crate::state::share_pda;
5
6use super::OilAccount;
7
8/// Share account tracks a user's contribution to a specific epoch for a specific well
9#[repr(C)]
10#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
11pub struct Share {
12    /// Authority who made the contribution
13    pub authority: Pubkey,
14    
15    /// Well ID this share is for (0-3)
16    pub well_id: u64,
17    
18    /// Epoch ID this share is for (included in PDA, stored here for convenience)
19    pub epoch_id: u64,
20    
21    /// User's contribution to this epoch's pool (in lamports)
22    pub contribution: u64,
23    
24    /// Timestamp when share was created (first contribution to this epoch)
25    pub created_at: u64,
26    
27    /// Amount of OIL claimed from this epoch (0 = not checkpointed, >0 = checkpointed)
28    pub claimed_oil: u64,
29    
30    /// Amount of SOL refund claimed from this epoch
31    pub claimed_sol: u64,
32    
33    /// Buffer field for future extensions
34    pub buffer_a: u64,
35    
36    /// Buffer field for future extensions
37    pub buffer_b: u64,
38    
39    /// Buffer field for future extensions
40    pub buffer_c: u64,
41}
42
43impl Share {
44    pub fn pda(authority: Pubkey, well_id: u64, epoch_id: u64) -> (Pubkey, u8) {
45        share_pda(authority, well_id, epoch_id)
46    }
47
48    pub fn initialize(&mut self, authority: Pubkey, well_id: u64, epoch_id: u64, clock: &Clock) {
49        self.authority = authority;
50        self.well_id = well_id;
51        self.epoch_id = epoch_id;
52        self.contribution = 0;
53        self.created_at = clock.unix_timestamp as u64;
54        self.claimed_oil = 0;
55        self.claimed_sol = 0;
56        self.buffer_a = 0;
57        self.buffer_b = 0;
58        self.buffer_c = 0;
59    }
60}
61
62account!(OilAccount, Share);