Skip to main content

ore_api/state/
treasury.rs

1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use crate::state::OreAccountV4;
5
6use super::OreAccountV1;
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 TreasuryV1 {
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!(OreAccountV1, TreasuryV1);
62account!(OreAccountV4, TreasuryV4);
63
64#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
65pub enum Treasury {
66    V1(TreasuryV1),
67    V4(TreasuryV4),
68}
69
70#[allow(deprecated)]
71impl Treasury {
72    pub fn balance(&self) -> u64 {
73        match self {
74            Treasury::V1(t) => t.balance,
75            Treasury::V4(_) => 0,
76        }
77    }
78
79    pub fn buffer_a(&self) -> u64 {
80        match self {
81            Treasury::V1(t) => t.buffer_a,
82            Treasury::V4(_) => 0,
83        }
84    }
85
86    pub fn motherlode(&self) -> u64 {
87        match self {
88            Treasury::V1(t) => t.motherlode,
89            Treasury::V4(t) => t.motherlode,
90        }
91    }
92
93    pub fn miner_rewards_factor(&self) -> Numeric {
94        match self {
95            Treasury::V1(t) => t.miner_rewards_factor,
96            Treasury::V4(t) => t.rewards_factor,
97        }
98    }
99
100    pub fn stake_rewards_factor(&self) -> Numeric {
101        match self {
102            Treasury::V1(t) => t.stake_rewards_factor,
103            Treasury::V4(_) => Numeric::ZERO,
104        }
105    }
106
107    pub fn buffer_b(&self) -> u64 {
108        match self {
109            Treasury::V1(t) => t.buffer_b,
110            Treasury::V4(_) => 0,
111        }
112    }
113
114    pub fn total_refined(&self) -> u64 {
115        match self {
116            Treasury::V1(t) => t.total_refined,
117            Treasury::V4(t) => t.total_refined,
118        }
119    }
120
121    pub fn total_staked(&self) -> u64 {
122        match self {
123            Treasury::V1(t) => t.total_staked,
124            Treasury::V4(_) => 0,
125        }
126    }
127
128    pub fn total_unclaimed(&self) -> u64 {
129        match self {
130            Treasury::V1(t) => t.total_unclaimed,
131            Treasury::V4(t) => t.total_unrefined,
132        }
133    }
134}