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 CloseSwigV1 {}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CloseSwigV1InstructionAccounts {
pub swig: solana_pubkey::Pubkey,
pub swig_wallet_address: solana_pubkey::Pubkey,
pub destination: solana_pubkey::Pubkey,
pub system_program: solana_pubkey::Pubkey,
pub remaining: Vec<solana_instruction::AccountMeta>,
}
impl CloseSwigV1 {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.is_empty() {
return None;
}
let discriminator = &data[0..1];
if discriminator != [15] {
return None;
}
let mut data_slice = data;
data_slice = &data_slice[1..];
borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
}
}
impl ArrangeAccounts for CloseSwigV1 {
type ArrangedAccounts = CloseSwigV1InstructionAccounts;
fn arrange_accounts(
accounts: &[solana_instruction::AccountMeta],
) -> Option<Self::ArrangedAccounts> {
let mut iter = accounts.iter();
let swig = next_account(&mut iter)?;
let swig_wallet_address = next_account(&mut iter)?;
let destination = next_account(&mut iter)?;
let system_program = next_account(&mut iter)?;
let remaining = iter.as_slice();
Some(CloseSwigV1InstructionAccounts {
swig,
swig_wallet_address,
destination,
system_program,
remaining: remaining.to_vec(),
})
}
}