use {
super::{clock::DEFAULT_MS_PER_SLOT, Sysvar},
crate::impl_sysvar_get,
};
#[cfg_attr(feature = "copy", derive(Copy))]
#[derive(Clone, Debug)]
pub struct FeeCalculator {
pub lamports_per_signature: u64,
}
impl FeeCalculator {
pub fn new(lamports_per_signature: u64) -> Self {
Self {
lamports_per_signature,
}
}
}
#[cfg_attr(feature = "copy", derive(Copy))]
#[derive(Clone, Debug)]
pub struct FeeRateGovernor {
pub lamports_per_signature: u64,
pub target_lamports_per_signature: u64,
pub target_signatures_per_slot: u64,
pub min_lamports_per_signature: u64,
pub max_lamports_per_signature: u64,
pub burn_percent: u8,
}
pub const DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE: u64 = 10_000;
pub const DEFAULT_TARGET_SIGNATURES_PER_SLOT: u64 = 50 * DEFAULT_MS_PER_SLOT;
pub const DEFAULT_BURN_PERCENT: u8 = 50;
impl Default for FeeRateGovernor {
fn default() -> Self {
Self {
lamports_per_signature: 0,
target_lamports_per_signature: DEFAULT_TARGET_LAMPORTS_PER_SIGNATURE,
target_signatures_per_slot: DEFAULT_TARGET_SIGNATURES_PER_SLOT,
min_lamports_per_signature: 0,
max_lamports_per_signature: 0,
burn_percent: DEFAULT_BURN_PERCENT,
}
}
}
impl FeeRateGovernor {
pub fn create_fee_calculator(&self) -> FeeCalculator {
FeeCalculator::new(self.lamports_per_signature)
}
pub fn burn(&self, fees: u64) -> (u64, u64) {
let burned = fees * u64::from(self.burn_percent) / 100;
(fees - burned, burned)
}
}
#[cfg_attr(feature = "copy", derive(Copy))]
#[derive(Clone, Debug)]
pub struct Fees {
pub fee_calculator: FeeCalculator,
pub fee_rate_governor: FeeRateGovernor,
}
impl Fees {
pub fn new(fee_calculator: FeeCalculator, fee_rate_governor: FeeRateGovernor) -> Self {
Self {
fee_calculator,
fee_rate_governor,
}
}
}
impl Sysvar for Fees {
impl_sysvar_get!(sol_get_fees_sysvar);
}