use borsh::BorshDeserialize;
use borsh::BorshSerialize;
#[derive(Debug)]
pub struct SweepFees {
pub market: solana_pubkey::Pubkey,
pub pc_vault: solana_pubkey::Pubkey,
pub fee_sweeping_authority: solana_pubkey::Pubkey,
pub fee_receivable: solana_pubkey::Pubkey,
pub vault_signer: solana_pubkey::Pubkey,
pub spl_token_program: solana_pubkey::Pubkey,
}
impl SweepFees {
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(6 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(self.market, false));
accounts.push(solana_instruction::AccountMeta::new(self.pc_vault, false));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.fee_sweeping_authority,
true,
));
accounts.push(solana_instruction::AccountMeta::new(
self.fee_receivable,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.vault_signer,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.spl_token_program,
false,
));
accounts.extend_from_slice(remaining_accounts);
let data = borsh::to_vec(&SweepFeesInstructionData::new()).unwrap();
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 SweepFeesInstructionData {
discriminator: [u8; 8],
}
impl SweepFeesInstructionData {
pub fn new() -> Self {
Self {
discriminator: [175, 225, 98, 71, 118, 66, 34, 148],
}
}
}
impl Default for SweepFeesInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, Debug, Default)]
pub struct SweepFeesBuilder {
market: Option<solana_pubkey::Pubkey>,
pc_vault: Option<solana_pubkey::Pubkey>,
fee_sweeping_authority: Option<solana_pubkey::Pubkey>,
fee_receivable: Option<solana_pubkey::Pubkey>,
vault_signer: Option<solana_pubkey::Pubkey>,
spl_token_program: Option<solana_pubkey::Pubkey>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl SweepFeesBuilder {
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 pc_vault(&mut self, pc_vault: solana_pubkey::Pubkey) -> &mut Self {
self.pc_vault = Some(pc_vault);
self
}
#[inline(always)]
pub fn fee_sweeping_authority(
&mut self,
fee_sweeping_authority: solana_pubkey::Pubkey,
) -> &mut Self {
self.fee_sweeping_authority = Some(fee_sweeping_authority);
self
}
#[inline(always)]
pub fn fee_receivable(&mut self, fee_receivable: solana_pubkey::Pubkey) -> &mut Self {
self.fee_receivable = Some(fee_receivable);
self
}
#[inline(always)]
pub fn vault_signer(&mut self, vault_signer: solana_pubkey::Pubkey) -> &mut Self {
self.vault_signer = Some(vault_signer);
self
}
#[inline(always)]
pub fn spl_token_program(&mut self, spl_token_program: solana_pubkey::Pubkey) -> &mut Self {
self.spl_token_program = Some(spl_token_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 = SweepFees {
market: self.market.expect("market is not set"),
pc_vault: self.pc_vault.expect("pc_vault is not set"),
fee_sweeping_authority: self
.fee_sweeping_authority
.expect("fee_sweeping_authority is not set"),
fee_receivable: self.fee_receivable.expect("fee_receivable is not set"),
vault_signer: self.vault_signer.expect("vault_signer is not set"),
spl_token_program: self.spl_token_program.unwrap_or(solana_pubkey::pubkey!(
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
)),
};
accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
}
}
pub struct SweepFeesCpiAccounts<'a, 'b> {
pub market: &'b solana_account_info::AccountInfo<'a>,
pub pc_vault: &'b solana_account_info::AccountInfo<'a>,
pub fee_sweeping_authority: &'b solana_account_info::AccountInfo<'a>,
pub fee_receivable: &'b solana_account_info::AccountInfo<'a>,
pub vault_signer: &'b solana_account_info::AccountInfo<'a>,
pub spl_token_program: &'b solana_account_info::AccountInfo<'a>,
}
pub struct SweepFeesCpi<'a, 'b> {
pub __program: &'b solana_account_info::AccountInfo<'a>,
pub market: &'b solana_account_info::AccountInfo<'a>,
pub pc_vault: &'b solana_account_info::AccountInfo<'a>,
pub fee_sweeping_authority: &'b solana_account_info::AccountInfo<'a>,
pub fee_receivable: &'b solana_account_info::AccountInfo<'a>,
pub vault_signer: &'b solana_account_info::AccountInfo<'a>,
pub spl_token_program: &'b solana_account_info::AccountInfo<'a>,
}
impl<'a, 'b> SweepFeesCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: SweepFeesCpiAccounts<'a, 'b>,
) -> Self {
Self {
__program: program,
market: accounts.market,
pc_vault: accounts.pc_vault,
fee_sweeping_authority: accounts.fee_sweeping_authority,
fee_receivable: accounts.fee_receivable,
vault_signer: accounts.vault_signer,
spl_token_program: accounts.spl_token_program,
}
}
#[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(6 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
*self.market.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.pc_vault.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.fee_sweeping_authority.key,
true,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.fee_receivable.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.vault_signer.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.spl_token_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(&SweepFeesInstructionData::new()).unwrap();
let instruction = solana_instruction::Instruction {
program_id: crate::OPEN_BOOK_DEX_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(7 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.market.clone());
account_infos.push(self.pc_vault.clone());
account_infos.push(self.fee_sweeping_authority.clone());
account_infos.push(self.fee_receivable.clone());
account_infos.push(self.vault_signer.clone());
account_infos.push(self.spl_token_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 SweepFeesCpiBuilder<'a, 'b> {
instruction: Box<SweepFeesCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> SweepFeesCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(SweepFeesCpiBuilderInstruction {
__program: program,
market: None,
pc_vault: None,
fee_sweeping_authority: None,
fee_receivable: None,
vault_signer: None,
spl_token_program: 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 pc_vault(&mut self, pc_vault: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.pc_vault = Some(pc_vault);
self
}
#[inline(always)]
pub fn fee_sweeping_authority(
&mut self,
fee_sweeping_authority: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.fee_sweeping_authority = Some(fee_sweeping_authority);
self
}
#[inline(always)]
pub fn fee_receivable(
&mut self,
fee_receivable: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.fee_receivable = Some(fee_receivable);
self
}
#[inline(always)]
pub fn vault_signer(
&mut self,
vault_signer: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.vault_signer = Some(vault_signer);
self
}
#[inline(always)]
pub fn spl_token_program(
&mut self,
spl_token_program: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.spl_token_program = Some(spl_token_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_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 instruction = SweepFeesCpi {
__program: self.instruction.__program,
market: self.instruction.market.expect("market is not set"),
pc_vault: self.instruction.pc_vault.expect("pc_vault is not set"),
fee_sweeping_authority: self
.instruction
.fee_sweeping_authority
.expect("fee_sweeping_authority is not set"),
fee_receivable: self
.instruction
.fee_receivable
.expect("fee_receivable is not set"),
vault_signer: self
.instruction
.vault_signer
.expect("vault_signer is not set"),
spl_token_program: self
.instruction
.spl_token_program
.expect("spl_token_program is not set"),
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
#[derive(Clone, Debug)]
struct SweepFeesCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_account_info::AccountInfo<'a>,
market: Option<&'b solana_account_info::AccountInfo<'a>>,
pc_vault: Option<&'b solana_account_info::AccountInfo<'a>>,
fee_sweeping_authority: Option<&'b solana_account_info::AccountInfo<'a>>,
fee_receivable: Option<&'b solana_account_info::AccountInfo<'a>>,
vault_signer: Option<&'b solana_account_info::AccountInfo<'a>>,
spl_token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}