Skip to main content

ore_api/state/
config.rs

1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use crate::state::{config_pda, OreAccountV4};
5
6use super::OreAccountV1;
7
8#[repr(C)]
9#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
10pub struct ConfigV1 {
11    /// The address that can update the config.
12    pub admin: Pubkey,
13
14    /// Buffer a (placeholder)
15    pub buffer_a: [u8; 32],
16
17    /// Buffer b (placeholder)
18    pub buffer_b: [u8; 32],
19
20    /// Buffer c (placeholder)
21    pub buffer_c: [u8; 32],
22
23    /// Buffer d (placeholder)
24    pub buffer_d: [u8; 32],
25
26    /// Buffer e (placeholder)
27    pub buffer_e: [u8; 8],
28}
29
30#[repr(C)]
31#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
32pub struct ConfigV4 {
33    /// The admin config.
34    pub admin: AdminConfig,
35
36    /// The protocol config.
37    pub protocol: ProtocolConfig,
38}
39
40#[repr(C)]
41#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
42pub struct AdminConfig {
43    /// The authority of this admin config.
44    pub authority: Pubkey,
45
46    /// The address of the admin fee collector.
47    pub fee_collector: Pubkey,
48
49    /// The admin fee rate.
50    pub fee_rate: u64,
51}
52
53#[repr(C)]
54#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
55pub struct ProtocolConfig {
56    /// The authority of this protocol config.
57    pub authority: Pubkey,
58
59    /// The address of the protocol fee collector.
60    pub fee_collector: Pubkey,
61
62    /// The protocol fee rate.
63    pub fee_rate: u64,
64
65    /// The number of slots in the intermission period.
66    pub intermission_slots: u64,
67
68    /// The number of slots in a round.
69    pub round_slots: u64,
70
71    /// The address of the var account.
72    pub entropy_var_address: Pubkey,
73
74    /// The entropy program id.
75    pub entropy_program_id: Pubkey,
76}
77
78impl ConfigV1 {
79    pub fn pda() -> (Pubkey, u8) {
80        config_pda()
81    }
82}
83
84impl ConfigV4 {
85    pub fn pda() -> (Pubkey, u8) {
86        config_pda()
87    }
88}
89
90account!(OreAccountV1, ConfigV1);
91account!(OreAccountV4, ConfigV4);
92
93pub enum Config {
94    V1(ConfigV1),
95    V4(ConfigV4),
96}
97
98impl Config {
99    pub fn admin(&self) -> Pubkey {
100        match self {
101            Config::V1(c) => c.admin,
102            Config::V4(c) => c.admin.authority,
103        }
104    }
105
106    pub fn buffer_a(&self) -> [u8; 32] {
107        match self {
108            Config::V1(c) => c.buffer_a,
109            Config::V4(_) => [0; 32],
110        }
111    }
112
113    pub fn buffer_b(&self) -> [u8; 32] {
114        match self {
115            Config::V1(c) => c.buffer_b,
116            Config::V4(_) => [0; 32],
117        }
118    }
119
120    pub fn buffer_c(&self) -> [u8; 32] {
121        match self {
122            Config::V1(c) => c.buffer_c,
123            Config::V4(_) => [0; 32],
124        }
125    }
126
127    pub fn buffer_d(&self) -> [u8; 32] {
128        match self {
129            Config::V1(c) => c.buffer_d,
130            Config::V4(_) => [0; 32],
131        }
132    }
133
134    pub fn buffer_e(&self) -> [u8; 8] {
135        match self {
136            Config::V1(c) => c.buffer_e,
137            Config::V4(_) => [0; 8],
138        }
139    }
140}