use borsh::BorshSerialize;
use borsh::BorshDeserialize;
pub const DEPOSIT_DRIFT_DISCRIMINATOR: [u8; 8] = [18, 70, 190, 154, 86, 199, 132, 143];
#[derive(Debug)]
pub struct DepositDrift {
pub main: solana_pubkey::Pubkey,
pub controller: solana_pubkey::Pubkey,
pub depositor: 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 spot_market_vault: solana_pubkey::Pubkey,
pub controller_token_account: solana_pubkey::Pubkey,
pub depositor_token_account: solana_pubkey::Pubkey,
pub oracle: solana_pubkey::Pubkey,
pub spot_market: solana_pubkey::Pubkey,
pub token_program: solana_pubkey::Pubkey,
}
impl DepositDrift {
pub fn instruction(&self, args: DepositDriftInstructionArgs) -> 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: DepositDriftInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
let mut accounts = Vec::with_capacity(13+ remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
self.main,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.controller,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.depositor,
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(
self.spot_market_vault,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.controller_token_account,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.depositor_token_account,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.oracle,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.spot_market,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.token_program,
false
));
accounts.extend_from_slice(remaining_accounts);
let mut data = DepositDriftInstructionData::new().try_to_vec().unwrap();
let mut args = args.try_to_vec().unwrap();
data.append(&mut args);
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 DepositDriftInstructionData {
discriminator: [u8; 8],
}
impl DepositDriftInstructionData {
pub fn new() -> Self {
Self {
discriminator: [18, 70, 190, 154, 86, 199, 132, 143],
}
}
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
borsh::to_vec(self)
}
}
impl Default for DepositDriftInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DepositDriftInstructionArgs {
pub controller_bump: u8,
pub controller_index: u8,
pub amount: u64,
}
impl DepositDriftInstructionArgs {
pub(crate) fn try_to_vec(&self) -> Result<Vec<u8>, std::io::Error> {
borsh::to_vec(self)
}
}
#[derive(Clone, Debug, Default)]
pub struct DepositDriftBuilder {
main: Option<solana_pubkey::Pubkey>,
controller: Option<solana_pubkey::Pubkey>,
depositor: 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>,
spot_market_vault: Option<solana_pubkey::Pubkey>,
controller_token_account: Option<solana_pubkey::Pubkey>,
depositor_token_account: Option<solana_pubkey::Pubkey>,
oracle: Option<solana_pubkey::Pubkey>,
spot_market: Option<solana_pubkey::Pubkey>,
token_program: Option<solana_pubkey::Pubkey>,
controller_bump: Option<u8>,
controller_index: Option<u8>,
amount: Option<u64>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl DepositDriftBuilder {
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 controller(&mut self, controller: solana_pubkey::Pubkey) -> &mut Self {
self.controller = Some(controller);
self
}
#[inline(always)]
pub fn depositor(&mut self, depositor: solana_pubkey::Pubkey) -> &mut Self {
self.depositor = Some(depositor);
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 spot_market_vault(&mut self, spot_market_vault: solana_pubkey::Pubkey) -> &mut Self {
self.spot_market_vault = Some(spot_market_vault);
self
}
#[inline(always)]
pub fn controller_token_account(&mut self, controller_token_account: solana_pubkey::Pubkey) -> &mut Self {
self.controller_token_account = Some(controller_token_account);
self
}
#[inline(always)]
pub fn depositor_token_account(&mut self, depositor_token_account: solana_pubkey::Pubkey) -> &mut Self {
self.depositor_token_account = Some(depositor_token_account);
self
}
#[inline(always)]
pub fn oracle(&mut self, oracle: solana_pubkey::Pubkey) -> &mut Self {
self.oracle = Some(oracle);
self
}
#[inline(always)]
pub fn spot_market(&mut self, spot_market: solana_pubkey::Pubkey) -> &mut Self {
self.spot_market = Some(spot_market);
self
}
#[inline(always)]
pub fn token_program(&mut self, token_program: solana_pubkey::Pubkey) -> &mut Self {
self.token_program = Some(token_program);
self
}
#[inline(always)]
pub fn controller_bump(&mut self, controller_bump: u8) -> &mut Self {
self.controller_bump = Some(controller_bump);
self
}
#[inline(always)]
pub fn controller_index(&mut self, controller_index: u8) -> &mut Self {
self.controller_index = Some(controller_index);
self
}
#[inline(always)]
pub fn amount(&mut self, amount: u64) -> &mut Self {
self.amount = Some(amount);
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 = DepositDrift {
main: self.main.expect("main is not set"),
controller: self.controller.expect("controller is not set"),
depositor: self.depositor.expect("depositor 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"),
spot_market_vault: self.spot_market_vault.expect("spot_market_vault is not set"),
controller_token_account: self.controller_token_account.expect("controller_token_account is not set"),
depositor_token_account: self.depositor_token_account.expect("depositor_token_account is not set"),
oracle: self.oracle.expect("oracle is not set"),
spot_market: self.spot_market.expect("spot_market is not set"),
token_program: self.token_program.unwrap_or(solana_pubkey::pubkey!("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")),
};
let args = DepositDriftInstructionArgs {
controller_bump: self.controller_bump.clone().expect("controller_bump is not set"),
controller_index: self.controller_index.clone().expect("controller_index is not set"),
amount: self.amount.clone().expect("amount is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct DepositDriftCpiAccounts<'a, 'b> {
pub main: &'b solana_account_info::AccountInfo<'a>,
pub controller: &'b solana_account_info::AccountInfo<'a>,
pub depositor: &'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 spot_market_vault: &'b solana_account_info::AccountInfo<'a>,
pub controller_token_account: &'b solana_account_info::AccountInfo<'a>,
pub depositor_token_account: &'b solana_account_info::AccountInfo<'a>,
pub oracle: &'b solana_account_info::AccountInfo<'a>,
pub spot_market: &'b solana_account_info::AccountInfo<'a>,
pub token_program: &'b solana_account_info::AccountInfo<'a>,
}
pub struct DepositDriftCpi<'a, 'b> {
pub __program: &'b solana_account_info::AccountInfo<'a>,
pub main: &'b solana_account_info::AccountInfo<'a>,
pub controller: &'b solana_account_info::AccountInfo<'a>,
pub depositor: &'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 spot_market_vault: &'b solana_account_info::AccountInfo<'a>,
pub controller_token_account: &'b solana_account_info::AccountInfo<'a>,
pub depositor_token_account: &'b solana_account_info::AccountInfo<'a>,
pub oracle: &'b solana_account_info::AccountInfo<'a>,
pub spot_market: &'b solana_account_info::AccountInfo<'a>,
pub token_program: &'b solana_account_info::AccountInfo<'a>,
pub __args: DepositDriftInstructionArgs,
}
impl<'a, 'b> DepositDriftCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: DepositDriftCpiAccounts<'a, 'b>,
args: DepositDriftInstructionArgs,
) -> Self {
Self {
__program: program,
main: accounts.main,
controller: accounts.controller,
depositor: accounts.depositor,
drift: accounts.drift,
state: accounts.state,
user_stats: accounts.user_stats,
user_account: accounts.user_account,
spot_market_vault: accounts.spot_market_vault,
controller_token_account: accounts.controller_token_account,
depositor_token_account: accounts.depositor_token_account,
oracle: accounts.oracle,
spot_market: accounts.spot_market,
token_program: accounts.token_program,
__args: args,
}
}
#[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(13+ remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
*self.main.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.controller.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.depositor.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(
*self.spot_market_vault.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.controller_token_account.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.depositor_token_account.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.oracle.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.spot_market.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.token_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 mut data = DepositDriftInstructionData::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::REFLECT_MAIN_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(14 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.main.clone());
account_infos.push(self.controller.clone());
account_infos.push(self.depositor.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.spot_market_vault.clone());
account_infos.push(self.controller_token_account.clone());
account_infos.push(self.depositor_token_account.clone());
account_infos.push(self.oracle.clone());
account_infos.push(self.spot_market.clone());
account_infos.push(self.token_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 DepositDriftCpiBuilder<'a, 'b> {
instruction: Box<DepositDriftCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> DepositDriftCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(DepositDriftCpiBuilderInstruction {
__program: program,
main: None,
controller: None,
depositor: None,
drift: None,
state: None,
user_stats: None,
user_account: None,
spot_market_vault: None,
controller_token_account: None,
depositor_token_account: None,
oracle: None,
spot_market: None,
token_program: None,
controller_bump: None,
controller_index: None,
amount: 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 controller(&mut self, controller: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.controller = Some(controller);
self
}
#[inline(always)]
pub fn depositor(&mut self, depositor: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.depositor = Some(depositor);
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 spot_market_vault(&mut self, spot_market_vault: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.spot_market_vault = Some(spot_market_vault);
self
}
#[inline(always)]
pub fn controller_token_account(&mut self, controller_token_account: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.controller_token_account = Some(controller_token_account);
self
}
#[inline(always)]
pub fn depositor_token_account(&mut self, depositor_token_account: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.depositor_token_account = Some(depositor_token_account);
self
}
#[inline(always)]
pub fn oracle(&mut self, oracle: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.oracle = Some(oracle);
self
}
#[inline(always)]
pub fn spot_market(&mut self, spot_market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.spot_market = Some(spot_market);
self
}
#[inline(always)]
pub fn token_program(&mut self, token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.token_program = Some(token_program);
self
}
#[inline(always)]
pub fn controller_bump(&mut self, controller_bump: u8) -> &mut Self {
self.instruction.controller_bump = Some(controller_bump);
self
}
#[inline(always)]
pub fn controller_index(&mut self, controller_index: u8) -> &mut Self {
self.instruction.controller_index = Some(controller_index);
self
}
#[inline(always)]
pub fn amount(&mut self, amount: u64) -> &mut Self {
self.instruction.amount = Some(amount);
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 args = DepositDriftInstructionArgs {
controller_bump: self.instruction.controller_bump.clone().expect("controller_bump is not set"),
controller_index: self.instruction.controller_index.clone().expect("controller_index is not set"),
amount: self.instruction.amount.clone().expect("amount is not set"),
};
let instruction = DepositDriftCpi {
__program: self.instruction.__program,
main: self.instruction.main.expect("main is not set"),
controller: self.instruction.controller.expect("controller is not set"),
depositor: self.instruction.depositor.expect("depositor 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"),
spot_market_vault: self.instruction.spot_market_vault.expect("spot_market_vault is not set"),
controller_token_account: self.instruction.controller_token_account.expect("controller_token_account is not set"),
depositor_token_account: self.instruction.depositor_token_account.expect("depositor_token_account is not set"),
oracle: self.instruction.oracle.expect("oracle is not set"),
spot_market: self.instruction.spot_market.expect("spot_market is not set"),
token_program: self.instruction.token_program.expect("token_program is not set"),
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
}
}
#[derive(Clone, Debug)]
struct DepositDriftCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_account_info::AccountInfo<'a>,
main: Option<&'b solana_account_info::AccountInfo<'a>>,
controller: Option<&'b solana_account_info::AccountInfo<'a>>,
depositor: 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>>,
spot_market_vault: Option<&'b solana_account_info::AccountInfo<'a>>,
controller_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
depositor_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
oracle: Option<&'b solana_account_info::AccountInfo<'a>>,
spot_market: Option<&'b solana_account_info::AccountInfo<'a>>,
token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
controller_bump: Option<u8>,
controller_index: Option<u8>,
amount: Option<u64>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}