#[doc(hidden)]
pub const STR_002_MODULE_PRESENT: () = ();
use crate::constants::{
EPOCH_FIRST_BLOCK_BONUS, FEE_PROPOSER_SHARE_PCT, HALVINGS_BEFORE_TAIL, HALVING_INTERVAL_BLOCKS,
INITIAL_BLOCK_REWARD, MINIMUM_EPOCH_REWARD, TAIL_BLOCK_REWARD,
};
use crate::types::reward::RewardDistribution;
pub fn block_reward_at_height(height: u64) -> u64 {
let halvings = (height - 1) / HALVING_INTERVAL_BLOCKS;
if halvings >= HALVINGS_BEFORE_TAIL {
TAIL_BLOCK_REWARD
} else {
INITIAL_BLOCK_REWARD >> halvings
}
}
pub fn total_block_reward(height: u64, is_first_of_epoch: bool) -> u64 {
block_reward_at_height(height)
+ if is_first_of_epoch {
EPOCH_FIRST_BLOCK_BONUS
} else {
0
}
}
pub fn proposer_fee_share(total_fees: u64) -> u64 {
total_fees * FEE_PROPOSER_SHARE_PCT / 100
}
pub fn burned_fee_remainder(total_fees: u64) -> u64 {
total_fees - proposer_fee_share(total_fees)
}
pub fn compute_reward_distribution(
epoch: u64,
total_reward: u64,
total_fees: u64,
) -> RewardDistribution {
let proposer_reward = total_reward * 10 / 100;
let ef_spawner_reward = total_reward * 3 / 100;
let score_submitter_reward = total_reward * 4 / 100;
let finalizer_reward = total_reward * 3 / 100;
let attester_reward = total_reward
- proposer_reward
- ef_spawner_reward
- score_submitter_reward
- finalizer_reward;
RewardDistribution {
epoch,
proposer_reward,
attester_reward,
ef_spawner_reward,
score_submitter_reward,
finalizer_reward,
proposer_fee_share: proposer_fee_share(total_fees),
burned_fees: burned_fee_remainder(total_fees),
}
}
pub fn epoch_reward_with_floor(computed_epoch_reward: u64) -> u64 {
computed_epoch_reward.max(MINIMUM_EPOCH_REWARD)
}