use borsh::BorshDeserialize;
use borsh::BorshSerialize;
pub const LP_TAKEOVER_DISCRIMINATOR: u8 = 58;
#[derive(Debug)]
pub struct LpTakeover {
pub authority: solana_pubkey::Pubkey,
pub authority_config: solana_pubkey::Pubkey,
pub lp_authority: solana_pubkey::Pubkey,
pub new_lp_authority: solana_pubkey::Pubkey,
pub lp_escrow: solana_pubkey::Pubkey,
pub new_lp_escrow: solana_pubkey::Pubkey,
pub position_mint: solana_pubkey::Pubkey,
pub position: solana_pubkey::Pubkey,
pub position_token_account: solana_pubkey::Pubkey,
pub new_position_token_account: solana_pubkey::Pubkey,
pub lock_config: solana_pubkey::Pubkey,
pub system_program: solana_pubkey::Pubkey,
pub token22_program: solana_pubkey::Pubkey,
pub ata_program: solana_pubkey::Pubkey,
pub whirlpool_program: solana_pubkey::Pubkey,
}
impl LpTakeover {
pub fn instruction(&self) -> solana_instruction::Instruction {
self.instruction_with_remaining_accounts(&[])
}
#[allow(clippy::arithmetic_side_effects)]
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(
&self,
remaining_accounts: &[solana_instruction::AccountMeta],
) -> solana_instruction::Instruction {
let mut accounts = Vec::with_capacity(15 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(self.authority, true));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.authority_config,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.lp_authority,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.new_lp_authority,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.lp_escrow,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.new_lp_escrow,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.position_mint,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.position,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.position_token_account,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.new_position_token_account,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.lock_config,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.system_program,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.token22_program,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.ata_program,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.whirlpool_program,
false,
));
accounts.extend_from_slice(remaining_accounts);
let data = borsh::to_vec(&LpTakeoverInstructionData::new()).unwrap();
solana_instruction::Instruction {
program_id: crate::WAVEBREAK_ID,
accounts,
data,
}
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct LpTakeoverInstructionData {
discriminator: u8,
}
impl LpTakeoverInstructionData {
pub fn new() -> Self {
Self { discriminator: 58 }
}
}
impl Default for LpTakeoverInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, Debug, Default)]
pub struct LpTakeoverBuilder {
authority: Option<solana_pubkey::Pubkey>,
authority_config: Option<solana_pubkey::Pubkey>,
lp_authority: Option<solana_pubkey::Pubkey>,
new_lp_authority: Option<solana_pubkey::Pubkey>,
lp_escrow: Option<solana_pubkey::Pubkey>,
new_lp_escrow: Option<solana_pubkey::Pubkey>,
position_mint: Option<solana_pubkey::Pubkey>,
position: Option<solana_pubkey::Pubkey>,
position_token_account: Option<solana_pubkey::Pubkey>,
new_position_token_account: Option<solana_pubkey::Pubkey>,
lock_config: Option<solana_pubkey::Pubkey>,
system_program: Option<solana_pubkey::Pubkey>,
token22_program: Option<solana_pubkey::Pubkey>,
ata_program: Option<solana_pubkey::Pubkey>,
whirlpool_program: Option<solana_pubkey::Pubkey>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl LpTakeoverBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn authority(&mut self, authority: solana_pubkey::Pubkey) -> &mut Self {
self.authority = Some(authority);
self
}
#[inline(always)]
pub fn authority_config(&mut self, authority_config: solana_pubkey::Pubkey) -> &mut Self {
self.authority_config = Some(authority_config);
self
}
#[inline(always)]
pub fn lp_authority(&mut self, lp_authority: solana_pubkey::Pubkey) -> &mut Self {
self.lp_authority = Some(lp_authority);
self
}
#[inline(always)]
pub fn new_lp_authority(&mut self, new_lp_authority: solana_pubkey::Pubkey) -> &mut Self {
self.new_lp_authority = Some(new_lp_authority);
self
}
#[inline(always)]
pub fn lp_escrow(&mut self, lp_escrow: solana_pubkey::Pubkey) -> &mut Self {
self.lp_escrow = Some(lp_escrow);
self
}
#[inline(always)]
pub fn new_lp_escrow(&mut self, new_lp_escrow: solana_pubkey::Pubkey) -> &mut Self {
self.new_lp_escrow = Some(new_lp_escrow);
self
}
#[inline(always)]
pub fn position_mint(&mut self, position_mint: solana_pubkey::Pubkey) -> &mut Self {
self.position_mint = Some(position_mint);
self
}
#[inline(always)]
pub fn position(&mut self, position: solana_pubkey::Pubkey) -> &mut Self {
self.position = Some(position);
self
}
#[inline(always)]
pub fn position_token_account(
&mut self,
position_token_account: solana_pubkey::Pubkey,
) -> &mut Self {
self.position_token_account = Some(position_token_account);
self
}
#[inline(always)]
pub fn new_position_token_account(
&mut self,
new_position_token_account: solana_pubkey::Pubkey,
) -> &mut Self {
self.new_position_token_account = Some(new_position_token_account);
self
}
#[inline(always)]
pub fn lock_config(&mut self, lock_config: solana_pubkey::Pubkey) -> &mut Self {
self.lock_config = Some(lock_config);
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 token22_program(&mut self, token22_program: solana_pubkey::Pubkey) -> &mut Self {
self.token22_program = Some(token22_program);
self
}
#[inline(always)]
pub fn ata_program(&mut self, ata_program: solana_pubkey::Pubkey) -> &mut Self {
self.ata_program = Some(ata_program);
self
}
#[inline(always)]
pub fn whirlpool_program(&mut self, whirlpool_program: solana_pubkey::Pubkey) -> &mut Self {
self.whirlpool_program = Some(whirlpool_program);
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 = LpTakeover {
authority: self.authority.expect("authority is not set"),
authority_config: self.authority_config.expect("authority_config is not set"),
lp_authority: self.lp_authority.expect("lp_authority is not set"),
new_lp_authority: self.new_lp_authority.expect("new_lp_authority is not set"),
lp_escrow: self.lp_escrow.expect("lp_escrow is not set"),
new_lp_escrow: self.new_lp_escrow.expect("new_lp_escrow is not set"),
position_mint: self.position_mint.expect("position_mint is not set"),
position: self.position.expect("position is not set"),
position_token_account: self
.position_token_account
.expect("position_token_account is not set"),
new_position_token_account: self
.new_position_token_account
.expect("new_position_token_account is not set"),
lock_config: self.lock_config.expect("lock_config is not set"),
system_program: self
.system_program
.unwrap_or(solana_pubkey::pubkey!("11111111111111111111111111111111")),
token22_program: self.token22_program.expect("token22_program is not set"),
ata_program: self.ata_program.unwrap_or(solana_pubkey::pubkey!(
"ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
)),
whirlpool_program: self
.whirlpool_program
.expect("whirlpool_program is not set"),
};
accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
}
}
pub struct LpTakeoverCpiAccounts<'a, 'b> {
pub authority: &'b solana_account_info::AccountInfo<'a>,
pub authority_config: &'b solana_account_info::AccountInfo<'a>,
pub lp_authority: &'b solana_account_info::AccountInfo<'a>,
pub new_lp_authority: &'b solana_account_info::AccountInfo<'a>,
pub lp_escrow: &'b solana_account_info::AccountInfo<'a>,
pub new_lp_escrow: &'b solana_account_info::AccountInfo<'a>,
pub position_mint: &'b solana_account_info::AccountInfo<'a>,
pub position: &'b solana_account_info::AccountInfo<'a>,
pub position_token_account: &'b solana_account_info::AccountInfo<'a>,
pub new_position_token_account: &'b solana_account_info::AccountInfo<'a>,
pub lock_config: &'b solana_account_info::AccountInfo<'a>,
pub system_program: &'b solana_account_info::AccountInfo<'a>,
pub token22_program: &'b solana_account_info::AccountInfo<'a>,
pub ata_program: &'b solana_account_info::AccountInfo<'a>,
pub whirlpool_program: &'b solana_account_info::AccountInfo<'a>,
}
pub struct LpTakeoverCpi<'a, 'b> {
pub __program: &'b solana_account_info::AccountInfo<'a>,
pub authority: &'b solana_account_info::AccountInfo<'a>,
pub authority_config: &'b solana_account_info::AccountInfo<'a>,
pub lp_authority: &'b solana_account_info::AccountInfo<'a>,
pub new_lp_authority: &'b solana_account_info::AccountInfo<'a>,
pub lp_escrow: &'b solana_account_info::AccountInfo<'a>,
pub new_lp_escrow: &'b solana_account_info::AccountInfo<'a>,
pub position_mint: &'b solana_account_info::AccountInfo<'a>,
pub position: &'b solana_account_info::AccountInfo<'a>,
pub position_token_account: &'b solana_account_info::AccountInfo<'a>,
pub new_position_token_account: &'b solana_account_info::AccountInfo<'a>,
pub lock_config: &'b solana_account_info::AccountInfo<'a>,
pub system_program: &'b solana_account_info::AccountInfo<'a>,
pub token22_program: &'b solana_account_info::AccountInfo<'a>,
pub ata_program: &'b solana_account_info::AccountInfo<'a>,
pub whirlpool_program: &'b solana_account_info::AccountInfo<'a>,
}
impl<'a, 'b> LpTakeoverCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: LpTakeoverCpiAccounts<'a, 'b>,
) -> Self {
Self {
__program: program,
authority: accounts.authority,
authority_config: accounts.authority_config,
lp_authority: accounts.lp_authority,
new_lp_authority: accounts.new_lp_authority,
lp_escrow: accounts.lp_escrow,
new_lp_escrow: accounts.new_lp_escrow,
position_mint: accounts.position_mint,
position: accounts.position,
position_token_account: accounts.position_token_account,
new_position_token_account: accounts.new_position_token_account,
lock_config: accounts.lock_config,
system_program: accounts.system_program,
token22_program: accounts.token22_program,
ata_program: accounts.ata_program,
whirlpool_program: accounts.whirlpool_program,
}
}
#[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(15 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
*self.authority.key,
true,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.authority_config.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.lp_authority.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.new_lp_authority.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.lp_escrow.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.new_lp_escrow.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.position_mint.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.position.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.position_token_account.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.new_position_token_account.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.lock_config.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.system_program.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.token22_program.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.ata_program.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.whirlpool_program.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 data = borsh::to_vec(&LpTakeoverInstructionData::new()).unwrap();
let instruction = solana_instruction::Instruction {
program_id: crate::WAVEBREAK_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(16 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.authority.clone());
account_infos.push(self.authority_config.clone());
account_infos.push(self.lp_authority.clone());
account_infos.push(self.new_lp_authority.clone());
account_infos.push(self.lp_escrow.clone());
account_infos.push(self.new_lp_escrow.clone());
account_infos.push(self.position_mint.clone());
account_infos.push(self.position.clone());
account_infos.push(self.position_token_account.clone());
account_infos.push(self.new_position_token_account.clone());
account_infos.push(self.lock_config.clone());
account_infos.push(self.system_program.clone());
account_infos.push(self.token22_program.clone());
account_infos.push(self.ata_program.clone());
account_infos.push(self.whirlpool_program.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 LpTakeoverCpiBuilder<'a, 'b> {
instruction: Box<LpTakeoverCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> LpTakeoverCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(LpTakeoverCpiBuilderInstruction {
__program: program,
authority: None,
authority_config: None,
lp_authority: None,
new_lp_authority: None,
lp_escrow: None,
new_lp_escrow: None,
position_mint: None,
position: None,
position_token_account: None,
new_position_token_account: None,
lock_config: None,
system_program: None,
token22_program: None,
ata_program: None,
whirlpool_program: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn authority(&mut self, authority: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.authority = Some(authority);
self
}
#[inline(always)]
pub fn authority_config(
&mut self,
authority_config: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.authority_config = Some(authority_config);
self
}
#[inline(always)]
pub fn lp_authority(
&mut self,
lp_authority: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.lp_authority = Some(lp_authority);
self
}
#[inline(always)]
pub fn new_lp_authority(
&mut self,
new_lp_authority: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.new_lp_authority = Some(new_lp_authority);
self
}
#[inline(always)]
pub fn lp_escrow(&mut self, lp_escrow: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.lp_escrow = Some(lp_escrow);
self
}
#[inline(always)]
pub fn new_lp_escrow(
&mut self,
new_lp_escrow: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.new_lp_escrow = Some(new_lp_escrow);
self
}
#[inline(always)]
pub fn position_mint(
&mut self,
position_mint: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.position_mint = Some(position_mint);
self
}
#[inline(always)]
pub fn position(&mut self, position: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.position = Some(position);
self
}
#[inline(always)]
pub fn position_token_account(
&mut self,
position_token_account: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.position_token_account = Some(position_token_account);
self
}
#[inline(always)]
pub fn new_position_token_account(
&mut self,
new_position_token_account: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.new_position_token_account = Some(new_position_token_account);
self
}
#[inline(always)]
pub fn lock_config(
&mut self,
lock_config: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.lock_config = Some(lock_config);
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 token22_program(
&mut self,
token22_program: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.token22_program = Some(token22_program);
self
}
#[inline(always)]
pub fn ata_program(
&mut self,
ata_program: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.ata_program = Some(ata_program);
self
}
#[inline(always)]
pub fn whirlpool_program(
&mut self,
whirlpool_program: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.whirlpool_program = Some(whirlpool_program);
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 instruction = LpTakeoverCpi {
__program: self.instruction.__program,
authority: self.instruction.authority.expect("authority is not set"),
authority_config: self
.instruction
.authority_config
.expect("authority_config is not set"),
lp_authority: self
.instruction
.lp_authority
.expect("lp_authority is not set"),
new_lp_authority: self
.instruction
.new_lp_authority
.expect("new_lp_authority is not set"),
lp_escrow: self.instruction.lp_escrow.expect("lp_escrow is not set"),
new_lp_escrow: self
.instruction
.new_lp_escrow
.expect("new_lp_escrow is not set"),
position_mint: self
.instruction
.position_mint
.expect("position_mint is not set"),
position: self.instruction.position.expect("position is not set"),
position_token_account: self
.instruction
.position_token_account
.expect("position_token_account is not set"),
new_position_token_account: self
.instruction
.new_position_token_account
.expect("new_position_token_account is not set"),
lock_config: self
.instruction
.lock_config
.expect("lock_config is not set"),
system_program: self
.instruction
.system_program
.expect("system_program is not set"),
token22_program: self
.instruction
.token22_program
.expect("token22_program is not set"),
ata_program: self
.instruction
.ata_program
.expect("ata_program is not set"),
whirlpool_program: self
.instruction
.whirlpool_program
.expect("whirlpool_program is not set"),
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
#[derive(Clone, Debug)]
struct LpTakeoverCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_account_info::AccountInfo<'a>,
authority: Option<&'b solana_account_info::AccountInfo<'a>>,
authority_config: Option<&'b solana_account_info::AccountInfo<'a>>,
lp_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
new_lp_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
lp_escrow: Option<&'b solana_account_info::AccountInfo<'a>>,
new_lp_escrow: Option<&'b solana_account_info::AccountInfo<'a>>,
position_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
position: Option<&'b solana_account_info::AccountInfo<'a>>,
position_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
new_position_token_account: Option<&'b solana_account_info::AccountInfo<'a>>,
lock_config: Option<&'b solana_account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
token22_program: Option<&'b solana_account_info::AccountInfo<'a>>,
ata_program: Option<&'b solana_account_info::AccountInfo<'a>>,
whirlpool_program: Option<&'b solana_account_info::AccountInfo<'a>>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}