use solana_pubkey::Pubkey;
use borsh::BorshSerialize;
use borsh::BorshDeserialize;
#[derive(Debug)]
pub struct CreateTreasury {
pub authority: solana_pubkey::Pubkey,
pub staked_token_mint: solana_pubkey::Pubkey,
pub treasury: solana_pubkey::Pubkey,
pub system_program: solana_pubkey::Pubkey,
pub rent: solana_pubkey::Pubkey,
}
impl CreateTreasury {
pub fn instruction(&self, args: CreateTreasuryInstructionArgs) -> 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: CreateTreasuryInstructionArgs, remaining_accounts: &[solana_instruction::AccountMeta]) -> solana_instruction::Instruction {
let mut accounts = Vec::with_capacity(5+ remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
self.authority,
true
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
self.staked_token_mint,
false
));
accounts.push(solana_instruction::AccountMeta::new(
self.treasury,
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(&CreateTreasuryInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&args).unwrap();
data.append(&mut args);
solana_instruction::Instruction {
program_id: crate::TUNA_STAKING_ID,
accounts,
data,
}
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateTreasuryInstructionData {
discriminator: [u8; 8],
}
impl CreateTreasuryInstructionData {
pub fn new() -> Self {
Self {
discriminator: [254, 98, 217, 51, 25, 88, 140, 45],
}
}
}
impl Default for CreateTreasuryInstructionData {
fn default() -> Self {
Self::new()
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateTreasuryInstructionArgs {
pub reward_token_mint: Pubkey,
pub admin_authority: Pubkey,
pub swap_authority: Pubkey,
}
#[derive(Clone, Debug, Default)]
pub struct CreateTreasuryBuilder {
authority: Option<solana_pubkey::Pubkey>,
staked_token_mint: Option<solana_pubkey::Pubkey>,
treasury: Option<solana_pubkey::Pubkey>,
system_program: Option<solana_pubkey::Pubkey>,
rent: Option<solana_pubkey::Pubkey>,
reward_token_mint: Option<Pubkey>,
admin_authority: Option<Pubkey>,
swap_authority: Option<Pubkey>,
__remaining_accounts: Vec<solana_instruction::AccountMeta>,
}
impl CreateTreasuryBuilder {
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 staked_token_mint(&mut self, staked_token_mint: solana_pubkey::Pubkey) -> &mut Self {
self.staked_token_mint = Some(staked_token_mint);
self
}
#[inline(always)]
pub fn treasury(&mut self, treasury: solana_pubkey::Pubkey) -> &mut Self {
self.treasury = Some(treasury);
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 reward_token_mint(&mut self, reward_token_mint: Pubkey) -> &mut Self {
self.reward_token_mint = Some(reward_token_mint);
self
}
#[inline(always)]
pub fn admin_authority(&mut self, admin_authority: Pubkey) -> &mut Self {
self.admin_authority = Some(admin_authority);
self
}
#[inline(always)]
pub fn swap_authority(&mut self, swap_authority: Pubkey) -> &mut Self {
self.swap_authority = Some(swap_authority);
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 = CreateTreasury {
authority: self.authority.expect("authority is not set"),
staked_token_mint: self.staked_token_mint.expect("staked_token_mint is not set"),
treasury: self.treasury.expect("treasury 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 = CreateTreasuryInstructionArgs {
reward_token_mint: self.reward_token_mint.clone().expect("reward_token_mint is not set"),
admin_authority: self.admin_authority.clone().expect("admin_authority is not set"),
swap_authority: self.swap_authority.clone().expect("swap_authority is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct CreateTreasuryCpiAccounts<'a, 'b> {
pub authority: &'b solana_account_info::AccountInfo<'a>,
pub staked_token_mint: &'b solana_account_info::AccountInfo<'a>,
pub treasury: &'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 CreateTreasuryCpi<'a, 'b> {
pub __program: &'b solana_account_info::AccountInfo<'a>,
pub authority: &'b solana_account_info::AccountInfo<'a>,
pub staked_token_mint: &'b solana_account_info::AccountInfo<'a>,
pub treasury: &'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: CreateTreasuryInstructionArgs,
}
impl<'a, 'b> CreateTreasuryCpi<'a, 'b> {
pub fn new(
program: &'b solana_account_info::AccountInfo<'a>,
accounts: CreateTreasuryCpiAccounts<'a, 'b>,
args: CreateTreasuryInstructionArgs,
) -> Self {
Self {
__program: program,
authority: accounts.authority,
staked_token_mint: accounts.staked_token_mint,
treasury: accounts.treasury,
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(5+ remaining_accounts.len());
accounts.push(solana_instruction::AccountMeta::new(
*self.authority.key,
true
));
accounts.push(solana_instruction::AccountMeta::new_readonly(
*self.staked_token_mint.key,
false
));
accounts.push(solana_instruction::AccountMeta::new(
*self.treasury.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(&CreateTreasuryInstructionData::new()).unwrap();
let mut args = borsh::to_vec(&self.__args).unwrap();
data.append(&mut args);
let instruction = solana_instruction::Instruction {
program_id: crate::TUNA_STAKING_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(6 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.authority.clone());
account_infos.push(self.staked_token_mint.clone());
account_infos.push(self.treasury.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 CreateTreasuryCpiBuilder<'a, 'b> {
instruction: Box<CreateTreasuryCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> CreateTreasuryCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(CreateTreasuryCpiBuilderInstruction {
__program: program,
authority: None,
staked_token_mint: None,
treasury: None,
system_program: None,
rent: None,
reward_token_mint: None,
admin_authority: None,
swap_authority: 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 staked_token_mint(&mut self, staked_token_mint: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.staked_token_mint = Some(staked_token_mint);
self
}
#[inline(always)]
pub fn treasury(&mut self, treasury: &'b solana_account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.treasury = Some(treasury);
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 reward_token_mint(&mut self, reward_token_mint: Pubkey) -> &mut Self {
self.instruction.reward_token_mint = Some(reward_token_mint);
self
}
#[inline(always)]
pub fn admin_authority(&mut self, admin_authority: Pubkey) -> &mut Self {
self.instruction.admin_authority = Some(admin_authority);
self
}
#[inline(always)]
pub fn swap_authority(&mut self, swap_authority: Pubkey) -> &mut Self {
self.instruction.swap_authority = Some(swap_authority);
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 = CreateTreasuryInstructionArgs {
reward_token_mint: self.instruction.reward_token_mint.clone().expect("reward_token_mint is not set"),
admin_authority: self.instruction.admin_authority.clone().expect("admin_authority is not set"),
swap_authority: self.instruction.swap_authority.clone().expect("swap_authority is not set"),
};
let instruction = CreateTreasuryCpi {
__program: self.instruction.__program,
authority: self.instruction.authority.expect("authority is not set"),
staked_token_mint: self.instruction.staked_token_mint.expect("staked_token_mint is not set"),
treasury: self.instruction.treasury.expect("treasury 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 CreateTreasuryCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_account_info::AccountInfo<'a>,
authority: Option<&'b solana_account_info::AccountInfo<'a>>,
staked_token_mint: Option<&'b solana_account_info::AccountInfo<'a>>,
treasury: Option<&'b solana_account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_account_info::AccountInfo<'a>>,
rent: Option<&'b solana_account_info::AccountInfo<'a>>,
reward_token_mint: Option<Pubkey>,
admin_authority: Option<Pubkey>,
swap_authority: Option<Pubkey>,
__remaining_accounts: Vec<(&'b solana_account_info::AccountInfo<'a>, bool, bool)>,
}