spl_token_2022_interface/
lib.rs1#![allow(clippy::arithmetic_side_effects)]
2#![deny(missing_docs)]
3#![no_std]
4#![cfg_attr(not(test), warn(unsafe_code))]
5
6extern crate alloc;
9
10pub mod error;
11pub mod extension;
12pub mod generic_token_account;
13pub mod instruction;
14pub mod native_mint;
15pub mod pod;
16#[cfg(feature = "serde")]
17pub mod serialization;
18pub mod state;
19
20pub use solana_zk_elgamal_proof_interface;
23use {
24 alloc::string::{String, ToString},
25 solana_address::Address,
26 solana_program_error::{ProgramError, ProgramResult},
27};
28
29solana_address::declare_id!("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
30
31pub fn check_program_account(spl_token_program_id: &Address) -> ProgramResult {
33 if spl_token_program_id != &id() {
34 return Err(ProgramError::IncorrectProgramId);
35 }
36 Ok(())
37}
38
39pub mod inline_spl_token {
41 solana_address::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
42}
43
44pub fn check_spl_token_program_account(spl_token_program_id: &Address) -> ProgramResult {
47 if spl_token_program_id != &id() && spl_token_program_id != &inline_spl_token::id() {
48 return Err(ProgramError::IncorrectProgramId);
49 }
50 Ok(())
51}
52
53fn trim_ui_amount_string(mut ui_amount: String, decimals: u8) -> String {
55 if decimals > 0 {
56 let zeros_trimmed = ui_amount.trim_end_matches('0');
57 ui_amount = zeros_trimmed.trim_end_matches('.').to_string();
58 }
59 ui_amount
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65
66 #[test]
67 fn test_inline_spl_token_program_id() {
68 assert_eq!(inline_spl_token::id(), spl_token_interface::id());
69 }
70}