1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use crate::state::{config_pda, OreAccountV4};
5
6use super::OreAccount;
7
8#[repr(C)]
9#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
10pub struct Config {
11 pub admin: Pubkey,
13
14 pub buffer_a: [u8; 32],
16
17 pub buffer_b: [u8; 32],
19
20 pub buffer_c: [u8; 32],
22
23 pub buffer_d: [u8; 32],
25
26 pub buffer_e: [u8; 8],
28}
29
30#[repr(C)]
31#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
32pub struct ConfigV4 {
33 pub admin: AdminConfig,
35
36 pub protocol: ProtocolConfig,
38}
39
40#[repr(C)]
41#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
42pub struct AdminConfig {
43 pub authority: Pubkey,
45
46 pub fee_collector: Pubkey,
48
49 pub fee_rate: u64,
51}
52
53#[repr(C)]
54#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
55pub struct ProtocolConfig {
56 pub authority: Pubkey,
58
59 pub fee_collector: Pubkey,
61
62 pub fee_rate: u64,
64
65 pub intermission_slots: u64,
67
68 pub round_slots: u64,
70
71 pub entropy_var_address: Pubkey,
73
74 pub entropy_program_id: Pubkey,
76}
77
78impl Config {
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!(OreAccount, Config);
91account!(OreAccountV4, ConfigV4);
92
93pub enum ConfigAccount {
94 Config(Config),
95 ConfigV4(ConfigV4),
96}
97
98impl ConfigAccount {
99 pub fn admin(&self) -> Pubkey {
100 match self {
101 ConfigAccount::Config(c) => c.admin,
102 ConfigAccount::ConfigV4(c) => c.admin.authority,
103 }
104 }
105
106 pub fn buffer_a(&self) -> [u8; 32] {
107 match self {
108 ConfigAccount::Config(c) => c.buffer_a,
109 ConfigAccount::ConfigV4(_) => [0; 32],
110 }
111 }
112
113 pub fn buffer_b(&self) -> [u8; 32] {
114 match self {
115 ConfigAccount::Config(c) => c.buffer_b,
116 ConfigAccount::ConfigV4(_) => [0; 32],
117 }
118 }
119
120 pub fn buffer_c(&self) -> [u8; 32] {
121 match self {
122 ConfigAccount::Config(c) => c.buffer_c,
123 ConfigAccount::ConfigV4(_) => [0; 32],
124 }
125 }
126
127 pub fn buffer_d(&self) -> [u8; 32] {
128 match self {
129 ConfigAccount::Config(c) => c.buffer_d,
130 ConfigAccount::ConfigV4(_) => [0; 32],
131 }
132 }
133
134 pub fn buffer_e(&self) -> [u8; 8] {
135 match self {
136 ConfigAccount::Config(c) => c.buffer_e,
137 ConfigAccount::ConfigV4(_) => [0; 8],
138 }
139 }
140}