1use serde::{Deserialize, Serialize};
2use steel::*;
3
4use crate::state::{board_pda, stats_pda, OreAccountV4};
5
6use super::OreAccount;
7
8#[repr(C)]
9#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
10pub struct Board {
11 pub round_id: u64,
13
14 pub start_slot: u64,
16
17 pub end_slot: u64,
19
20 pub epoch_id: u64,
22}
23
24#[repr(C)]
26#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
27pub struct BoardV4 {
28 pub round_id: u64,
30
31 pub start_slot: u64,
33
34 pub end_slot: u64,
36
37 pub production_cost_ema: u64,
39}
40
41impl Board {
42 pub fn pda(&self) -> (Pubkey, u8) {
43 board_pda()
44 }
45}
46
47impl BoardV4 {
48 pub fn pda(&self) -> (Pubkey, u8) {
49 stats_pda()
50 }
51}
52
53account!(OreAccount, Board);
54account!(OreAccountV4, BoardV4);
55
56pub enum BoardAccount {
57 Board(Board),
58 BoardV4(BoardV4),
59}
60
61impl BoardAccount {
62 pub fn round_id(&self) -> u64 {
63 match self {
64 BoardAccount::Board(b) => b.round_id,
65 BoardAccount::BoardV4(b) => b.round_id,
66 }
67 }
68
69 pub fn start_slot(&self) -> u64 {
70 match self {
71 BoardAccount::Board(b) => b.start_slot,
72 BoardAccount::BoardV4(b) => b.start_slot,
73 }
74 }
75
76 pub fn end_slot(&self) -> u64 {
77 match self {
78 BoardAccount::Board(b) => b.end_slot,
79 BoardAccount::BoardV4(b) => b.end_slot,
80 }
81 }
82
83 pub fn epoch_id(&self) -> u64 {
84 match self {
85 BoardAccount::Board(b) => b.epoch_id,
86 BoardAccount::BoardV4(b) => 0,
87 }
88 }
89
90 pub fn pda(&self) -> (Pubkey, u8) {
91 match self {
92 BoardAccount::Board(b) => b.pda(),
93 BoardAccount::BoardV4(b) => b.pda(),
94 }
95 }
96}