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::OreAccountV1;
7
8#[repr(C)]
9#[derive(Clone, Copy, Debug, PartialEq, Pod, Zeroable, Serialize, Deserialize)]
10pub struct BoardV1 {
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 BoardV1 {
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!(OreAccountV1, BoardV1);
54account!(OreAccountV4, BoardV4);
55
56#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
57pub enum Board {
58    V1(BoardV1),
59    V4(BoardV4),
60}
61
62impl Board {
63    pub fn round_id(&self) -> u64 {
64        match self {
65            Board::V1(b) => b.round_id,
66            Board::V4(b) => b.round_id,
67        }
68    }
69
70    pub fn start_slot(&self) -> u64 {
71        match self {
72            Board::V1(b) => b.start_slot,
73            Board::V4(b) => b.start_slot,
74        }
75    }
76
77    pub fn end_slot(&self) -> u64 {
78        match self {
79            Board::V1(b) => b.end_slot,
80            Board::V4(b) => b.end_slot,
81        }
82    }
83
84    pub fn epoch_id(&self) -> u64 {
85        match self {
86            Board::V1(b) => b.epoch_id,
87            Board::V4(_) => 0,
88        }
89    }
90
91    pub fn pda(&self) -> (Pubkey, u8) {
92        match self {
93            Board::V1(b) => b.pda(),
94            Board::V4(b) => b.pda(),
95        }
96    }
97}