hpsvm_token/
sync_native.rs1use hpsvm::{HPSVM, types::FailedTransactionMetadata};
2use solana_address::Address;
3use solana_keypair::Keypair;
4
5use super::{TOKEN_ID, spl_token::instruction::sync_native};
6
7#[derive(Debug)]
13pub struct SyncNative<'a> {
14 svm: &'a mut HPSVM,
15 payer: &'a Keypair,
16 account: &'a Address,
17 token_program_id: Option<&'a Address>,
18}
19
20impl<'a> SyncNative<'a> {
21 pub fn new(svm: &'a mut HPSVM, payer: &'a Keypair, account: &'a Address) -> Self {
23 SyncNative { svm, payer, account, token_program_id: None }
24 }
25
26 pub fn token_program_id(mut self, program_id: &'a Address) -> Self {
28 self.token_program_id = Some(program_id);
29 self
30 }
31
32 pub fn send(self) -> Result<(), FailedTransactionMetadata> {
34 let token_program_id = self.token_program_id.unwrap_or(&TOKEN_ID);
35
36 let ix = sync_native(token_program_id, self.account)?;
37
38 super::sign_and_send(self.svm, self.payer, &[], ix)
39 }
40}