Skip to main content

carbon_token_program_decoder/instructions/
sync_native.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3/// Given a wrapped / native token account (a token account containing SOL)
4/// updates its amount field based on the account's underlying `lamports`.
5/// This is useful if a non-wrapped SOL account uses
6/// `system_instruction::transfer` to move lamports to a wrapped token
7/// account, and needs to have its token `amount` field updated.
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
10pub struct SyncNative {}
11
12#[derive(Debug, Clone, PartialEq)]
13#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
14pub struct SyncNativeInstructionAccounts {
15    pub account: solana_pubkey::Pubkey,
16    pub rent: Option<solana_pubkey::Pubkey>,
17    pub remaining: Vec<solana_instruction::AccountMeta>,
18}
19
20impl SyncNative {
21    pub fn decode(data: &[u8]) -> Option<Self> {
22        if data.is_empty() {
23            return None;
24        }
25        let discriminator = &data[0..1];
26        if discriminator != [17] {
27            return None;
28        }
29
30        let mut data_slice = data;
31
32        data_slice = &data_slice[1..];
33
34        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
35    }
36}
37
38impl ArrangeAccounts for SyncNative {
39    type ArrangedAccounts = SyncNativeInstructionAccounts;
40
41    fn arrange_accounts(
42        accounts: &[solana_instruction::AccountMeta],
43    ) -> Option<Self::ArrangedAccounts> {
44        let mut iter = accounts.iter();
45
46        let account = next_account(&mut iter)?;
47        let rent = next_account(&mut iter);
48
49        let remaining = iter.as_slice();
50
51        Some(SyncNativeInstructionAccounts {
52            account,
53            rent,
54            remaining: remaining.to_vec(),
55        })
56    }
57}