Skip to main content

dig_epoch/types/
reward.rs

1//! # `types::reward` — `RewardDistribution` struct
2//!
3//! **Owner:** REW-007 / REW-004.
4//!
5//! **Spec reference:** [`SPEC.md` §3.12](../../../docs/resources/SPEC.md)
6
7/// Sentinel marker proving the module exists and is reachable at
8/// `dig_epoch::types::reward::STR_002_MODULE_PRESENT`.
9#[doc(hidden)]
10pub const STR_002_MODULE_PRESENT: () = ();
11
12// -----------------------------------------------------------------------------
13// REW-007 — RewardDistribution
14// -----------------------------------------------------------------------------
15
16use serde::{Deserialize, Serialize};
17
18use crate::error::EpochError;
19
20/// Per-epoch reward split across five roles plus the fee distribution.
21///
22/// Spec ref: SPEC §3.12 / REW-007.
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct RewardDistribution {
25    /// Epoch number.
26    pub epoch: u64,
27    /// Block proposer reward share (10% of total).
28    pub proposer_reward: u64,
29    /// Attester reward share (80% of total, absorbs rounding).
30    pub attester_reward: u64,
31    /// Epoch-first spawner reward share (3% of total).
32    pub ef_spawner_reward: u64,
33    /// Checkpoint score submitter reward share (4% of total).
34    pub score_submitter_reward: u64,
35    /// Competition finalizer reward share (3% of total).
36    pub finalizer_reward: u64,
37    /// Proposer's share of transaction fees (50% of total fees).
38    pub proposer_fee_share: u64,
39    /// Burned portion of transaction fees.
40    pub burned_fees: u64,
41}
42
43impl RewardDistribution {
44    /// Serializes with bincode. Infallible for well-formed structs.
45    pub fn to_bytes(&self) -> Vec<u8> {
46        bincode::serialize(self).expect("RewardDistribution serialization should never fail")
47    }
48
49    /// Deserializes from bincode bytes, returning `EpochError::InvalidData` on failure.
50    pub fn from_bytes(bytes: &[u8]) -> Result<Self, EpochError> {
51        bincode::deserialize(bytes).map_err(|e| EpochError::InvalidData(e.to_string()))
52    }
53}