use borsh::BorshSerialize;
use borsh::BorshDeserialize;
#[derive(Debug)]
pub struct SwapRewardOrca {
pub authority: solana_pubkey::Pubkey,
pub treasury: solana_pubkey::Pubkey,
pub input_token_mint: solana_pubkey::Pubkey,
pub reward_token_mint: solana_pubkey::Pubkey,
pub input_token_program: solana_pubkey::Pubkey,
pub reward_token_program: solana_pubkey::Pubkey,
pub input_token_account: solana_pubkey::Pubkey,
pub reward_token_account: solana_pubkey::Pubkey,
pub whirlpool_program: solana_pubkey::Pubkey,
pub whirlpool: solana_pubkey::Pubkey,
pub memo_program: solana_pubkey::Pubkey,
}
impl SwapRewardOrca {
pub fn instruction(&self) -> solana_instruction::Instruction {
self.instruction_with_remaining_accounts(&[])
}
#[allow(clippy::arithmetic_side_effects)]
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(&self, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
let mut accounts = Vec::with_capacity(11+ 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_readonly(
self.input_token_mint,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.reward_token_mint,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.input_token_program,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.reward_token_program,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.input_token_account,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.reward_token_account,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.whirlpool_program,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.whirlpool,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.memo_program,
false
));
accounts.extend_from_slice(remaining_accounts);
let data = borsh::to_vec(&SwapRewardOrcaInstructionData::new()).unwrap();
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 SwapRewardOrcaInstructionData {
discriminator: [u8; 8],
}
impl SwapRewardOrcaInstructionData {
pub fn new() -> Self {
Self {
discriminator: [43, 202, 126, 117, 222, 128, 208, 163],
}
}
}
impl Default for SwapRewardOrcaInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, Debug, Default)]
pub struct SwapRewardOrcaBuilder {
authority: Option<solana_pubkey::Pubkey>,
treasury: Option<solana_pubkey::Pubkey>,
input_token_mint: Option<solana_pubkey::Pubkey>,
reward_token_mint: Option<solana_pubkey::Pubkey>,
input_token_program: Option<solana_pubkey::Pubkey>,
reward_token_program: Option<solana_pubkey::Pubkey>,
input_token_account: Option<solana_pubkey::Pubkey>,
reward_token_account: Option<solana_pubkey::Pubkey>,
whirlpool_program: Option<solana_pubkey::Pubkey>,
whirlpool: Option<solana_pubkey::Pubkey>,
memo_program: Option<solana_pubkey::Pubkey>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl SwapRewardOrcaBuilder {
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 input_token_mint(&mut self, input_token_mint: solana_pubkey::Pubkey) -> &mut Self {
self.input_token_mint = Some(input_token_mint);
self
}
#[inline(always)]
pub fn reward_token_mint(&mut self, reward_token_mint: solana_pubkey::Pubkey) -> &mut Self {
self.reward_token_mint = Some(reward_token_mint);
self
}
#[inline(always)]
pub fn input_token_program(&mut self, input_token_program: solana_pubkey::Pubkey) -> &mut Self {
self.input_token_program = Some(input_token_program);
self
}
#[inline(always)]
pub fn reward_token_program(&mut self, reward_token_program: solana_pubkey::Pubkey) -> &mut Self {
self.reward_token_program = Some(reward_token_program);
self
}
#[inline(always)]
pub fn input_token_account(&mut self, input_token_account: solana_pubkey::Pubkey) -> &mut Self {
self.input_token_account = Some(input_token_account);
self
}
#[inline(always)]
pub fn reward_token_account(&mut self, reward_token_account: solana_pubkey::Pubkey) -> &mut Self {
self.reward_token_account = Some(reward_token_account);
self
}
#[inline(always)]
pub fn whirlpool_program(&mut self, whirlpool_program: solana_pubkey::Pubkey) -> &mut Self {
self.whirlpool_program = Some(whirlpool_program);
self
}
#[inline(always)]
pub fn whirlpool(&mut self, whirlpool: solana_pubkey::Pubkey) -> &mut Self {
self.whirlpool = Some(whirlpool);
self
}
#[inline(always)]
pub fn memo_program(&mut self, memo_program: solana_pubkey::Pubkey) -> &mut Self {
self.memo_program = Some(memo_program);
self
}
#[inline(always)]
pub fn add_remaining_account(&mut self, account: solana_instruction::AccountMeta) -> &mut Self {
self.__remaining_accounts.push(account);
self
}
#[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 = SwapRewardOrca {
authority: self.authority.expect("authority is not set"),
treasury: self.treasury.expect("treasury is not set"),
input_token_mint: self.input_token_mint.expect("input_token_mint is not set"),
reward_token_mint: self.reward_token_mint.expect("reward_token_mint is not set"),
input_token_program: self.input_token_program.expect("input_token_program is not set"),
reward_token_program: self.reward_token_program.expect("reward_token_program is not set"),
input_token_account: self.input_token_account.expect("input_token_account is not set"),
reward_token_account: self.reward_token_account.expect("reward_token_account is not set"),
whirlpool_program: self.whirlpool_program.expect("whirlpool_program is not set"),
whirlpool: self.whirlpool.expect("whirlpool is not set"),
memo_program: self.memo_program.expect("memo_program is not set"),
};
accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
}
}
pub struct SwapRewardOrcaCpiAccounts<'a, 'b> {
pub authority: &'b solana_account_info::AccountInfo<'a>,
pub treasury: &'b solana_account_info::AccountInfo<'a>,
pub input_token_mint: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_mint: &'b solana_account_info::AccountInfo<'a>,
pub input_token_program: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_program: &'b solana_account_info::AccountInfo<'a>,
pub input_token_account: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_account: &'b solana_account_info::AccountInfo<'a>,
pub whirlpool_program: &'b solana_account_info::AccountInfo<'a>,
pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
pub memo_program: &'b solana_account_info::AccountInfo<'a>,
}
pub struct SwapRewardOrcaCpi<'a, 'b> {
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 input_token_mint: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_mint: &'b solana_account_info::AccountInfo<'a>,
pub input_token_program: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_program: &'b solana_account_info::AccountInfo<'a>,
pub input_token_account: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_account: &'b solana_account_info::AccountInfo<'a>,
pub whirlpool_program: &'b solana_account_info::AccountInfo<'a>,
pub whirlpool: &'b solana_account_info::AccountInfo<'a>,
pub memo_program: &'b solana_account_info::AccountInfo<'a>,
}
impl<'a, 'b> SwapRewardOrcaCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: SwapRewardOrcaCpiAccounts<'a, 'b>,
) -> Self {
Self {
__program: program,
authority: accounts.authority,
treasury: accounts.treasury,
input_token_mint: accounts.input_token_mint,
reward_token_mint: accounts.reward_token_mint,
input_token_program: accounts.input_token_program,
reward_token_program: accounts.reward_token_program,
input_token_account: accounts.input_token_account,
reward_token_account: accounts.reward_token_account,
whirlpool_program: accounts.whirlpool_program,
whirlpool: accounts.whirlpool,
memo_program: accounts.memo_program,
}
}
#[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(11+ 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_readonly(
*self.input_token_mint.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.reward_token_mint.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.input_token_program.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.reward_token_program.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.input_token_account.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.reward_token_account.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.whirlpool_program.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.whirlpool.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.memo_program.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 data = borsh::to_vec(&SwapRewardOrcaInstructionData::new()).unwrap();
let instruction = solana_instruction::Instruction {
program_id: crate::TUNA_STAKING_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(12 + 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.input_token_mint.clone());
account_infos.push(self.reward_token_mint.clone());
account_infos.push(self.input_token_program.clone());
account_infos.push(self.reward_token_program.clone());
account_infos.push(self.input_token_account.clone());
account_infos.push(self.reward_token_account.clone());
account_infos.push(self.whirlpool_program.clone());
account_infos.push(self.whirlpool.clone());
account_infos.push(self.memo_program.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)
}
}
}
#[derive(Clone, Debug)]
pub struct SwapRewardOrcaCpiBuilder<'a, 'b> {
instruction: Box<SwapRewardOrcaCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> SwapRewardOrcaCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(SwapRewardOrcaCpiBuilderInstruction {
__program: program,
authority: None,
treasury: None,
input_token_mint: None,
reward_token_mint: None,
input_token_program: None,
reward_token_program: None,
input_token_account: None,
reward_token_account: None,
whirlpool_program: None,
whirlpool: None,
memo_program: 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 input_token_mint(&mut self, input_token_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.input_token_mint = Some(input_token_mint);
self
}
#[inline(always)]
pub fn reward_token_mint(&mut self, reward_token_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.reward_token_mint = Some(reward_token_mint);
self
}
#[inline(always)]
pub fn input_token_program(&mut self, input_token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.input_token_program = Some(input_token_program);
self
}
#[inline(always)]
pub fn reward_token_program(&mut self, reward_token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.reward_token_program = Some(reward_token_program);
self
}
#[inline(always)]
pub fn input_token_account(&mut self, input_token_account: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.input_token_account = Some(input_token_account);
self
}
#[inline(always)]
pub fn reward_token_account(&mut self, reward_token_account: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.reward_token_account = Some(reward_token_account);
self
}
#[inline(always)]
pub fn whirlpool_program(&mut self, whirlpool_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.whirlpool_program = Some(whirlpool_program);
self
}
#[inline(always)]
pub fn whirlpool(&mut self, whirlpool: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.whirlpool = Some(whirlpool);
self
}
#[inline(always)]
pub fn memo_program(&mut self, memo_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.memo_program = Some(memo_program);
self
}
#[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
}
#[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 instruction = SwapRewardOrcaCpi {
__program: self.instruction.__program,
authority: self.instruction.authority.expect("authority is not set"),
treasury: self.instruction.treasury.expect("treasury is not set"),
input_token_mint: self.instruction.input_token_mint.expect("input_token_mint is not set"),
reward_token_mint: self.instruction.reward_token_mint.expect("reward_token_mint is not set"),
input_token_program: self.instruction.input_token_program.expect("input_token_program is not set"),
reward_token_program: self.instruction.reward_token_program.expect("reward_token_program is not set"),
input_token_account: self.instruction.input_token_account.expect("input_token_account is not set"),
reward_token_account: self.instruction.reward_token_account.expect("reward_token_account is not set"),
whirlpool_program: self.instruction.whirlpool_program.expect("whirlpool_program is not set"),
whirlpool: self.instruction.whirlpool.expect("whirlpool is not set"),
memo_program: self.instruction.memo_program.expect("memo_program is not set"),
};
instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
}
}
#[derive(Clone, Debug)]
struct SwapRewardOrcaCpiBuilderInstruction<'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>>,
input_token_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
reward_token_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
input_token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
reward_token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
input_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
reward_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
whirlpool_program: Option<&'b solana_account_info::AccountInfo<'a>>,
whirlpool: Option<&'b solana_account_info::AccountInfo<'a>>,
memo_program: Option<&'b solana_account_info::AccountInfo<'a>>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}