//! 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 InitializePoolV2 {
    pub whirlpools_config: solana_pubkey::Pubkey,

    pub token_mint_a: solana_pubkey::Pubkey,

    pub token_mint_b: solana_pubkey::Pubkey,

    pub token_badge_a: solana_pubkey::Pubkey,

    pub token_badge_b: solana_pubkey::Pubkey,

    pub funder: solana_pubkey::Pubkey,

    pub whirlpool: solana_pubkey::Pubkey,

    pub token_vault_a: solana_pubkey::Pubkey,

    pub token_vault_b: solana_pubkey::Pubkey,

    pub fee_tier: solana_pubkey::Pubkey,

    pub token_program_a: solana_pubkey::Pubkey,

    pub token_program_b: solana_pubkey::Pubkey,

    pub system_program: solana_pubkey::Pubkey,

    pub rent: solana_pubkey::Pubkey,
}

impl InitializePoolV2 {
    pub fn instruction(
        &self,
        args: InitializePoolV2InstructionArgs,
    ) -> 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: InitializePoolV2InstructionArgs,
        remaining_accounts: &[solana_instruction::AccountMeta],
    ) -> solana_instruction::Instruction {
        let mut accounts = Vec::with_capacity(14 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.whirlpools_config,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token_mint_a,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token_mint_b,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token_badge_a,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token_badge_b,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(self.funder, true));
        accounts.push(solana_instruction::AccountMeta::new(self.whirlpool, false));
        accounts.push(solana_instruction::AccountMeta::new(
            self.token_vault_a,
            true,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.token_vault_b,
            true,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.fee_tier,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token_program_a,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token_program_b,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.system_program,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.rent, false,
        ));
        accounts.extend_from_slice(remaining_accounts);
        let mut data = borsh::to_vec(&InitializePoolV2InstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&args).unwrap();
        data.append(&mut args);

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

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

impl InitializePoolV2InstructionData {
    pub fn new() -> Self {
        Self {
            discriminator: [207, 45, 87, 242, 27, 63, 204, 67],
        }
    }
}

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

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InitializePoolV2InstructionArgs {
    pub tick_spacing: u16,
    pub initial_sqrt_price: u128,
}

/// Instruction builder for `InitializePoolV2`.
///
/// ### Accounts:
///
///   0. `[]` whirlpools_config
///   1. `[]` token_mint_a
///   2. `[]` token_mint_b
///   3. `[]` token_badge_a
///   4. `[]` token_badge_b
///   5. `[writable, signer]` funder
///   6. `[writable]` whirlpool
///   7. `[writable, signer]` token_vault_a
///   8. `[writable, signer]` token_vault_b
///   9. `[]` fee_tier
///   10. `[]` token_program_a
///   11. `[]` token_program_b
///   12. `[optional]` system_program (default to `11111111111111111111111111111111`)
///   13. `[optional]` rent (default to `SysvarRent111111111111111111111111111111111`)
#[derive(Clone, Debug, Default)]
pub struct InitializePoolV2Builder {
    whirlpools_config: Option<solana_pubkey::Pubkey>,
    token_mint_a: Option<solana_pubkey::Pubkey>,
    token_mint_b: Option<solana_pubkey::Pubkey>,
    token_badge_a: Option<solana_pubkey::Pubkey>,
    token_badge_b: Option<solana_pubkey::Pubkey>,
    funder: Option<solana_pubkey::Pubkey>,
    whirlpool: Option<solana_pubkey::Pubkey>,
    token_vault_a: Option<solana_pubkey::Pubkey>,
    token_vault_b: Option<solana_pubkey::Pubkey>,
    fee_tier: Option<solana_pubkey::Pubkey>,
    token_program_a: Option<solana_pubkey::Pubkey>,
    token_program_b: Option<solana_pubkey::Pubkey>,
    system_program: Option<solana_pubkey::Pubkey>,
    rent: Option<solana_pubkey::Pubkey>,
    tick_spacing: Option<u16>,
    initial_sqrt_price: Option<u128>,
    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl InitializePoolV2Builder {
    pub fn new() -> Self {
        Self::default()
    }
    #[inline(always)]
    pub fn whirlpools_config(&mut self, whirlpools_config: solana_pubkey::Pubkey) -> &mut Self {
        self.whirlpools_config = Some(whirlpools_config);
        self
    }
    #[inline(always)]
    pub fn token_mint_a(&mut self, token_mint_a: solana_pubkey::Pubkey) -> &mut Self {
        self.token_mint_a = Some(token_mint_a);
        self
    }
    #[inline(always)]
    pub fn token_mint_b(&mut self, token_mint_b: solana_pubkey::Pubkey) -> &mut Self {
        self.token_mint_b = Some(token_mint_b);
        self
    }
    #[inline(always)]
    pub fn token_badge_a(&mut self, token_badge_a: solana_pubkey::Pubkey) -> &mut Self {
        self.token_badge_a = Some(token_badge_a);
        self
    }
    #[inline(always)]
    pub fn token_badge_b(&mut self, token_badge_b: solana_pubkey::Pubkey) -> &mut Self {
        self.token_badge_b = Some(token_badge_b);
        self
    }
    #[inline(always)]
    pub fn funder(&mut self, funder: solana_pubkey::Pubkey) -> &mut Self {
        self.funder = Some(funder);
        self
    }
    #[inline(always)]
    pub fn whirlpool(&mut self, whirlpool: solana_pubkey::Pubkey) -> &mut Self {
        self.whirlpool = Some(whirlpool);
        self
    }
    #[inline(always)]
    pub fn token_vault_a(&mut self, token_vault_a: solana_pubkey::Pubkey) -> &mut Self {
        self.token_vault_a = Some(token_vault_a);
        self
    }
    #[inline(always)]
    pub fn token_vault_b(&mut self, token_vault_b: solana_pubkey::Pubkey) -> &mut Self {
        self.token_vault_b = Some(token_vault_b);
        self
    }
    #[inline(always)]
    pub fn fee_tier(&mut self, fee_tier: solana_pubkey::Pubkey) -> &mut Self {
        self.fee_tier = Some(fee_tier);
        self
    }
    #[inline(always)]
    pub fn token_program_a(&mut self, token_program_a: solana_pubkey::Pubkey) -> &mut Self {
        self.token_program_a = Some(token_program_a);
        self
    }
    #[inline(always)]
    pub fn token_program_b(&mut self, token_program_b: solana_pubkey::Pubkey) -> &mut Self {
        self.token_program_b = Some(token_program_b);
        self
    }
    /// `[optional account, default to '11111111111111111111111111111111']`
    #[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 'SysvarRent111111111111111111111111111111111']`
    #[inline(always)]
    pub fn rent(&mut self, rent: solana_pubkey::Pubkey) -> &mut Self {
        self.rent = Some(rent);
        self
    }
    #[inline(always)]
    pub fn tick_spacing(&mut self, tick_spacing: u16) -> &mut Self {
        self.tick_spacing = Some(tick_spacing);
        self
    }
    #[inline(always)]
    pub fn initial_sqrt_price(&mut self, initial_sqrt_price: u128) -> &mut Self {
        self.initial_sqrt_price = Some(initial_sqrt_price);
        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 = InitializePoolV2 {
            whirlpools_config: self
                .whirlpools_config
                .expect("whirlpools_config is not set"),
            token_mint_a: self.token_mint_a.expect("token_mint_a is not set"),
            token_mint_b: self.token_mint_b.expect("token_mint_b is not set"),
            token_badge_a: self.token_badge_a.expect("token_badge_a is not set"),
            token_badge_b: self.token_badge_b.expect("token_badge_b is not set"),
            funder: self.funder.expect("funder is not set"),
            whirlpool: self.whirlpool.expect("whirlpool is not set"),
            token_vault_a: self.token_vault_a.expect("token_vault_a is not set"),
            token_vault_b: self.token_vault_b.expect("token_vault_b is not set"),
            fee_tier: self.fee_tier.expect("fee_tier is not set"),
            token_program_a: self.token_program_a.expect("token_program_a is not set"),
            token_program_b: self.token_program_b.expect("token_program_b is not set"),
            system_program: self
                .system_program
                .unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
            rent: self.rent.unwrap_or(solana_pubkey::pubkey!(
                "SysvarRent111111111111111111111111111111111"
            )),
        };
        let args = InitializePoolV2InstructionArgs {
            tick_spacing: self.tick_spacing.clone().expect("tick_spacing is not set"),
            initial_sqrt_price: self
                .initial_sqrt_price
                .clone()
                .expect("initial_sqrt_price is not set"),
        };

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

/// `initialize_pool_v2` CPI accounts.
pub struct InitializePoolV2CpiAccounts<'a, 'b> {
    pub whirlpools_config: &'b solana_account_info::AccountInfo<'a>,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<'a, 'b> InitializePoolV2Cpi<'a, 'b> {
    pub fn new(
        program: &'b solana_account_info::AccountInfo<'a>,
        accounts: InitializePoolV2CpiAccounts<'a, 'b>,
        args: InitializePoolV2InstructionArgs,
    ) -> Self {
        Self {
            __program: program,
            whirlpools_config: accounts.whirlpools_config,
            token_mint_a: accounts.token_mint_a,
            token_mint_b: accounts.token_mint_b,
            token_badge_a: accounts.token_badge_a,
            token_badge_b: accounts.token_badge_b,
            funder: accounts.funder,
            whirlpool: accounts.whirlpool,
            token_vault_a: accounts.token_vault_a,
            token_vault_b: accounts.token_vault_b,
            fee_tier: accounts.fee_tier,
            token_program_a: accounts.token_program_a,
            token_program_b: accounts.token_program_b,
            system_program: accounts.system_program,
            rent: accounts.rent,
            __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(14 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.whirlpools_config.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token_mint_a.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token_mint_b.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token_badge_a.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token_badge_b.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(*self.funder.key, true));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.whirlpool.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.token_vault_a.key,
            true,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.token_vault_b.key,
            true,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.fee_tier.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token_program_a.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token_program_b.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.system_program.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.rent.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(&InitializePoolV2InstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&self.__args).unwrap();
        data.append(&mut args);

        let instruction = solana_instruction::Instruction {
            program_id: crate::WHIRLPOOL_ID,
            accounts,
            data,
        };
        let mut account_infos = Vec::with_capacity(15 + remaining_accounts.len());
        account_infos.push(self.__program.clone());
        account_infos.push(self.whirlpools_config.clone());
        account_infos.push(self.token_mint_a.clone());
        account_infos.push(self.token_mint_b.clone());
        account_infos.push(self.token_badge_a.clone());
        account_infos.push(self.token_badge_b.clone());
        account_infos.push(self.funder.clone());
        account_infos.push(self.whirlpool.clone());
        account_infos.push(self.token_vault_a.clone());
        account_infos.push(self.token_vault_b.clone());
        account_infos.push(self.fee_tier.clone());
        account_infos.push(self.token_program_a.clone());
        account_infos.push(self.token_program_b.clone());
        account_infos.push(self.system_program.clone());
        account_infos.push(self.rent.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 `InitializePoolV2` via CPI.
///
/// ### Accounts:
///
///   0. `[]` whirlpools_config
///   1. `[]` token_mint_a
///   2. `[]` token_mint_b
///   3. `[]` token_badge_a
///   4. `[]` token_badge_b
///   5. `[writable, signer]` funder
///   6. `[writable]` whirlpool
///   7. `[writable, signer]` token_vault_a
///   8. `[writable, signer]` token_vault_b
///   9. `[]` fee_tier
///   10. `[]` token_program_a
///   11. `[]` token_program_b
///   12. `[]` system_program
///   13. `[]` rent
#[derive(Clone, Debug)]
pub struct InitializePoolV2CpiBuilder<'a, 'b> {
    instruction: Box<InitializePoolV2CpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> InitializePoolV2CpiBuilder<'a, 'b> {
    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
        let instruction = Box::new(InitializePoolV2CpiBuilderInstruction {
            __program: program,
            whirlpools_config: None,
            token_mint_a: None,
            token_mint_b: None,
            token_badge_a: None,
            token_badge_b: None,
            funder: None,
            whirlpool: None,
            token_vault_a: None,
            token_vault_b: None,
            fee_tier: None,
            token_program_a: None,
            token_program_b: None,
            system_program: None,
            rent: None,
            tick_spacing: None,
            initial_sqrt_price: None,
            __remaining_accounts: Vec::new(),
        });
        Self { instruction }
    }
    #[inline(always)]
    pub fn whirlpools_config(
        &mut self,
        whirlpools_config: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.whirlpools_config = Some(whirlpools_config);
        self
    }
    #[inline(always)]
    pub fn token_mint_a(
        &mut self,
        token_mint_a: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_mint_a = Some(token_mint_a);
        self
    }
    #[inline(always)]
    pub fn token_mint_b(
        &mut self,
        token_mint_b: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_mint_b = Some(token_mint_b);
        self
    }
    #[inline(always)]
    pub fn token_badge_a(
        &mut self,
        token_badge_a: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_badge_a = Some(token_badge_a);
        self
    }
    #[inline(always)]
    pub fn token_badge_b(
        &mut self,
        token_badge_b: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_badge_b = Some(token_badge_b);
        self
    }
    #[inline(always)]
    pub fn funder(&mut self, funder: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.funder = Some(funder);
        self
    }
    #[inline(always)]
    pub fn whirlpool(&mut self, whirlpool: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.whirlpool = Some(whirlpool);
        self
    }
    #[inline(always)]
    pub fn token_vault_a(
        &mut self,
        token_vault_a: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_vault_a = Some(token_vault_a);
        self
    }
    #[inline(always)]
    pub fn token_vault_b(
        &mut self,
        token_vault_b: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_vault_b = Some(token_vault_b);
        self
    }
    #[inline(always)]
    pub fn fee_tier(&mut self, fee_tier: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
        self.instruction.fee_tier = Some(fee_tier);
        self
    }
    #[inline(always)]
    pub fn token_program_a(
        &mut self,
        token_program_a: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_program_a = Some(token_program_a);
        self
    }
    #[inline(always)]
    pub fn token_program_b(
        &mut self,
        token_program_b: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_program_b = Some(token_program_b);
        self
    }
    #[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
    }
    #[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 tick_spacing(&mut self, tick_spacing: u16) -> &mut Self {
        self.instruction.tick_spacing = Some(tick_spacing);
        self
    }
    #[inline(always)]
    pub fn initial_sqrt_price(&mut self, initial_sqrt_price: u128) -> &mut Self {
        self.instruction.initial_sqrt_price = Some(initial_sqrt_price);
        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 = InitializePoolV2InstructionArgs {
            tick_spacing: self
                .instruction
                .tick_spacing
                .clone()
                .expect("tick_spacing is not set"),
            initial_sqrt_price: self
                .instruction
                .initial_sqrt_price
                .clone()
                .expect("initial_sqrt_price is not set"),
        };
        let instruction = InitializePoolV2Cpi {
            __program: self.instruction.__program,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#[derive(Clone, Debug)]
struct InitializePoolV2CpiBuilderInstruction<'a, 'b> {
    __program: &'b solana_account_info::AccountInfo<'a>,
    whirlpools_config: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_mint_a: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_mint_b: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_badge_a: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_badge_b: Option<&'b solana_account_info::AccountInfo<'a>>,
    funder: Option<&'b solana_account_info::AccountInfo<'a>>,
    whirlpool: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_vault_a: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_vault_b: Option<&'b solana_account_info::AccountInfo<'a>>,
    fee_tier: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_program_a: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_program_b: Option<&'b solana_account_info::AccountInfo<'a>>,
    system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    rent: Option<&'b solana_account_info::AccountInfo<'a>>,
    tick_spacing: Option<u16>,
    initial_sqrt_price: Option<u128>,
    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}
