//! 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::BorshSerialize;
use borsh::BorshDeserialize;

/// Accounts.
#[derive(Debug)]
pub struct OpenPositionFusion {
            /// 
/// TUNA accounts
/// 

    
              
          pub authority: solana_program::pubkey::Pubkey,
          
              
          pub mint_a: solana_program::pubkey::Pubkey,
          
              
          pub mint_b: solana_program::pubkey::Pubkey,
          
              
          pub token_program_a: solana_program::pubkey::Pubkey,
          
              
          pub token_program_b: solana_program::pubkey::Pubkey,
          
              
          pub market: solana_program::pubkey::Pubkey,
          
              
          pub tuna_position: solana_program::pubkey::Pubkey,
          
              
          pub tuna_position_mint: solana_program::pubkey::Pubkey,
          
              
          pub tuna_position_ata: solana_program::pubkey::Pubkey,
          
              
          pub tuna_position_ata_a: solana_program::pubkey::Pubkey,
          
              
          pub tuna_position_ata_b: solana_program::pubkey::Pubkey,
                /// 
/// Fusion AMM accounts
/// 

    
              
          pub fusionamm_program: solana_program::pubkey::Pubkey,
          
              
          pub fusion_pool: solana_program::pubkey::Pubkey,
          
              
          pub fusion_position: solana_program::pubkey::Pubkey,
          
              
          pub metadata_update_auth: solana_program::pubkey::Pubkey,
                /// 
/// Other accounts
/// 

    
              
          pub token2022_program: solana_program::pubkey::Pubkey,
          
              
          pub system_program: solana_program::pubkey::Pubkey,
          
              
          pub associated_token_program: solana_program::pubkey::Pubkey,
      }

impl OpenPositionFusion {
  pub fn instruction(&self, args: OpenPositionFusionInstructionArgs) -> solana_program::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: OpenPositionFusionInstructionArgs, remaining_accounts: &[solana_program::instruction::AccountMeta]) -> solana_program::instruction::Instruction {
    let mut accounts = Vec::with_capacity(18+ remaining_accounts.len());
                            accounts.push(solana_program::instruction::AccountMeta::new(
            self.authority,
            true
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            self.mint_a,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            self.mint_b,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            self.token_program_a,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            self.token_program_b,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            self.market,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            self.tuna_position,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            self.tuna_position_mint,
            true
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            self.tuna_position_ata,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            self.tuna_position_ata_a,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            self.tuna_position_ata_b,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            self.fusionamm_program,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            self.fusion_pool,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            self.fusion_position,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            self.metadata_update_auth,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            self.token2022_program,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            self.system_program,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            self.associated_token_program,
            false
          ));
                      accounts.extend_from_slice(remaining_accounts);
    let mut data = borsh::to_vec(&OpenPositionFusionInstructionData::new()).unwrap();
          let mut args = borsh::to_vec(&args).unwrap();
      data.append(&mut args);
    
    solana_program::instruction::Instruction {
      program_id: crate::TUNA_ID,
      accounts,
      data,
    }
  }
}

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

impl OpenPositionFusionInstructionData {
  pub fn new() -> Self {
    Self {
                        discriminator: [78, 68, 77, 41, 132, 42, 34, 238],
                                                                                        }
  }
}

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

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
 pub struct OpenPositionFusionInstructionArgs {
                  pub tick_lower_index: i32,
                pub tick_upper_index: i32,
                pub tick_stop_loss_index: i32,
                pub tick_take_profit_index: i32,
                pub flags: u32,
      }


