carbon_token_program_decoder/instructions/
close_account.rs1use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
3#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
7pub struct CloseAccount {}
8
9#[derive(Debug, Clone, PartialEq)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct CloseAccountInstructionAccounts {
12 pub account: solana_pubkey::Pubkey,
13 pub destination: solana_pubkey::Pubkey,
14 pub owner: solana_pubkey::Pubkey,
15 pub remaining: Vec<solana_instruction::AccountMeta>,
16}
17
18impl CloseAccount {
19 pub fn decode(data: &[u8]) -> Option<Self> {
20 if data.is_empty() {
21 return None;
22 }
23 let discriminator = &data[0..1];
24 if discriminator != [9] {
25 return None;
26 }
27
28 let mut data_slice = data;
29
30 data_slice = &data_slice[1..];
31
32 borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
33 }
34}
35
36impl ArrangeAccounts for CloseAccount {
37 type ArrangedAccounts = CloseAccountInstructionAccounts;
38
39 fn arrange_accounts(
40 accounts: &[solana_instruction::AccountMeta],
41 ) -> Option<Self::ArrangedAccounts> {
42 let mut iter = accounts.iter();
43
44 let account = next_account(&mut iter)?;
45 let destination = next_account(&mut iter)?;
46 let owner = next_account(&mut iter)?;
47
48 let remaining = iter.as_slice();
49
50 Some(CloseAccountInstructionAccounts {
51 account,
52 destination,
53 owner,
54 remaining: remaining.to_vec(),
55 })
56 }
57}