use crate::{cdk::types::Cycles, config::schema::CanisterConfig};
pub const CYCLE_TRACKER_RETENTION_SECS: u64 = 60 * 60 * 24 * 7;
#[must_use]
pub const fn retention_cutoff(now: u64) -> u64 {
now.saturating_sub(CYCLE_TRACKER_RETENTION_SECS)
}
#[derive(Clone, Debug)]
pub struct TopupPlan {
pub amount: Cycles,
}
#[must_use]
pub fn should_topup(cycles: u128, cfg: &CanisterConfig) -> Option<TopupPlan> {
let topup_policy = cfg.topup_policy.as_ref()?;
if cycles >= topup_policy.threshold.to_u128() {
return None;
}
Some(TopupPlan {
amount: topup_policy.amount.clone(),
})
}