//! This code was AUTOGENERATED using the codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

use borsh::BorshDeserialize;
use borsh::BorshSerialize;

pub const TOKEN_SELL_EXACT_IN_DISCRIMINATOR: u8 = 10;

/// Accounts.
#[derive(Debug)]
pub struct TokenSellExactIn {
    /// The seller of the token
    pub seller: solana_pubkey::Pubkey,
    /// The bonding curve account
    pub bonding_curve: solana_pubkey::Pubkey,
    /// The base token mint account
    pub base_mint: solana_pubkey::Pubkey,
    /// The base token ata for the seller
    pub base_ata: solana_pubkey::Pubkey,
    /// The quote token mint account
    pub quote_mint: solana_pubkey::Pubkey,
    /// The quote token vault
    pub quote_vault: solana_pubkey::Pubkey,
    /// The quote token ata for the seller
    pub quote_ata: solana_pubkey::Pubkey,
    /// System program
    pub system_program: solana_pubkey::Pubkey,
    /// The associated token account program
    pub ata_program: solana_pubkey::Pubkey,
    /// The token program for the base token
    pub base_token_program: solana_pubkey::Pubkey,
    /// The token program for the quote token
    pub quote_token_program: solana_pubkey::Pubkey,
}

impl TokenSellExactIn {
    pub fn instruction(
        &self,
        args: TokenSellExactInInstructionArgs,
    ) -> solana_instruction::Instruction {
        self.instruction_with_remaining_accounts(args, &[])
    }
    #[allow(clippy::arithmetic_side_effects)]
    #[allow(clippy::vec_init_then_push)]
    pub fn instruction_with_remaining_accounts(
        &self,
        args: TokenSellExactInInstructionArgs,
        remaining_accounts: &[solana_instruction::AccountMeta],
    ) -> solana_instruction::Instruction {
        let mut accounts = Vec::with_capacity(11 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new(self.seller, true));
        accounts.push(solana_instruction::AccountMeta::new(
            self.bonding_curve,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(self.base_mint, false));
        accounts.push(solana_instruction::AccountMeta::new(self.base_ata, false));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.quote_mint,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.quote_vault,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(self.quote_ata, false));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.system_program,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.ata_program,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.base_token_program,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.quote_token_program,
            false,
        ));
        accounts.extend_from_slice(remaining_accounts);
        let mut data = borsh::to_vec(&TokenSellExactInInstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&args).unwrap();
        data.append(&mut args);

        solana_instruction::Instruction {
            program_id: crate::WAVEBREAK_ID,
            accounts,
            data,
        }
    }
}

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TokenSellExactInInstructionData {
    discriminator: u8,
}

impl TokenSellExactInInstructionData {
    pub fn new() -> Self {
        Self { discriminator: 10 }
    }
}

impl Default for TokenSellExactInInstructionData {
    fn default() -> Self {
        Self::new()
    }
}

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TokenSellExactInInstructionArgs {
    pub amount_in: u64,
    pub allow_partial_fill: bool,
    pub price_threshold: Option<(u64, u64)>,
}

