hpsvm_token/
freeze_account.rs1use hpsvm::{HPSVM, types::FailedTransactionMetadata};
2use smallvec::{SmallVec, smallvec};
3use solana_address::Address;
4use solana_keypair::Keypair;
5use solana_signer::{Signer, signers::Signers};
6
7use super::{TOKEN_ID, get_multisig_signers, spl_token::instruction::freeze_account};
8
9#[derive(Debug)]
17pub struct FreezeAccount<'a> {
18 svm: &'a mut HPSVM,
19 payer: &'a Keypair,
20 mint: &'a Address,
21 account: Option<&'a Address>,
22 token_program_id: Option<&'a Address>,
23 signers: SmallVec<[&'a Keypair; 1]>,
24 owner: Option<Address>,
25}
26
27impl<'a> FreezeAccount<'a> {
28 pub fn new(svm: &'a mut HPSVM, payer: &'a Keypair, mint: &'a Address) -> Self {
30 FreezeAccount {
31 svm,
32 payer,
33 account: None,
34 mint,
35 owner: None,
36 signers: smallvec![payer],
37 token_program_id: None,
38 }
39 }
40
41 pub fn owner(mut self, owner: &'a Keypair) -> Self {
43 self.owner = Some(owner.pubkey());
44 self.signers = smallvec![owner];
45 self
46 }
47
48 pub fn multisig(mut self, multisig: &'a Address, signers: &'a [&'a Keypair]) -> Self {
50 self.owner = Some(*multisig);
51 self.signers = SmallVec::from(signers);
52 self
53 }
54
55 pub fn token_program_id(mut self, program_id: &'a Address) -> Self {
57 self.token_program_id = Some(program_id);
58 self
59 }
60
61 pub fn send(self) -> Result<(), FailedTransactionMetadata> {
63 let token_program_id = self.token_program_id.unwrap_or(&TOKEN_ID);
64 let payer_pk = self.payer.pubkey();
65
66 let authority = self.owner.unwrap_or(payer_pk);
67 let signing_keys = self.signers.pubkeys();
68 let signer_keys = get_multisig_signers(&authority, &signing_keys);
69
70 let account = if let Some(account) = self.account {
71 *account
72 } else {
73 spl_associated_token_account_interface::address::get_associated_token_address_with_program_id(
74 &authority,
75 self.mint,
76 token_program_id,
77 )
78 };
79
80 let ix = freeze_account(token_program_id, &account, self.mint, &authority, &signer_keys)?;
81
82 super::sign_and_send(self.svm, self.payer, &self.signers, ix)
83 }
84}