gpl_token/
lib.rs

1#![deny(missing_docs)]
2#![cfg_attr(not(test), forbid(unsafe_code))]
3
4//! An ERC20-like Token program for the Gemachain blockchain
5
6pub mod error;
7pub mod instruction;
8pub mod native_mint;
9pub mod processor;
10pub mod state;
11
12#[cfg(not(feature = "no-entrypoint"))]
13mod entrypoint;
14
15// Export current sdk types for downstream users building with a different sdk version
16pub use gemachain_program;
17use gemachain_program::{entrypoint::ProgramResult, program_error::ProgramError, pubkey::Pubkey};
18
19/// Convert the UI representation of a token amount (using the decimals field defined in its mint)
20/// to the raw amount
21pub fn ui_amount_to_amount(ui_amount: f64, decimals: u8) -> u64 {
22    (ui_amount * 10_usize.pow(decimals as u32) as f64) as u64
23}
24
25/// Convert a raw amount to its UI representation (using the decimals field defined in its mint)
26pub fn amount_to_ui_amount(amount: u64, decimals: u8) -> f64 {
27    amount as f64 / 10_usize.pow(decimals as u32) as f64
28}
29
30gemachain_program::declare_id!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
31
32/// Checks that the supplied program ID is the correct one for SPL-token
33pub fn check_program_account(spl_token_program_id: &Pubkey) -> ProgramResult {
34    if spl_token_program_id != &id() {
35        return Err(ProgramError::IncorrectProgramId);
36    }
37    Ok(())
38}