carbon_token_2022_decoder/instructions/
sync_native.rs

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