use borsh::BorshDeserialize;
use borsh::BorshSerialize;
pub struct WithdrawProtocolFees {
pub pool: solana_program::pubkey::Pubkey,
pub a_vault_lp: solana_program::pubkey::Pubkey,
pub protocol_token_a_fee: solana_program::pubkey::Pubkey,
pub protocol_token_b_fee: solana_program::pubkey::Pubkey,
pub treasury_token_a: solana_program::pubkey::Pubkey,
pub treasury_token_b: solana_program::pubkey::Pubkey,
pub token_program: solana_program::pubkey::Pubkey,
}
impl WithdrawProtocolFees {
pub fn instruction(&self) -> solana_program::instruction::Instruction {
self.instruction_with_remaining_accounts(&[])
}
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(
&self,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.pool, false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.a_vault_lp,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.protocol_token_a_fee,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.protocol_token_b_fee,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.treasury_token_a,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.treasury_token_b,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.token_program,
false,
));
accounts.extend_from_slice(remaining_accounts);
let data = WithdrawProtocolFeesInstructionData::new()
.try_to_vec()
.unwrap();
solana_program::instruction::Instruction {
program_id: crate::AMM_ID,
accounts,
data,
}
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WithdrawProtocolFeesInstructionData {
discriminator: [u8; 8],
}
impl WithdrawProtocolFeesInstructionData {
pub fn new() -> Self {
Self {
discriminator: [11, 68, 165, 98, 18, 208, 134, 73],
}
}
}
impl Default for WithdrawProtocolFeesInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(Clone, Debug, Default)]
pub struct WithdrawProtocolFeesBuilder {
pool: Option<solana_program::pubkey::Pubkey>,
a_vault_lp: Option<solana_program::pubkey::Pubkey>,
protocol_token_a_fee: Option<solana_program::pubkey::Pubkey>,
protocol_token_b_fee: Option<solana_program::pubkey::Pubkey>,
treasury_token_a: Option<solana_program::pubkey::Pubkey>,
treasury_token_b: Option<solana_program::pubkey::Pubkey>,
token_program: Option<solana_program::pubkey::Pubkey>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}
impl WithdrawProtocolFeesBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn pool(&mut self, pool: solana_program::pubkey::Pubkey) -> &mut Self {
self.pool = Some(pool);
self
}
#[inline(always)]
pub fn a_vault_lp(&mut self, a_vault_lp: solana_program::pubkey::Pubkey) -> &mut Self {
self.a_vault_lp = Some(a_vault_lp);
self
}
#[inline(always)]
pub fn protocol_token_a_fee(
&mut self,
protocol_token_a_fee: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.protocol_token_a_fee = Some(protocol_token_a_fee);
self
}
#[inline(always)]
pub fn protocol_token_b_fee(
&mut self,
protocol_token_b_fee: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.protocol_token_b_fee = Some(protocol_token_b_fee);
self
}
#[inline(always)]
pub fn treasury_token_a(
&mut self,
treasury_token_a: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.treasury_token_a = Some(treasury_token_a);
self
}
#[inline(always)]
pub fn treasury_token_b(
&mut self,
treasury_token_b: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.treasury_token_b = Some(treasury_token_b);
self
}
#[inline(always)]
pub fn token_program(&mut self, token_program: solana_program::pubkey::Pubkey) -> &mut Self {
self.token_program = Some(token_program);
self
}
#[inline(always)]
pub fn add_remaining_account(
&mut self,
account: solana_program::instruction::AccountMeta,
) -> &mut Self {
self.__remaining_accounts.push(account);
self
}
#[inline(always)]
pub fn add_remaining_accounts(
&mut self,
accounts: &[solana_program::instruction::AccountMeta],
) -> &mut Self {
self.__remaining_accounts.extend_from_slice(accounts);
self
}
#[allow(clippy::clone_on_copy)]
pub fn instruction(&self) -> solana_program::instruction::Instruction {
let accounts = WithdrawProtocolFees {
pool: self.pool.expect("pool is not set"),
a_vault_lp: self.a_vault_lp.expect("a_vault_lp is not set"),
protocol_token_a_fee: self
.protocol_token_a_fee
.expect("protocol_token_a_fee is not set"),
protocol_token_b_fee: self
.protocol_token_b_fee
.expect("protocol_token_b_fee is not set"),
treasury_token_a: self.treasury_token_a.expect("treasury_token_a is not set"),
treasury_token_b: self.treasury_token_b.expect("treasury_token_b is not set"),
token_program: self.token_program.unwrap_or(solana_program::pubkey!(
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
)),
};
accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
}
}
pub struct WithdrawProtocolFeesCpiAccounts<'a, 'b> {
pub pool: &'b solana_program::account_info::AccountInfo<'a>,
pub a_vault_lp: &'b solana_program::account_info::AccountInfo<'a>,
pub protocol_token_a_fee: &'b solana_program::account_info::AccountInfo<'a>,
pub protocol_token_b_fee: &'b solana_program::account_info::AccountInfo<'a>,
pub treasury_token_a: &'b solana_program::account_info::AccountInfo<'a>,
pub treasury_token_b: &'b solana_program::account_info::AccountInfo<'a>,
pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
}
pub struct WithdrawProtocolFeesCpi<'a, 'b> {
pub __program: &'b solana_program::account_info::AccountInfo<'a>,
pub pool: &'b solana_program::account_info::AccountInfo<'a>,
pub a_vault_lp: &'b solana_program::account_info::AccountInfo<'a>,
pub protocol_token_a_fee: &'b solana_program::account_info::AccountInfo<'a>,
pub protocol_token_b_fee: &'b solana_program::account_info::AccountInfo<'a>,
pub treasury_token_a: &'b solana_program::account_info::AccountInfo<'a>,
pub treasury_token_b: &'b solana_program::account_info::AccountInfo<'a>,
pub token_program: &'b solana_program::account_info::AccountInfo<'a>,
}
impl<'a, 'b> WithdrawProtocolFeesCpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: WithdrawProtocolFeesCpiAccounts<'a, 'b>,
) -> Self {
Self {
__program: program,
pool: accounts.pool,
a_vault_lp: accounts.a_vault_lp,
protocol_token_a_fee: accounts.protocol_token_a_fee,
protocol_token_b_fee: accounts.protocol_token_b_fee,
treasury_token_a: accounts.treasury_token_a,
treasury_token_b: accounts.treasury_token_b,
token_program: accounts.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_program::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::clone_on_copy)]
#[allow(clippy::vec_init_then_push)]
pub fn invoke_signed_with_remaining_accounts(
&self,
signers_seeds: &[&[&[u8]]],
remaining_accounts: &[(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)],
) -> solana_program::entrypoint::ProgramResult {
let mut accounts = Vec::with_capacity(7 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.pool.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.a_vault_lp.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.protocol_token_a_fee.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.protocol_token_b_fee.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.treasury_token_a.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.treasury_token_b.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.token_program.key,
false,
));
remaining_accounts.iter().for_each(|remaining_account| {
accounts.push(solana_program::instruction::AccountMeta {
pubkey: *remaining_account.0.key,
is_signer: remaining_account.1,
is_writable: remaining_account.2,
})
});
let data = WithdrawProtocolFeesInstructionData::new()
.try_to_vec()
.unwrap();
let instruction = solana_program::instruction::Instruction {
program_id: crate::AMM_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(8 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.pool.clone());
account_infos.push(self.a_vault_lp.clone());
account_infos.push(self.protocol_token_a_fee.clone());
account_infos.push(self.protocol_token_b_fee.clone());
account_infos.push(self.treasury_token_a.clone());
account_infos.push(self.treasury_token_b.clone());
account_infos.push(self.token_program.clone());
remaining_accounts
.iter()
.for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
if signers_seeds.is_empty() {
solana_program::program::invoke(&instruction, &account_infos)
} else {
solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
}
}
}
#[derive(Clone, Debug)]
pub struct WithdrawProtocolFeesCpiBuilder<'a, 'b> {
instruction: Box<WithdrawProtocolFeesCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> WithdrawProtocolFeesCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(WithdrawProtocolFeesCpiBuilderInstruction {
__program: program,
pool: None,
a_vault_lp: None,
protocol_token_a_fee: None,
protocol_token_b_fee: None,
treasury_token_a: None,
treasury_token_b: None,
token_program: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn pool(&mut self, pool: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.pool = Some(pool);
self
}
#[inline(always)]
pub fn a_vault_lp(
&mut self,
a_vault_lp: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.a_vault_lp = Some(a_vault_lp);
self
}
#[inline(always)]
pub fn protocol_token_a_fee(
&mut self,
protocol_token_a_fee: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.protocol_token_a_fee = Some(protocol_token_a_fee);
self
}
#[inline(always)]
pub fn protocol_token_b_fee(
&mut self,
protocol_token_b_fee: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.protocol_token_b_fee = Some(protocol_token_b_fee);
self
}
#[inline(always)]
pub fn treasury_token_a(
&mut self,
treasury_token_a: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.treasury_token_a = Some(treasury_token_a);
self
}
#[inline(always)]
pub fn treasury_token_b(
&mut self,
treasury_token_b: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.treasury_token_b = Some(treasury_token_b);
self
}
#[inline(always)]
pub fn token_program(
&mut self,
token_program: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.token_program = Some(token_program);
self
}
#[inline(always)]
pub fn add_remaining_account(
&mut self,
account: &'b solana_program::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_program::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 = WithdrawProtocolFeesCpi {
__program: self.instruction.__program,
pool: self.instruction.pool.expect("pool is not set"),
a_vault_lp: self.instruction.a_vault_lp.expect("a_vault_lp is not set"),
protocol_token_a_fee: self
.instruction
.protocol_token_a_fee
.expect("protocol_token_a_fee is not set"),
protocol_token_b_fee: self
.instruction
.protocol_token_b_fee
.expect("protocol_token_b_fee is not set"),
treasury_token_a: self
.instruction
.treasury_token_a
.expect("treasury_token_a is not set"),
treasury_token_b: self
.instruction
.treasury_token_b
.expect("treasury_token_b is not set"),
token_program: self
.instruction
.token_program
.expect("token_program is not set"),
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
#[derive(Clone, Debug)]
struct WithdrawProtocolFeesCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
pool: Option<&'b solana_program::account_info::AccountInfo<'a>>,
a_vault_lp: Option<&'b solana_program::account_info::AccountInfo<'a>>,
protocol_token_a_fee: Option<&'b solana_program::account_info::AccountInfo<'a>>,
protocol_token_b_fee: Option<&'b solana_program::account_info::AccountInfo<'a>>,
treasury_token_a: Option<&'b solana_program::account_info::AccountInfo<'a>>,
treasury_token_b: Option<&'b solana_program::account_info::AccountInfo<'a>>,
token_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}