lib.rs 1.2 KB

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