/// Instruction builder for `TokenSellExactIn`.
///
/// ### Accounts:
///
///   0. `[writable, signer]` seller
///   1. `[writable]` bonding_curve
///   2. `[writable]` base_mint
///   3. `[writable]` base_ata
///   4. `[]` quote_mint
///   5. `[writable]` quote_vault
///   6. `[writable]` quote_ata
///   7. `[optional]` system_program (default to `11111111111111111111111111111111`)
///   8. `[optional]` ata_program (default to `ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL`)
///   9. `[]` base_token_program
///   10. `[]` quote_token_program
#[derive(Clone, Debug, Default)]
pub struct TokenSellExactInBuilder {
    seller: Option<solana_pubkey::Pubkey>,
    bonding_curve: Option<solana_pubkey::Pubkey>,
    base_mint: Option<solana_pubkey::Pubkey>,
    base_ata: Option<solana_pubkey::Pubkey>,
    quote_mint: Option<solana_pubkey::Pubkey>,
    quote_vault: Option<solana_pubkey::Pubkey>,
    quote_ata: Option<solana_pubkey::Pubkey>,
    system_program: Option<solana_pubkey::Pubkey>,
    ata_program: Option<solana_pubkey::Pubkey>,
    base_token_program: Option<solana_pubkey::Pubkey>,
    quote_token_program: Option<solana_pubkey::Pubkey>,
    amount_in: Option<u64>,
    allow_partial_fill: Option<bool>,
    price_threshold: Option<(u64, u64)>,
    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl TokenSellExactInBuilder {
    pub fn new() -> Self {
        Self::default()
    }
    /// The seller of the token
    #[inline(always)]
    pub fn seller(&mut self, seller: solana_pubkey::Pubkey) -> &mut Self {
        self.seller = Some(seller);
        self
    }
    /// The bonding curve account
    #[inline(always)]
    pub fn bonding_curve(&mut self, bonding_curve: solana_pubkey::Pubkey) -> &mut Self {
        self.bonding_curve = Some(bonding_curve);
        self
    }
    /// The base token mint account
    #[inline(always)]
    pub fn base_mint(&mut self, base_mint: solana_pubkey::Pubkey) -> &mut Self {
        self.base_mint = Some(base_mint);
        self
    }
    /// The base token ata for the seller
    #[inline(always)]
    pub fn base_ata(&mut self, base_ata: solana_pubkey::Pubkey) -> &mut Self {
        self.base_ata = Some(base_ata);
        self
    }
    /// The quote token mint account
    #[inline(always)]
    pub fn quote_mint(&mut self, quote_mint: solana_pubkey::Pubkey) -> &mut Self {
        self.quote_mint = Some(quote_mint);
        self
    }
    /// The quote token vault
    #[inline(always)]
    pub fn quote_vault(&mut self, quote_vault: solana_pubkey::Pubkey) -> &mut Self {
        self.quote_vault = Some(quote_vault);
        self
    }
    /// The quote token ata for the seller
    #[inline(always)]
    pub fn quote_ata(&mut self, quote_ata: solana_pubkey::Pubkey) -> &mut Self {
        self.quote_ata = Some(quote_ata);
        self
    }
    /// `[optional account, default to '11111111111111111111111111111111']`
    /// System program
    #[inline(always)]
    pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
        self.system_program = Some(system_program);
        self
    }
    /// `[optional account, default to 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL']`
    /// The associated token account program
    #[inline(always)]
    pub fn ata_program(&mut self, ata_program: solana_pubkey::Pubkey) -> &mut Self {
        self.ata_program = Some(ata_program);
        self
    }
    /// The token program for the base token
    #[inline(always)]
    pub fn base_token_program(&mut self, base_token_program: solana_pubkey::Pubkey) -> &mut Self {
        self.base_token_program = Some(base_token_program);
        self
    }
    /// The token program for the quote token
    #[inline(always)]
    pub fn quote_token_program(&mut self, quote_token_program: solana_pubkey::Pubkey) -> &mut Self {
        self.quote_token_program = Some(quote_token_program);
        self
    }
    #[inline(always)]
    pub fn amount_in(&mut self, amount_in: u64) -> &mut Self {
        self.amount_in = Some(amount_in);
        self
    }
    #[inline(always)]
    pub fn allow_partial_fill(&mut self, allow_partial_fill: bool) -> &mut Self {
        self.allow_partial_fill = Some(allow_partial_fill);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn price_threshold(&mut self, price_threshold: (u64, u64)) -> &mut Self {
        self.price_threshold = Some(price_threshold);
        self
    }
    /// Add an additional account to the instruction.
    #[inline(always)]
    pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
        self.__remaining_accounts.push(account);
        self
    }
    /// Add additional accounts to the instruction.
    #[inline(always)]
    pub fn add_remaining_accounts(
        &mut self,
        accounts: &[solana_instruction::AccountMeta],
    ) -> &mut Self {
        self.__remaining_accounts.extend_from_slice(accounts);
        self
    }
    #[allow(clippy::clone_on_copy)]
    pub fn instruction(&self) -> solana_instruction::Instruction {
        let accounts = TokenSellExactIn {
            seller: self.seller.expect("seller is not set"),
            bonding_curve: self.bonding_curve.expect("bonding_curve is not set"),
            base_mint: self.base_mint.expect("base_mint is not set"),
            base_ata: self.base_ata.expect("base_ata is not set"),
            quote_mint: self.quote_mint.expect("quote_mint is not set"),
            quote_vault: self.quote_vault.expect("quote_vault is not set"),
            quote_ata: self.quote_ata.expect("quote_ata is not set"),
            system_program: self
                .system_program
                .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
            ata_program: self.ata_program.unwrap_or(solana_pubkey::pubkey!(
                "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
            )),
            base_token_program: self
                .base_token_program
                .expect("base_token_program is not set"),
            quote_token_program: self
                .quote_token_program
                .expect("quote_token_program is not set"),
        };
        let args = TokenSellExactInInstructionArgs {
            amount_in: self.amount_in.clone().expect("amount_in is not set"),
            allow_partial_fill: self
                .allow_partial_fill
                .clone()
                .expect("allow_partial_fill is not set"),
            price_threshold: self.price_threshold.clone(),
        };

        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
    }
}

