//! 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;

/// Accounts.
#[derive(Debug)]
pub struct MonitorStep {
    pub token_program: solana_pubkey::Pubkey,

    pub rent: solana_pubkey::Pubkey,

    pub clock: solana_pubkey::Pubkey,

    pub amm: solana_pubkey::Pubkey,

    pub amm_authority: solana_pubkey::Pubkey,

    pub amm_open_orders: solana_pubkey::Pubkey,

    pub amm_target_orders: solana_pubkey::Pubkey,

    pub pool_coin_token_account: solana_pubkey::Pubkey,

    pub pool_pc_token_account: solana_pubkey::Pubkey,

    pub pool_withdraw_queue: solana_pubkey::Pubkey,

    pub serum_program: solana_pubkey::Pubkey,

    pub serum_market: solana_pubkey::Pubkey,

    pub serum_coin_vault_account: solana_pubkey::Pubkey,

    pub serum_pc_vault_account: solana_pubkey::Pubkey,

    pub serum_vault_signer: solana_pubkey::Pubkey,

    pub serum_req_q: solana_pubkey::Pubkey,

    pub serum_event_q: solana_pubkey::Pubkey,

    pub serum_bids: solana_pubkey::Pubkey,

    pub serum_asks: solana_pubkey::Pubkey,
}

impl MonitorStep {
    pub fn instruction(&self, args: MonitorStepInstructionArgs) -> 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: MonitorStepInstructionArgs,
        remaining_accounts: &[solana_instruction::AccountMeta],
    ) -> solana_instruction::Instruction {
        let mut accounts = Vec::with_capacity(19 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token_program,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.rent, false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.clock, false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(self.amm, false));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.amm_authority,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.amm_open_orders,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.amm_target_orders,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.pool_coin_token_account,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.pool_pc_token_account,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.pool_withdraw_queue,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.serum_program,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.serum_market,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.serum_coin_vault_account,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.serum_pc_vault_account,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.serum_vault_signer,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.serum_req_q,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.serum_event_q,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(self.serum_bids, false));
        accounts.push(solana_instruction::AccountMeta::new(self.serum_asks, false));
        accounts.extend_from_slice(remaining_accounts);
        let mut data = borsh::to_vec(&MonitorStepInstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&args).unwrap();
        data.append(&mut args);

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

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

impl MonitorStepInstructionData {
    pub fn new() -> Self {
        Self { discriminator: [2] }
    }
}

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

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MonitorStepInstructionArgs {
    pub plan_order_limit: u16,
    pub place_order_limit: u16,
    pub cancel_order_limit: u16,
}

