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 TransferToNewAccountPda {
pub account_index: u16,
pub third_party_id: Option<u16>,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TransferToNewAccountPdaInstructionAccounts {
pub group: solana_pubkey::Pubkey,
pub old_marginfi_account: solana_pubkey::Pubkey,
pub new_marginfi_account: solana_pubkey::Pubkey,
pub authority: solana_pubkey::Pubkey,
pub fee_payer: solana_pubkey::Pubkey,
pub new_authority: solana_pubkey::Pubkey,
pub global_fee_wallet: solana_pubkey::Pubkey,
pub instructions_sysvar: solana_pubkey::Pubkey,
pub system_program: solana_pubkey::Pubkey,
pub remaining: Vec<solana_instruction::AccountMeta>,
}
impl TransferToNewAccountPda {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.len() < 8 {
return None;
}
let discriminator = &data[0..8];
if discriminator != [172, 210, 224, 220, 146, 212, 253, 49] {
return None;
}
let mut data_slice = data;
data_slice = &data_slice[8..];
borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
}
}
impl ArrangeAccounts for TransferToNewAccountPda {
type ArrangedAccounts = TransferToNewAccountPdaInstructionAccounts;
fn arrange_accounts(
accounts: &[solana_instruction::AccountMeta],
) -> Option<Self::ArrangedAccounts> {
let mut iter = accounts.iter();
let group = next_account(&mut iter)?;
let old_marginfi_account = next_account(&mut iter)?;
let new_marginfi_account = next_account(&mut iter)?;
let authority = next_account(&mut iter)?;
let fee_payer = next_account(&mut iter)?;
let new_authority = next_account(&mut iter)?;
let global_fee_wallet = next_account(&mut iter)?;
let instructions_sysvar = next_account(&mut iter)?;
let system_program = next_account(&mut iter)?;
let remaining = iter.as_slice();
Some(TransferToNewAccountPdaInstructionAccounts {
group,
old_marginfi_account,
new_marginfi_account,
authority,
fee_payer,
new_authority,
global_fee_wallet,
instructions_sysvar,
system_program,
remaining: remaining.to_vec(),
})
}
}