defituna-staking 1.0.7

Rust client to interact with DefiTuna's Staking on-chain program.
Documentation
//! 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 Unstake {
      
              
          pub authority: solana_pubkey::Pubkey,
          
              
          pub treasury: solana_pubkey::Pubkey,
          
              
          pub position: solana_pubkey::Pubkey,
          
              
          pub vesting_strategy: solana_pubkey::Pubkey,
      }

impl Unstake {
  pub fn instruction(&self, args: UnstakeInstructionArgs) -> 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: UnstakeInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
    let mut accounts = Vec::with_capacity(4+ remaining_accounts.len());
                            accounts.push(solana_instruction::AccountMeta::new(
            self.authority,
            true
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.treasury,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.position,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            self.vesting_strategy,
            false
          ));
                      accounts.extend_from_slice(remaining_accounts);
    let mut data = borsh::to_vec(&UnstakeInstructionData::new()).unwrap();
          let mut args = borsh::to_vec(&args).unwrap();
      data.append(&mut args);
    
    solana_instruction::Instruction {
      program_id: crate::TUNA_STAKING_ID,
      accounts,
      data,
    }
  }
}

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

impl UnstakeInstructionData {
  pub fn new() -> Self {
    Self {
                        discriminator: [90, 95, 107, 42, 205, 124, 50, 225],
                                }
  }
}

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

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


/// Instruction builder for `Unstake`.
///
/// ### Accounts:
///
                      ///   0. `[writable, signer]` authority
                ///   1. `[writable]` treasury
                ///   2. `[writable]` position
                ///   3. `[writable]` vesting_strategy
#[derive(Clone, Debug, Default)]
pub struct UnstakeBuilder {
            authority: Option<solana_pubkey::Pubkey>,
                treasury: Option<solana_pubkey::Pubkey>,
                position: Option<solana_pubkey::Pubkey>,
                vesting_strategy: Option<solana_pubkey::Pubkey>,
                        shares: Option<u64>,
        __remaining_accounts: Vec<solana_instruction::AccountMeta>,
}

impl UnstakeBuilder {
  pub fn new() -> Self {
    Self::default()
  }
            #[inline(always)]
    pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
                        self.authority = Some(authority);
                    self
    }
            #[inline(always)]
    pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self {
                        self.treasury = Some(treasury);
                    self
    }
            #[inline(always)]
    pub fn position(&mut self, position: solana_pubkey::Pubkey) -> &mut Self {
                        self.position = Some(position);
                    self
    }
            #[inline(always)]
    pub fn vesting_strategy(&mut self, vesting_strategy: solana_pubkey::Pubkey) -> &mut Self {
                        self.vesting_strategy = Some(vesting_strategy);
                    self
    }
                    #[inline(always)]
      pub fn shares(&mut self, shares: u64) -> &mut Self {
        self.shares = Some(shares);
        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 = Unstake {
                              authority: self.authority.expect("authority is not set"),
                                        treasury: self.treasury.expect("treasury is not set"),
                                        position: self.position.expect("position is not set"),
                                        vesting_strategy: self.vesting_strategy.expect("vesting_strategy is not set"),
                      };
          let args = UnstakeInstructionArgs {
                                                              shares: self.shares.clone().expect("shares is not set"),
                                    };
    
    accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
  }
}

  /// `unstake` CPI accounts.
  pub struct UnstakeCpiAccounts<'a, 'b> {
          
                    
              pub authority: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub treasury: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub position: &'b solana_account_info::AccountInfo<'a>,
                
                    
              pub vesting_strategy: &'b solana_account_info::AccountInfo<'a>,
            }

/// `unstake` CPI instruction.
pub struct UnstakeCpi<'a, 'b> {
  /// The program to invoke.
  pub __program: &'b solana_account_info::AccountInfo<'a>,
      
              
          pub authority: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub treasury: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub position: &'b solana_account_info::AccountInfo<'a>,
          
              
          pub vesting_strategy: &'b solana_account_info::AccountInfo<'a>,
            /// The arguments for the instruction.
    pub __args: UnstakeInstructionArgs,
  }