/// `token_sell_exact_in` CPI accounts.
pub struct TokenSellExactInCpiAccounts<'a, 'b> {
    /// The seller of the token
    pub seller: &'b solana_account_info::AccountInfo<'a>,
    /// The bonding curve account
    pub bonding_curve: &'b solana_account_info::AccountInfo<'a>,
    /// The base token mint account
    pub base_mint: &'b solana_account_info::AccountInfo<'a>,
    /// The base token ata for the seller
    pub base_ata: &'b solana_account_info::AccountInfo<'a>,
    /// The quote token mint account
    pub quote_mint: &'b solana_account_info::AccountInfo<'a>,
    /// The quote token vault
    pub quote_vault: &'b solana_account_info::AccountInfo<'a>,
    /// The quote token ata for the seller
    pub quote_ata: &'b solana_account_info::AccountInfo<'a>,
    /// System program
    pub system_program: &'b solana_account_info::AccountInfo<'a>,
    /// The associated token account program
    pub ata_program: &'b solana_account_info::AccountInfo<'a>,
    /// The token program for the base token
    pub base_token_program: &'b solana_account_info::AccountInfo<'a>,
    /// The token program for the quote token
    pub quote_token_program: &'b solana_account_info::AccountInfo<'a>,
}

/// `token_sell_exact_in` CPI instruction.
pub struct TokenSellExactInCpi<'a, 'b> {
    /// The program to invoke.
    pub __program: &'b solana_account_info::AccountInfo<'a>,
    /// The seller of the token
    pub seller: &'b solana_account_info::AccountInfo<'a>,
    /// The bonding curve account
    pub bonding_curve: &'b solana_account_info::AccountInfo<'a>,
    /// The base token mint account
    pub base_mint: &'b solana_account_info::AccountInfo<'a>,
    /// The base token ata for the seller
    pub base_ata: &'b solana_account_info::AccountInfo<'a>,
    /// The quote token mint account
    pub quote_mint: &'b solana_account_info::AccountInfo<'a>,
    /// The quote token vault
    pub quote_vault: &'b solana_account_info::AccountInfo<'a>,
    /// The quote token ata for the seller
    pub quote_ata: &'b solana_account_info::AccountInfo<'a>,
    /// System program
    pub system_program: &'b solana_account_info::AccountInfo<'a>,
    /// The associated token account program
    pub ata_program: &'b solana_account_info::AccountInfo<'a>,
    /// The token program for the base token
    pub base_token_program: &'b solana_account_info::AccountInfo<'a>,
    /// The token program for the quote token
    pub quote_token_program: &'b solana_account_info::AccountInfo<'a>,
    /// The arguments for the instruction.
    pub __args: TokenSellExactInInstructionArgs,
}