/// Instruction builder for `MonitorStep`.
///
/// ### Accounts:
///
///   0. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`)
///   1. `[optional]` rent (default to `SysvarRent111111111111111111111111111111111`)
///   2. `[]` clock
///   3. `[writable]` amm
///   4. `[]` amm_authority
///   5. `[writable]` amm_open_orders
///   6. `[writable]` amm_target_orders
///   7. `[writable]` pool_coin_token_account
///   8. `[writable]` pool_pc_token_account
///   9. `[writable]` pool_withdraw_queue
///   10. `[]` serum_program
///   11. `[writable]` serum_market
///   12. `[writable]` serum_coin_vault_account
///   13. `[writable]` serum_pc_vault_account
///   14. `[]` serum_vault_signer
///   15. `[writable]` serum_req_q
///   16. `[writable]` serum_event_q
///   17. `[writable]` serum_bids
///   18. `[writable]` serum_asks
#[derive(Clone, Debug, Default)]
pub struct MonitorStepBuilder {
    token_program: Option<solana_pubkey::Pubkey>,
    rent: Option<solana_pubkey::Pubkey>,
    clock: Option<solana_pubkey::Pubkey>,
    amm: Option<solana_pubkey::Pubkey>,
    amm_authority: Option<solana_pubkey::Pubkey>,
    amm_open_orders: Option<solana_pubkey::Pubkey>,
    amm_target_orders: Option<solana_pubkey::Pubkey>,
    pool_coin_token_account: Option<solana_pubkey::Pubkey>,
    pool_pc_token_account: Option<solana_pubkey::Pubkey>,
    pool_withdraw_queue: Option<solana_pubkey::Pubkey>,
    serum_program: Option<solana_pubkey::Pubkey>,
    serum_market: Option<solana_pubkey::Pubkey>,
    serum_coin_vault_account: Option<solana_pubkey::Pubkey>,
    serum_pc_vault_account: Option<solana_pubkey::Pubkey>,
    serum_vault_signer: Option<solana_pubkey::Pubkey>,
    serum_req_q: Option<solana_pubkey::Pubkey>,
    serum_event_q: Option<solana_pubkey::Pubkey>,
    serum_bids: Option<solana_pubkey::Pubkey>,
    serum_asks: Option<solana_pubkey::Pubkey>,
    plan_order_limit: Option<u16>,
    place_order_limit: Option<u16>,
    cancel_order_limit: Option<u16>,
    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl MonitorStepBuilder {
    pub fn new() -> Self {
        Self::default()
    }
    /// `[optional account, default to 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA']`
    #[inline(always)]
    pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self {
        self.token_program = Some(token_program);
        self
    }
    /// `[optional account, default to 'SysvarRent111111111111111111111111111111111']`
    #[inline(always)]
    pub fn rent(&mut self, rent: solana_pubkey::Pubkey) -> &mut Self {
        self.rent = Some(rent);
        self
    }
    #[inline(always)]
    pub fn clock(&mut self, clock: solana_pubkey::Pubkey) -> &mut Self {
        self.clock = Some(clock);
        self
    }
    #[inline(always)]
    pub fn amm(&mut self, amm: solana_pubkey::Pubkey) -> &mut Self {
        self.amm = Some(amm);
        self
    }
    #[inline(always)]
    pub fn amm_authority(&mut self, amm_authority: solana_pubkey::Pubkey) -> &mut Self {
        self.amm_authority = Some(amm_authority);
        self
    }
    #[inline(always)]
    pub fn amm_open_orders(&mut self, amm_open_orders: solana_pubkey::Pubkey) -> &mut Self {
        self.amm_open_orders = Some(amm_open_orders);
        self
    }
    #[inline(always)]
    pub fn amm_target_orders(&mut self, amm_target_orders: solana_pubkey::Pubkey) -> &mut Self {
        self.amm_target_orders = Some(amm_target_orders);
        self
    }
    #[inline(always)]
    pub fn pool_coin_token_account(
        &mut self,
        pool_coin_token_account: solana_pubkey::Pubkey,
    ) -> &mut Self {
        self.pool_coin_token_account = Some(pool_coin_token_account);
        self
    }
    #[inline(always)]
    pub fn pool_pc_token_account(
        &mut self,
        pool_pc_token_account: solana_pubkey::Pubkey,
    ) -> &mut Self {
        self.pool_pc_token_account = Some(pool_pc_token_account);
        self
    }
    #[inline(always)]
    pub fn pool_withdraw_queue(&mut self, pool_withdraw_queue: solana_pubkey::Pubkey) -> &mut Self {
        self.pool_withdraw_queue = Some(pool_withdraw_queue);
        self
    }
    #[inline(always)]
    pub fn serum_program(&mut self, serum_program: solana_pubkey::Pubkey) -> &mut Self {
        self.serum_program = Some(serum_program);
        self
    }
    #[inline(always)]
    pub fn serum_market(&mut self, serum_market: solana_pubkey::Pubkey) -> &mut Self {
        self.serum_market = Some(serum_market);
        self
    }
    #[inline(always)]
    pub fn serum_coin_vault_account(
        &mut self,
        serum_coin_vault_account: solana_pubkey::Pubkey,
    ) -> &mut Self {
        self.serum_coin_vault_account = Some(serum_coin_vault_account);
        self
    }
    #[inline(always)]
    pub fn serum_pc_vault_account(
        &mut self,
        serum_pc_vault_account: solana_pubkey::Pubkey,
    ) -> &mut Self {
        self.serum_pc_vault_account = Some(serum_pc_vault_account);
        self
    }
    #[inline(always)]
    pub fn serum_vault_signer(&mut self, serum_vault_signer: solana_pubkey::Pubkey) -> &mut Self {
        self.serum_vault_signer = Some(serum_vault_signer);
        self
    }
    #[inline(always)]
    pub fn serum_req_q(&mut self, serum_req_q: solana_pubkey::Pubkey) -> &mut Self {
        self.serum_req_q = Some(serum_req_q);
        self
    }
    #[inline(always)]
    pub fn serum_event_q(&mut self, serum_event_q: solana_pubkey::Pubkey) -> &mut Self {
        self.serum_event_q = Some(serum_event_q);
        self
    }
    #[inline(always)]
    pub fn serum_bids(&mut self, serum_bids: solana_pubkey::Pubkey) -> &mut Self {
        self.serum_bids = Some(serum_bids);
        self
    }
    #[inline(always)]
    pub fn serum_asks(&mut self, serum_asks: solana_pubkey::Pubkey) -> &mut Self {
        self.serum_asks = Some(serum_asks);
        self
    }
    #[inline(always)]
    pub fn plan_order_limit(&mut self, plan_order_limit: u16) -> &mut Self {
        self.plan_order_limit = Some(plan_order_limit);
        self
    }
    #[inline(always)]
    pub fn place_order_limit(&mut self, place_order_limit: u16) -> &mut Self {
        self.place_order_limit = Some(place_order_limit);
        self
    }
    #[inline(always)]
    pub fn cancel_order_limit(&mut self, cancel_order_limit: u16) -> &mut Self {
        self.cancel_order_limit = Some(cancel_order_limit);
        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 = MonitorStep {
            token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!(
                "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
            )),
            rent: self.rent.unwrap_or(solana_pubkey::pubkey!(
                "SysvarRent111111111111111111111111111111111"
            )),
            clock: self.clock.expect("clock is not set"),
            amm: self.amm.expect("amm is not set"),
            amm_authority: self.amm_authority.expect("amm_authority is not set"),
            amm_open_orders: self.amm_open_orders.expect("amm_open_orders is not set"),
            amm_target_orders: self
                .amm_target_orders
                .expect("amm_target_orders is not set"),
            pool_coin_token_account: self
                .pool_coin_token_account
                .expect("pool_coin_token_account is not set"),
            pool_pc_token_account: self
                .pool_pc_token_account
                .expect("pool_pc_token_account is not set"),
            pool_withdraw_queue: self
                .pool_withdraw_queue
                .expect("pool_withdraw_queue is not set"),
            serum_program: self.serum_program.expect("serum_program is not set"),
            serum_market: self.serum_market.expect("serum_market is not set"),
            serum_coin_vault_account: self
                .serum_coin_vault_account
                .expect("serum_coin_vault_account is not set"),
            serum_pc_vault_account: self
                .serum_pc_vault_account
                .expect("serum_pc_vault_account is not set"),
            serum_vault_signer: self
                .serum_vault_signer
                .expect("serum_vault_signer is not set"),
            serum_req_q: self.serum_req_q.expect("serum_req_q is not set"),
            serum_event_q: self.serum_event_q.expect("serum_event_q is not set"),
            serum_bids: self.serum_bids.expect("serum_bids is not set"),
            serum_asks: self.serum_asks.expect("serum_asks is not set"),
        };
        let args = MonitorStepInstructionArgs {
            plan_order_limit: self
                .plan_order_limit
                .clone()
                .expect("plan_order_limit is not set"),
            place_order_limit: self
                .place_order_limit
                .clone()
                .expect("place_order_limit is not set"),
            cancel_order_limit: self
                .cancel_order_limit
                .clone()
                .expect("cancel_order_limit is not set"),
        };

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

/// `monitor_step` CPI accounts.
pub struct MonitorStepCpiAccounts<'a, 'b> {
    pub token_program: &'b solana_account_info::AccountInfo<'a>,

    pub rent: &'b solana_account_info::AccountInfo<'a>,

    pub clock: &'b solana_account_info::AccountInfo<'a>,

    pub amm: &'b solana_account_info::AccountInfo<'a>,

    pub amm_authority: &'b solana_account_info::AccountInfo<'a>,

    pub amm_open_orders: &'b solana_account_info::AccountInfo<'a>,

    pub amm_target_orders: &'b solana_account_info::AccountInfo<'a>,

    pub pool_coin_token_account: &'b solana_account_info::AccountInfo<'a>,

    pub pool_pc_token_account: &'b solana_account_info::AccountInfo<'a>,

    pub pool_withdraw_queue: &'b solana_account_info::AccountInfo<'a>,

    pub serum_program: &'b solana_account_info::AccountInfo<'a>,

    pub serum_market: &'b solana_account_info::AccountInfo<'a>,

    pub serum_coin_vault_account: &'b solana_account_info::AccountInfo<'a>,

    pub serum_pc_vault_account: &'b solana_account_info::AccountInfo<'a>,

    pub serum_vault_signer: &'b solana_account_info::AccountInfo<'a>,

    pub serum_req_q: &'b solana_account_info::AccountInfo<'a>,

    pub serum_event_q: &'b solana_account_info::AccountInfo<'a>,

    pub serum_bids: &'b solana_account_info::AccountInfo<'a>,

    pub serum_asks: &'b solana_account_info::AccountInfo<'a>,
}

/// `monitor_step` CPI instruction.
pub struct MonitorStepCpi<'a, 'b> {
    /// The program to invoke.
    pub __program: &'b solana_account_info::AccountInfo<'a>,

    pub token_program: &'b solana_account_info::AccountInfo<'a>,

    pub rent: &'b solana_account_info::AccountInfo<'a>,

    pub clock: &'b solana_account_info::AccountInfo<'a>,

    pub amm: &'b solana_account_info::AccountInfo<'a>,

    pub amm_authority: &'b solana_account_info::AccountInfo<'a>,

    pub amm_open_orders: &'b solana_account_info::AccountInfo<'a>,

    pub amm_target_orders: &'b solana_account_info::AccountInfo<'a>,

    pub pool_coin_token_account: &'b solana_account_info::AccountInfo<'a>,

    pub pool_pc_token_account: &'b solana_account_info::AccountInfo<'a>,

    pub pool_withdraw_queue: &'b solana_account_info::AccountInfo<'a>,

    pub serum_program: &'b solana_account_info::AccountInfo<'a>,

    pub serum_market: &'b solana_account_info::AccountInfo<'a>,

    pub serum_coin_vault_account: &'b solana_account_info::AccountInfo<'a>,

    pub serum_pc_vault_account: &'b solana_account_info::AccountInfo<'a>,

    pub serum_vault_signer: &'b solana_account_info::AccountInfo<'a>,

    pub serum_req_q: &'b solana_account_info::AccountInfo<'a>,

    pub serum_event_q: &'b solana_account_info::AccountInfo<'a>,

    pub serum_bids: &'b solana_account_info::AccountInfo<'a>,

    pub serum_asks: &'b solana_account_info::AccountInfo<'a>,
    /// The arguments for the instruction.
    pub __args: MonitorStepInstructionArgs,
}

impl<'a, 'b> MonitorStepCpi<'a, 'b> {
    pub fn new(
        program: &'b solana_account_info::AccountInfo<'a>,
        accounts: MonitorStepCpiAccounts<'a, 'b>,
        args: MonitorStepInstructionArgs,
    ) -> Self {
        Self {
            __program: program,
            token_program: accounts.token_program,
            rent: accounts.rent,
            clock: accounts.clock,
            amm: accounts.amm,
            amm_authority: accounts.amm_authority,
            amm_open_orders: accounts.amm_open_orders,
            amm_target_orders: accounts.amm_target_orders,
            pool_coin_token_account: accounts.pool_coin_token_account,
            pool_pc_token_account: accounts.pool_pc_token_account,
            pool_withdraw_queue: accounts.pool_withdraw_queue,
            serum_program: accounts.serum_program,
            serum_market: accounts.serum_market,
            serum_coin_vault_account: accounts.serum_coin_vault_account,
            serum_pc_vault_account: accounts.serum_pc_vault_account,
            serum_vault_signer: accounts.serum_vault_signer,
            serum_req_q: accounts.serum_req_q,
            serum_event_q: accounts.serum_event_q,
            serum_bids: accounts.serum_bids,
            serum_asks: accounts.serum_asks,
            __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(19 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token_program.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.rent.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.clock.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(*self.amm.key, false));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.amm_authority.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.amm_open_orders.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.amm_target_orders.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.pool_coin_token_account.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.pool_pc_token_account.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.pool_withdraw_queue.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.serum_program.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.serum_market.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.serum_coin_vault_account.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.serum_pc_vault_account.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.serum_vault_signer.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.serum_req_q.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.serum_event_q.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.serum_bids.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.serum_asks.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(&MonitorStepInstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&self.__args).unwrap();
        data.append(&mut args);

        let instruction = solana_instruction::Instruction {
            program_id: crate::RAYDIUM_AMM_ID,
            accounts,
            data,
        };
        let mut account_infos = Vec::with_capacity(20 + remaining_accounts.len());
        account_infos.push(self.__program.clone());
        account_infos.push(self.token_program.clone());
        account_infos.push(self.rent.clone());
        account_infos.push(self.clock.clone());
        account_infos.push(self.amm.clone());
        account_infos.push(self.amm_authority.clone());
        account_infos.push(self.amm_open_orders.clone());
        account_infos.push(self.amm_target_orders.clone());
        account_infos.push(self.pool_coin_token_account.clone());
        account_infos.push(self.pool_pc_token_account.clone());
        account_infos.push(self.pool_withdraw_queue.clone());
        account_infos.push(self.serum_program.clone());
        account_infos.push(self.serum_market.clone());
        account_infos.push(self.serum_coin_vault_account.clone());
        account_infos.push(self.serum_pc_vault_account.clone());
        account_infos.push(self.serum_vault_signer.clone());
        account_infos.push(self.serum_req_q.clone());
        account_infos.push(self.serum_event_q.clone());
        account_infos.push(self.serum_bids.clone());
        account_infos.push(self.serum_asks.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 `MonitorStep` via CPI.
///
/// ### Accounts:
///
///   0. `[]` token_program
///   1. `[]` rent
///   2. `[]` clock
///   3. `[writable]` amm
///   4. `[]` amm_authority
///   5. `[writable]` amm_open_orders
///   6. `[writable]` amm_target_orders
///   7. `[writable]` pool_coin_token_account
///   8. `[writable]` pool_pc_token_account
///   9. `[writable]` pool_withdraw_queue
///   10. `[]` serum_program
///   11. `[writable]` serum_market
///   12. `[writable]` serum_coin_vault_account
///   13. `[writable]` serum_pc_vault_account
///   14. `[]` serum_vault_signer
///   15. `[writable]` serum_req_q
///   16. `[writable]` serum_event_q
///   17. `[writable]` serum_bids
///   18. `[writable]` serum_asks
#[derive(Clone, Debug)]
pub struct MonitorStepCpiBuilder<'a, 'b> {
    instruction: Box<MonitorStepCpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> MonitorStepCpiBuilder<'a, 'b> {
    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
        let instruction = Box::new(MonitorStepCpiBuilderInstruction {
            __program: program,
            token_program: None,
            rent: None,
            clock: None,
            amm: None,
            amm_authority: None,
            amm_open_orders: None,
            amm_target_orders: None,
            pool_coin_token_account: None,
            pool_pc_token_account: None,
            pool_withdraw_queue: None,
            serum_program: None,
            serum_market: None,
            serum_coin_vault_account: None,
            serum_pc_vault_account: None,
            serum_vault_signer: None,
            serum_req_q: None,
            serum_event_q: None,
            serum_bids: None,
            serum_asks: None,
            plan_order_limit: None,
            place_order_limit: None,
            cancel_order_limit: None,
            __remaining_accounts: Vec::new(),
        });
        Self { instruction }
    }
    #[inline(always)]
    pub fn token_program(
        &mut self,
        token_program: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_program = Some(token_program);
        self
    }
    #[inline(always)]
    pub fn rent(&mut self, rent: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.rent = Some(rent);
        self
    }
    #[inline(always)]
    pub fn clock(&mut self, clock: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.clock = Some(clock);
        self
    }
    #[inline(always)]
    pub fn amm(&mut self, amm: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.amm = Some(amm);
        self
    }
    #[inline(always)]
    pub fn amm_authority(
        &mut self,
        amm_authority: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.amm_authority = Some(amm_authority);
        self
    }
    #[inline(always)]
    pub fn amm_open_orders(
        &mut self,
        amm_open_orders: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.amm_open_orders = Some(amm_open_orders);
        self
    }
    #[inline(always)]
    pub fn amm_target_orders(
        &mut self,
        amm_target_orders: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.amm_target_orders = Some(amm_target_orders);
        self
    }
    #[inline(always)]
    pub fn pool_coin_token_account(
        &mut self,
        pool_coin_token_account: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.pool_coin_token_account = Some(pool_coin_token_account);
        self
    }
    #[inline(always)]
    pub fn pool_pc_token_account(
        &mut self,
        pool_pc_token_account: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.pool_pc_token_account = Some(pool_pc_token_account);
        self
    }
    #[inline(always)]
    pub fn pool_withdraw_queue(
        &mut self,
        pool_withdraw_queue: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.pool_withdraw_queue = Some(pool_withdraw_queue);
        self
    }
    #[inline(always)]
    pub fn serum_program(
        &mut self,
        serum_program: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.serum_program = Some(serum_program);
        self
    }
    #[inline(always)]
    pub fn serum_market(
        &mut self,
        serum_market: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.serum_market = Some(serum_market);
        self
    }
    #[inline(always)]
    pub fn serum_coin_vault_account(
        &mut self,
        serum_coin_vault_account: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.serum_coin_vault_account = Some(serum_coin_vault_account);
        self
    }
    #[inline(always)]
    pub fn serum_pc_vault_account(
        &mut self,
        serum_pc_vault_account: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.serum_pc_vault_account = Some(serum_pc_vault_account);
        self
    }
    #[inline(always)]
    pub fn serum_vault_signer(
        &mut self,
        serum_vault_signer: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.serum_vault_signer = Some(serum_vault_signer);
        self
    }
    #[inline(always)]
    pub fn serum_req_q(
        &mut self,
        serum_req_q: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.serum_req_q = Some(serum_req_q);
        self
    }
    #[inline(always)]
    pub fn serum_event_q(
        &mut self,
        serum_event_q: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.serum_event_q = Some(serum_event_q);
        self
    }
    #[inline(always)]
    pub fn serum_bids(
        &mut self,
        serum_bids: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.serum_bids = Some(serum_bids);
        self
    }
    #[inline(always)]
    pub fn serum_asks(
        &mut self,
        serum_asks: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.serum_asks = Some(serum_asks);
        self
    }
    #[inline(always)]
    pub fn plan_order_limit(&mut self, plan_order_limit: u16) -> &mut Self {
        self.instruction.plan_order_limit = Some(plan_order_limit);
        self
    }
    #[inline(always)]
    pub fn place_order_limit(&mut self, place_order_limit: u16) -> &mut Self {
        self.instruction.place_order_limit = Some(place_order_limit);
        self
    }
    #[inline(always)]
    pub fn cancel_order_limit(&mut self, cancel_order_limit: u16) -> &mut Self {
        self.instruction.cancel_order_limit = Some(cancel_order_limit);
        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 = MonitorStepInstructionArgs {
            plan_order_limit: self
                .instruction
                .plan_order_limit
                .clone()
                .expect("plan_order_limit is not set"),
            place_order_limit: self
                .instruction
                .place_order_limit
                .clone()
                .expect("place_order_limit is not set"),
            cancel_order_limit: self
                .instruction
                .cancel_order_limit
                .clone()
                .expect("cancel_order_limit is not set"),
        };
        let instruction = MonitorStepCpi {
            __program: self.instruction.__program,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#[derive(Clone, Debug)]
struct MonitorStepCpiBuilderInstruction<'a, 'b> {
    __program: &'b solana_account_info::AccountInfo<'a>,
    token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    rent: Option<&'b solana_account_info::AccountInfo<'a>>,
    clock: Option<&'b solana_account_info::AccountInfo<'a>>,
    amm: Option<&'b solana_account_info::AccountInfo<'a>>,
    amm_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
    amm_open_orders: Option<&'b solana_account_info::AccountInfo<'a>>,
    amm_target_orders: Option<&'b solana_account_info::AccountInfo<'a>>,
    pool_coin_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
    pool_pc_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
    pool_withdraw_queue: Option<&'b solana_account_info::AccountInfo<'a>>,
    serum_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    serum_market: Option<&'b solana_account_info::AccountInfo<'a>>,
    serum_coin_vault_account: Option<&'b solana_account_info::AccountInfo<'a>>,
    serum_pc_vault_account: Option<&'b solana_account_info::AccountInfo<'a>>,
    serum_vault_signer: Option<&'b solana_account_info::AccountInfo<'a>>,
    serum_req_q: Option<&'b solana_account_info::AccountInfo<'a>>,
    serum_event_q: Option<&'b solana_account_info::AccountInfo<'a>>,
    serum_bids: Option<&'b solana_account_info::AccountInfo<'a>>,
    serum_asks: Option<&'b solana_account_info::AccountInfo<'a>>,
    plan_order_limit: Option<u16>,
    place_order_limit: Option<u16>,
    cancel_order_limit: Option<u16>,
    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}
