use borsh::BorshDeserialize;
use borsh::BorshSerialize;
#[derive(Debug)]
pub struct CancelOrderByClientId {
pub market: solana_pubkey::Pubkey,
pub open_orders: solana_pubkey::Pubkey,
pub request_queue: solana_pubkey::Pubkey,
pub owner: solana_pubkey::Pubkey,
}
impl CancelOrderByClientId {
pub fn instruction(
&self,
args: CancelOrderByClientIdInstructionArgs,
) -> 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: CancelOrderByClientIdInstructionArgs,
remaining_accounts: &[solana_instruction::AccountMeta],
) -> solana_instruction::Instruction {
let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.market,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.open_orders,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.request_queue,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.owner, true,
));
accounts.extend_from_slice(remaining_accounts);
let mut data = borsh::to_vec(&CancelOrderByClientIdInstructionData::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 CancelOrderByClientIdInstructionData {
discriminator: [u8; 8],
}
impl CancelOrderByClientIdInstructionData {
pub fn new() -> Self {
Self {
discriminator: [223, 248, 134, 155, 106, 111, 152, 171],
}
}
}
impl Default for CancelOrderByClientIdInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CancelOrderByClientIdInstructionArgs {
pub client_order_i_d: u64,
}
#[derive(Clone, Debug, Default)]
pub struct CancelOrderByClientIdBuilder {
market: Option<solana_pubkey::Pubkey>,
open_orders: Option<solana_pubkey::Pubkey>,
request_queue: Option<solana_pubkey::Pubkey>,
owner: Option<solana_pubkey::Pubkey>,
client_order_i_d: Option<u64>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl CancelOrderByClientIdBuilder {
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 open_orders(&mut self, open_orders: solana_pubkey::Pubkey) -> &mut Self {
self.open_orders = Some(open_orders);
self
}
#[inline(always)]
pub fn request_queue(&mut self, request_queue: solana_pubkey::Pubkey) -> &mut Self {
self.request_queue = Some(request_queue);
self
}
#[inline(always)]
pub fn owner(&mut self, owner: solana_pubkey::Pubkey) -> &mut Self {
self.owner = Some(owner);
self
}
#[inline(always)]
pub fn client_order_i_d(&mut self, client_order_i_d: u64) -> &mut Self {
self.client_order_i_d = Some(client_order_i_d);
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 = CancelOrderByClientId {
market: self.market.expect("market is not set"),
open_orders: self.open_orders.expect("open_orders is not set"),
request_queue: self.request_queue.expect("request_queue is not set"),
owner: self.owner.expect("owner is not set"),
};
let args = CancelOrderByClientIdInstructionArgs {
client_order_i_d: self
.client_order_i_d
.clone()
.expect("client_order_i_d is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct CancelOrderByClientIdCpiAccounts<'a, 'b> {
pub market: &'b solana_account_info::AccountInfo<'a>,
pub open_orders: &'b solana_account_info::AccountInfo<'a>,
pub request_queue: &'b solana_account_info::AccountInfo<'a>,
pub owner: &'b solana_account_info::AccountInfo<'a>,
}
pub struct CancelOrderByClientIdCpi<'a, 'b> {
pub __program: &'b solana_account_info::AccountInfo<'a>,
pub market: &'b solana_account_info::AccountInfo<'a>,
pub open_orders: &'b solana_account_info::AccountInfo<'a>,
pub request_queue: &'b solana_account_info::AccountInfo<'a>,
pub owner: &'b solana_account_info::AccountInfo<'a>,
pub __args: CancelOrderByClientIdInstructionArgs,
}
impl<'a, 'b> CancelOrderByClientIdCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: CancelOrderByClientIdCpiAccounts<'a, 'b>,
args: CancelOrderByClientIdInstructionArgs,
) -> Self {
Self {
__program: program,
market: accounts.market,
open_orders: accounts.open_orders,
request_queue: accounts.request_queue,
owner: accounts.owner,
__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(4 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.market.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.open_orders.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.request_queue.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.owner.key,
true,
));
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(&CancelOrderByClientIdInstructionData::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(5 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.market.clone());
account_infos.push(self.open_orders.clone());
account_infos.push(self.request_queue.clone());
account_infos.push(self.owner.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 CancelOrderByClientIdCpiBuilder<'a, 'b> {
instruction: Box<CancelOrderByClientIdCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> CancelOrderByClientIdCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(CancelOrderByClientIdCpiBuilderInstruction {
__program: program,
market: None,
open_orders: None,
request_queue: None,
owner: None,
client_order_i_d: 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 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 request_queue(
&mut self,
request_queue: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.request_queue = Some(request_queue);
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 client_order_i_d(&mut self, client_order_i_d: u64) -> &mut Self {
self.instruction.client_order_i_d = Some(client_order_i_d);
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 = CancelOrderByClientIdInstructionArgs {
client_order_i_d: self
.instruction
.client_order_i_d
.clone()
.expect("client_order_i_d is not set"),
};
let instruction = CancelOrderByClientIdCpi {
__program: self.instruction.__program,
market: self.instruction.market.expect("market is not set"),
open_orders: self
.instruction
.open_orders
.expect("open_orders is not set"),
request_queue: self
.instruction
.request_queue
.expect("request_queue is not set"),
owner: self.instruction.owner.expect("owner is not set"),
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
#[derive(Clone, Debug)]
struct CancelOrderByClientIdCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_account_info::AccountInfo<'a>,
market: Option<&'b solana_account_info::AccountInfo<'a>>,
open_orders: Option<&'b solana_account_info::AccountInfo<'a>>,
request_queue: Option<&'b solana_account_info::AccountInfo<'a>>,
owner: Option<&'b solana_account_info::AccountInfo<'a>>,
client_order_i_d: Option<u64>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}