use borsh::BorshDeserialize;
use borsh::BorshSerialize;
#[derive(Debug)]
pub struct CreatePool {
pub pool_creator: solana_pubkey::Pubkey,
pub amm_config: solana_pubkey::Pubkey,
pub pool_state: solana_pubkey::Pubkey,
pub token_mint0: solana_pubkey::Pubkey,
pub token_mint1: solana_pubkey::Pubkey,
pub token_vault0: solana_pubkey::Pubkey,
pub token_vault1: solana_pubkey::Pubkey,
pub observation_state: solana_pubkey::Pubkey,
pub tick_array_bitmap: solana_pubkey::Pubkey,
pub token_program0: solana_pubkey::Pubkey,
pub token_program1: solana_pubkey::Pubkey,
pub system_program: solana_pubkey::Pubkey,
pub rent: solana_pubkey::Pubkey,
}
impl CreatePool {
pub fn instruction(&self, args: CreatePoolInstructionArgs) -> 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: CreatePoolInstructionArgs,
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.pool_creator,
true,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.amm_config,
false,
));
accounts.push(solana_instruction::AccountMeta::new(self.pool_state, false));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.token_mint0,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.token_mint1,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.token_vault0,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.token_vault1,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.observation_state,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.tick_array_bitmap,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.token_program0,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.token_program1,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.system_program,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.rent, false,
));
accounts.extend_from_slice(remaining_accounts);
let mut data = borsh::to_vec(&CreatePoolInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&args).unwrap();
data.append(&mut args);
solana_instruction::Instruction {
program_id: crate::AMM_V3_ID,
accounts,
data,
}
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreatePoolInstructionData {
discriminator: [u8; 8],
}
impl CreatePoolInstructionData {
pub fn new() -> Self {
Self {
discriminator: [233, 146, 209, 142, 207, 104, 64, 188],
}
}
}
impl Default for CreatePoolInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreatePoolInstructionArgs {
pub sqrt_price_x64: u128,
pub open_time: u64,
}
#[derive(Clone, Debug, Default)]
pub struct CreatePoolBuilder {
pool_creator: Option<solana_pubkey::Pubkey>,
amm_config: Option<solana_pubkey::Pubkey>,
pool_state: Option<solana_pubkey::Pubkey>,
token_mint0: Option<solana_pubkey::Pubkey>,
token_mint1: Option<solana_pubkey::Pubkey>,
token_vault0: Option<solana_pubkey::Pubkey>,
token_vault1: Option<solana_pubkey::Pubkey>,
observation_state: Option<solana_pubkey::Pubkey>,
tick_array_bitmap: Option<solana_pubkey::Pubkey>,
token_program0: Option<solana_pubkey::Pubkey>,
token_program1: Option<solana_pubkey::Pubkey>,
system_program: Option<solana_pubkey::Pubkey>,
rent: Option<solana_pubkey::Pubkey>,
sqrt_price_x64: Option<u128>,
open_time: Option<u64>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl CreatePoolBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn pool_creator(&mut self, pool_creator: solana_pubkey::Pubkey) -> &mut Self {
self.pool_creator = Some(pool_creator);
self
}
#[inline(always)]
pub fn amm_config(&mut self, amm_config: solana_pubkey::Pubkey) -> &mut Self {
self.amm_config = Some(amm_config);
self
}
#[inline(always)]
pub fn pool_state(&mut self, pool_state: solana_pubkey::Pubkey) -> &mut Self {
self.pool_state = Some(pool_state);
self
}
#[inline(always)]
pub fn token_mint0(&mut self, token_mint0: solana_pubkey::Pubkey) -> &mut Self {
self.token_mint0 = Some(token_mint0);
self
}
#[inline(always)]
pub fn token_mint1(&mut self, token_mint1: solana_pubkey::Pubkey) -> &mut Self {
self.token_mint1 = Some(token_mint1);
self
}
#[inline(always)]
pub fn token_vault0(&mut self, token_vault0: solana_pubkey::Pubkey) -> &mut Self {
self.token_vault0 = Some(token_vault0);
self
}
#[inline(always)]
pub fn token_vault1(&mut self, token_vault1: solana_pubkey::Pubkey) -> &mut Self {
self.token_vault1 = Some(token_vault1);
self
}
#[inline(always)]
pub fn observation_state(&mut self, observation_state: solana_pubkey::Pubkey) -> &mut Self {
self.observation_state = Some(observation_state);
self
}
#[inline(always)]
pub fn tick_array_bitmap(&mut self, tick_array_bitmap: solana_pubkey::Pubkey) -> &mut Self {
self.tick_array_bitmap = Some(tick_array_bitmap);
self
}
#[inline(always)]
pub fn token_program0(&mut self, token_program0: solana_pubkey::Pubkey) -> &mut Self {
self.token_program0 = Some(token_program0);
self
}
#[inline(always)]
pub fn token_program1(&mut self, token_program1: solana_pubkey::Pubkey) -> &mut Self {
self.token_program1 = Some(token_program1);
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 rent(&mut self, rent: solana_pubkey::Pubkey) -> &mut Self {
self.rent = Some(rent);
self
}
#[inline(always)]
pub fn sqrt_price_x64(&mut self, sqrt_price_x64: u128) -> &mut Self {
self.sqrt_price_x64 = Some(sqrt_price_x64);
self
}
#[inline(always)]
pub fn open_time(&mut self, open_time: u64) -> &mut Self {
self.open_time = Some(open_time);
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 = CreatePool {
pool_creator: self.pool_creator.expect("pool_creator is not set"),
amm_config: self.amm_config.expect("amm_config is not set"),
pool_state: self.pool_state.expect("pool_state is not set"),
token_mint0: self.token_mint0.expect("token_mint0 is not set"),
token_mint1: self.token_mint1.expect("token_mint1 is not set"),
token_vault0: self.token_vault0.expect("token_vault0 is not set"),
token_vault1: self.token_vault1.expect("token_vault1 is not set"),
observation_state: self
.observation_state
.expect("observation_state is not set"),
tick_array_bitmap: self
.tick_array_bitmap
.expect("tick_array_bitmap is not set"),
token_program0: self.token_program0.expect("token_program0 is not set"),
token_program1: self.token_program1.expect("token_program1 is not set"),
system_program: self
.system_program
.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
rent: self.rent.unwrap_or(solana_pubkey::pubkey!(
"SysvarRent111111111111111111111111111111111"
)),
};
let args = CreatePoolInstructionArgs {
sqrt_price_x64: self
.sqrt_price_x64
.clone()
.expect("sqrt_price_x64 is not set"),
open_time: self.open_time.clone().expect("open_time is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct CreatePoolCpiAccounts<'a, 'b> {
pub pool_creator: &'b solana_account_info::AccountInfo<'a>,
pub amm_config: &'b solana_account_info::AccountInfo<'a>,
pub pool_state: &'b solana_account_info::AccountInfo<'a>,
pub token_mint0: &'b solana_account_info::AccountInfo<'a>,
pub token_mint1: &'b solana_account_info::AccountInfo<'a>,
pub token_vault0: &'b solana_account_info::AccountInfo<'a>,
pub token_vault1: &'b solana_account_info::AccountInfo<'a>,
pub observation_state: &'b solana_account_info::AccountInfo<'a>,
pub tick_array_bitmap: &'b solana_account_info::AccountInfo<'a>,
pub token_program0: &'b solana_account_info::AccountInfo<'a>,
pub token_program1: &'b solana_account_info::AccountInfo<'a>,
pub system_program: &'b solana_account_info::AccountInfo<'a>,
pub rent: &'b solana_account_info::AccountInfo<'a>,
}
pub struct CreatePoolCpi<'a, 'b> {
pub __program: &'b solana_account_info::AccountInfo<'a>,
pub pool_creator: &'b solana_account_info::AccountInfo<'a>,
pub amm_config: &'b solana_account_info::AccountInfo<'a>,
pub pool_state: &'b solana_account_info::AccountInfo<'a>,
pub token_mint0: &'b solana_account_info::AccountInfo<'a>,
pub token_mint1: &'b solana_account_info::AccountInfo<'a>,
pub token_vault0: &'b solana_account_info::AccountInfo<'a>,
pub token_vault1: &'b solana_account_info::AccountInfo<'a>,
pub observation_state: &'b solana_account_info::AccountInfo<'a>,
pub tick_array_bitmap: &'b solana_account_info::AccountInfo<'a>,
pub token_program0: &'b solana_account_info::AccountInfo<'a>,
pub token_program1: &'b solana_account_info::AccountInfo<'a>,
pub system_program: &'b solana_account_info::AccountInfo<'a>,
pub rent: &'b solana_account_info::AccountInfo<'a>,
pub __args: CreatePoolInstructionArgs,
}
impl<'a, 'b> CreatePoolCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: CreatePoolCpiAccounts<'a, 'b>,
args: CreatePoolInstructionArgs,
) -> Self {
Self {
__program: program,
pool_creator: accounts.pool_creator,
amm_config: accounts.amm_config,
pool_state: accounts.pool_state,
token_mint0: accounts.token_mint0,
token_mint1: accounts.token_mint1,
token_vault0: accounts.token_vault0,
token_vault1: accounts.token_vault1,
observation_state: accounts.observation_state,
tick_array_bitmap: accounts.tick_array_bitmap,
token_program0: accounts.token_program0,
token_program1: accounts.token_program1,
system_program: accounts.system_program,
rent: accounts.rent,
__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(13 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
*self.pool_creator.key,
true,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.amm_config.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.pool_state.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.token_mint0.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.token_mint1.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.token_vault0.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.token_vault1.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.observation_state.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.tick_array_bitmap.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.token_program0.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.token_program1.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.system_program.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.rent.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(&CreatePoolInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&self.__args).unwrap();
data.append(&mut args);
let instruction = solana_instruction::Instruction {
program_id: crate::AMM_V3_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(14 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.pool_creator.clone());
account_infos.push(self.amm_config.clone());
account_infos.push(self.pool_state.clone());
account_infos.push(self.token_mint0.clone());
account_infos.push(self.token_mint1.clone());
account_infos.push(self.token_vault0.clone());
account_infos.push(self.token_vault1.clone());
account_infos.push(self.observation_state.clone());
account_infos.push(self.tick_array_bitmap.clone());
account_infos.push(self.token_program0.clone());
account_infos.push(self.token_program1.clone());
account_infos.push(self.system_program.clone());
account_infos.push(self.rent.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 CreatePoolCpiBuilder<'a, 'b> {
instruction: Box<CreatePoolCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> CreatePoolCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(CreatePoolCpiBuilderInstruction {
__program: program,
pool_creator: None,
amm_config: None,
pool_state: None,
token_mint0: None,
token_mint1: None,
token_vault0: None,
token_vault1: None,
observation_state: None,
tick_array_bitmap: None,
token_program0: None,
token_program1: None,
system_program: None,
rent: None,
sqrt_price_x64: None,
open_time: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn pool_creator(
&mut self,
pool_creator: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.pool_creator = Some(pool_creator);
self
}
#[inline(always)]
pub fn amm_config(
&mut self,
amm_config: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.amm_config = Some(amm_config);
self
}
#[inline(always)]
pub fn pool_state(
&mut self,
pool_state: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.pool_state = Some(pool_state);
self
}
#[inline(always)]
pub fn token_mint0(
&mut self,
token_mint0: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.token_mint0 = Some(token_mint0);
self
}
#[inline(always)]
pub fn token_mint1(
&mut self,
token_mint1: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.token_mint1 = Some(token_mint1);
self
}
#[inline(always)]
pub fn token_vault0(
&mut self,
token_vault0: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.token_vault0 = Some(token_vault0);
self
}
#[inline(always)]
pub fn token_vault1(
&mut self,
token_vault1: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.token_vault1 = Some(token_vault1);
self
}
#[inline(always)]
pub fn observation_state(
&mut self,
observation_state: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.observation_state = Some(observation_state);
self
}
#[inline(always)]
pub fn tick_array_bitmap(
&mut self,
tick_array_bitmap: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.tick_array_bitmap = Some(tick_array_bitmap);
self
}
#[inline(always)]
pub fn token_program0(
&mut self,
token_program0: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.token_program0 = Some(token_program0);
self
}
#[inline(always)]
pub fn token_program1(
&mut self,
token_program1: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.token_program1 = Some(token_program1);
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 rent(&mut self, rent: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.rent = Some(rent);
self
}
#[inline(always)]
pub fn sqrt_price_x64(&mut self, sqrt_price_x64: u128) -> &mut Self {
self.instruction.sqrt_price_x64 = Some(sqrt_price_x64);
self
}
#[inline(always)]
pub fn open_time(&mut self, open_time: u64) -> &mut Self {
self.instruction.open_time = Some(open_time);
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 = CreatePoolInstructionArgs {
sqrt_price_x64: self
.instruction
.sqrt_price_x64
.clone()
.expect("sqrt_price_x64 is not set"),
open_time: self
.instruction
.open_time
.clone()
.expect("open_time is not set"),
};
let instruction = CreatePoolCpi {
__program: self.instruction.__program,
pool_creator: self
.instruction
.pool_creator
.expect("pool_creator is not set"),
amm_config: self.instruction.amm_config.expect("amm_config is not set"),
pool_state: self.instruction.pool_state.expect("pool_state is not set"),
token_mint0: self
.instruction
.token_mint0
.expect("token_mint0 is not set"),
token_mint1: self
.instruction
.token_mint1
.expect("token_mint1 is not set"),
token_vault0: self
.instruction
.token_vault0
.expect("token_vault0 is not set"),
token_vault1: self
.instruction
.token_vault1
.expect("token_vault1 is not set"),
observation_state: self
.instruction
.observation_state
.expect("observation_state is not set"),
tick_array_bitmap: self
.instruction
.tick_array_bitmap
.expect("tick_array_bitmap is not set"),
token_program0: self
.instruction
.token_program0
.expect("token_program0 is not set"),
token_program1: self
.instruction
.token_program1
.expect("token_program1 is not set"),
system_program: self
.instruction
.system_program
.expect("system_program is not set"),
rent: self.instruction.rent.expect("rent is not set"),
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
#[derive(Clone, Debug)]
struct CreatePoolCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_account_info::AccountInfo<'a>,
pool_creator: Option<&'b solana_account_info::AccountInfo<'a>>,
amm_config: Option<&'b solana_account_info::AccountInfo<'a>>,
pool_state: Option<&'b solana_account_info::AccountInfo<'a>>,
token_mint0: Option<&'b solana_account_info::AccountInfo<'a>>,
token_mint1: Option<&'b solana_account_info::AccountInfo<'a>>,
token_vault0: Option<&'b solana_account_info::AccountInfo<'a>>,
token_vault1: Option<&'b solana_account_info::AccountInfo<'a>>,
observation_state: Option<&'b solana_account_info::AccountInfo<'a>>,
tick_array_bitmap: Option<&'b solana_account_info::AccountInfo<'a>>,
token_program0: Option<&'b solana_account_info::AccountInfo<'a>>,
token_program1: Option<&'b solana_account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
rent: Option<&'b solana_account_info::AccountInfo<'a>>,
sqrt_price_x64: Option<u128>,
open_time: Option<u64>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}