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 TransferFee {
pub amount: u64,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TransferFeeInstructionAccounts {
pub from: solana_pubkey::Pubkey,
pub to: solana_pubkey::Pubkey,
pub authority: solana_pubkey::Pubkey,
pub token_program: solana_pubkey::Pubkey,
pub event_authority: solana_pubkey::Pubkey,
pub program: solana_pubkey::Pubkey,
pub remaining: Vec<solana_instruction::AccountMeta>,
}
impl TransferFee {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.len() < 8 {
return None;
}
let discriminator = &data[0..8];
if discriminator != [129, 164, 196, 21, 177, 48, 180, 162] {
return None;
}
let mut data_slice = data;
data_slice = &data_slice[8..];
borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
}
}
impl ArrangeAccounts for TransferFee {
type ArrangedAccounts = TransferFeeInstructionAccounts;
fn arrange_accounts(
accounts: &[solana_instruction::AccountMeta],
) -> Option<Self::ArrangedAccounts> {
let mut iter = accounts.iter();
let from = next_account(&mut iter)?;
let to = next_account(&mut iter)?;
let authority = next_account(&mut iter)?;
let token_program = next_account(&mut iter)?;
let event_authority = next_account(&mut iter)?;
let program = next_account(&mut iter)?;
let remaining = iter.as_slice();
Some(TransferFeeInstructionAccounts {
from,
to,
authority,
token_program,
event_authority,
program,
remaining: remaining.to_vec(),
})
}
}