impl<'a, 'b> TokenSellExactInCpi<'a, 'b> {
    pub fn new(
        program: &'b solana_account_info::AccountInfo<'a>,
        accounts: TokenSellExactInCpiAccounts<'a, 'b>,
        args: TokenSellExactInInstructionArgs,
    ) -> Self {
        Self {
            __program: program,
            seller: accounts.seller,
            bonding_curve: accounts.bonding_curve,
            base_mint: accounts.base_mint,
            base_ata: accounts.base_ata,
            quote_mint: accounts.quote_mint,
            quote_vault: accounts.quote_vault,
            quote_ata: accounts.quote_ata,
            system_program: accounts.system_program,
            ata_program: accounts.ata_program,
            base_token_program: accounts.base_token_program,
            quote_token_program: accounts.quote_token_program,
            __args: args,
        }
    }
    #[inline(always)]
    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
        self.invoke_signed_with_remaining_accounts(&[], &[])
    }
    #[inline(always)]
    pub fn invoke_with_remaining_accounts(
        &self,
        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
    ) -> solana_program_entrypoint::ProgramResult {
        self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
    }
    #[inline(always)]
    pub fn invoke_signed(
        &self,
        signers_seeds: &[&[&[u8]]],
    ) -> solana_program_entrypoint::ProgramResult {
        self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
    }
    #[allow(clippy::arithmetic_side_effects)]
    #[allow(clippy::clone_on_copy)]
    #[allow(clippy::vec_init_then_push)]
    pub fn invoke_signed_with_remaining_accounts(
        &self,
        signers_seeds: &[&[&[u8]]],
        remaining_accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
    ) -> solana_program_entrypoint::ProgramResult {
        let mut accounts = Vec::with_capacity(11 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new(*self.seller.key, true));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.bonding_curve.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.base_mint.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.base_ata.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.quote_mint.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.quote_vault.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.quote_ata.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.system_program.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.ata_program.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.base_token_program.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.quote_token_program.key,
            false,
        ));
        remaining_accounts.iter().for_each(|remaining_account| {
            accounts.push(solana_instruction::AccountMeta {
                pubkey: *remaining_account.0.key,
                is_signer: remaining_account.1,
                is_writable: remaining_account.2,
            })
        });
        let mut data = borsh::to_vec(&TokenSellExactInInstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&self.__args).unwrap();
        data.append(&mut args);

        let instruction = solana_instruction::Instruction {
            program_id: crate::WAVEBREAK_ID,
            accounts,
            data,
        };
        let mut account_infos = Vec::with_capacity(12 + remaining_accounts.len());
        account_infos.push(self.__program.clone());
        account_infos.push(self.seller.clone());
        account_infos.push(self.bonding_curve.clone());
        account_infos.push(self.base_mint.clone());
        account_infos.push(self.base_ata.clone());
        account_infos.push(self.quote_mint.clone());
        account_infos.push(self.quote_vault.clone());
        account_infos.push(self.quote_ata.clone());
        account_infos.push(self.system_program.clone());
        account_infos.push(self.ata_program.clone());
        account_infos.push(self.base_token_program.clone());
        account_infos.push(self.quote_token_program.clone());
        remaining_accounts
            .iter()
            .for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));

        if signers_seeds.is_empty() {
            solana_cpi::invoke(&instruction, &account_infos)
        } else {
            solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
        }
    }
}

