light_token/instruction/
thaw.rs1use light_sdk_types::LIGHT_TOKEN_PROGRAM_ID;
2use solana_account_info::AccountInfo;
3use solana_cpi::{invoke, invoke_signed};
4use solana_instruction::{AccountMeta, Instruction};
5use solana_program_error::ProgramError;
6use solana_pubkey::Pubkey;
7
8pub struct Thaw {
23 pub token_account: Pubkey,
25 pub mint: Pubkey,
27 pub freeze_authority: Pubkey,
29}
30
31pub struct ThawCpi<'info> {
47 pub token_account: AccountInfo<'info>,
48 pub mint: AccountInfo<'info>,
49 pub freeze_authority: AccountInfo<'info>,
50}
51
52impl<'info> ThawCpi<'info> {
53 pub fn instruction(&self) -> Result<Instruction, ProgramError> {
54 Thaw::from(self).instruction()
55 }
56
57 pub fn invoke(self) -> Result<(), ProgramError> {
58 let instruction = Thaw::from(&self).instruction()?;
59 let account_infos = [self.token_account, self.mint, self.freeze_authority];
60 invoke(&instruction, &account_infos)
61 }
62
63 pub fn invoke_signed(self, signer_seeds: &[&[&[u8]]]) -> Result<(), ProgramError> {
64 let instruction = Thaw::from(&self).instruction()?;
65 let account_infos = [self.token_account, self.mint, self.freeze_authority];
66 invoke_signed(&instruction, &account_infos, signer_seeds)
67 }
68}
69
70impl<'info> From<&ThawCpi<'info>> for Thaw {
71 fn from(cpi: &ThawCpi<'info>) -> Self {
72 Self {
73 token_account: *cpi.token_account.key,
74 mint: *cpi.mint.key,
75 freeze_authority: *cpi.freeze_authority.key,
76 }
77 }
78}
79
80impl Thaw {
81 pub fn instruction(self) -> Result<Instruction, ProgramError> {
82 Ok(Instruction {
83 program_id: Pubkey::from(LIGHT_TOKEN_PROGRAM_ID),
84 accounts: vec![
85 AccountMeta::new(self.token_account, false),
86 AccountMeta::new_readonly(self.mint, false),
87 AccountMeta::new_readonly(self.freeze_authority, true),
88 ],
89 data: vec![11u8], })
91 }
92}