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 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 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
93#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
94pub enum Config {
95 V1(ConfigV1),
96 V4(ConfigV4),
97}
98
99impl Config {
100 pub fn admin(&self) -> Pubkey {
101 match self {
102 Config::V1(c) => c.admin,
103 Config::V4(c) => c.admin.authority,
104 }
105 }
106
107 pub fn buffer_a(&self) -> [u8; 32] {
108 match self {
109 Config::V1(c) => c.buffer_a,
110 Config::V4(_) => [0; 32],
111 }
112 }
113
114 pub fn buffer_b(&self) -> [u8; 32] {
115 match self {
116 Config::V1(c) => c.buffer_b,
117 Config::V4(_) => [0; 32],
118 }
119 }
120
121 pub fn buffer_c(&self) -> [u8; 32] {
122 match self {
123 Config::V1(c) => c.buffer_c,
124 Config::V4(_) => [0; 32],
125 }
126 }
127
128 pub fn buffer_d(&self) -> [u8; 32] {
129 match self {
130 Config::V1(c) => c.buffer_d,
131 Config::V4(_) => [0; 32],
132 }
133 }
134
135 pub fn buffer_e(&self) -> [u8; 8] {
136 match self {
137 Config::V1(c) => c.buffer_e,
138 Config::V4(_) => [0; 8],
139 }
140 }
141}