pinocchio_token/instructions/
sync_native.rs

1use solana_account_view::AccountView;
2use solana_instruction_view::{cpi::invoke, InstructionAccount, InstructionView};
3use solana_program_error::ProgramResult;
4
5/// Given a native token account updates its amount field based
6/// on the account's underlying `lamports`.
7///
8/// ### Accounts:
9///   0. `[WRITE]`  The native token account to sync with its underlying
10///      lamports.
11pub struct SyncNative<'a> {
12    /// Native Token Account
13    pub native_token: &'a AccountView,
14}
15
16impl SyncNative<'_> {
17    #[inline(always)]
18    pub fn invoke(&self) -> ProgramResult {
19        // Instruction accounts
20        let instruction_accounts: [InstructionAccount; 1] =
21            [InstructionAccount::writable(self.native_token.address())];
22
23        let instruction = InstructionView {
24            program_id: &crate::ID,
25            accounts: &instruction_accounts,
26            data: &[17],
27        };
28
29        invoke(&instruction, &[self.native_token])
30    }
31}