/// Instruction builder for `OpenPositionFusion`.
///
/// ### Accounts:
///
                      ///   0. `[writable, signer]` authority
          ///   1. `[]` mint_a
          ///   2. `[]` mint_b
          ///   3. `[]` token_program_a
          ///   4. `[]` token_program_b
          ///   5. `[]` market
                ///   6. `[writable]` tuna_position
                      ///   7. `[writable, signer]` tuna_position_mint
                ///   8. `[writable]` tuna_position_ata
                ///   9. `[writable]` tuna_position_ata_a
                ///   10. `[writable]` tuna_position_ata_b
          ///   11. `[]` fusionamm_program
          ///   12. `[]` fusion_pool
                ///   13. `[writable]` fusion_position
          ///   14. `[]` metadata_update_auth
          ///   15. `[]` token2022_program
                ///   16. `[optional]` system_program (default to `11111111111111111111111111111111`)
          ///   17. `[]` associated_token_program
#[derive(Clone, Debug, Default)]
pub struct OpenPositionFusionBuilder {
            authority: Option<solana_program::pubkey::Pubkey>,
                mint_a: Option<solana_program::pubkey::Pubkey>,
                mint_b: Option<solana_program::pubkey::Pubkey>,
                token_program_a: Option<solana_program::pubkey::Pubkey>,
                token_program_b: Option<solana_program::pubkey::Pubkey>,
                market: Option<solana_program::pubkey::Pubkey>,
                tuna_position: Option<solana_program::pubkey::Pubkey>,
                tuna_position_mint: Option<solana_program::pubkey::Pubkey>,
                tuna_position_ata: Option<solana_program::pubkey::Pubkey>,
                tuna_position_ata_a: Option<solana_program::pubkey::Pubkey>,
                tuna_position_ata_b: Option<solana_program::pubkey::Pubkey>,
                fusionamm_program: Option<solana_program::pubkey::Pubkey>,
                fusion_pool: Option<solana_program::pubkey::Pubkey>,
                fusion_position: Option<solana_program::pubkey::Pubkey>,
                metadata_update_auth: Option<solana_program::pubkey::Pubkey>,
                token2022_program: Option<solana_program::pubkey::Pubkey>,
                system_program: Option<solana_program::pubkey::Pubkey>,
                associated_token_program: Option<solana_program::pubkey::Pubkey>,
                        tick_lower_index: Option<i32>,
                tick_upper_index: Option<i32>,
                tick_stop_loss_index: Option<i32>,
                tick_take_profit_index: Option<i32>,
                flags: Option<u32>,
        __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}

impl OpenPositionFusionBuilder {
  pub fn new() -> Self {
    Self::default()
  }
            /// 
/// TUNA accounts
/// 
#[inline(always)]
    pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.authority = Some(authority);
                    self
    }
            #[inline(always)]
    pub fn mint_a(&mut self, mint_a: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.mint_a = Some(mint_a);
                    self
    }
            #[inline(always)]
    pub fn mint_b(&mut self, mint_b: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.mint_b = Some(mint_b);
                    self
    }
            #[inline(always)]
    pub fn token_program_a(&mut self, token_program_a: solana_program::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_program::pubkey::Pubkey) -> &mut Self {
                        self.token_program_b = Some(token_program_b);
                    self
    }
            #[inline(always)]
    pub fn market(&mut self, market: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.market = Some(market);
                    self
    }
            #[inline(always)]
    pub fn tuna_position(&mut self, tuna_position: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.tuna_position = Some(tuna_position);
                    self
    }
            #[inline(always)]
    pub fn tuna_position_mint(&mut self, tuna_position_mint: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.tuna_position_mint = Some(tuna_position_mint);
                    self
    }
            #[inline(always)]
    pub fn tuna_position_ata(&mut self, tuna_position_ata: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.tuna_position_ata = Some(tuna_position_ata);
                    self
    }
            #[inline(always)]
    pub fn tuna_position_ata_a(&mut self, tuna_position_ata_a: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.tuna_position_ata_a = Some(tuna_position_ata_a);
                    self
    }
            #[inline(always)]
    pub fn tuna_position_ata_b(&mut self, tuna_position_ata_b: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.tuna_position_ata_b = Some(tuna_position_ata_b);
                    self
    }
            /// 
