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