use light_sdk_types::LIGHT_TOKEN_PROGRAM_ID;
use solana_account_info::AccountInfo;
use solana_cpi::{invoke, invoke_signed};
use solana_instruction::{AccountMeta, Instruction};
use solana_program_error::ProgramError;
use solana_pubkey::Pubkey;
pub struct Freeze {
pub token_account: Pubkey,
pub mint: Pubkey,
pub freeze_authority: Pubkey,
}
pub struct FreezeCpi<'info> {
pub token_account: AccountInfo<'info>,
pub mint: AccountInfo<'info>,
pub freeze_authority: AccountInfo<'info>,
}
impl<'info> FreezeCpi<'info> {
pub fn instruction(&self) -> Result<Instruction, ProgramError> {
Freeze::from(self).instruction()
}
pub fn invoke(self) -> Result<(), ProgramError> {
let instruction = Freeze::from(&self).instruction()?;
let account_infos = [self.token_account, self.mint, self.freeze_authority];
invoke(&instruction, &account_infos)
}
pub fn invoke_signed(self, signer_seeds: &[&[&[u8]]]) -> Result<(), ProgramError> {
let instruction = Freeze::from(&self).instruction()?;
let account_infos = [self.token_account, self.mint, self.freeze_authority];
invoke_signed(&instruction, &account_infos, signer_seeds)
}
}
impl<'info> From<&FreezeCpi<'info>> for Freeze {
fn from(cpi: &FreezeCpi<'info>) -> Self {
Self {
token_account: *cpi.token_account.key,
mint: *cpi.mint.key,
freeze_authority: *cpi.freeze_authority.key,
}
}
}
impl Freeze {
pub fn instruction(self) -> Result<Instruction, ProgramError> {
Ok(Instruction {
program_id: Pubkey::from(LIGHT_TOKEN_PROGRAM_ID),
accounts: vec![
AccountMeta::new(self.token_account, false),
AccountMeta::new_readonly(self.mint, false),
AccountMeta::new_readonly(self.freeze_authority, true),
],
data: vec![10u8], })
}
}