hpsvm_token/
thaw_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::thaw_account};
8
9#[derive(Debug)]
17pub struct ThawAccount<'a> {
18 svm: &'a mut HPSVM,
19 payer: &'a Keypair,
20 mint: &'a Address,
21 signers: SmallVec<[&'a Keypair; 1]>,
22 account: Option<&'a Address>,
23 owner: Option<Address>,
24 token_program_id: Option<&'a Address>,
25}
26
27impl<'a> ThawAccount<'a> {
28 pub fn new(svm: &'a mut HPSVM, payer: &'a Keypair, mint: &'a Address) -> Self {
30 ThawAccount {
31 svm,
32 payer,
33 mint,
34 account: None,
35 owner: None,
36 token_program_id: None,
37 signers: smallvec![payer],
38 }
39 }
40
41 pub fn token_program_id(mut self, program_id: &'a Address) -> Self {
43 self.token_program_id = Some(program_id);
44 self
45 }
46
47 pub fn owner(mut self, owner: &'a Keypair) -> Self {
49 self.owner = Some(owner.pubkey());
50 self.signers = smallvec![owner];
51 self
52 }
53
54 pub fn multisig(mut self, multisig: &'a Address, signers: &'a [&'a Keypair]) -> Self {
56 self.owner = Some(*multisig);
57 self.signers = SmallVec::from(signers);
58 self
59 }
60
61 pub fn send(self) -> Result<(), FailedTransactionMetadata> {
63 let payer_pk = self.payer.pubkey();
64 let token_program_id = self.token_program_id.unwrap_or(&TOKEN_ID);
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 = thaw_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}