Skip to main content

carbon_token_program_decoder/instructions/
withdraw_excess_lamports.rs

1//! This code was AUTOGENERATED using the Codama library.
2use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3/// Rescue SOL sent to any TokenProgram-owned account
4/// by sending them to any other account, leaving behind only
5/// lamports for rent exemption.
6#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
8pub struct WithdrawExcessLamports {}
9
10#[derive(Debug, Clone, PartialEq)]
11#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
12pub struct WithdrawExcessLamportsInstructionAccounts {
13    pub source: solana_pubkey::Pubkey,
14    pub destination: solana_pubkey::Pubkey,
15    pub authority: solana_pubkey::Pubkey,
16    pub remaining: Vec<solana_instruction::AccountMeta>,
17}
18
19impl WithdrawExcessLamports {
20    pub fn decode(data: &[u8]) -> Option<Self> {
21        if data.is_empty() {
22            return None;
23        }
24        let discriminator = &data[0..1];
25        if discriminator != [38] {
26            return None;
27        }
28
29        let mut data_slice = data;
30
31        data_slice = &data_slice[1..];
32
33        borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
34    }
35}
36
37impl ArrangeAccounts for WithdrawExcessLamports {
38    type ArrangedAccounts = WithdrawExcessLamportsInstructionAccounts;
39
40    fn arrange_accounts(
41        accounts: &[solana_instruction::AccountMeta],
42    ) -> Option<Self::ArrangedAccounts> {
43        let mut iter = accounts.iter();
44
45        let source = next_account(&mut iter)?;
46        let destination = next_account(&mut iter)?;
47        let authority = next_account(&mut iter)?;
48
49        let remaining = iter.as_slice();
50
51        Some(WithdrawExcessLamportsInstructionAccounts {
52            source,
53            destination,
54            authority,
55            remaining: remaining.to_vec(),
56        })
57    }
58}