/// Fusion AMM accounts
/// 
#[inline(always)]
    pub fn fusionamm_program(&mut self, fusionamm_program: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.fusionamm_program = Some(fusionamm_program);
                    self
    }
            #[inline(always)]
    pub fn fusion_pool(&mut self, fusion_pool: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.fusion_pool = Some(fusion_pool);
                    self
    }
            #[inline(always)]
    pub fn fusion_position(&mut self, fusion_position: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.fusion_position = Some(fusion_position);
                    self
    }
            #[inline(always)]
    pub fn metadata_update_auth(&mut self, metadata_update_auth: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.metadata_update_auth = Some(metadata_update_auth);
                    self
    }
            /// 
/// Other accounts
/// 
#[inline(always)]
    pub fn token2022_program(&mut self, token2022_program: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.token2022_program = Some(token2022_program);
                    self
    }
            /// `[optional account, default to '11111111111111111111111111111111']`
#[inline(always)]
    pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.system_program = Some(system_program);
                    self
    }
            #[inline(always)]
    pub fn associated_token_program(&mut self, associated_token_program: solana_program::pubkey::Pubkey) -> &mut Self {
                        self.associated_token_program = Some(associated_token_program);
                    self
    }
                    #[inline(always)]
      pub fn tick_lower_index(&mut self, tick_lower_index: i32) -> &mut Self {
        self.tick_lower_index = Some(tick_lower_index);
        self
      }
                #[inline(always)]
      pub fn tick_upper_index(&mut self, tick_upper_index: i32) -> &mut Self {
        self.tick_upper_index = Some(tick_upper_index);
        self
      }
                #[inline(always)]
      pub fn tick_stop_loss_index(&mut self, tick_stop_loss_index: i32) -> &mut Self {
        self.tick_stop_loss_index = Some(tick_stop_loss_index);
        self
      }
                #[inline(always)]
      pub fn tick_take_profit_index(&mut self, tick_take_profit_index: i32) -> &mut Self {
        self.tick_take_profit_index = Some(tick_take_profit_index);
        self
      }
                #[inline(always)]
      pub fn flags(&mut self, flags: u32) -> &mut Self {
        self.flags = Some(flags);
        self
      }
        /// Add an additional account to the instruction.
  #[inline(always)]
  pub fn add_remaining_account(&mut self, account: solana_program::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_program::instruction::AccountMeta]) -> &mut Self {
    self.__remaining_accounts.extend_from_slice(accounts);
    self
  }
  #[allow(clippy::clone_on_copy)]
  pub fn instruction(&self) -> solana_program::instruction::Instruction {
    let accounts = OpenPositionFusion {
                              authority: self.authority.expect("authority is not set"),
                                        mint_a: self.mint_a.expect("mint_a is not set"),
                                        mint_b: self.mint_b.expect("mint_b 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"),
                                        market: self.market.expect("market is not set"),
                                        tuna_position: self.tuna_position.expect("tuna_position is not set"),
                                        tuna_position_mint: self.tuna_position_mint.expect("tuna_position_mint is not set"),
                                        tuna_position_ata: self.tuna_position_ata.expect("tuna_position_ata is not set"),
                                        tuna_position_ata_a: self.tuna_position_ata_a.expect("tuna_position_ata_a is not set"),
                                        tuna_position_ata_b: self.tuna_position_ata_b.expect("tuna_position_ata_b is not set"),
                                        fusionamm_program: self.fusionamm_program.expect("fusionamm_program is not set"),
                                        fusion_pool: self.fusion_pool.expect("fusion_pool is not set"),
                                        fusion_position: self.fusion_position.expect("fusion_position is not set"),
                                        metadata_update_auth: self.metadata_update_auth.expect("metadata_update_auth is not set"),
                                        token2022_program: self.token2022_program.expect("token2022_program is not set"),
                                        system_program: self.system_program.unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
                                        associated_token_program: self.associated_token_program.expect("associated_token_program is not set"),
                      };
          let args = OpenPositionFusionInstructionArgs {
                                                              tick_lower_index: self.tick_lower_index.clone().expect("tick_lower_index is not set"),
                                                                  tick_upper_index: self.tick_upper_index.clone().expect("tick_upper_index is not set"),
                                                                  tick_stop_loss_index: self.tick_stop_loss_index.clone().expect("tick_stop_loss_index is not set"),
                                                                  tick_take_profit_index: self.tick_take_profit_index.clone().expect("tick_take_profit_index is not set"),
                                                                  flags: self.flags.clone().expect("flags is not set"),
                                    };
    
    accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
  }
}

  /// `open_position_fusion` CPI accounts.
  pub struct OpenPositionFusionCpiAccounts<'a, 'b> {
                  /// 
/// TUNA accounts
/// 

      
                    
              pub authority: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub mint_a: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub mint_b: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub token_program_a: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub token_program_b: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub market: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub tuna_position: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub tuna_position_mint: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub tuna_position_ata: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub tuna_position_ata_a: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub tuna_position_ata_b: &'b solana_program::account_info::AccountInfo<'a>,
                        /// 
/// Fusion AMM accounts
/// 

      
                    
              pub fusionamm_program: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub fusion_pool: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub fusion_position: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub metadata_update_auth: &'b solana_program::account_info::AccountInfo<'a>,
                        /// 
/// Other accounts
/// 

      
                    
              pub token2022_program: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
                
                    
              pub associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
            }

