typed_money/currency/
ada.rs

1use super::{CurrencyType, LiquidityRating, SymbolPosition, VolatilityRating};
2use crate::Currency;
3
4/// Cardano (ADA)
5///
6/// Cardano is a blockchain platform for changemakers, innovators, and visionaries,
7/// with the tools and technologies required to create possibility for the many,
8/// as well as the few, and bring about positive global change.
9///
10/// # Examples
11///
12/// ```
13/// use typed_money::{Amount, Currency, ADA};
14///
15/// let amount = Amount::<ADA>::from_major(1000);
16/// assert_eq!(amount.to_major_floor(), 1000);
17/// assert_eq!(ADA::CODE, "ADA");
18/// assert_eq!(ADA::SYMBOL, "₳");
19/// ```
20#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
21pub struct ADA;
22
23impl Currency for ADA {
24    const DECIMALS: u8 = 6;
25    const CODE: &'static str = "ADA";
26    const SYMBOL: &'static str = "₳";
27
28    // Cryptocurrency metadata
29    const NAME: &'static str = "Cardano";
30    const COUNTRY: &'static str = "Global";
31    const REGION: &'static str = "Worldwide";
32    const CURRENCY_TYPE: CurrencyType = CurrencyType::Cryptocurrency;
33    const IS_MAJOR: bool = true;
34    const IS_STABLE: bool = false;
35    const INTRODUCED_YEAR: u16 = 2017;
36    const ISO_4217_NUMBER: u16 = 0; // No official ISO code for cryptocurrencies
37    const THOUSANDS_SEPARATOR: char = ',';
38    const DECIMAL_SEPARATOR: char = '.';
39    const SYMBOL_POSITION: SymbolPosition = SymbolPosition::Before;
40    const SPACE_BETWEEN: bool = false;
41    const VOLATILITY_RATING: VolatilityRating = VolatilityRating::High;
42    const LIQUIDITY_RATING: LiquidityRating = LiquidityRating::High;
43}
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48    use crate::Amount;
49
50    #[test]
51    fn test_ada_currency_properties() {
52        assert_eq!(ADA::DECIMALS, 6);
53        assert_eq!(ADA::CODE, "ADA");
54        assert_eq!(ADA::SYMBOL, "₳");
55    }
56
57    #[test]
58    fn test_ada_amount_creation() {
59        let amount = Amount::<ADA>::from_major(1000);
60        assert_eq!(amount.to_major_floor(), 1000);
61    }
62
63    #[test]
64    fn test_ada_amount_with_lovelace() {
65        let amount = Amount::<ADA>::from_minor(1_000_000); // 1.000000 ADA
66        assert_eq!(amount.to_major_floor(), 1);
67        assert_eq!(amount.to_minor(), 1_000_000);
68    }
69}