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 BeginLpSwap {
pub in_market_index: u16,
pub out_market_index: u16,
pub amount_in: u64,
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct BeginLpSwapInstructionAccounts {
pub state: solana_pubkey::Pubkey,
pub admin: solana_pubkey::Pubkey,
pub signer_out_token_account: solana_pubkey::Pubkey,
pub signer_in_token_account: solana_pubkey::Pubkey,
pub constituent_out_token_account: solana_pubkey::Pubkey,
pub constituent_in_token_account: solana_pubkey::Pubkey,
pub out_constituent: solana_pubkey::Pubkey,
pub in_constituent: solana_pubkey::Pubkey,
pub lp_pool: solana_pubkey::Pubkey,
pub instructions: solana_pubkey::Pubkey,
pub token_program: solana_pubkey::Pubkey,
pub remaining: Vec<solana_instruction::AccountMeta>,
}
impl BeginLpSwap {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.len() < 8 {
return None;
}
let discriminator = &data[0..8];
if discriminator != [64, 44, 24, 199, 48, 125, 67, 91] {
return None;
}
let mut data_slice = data;
data_slice = &data_slice[8..];
borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
}
}
impl ArrangeAccounts for BeginLpSwap {
type ArrangedAccounts = BeginLpSwapInstructionAccounts;
fn arrange_accounts(
accounts: &[solana_instruction::AccountMeta],
) -> Option<Self::ArrangedAccounts> {
let mut iter = accounts.iter();
let state = next_account(&mut iter)?;
let admin = next_account(&mut iter)?;
let signer_out_token_account = next_account(&mut iter)?;
let signer_in_token_account = next_account(&mut iter)?;
let constituent_out_token_account = next_account(&mut iter)?;
let constituent_in_token_account = next_account(&mut iter)?;
let out_constituent = next_account(&mut iter)?;
let in_constituent = next_account(&mut iter)?;
let lp_pool = next_account(&mut iter)?;
let instructions = next_account(&mut iter)?;
let token_program = next_account(&mut iter)?;
let remaining = iter.as_slice();
Some(BeginLpSwapInstructionAccounts {
state,
admin,
signer_out_token_account,
signer_in_token_account,
constituent_out_token_account,
constituent_in_token_account,
out_constituent,
in_constituent,
lp_pool,
instructions,
token_program,
remaining: remaining.to_vec(),
})
}
}