#![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 STAKE_DISCRIMINATOR: [u8; 8] =
[206, 176, 202, 18, 200, 209, 179, 108];
#[derive(Debug)]
pub struct Stake {
pub user: solana_address::Address,
pub payer: solana_address::Address,
pub staking_mint: solana_address::Address,
pub global_config: solana_address::Address,
pub staking_config: solana_address::Address,
pub user_stake_position: solana_address::Address,
pub user_token_account: solana_address::Address,
pub pool_vault: solana_address::Address,
pub token_program: solana_address::Address,
pub associated_token_program: solana_address::Address,
pub system_program: solana_address::Address,
pub event_authority: solana_address::Address,
pub program: solana_address::Address,
}
impl Stake {
pub fn instruction(
&self,
args: StakeInstructionArgs,
) -> 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: StakeInstructionArgs,
remaining_accounts: &[solana_instruction::AccountMeta],
) -> solana_instruction::Instruction {
let mut accounts = Vec::with_capacity(13 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.user, true,
));
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.global_config,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.staking_config,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.user_stake_position,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.user_token_account,
false,
));
accounts
.push(solana_instruction::AccountMeta::new(self.pool_vault, false));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.token_program,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.associated_token_program,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.system_program,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.event_authority,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.program,
false,
));
accounts.extend_from_slice(remaining_accounts);
let mut data = StakeInstructionData::new().try_to_vec().unwrap();
let mut args = args.try_to_vec().unwrap();
data.append(&mut args);
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 StakeInstructionData {
discriminator: [u8; 8],
}
impl StakeInstructionData {
pub fn new() -> Self {
Self {
discriminator: [206, 176, 202, 18, 200, 209, 179, 108],
}
}
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
borsh::to_vec(self)
}
}
impl Default for StakeInstructionData {
fn default() -> Self {
Self::new()
}
}
#[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 StakeInstructionArgs {
pub amount: u64,
}
impl StakeInstructionArgs {
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
borsh::to_vec(self)
}
}
#[derive(Clone, Debug)]
pub struct StakeBuilder {
user: solana_address::Address,
payer: solana_address::Address,
staking_mint: solana_address::Address,
staking_config: Option<solana_address::Address>,
user_stake_position: Option<solana_address::Address>,
user_token_account: Option<solana_address::Address>,
pool_vault: Option<solana_address::Address>,
amount: u64,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl StakeBuilder {
pub fn new(
user: solana_address::Address,
payer: solana_address::Address,
staking_mint: solana_address::Address,
amount: u64,
) -> Self {
Self {
user,
payer,
staking_mint,
staking_config: None,
user_stake_position: None,
user_token_account: None,
pool_vault: None,
amount,
__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 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_token_account(
&mut self,
user_token_account: solana_address::Address,
) -> &mut Self {
self.user_token_account = Some(user_token_account);
self
}
#[inline(always)]
pub fn pool_vault(
&mut self,
pool_vault: solana_address::Address,
) -> &mut Self {
self.pool_vault = Some(pool_vault);
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 global_config =
crate::nexus::generated::pdas::GLOBAL_CONFIG_ADDRESS;
let staking_config = self
.staking_config
.unwrap_or(crate::nexus::generated::pdas::STAKING_CONFIG_ADDRESS);
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_token_account = self.user_token_account.unwrap_or_else(|| {
solana_address::Address::find_program_address(
&[
self.user.as_ref(),
&[
6, 221, 246, 225, 238, 117, 143, 222, 24, 66, 93, 188,
228, 108, 205, 218, 182, 26, 252, 77, 131, 185, 13, 39,
254, 189, 249, 40, 216, 161, 139, 252,
],
self.staking_mint.as_ref(),
],
&solana_address::address!(
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
),
)
.0
});
let pool_vault = self.pool_vault.unwrap_or_else(|| {
solana_address::Address::find_program_address(
&[
staking_config.as_ref(),
&[
6, 221, 246, 225, 238, 117, 143, 222, 24, 66, 93, 188,
228, 108, 205, 218, 182, 26, 252, 77, 131, 185, 13, 39,
254, 189, 249, 40, 216, 161, 139, 252,
],
self.staking_mint.as_ref(),
],
&solana_address::address!(
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
),
)
.0
});
let token_program = solana_address::address!(
"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
);
let associated_token_program = solana_address::address!(
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
);
let system_program =
solana_address::address!("11111111111111111111111111111111");
let event_authority =
crate::nexus::generated::pdas::EVENT_AUTHORITY_ADDRESS;
let program = solana_address::address!(
"7rrCurqdWFesbzwtYPo95fM8waTtVXgXwCom45x1sfNX"
);
let accounts = Stake {
user,
payer,
staking_mint,
global_config,
staking_config,
user_stake_position,
user_token_account,
pool_vault,
token_program,
associated_token_program,
system_program,
event_authority,
program,
};
let args = StakeInstructionArgs {
amount: self.amount.clone(),
};
accounts.instruction_with_remaining_accounts(
args,
&self.__remaining_accounts,
)
}
}
pub struct StakeCpiAccounts<'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 global_config: &'b solana_program::account_info::AccountInfo<'a>,
pub staking_config: &'b solana_program::account_info::AccountInfo<'a>,
pub user_stake_position: &'b solana_program::account_info::AccountInfo<'a>,
pub user_token_account: &'b solana_program::account_info::AccountInfo<'a>,
pub pool_vault: &'b solana_program::account_info::AccountInfo<'a>,
pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
pub associated_token_program:
&'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
pub event_authority: &'b solana_program::account_info::AccountInfo<'a>,
pub program: &'b solana_program::account_info::AccountInfo<'a>,
}
pub struct StakeCpi<'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 global_config: &'b solana_program::account_info::AccountInfo<'a>,
pub staking_config: &'b solana_program::account_info::AccountInfo<'a>,
pub user_stake_position: &'b solana_program::account_info::AccountInfo<'a>,
pub user_token_account: &'b solana_program::account_info::AccountInfo<'a>,
pub pool_vault: &'b solana_program::account_info::AccountInfo<'a>,
pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
pub associated_token_program:
&'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
pub event_authority: &'b solana_program::account_info::AccountInfo<'a>,
pub program: &'b solana_program::account_info::AccountInfo<'a>,
pub __args: StakeInstructionArgs,
}
impl<'a, 'b> StakeCpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: StakeCpiAccounts<'a, 'b>,
args: StakeInstructionArgs,
) -> Self {
Self {
__program: program,
user: accounts.user,
payer: accounts.payer,
staking_mint: accounts.staking_mint,
global_config: accounts.global_config,
staking_config: accounts.staking_config,
user_stake_position: accounts.user_stake_position,
user_token_account: accounts.user_token_account,
pool_vault: accounts.pool_vault,
token_program: accounts.token_program,
associated_token_program: accounts.associated_token_program,
system_program: accounts.system_program,
event_authority: accounts.event_authority,
program: accounts.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(13 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.user.key,
true,
));
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.global_config.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.staking_config.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.user_stake_position.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.user_token_account.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.pool_vault.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.token_program.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.associated_token_program.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.system_program.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.event_authority.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.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 mut data = StakeInstructionData::new().try_to_vec().unwrap();
let mut args = self.__args.try_to_vec().unwrap();
data.append(&mut args);
let instruction = solana_instruction::Instruction {
program_id: crate::nexus::generated::SEND_NEXUS_ID,
accounts,
data,
};
let mut account_infos =
Vec::with_capacity(14 + 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.global_config.clone());
account_infos.push(self.staking_config.clone());
account_infos.push(self.user_stake_position.clone());
account_infos.push(self.user_token_account.clone());
account_infos.push(self.pool_vault.clone());
account_infos.push(self.token_program.clone());
account_infos.push(self.associated_token_program.clone());
account_infos.push(self.system_program.clone());
account_infos.push(self.event_authority.clone());
account_infos.push(self.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 StakeCpiBuilder<'a, 'b> {
instruction: Box<StakeCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> StakeCpiBuilder<'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>,
global_config: &'b solana_program::account_info::AccountInfo<'a>,
staking_config: &'b solana_program::account_info::AccountInfo<'a>,
user_stake_position: &'b solana_program::account_info::AccountInfo<'a>,
user_token_account: &'b solana_program::account_info::AccountInfo<'a>,
pool_vault: &'b solana_program::account_info::AccountInfo<'a>,
token_program: &'b solana_program::account_info::AccountInfo<'a>,
associated_token_program: &'b solana_program::account_info::AccountInfo<
'a,
>,
system_program: &'b solana_program::account_info::AccountInfo<'a>,
event_authority: &'b solana_program::account_info::AccountInfo<'a>,
program: &'b solana_program::account_info::AccountInfo<'a>,
amount: u64,
) -> Self {
let instruction = Box::new(StakeCpiBuilderInstruction {
__program,
user,
payer,
staking_mint,
global_config,
staking_config,
user_stake_position,
user_token_account,
pool_vault,
token_program,
associated_token_program,
system_program,
event_authority,
program,
amount,
__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 args = StakeInstructionArgs {
amount: self.instruction.amount.clone(),
};
let instruction = StakeCpi {
__program: self.instruction.__program,
user: self.instruction.user,
payer: self.instruction.payer,
staking_mint: self.instruction.staking_mint,
global_config: self.instruction.global_config,
staking_config: self.instruction.staking_config,
user_stake_position: self.instruction.user_stake_position,
user_token_account: self.instruction.user_token_account,
pool_vault: self.instruction.pool_vault,
token_program: self.instruction.token_program,
associated_token_program: self.instruction.associated_token_program,
system_program: self.instruction.system_program,
event_authority: self.instruction.event_authority,
program: self.instruction.program,
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
#[derive(Clone, Debug)]
struct StakeCpiBuilderInstruction<'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>,
global_config: &'b solana_program::account_info::AccountInfo<'a>,
staking_config: &'b solana_program::account_info::AccountInfo<'a>,
user_stake_position: &'b solana_program::account_info::AccountInfo<'a>,
user_token_account: &'b solana_program::account_info::AccountInfo<'a>,
pool_vault: &'b solana_program::account_info::AccountInfo<'a>,
token_program: &'b solana_program::account_info::AccountInfo<'a>,
associated_token_program: &'b solana_program::account_info::AccountInfo<'a>,
system_program: &'b solana_program::account_info::AccountInfo<'a>,
event_authority: &'b solana_program::account_info::AccountInfo<'a>,
program: &'b solana_program::account_info::AccountInfo<'a>,
amount: u64,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}