use borsh::BorshDeserialize;
use borsh::BorshSerialize;
#[derive(Debug)]
pub struct InitializeReward {
pub reward_funder: solana_pubkey::Pubkey,
pub funder_token_account: solana_pubkey::Pubkey,
pub amm_config: solana_pubkey::Pubkey,
pub pool_state: solana_pubkey::Pubkey,
pub operation_state: solana_pubkey::Pubkey,
pub reward_token_mint: solana_pubkey::Pubkey,
pub reward_token_vault: solana_pubkey::Pubkey,
pub reward_token_program: solana_pubkey::Pubkey,
pub system_program: solana_pubkey::Pubkey,
pub rent: solana_pubkey::Pubkey,
}
impl InitializeReward {
pub fn instruction(
&self,
args: InitializeRewardInstructionArgs,
) -> 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: InitializeRewardInstructionArgs,
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.reward_funder,
true,
));
accounts.push(solana_instruction::AccountMeta::new(
self.funder_token_account,
false,
));
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.operation_state,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.reward_token_mint,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
self.reward_token_vault,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.reward_token_program,
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(&InitializeRewardInstructionData::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 InitializeRewardInstructionData {
discriminator: [u8; 8],
}
impl InitializeRewardInstructionData {
pub fn new() -> Self {
Self {
discriminator: [95, 135, 192, 196, 242, 129, 230, 68],
}
}
}
impl Default for InitializeRewardInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct InitializeRewardInstructionArgs {
pub open_time: u64,
pub end_time: u64,
pub emissions_per_second_x64: u128,
}
#[derive(Clone, Debug, Default)]
pub struct InitializeRewardBuilder {
reward_funder: Option<solana_pubkey::Pubkey>,
funder_token_account: Option<solana_pubkey::Pubkey>,
amm_config: Option<solana_pubkey::Pubkey>,
pool_state: Option<solana_pubkey::Pubkey>,
operation_state: Option<solana_pubkey::Pubkey>,
reward_token_mint: Option<solana_pubkey::Pubkey>,
reward_token_vault: Option<solana_pubkey::Pubkey>,
reward_token_program: Option<solana_pubkey::Pubkey>,
system_program: Option<solana_pubkey::Pubkey>,
rent: Option<solana_pubkey::Pubkey>,
open_time: Option<u64>,
end_time: Option<u64>,
emissions_per_second_x64: Option<u128>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl InitializeRewardBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn reward_funder(&mut self, reward_funder: solana_pubkey::Pubkey) -> &mut Self {
self.reward_funder = Some(reward_funder);
self
}
#[inline(always)]
pub fn funder_token_account(
&mut self,
funder_token_account: solana_pubkey::Pubkey,
) -> &mut Self {
self.funder_token_account = Some(funder_token_account);
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 operation_state(&mut self, operation_state: solana_pubkey::Pubkey) -> &mut Self {
self.operation_state = Some(operation_state);
self
}
#[inline(always)]
pub fn reward_token_mint(&mut self, reward_token_mint: solana_pubkey::Pubkey) -> &mut Self {
self.reward_token_mint = Some(reward_token_mint);
self
}
#[inline(always)]
pub fn reward_token_vault(&mut self, reward_token_vault: solana_pubkey::Pubkey) -> &mut Self {
self.reward_token_vault = Some(reward_token_vault);
self
}
#[inline(always)]
pub fn reward_token_program(
&mut self,
reward_token_program: solana_pubkey::Pubkey,
) -> &mut Self {
self.reward_token_program = Some(reward_token_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 rent(&mut self, rent: solana_pubkey::Pubkey) -> &mut Self {
self.rent = Some(rent);
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 end_time(&mut self, end_time: u64) -> &mut Self {
self.end_time = Some(end_time);
self
}
#[inline(always)]
pub fn emissions_per_second_x64(&mut self, emissions_per_second_x64: u128) -> &mut Self {
self.emissions_per_second_x64 = Some(emissions_per_second_x64);
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 = InitializeReward {
reward_funder: self.reward_funder.expect("reward_funder is not set"),
funder_token_account: self
.funder_token_account
.expect("funder_token_account 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"),
operation_state: self.operation_state.expect("operation_state is not set"),
reward_token_mint: self
.reward_token_mint
.expect("reward_token_mint is not set"),
reward_token_vault: self
.reward_token_vault
.expect("reward_token_vault is not set"),
reward_token_program: self
.reward_token_program
.expect("reward_token_program 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 = InitializeRewardInstructionArgs {
open_time: self.open_time.clone().expect("open_time is not set"),
end_time: self.end_time.clone().expect("end_time is not set"),
emissions_per_second_x64: self
.emissions_per_second_x64
.clone()
.expect("emissions_per_second_x64 is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct InitializeRewardCpiAccounts<'a, 'b> {
pub reward_funder: &'b solana_account_info::AccountInfo<'a>,
pub funder_token_account: &'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 operation_state: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_mint: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_vault: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_program: &'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 InitializeRewardCpi<'a, 'b> {
pub __program: &'b solana_account_info::AccountInfo<'a>,
pub reward_funder: &'b solana_account_info::AccountInfo<'a>,
pub funder_token_account: &'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 operation_state: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_mint: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_vault: &'b solana_account_info::AccountInfo<'a>,
pub reward_token_program: &'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: InitializeRewardInstructionArgs,
}
impl<'a, 'b> InitializeRewardCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: InitializeRewardCpiAccounts<'a, 'b>,
args: InitializeRewardInstructionArgs,
) -> Self {
Self {
__program: program,
reward_funder: accounts.reward_funder,
funder_token_account: accounts.funder_token_account,
amm_config: accounts.amm_config,
pool_state: accounts.pool_state,
operation_state: accounts.operation_state,
reward_token_mint: accounts.reward_token_mint,
reward_token_vault: accounts.reward_token_vault,
reward_token_program: accounts.reward_token_program,
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(10 + remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
*self.reward_funder.key,
true,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.funder_token_account.key,
false,
));
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.operation_state.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.reward_token_mint.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new(
*self.reward_token_vault.key,
false,
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.reward_token_program.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(&InitializeRewardInstructionData::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(11 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.reward_funder.clone());
account_infos.push(self.funder_token_account.clone());
account_infos.push(self.amm_config.clone());
account_infos.push(self.pool_state.clone());
account_infos.push(self.operation_state.clone());
account_infos.push(self.reward_token_mint.clone());
account_infos.push(self.reward_token_vault.clone());
account_infos.push(self.reward_token_program.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 InitializeRewardCpiBuilder<'a, 'b> {
instruction: Box<InitializeRewardCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> InitializeRewardCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(InitializeRewardCpiBuilderInstruction {
__program: program,
reward_funder: None,
funder_token_account: None,
amm_config: None,
pool_state: None,
operation_state: None,
reward_token_mint: None,
reward_token_vault: None,
reward_token_program: None,
system_program: None,
rent: None,
open_time: None,
end_time: None,
emissions_per_second_x64: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn reward_funder(
&mut self,
reward_funder: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.reward_funder = Some(reward_funder);
self
}
#[inline(always)]
pub fn funder_token_account(
&mut self,
funder_token_account: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.funder_token_account = Some(funder_token_account);
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 operation_state(
&mut self,
operation_state: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.operation_state = Some(operation_state);
self
}
#[inline(always)]
pub fn reward_token_mint(
&mut self,
reward_token_mint: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.reward_token_mint = Some(reward_token_mint);
self
}
#[inline(always)]
pub fn reward_token_vault(
&mut self,
reward_token_vault: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.reward_token_vault = Some(reward_token_vault);
self
}
#[inline(always)]
pub fn reward_token_program(
&mut self,
reward_token_program: &'b solana_account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.reward_token_program = Some(reward_token_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 rent(&mut self, rent: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.rent = Some(rent);
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 end_time(&mut self, end_time: u64) -> &mut Self {
self.instruction.end_time = Some(end_time);
self
}
#[inline(always)]
pub fn emissions_per_second_x64(&mut self, emissions_per_second_x64: u128) -> &mut Self {
self.instruction.emissions_per_second_x64 = Some(emissions_per_second_x64);
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 = InitializeRewardInstructionArgs {
open_time: self
.instruction
.open_time
.clone()
.expect("open_time is not set"),
end_time: self
.instruction
.end_time
.clone()
.expect("end_time is not set"),
emissions_per_second_x64: self
.instruction
.emissions_per_second_x64
.clone()
.expect("emissions_per_second_x64 is not set"),
};
let instruction = InitializeRewardCpi {
__program: self.instruction.__program,
reward_funder: self
.instruction
.reward_funder
.expect("reward_funder is not set"),
funder_token_account: self
.instruction
.funder_token_account
.expect("funder_token_account 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"),
operation_state: self
.instruction
.operation_state
.expect("operation_state is not set"),
reward_token_mint: self
.instruction
.reward_token_mint
.expect("reward_token_mint is not set"),
reward_token_vault: self
.instruction
.reward_token_vault
.expect("reward_token_vault is not set"),
reward_token_program: self
.instruction
.reward_token_program
.expect("reward_token_program 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 InitializeRewardCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_account_info::AccountInfo<'a>,
reward_funder: Option<&'b solana_account_info::AccountInfo<'a>>,
funder_token_account: 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>>,
operation_state: Option<&'b solana_account_info::AccountInfo<'a>>,
reward_token_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
reward_token_vault: Option<&'b solana_account_info::AccountInfo<'a>>,
reward_token_program: Option<&'b solana_account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
rent: Option<&'b solana_account_info::AccountInfo<'a>>,
open_time: Option<u64>,
end_time: Option<u64>,
emissions_per_second_x64: Option<u128>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}