canic-core 0.26.7

Canic — a canister orchestration and management toolkit for the Internet Computer
Documentation
use crate::{cdk::types::Cycles, config::schema::CanisterConfig};

///
/// CycleTracker retention policy.
///

pub const CYCLE_TRACKER_RETENTION_SECS: u64 = 60 * 60 * 24 * 7; // ~7 days

#[must_use]
pub const fn retention_cutoff(now: u64) -> u64 {
    now.saturating_sub(CYCLE_TRACKER_RETENTION_SECS)
}

///
/// TopupPlan
///

#[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(),
    })
}