typed_money/currency/
comp.rs

1use super::{Currency, CurrencyType, LiquidityRating, SymbolPosition, VolatilityRating};
2
3/// Compound (COMP)
4///
5/// Compound is a decentralized finance (DeFi) protocol that allows users to
6/// earn interest on their cryptocurrency holdings or borrow against them.
7/// The COMP token is the governance token of the Compound protocol.
8///
9/// # Examples
10///
11/// ```
12/// use typed_money::{Amount, Currency, COMP};
13///
14/// let amount = Amount::<COMP>::from_major(10);
15/// assert_eq!(amount.to_major_floor(), 10);
16/// assert_eq!(COMP::CODE, "COMP");
17/// assert_eq!(COMP::SYMBOL, "COMP");
18/// ```
19#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
20pub struct COMP;
21
22impl Currency for COMP {
23    const DECIMALS: u8 = 18;
24    const CODE: &'static str = "COMP";
25    const SYMBOL: &'static str = "COMP";
26
27    // Rich metadata
28    const NAME: &'static str = "Compound";
29    const COUNTRY: &'static str = "Global";
30    const REGION: &'static str = "Worldwide";
31    const CURRENCY_TYPE: CurrencyType = CurrencyType::Cryptocurrency;
32    const IS_MAJOR: bool = false;
33    const IS_STABLE: bool = false;
34    const INTRODUCED_YEAR: u16 = 2020;
35    const ISO_4217_NUMBER: u16 = 0; // Not an ISO currency
36    const THOUSANDS_SEPARATOR: char = ',';
37    const DECIMAL_SEPARATOR: char = '.';
38    const SYMBOL_POSITION: SymbolPosition = SymbolPosition::After;
39    const SPACE_BETWEEN: bool = true;
40    const VOLATILITY_RATING: VolatilityRating = VolatilityRating::High;
41    const LIQUIDITY_RATING: LiquidityRating = LiquidityRating::Medium;
42}
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47    use crate::Amount;
48
49    #[test]
50    fn test_comp_currency_properties() {
51        assert_eq!(COMP::DECIMALS, 18);
52        assert_eq!(COMP::CODE, "COMP");
53        assert_eq!(COMP::SYMBOL, "COMP");
54    }
55
56    #[test]
57    fn test_comp_amount_creation() {
58        let amount = Amount::<COMP>::from_major(10);
59        assert_eq!(amount.to_major_floor(), 10);
60    }
61
62    #[test]
63    fn test_comp_amount_with_wei() {
64        let amount = Amount::<COMP>::from_minor(1_000_000_000_000_000_000); // 1.000000000000000000 COMP
65        assert_eq!(amount.to_major_floor(), 1);
66        assert_eq!(amount.to_minor(), 1_000_000_000_000_000_000);
67    }
68}