/// `open_position_fusion` CPI instruction.
pub struct OpenPositionFusionCpi<'a, 'b> {
  /// The program to invoke.
  pub __program: &'b solana_program::account_info::AccountInfo<'a>,
            /// 
/// TUNA accounts
/// 

    
              
          pub authority: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub mint_a: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub mint_b: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub token_program_a: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub token_program_b: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub market: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub tuna_position: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub tuna_position_mint: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub tuna_position_ata: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub tuna_position_ata_a: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub tuna_position_ata_b: &'b solana_program::account_info::AccountInfo<'a>,
                /// 
/// Fusion AMM accounts
/// 

    
              
          pub fusionamm_program: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub fusion_pool: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub fusion_position: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub metadata_update_auth: &'b solana_program::account_info::AccountInfo<'a>,
                /// 
/// Other accounts
/// 

    
              
          pub token2022_program: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
          
              
          pub associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
            /// The arguments for the instruction.
    pub __args: OpenPositionFusionInstructionArgs,
  }

impl<'a, 'b> OpenPositionFusionCpi<'a, 'b> {
  pub fn new(
    program: &'b solana_program::account_info::AccountInfo<'a>,
          accounts: OpenPositionFusionCpiAccounts<'a, 'b>,
              args: OpenPositionFusionInstructionArgs,
      ) -> Self {
    Self {
      __program: program,
              authority: accounts.authority,
              mint_a: accounts.mint_a,
              mint_b: accounts.mint_b,
              token_program_a: accounts.token_program_a,
              token_program_b: accounts.token_program_b,
              market: accounts.market,
              tuna_position: accounts.tuna_position,
              tuna_position_mint: accounts.tuna_position_mint,
              tuna_position_ata: accounts.tuna_position_ata,
              tuna_position_ata_a: accounts.tuna_position_ata_a,
              tuna_position_ata_b: accounts.tuna_position_ata_b,
              fusionamm_program: accounts.fusionamm_program,
              fusion_pool: accounts.fusion_pool,
              fusion_position: accounts.fusion_position,
              metadata_update_auth: accounts.metadata_update_auth,
              token2022_program: accounts.token2022_program,
              system_program: accounts.system_program,
              associated_token_program: accounts.associated_token_program,
                    __args: args,
          }
  }
  #[inline(always)]
  pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
    self.invoke_signed_with_remaining_accounts(&[], &[])
  }
  #[inline(always)]
  pub fn invoke_with_remaining_accounts(&self, remaining_accounts: &[(&'b solana_program::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_program::account_info::AccountInfo<'a>, bool, bool)]
  ) -> solana_program::entrypoint::ProgramResult {
    let mut accounts = Vec::with_capacity(18+ remaining_accounts.len());
                            accounts.push(solana_program::instruction::AccountMeta::new(
            *self.authority.key,
            true
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            *self.mint_a.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            *self.mint_b.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            *self.token_program_a.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            *self.token_program_b.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            *self.market.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            *self.tuna_position.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            *self.tuna_position_mint.key,
            true
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            *self.tuna_position_ata.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            *self.tuna_position_ata_a.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            *self.tuna_position_ata_b.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            *self.fusionamm_program.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            *self.fusion_pool.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new(
            *self.fusion_position.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            *self.metadata_update_auth.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            *self.token2022_program.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            *self.system_program.key,
            false
          ));
                                          accounts.push(solana_program::instruction::AccountMeta::new_readonly(
            *self.associated_token_program.key,
            false
          ));
                      remaining_accounts.iter().for_each(|remaining_account| {
      accounts.push(solana_program::instruction::AccountMeta {
          pubkey: *remaining_account.0.key,
          is_signer: remaining_account.1,
          is_writable: remaining_account.2,
      })
    });
    let mut data = borsh::to_vec(&OpenPositionFusionInstructionData::new()).unwrap();
          let mut args = borsh::to_vec(&self.__args).unwrap();
      data.append(&mut args);
    
    let instruction = solana_program::instruction::Instruction {
      program_id: crate::TUNA_ID,
      accounts,
      data,
    };
    let mut account_infos = Vec::with_capacity(19 + remaining_accounts.len());
    account_infos.push(self.__program.clone());
                  account_infos.push(self.authority.clone());
                        account_infos.push(self.mint_a.clone());
                        account_infos.push(self.mint_b.clone());
                        account_infos.push(self.token_program_a.clone());
                        account_infos.push(self.token_program_b.clone());
                        account_infos.push(self.market.clone());
                        account_infos.push(self.tuna_position.clone());
                        account_infos.push(self.tuna_position_mint.clone());
                        account_infos.push(self.tuna_position_ata.clone());
                        account_infos.push(self.tuna_position_ata_a.clone());
                        account_infos.push(self.tuna_position_ata_b.clone());
                        account_infos.push(self.fusionamm_program.clone());
                        account_infos.push(self.fusion_pool.clone());
                        account_infos.push(self.fusion_position.clone());
                        account_infos.push(self.metadata_update_auth.clone());
                        account_infos.push(self.token2022_program.clone());
                        account_infos.push(self.system_program.clone());
                        account_infos.push(self.associated_token_program.clone());
              remaining_accounts.iter().for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));

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

