Skip to main content

carbon_token_program_decoder/instructions/
unwrap_lamports.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3/// Transfer lamports from a native SOL account to a destination account.
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
6pub struct UnwrapLamports {
7    /// Optional amount of lamports to transfer.
8    /// If not provided, the instruction will unwrap all lamports in excess of
9    /// rent exemption.
10    pub amount: Option<u64>,
11}
12
13#[derive(Debug, Clone, PartialEq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct UnwrapLamportsInstructionAccounts {
16    pub source: solana_pubkey::Pubkey,
17    pub destination: solana_pubkey::Pubkey,
18    pub authority: solana_pubkey::Pubkey,
19    pub remaining: Vec<solana_instruction::AccountMeta>,
20}
21
22impl UnwrapLamports {
23    pub fn decode(data: &[u8]) -> Option<Self> {
24        if data.is_empty() {
25            return None;
26        }
27        let discriminator = &data[0..1];
28        if discriminator != [45] {
29            return None;
30        }
31
32        let mut data_slice = data;
33
34        data_slice = &data_slice[1..];
35
36        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
37    }
38}
39
40impl ArrangeAccounts for UnwrapLamports {
41    type ArrangedAccounts = UnwrapLamportsInstructionAccounts;
42
43    fn arrange_accounts(
44        accounts: &[solana_instruction::AccountMeta],
45    ) -> Option<Self::ArrangedAccounts> {
46        let mut iter = accounts.iter();
47
48        let source = next_account(&mut iter)?;
49        let destination = next_account(&mut iter)?;
50        let authority = next_account(&mut iter)?;
51
52        let remaining = iter.as_slice();
53
54        Some(UnwrapLamportsInstructionAccounts {
55            source,
56            destination,
57            authority,
58            remaining: remaining.to_vec(),
59        })
60    }
61}