cbe-program 1.15.0

Cartallum CBE Program
Documentation
//! Definitions for the native CBC token and its fractional scoobies.

#![allow(clippy::integer_arithmetic)]

/// There are 10^9 scoobies in one CBC
pub const SCOOBIES_PER_CBC: u64 = 1_000_000_000;

/// Approximately convert fractional native tokens (scoobies) into native tokens (CBC)
pub fn scoobies_to_cbc(scoobies: u64) -> f64 {
    scoobies as f64 / SCOOBIES_PER_CBC as f64
}

/// Approximately convert native tokens (CBC) into fractional native tokens (scoobies)
pub fn cbc_to_scoobies(cbc: f64) -> u64 {
    (cbc * SCOOBIES_PER_CBC as f64) as u64
}

use std::fmt::{Debug, Display, Formatter, Result};
pub struct CBC(pub u64);

impl CBC {
    fn write_in_sol(&self, f: &mut Formatter) -> Result {
        write!(
            f,
            "{}.{:09}",
            self.0 / SCOOBIES_PER_CBC,
            self.0 % SCOOBIES_PER_CBC
        )
    }
}

impl Display for CBC {
    fn fmt(&self, f: &mut Formatter) -> Result {
        self.write_in_sol(f)
    }
}

impl Debug for CBC {
    fn fmt(&self, f: &mut Formatter) -> Result {
        self.write_in_sol(f)
    }
}