use borsh::BorshDeserialize;
use borsh::BorshSerialize;
#[derive(Debug)]
pub struct ConsumeEvents {
pub open_orders: solana_pubkey::Pubkey,
pub market: solana_pubkey::Pubkey,
pub event_queue: solana_pubkey::Pubkey,
pub coin_fee_receivable: solana_pubkey::Pubkey,
pub pc_fee_receivable: solana_pubkey::Pubkey,
}
impl ConsumeEvents {
pub fn instruction(
&self,
args: ConsumeEventsInstructionArgs,
) -> 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: ConsumeEventsInstructionArgs,
remaining_accounts: &[solana_instruction::AccountMeta],
) -> solana_instruction::Instruction {
let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
self.open_orders,
false,
));
accounts.push(solana_instruction::AccountMeta::new(self.market, false));
accounts.push(solana_instruction::AccountMeta::new(
self.event_queue,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.coin_fee_receivable,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.pc_fee_receivable,
false,
));
accounts.extend_from_slice(remaining_accounts);
let mut data = borsh::to_vec(&ConsumeEventsInstructionData::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 ConsumeEventsInstructionData {
discriminator: [u8; 8],
}
impl ConsumeEventsInstructionData {
pub fn new() -> Self {
Self {
discriminator: [221, 145, 177, 52, 31, 47, 63, 201],
}
}
}
impl Default for ConsumeEventsInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ConsumeEventsInstructionArgs {
pub limit: u16,
}
#[derive(Clone, Debug, Default)]
pub struct ConsumeEventsBuilder {
open_orders: Option<solana_pubkey::Pubkey>,
market: Option<solana_pubkey::Pubkey>,
event_queue: Option<solana_pubkey::Pubkey>,
coin_fee_receivable: Option<solana_pubkey::Pubkey>,
pc_fee_receivable: Option<solana_pubkey::Pubkey>,
limit: Option<u16>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl ConsumeEventsBuilder {
pub fn new() -> Self {
Self::default()
}
#[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 market(&mut self, market: solana_pubkey::Pubkey) -> &mut Self {
self.market = Some(market);
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 coin_fee_receivable(&mut self, coin_fee_receivable: solana_pubkey::Pubkey) -> &mut Self {
self.coin_fee_receivable = Some(coin_fee_receivable);
self
}
#[inline(always)]
pub fn pc_fee_receivable(&mut self, pc_fee_receivable: solana_pubkey::Pubkey) -> &mut Self {
self.pc_fee_receivable = Some(pc_fee_receivable);
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 = ConsumeEvents {
open_orders: self.open_orders.expect("open_orders is not set"),
market: self.market.expect("market is not set"),
event_queue: self.event_queue.expect("event_queue is not set"),
coin_fee_receivable: self
.coin_fee_receivable
.expect("coin_fee_receivable is not set"),
pc_fee_receivable: self
.pc_fee_receivable
.expect("pc_fee_receivable is not set"),
};
let args = ConsumeEventsInstructionArgs {
limit: self.limit.clone().expect("limit is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct ConsumeEventsCpiAccounts<'a, 'b> {
pub open_orders: &'b solana_account_info::AccountInfo<'a>,
pub market: &'b solana_account_info::AccountInfo<'a>,
pub event_queue: &'b solana_account_info::AccountInfo<'a>,
pub coin_fee_receivable: &'b solana_account_info::AccountInfo<'a>,
pub pc_fee_receivable: &'b solana_account_info::AccountInfo<'a>,
}
pub struct ConsumeEventsCpi<'a, 'b> {
pub __program: &'b solana_account_info::AccountInfo<'a>,
pub open_orders: &'b solana_account_info::AccountInfo<'a>,
pub market: &'b solana_account_info::AccountInfo<'a>,
pub event_queue: &'b solana_account_info::AccountInfo<'a>,
pub coin_fee_receivable: &'b solana_account_info::AccountInfo<'a>,
pub pc_fee_receivable: &'b solana_account_info::AccountInfo<'a>,
pub __args: ConsumeEventsInstructionArgs,
}
impl<'a, 'b> ConsumeEventsCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: ConsumeEventsCpiAccounts<'a, 'b>,
args: ConsumeEventsInstructionArgs,
) -> Self {
Self {
__program: program,
open_orders: accounts.open_orders,
market: accounts.market,
event_queue: accounts.event_queue,
coin_fee_receivable: accounts.coin_fee_receivable,
pc_fee_receivable: accounts.pc_fee_receivable,
__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(5 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
*self.open_orders.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.market.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.event_queue.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.coin_fee_receivable.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.pc_fee_receivable.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(&ConsumeEventsInstructionData::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(6 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.open_orders.clone());
account_infos.push(self.market.clone());
account_infos.push(self.event_queue.clone());
account_infos.push(self.coin_fee_receivable.clone());
account_infos.push(self.pc_fee_receivable.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 ConsumeEventsCpiBuilder<'a, 'b> {
instruction: Box<ConsumeEventsCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> ConsumeEventsCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(ConsumeEventsCpiBuilderInstruction {
__program: program,
open_orders: None,
market: None,
event_queue: None,
coin_fee_receivable: None,
pc_fee_receivable: None,
limit: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[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 market(&mut self, market: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.market = Some(market);
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 coin_fee_receivable(
&mut self,
coin_fee_receivable: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.coin_fee_receivable = Some(coin_fee_receivable);
self
}
#[inline(always)]
pub fn pc_fee_receivable(
&mut self,
pc_fee_receivable: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.pc_fee_receivable = Some(pc_fee_receivable);
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 = ConsumeEventsInstructionArgs {
limit: self.instruction.limit.clone().expect("limit is not set"),
};
let instruction = ConsumeEventsCpi {
__program: self.instruction.__program,
open_orders: self
.instruction
.open_orders
.expect("open_orders is not set"),
market: self.instruction.market.expect("market is not set"),
event_queue: self
.instruction
.event_queue
.expect("event_queue is not set"),
coin_fee_receivable: self
.instruction
.coin_fee_receivable
.expect("coin_fee_receivable is not set"),
pc_fee_receivable: self
.instruction
.pc_fee_receivable
.expect("pc_fee_receivable is not set"),
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
#[derive(Clone, Debug)]
struct ConsumeEventsCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_account_info::AccountInfo<'a>,
open_orders: Option<&'b solana_account_info::AccountInfo<'a>>,
market: Option<&'b solana_account_info::AccountInfo<'a>>,
event_queue: Option<&'b solana_account_info::AccountInfo<'a>>,
coin_fee_receivable: Option<&'b solana_account_info::AccountInfo<'a>>,
pc_fee_receivable: Option<&'b solana_account_info::AccountInfo<'a>>,
limit: Option<u16>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}