#![allow(
clippy::all,
clippy::pedantic,
clippy::nursery,
clippy::expect_used,
clippy::unwrap_used,
clippy::indexing_slicing,
clippy::allow_attributes,
clippy::allow_attributes_without_reason,
clippy::mem_forget,
unfulfilled_lint_expectations,
unexpected_cfgs,
unused_imports
)]
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
pub const CREATE_USER_REWARD_DEBT_DISCRIMINATOR: [u8; 8] =
[155, 124, 113, 190, 252, 235, 113, 155];
#[derive(Debug)]
pub struct CreateUserRewardDebt {
pub user: solana_address::Address,
pub payer: solana_address::Address,
pub staking_mint: solana_address::Address,
pub reward_mint: solana_address::Address,
pub staking_config: solana_address::Address,
pub reward_state: solana_address::Address,
pub user_stake_position: solana_address::Address,
pub user_reward_debt: solana_address::Address,
pub system_program: solana_address::Address,
}
impl CreateUserRewardDebt {
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(9 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.user, false,
));
accounts.push(solana_instruction::AccountMeta::new(self.payer, true));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.staking_mint,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.reward_mint,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.staking_config,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.reward_state,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.user_stake_position,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.user_reward_debt,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.system_program,
false,
));
accounts.extend_from_slice(remaining_accounts);
let data = CreateUserRewardDebtInstructionData::new()
.try_to_vec()
.unwrap();
solana_instruction::Instruction {
program_id: crate::nexus::generated::SEND_NEXUS_ID,
accounts,
data,
}
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
pub struct CreateUserRewardDebtInstructionData {
discriminator: [u8; 8],
}
impl CreateUserRewardDebtInstructionData {
pub fn new() -> Self {
Self {
discriminator: [155, 124, 113, 190, 252, 235, 113, 155],
}
}
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
borsh::to_vec(self)
}
}
impl Default for CreateUserRewardDebtInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, Debug)]
pub struct CreateUserRewardDebtBuilder {
user: solana_address::Address,
payer: solana_address::Address,
staking_mint: solana_address::Address,
reward_mint: solana_address::Address,
staking_config: Option<solana_address::Address>,
reward_state: Option<solana_address::Address>,
user_stake_position: Option<solana_address::Address>,
user_reward_debt: Option<solana_address::Address>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl CreateUserRewardDebtBuilder {
pub fn new(
user: solana_address::Address,
payer: solana_address::Address,
staking_mint: solana_address::Address,
reward_mint: solana_address::Address,
) -> Self {
Self {
user,
payer,
staking_mint,
reward_mint,
staking_config: None,
reward_state: None,
user_stake_position: None,
user_reward_debt: None,
__remaining_accounts: Vec::new(),
}
}
#[inline(always)]
pub fn staking_config(
&mut self,
staking_config: solana_address::Address,
) -> &mut Self {
self.staking_config = Some(staking_config);
self
}
#[inline(always)]
pub fn reward_state(
&mut self,
reward_state: solana_address::Address,
) -> &mut Self {
self.reward_state = Some(reward_state);
self
}
#[inline(always)]
pub fn user_stake_position(
&mut self,
user_stake_position: solana_address::Address,
) -> &mut Self {
self.user_stake_position = Some(user_stake_position);
self
}
#[inline(always)]
pub fn user_reward_debt(
&mut self,
user_reward_debt: solana_address::Address,
) -> &mut Self {
self.user_reward_debt = Some(user_reward_debt);
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 user = self.user;
let payer = self.payer;
let staking_mint = self.staking_mint;
let reward_mint = self.reward_mint;
let staking_config = self
.staking_config
.unwrap_or(crate::nexus::generated::pdas::STAKING_CONFIG_ADDRESS);
let reward_state = self.reward_state.unwrap_or_else(|| {
crate::nexus::generated::pdas::find_reward_state_pda(
&staking_config,
&self.reward_mint,
)
.0
});
let user_stake_position =
self.user_stake_position.unwrap_or_else(|| {
crate::nexus::generated::pdas::find_user_stake_position_pda(
&self.user,
&self.staking_mint,
)
.0
});
let user_reward_debt = self.user_reward_debt.unwrap_or_else(|| {
crate::nexus::generated::pdas::find_user_reward_debt_pda(
&self.user,
&self.staking_mint,
&self.reward_mint,
)
.0
});
let system_program =
solana_address::address!("11111111111111111111111111111111");
let accounts = CreateUserRewardDebt {
user,
payer,
staking_mint,
reward_mint,
staking_config,
reward_state,
user_stake_position,
user_reward_debt,
system_program,
};
accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
}
}
pub struct CreateUserRewardDebtCpiAccounts<'a, 'b> {
pub user: &'b solana_program::account_info::AccountInfo<'a>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub staking_mint: &'b solana_program::account_info::AccountInfo<'a>,
pub reward_mint: &'b solana_program::account_info::AccountInfo<'a>,
pub staking_config: &'b solana_program::account_info::AccountInfo<'a>,
pub reward_state: &'b solana_program::account_info::AccountInfo<'a>,
pub user_stake_position: &'b solana_program::account_info::AccountInfo<'a>,
pub user_reward_debt: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
}
pub struct CreateUserRewardDebtCpi<'a, 'b> {
pub __program: &'b solana_program::account_info::AccountInfo<'a>,
pub user: &'b solana_program::account_info::AccountInfo<'a>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub staking_mint: &'b solana_program::account_info::AccountInfo<'a>,
pub reward_mint: &'b solana_program::account_info::AccountInfo<'a>,
pub staking_config: &'b solana_program::account_info::AccountInfo<'a>,
pub reward_state: &'b solana_program::account_info::AccountInfo<'a>,
pub user_stake_position: &'b solana_program::account_info::AccountInfo<'a>,
pub user_reward_debt: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
}
impl<'a, 'b> CreateUserRewardDebtCpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: CreateUserRewardDebtCpiAccounts<'a, 'b>,
) -> Self {
Self {
__program: program,
user: accounts.user,
payer: accounts.payer,
staking_mint: accounts.staking_mint,
reward_mint: accounts.reward_mint,
staking_config: accounts.staking_config,
reward_state: accounts.reward_state,
user_stake_position: accounts.user_stake_position,
user_reward_debt: accounts.user_reward_debt,
system_program: accounts.system_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_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(9 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.user.key,
false,
));
accounts
.push(solana_instruction::AccountMeta::new(*self.payer.key, true));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.staking_mint.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.reward_mint.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.staking_config.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.reward_state.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.user_stake_position.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.user_reward_debt.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.system_program.key,
false,
));
remaining_accounts.iter().for_each(|remaining_account| {
accounts.push(solana_instruction::AccountMeta {
pubkey: *remaining_account.0.key,
is_writable: remaining_account.1,
is_signer: remaining_account.2,
})
});
let data = CreateUserRewardDebtInstructionData::new()
.try_to_vec()
.unwrap();
let instruction = solana_instruction::Instruction {
program_id: crate::nexus::generated::SEND_NEXUS_ID,
accounts,
data,
};
let mut account_infos =
Vec::with_capacity(10 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.user.clone());
account_infos.push(self.payer.clone());
account_infos.push(self.staking_mint.clone());
account_infos.push(self.reward_mint.clone());
account_infos.push(self.staking_config.clone());
account_infos.push(self.reward_state.clone());
account_infos.push(self.user_stake_position.clone());
account_infos.push(self.user_reward_debt.clone());
account_infos.push(self.system_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,
)
}
}
}
#[derive(Clone, Debug)]
pub struct CreateUserRewardDebtCpiBuilder<'a, 'b> {
instruction: Box<CreateUserRewardDebtCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> CreateUserRewardDebtCpiBuilder<'a, 'b> {
pub fn new(
__program: &'b solana_program::account_info::AccountInfo<'a>,
user: &'b solana_program::account_info::AccountInfo<'a>,
payer: &'b solana_program::account_info::AccountInfo<'a>,
staking_mint: &'b solana_program::account_info::AccountInfo<'a>,
reward_mint: &'b solana_program::account_info::AccountInfo<'a>,
staking_config: &'b solana_program::account_info::AccountInfo<'a>,
reward_state: &'b solana_program::account_info::AccountInfo<'a>,
user_stake_position: &'b solana_program::account_info::AccountInfo<'a>,
user_reward_debt: &'b solana_program::account_info::AccountInfo<'a>,
system_program: &'b solana_program::account_info::AccountInfo<'a>,
) -> Self {
let instruction = Box::new(CreateUserRewardDebtCpiBuilderInstruction {
__program,
user,
payer,
staking_mint,
reward_mint,
staking_config,
reward_state,
user_stake_position,
user_reward_debt,
system_program,
__remaining_accounts: Vec::new(),
});
Self { 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
}
#[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 instruction = CreateUserRewardDebtCpi {
__program: self.instruction.__program,
user: self.instruction.user,
payer: self.instruction.payer,
staking_mint: self.instruction.staking_mint,
reward_mint: self.instruction.reward_mint,
staking_config: self.instruction.staking_config,
reward_state: self.instruction.reward_state,
user_stake_position: self.instruction.user_stake_position,
user_reward_debt: self.instruction.user_reward_debt,
system_program: self.instruction.system_program,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
#[derive(Clone, Debug)]
struct CreateUserRewardDebtCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
user: &'b solana_program::account_info::AccountInfo<'a>,
payer: &'b solana_program::account_info::AccountInfo<'a>,
staking_mint: &'b solana_program::account_info::AccountInfo<'a>,
reward_mint: &'b solana_program::account_info::AccountInfo<'a>,
staking_config: &'b solana_program::account_info::AccountInfo<'a>,
reward_state: &'b solana_program::account_info::AccountInfo<'a>,
user_stake_position: &'b solana_program::account_info::AccountInfo<'a>,
user_reward_debt: &'b solana_program::account_info::AccountInfo<'a>,
system_program: &'b solana_program::account_info::AccountInfo<'a>,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}