/// Instruction builder for `OpenPositionFusion` via CPI.
///
/// ### Accounts:
///
                      ///   0. `[writable, signer]` authority
          ///   1. `[]` mint_a
          ///   2. `[]` mint_b
          ///   3. `[]` token_program_a
          ///   4. `[]` token_program_b
          ///   5. `[]` market
                ///   6. `[writable]` tuna_position
                      ///   7. `[writable, signer]` tuna_position_mint
                ///   8. `[writable]` tuna_position_ata
                ///   9. `[writable]` tuna_position_ata_a
                ///   10. `[writable]` tuna_position_ata_b
          ///   11. `[]` fusionamm_program
          ///   12. `[]` fusion_pool
                ///   13. `[writable]` fusion_position
          ///   14. `[]` metadata_update_auth
          ///   15. `[]` token2022_program
          ///   16. `[]` system_program
          ///   17. `[]` associated_token_program
#[derive(Clone, Debug)]
pub struct OpenPositionFusionCpiBuilder<'a, 'b> {
  instruction: Box<OpenPositionFusionCpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> OpenPositionFusionCpiBuilder<'a, 'b> {
  pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
    let instruction = Box::new(OpenPositionFusionCpiBuilderInstruction {
      __program: program,
              authority: None,
              mint_a: None,
              mint_b: None,
              token_program_a: None,
              token_program_b: None,
              market: None,
              tuna_position: None,
              tuna_position_mint: None,
              tuna_position_ata: None,
              tuna_position_ata_a: None,
              tuna_position_ata_b: None,
              fusionamm_program: None,
              fusion_pool: None,
              fusion_position: None,
              metadata_update_auth: None,
              token2022_program: None,
              system_program: None,
              associated_token_program: None,
                                            tick_lower_index: None,
                                tick_upper_index: None,
                                tick_stop_loss_index: None,
                                tick_take_profit_index: None,
                                flags: None,
                    __remaining_accounts: Vec::new(),
    });
    Self { instruction }
  }
      /// 
/// TUNA accounts
/// 
#[inline(always)]
    pub fn authority(&mut self, authority: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.authority = Some(authority);
                    self
    }
      #[inline(always)]
    pub fn mint_a(&mut self, mint_a: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.mint_a = Some(mint_a);
                    self
    }
      #[inline(always)]
    pub fn mint_b(&mut self, mint_b: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.mint_b = Some(mint_b);
                    self
    }
      #[inline(always)]
    pub fn token_program_a(&mut self, token_program_a: &'b solana_program::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_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.token_program_b = Some(token_program_b);
                    self
    }
      #[inline(always)]
    pub fn market(&mut self, market: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.market = Some(market);
                    self
    }
      #[inline(always)]
    pub fn tuna_position(&mut self, tuna_position: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.tuna_position = Some(tuna_position);
                    self
    }
      #[inline(always)]
    pub fn tuna_position_mint(&mut self, tuna_position_mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.tuna_position_mint = Some(tuna_position_mint);
                    self
    }
      #[inline(always)]
    pub fn tuna_position_ata(&mut self, tuna_position_ata: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.tuna_position_ata = Some(tuna_position_ata);
                    self
    }
      #[inline(always)]
    pub fn tuna_position_ata_a(&mut self, tuna_position_ata_a: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.tuna_position_ata_a = Some(tuna_position_ata_a);
                    self
    }
      #[inline(always)]
    pub fn tuna_position_ata_b(&mut self, tuna_position_ata_b: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.tuna_position_ata_b = Some(tuna_position_ata_b);
                    self
    }
      /// 
/// Fusion AMM accounts
/// 
#[inline(always)]
    pub fn fusionamm_program(&mut self, fusionamm_program: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.fusionamm_program = Some(fusionamm_program);
                    self
    }
      #[inline(always)]
    pub fn fusion_pool(&mut self, fusion_pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.fusion_pool = Some(fusion_pool);
                    self
    }
      #[inline(always)]
    pub fn fusion_position(&mut self, fusion_position: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.fusion_position = Some(fusion_position);
                    self
    }
      #[inline(always)]
    pub fn metadata_update_auth(&mut self, metadata_update_auth: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.metadata_update_auth = Some(metadata_update_auth);
                    self
    }
      /// 
/// Other accounts
/// 
#[inline(always)]
    pub fn token2022_program(&mut self, token2022_program: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.token2022_program = Some(token2022_program);
                    self
    }
      #[inline(always)]
    pub fn system_program(&mut self, system_program: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.system_program = Some(system_program);
                    self
    }
      #[inline(always)]
    pub fn associated_token_program(&mut self, associated_token_program: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.associated_token_program = Some(associated_token_program);
                    self
    }
                    #[inline(always)]
      pub fn tick_lower_index(&mut self, tick_lower_index: i32) -> &mut Self {
        self.instruction.tick_lower_index = Some(tick_lower_index);
        self
      }
                #[inline(always)]
      pub fn tick_upper_index(&mut self, tick_upper_index: i32) -> &mut Self {
        self.instruction.tick_upper_index = Some(tick_upper_index);
        self
      }
                #[inline(always)]
      pub fn tick_stop_loss_index(&mut self, tick_stop_loss_index: i32) -> &mut Self {
        self.instruction.tick_stop_loss_index = Some(tick_stop_loss_index);
        self
      }
                #[inline(always)]
      pub fn tick_take_profit_index(&mut self, tick_take_profit_index: i32) -> &mut Self {
        self.instruction.tick_take_profit_index = Some(tick_take_profit_index);
        self
      }
                #[inline(always)]
      pub fn flags(&mut self, flags: u32) -> &mut Self {
        self.instruction.flags = Some(flags);
        self
      }
        /// Add an additional account to the instruction.
  #[inline(always)]
  pub fn add_remaining_account(&mut self, account: &'b solana_program::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_program::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 = OpenPositionFusionInstructionArgs {
                                                              tick_lower_index: self.instruction.tick_lower_index.clone().expect("tick_lower_index is not set"),
                                                                  tick_upper_index: self.instruction.tick_upper_index.clone().expect("tick_upper_index is not set"),
                                                                  tick_stop_loss_index: self.instruction.tick_stop_loss_index.clone().expect("tick_stop_loss_index is not set"),
                                                                  tick_take_profit_index: self.instruction.tick_take_profit_index.clone().expect("tick_take_profit_index is not set"),
                                                                  flags: self.instruction.flags.clone().expect("flags is not set"),
                                    };
        let instruction = OpenPositionFusionCpi {
        __program: self.instruction.__program,
                  
          authority: self.instruction.authority.expect("authority is not set"),
                  
          mint_a: self.instruction.mint_a.expect("mint_a is not set"),
                  
          mint_b: self.instruction.mint_b.expect("mint_b 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"),
                  
          market: self.instruction.market.expect("market is not set"),
                  
          tuna_position: self.instruction.tuna_position.expect("tuna_position is not set"),
                  
          tuna_position_mint: self.instruction.tuna_position_mint.expect("tuna_position_mint is not set"),
                  
          tuna_position_ata: self.instruction.tuna_position_ata.expect("tuna_position_ata is not set"),
                  
          tuna_position_ata_a: self.instruction.tuna_position_ata_a.expect("tuna_position_ata_a is not set"),
                  
          tuna_position_ata_b: self.instruction.tuna_position_ata_b.expect("tuna_position_ata_b is not set"),
                  
          fusionamm_program: self.instruction.fusionamm_program.expect("fusionamm_program is not set"),
                  
          fusion_pool: self.instruction.fusion_pool.expect("fusion_pool is not set"),
                  
          fusion_position: self.instruction.fusion_position.expect("fusion_position is not set"),
                  
          metadata_update_auth: self.instruction.metadata_update_auth.expect("metadata_update_auth is not set"),
                  
          token2022_program: self.instruction.token2022_program.expect("token2022_program is not set"),
                  
          system_program: self.instruction.system_program.expect("system_program is not set"),
                  
          associated_token_program: self.instruction.associated_token_program.expect("associated_token_program is not set"),
                          __args: args,
            };
    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
  }
}

#[derive(Clone, Debug)]
struct OpenPositionFusionCpiBuilderInstruction<'a, 'b> {
  __program: &'b solana_program::account_info::AccountInfo<'a>,
            authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                mint_a: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                mint_b: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                token_program_a: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                token_program_b: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                market: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                tuna_position: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                tuna_position_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                tuna_position_ata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                tuna_position_ata_a: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                tuna_position_ata_b: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                fusionamm_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                fusion_pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                fusion_position: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                metadata_update_auth: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                token2022_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                associated_token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
                        tick_lower_index: Option<i32>,
                tick_upper_index: Option<i32>,
                tick_stop_loss_index: Option<i32>,
                tick_take_profit_index: Option<i32>,
                flags: Option<u32>,
        /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
  __remaining_accounts: Vec<(&'b solana_program::account_info::AccountInfo<'a>, bool, bool)>,
}

