Skip to main content

ore_api/state/
treasury.rs

1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use crate::state::OreAccountV4;
5
6use super::OreAccount;
7
8/// Treasury is a singleton account which is the mint authority for the ORE token and the authority of
9/// the program's global token account.
10#[repr(C)]
11#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
12pub struct Treasury {
13    // The amount of SOL collected for buy-bury operations.
14    pub balance: u64,
15
16    /// Buffer a (placeholder)
17    pub buffer_a: u64,
18
19    /// The amount of ORE in the motherlode rewards pool.
20    pub motherlode: u64,
21
22    /// The cumulative ORE distributed to miners, divided by the total unclaimed ORE at the time of distribution.
23    pub miner_rewards_factor: Numeric,
24
25    /// The cumulative ORE distributed to stakers, divided by the total stake at the time of distribution.
26    #[deprecated(since = "3.8.0", note = "Staking has moved to ore-stake program")]
27    pub stake_rewards_factor: Numeric,
28
29    /// Buffer b (placeholder)
30    pub buffer_b: u64,
31
32    /// The current total amount of refined ORE mining rewards.
33    pub total_refined: u64,
34
35    /// The current total amount of ORE staking deposits.
36    #[deprecated(since = "3.8.0", note = "Staking has moved to ore-stake program")]
37    pub total_staked: u64,
38
39    /// The current total amount of unclaimed ORE mining rewards.
40    pub total_unclaimed: u64,
41}
42
43/// Treasury is a singleton account which is the mint authority for the ORE token and the authority of
44/// the program's global token account.
45#[repr(C)]
46#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
47pub struct TreasuryV4 {
48    /// The amount of ORE in the motherlode rewards pool.
49    pub motherlode: u64,
50
51    /// The cumulative ORE distributed to miners, divided by the total unclaimed ORE at the time of distribution.
52    pub rewards_factor: Numeric,
53
54    /// The current total amount of refined ORE mining rewards.
55    pub total_refined: u64,
56
57    /// The current total amount of unrefined ORE mining rewards.
58    pub total_unrefined: u64,
59}
60
61account!(OreAccount, Treasury);
62account!(OreAccountV4, TreasuryV4);
63
64pub enum TreasuryAccount {
65    Treasury(Treasury),
66    TreasuryV4(TreasuryV4),
67}
68
69#[allow(deprecated)]
70impl TreasuryAccount {
71    pub fn balance(&self) -> u64 {
72        match self {
73            TreasuryAccount::Treasury(t) => t.balance,
74            TreasuryAccount::TreasuryV4(_) => 0,
75        }
76    }
77
78    pub fn buffer_a(&self) -> u64 {
79        match self {
80            TreasuryAccount::Treasury(t) => t.buffer_a,
81            TreasuryAccount::TreasuryV4(_) => 0,
82        }
83    }
84
85    pub fn motherlode(&self) -> u64 {
86        match self {
87            TreasuryAccount::Treasury(t) => t.motherlode,
88            TreasuryAccount::TreasuryV4(t) => t.motherlode,
89        }
90    }
91
92    pub fn miner_rewards_factor(&self) -> Numeric {
93        match self {
94            TreasuryAccount::Treasury(t) => t.miner_rewards_factor,
95            TreasuryAccount::TreasuryV4(t) => t.rewards_factor,
96        }
97    }
98
99    pub fn stake_rewards_factor(&self) -> Numeric {
100        match self {
101            TreasuryAccount::Treasury(t) => t.stake_rewards_factor,
102            TreasuryAccount::TreasuryV4(_) => Numeric::ZERO,
103        }
104    }
105
106    pub fn buffer_b(&self) -> u64 {
107        match self {
108            TreasuryAccount::Treasury(t) => t.buffer_b,
109            TreasuryAccount::TreasuryV4(_) => 0,
110        }
111    }
112
113    pub fn total_refined(&self) -> u64 {
114        match self {
115            TreasuryAccount::Treasury(t) => t.total_refined,
116            TreasuryAccount::TreasuryV4(t) => t.total_refined,
117        }
118    }
119
120    pub fn total_staked(&self) -> u64 {
121        match self {
122            TreasuryAccount::Treasury(t) => t.total_staked,
123            TreasuryAccount::TreasuryV4(_) => 0,
124        }
125    }
126
127    pub fn total_unclaimed(&self) -> u64 {
128        match self {
129            TreasuryAccount::Treasury(t) => t.total_unclaimed,
130            TreasuryAccount::TreasuryV4(t) => t.total_unrefined,
131        }
132    }
133}