Skip to main content

ore_api/state/
board.rs

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    /// The current round number.
12    pub round_id: u64,
13
14    /// The slot at which the current round starts mining.
15    pub start_slot: u64,
16
17    /// The slot at which the current round ends mining.
18    pub end_slot: u64,
19
20    /// The current epoch id.
21    pub epoch_id: u64,
22}
23
24/// BoardV4 is a singleton account tracking global game state.
25#[repr(C)]
26#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
27pub struct BoardV4 {
28    /// The current round number.
29    pub round_id: u64,
30
31    /// The slot at which the current round starts mining.
32    pub start_slot: u64,
33
34    /// The slot at which the current round ends mining.
35    pub end_slot: u64,
36
37    /// The exponential moving average of production cost (lamports per whole ORE).
38    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}