atlas_token_2022_interface/
lib.rs

1#![allow(clippy::arithmetic_side_effects)]
2#![deny(missing_docs)]
3#![cfg_attr(not(test), warn(unsafe_code))]
4
5//! An ERC20-like Token program for the Atlas blockchain
6
7pub mod error;
8pub mod extension;
9pub mod generic_token_account;
10pub mod instruction;
11pub mod native_mint;
12pub mod pod;
13#[cfg(feature = "serde")]
14pub mod serialization;
15pub mod state;
16
17// Export current sdk types for downstream users building with a different sdk
18// version
19pub use atlas_zk_sdk;
20use {
21    atlas_program_error::{ProgramError, ProgramResult},
22    atlas_pubkey::Pubkey,
23};
24
25atlas_pubkey::declare_id!("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
26
27/// Checks that the supplied program ID is correct for atlas-token-2022
28pub fn check_program_account(atlas_token_program_id: &Pubkey) -> ProgramResult {
29    if atlas_token_program_id != &id() {
30        return Err(ProgramError::IncorrectProgramId);
31    }
32    Ok(())
33}
34
35/// In-lined spl token program id to avoid a dependency
36pub mod inline_atlas_token {
37    atlas_pubkey::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
38}
39
40/// Checks that the supplied program ID is correct for atlas-token or
41/// atlas-token-2022
42pub fn check_atlas_token_program_account(atlas_token_program_id: &Pubkey) -> ProgramResult {
43    if atlas_token_program_id != &id() && atlas_token_program_id != &inline_atlas_token::id() {
44        return Err(ProgramError::IncorrectProgramId);
45    }
46    Ok(())
47}
48
49/// Trims a string number by removing excess zeroes or unneeded decimal point
50fn trim_ui_amount_string(mut ui_amount: String, decimals: u8) -> String {
51    if decimals > 0 {
52        let zeros_trimmed = ui_amount.trim_end_matches('0');
53        ui_amount = zeros_trimmed.trim_end_matches('.').to_string();
54    }
55    ui_amount
56}
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_inline_atlas_token_program_id() {
64        assert_eq!(inline_atlas_token::id(), atlas_token_interface::id());
65    }
66}