/// Instruction builder for `TokenSellExactIn` via CPI.
///
/// ### Accounts:
///
///   0. `[writable, signer]` seller
///   1. `[writable]` bonding_curve
///   2. `[writable]` base_mint
///   3. `[writable]` base_ata
///   4. `[]` quote_mint
///   5. `[writable]` quote_vault
///   6. `[writable]` quote_ata
///   7. `[]` system_program
///   8. `[]` ata_program
///   9. `[]` base_token_program
///   10. `[]` quote_token_program
#[derive(Clone, Debug)]
pub struct TokenSellExactInCpiBuilder<'a, 'b> {
    instruction: Box<TokenSellExactInCpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> TokenSellExactInCpiBuilder<'a, 'b> {
    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
        let instruction = Box::new(TokenSellExactInCpiBuilderInstruction {
            __program: program,
            seller: None,
            bonding_curve: None,
            base_mint: None,
            base_ata: None,
            quote_mint: None,
            quote_vault: None,
            quote_ata: None,
            system_program: None,
            ata_program: None,
            base_token_program: None,
            quote_token_program: None,
            amount_in: None,
            allow_partial_fill: None,
            price_threshold: None,
            __remaining_accounts: Vec::new(),
        });
        Self { instruction }
    }
    /// The seller of the token
    #[inline(always)]
    pub fn seller(&mut self, seller: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.seller = Some(seller);
        self
    }
    /// The bonding curve account
    #[inline(always)]
    pub fn bonding_curve(
        &mut self,
        bonding_curve: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.bonding_curve = Some(bonding_curve);
        self
    }
    /// The base token mint account
    #[inline(always)]
    pub fn base_mint(&mut self, base_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.base_mint = Some(base_mint);
        self
    }
    /// The base token ata for the seller
    #[inline(always)]
    pub fn base_ata(&mut self, base_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.base_ata = Some(base_ata);
        self
    }
    /// The quote token mint account
    #[inline(always)]
    pub fn quote_mint(
        &mut self,
        quote_mint: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.quote_mint = Some(quote_mint);
        self
    }
    /// The quote token vault
    #[inline(always)]
    pub fn quote_vault(
        &mut self,
        quote_vault: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.quote_vault = Some(quote_vault);
        self
    }
    /// The quote token ata for the seller
    #[inline(always)]
    pub fn quote_ata(&mut self, quote_ata: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.quote_ata = Some(quote_ata);
        self
    }
    /// System program
    #[inline(always)]
    pub fn system_program(
        &mut self,
        system_program: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.system_program = Some(system_program);
        self
    }
    /// The associated token account program
    #[inline(always)]
    pub fn ata_program(
        &mut self,
        ata_program: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.ata_program = Some(ata_program);
        self
    }
    /// The token program for the base token
    #[inline(always)]
    pub fn base_token_program(
        &mut self,
        base_token_program: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.base_token_program = Some(base_token_program);
        self
    }
    /// The token program for the quote token
    #[inline(always)]
    pub fn quote_token_program(
        &mut self,
        quote_token_program: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.quote_token_program = Some(quote_token_program);
        self
    }
    #[inline(always)]
    pub fn amount_in(&mut self, amount_in: u64) -> &mut Self {
        self.instruction.amount_in = Some(amount_in);
        self
    }
    #[inline(always)]
    pub fn allow_partial_fill(&mut self, allow_partial_fill: bool) -> &mut Self {
        self.instruction.allow_partial_fill = Some(allow_partial_fill);
        self
    }
    /// `[optional argument]`
    #[inline(always)]
    pub fn price_threshold(&mut self, price_threshold: (u64, u64)) -> &mut Self {
        self.instruction.price_threshold = Some(price_threshold);
        self
    }
    /// Add an additional account to the instruction.
    #[inline(always)]
    pub fn add_remaining_account(
        &mut self,
        account: &'b solana_account_info::AccountInfo<'a>,
        is_writable: bool,
        is_signer: bool,
    ) -> &mut Self {
        self.instruction
            .__remaining_accounts
            .push((account, is_writable, is_signer));
        self
    }
    /// Add additional accounts to the instruction.
    ///
    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
    /// and a `bool` indicating whether the account is a signer or not.
    #[inline(always)]
    pub fn add_remaining_accounts(
        &mut self,
        accounts: &[(&'b solana_account_info::AccountInfo<'a>, bool, bool)],
    ) -> &mut Self {
        self.instruction
            .__remaining_accounts
            .extend_from_slice(accounts);
        self
    }
    #[inline(always)]
    pub fn invoke(&self) -> solana_program_entrypoint::ProgramResult {
        self.invoke_signed(&[])
    }
    #[allow(clippy::clone_on_copy)]
    #[allow(clippy::vec_init_then_push)]
    pub fn invoke_signed(
        &self,
        signers_seeds: &[&[&[u8]]],
    ) -> solana_program_entrypoint::ProgramResult {
        let args = TokenSellExactInInstructionArgs {
            amount_in: self
                .instruction
                .amount_in
                .clone()
                .expect("amount_in is not set"),
            allow_partial_fill: self
                .instruction
                .allow_partial_fill
                .clone()
                .expect("allow_partial_fill is not set"),
            price_threshold: self.instruction.price_threshold.clone(),
        };
        let instruction = TokenSellExactInCpi {
            __program: self.instruction.__program,

            seller: self.instruction.seller.expect("seller is not set"),

            bonding_curve: self
                .instruction
                .bonding_curve
                .expect("bonding_curve is not set"),

            base_mint: self.instruction.base_mint.expect("base_mint is not set"),

            base_ata: self.instruction.base_ata.expect("base_ata is not set"),

            quote_mint: self.instruction.quote_mint.expect("quote_mint is not set"),

            quote_vault: self
                .instruction
                .quote_vault
                .expect("quote_vault is not set"),

            quote_ata: self.instruction.quote_ata.expect("quote_ata is not set"),

            system_program: self
                .instruction
                .system_program
                .expect("system_program is not set"),

            ata_program: self
                .instruction
                .ata_program
                .expect("ata_program is not set"),

            base_token_program: self
                .instruction
                .base_token_program
                .expect("base_token_program is not set"),

            quote_token_program: self
                .instruction
                .quote_token_program
                .expect("quote_token_program is not set"),
            __args: args,
        };
        instruction.invoke_signed_with_remaining_accounts(
            signers_seeds,
            &self.instruction.__remaining_accounts,
        )
    }
}

#[derive(Clone, Debug)]
struct TokenSellExactInCpiBuilderInstruction<'a, 'b> {
    __program: &'b solana_account_info::AccountInfo<'a>,
    seller: Option<&'b solana_account_info::AccountInfo<'a>>,
    bonding_curve: Option<&'b solana_account_info::AccountInfo<'a>>,
    base_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
    base_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
    quote_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
    quote_vault: Option<&'b solana_account_info::AccountInfo<'a>>,
    quote_ata: Option<&'b solana_account_info::AccountInfo<'a>>,
    system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    ata_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    base_token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    quote_token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    amount_in: Option<u64>,
    allow_partial_fill: Option<bool>,
    price_threshold: Option<(u64, u64)>,
    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}
