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

    pub token_authority: solana_pubkey::Pubkey,

    pub whirlpool_one: solana_pubkey::Pubkey,

    pub whirlpool_two: solana_pubkey::Pubkey,

    pub token_owner_account_one_a: solana_pubkey::Pubkey,

    pub token_vault_one_a: solana_pubkey::Pubkey,

    pub token_owner_account_one_b: solana_pubkey::Pubkey,

    pub token_vault_one_b: solana_pubkey::Pubkey,

    pub token_owner_account_two_a: solana_pubkey::Pubkey,

    pub token_vault_two_a: solana_pubkey::Pubkey,

    pub token_owner_account_two_b: solana_pubkey::Pubkey,

    pub token_vault_two_b: solana_pubkey::Pubkey,

    pub tick_array_one0: solana_pubkey::Pubkey,

    pub tick_array_one1: solana_pubkey::Pubkey,

    pub tick_array_one2: solana_pubkey::Pubkey,

    pub tick_array_two0: solana_pubkey::Pubkey,

    pub tick_array_two1: solana_pubkey::Pubkey,

    pub tick_array_two2: solana_pubkey::Pubkey,

    pub oracle_one: solana_pubkey::Pubkey,

    pub oracle_two: solana_pubkey::Pubkey,
}

impl TwoHopSwap {
    pub fn instruction(&self, args: TwoHopSwapInstructionArgs) -> 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: TwoHopSwapInstructionArgs,
        remaining_accounts: &[solana_instruction::AccountMeta],
    ) -> solana_instruction::Instruction {
        let mut accounts = Vec::with_capacity(20 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token_program,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.token_authority,
            true,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.whirlpool_one,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.whirlpool_two,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.token_owner_account_one_a,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.token_vault_one_a,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.token_owner_account_one_b,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.token_vault_one_b,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.token_owner_account_two_a,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.token_vault_two_a,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.token_owner_account_two_b,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.token_vault_two_b,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.tick_array_one0,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.tick_array_one1,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.tick_array_one2,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.tick_array_two0,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.tick_array_two1,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            self.tick_array_two2,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.oracle_one,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            self.oracle_two,
            false,
        ));
        accounts.extend_from_slice(remaining_accounts);
        let mut data = borsh::to_vec(&TwoHopSwapInstructionData::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 TwoHopSwapInstructionData {
    discriminator: [u8; 8],
}

impl TwoHopSwapInstructionData {
    pub fn new() -> Self {
        Self {
            discriminator: [195, 96, 237, 108, 68, 162, 219, 230],
        }
    }
}

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

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TwoHopSwapInstructionArgs {
    pub amount: u64,
    pub other_amount_threshold: u64,
    pub amount_specified_is_input: bool,
    pub a_to_b_one: bool,
    pub a_to_b_two: bool,
    pub sqrt_price_limit_one: u128,
    pub sqrt_price_limit_two: u128,
}

/// Instruction builder for `TwoHopSwap`.
///
/// ### Accounts:
///
///   0. `[optional]` token_program (default to `TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA`)
///   1. `[signer]` token_authority
///   2. `[writable]` whirlpool_one
///   3. `[writable]` whirlpool_two
///   4. `[writable]` token_owner_account_one_a
///   5. `[writable]` token_vault_one_a
///   6. `[writable]` token_owner_account_one_b
///   7. `[writable]` token_vault_one_b
///   8. `[writable]` token_owner_account_two_a
///   9. `[writable]` token_vault_two_a
///   10. `[writable]` token_owner_account_two_b
///   11. `[writable]` token_vault_two_b
///   12. `[writable]` tick_array_one0
///   13. `[writable]` tick_array_one1
///   14. `[writable]` tick_array_one2
///   15. `[writable]` tick_array_two0
///   16. `[writable]` tick_array_two1
///   17. `[writable]` tick_array_two2
///   18. `[]` oracle_one
///   19. `[]` oracle_two
#[derive(Clone, Debug, Default)]
pub struct TwoHopSwapBuilder {
    token_program: Option<solana_pubkey::Pubkey>,
    token_authority: Option<solana_pubkey::Pubkey>,
    whirlpool_one: Option<solana_pubkey::Pubkey>,
    whirlpool_two: Option<solana_pubkey::Pubkey>,
    token_owner_account_one_a: Option<solana_pubkey::Pubkey>,
    token_vault_one_a: Option<solana_pubkey::Pubkey>,
    token_owner_account_one_b: Option<solana_pubkey::Pubkey>,
    token_vault_one_b: Option<solana_pubkey::Pubkey>,
    token_owner_account_two_a: Option<solana_pubkey::Pubkey>,
    token_vault_two_a: Option<solana_pubkey::Pubkey>,
    token_owner_account_two_b: Option<solana_pubkey::Pubkey>,
    token_vault_two_b: Option<solana_pubkey::Pubkey>,
    tick_array_one0: Option<solana_pubkey::Pubkey>,
    tick_array_one1: Option<solana_pubkey::Pubkey>,
    tick_array_one2: Option<solana_pubkey::Pubkey>,
    tick_array_two0: Option<solana_pubkey::Pubkey>,
    tick_array_two1: Option<solana_pubkey::Pubkey>,
    tick_array_two2: Option<solana_pubkey::Pubkey>,
    oracle_one: Option<solana_pubkey::Pubkey>,
    oracle_two: Option<solana_pubkey::Pubkey>,
    amount: Option<u64>,
    other_amount_threshold: Option<u64>,
    amount_specified_is_input: Option<bool>,
    a_to_b_one: Option<bool>,
    a_to_b_two: Option<bool>,
    sqrt_price_limit_one: Option<u128>,
    sqrt_price_limit_two: Option<u128>,
    __remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl TwoHopSwapBuilder {
    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
    }
    #[inline(always)]
    pub fn token_authority(&mut self, token_authority: solana_pubkey::Pubkey) -> &mut Self {
        self.token_authority = Some(token_authority);
        self
    }
    #[inline(always)]
    pub fn whirlpool_one(&mut self, whirlpool_one: solana_pubkey::Pubkey) -> &mut Self {
        self.whirlpool_one = Some(whirlpool_one);
        self
    }
    #[inline(always)]
    pub fn whirlpool_two(&mut self, whirlpool_two: solana_pubkey::Pubkey) -> &mut Self {
        self.whirlpool_two = Some(whirlpool_two);
        self
    }
    #[inline(always)]
    pub fn token_owner_account_one_a(
        &mut self,
        token_owner_account_one_a: solana_pubkey::Pubkey,
    ) -> &mut Self {
        self.token_owner_account_one_a = Some(token_owner_account_one_a);
        self
    }
    #[inline(always)]
    pub fn token_vault_one_a(&mut self, token_vault_one_a: solana_pubkey::Pubkey) -> &mut Self {
        self.token_vault_one_a = Some(token_vault_one_a);
        self
    }
    #[inline(always)]
    pub fn token_owner_account_one_b(
        &mut self,
        token_owner_account_one_b: solana_pubkey::Pubkey,
    ) -> &mut Self {
        self.token_owner_account_one_b = Some(token_owner_account_one_b);
        self
    }
    #[inline(always)]
    pub fn token_vault_one_b(&mut self, token_vault_one_b: solana_pubkey::Pubkey) -> &mut Self {
        self.token_vault_one_b = Some(token_vault_one_b);
        self
    }
    #[inline(always)]
    pub fn token_owner_account_two_a(
        &mut self,
        token_owner_account_two_a: solana_pubkey::Pubkey,
    ) -> &mut Self {
        self.token_owner_account_two_a = Some(token_owner_account_two_a);
        self
    }
    #[inline(always)]
    pub fn token_vault_two_a(&mut self, token_vault_two_a: solana_pubkey::Pubkey) -> &mut Self {
        self.token_vault_two_a = Some(token_vault_two_a);
        self
    }
    #[inline(always)]
    pub fn token_owner_account_two_b(
        &mut self,
        token_owner_account_two_b: solana_pubkey::Pubkey,
    ) -> &mut Self {
        self.token_owner_account_two_b = Some(token_owner_account_two_b);
        self
    }
    #[inline(always)]
    pub fn token_vault_two_b(&mut self, token_vault_two_b: solana_pubkey::Pubkey) -> &mut Self {
        self.token_vault_two_b = Some(token_vault_two_b);
        self
    }
    #[inline(always)]
    pub fn tick_array_one0(&mut self, tick_array_one0: solana_pubkey::Pubkey) -> &mut Self {
        self.tick_array_one0 = Some(tick_array_one0);
        self
    }
    #[inline(always)]
    pub fn tick_array_one1(&mut self, tick_array_one1: solana_pubkey::Pubkey) -> &mut Self {
        self.tick_array_one1 = Some(tick_array_one1);
        self
    }
    #[inline(always)]
    pub fn tick_array_one2(&mut self, tick_array_one2: solana_pubkey::Pubkey) -> &mut Self {
        self.tick_array_one2 = Some(tick_array_one2);
        self
    }
    #[inline(always)]
    pub fn tick_array_two0(&mut self, tick_array_two0: solana_pubkey::Pubkey) -> &mut Self {
        self.tick_array_two0 = Some(tick_array_two0);
        self
    }
    #[inline(always)]
    pub fn tick_array_two1(&mut self, tick_array_two1: solana_pubkey::Pubkey) -> &mut Self {
        self.tick_array_two1 = Some(tick_array_two1);
        self
    }
    #[inline(always)]
    pub fn tick_array_two2(&mut self, tick_array_two2: solana_pubkey::Pubkey) -> &mut Self {
        self.tick_array_two2 = Some(tick_array_two2);
        self
    }
    #[inline(always)]
    pub fn oracle_one(&mut self, oracle_one: solana_pubkey::Pubkey) -> &mut Self {
        self.oracle_one = Some(oracle_one);
        self
    }
    #[inline(always)]
    pub fn oracle_two(&mut self, oracle_two: solana_pubkey::Pubkey) -> &mut Self {
        self.oracle_two = Some(oracle_two);
        self
    }
    #[inline(always)]
    pub fn amount(&mut self, amount: u64) -> &mut Self {
        self.amount = Some(amount);
        self
    }
    #[inline(always)]
    pub fn other_amount_threshold(&mut self, other_amount_threshold: u64) -> &mut Self {
        self.other_amount_threshold = Some(other_amount_threshold);
        self
    }
    #[inline(always)]
    pub fn amount_specified_is_input(&mut self, amount_specified_is_input: bool) -> &mut Self {
        self.amount_specified_is_input = Some(amount_specified_is_input);
        self
    }
    #[inline(always)]
    pub fn a_to_b_one(&mut self, a_to_b_one: bool) -> &mut Self {
        self.a_to_b_one = Some(a_to_b_one);
        self
    }
    #[inline(always)]
    pub fn a_to_b_two(&mut self, a_to_b_two: bool) -> &mut Self {
        self.a_to_b_two = Some(a_to_b_two);
        self
    }
    #[inline(always)]
    pub fn sqrt_price_limit_one(&mut self, sqrt_price_limit_one: u128) -> &mut Self {
        self.sqrt_price_limit_one = Some(sqrt_price_limit_one);
        self
    }
    #[inline(always)]
    pub fn sqrt_price_limit_two(&mut self, sqrt_price_limit_two: u128) -> &mut Self {
        self.sqrt_price_limit_two = Some(sqrt_price_limit_two);
        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 = TwoHopSwap {
            token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!(
                "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
            )),
            token_authority: self.token_authority.expect("token_authority is not set"),
            whirlpool_one: self.whirlpool_one.expect("whirlpool_one is not set"),
            whirlpool_two: self.whirlpool_two.expect("whirlpool_two is not set"),
            token_owner_account_one_a: self
                .token_owner_account_one_a
                .expect("token_owner_account_one_a is not set"),
            token_vault_one_a: self
                .token_vault_one_a
                .expect("token_vault_one_a is not set"),
            token_owner_account_one_b: self
                .token_owner_account_one_b
                .expect("token_owner_account_one_b is not set"),
            token_vault_one_b: self
                .token_vault_one_b
                .expect("token_vault_one_b is not set"),
            token_owner_account_two_a: self
                .token_owner_account_two_a
                .expect("token_owner_account_two_a is not set"),
            token_vault_two_a: self
                .token_vault_two_a
                .expect("token_vault_two_a is not set"),
            token_owner_account_two_b: self
                .token_owner_account_two_b
                .expect("token_owner_account_two_b is not set"),
            token_vault_two_b: self
                .token_vault_two_b
                .expect("token_vault_two_b is not set"),
            tick_array_one0: self.tick_array_one0.expect("tick_array_one0 is not set"),
            tick_array_one1: self.tick_array_one1.expect("tick_array_one1 is not set"),
            tick_array_one2: self.tick_array_one2.expect("tick_array_one2 is not set"),
            tick_array_two0: self.tick_array_two0.expect("tick_array_two0 is not set"),
            tick_array_two1: self.tick_array_two1.expect("tick_array_two1 is not set"),
            tick_array_two2: self.tick_array_two2.expect("tick_array_two2 is not set"),
            oracle_one: self.oracle_one.expect("oracle_one is not set"),
            oracle_two: self.oracle_two.expect("oracle_two is not set"),
        };
        let args = TwoHopSwapInstructionArgs {
            amount: self.amount.clone().expect("amount is not set"),
            other_amount_threshold: self
                .other_amount_threshold
                .clone()
                .expect("other_amount_threshold is not set"),
            amount_specified_is_input: self
                .amount_specified_is_input
                .clone()
                .expect("amount_specified_is_input is not set"),
            a_to_b_one: self.a_to_b_one.clone().expect("a_to_b_one is not set"),
            a_to_b_two: self.a_to_b_two.clone().expect("a_to_b_two is not set"),
            sqrt_price_limit_one: self
                .sqrt_price_limit_one
                .clone()
                .expect("sqrt_price_limit_one is not set"),
            sqrt_price_limit_two: self
                .sqrt_price_limit_two
                .clone()
                .expect("sqrt_price_limit_two is not set"),
        };

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<'a, 'b> TwoHopSwapCpi<'a, 'b> {
    pub fn new(
        program: &'b solana_account_info::AccountInfo<'a>,
        accounts: TwoHopSwapCpiAccounts<'a, 'b>,
        args: TwoHopSwapInstructionArgs,
    ) -> Self {
        Self {
            __program: program,
            token_program: accounts.token_program,
            token_authority: accounts.token_authority,
            whirlpool_one: accounts.whirlpool_one,
            whirlpool_two: accounts.whirlpool_two,
            token_owner_account_one_a: accounts.token_owner_account_one_a,
            token_vault_one_a: accounts.token_vault_one_a,
            token_owner_account_one_b: accounts.token_owner_account_one_b,
            token_vault_one_b: accounts.token_vault_one_b,
            token_owner_account_two_a: accounts.token_owner_account_two_a,
            token_vault_two_a: accounts.token_vault_two_a,
            token_owner_account_two_b: accounts.token_owner_account_two_b,
            token_vault_two_b: accounts.token_vault_two_b,
            tick_array_one0: accounts.tick_array_one0,
            tick_array_one1: accounts.tick_array_one1,
            tick_array_one2: accounts.tick_array_one2,
            tick_array_two0: accounts.tick_array_two0,
            tick_array_two1: accounts.tick_array_two1,
            tick_array_two2: accounts.tick_array_two2,
            oracle_one: accounts.oracle_one,
            oracle_two: accounts.oracle_two,
            __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(20 + remaining_accounts.len());
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token_program.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.token_authority.key,
            true,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.whirlpool_one.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.whirlpool_two.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.token_owner_account_one_a.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.token_vault_one_a.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.token_owner_account_one_b.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.token_vault_one_b.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.token_owner_account_two_a.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.token_vault_two_a.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.token_owner_account_two_b.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.token_vault_two_b.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.tick_array_one0.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.tick_array_one1.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.tick_array_one2.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.tick_array_two0.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.tick_array_two1.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new(
            *self.tick_array_two2.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.oracle_one.key,
            false,
        ));
        accounts.push(solana_instruction::AccountMeta::new_readonly(
            *self.oracle_two.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(&TwoHopSwapInstructionData::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(21 + remaining_accounts.len());
        account_infos.push(self.__program.clone());
        account_infos.push(self.token_program.clone());
        account_infos.push(self.token_authority.clone());
        account_infos.push(self.whirlpool_one.clone());
        account_infos.push(self.whirlpool_two.clone());
        account_infos.push(self.token_owner_account_one_a.clone());
        account_infos.push(self.token_vault_one_a.clone());
        account_infos.push(self.token_owner_account_one_b.clone());
        account_infos.push(self.token_vault_one_b.clone());
        account_infos.push(self.token_owner_account_two_a.clone());
        account_infos.push(self.token_vault_two_a.clone());
        account_infos.push(self.token_owner_account_two_b.clone());
        account_infos.push(self.token_vault_two_b.clone());
        account_infos.push(self.tick_array_one0.clone());
        account_infos.push(self.tick_array_one1.clone());
        account_infos.push(self.tick_array_one2.clone());
        account_infos.push(self.tick_array_two0.clone());
        account_infos.push(self.tick_array_two1.clone());
        account_infos.push(self.tick_array_two2.clone());
        account_infos.push(self.oracle_one.clone());
        account_infos.push(self.oracle_two.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 `TwoHopSwap` via CPI.
///
/// ### Accounts:
///
///   0. `[]` token_program
///   1. `[signer]` token_authority
///   2. `[writable]` whirlpool_one
///   3. `[writable]` whirlpool_two
///   4. `[writable]` token_owner_account_one_a
///   5. `[writable]` token_vault_one_a
///   6. `[writable]` token_owner_account_one_b
///   7. `[writable]` token_vault_one_b
///   8. `[writable]` token_owner_account_two_a
///   9. `[writable]` token_vault_two_a
///   10. `[writable]` token_owner_account_two_b
///   11. `[writable]` token_vault_two_b
///   12. `[writable]` tick_array_one0
///   13. `[writable]` tick_array_one1
///   14. `[writable]` tick_array_one2
///   15. `[writable]` tick_array_two0
///   16. `[writable]` tick_array_two1
///   17. `[writable]` tick_array_two2
///   18. `[]` oracle_one
///   19. `[]` oracle_two
#[derive(Clone, Debug)]
pub struct TwoHopSwapCpiBuilder<'a, 'b> {
    instruction: Box<TwoHopSwapCpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> TwoHopSwapCpiBuilder<'a, 'b> {
    pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
        let instruction = Box::new(TwoHopSwapCpiBuilderInstruction {
            __program: program,
            token_program: None,
            token_authority: None,
            whirlpool_one: None,
            whirlpool_two: None,
            token_owner_account_one_a: None,
            token_vault_one_a: None,
            token_owner_account_one_b: None,
            token_vault_one_b: None,
            token_owner_account_two_a: None,
            token_vault_two_a: None,
            token_owner_account_two_b: None,
            token_vault_two_b: None,
            tick_array_one0: None,
            tick_array_one1: None,
            tick_array_one2: None,
            tick_array_two0: None,
            tick_array_two1: None,
            tick_array_two2: None,
            oracle_one: None,
            oracle_two: None,
            amount: None,
            other_amount_threshold: None,
            amount_specified_is_input: None,
            a_to_b_one: None,
            a_to_b_two: None,
            sqrt_price_limit_one: None,
            sqrt_price_limit_two: 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 token_authority(
        &mut self,
        token_authority: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_authority = Some(token_authority);
        self
    }
    #[inline(always)]
    pub fn whirlpool_one(
        &mut self,
        whirlpool_one: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.whirlpool_one = Some(whirlpool_one);
        self
    }
    #[inline(always)]
    pub fn whirlpool_two(
        &mut self,
        whirlpool_two: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.whirlpool_two = Some(whirlpool_two);
        self
    }
    #[inline(always)]
    pub fn token_owner_account_one_a(
        &mut self,
        token_owner_account_one_a: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_owner_account_one_a = Some(token_owner_account_one_a);
        self
    }
    #[inline(always)]
    pub fn token_vault_one_a(
        &mut self,
        token_vault_one_a: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_vault_one_a = Some(token_vault_one_a);
        self
    }
    #[inline(always)]
    pub fn token_owner_account_one_b(
        &mut self,
        token_owner_account_one_b: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_owner_account_one_b = Some(token_owner_account_one_b);
        self
    }
    #[inline(always)]
    pub fn token_vault_one_b(
        &mut self,
        token_vault_one_b: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_vault_one_b = Some(token_vault_one_b);
        self
    }
    #[inline(always)]
    pub fn token_owner_account_two_a(
        &mut self,
        token_owner_account_two_a: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_owner_account_two_a = Some(token_owner_account_two_a);
        self
    }
    #[inline(always)]
    pub fn token_vault_two_a(
        &mut self,
        token_vault_two_a: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_vault_two_a = Some(token_vault_two_a);
        self
    }
    #[inline(always)]
    pub fn token_owner_account_two_b(
        &mut self,
        token_owner_account_two_b: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_owner_account_two_b = Some(token_owner_account_two_b);
        self
    }
    #[inline(always)]
    pub fn token_vault_two_b(
        &mut self,
        token_vault_two_b: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.token_vault_two_b = Some(token_vault_two_b);
        self
    }
    #[inline(always)]
    pub fn tick_array_one0(
        &mut self,
        tick_array_one0: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.tick_array_one0 = Some(tick_array_one0);
        self
    }
    #[inline(always)]
    pub fn tick_array_one1(
        &mut self,
        tick_array_one1: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.tick_array_one1 = Some(tick_array_one1);
        self
    }
    #[inline(always)]
    pub fn tick_array_one2(
        &mut self,
        tick_array_one2: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.tick_array_one2 = Some(tick_array_one2);
        self
    }
    #[inline(always)]
    pub fn tick_array_two0(
        &mut self,
        tick_array_two0: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.tick_array_two0 = Some(tick_array_two0);
        self
    }
    #[inline(always)]
    pub fn tick_array_two1(
        &mut self,
        tick_array_two1: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.tick_array_two1 = Some(tick_array_two1);
        self
    }
    #[inline(always)]
    pub fn tick_array_two2(
        &mut self,
        tick_array_two2: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.tick_array_two2 = Some(tick_array_two2);
        self
    }
    #[inline(always)]
    pub fn oracle_one(
        &mut self,
        oracle_one: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.oracle_one = Some(oracle_one);
        self
    }
    #[inline(always)]
    pub fn oracle_two(
        &mut self,
        oracle_two: &'b solana_account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.oracle_two = Some(oracle_two);
        self
    }
    #[inline(always)]
    pub fn amount(&mut self, amount: u64) -> &mut Self {
        self.instruction.amount = Some(amount);
        self
    }
    #[inline(always)]
    pub fn other_amount_threshold(&mut self, other_amount_threshold: u64) -> &mut Self {
        self.instruction.other_amount_threshold = Some(other_amount_threshold);
        self
    }
    #[inline(always)]
    pub fn amount_specified_is_input(&mut self, amount_specified_is_input: bool) -> &mut Self {
        self.instruction.amount_specified_is_input = Some(amount_specified_is_input);
        self
    }
    #[inline(always)]
    pub fn a_to_b_one(&mut self, a_to_b_one: bool) -> &mut Self {
        self.instruction.a_to_b_one = Some(a_to_b_one);
        self
    }
    #[inline(always)]
    pub fn a_to_b_two(&mut self, a_to_b_two: bool) -> &mut Self {
        self.instruction.a_to_b_two = Some(a_to_b_two);
        self
    }
    #[inline(always)]
    pub fn sqrt_price_limit_one(&mut self, sqrt_price_limit_one: u128) -> &mut Self {
        self.instruction.sqrt_price_limit_one = Some(sqrt_price_limit_one);
        self
    }
    #[inline(always)]
    pub fn sqrt_price_limit_two(&mut self, sqrt_price_limit_two: u128) -> &mut Self {
        self.instruction.sqrt_price_limit_two = Some(sqrt_price_limit_two);
        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 = TwoHopSwapInstructionArgs {
            amount: self.instruction.amount.clone().expect("amount is not set"),
            other_amount_threshold: self
                .instruction
                .other_amount_threshold
                .clone()
                .expect("other_amount_threshold is not set"),
            amount_specified_is_input: self
                .instruction
                .amount_specified_is_input
                .clone()
                .expect("amount_specified_is_input is not set"),
            a_to_b_one: self
                .instruction
                .a_to_b_one
                .clone()
                .expect("a_to_b_one is not set"),
            a_to_b_two: self
                .instruction
                .a_to_b_two
                .clone()
                .expect("a_to_b_two is not set"),
            sqrt_price_limit_one: self
                .instruction
                .sqrt_price_limit_one
                .clone()
                .expect("sqrt_price_limit_one is not set"),
            sqrt_price_limit_two: self
                .instruction
                .sqrt_price_limit_two
                .clone()
                .expect("sqrt_price_limit_two is not set"),
        };
        let instruction = TwoHopSwapCpi {
            __program: self.instruction.__program,

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

#[derive(Clone, Debug)]
struct TwoHopSwapCpiBuilderInstruction<'a, 'b> {
    __program: &'b solana_account_info::AccountInfo<'a>,
    token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
    whirlpool_one: Option<&'b solana_account_info::AccountInfo<'a>>,
    whirlpool_two: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_owner_account_one_a: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_vault_one_a: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_owner_account_one_b: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_vault_one_b: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_owner_account_two_a: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_vault_two_a: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_owner_account_two_b: Option<&'b solana_account_info::AccountInfo<'a>>,
    token_vault_two_b: Option<&'b solana_account_info::AccountInfo<'a>>,
    tick_array_one0: Option<&'b solana_account_info::AccountInfo<'a>>,
    tick_array_one1: Option<&'b solana_account_info::AccountInfo<'a>>,
    tick_array_one2: Option<&'b solana_account_info::AccountInfo<'a>>,
    tick_array_two0: Option<&'b solana_account_info::AccountInfo<'a>>,
    tick_array_two1: Option<&'b solana_account_info::AccountInfo<'a>>,
    tick_array_two2: Option<&'b solana_account_info::AccountInfo<'a>>,
    oracle_one: Option<&'b solana_account_info::AccountInfo<'a>>,
    oracle_two: Option<&'b solana_account_info::AccountInfo<'a>>,
    amount: Option<u64>,
    other_amount_threshold: Option<u64>,
    amount_specified_is_input: Option<bool>,
    a_to_b_one: Option<bool>,
    a_to_b_two: Option<bool>,
    sqrt_price_limit_one: Option<u128>,
    sqrt_price_limit_two: Option<u128>,
    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
    __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}
