use crate::generated::types::MetadataArgs;
#[cfg(feature = "anchor")]
use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
#[cfg(not(feature = "anchor"))]
use borsh::{BorshDeserialize, BorshSerialize};
pub struct MintV1 {
pub tree_config: solana_program::pubkey::Pubkey,
pub leaf_owner: solana_program::pubkey::Pubkey,
pub leaf_delegate: solana_program::pubkey::Pubkey,
pub merkle_tree: solana_program::pubkey::Pubkey,
pub payer: solana_program::pubkey::Pubkey,
pub tree_creator_or_delegate: solana_program::pubkey::Pubkey,
pub log_wrapper: solana_program::pubkey::Pubkey,
pub compression_program: solana_program::pubkey::Pubkey,
pub system_program: solana_program::pubkey::Pubkey,
}
impl MintV1 {
pub fn instruction(
&self,
args: MintV1InstructionArgs,
) -> solana_program::instruction::Instruction {
self.instruction_with_remaining_accounts(args, &[])
}
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(
&self,
args: MintV1InstructionArgs,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
let mut accounts = Vec::with_capacity(9 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
self.tree_config,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.leaf_owner,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.leaf_delegate,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.merkle_tree,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.payer, true,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.tree_creator_or_delegate,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.log_wrapper,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.compression_program,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.system_program,
false,
));
accounts.extend_from_slice(remaining_accounts);
let mut data = borsh::to_vec(&(MintV1InstructionData::new())).unwrap();
let mut args = borsh::to_vec(&args).unwrap();
data.append(&mut args);
solana_program::instruction::Instruction {
program_id: crate::MPL_BUBBLEGUM_ID,
accounts,
data,
}
}
}
#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
pub struct MintV1InstructionData {
discriminator: [u8; 8],
}
impl MintV1InstructionData {
pub fn new() -> Self {
Self {
discriminator: [145, 98, 192, 118, 184, 147, 118, 104],
}
}
}
#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MintV1InstructionArgs {
pub metadata: MetadataArgs,
}
#[derive(Default)]
pub struct MintV1Builder {
tree_config: Option<solana_program::pubkey::Pubkey>,
leaf_owner: Option<solana_program::pubkey::Pubkey>,
leaf_delegate: Option<solana_program::pubkey::Pubkey>,
merkle_tree: Option<solana_program::pubkey::Pubkey>,
payer: Option<solana_program::pubkey::Pubkey>,
tree_creator_or_delegate: Option<solana_program::pubkey::Pubkey>,
log_wrapper: Option<solana_program::pubkey::Pubkey>,
compression_program: Option<solana_program::pubkey::Pubkey>,
system_program: Option<solana_program::pubkey::Pubkey>,
metadata: Option<MetadataArgs>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}
impl MintV1Builder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn tree_config(&mut self, tree_config: solana_program::pubkey::Pubkey) -> &mut Self {
self.tree_config = Some(tree_config);
self
}
#[inline(always)]
pub fn leaf_owner(&mut self, leaf_owner: solana_program::pubkey::Pubkey) -> &mut Self {
self.leaf_owner = Some(leaf_owner);
self
}
#[inline(always)]
pub fn leaf_delegate(&mut self, leaf_delegate: solana_program::pubkey::Pubkey) -> &mut Self {
self.leaf_delegate = Some(leaf_delegate);
self
}
#[inline(always)]
pub fn merkle_tree(&mut self, merkle_tree: solana_program::pubkey::Pubkey) -> &mut Self {
self.merkle_tree = Some(merkle_tree);
self
}
#[inline(always)]
pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
self.payer = Some(payer);
self
}
#[inline(always)]
pub fn tree_creator_or_delegate(
&mut self,
tree_creator_or_delegate: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.tree_creator_or_delegate = Some(tree_creator_or_delegate);
self
}
#[inline(always)]
pub fn log_wrapper(&mut self, log_wrapper: solana_program::pubkey::Pubkey) -> &mut Self {
self.log_wrapper = Some(log_wrapper);
self
}
#[inline(always)]
pub fn compression_program(
&mut self,
compression_program: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.compression_program = Some(compression_program);
self
}
#[inline(always)]
pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
self.system_program = Some(system_program);
self
}
#[inline(always)]
pub fn metadata(&mut self, metadata: MetadataArgs) -> &mut Self {
self.metadata = Some(metadata);
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 = MintV1 {
tree_config: self.tree_config.expect("tree_config is not set"),
leaf_owner: self.leaf_owner.expect("leaf_owner is not set"),
leaf_delegate: self.leaf_delegate.expect("leaf_delegate is not set"),
merkle_tree: self.merkle_tree.expect("merkle_tree is not set"),
payer: self.payer.expect("payer is not set"),
tree_creator_or_delegate: self
.tree_creator_or_delegate
.expect("tree_creator_or_delegate is not set"),
log_wrapper: self.log_wrapper.unwrap_or(solana_program::pubkey!(
"noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV"
)),
compression_program: self.compression_program.unwrap_or(solana_program::pubkey!(
"cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK"
)),
system_program: self
.system_program
.unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
};
let args = MintV1InstructionArgs {
metadata: self.metadata.clone().expect("metadata is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct MintV1CpiAccounts<'a, 'b> {
pub tree_config: &'b solana_program::account_info::AccountInfo<'a>,
pub leaf_owner: &'b solana_program::account_info::AccountInfo<'a>,
pub leaf_delegate: &'b solana_program::account_info::AccountInfo<'a>,
pub merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub tree_creator_or_delegate: &'b solana_program::account_info::AccountInfo<'a>,
pub log_wrapper: &'b solana_program::account_info::AccountInfo<'a>,
pub compression_program: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
}
pub struct MintV1Cpi<'a, 'b> {
pub __program: &'b solana_program::account_info::AccountInfo<'a>,
pub tree_config: &'b solana_program::account_info::AccountInfo<'a>,
pub leaf_owner: &'b solana_program::account_info::AccountInfo<'a>,
pub leaf_delegate: &'b solana_program::account_info::AccountInfo<'a>,
pub merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub tree_creator_or_delegate: &'b solana_program::account_info::AccountInfo<'a>,
pub log_wrapper: &'b solana_program::account_info::AccountInfo<'a>,
pub compression_program: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
pub __args: MintV1InstructionArgs,
}
impl<'a, 'b> MintV1Cpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: MintV1CpiAccounts<'a, 'b>,
args: MintV1InstructionArgs,
) -> Self {
Self {
__program: program,
tree_config: accounts.tree_config,
leaf_owner: accounts.leaf_owner,
leaf_delegate: accounts.leaf_delegate,
merkle_tree: accounts.merkle_tree,
payer: accounts.payer,
tree_creator_or_delegate: accounts.tree_creator_or_delegate,
log_wrapper: accounts.log_wrapper,
compression_program: accounts.compression_program,
system_program: accounts.system_program,
__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_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(9 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
*self.tree_config.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.leaf_owner.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.leaf_delegate.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.merkle_tree.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.payer.key,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.tree_creator_or_delegate.key,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.log_wrapper.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.compression_program.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.system_program.key,
false,
));
remaining_accounts.iter().for_each(|remaining_account| {
accounts.push(solana_program::instruction::AccountMeta {
pubkey: *remaining_account.0.key,
is_writable: remaining_account.1,
is_signer: remaining_account.2,
})
});
let mut data = borsh::to_vec(&(MintV1InstructionData::new())).unwrap();
let mut args = borsh::to_vec(&self.__args).unwrap();
data.append(&mut args);
let instruction = solana_program::instruction::Instruction {
program_id: crate::MPL_BUBBLEGUM_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(9 + 1 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.tree_config.clone());
account_infos.push(self.leaf_owner.clone());
account_infos.push(self.leaf_delegate.clone());
account_infos.push(self.merkle_tree.clone());
account_infos.push(self.payer.clone());
account_infos.push(self.tree_creator_or_delegate.clone());
account_infos.push(self.log_wrapper.clone());
account_infos.push(self.compression_program.clone());
account_infos.push(self.system_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)
}
}
}
pub struct MintV1CpiBuilder<'a, 'b> {
instruction: Box<MintV1CpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> MintV1CpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(MintV1CpiBuilderInstruction {
__program: program,
tree_config: None,
leaf_owner: None,
leaf_delegate: None,
merkle_tree: None,
payer: None,
tree_creator_or_delegate: None,
log_wrapper: None,
compression_program: None,
system_program: None,
metadata: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn tree_config(
&mut self,
tree_config: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.tree_config = Some(tree_config);
self
}
#[inline(always)]
pub fn leaf_owner(
&mut self,
leaf_owner: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.leaf_owner = Some(leaf_owner);
self
}
#[inline(always)]
pub fn leaf_delegate(
&mut self,
leaf_delegate: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.leaf_delegate = Some(leaf_delegate);
self
}
#[inline(always)]
pub fn merkle_tree(
&mut self,
merkle_tree: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.merkle_tree = Some(merkle_tree);
self
}
#[inline(always)]
pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.payer = Some(payer);
self
}
#[inline(always)]
pub fn tree_creator_or_delegate(
&mut self,
tree_creator_or_delegate: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.tree_creator_or_delegate = Some(tree_creator_or_delegate);
self
}
#[inline(always)]
pub fn log_wrapper(
&mut self,
log_wrapper: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.log_wrapper = Some(log_wrapper);
self
}
#[inline(always)]
pub fn compression_program(
&mut self,
compression_program: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.compression_program = Some(compression_program);
self
}
#[inline(always)]
pub fn system_program(
&mut self,
system_program: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.system_program = Some(system_program);
self
}
#[inline(always)]
pub fn metadata(&mut self, metadata: MetadataArgs) -> &mut Self {
self.instruction.metadata = Some(metadata);
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 args = MintV1InstructionArgs {
metadata: self
.instruction
.metadata
.clone()
.expect("metadata is not set"),
};
let instruction = MintV1Cpi {
__program: self.instruction.__program,
tree_config: self
.instruction
.tree_config
.expect("tree_config is not set"),
leaf_owner: self.instruction.leaf_owner.expect("leaf_owner is not set"),
leaf_delegate: self
.instruction
.leaf_delegate
.expect("leaf_delegate is not set"),
merkle_tree: self
.instruction
.merkle_tree
.expect("merkle_tree is not set"),
payer: self.instruction.payer.expect("payer is not set"),
tree_creator_or_delegate: self
.instruction
.tree_creator_or_delegate
.expect("tree_creator_or_delegate is not set"),
log_wrapper: self
.instruction
.log_wrapper
.expect("log_wrapper is not set"),
compression_program: self
.instruction
.compression_program
.expect("compression_program is not set"),
system_program: self
.instruction
.system_program
.expect("system_program is not set"),
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
struct MintV1CpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
tree_config: Option<&'b solana_program::account_info::AccountInfo<'a>>,
leaf_owner: Option<&'b solana_program::account_info::AccountInfo<'a>>,
leaf_delegate: Option<&'b solana_program::account_info::AccountInfo<'a>>,
merkle_tree: Option<&'b solana_program::account_info::AccountInfo<'a>>,
payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
tree_creator_or_delegate: Option<&'b solana_program::account_info::AccountInfo<'a>>,
log_wrapper: Option<&'b solana_program::account_info::AccountInfo<'a>>,
compression_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
metadata: Option<MetadataArgs>,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}