use borsh::BorshSerialize;
use borsh::BorshDeserialize;
pub const ADD_SUB_ACCOUNT_DISCRIMINATOR: [u8; 8] = [240, 103, 167, 75, 38, 29, 48, 88];
#[derive(Debug)]
pub struct AddSubAccount {
pub main: solana_pubkey::Pubkey,
pub lst_controller: solana_pubkey::Pubkey,
pub admin_permissions: solana_pubkey::Pubkey,
pub admin: solana_pubkey::Pubkey,
pub drift: solana_pubkey::Pubkey,
pub state: solana_pubkey::Pubkey,
pub user_stats: solana_pubkey::Pubkey,
pub user_account: solana_pubkey::Pubkey,
pub rent: solana_pubkey::Pubkey,
pub system_program: solana_pubkey::Pubkey,
}
impl AddSubAccount {
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(10+ remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
self.main,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.lst_controller,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.admin_permissions,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.admin,
true
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.drift,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.state,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.user_stats,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.user_account,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.rent,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.system_program,
false
));
accounts.extend_from_slice(remaining_accounts);
let data = AddSubAccountInstructionData::new().try_to_vec().unwrap();
solana_instruction::Instruction {
program_id: crate::REFLECT_MAIN_ID,
accounts,
data,
}
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AddSubAccountInstructionData {
discriminator: [u8; 8],
}
impl AddSubAccountInstructionData {
pub fn new() -> Self {
Self {
discriminator: [240, 103, 167, 75, 38, 29, 48, 88],
}
}
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
borsh::to_vec(self)
}
}
impl Default for AddSubAccountInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, Debug, Default)]
pub struct AddSubAccountBuilder {
main: Option<solana_pubkey::Pubkey>,
lst_controller: Option<solana_pubkey::Pubkey>,
admin_permissions: Option<solana_pubkey::Pubkey>,
admin: Option<solana_pubkey::Pubkey>,
drift: Option<solana_pubkey::Pubkey>,
state: Option<solana_pubkey::Pubkey>,
user_stats: Option<solana_pubkey::Pubkey>,
user_account: Option<solana_pubkey::Pubkey>,
rent: Option<solana_pubkey::Pubkey>,
system_program: Option<solana_pubkey::Pubkey>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl AddSubAccountBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn main(&mut self, main: solana_pubkey::Pubkey) -> &mut Self {
self.main = Some(main);
self
}
#[inline(always)]
pub fn lst_controller(&mut self, lst_controller: solana_pubkey::Pubkey) -> &mut Self {
self.lst_controller = Some(lst_controller);
self
}
#[inline(always)]
pub fn admin_permissions(&mut self, admin_permissions: solana_pubkey::Pubkey) -> &mut Self {
self.admin_permissions = Some(admin_permissions);
self
}
#[inline(always)]
pub fn admin(&mut self, admin: solana_pubkey::Pubkey) -> &mut Self {
self.admin = Some(admin);
self
}
#[inline(always)]
pub fn drift(&mut self, drift: solana_pubkey::Pubkey) -> &mut Self {
self.drift = Some(drift);
self
}
#[inline(always)]
pub fn state(&mut self, state: solana_pubkey::Pubkey) -> &mut Self {
self.state = Some(state);
self
}
#[inline(always)]
pub fn user_stats(&mut self, user_stats: solana_pubkey::Pubkey) -> &mut Self {
self.user_stats = Some(user_stats);
self
}
#[inline(always)]
pub fn user_account(&mut self, user_account: solana_pubkey::Pubkey) -> &mut Self {
self.user_account = Some(user_account);
self
}
#[inline(always)]
pub fn rent(&mut self, rent: solana_pubkey::Pubkey) -> &mut Self {
self.rent = Some(rent);
self
}
#[inline(always)]
pub fn system_program(&mut self, system_program: solana_pubkey::Pubkey) -> &mut Self {
self.system_program = Some(system_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 = AddSubAccount {
main: self.main.expect("main is not set"),
lst_controller: self.lst_controller.expect("lst_controller is not set"),
admin_permissions: self.admin_permissions.expect("admin_permissions is not set"),
admin: self.admin.expect("admin is not set"),
drift: self.drift.expect("drift is not set"),
state: self.state.expect("state is not set"),
user_stats: self.user_stats.expect("user_stats is not set"),
user_account: self.user_account.expect("user_account is not set"),
rent: self.rent.unwrap_or(solana_pubkey::pubkey!("SysvarRent111111111111111111111111111111111")),
system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
};
accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
}
}
pub struct AddSubAccountCpiAccounts<'a, 'b> {
pub main: &'b solana_account_info::AccountInfo<'a>,
pub lst_controller: &'b solana_account_info::AccountInfo<'a>,
pub admin_permissions: &'b solana_account_info::AccountInfo<'a>,
pub admin: &'b solana_account_info::AccountInfo<'a>,
pub drift: &'b solana_account_info::AccountInfo<'a>,
pub state: &'b solana_account_info::AccountInfo<'a>,
pub user_stats: &'b solana_account_info::AccountInfo<'a>,
pub user_account: &'b solana_account_info::AccountInfo<'a>,
pub rent: &'b solana_account_info::AccountInfo<'a>,
pub system_program: &'b solana_account_info::AccountInfo<'a>,
}
pub struct AddSubAccountCpi<'a, 'b> {
pub __program: &'b solana_account_info::AccountInfo<'a>,
pub main: &'b solana_account_info::AccountInfo<'a>,
pub lst_controller: &'b solana_account_info::AccountInfo<'a>,
pub admin_permissions: &'b solana_account_info::AccountInfo<'a>,
pub admin: &'b solana_account_info::AccountInfo<'a>,
pub drift: &'b solana_account_info::AccountInfo<'a>,
pub state: &'b solana_account_info::AccountInfo<'a>,
pub user_stats: &'b solana_account_info::AccountInfo<'a>,
pub user_account: &'b solana_account_info::AccountInfo<'a>,
pub rent: &'b solana_account_info::AccountInfo<'a>,
pub system_program: &'b solana_account_info::AccountInfo<'a>,
}
impl<'a, 'b> AddSubAccountCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: AddSubAccountCpiAccounts<'a, 'b>,
) -> Self {
Self {
__program: program,
main: accounts.main,
lst_controller: accounts.lst_controller,
admin_permissions: accounts.admin_permissions,
admin: accounts.admin,
drift: accounts.drift,
state: accounts.state,
user_stats: accounts.user_stats,
user_account: accounts.user_account,
rent: accounts.rent,
system_program: accounts.system_program,
}
}
#[inline(always)]
pub fn invoke(&self) -> solana_program_error::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_error::ProgramResult {
self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
}
#[inline(always)]
pub fn invoke_signed(&self, signers_seeds: &[&[&[u8]]]) -> solana_program_error::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_error::ProgramResult {
let mut accounts = Vec::with_capacity(10+ remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
*self.main.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.lst_controller.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.admin_permissions.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.admin.key,
true
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.drift.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.state.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.user_stats.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.user_account.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.rent.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_signer: remaining_account.1,
is_writable: remaining_account.2,
})
});
let data = AddSubAccountInstructionData::new().try_to_vec().unwrap();
let instruction = solana_instruction::Instruction {
program_id: crate::REFLECT_MAIN_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(11 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.main.clone());
account_infos.push(self.lst_controller.clone());
account_infos.push(self.admin_permissions.clone());
account_infos.push(self.admin.clone());
account_infos.push(self.drift.clone());
account_infos.push(self.state.clone());
account_infos.push(self.user_stats.clone());
account_infos.push(self.user_account.clone());
account_infos.push(self.rent.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_cpi::invoke(&instruction, &account_infos)
} else {
solana_cpi::invoke_signed(&instruction, &account_infos, signers_seeds)
}
}
}
#[derive(Clone, Debug)]
pub struct AddSubAccountCpiBuilder<'a, 'b> {
instruction: Box<AddSubAccountCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> AddSubAccountCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(AddSubAccountCpiBuilderInstruction {
__program: program,
main: None,
lst_controller: None,
admin_permissions: None,
admin: None,
drift: None,
state: None,
user_stats: None,
user_account: None,
rent: None,
system_program: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn main(&mut self, main: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.main = Some(main);
self
}
#[inline(always)]
pub fn lst_controller(&mut self, lst_controller: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.lst_controller = Some(lst_controller);
self
}
#[inline(always)]
pub fn admin_permissions(&mut self, admin_permissions: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.admin_permissions = Some(admin_permissions);
self
}
#[inline(always)]
pub fn admin(&mut self, admin: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.admin = Some(admin);
self
}
#[inline(always)]
pub fn drift(&mut self, drift: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.drift = Some(drift);
self
}
#[inline(always)]
pub fn state(&mut self, state: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.state = Some(state);
self
}
#[inline(always)]
pub fn user_stats(&mut self, user_stats: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.user_stats = Some(user_stats);
self
}
#[inline(always)]
pub fn user_account(&mut self, user_account: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.user_account = Some(user_account);
self
}
#[inline(always)]
pub fn rent(&mut self, rent: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.rent = Some(rent);
self
}
#[inline(always)]
pub fn system_program(&mut self, system_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.system_program = Some(system_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_error::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_error::ProgramResult {
let instruction = AddSubAccountCpi {
__program: self.instruction.__program,
main: self.instruction.main.expect("main is not set"),
lst_controller: self.instruction.lst_controller.expect("lst_controller is not set"),
admin_permissions: self.instruction.admin_permissions.expect("admin_permissions is not set"),
admin: self.instruction.admin.expect("admin is not set"),
drift: self.instruction.drift.expect("drift is not set"),
state: self.instruction.state.expect("state is not set"),
user_stats: self.instruction.user_stats.expect("user_stats is not set"),
user_account: self.instruction.user_account.expect("user_account is not set"),
rent: self.instruction.rent.expect("rent is not set"),
system_program: self.instruction.system_program.expect("system_program is not set"),
};
instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
}
}
#[derive(Clone, Debug)]
struct AddSubAccountCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_account_info::AccountInfo<'a>,
main: Option<&'b solana_account_info::AccountInfo<'a>>,
lst_controller: Option<&'b solana_account_info::AccountInfo<'a>>,
admin_permissions: Option<&'b solana_account_info::AccountInfo<'a>>,
admin: Option<&'b solana_account_info::AccountInfo<'a>>,
drift: Option<&'b solana_account_info::AccountInfo<'a>>,
state: Option<&'b solana_account_info::AccountInfo<'a>>,
user_stats: Option<&'b solana_account_info::AccountInfo<'a>>,
user_account: Option<&'b solana_account_info::AccountInfo<'a>>,
rent: Option<&'b solana_account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}