miner_api/state.rs
1use bytemuck::{Pod, Zeroable};
2
3/// Account discriminators.
4pub const CONFIG_DISCRIMINATOR: u64 = 1;
5pub const ROUND_DISCRIMINATOR: u64 = 2;
6pub const MINER_DISCRIMINATOR: u64 = 3;
7
8/// Global program configuration ("config" PDA, singleton).
9#[repr(C)]
10#[derive(Clone, Copy, Debug, Pod, Zeroable)]
11pub struct Config {
12 pub discriminator: u64,
13 /// Admin (update_config / set_admin). Held by a multisig with a timelock.
14 pub admin: [u8; 32],
15 /// Token mint (mint authority = "treasury" PDA).
16 pub mint: [u8; 32],
17 /// Index of the current (open) round.
18 pub current_round: u64,
19 /// Start timestamp of the current round.
20 pub round_start_ts: i64,
21 /// Minimum hash difficulty (leading zero bits).
22 pub min_difficulty: u64,
23 /// Free-tier base weight in native token units.
24 pub base_weight: u64,
25 /// Round length in seconds (submit cadence; the round budget scales
26 /// pro-rata, so emission per minute stays constant).
27 pub round_seconds: u64,
28 /// Config PDA bump.
29 pub config_bump: u64,
30 /// Treasury PDA bump.
31 pub treasury_bump: u64,
32}
33
34/// One distribution round ("round" PDA + LE index).
35/// A round is open when index == config.current_round; settleable when
36/// index < config.current_round; closable (rent recovery) after
37/// ROUND_RETENTION.
38#[repr(C)]
39#[derive(Clone, Copy, Debug, Pod, Zeroable)]
40pub struct Round {
41 pub discriminator: u64,
42 pub index: u64,
43 /// Sum of all submit weights in the round (native token units).
44 pub total_weight: u64,
45 /// Round open timestamp.
46 pub start_ts: i64,
47 /// Round emission budget (frozen at open from config.round_seconds so
48 /// a later cadence change never touches old rounds' settlements).
49 pub budget: u64,
50}
51
52/// Miner account ("miner" PDA + authority).
53#[repr(C)]
54#[derive(Clone, Copy, Debug, Pod, Zeroable)]
55pub struct Miner {
56 pub discriminator: u64,
57 /// Owner wallet (a browser burner or a connected wallet).
58 pub authority: [u8; 32],
59 /// Session key allowed to submit (zeros = none).
60 pub session_key: [u8; 32],
61 /// Current PoW challenge.
62 pub challenge: [u8; 32],
63 /// Round index of the last submit.
64 pub last_round: u64,
65 /// Weight submitted in round last_round (unsettled if > 0).
66 pub last_round_weight: u64,
67 /// Token balance at the last submit (min-balance / anti-cycling rule).
68 pub last_balance: u64,
69 /// Accrued, unclaimed rewards (native units).
70 pub pending_rewards: u64,
71 /// Lifetime stats.
72 pub total_mined: u64,
73 pub total_hashes: u64,
74 /// PDA bump.
75 pub bump: u64,
76}
77
78impl Config {
79 pub const SIZE: usize = core::mem::size_of::<Config>();
80}
81impl Round {
82 pub const SIZE: usize = core::mem::size_of::<Round>();
83}
84impl Miner {
85 pub const SIZE: usize = core::mem::size_of::<Miner>();
86}