use borsh::BorshDeserialize;
use borsh::BorshSerialize;
#[derive(Debug)]
pub struct Prune {
pub market: solana_pubkey::Pubkey,
pub bids: solana_pubkey::Pubkey,
pub asks: solana_pubkey::Pubkey,
pub prune_authority: solana_pubkey::Pubkey,
pub open_orders: solana_pubkey::Pubkey,
pub owner: solana_pubkey::Pubkey,
pub event_queue: solana_pubkey::Pubkey,
}
impl Prune {
pub fn instruction(&self, args: PruneInstructionArgs) -> 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: PruneInstructionArgs,
remaining_accounts: &[solana_instruction::AccountMeta],
) -> solana_instruction::Instruction {
let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(self.market, false));
accounts.push(solana_instruction::AccountMeta::new(self.bids, false));
accounts.push(solana_instruction::AccountMeta::new(self.asks, false));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.prune_authority,
true,
));
accounts.push(solana_instruction::AccountMeta::new(
self.open_orders,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.owner, false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.event_queue,
false,
));
accounts.extend_from_slice(remaining_accounts);
let mut data = borsh::to_vec(&PruneInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&args).unwrap();
data.append(&mut args);
solana_instruction::Instruction {
program_id: crate::OPEN_BOOK_DEX_ID,
accounts,
data,
}
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PruneInstructionData {
discriminator: [u8; 8],
}
impl PruneInstructionData {
pub fn new() -> Self {
Self {
discriminator: [136, 19, 42, 184, 152, 204, 244, 94],
}
}
}
impl Default for PruneInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct PruneInstructionArgs {
pub limit: u16,
}
#[derive(Clone, Debug, Default)]
pub struct PruneBuilder {
market: Option<solana_pubkey::Pubkey>,
bids: Option<solana_pubkey::Pubkey>,
asks: Option<solana_pubkey::Pubkey>,
prune_authority: Option<solana_pubkey::Pubkey>,
open_orders: Option<solana_pubkey::Pubkey>,
owner: Option<solana_pubkey::Pubkey>,
event_queue: Option<solana_pubkey::Pubkey>,
limit: Option<u16>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl PruneBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn market(&mut self, market: solana_pubkey::Pubkey) -> &mut Self {
self.market = Some(market);
self
}
#[inline(always)]
pub fn bids(&mut self, bids: solana_pubkey::Pubkey) -> &mut Self {
self.bids = Some(bids);
self
}
#[inline(always)]
pub fn asks(&mut self, asks: solana_pubkey::Pubkey) -> &mut Self {
self.asks = Some(asks);
self
}
#[inline(always)]
pub fn prune_authority(&mut self, prune_authority: solana_pubkey::Pubkey) -> &mut Self {
self.prune_authority = Some(prune_authority);
self
}
#[inline(always)]
pub fn open_orders(&mut self, open_orders: solana_pubkey::Pubkey) -> &mut Self {
self.open_orders = Some(open_orders);
self
}
#[inline(always)]
pub fn owner(&mut self, owner: solana_pubkey::Pubkey) -> &mut Self {
self.owner = Some(owner);
self
}
#[inline(always)]
pub fn event_queue(&mut self, event_queue: solana_pubkey::Pubkey) -> &mut Self {
self.event_queue = Some(event_queue);
self
}
#[inline(always)]
pub fn limit(&mut self, limit: u16) -> &mut Self {
self.limit = Some(limit);
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 = Prune {
market: self.market.expect("market is not set"),
bids: self.bids.expect("bids is not set"),
asks: self.asks.expect("asks is not set"),
prune_authority: self.prune_authority.expect("prune_authority is not set"),
open_orders: self.open_orders.expect("open_orders is not set"),
owner: self.owner.expect("owner is not set"),
event_queue: self.event_queue.expect("event_queue is not set"),
};
let args = PruneInstructionArgs {
limit: self.limit.clone().expect("limit is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct PruneCpiAccounts<'a, 'b> {
pub market: &'b solana_account_info::AccountInfo<'a>,
pub bids: &'b solana_account_info::AccountInfo<'a>,
pub asks: &'b solana_account_info::AccountInfo<'a>,
pub prune_authority: &'b solana_account_info::AccountInfo<'a>,
pub open_orders: &'b solana_account_info::AccountInfo<'a>,
pub owner: &'b solana_account_info::AccountInfo<'a>,
pub event_queue: &'b solana_account_info::AccountInfo<'a>,
}
pub struct PruneCpi<'a, 'b> {
pub __program: &'b solana_account_info::AccountInfo<'a>,
pub market: &'b solana_account_info::AccountInfo<'a>,
pub bids: &'b solana_account_info::AccountInfo<'a>,
pub asks: &'b solana_account_info::AccountInfo<'a>,
pub prune_authority: &'b solana_account_info::AccountInfo<'a>,
pub open_orders: &'b solana_account_info::AccountInfo<'a>,
pub owner: &'b solana_account_info::AccountInfo<'a>,
pub event_queue: &'b solana_account_info::AccountInfo<'a>,
pub __args: PruneInstructionArgs,
}
impl<'a, 'b> PruneCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: PruneCpiAccounts<'a, 'b>,
args: PruneInstructionArgs,
) -> Self {
Self {
__program: program,
market: accounts.market,
bids: accounts.bids,
asks: accounts.asks,
prune_authority: accounts.prune_authority,
open_orders: accounts.open_orders,
owner: accounts.owner,
event_queue: accounts.event_queue,
__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_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(7 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
*self.market.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(*self.bids.key, false));
accounts.push(solana_instruction::AccountMeta::new(*self.asks.key, false));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.prune_authority.key,
true,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.open_orders.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.owner.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.event_queue.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 = borsh::to_vec(&PruneInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&self.__args).unwrap();
data.append(&mut args);
let instruction = solana_instruction::Instruction {
program_id: crate::OPEN_BOOK_DEX_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(8 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.market.clone());
account_infos.push(self.bids.clone());
account_infos.push(self.asks.clone());
account_infos.push(self.prune_authority.clone());
account_infos.push(self.open_orders.clone());
account_infos.push(self.owner.clone());
account_infos.push(self.event_queue.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 PruneCpiBuilder<'a, 'b> {
instruction: Box<PruneCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> PruneCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(PruneCpiBuilderInstruction {
__program: program,
market: None,
bids: None,
asks: None,
prune_authority: None,
open_orders: None,
owner: None,
event_queue: None,
limit: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn market(&mut self, market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.market = Some(market);
self
}
#[inline(always)]
pub fn bids(&mut self, bids: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.bids = Some(bids);
self
}
#[inline(always)]
pub fn asks(&mut self, asks: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.asks = Some(asks);
self
}
#[inline(always)]
pub fn prune_authority(
&mut self,
prune_authority: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.prune_authority = Some(prune_authority);
self
}
#[inline(always)]
pub fn open_orders(
&mut self,
open_orders: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.open_orders = Some(open_orders);
self
}
#[inline(always)]
pub fn owner(&mut self, owner: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.owner = Some(owner);
self
}
#[inline(always)]
pub fn event_queue(
&mut self,
event_queue: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.event_queue = Some(event_queue);
self
}
#[inline(always)]
pub fn limit(&mut self, limit: u16) -> &mut Self {
self.instruction.limit = Some(limit);
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 args = PruneInstructionArgs {
limit: self.instruction.limit.clone().expect("limit is not set"),
};
let instruction = PruneCpi {
__program: self.instruction.__program,
market: self.instruction.market.expect("market is not set"),
bids: self.instruction.bids.expect("bids is not set"),
asks: self.instruction.asks.expect("asks is not set"),
prune_authority: self
.instruction
.prune_authority
.expect("prune_authority is not set"),
open_orders: self
.instruction
.open_orders
.expect("open_orders is not set"),
owner: self.instruction.owner.expect("owner is not set"),
event_queue: self
.instruction
.event_queue
.expect("event_queue is not set"),
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
#[derive(Clone, Debug)]
struct PruneCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_account_info::AccountInfo<'a>,
market: Option<&'b solana_account_info::AccountInfo<'a>>,
bids: Option<&'b solana_account_info::AccountInfo<'a>>,
asks: Option<&'b solana_account_info::AccountInfo<'a>>,
prune_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
open_orders: Option<&'b solana_account_info::AccountInfo<'a>>,
owner: Option<&'b solana_account_info::AccountInfo<'a>>,
event_queue: Option<&'b solana_account_info::AccountInfo<'a>>,
limit: Option<u16>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}