impl<'a, 'b> UnstakeCpi<'a, 'b> {
  pub fn new(
    program: &'b solana_account_info::AccountInfo<'a>,
          accounts: UnstakeCpiAccounts<'a, 'b>,
              args: UnstakeInstructionArgs,
      ) -> Self {
    Self {
      __program: program,
              authority: accounts.authority,
              treasury: accounts.treasury,
              position: accounts.position,
              vesting_strategy: accounts.vesting_strategy,
                    __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(4+ remaining_accounts.len());
                            accounts.push(solana_instruction::AccountMeta::new(
            *self.authority.key,
            true
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.treasury.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.position.key,
            false
          ));
                                          accounts.push(solana_instruction::AccountMeta::new(
            *self.vesting_strategy.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(&UnstakeInstructionData::new()).unwrap();
          let mut args = borsh::to_vec(&self.__args).unwrap();
      data.append(&mut args);
    
    let instruction = solana_instruction::Instruction {
      program_id: crate::TUNA_STAKING_ID,
      accounts,
      data,
    };
    let mut account_infos = Vec::with_capacity(5 + remaining_accounts.len());
    account_infos.push(self.__program.clone());
                  account_infos.push(self.authority.clone());
                        account_infos.push(self.treasury.clone());
                        account_infos.push(self.position.clone());
                        account_infos.push(self.vesting_strategy.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 `Unstake` via CPI.
///
/// ### Accounts:
///
                      ///   0. `[writable, signer]` authority
                ///   1. `[writable]` treasury
                ///   2. `[writable]` position
                ///   3. `[writable]` vesting_strategy
#[derive(Clone, Debug)]
pub struct UnstakeCpiBuilder<'a, 'b> {
  instruction: Box<UnstakeCpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> UnstakeCpiBuilder<'a, 'b> {
  pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
    let instruction = Box::new(UnstakeCpiBuilderInstruction {
      __program: program,
              authority: None,
              treasury: None,
              position: None,
              vesting_strategy: None,
                                            shares: None,
                    __remaining_accounts: Vec::new(),
    });
    Self { instruction }
  }
      #[inline(always)]
    pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.authority = Some(authority);
                    self
    }
      #[inline(always)]
    pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.treasury = Some(treasury);
                    self
    }
      #[inline(always)]
    pub fn position(&mut self, position: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.position = Some(position);
                    self
    }
      #[inline(always)]
    pub fn vesting_strategy(&mut self, vesting_strategy: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
                        self.instruction.vesting_strategy = Some(vesting_strategy);
                    self
    }
                    #[inline(always)]
      pub fn shares(&mut self, shares: u64) -> &mut Self {
        self.instruction.shares = Some(shares);
        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 = UnstakeInstructionArgs {
                                                              shares: self.instruction.shares.clone().expect("shares is not set"),
                                    };
        let instruction = UnstakeCpi {
        __program: self.instruction.__program,
                  
          authority: self.instruction.authority.expect("authority is not set"),
                  
          treasury: self.instruction.treasury.expect("treasury is not set"),
                  
          position: self.instruction.position.expect("position is not set"),
                  
          vesting_strategy: self.instruction.vesting_strategy.expect("vesting_strategy is not set"),
                          __args: args,
            };
    instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
  }
}

#[derive(Clone, Debug)]
struct UnstakeCpiBuilderInstruction<'a, 'b> {
  __program: &'b solana_account_info::AccountInfo<'a>,
            authority: Option<&'b solana_account_info::AccountInfo<'a>>,
                treasury: Option<&'b solana_account_info::AccountInfo<'a>>,
                position: Option<&'b solana_account_info::AccountInfo<'a>>,
                vesting_strategy: Option<&'b solana_account_info::AccountInfo<'a>>,
                        shares: Option<u64>,
        /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
  __remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}