tpl-token-2022-interface 3.2.3

Trezoa Program Library Token 2022 Interface
Documentation
#![allow(clippy::arithmetic_side_effects)]
#![deny(missing_docs)]
#![cfg_attr(not(test), warn(unsafe_code))]

//! An ERC20-like Token program for the Trezoa blockchain

pub mod error;
pub mod extension;
pub mod generic_token_account;
pub mod instruction;
pub mod native_mint;
pub mod pod;
#[cfg(feature = "serde")]
pub mod serialization;
pub mod state;

// Export current sdk types for downstream users building with a different sdk
// version
pub use trezoa_zk_sdk;
use {
    trezoa_program_error::{ProgramError, ProgramResult},
    trezoa_pubkey::Pubkey,
};

trezoa_pubkey::declare_id!("7LwqBGzqGyNW2v1iNwxKR4kbVSYvGMC5xr3MxbkrCEKV");

/// Checks that the supplied program ID is correct for tpl-token-2022
pub fn check_program_account(tpl_token_program_id: &Pubkey) -> ProgramResult {
    if tpl_token_program_id != &id() {
        return Err(ProgramError::IncorrectProgramId);
    }
    Ok(())
}

/// In-lined tpl token program id to avoid a dependency
pub mod inline_tpl_token {
    trezoa_pubkey::declare_id!("4JkrrPuuQPxDZuBW1bgrM1GBa8oYg1LxcuX9szBPh3ic");
}

/// Checks that the supplied program ID is correct for tpl-token or
/// tpl-token-2022
pub fn check_tpl_token_program_account(tpl_token_program_id: &Pubkey) -> ProgramResult {
    if tpl_token_program_id != &id() && tpl_token_program_id != &inline_tpl_token::id() {
        return Err(ProgramError::IncorrectProgramId);
    }
    Ok(())
}

/// Trims a string number by removing excess zeroes or unneeded decimal point
fn trim_ui_amount_string(mut ui_amount: String, decimals: u8) -> String {
    if decimals > 0 {
        let zeros_trimmed = ui_amount.trim_end_matches('0');
        ui_amount = zeros_trimmed.trim_end_matches('.').to_string();
    }
    ui_amount
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_inline_tpl_token_program_id() {
        assert_eq!(inline_tpl_token::id(), tpl_token_interface::id());
    }
}