use borsh::BorshSerialize;
use borsh::BorshDeserialize;
pub const OPEN_LIMIT_ORDER_DISCRIMINATOR: [u8; 8] = [157, 32, 218, 183, 71, 29, 18, 147];
#[derive(Debug)]
pub struct OpenLimitOrder {
pub funder: solana_pubkey::Pubkey,
pub owner: solana_pubkey::Pubkey,
pub limit_order: solana_pubkey::Pubkey,
pub limit_order_mint: solana_pubkey::Pubkey,
pub limit_order_token_account: solana_pubkey::Pubkey,
pub fusion_pool: solana_pubkey::Pubkey,
pub token2022_program: solana_pubkey::Pubkey,
pub system_program: solana_pubkey::Pubkey,
pub associated_token_program: solana_pubkey::Pubkey,
pub metadata_update_auth: solana_pubkey::Pubkey,
}
impl OpenLimitOrder {
pub fn instruction(&self, args: OpenLimitOrderInstructionArgs) -> 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: OpenLimitOrderInstructionArgs, 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.funder,
true
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.owner,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.limit_order,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.limit_order_mint,
true
));
accounts.push(solana_instruction::AccountMeta::new(
self.limit_order_token_account,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.fusion_pool,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.token2022_program,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.system_program,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.associated_token_program,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.metadata_update_auth,
false
));
accounts.extend_from_slice(remaining_accounts);
let mut data = borsh::to_vec(&OpenLimitOrderInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&args).unwrap();
data.append(&mut args);
solana_instruction::Instruction {
program_id: crate::FUSIONAMM_ID,
accounts,
data,
}
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OpenLimitOrderInstructionData {
discriminator: [u8; 8],
}
impl OpenLimitOrderInstructionData {
pub fn new() -> Self {
Self {
discriminator: [157, 32, 218, 183, 71, 29, 18, 147],
}
}
}
impl Default for OpenLimitOrderInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct OpenLimitOrderInstructionArgs {
pub tick_index: i32,
pub a_to_b: bool,
pub with_token_metadata_extension: bool,
}
#[derive(Clone, Debug, Default)]
pub struct OpenLimitOrderBuilder {
funder: Option<solana_pubkey::Pubkey>,
owner: Option<solana_pubkey::Pubkey>,
limit_order: Option<solana_pubkey::Pubkey>,
limit_order_mint: Option<solana_pubkey::Pubkey>,
limit_order_token_account: Option<solana_pubkey::Pubkey>,
fusion_pool: Option<solana_pubkey::Pubkey>,
token2022_program: Option<solana_pubkey::Pubkey>,
system_program: Option<solana_pubkey::Pubkey>,
associated_token_program: Option<solana_pubkey::Pubkey>,
metadata_update_auth: Option<solana_pubkey::Pubkey>,
tick_index: Option<i32>,
a_to_b: Option<bool>,
with_token_metadata_extension: Option<bool>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl OpenLimitOrderBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn funder(&mut self, funder: solana_pubkey::Pubkey) -> &mut Self {
self.funder = Some(funder);
self
}
#[inline(always)]
pub fn owner(&mut self, owner: solana_pubkey::Pubkey) -> &mut Self {
self.owner = Some(owner);
self
}
#[inline(always)]
pub fn limit_order(&mut self, limit_order: solana_pubkey::Pubkey) -> &mut Self {
self.limit_order = Some(limit_order);
self
}
#[inline(always)]
pub fn limit_order_mint(&mut self, limit_order_mint: solana_pubkey::Pubkey) -> &mut Self {
self.limit_order_mint = Some(limit_order_mint);
self
}
#[inline(always)]
pub fn limit_order_token_account(&mut self, limit_order_token_account: solana_pubkey::Pubkey) -> &mut Self {
self.limit_order_token_account = Some(limit_order_token_account);
self
}
#[inline(always)]
pub fn fusion_pool(&mut self, fusion_pool: solana_pubkey::Pubkey) -> &mut Self {
self.fusion_pool = Some(fusion_pool);
self
}
#[inline(always)]
pub fn token2022_program(&mut self, token2022_program: solana_pubkey::Pubkey) -> &mut Self {
self.token2022_program = Some(token2022_program);
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 associated_token_program(&mut self, associated_token_program: solana_pubkey::Pubkey) -> &mut Self {
self.associated_token_program = Some(associated_token_program);
self
}
#[inline(always)]
pub fn metadata_update_auth(&mut self, metadata_update_auth: solana_pubkey::Pubkey) -> &mut Self {
self.metadata_update_auth = Some(metadata_update_auth);
self
}
#[inline(always)]
pub fn tick_index(&mut self, tick_index: i32) -> &mut Self {
self.tick_index = Some(tick_index);
self
}
#[inline(always)]
pub fn a_to_b(&mut self, a_to_b: bool) -> &mut Self {
self.a_to_b = Some(a_to_b);
self
}
#[inline(always)]
pub fn with_token_metadata_extension(&mut self, with_token_metadata_extension: bool) -> &mut Self {
self.with_token_metadata_extension = Some(with_token_metadata_extension);
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 = OpenLimitOrder {
funder: self.funder.expect("funder is not set"),
owner: self.owner.expect("owner is not set"),
limit_order: self.limit_order.expect("limit_order is not set"),
limit_order_mint: self.limit_order_mint.expect("limit_order_mint is not set"),
limit_order_token_account: self.limit_order_token_account.expect("limit_order_token_account is not set"),
fusion_pool: self.fusion_pool.expect("fusion_pool is not set"),
token2022_program: self.token2022_program.expect("token2022_program is not set"),
system_program: self.system_program.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
associated_token_program: self.associated_token_program.expect("associated_token_program is not set"),
metadata_update_auth: self.metadata_update_auth.expect("metadata_update_auth is not set"),
};
let args = OpenLimitOrderInstructionArgs {
tick_index: self.tick_index.clone().expect("tick_index is not set"),
a_to_b: self.a_to_b.clone().expect("a_to_b is not set"),
with_token_metadata_extension: self.with_token_metadata_extension.clone().expect("with_token_metadata_extension is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct OpenLimitOrderCpiAccounts<'a, 'b> {
pub funder: &'b solana_account_info::AccountInfo<'a>,
pub owner: &'b solana_account_info::AccountInfo<'a>,
pub limit_order: &'b solana_account_info::AccountInfo<'a>,
pub limit_order_mint: &'b solana_account_info::AccountInfo<'a>,
pub limit_order_token_account: &'b solana_account_info::AccountInfo<'a>,
pub fusion_pool: &'b solana_account_info::AccountInfo<'a>,
pub token2022_program: &'b solana_account_info::AccountInfo<'a>,
pub system_program: &'b solana_account_info::AccountInfo<'a>,
pub associated_token_program: &'b solana_account_info::AccountInfo<'a>,
pub metadata_update_auth: &'b solana_account_info::AccountInfo<'a>,
}
pub struct OpenLimitOrderCpi<'a, 'b> {
pub __program: &'b solana_account_info::AccountInfo<'a>,
pub funder: &'b solana_account_info::AccountInfo<'a>,
pub owner: &'b solana_account_info::AccountInfo<'a>,
pub limit_order: &'b solana_account_info::AccountInfo<'a>,
pub limit_order_mint: &'b solana_account_info::AccountInfo<'a>,
pub limit_order_token_account: &'b solana_account_info::AccountInfo<'a>,
pub fusion_pool: &'b solana_account_info::AccountInfo<'a>,
pub token2022_program: &'b solana_account_info::AccountInfo<'a>,
pub system_program: &'b solana_account_info::AccountInfo<'a>,
pub associated_token_program: &'b solana_account_info::AccountInfo<'a>,
pub metadata_update_auth: &'b solana_account_info::AccountInfo<'a>,
pub __args: OpenLimitOrderInstructionArgs,
}
impl<'a, 'b> OpenLimitOrderCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: OpenLimitOrderCpiAccounts<'a, 'b>,
args: OpenLimitOrderInstructionArgs,
) -> Self {
Self {
__program: program,
funder: accounts.funder,
owner: accounts.owner,
limit_order: accounts.limit_order,
limit_order_mint: accounts.limit_order_mint,
limit_order_token_account: accounts.limit_order_token_account,
fusion_pool: accounts.fusion_pool,
token2022_program: accounts.token2022_program,
system_program: accounts.system_program,
associated_token_program: accounts.associated_token_program,
metadata_update_auth: accounts.metadata_update_auth,
__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(10+ remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
*self.funder.key,
true
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.owner.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.limit_order.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.limit_order_mint.key,
true
));
accounts.push(solana_instruction::AccountMeta::new(
*self.limit_order_token_account.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.fusion_pool.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.token2022_program.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.system_program.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.associated_token_program.key,
false
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.metadata_update_auth.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(&OpenLimitOrderInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&self.__args).unwrap();
data.append(&mut args);
let instruction = solana_instruction::Instruction {
program_id: crate::FUSIONAMM_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(11 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.funder.clone());
account_infos.push(self.owner.clone());
account_infos.push(self.limit_order.clone());
account_infos.push(self.limit_order_mint.clone());
account_infos.push(self.limit_order_token_account.clone());
account_infos.push(self.fusion_pool.clone());
account_infos.push(self.token2022_program.clone());
account_infos.push(self.system_program.clone());
account_infos.push(self.associated_token_program.clone());
account_infos.push(self.metadata_update_auth.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 OpenLimitOrderCpiBuilder<'a, 'b> {
instruction: Box<OpenLimitOrderCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> OpenLimitOrderCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(OpenLimitOrderCpiBuilderInstruction {
__program: program,
funder: None,
owner: None,
limit_order: None,
limit_order_mint: None,
limit_order_token_account: None,
fusion_pool: None,
token2022_program: None,
system_program: None,
associated_token_program: None,
metadata_update_auth: None,
tick_index: None,
a_to_b: None,
with_token_metadata_extension: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn funder(&mut self, funder: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.funder = Some(funder);
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 limit_order(&mut self, limit_order: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.limit_order = Some(limit_order);
self
}
#[inline(always)]
pub fn limit_order_mint(&mut self, limit_order_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.limit_order_mint = Some(limit_order_mint);
self
}
#[inline(always)]
pub fn limit_order_token_account(&mut self, limit_order_token_account: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.limit_order_token_account = Some(limit_order_token_account);
self
}
#[inline(always)]
pub fn fusion_pool(&mut self, fusion_pool: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.fusion_pool = Some(fusion_pool);
self
}
#[inline(always)]
pub fn token2022_program(&mut self, token2022_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.token2022_program = Some(token2022_program);
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 associated_token_program(&mut self, associated_token_program: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.associated_token_program = Some(associated_token_program);
self
}
#[inline(always)]
pub fn metadata_update_auth(&mut self, metadata_update_auth: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.metadata_update_auth = Some(metadata_update_auth);
self
}
#[inline(always)]
pub fn tick_index(&mut self, tick_index: i32) -> &mut Self {
self.instruction.tick_index = Some(tick_index);
self
}
#[inline(always)]
pub fn a_to_b(&mut self, a_to_b: bool) -> &mut Self {
self.instruction.a_to_b = Some(a_to_b);
self
}
#[inline(always)]
pub fn with_token_metadata_extension(&mut self, with_token_metadata_extension: bool) -> &mut Self {
self.instruction.with_token_metadata_extension = Some(with_token_metadata_extension);
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 = OpenLimitOrderInstructionArgs {
tick_index: self.instruction.tick_index.clone().expect("tick_index is not set"),
a_to_b: self.instruction.a_to_b.clone().expect("a_to_b is not set"),
with_token_metadata_extension: self.instruction.with_token_metadata_extension.clone().expect("with_token_metadata_extension is not set"),
};
let instruction = OpenLimitOrderCpi {
__program: self.instruction.__program,
funder: self.instruction.funder.expect("funder is not set"),
owner: self.instruction.owner.expect("owner is not set"),
limit_order: self.instruction.limit_order.expect("limit_order is not set"),
limit_order_mint: self.instruction.limit_order_mint.expect("limit_order_mint is not set"),
limit_order_token_account: self.instruction.limit_order_token_account.expect("limit_order_token_account is not set"),
fusion_pool: self.instruction.fusion_pool.expect("fusion_pool is not set"),
token2022_program: self.instruction.token2022_program.expect("token2022_program is not set"),
system_program: self.instruction.system_program.expect("system_program is not set"),
associated_token_program: self.instruction.associated_token_program.expect("associated_token_program is not set"),
metadata_update_auth: self.instruction.metadata_update_auth.expect("metadata_update_auth is not set"),
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(signers_seeds, &self.instruction.__remaining_accounts)
}
}
#[derive(Clone, Debug)]
struct OpenLimitOrderCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_account_info::AccountInfo<'a>,
funder: Option<&'b solana_account_info::AccountInfo<'a>>,
owner: Option<&'b solana_account_info::AccountInfo<'a>>,
limit_order: Option<&'b solana_account_info::AccountInfo<'a>>,
limit_order_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
limit_order_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
fusion_pool: Option<&'b solana_account_info::AccountInfo<'a>>,
token2022_program: Option<&'b solana_account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
associated_token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
metadata_update_auth: Option<&'b solana_account_info::AccountInfo<'a>>,
tick_index: Option<i32>,
a_to_b: Option<bool>,
with_token_metadata_extension: Option<bool>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}