use carbon_core::{account_utils::next_account, deserialize::ArrangeAccounts};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct CloseEmptyTokenAccount {}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CloseEmptyTokenAccountInstructionAccounts {
pub token_account: solana_pubkey::Pubkey,
pub authority: solana_pubkey::Pubkey,
pub destination: solana_pubkey::Pubkey,
pub token_program: solana_pubkey::Pubkey,
pub remaining: Vec<solana_instruction::AccountMeta>,
}
impl CloseEmptyTokenAccount {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.len() < 8 {
return None;
}
let discriminator = &data[0..8];
if discriminator != [232, 75, 140, 136, 250, 78, 224, 188] {
return None;
}
let mut data_slice = data;
data_slice = &data_slice[8..];
borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
}
}
impl ArrangeAccounts for CloseEmptyTokenAccount {
type ArrangedAccounts = CloseEmptyTokenAccountInstructionAccounts;
fn arrange_accounts(
accounts: &[solana_instruction::AccountMeta],
) -> Option<Self::ArrangedAccounts> {
let mut iter = accounts.iter();
let token_account = next_account(&mut iter)?;
let authority = next_account(&mut iter)?;
let destination = next_account(&mut iter)?;
let token_program = next_account(&mut iter)?;
let remaining = iter.as_slice();
Some(CloseEmptyTokenAccountInstructionAccounts {
token_account,
authority,
destination,
token_program,
remaining: remaining.to_vec(),
})
}
}