pub use light_compressed_token_sdk::utils::TokenDefaultAccounts;
use light_token_interface::state::Token;
use solana_account_info::AccountInfo;
use solana_program_error::ProgramError;
use solana_pubkey::Pubkey;
use crate::{constants::LIGHT_TOKEN_PROGRAM_ID as PROGRAM_ID, error::TokenSdkError};
pub fn get_associated_token_address(owner: &Pubkey, mint: &Pubkey) -> Pubkey {
get_associated_token_address_and_bump(owner, mint).0
}
pub fn get_associated_token_address_and_bump(owner: &Pubkey, mint: &Pubkey) -> (Pubkey, u8) {
Pubkey::find_program_address(
&[&owner.to_bytes(), &PROGRAM_ID.to_bytes(), &mint.to_bytes()],
&PROGRAM_ID,
)
}
pub fn get_token_account_balance(token_account_info: &AccountInfo) -> Result<u64, ProgramError> {
Token::amount_from_account_info(token_account_info).map_err(Into::into)
}
pub fn is_light_token_owner(owner: &Pubkey) -> Result<bool, TokenSdkError> {
let light_token_program_id = PROGRAM_ID;
if owner == &light_token_program_id {
return Ok(true);
}
let spl_token = Pubkey::from(light_token_types::SPL_TOKEN_PROGRAM_ID);
let spl_token_2022 = Pubkey::from(light_token_types::SPL_TOKEN_2022_PROGRAM_ID);
if owner == &spl_token_2022 || owner == &spl_token {
return Ok(false);
}
Err(TokenSdkError::CannotDetermineAccountType)
}
pub fn is_token_account(account_info: &AccountInfo) -> Result<bool, TokenSdkError> {
is_light_token_owner(account_info.owner)
}