safe_token_2022/
native_mint.rs

1//! The Mint that represents the native token
2
3/// There are 10^9 lamports in one SAFE
4pub const DECIMALS: u8 = 9;
5
6// The Mint for native SAFE Token accounts
7solana_program::declare_id!("JUFMnWZ6ksBramrswzjQNraYAgHXbQPeC57URvxdcf8");
8
9/// Seed for the native_mint's program-derived address
10pub const PROGRAM_ADDRESS_SEEDS: &[&[u8]] = &["native-mint".as_bytes(), &[255]];
11
12#[cfg(test)]
13mod tests {
14    use {
15        super::*,
16        solana_program::{native_token::*, pubkey::Pubkey},
17    };
18
19    #[test]
20    fn test_decimals() {
21        assert!(
22            (lamports_to_sol(42) - crate::amount_to_ui_amount(42, DECIMALS)).abs() < f64::EPSILON
23        );
24        assert_eq!(
25            sol_to_lamports(42.),
26            crate::ui_amount_to_amount(42., DECIMALS)
27        );
28    }
29
30    #[test]
31    fn expected_native_mint_id() {
32        let native_mint_id =
33            Pubkey::create_program_address(PROGRAM_ADDRESS_SEEDS, &crate::id()).unwrap();
34        assert_eq!(id(), native_mint_id);
35    }
36}