use crate::generated::types::AllowedDistributor;
use crate::generated::types::DistributionType;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use solana_program::pubkey;
use solana_program::pubkey::Pubkey;
pub struct CreateDistribution {
pub distribution: solana_program::pubkey::Pubkey,
pub mint: solana_program::pubkey::Pubkey,
pub payer: solana_program::pubkey::Pubkey,
pub authority: Option<solana_program::pubkey::Pubkey>,
pub fee_wallet: solana_program::pubkey::Pubkey,
pub seed: solana_program::pubkey::Pubkey,
pub system_program: solana_program::pubkey::Pubkey,
}
impl CreateDistribution {
pub fn instruction(
&self,
args: CreateDistributionInstructionArgs,
) -> solana_program::instruction::Instruction {
self.instruction_with_remaining_accounts(args, &[])
}
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(
&self,
args: CreateDistributionInstructionArgs,
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(
self.distribution,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.mint, false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.payer, true,
));
if let Some(authority) = self.authority {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
authority, true,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_DISTRO_ID,
false,
));
}
accounts.push(solana_program::instruction::AccountMeta::new(
self.fee_wallet,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.seed, true,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.system_program,
false,
));
accounts.extend_from_slice(remaining_accounts);
let mut data = CreateDistributionInstructionData::new()
.try_to_vec()
.unwrap();
let mut args = args.try_to_vec().unwrap();
data.append(&mut args);
solana_program::instruction::Instruction {
program_id: crate::MPL_DISTRO_ID,
accounts,
data,
}
}
}
#[derive(BorshDeserialize, BorshSerialize)]
struct CreateDistributionInstructionData {
discriminator: u8,
}
impl CreateDistributionInstructionData {
fn new() -> Self {
Self { discriminator: 0 }
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct CreateDistributionInstructionArgs {
pub merkle_root: [u8; 32],
pub tree_height: u8,
pub start_time: i64,
pub end_time: i64,
pub total_claimants: u64,
pub name: String,
pub distribution_type: DistributionType,
pub subsidize_receipts: bool,
pub allowed_distributor: AllowedDistributor,
pub permissioned_distributor: Pubkey,
}
#[derive(Default)]
pub struct CreateDistributionBuilder {
distribution: Option<solana_program::pubkey::Pubkey>,
mint: Option<solana_program::pubkey::Pubkey>,
payer: Option<solana_program::pubkey::Pubkey>,
authority: Option<solana_program::pubkey::Pubkey>,
fee_wallet: Option<solana_program::pubkey::Pubkey>,
seed: Option<solana_program::pubkey::Pubkey>,
system_program: Option<solana_program::pubkey::Pubkey>,
merkle_root: Option<[u8; 32]>,
tree_height: Option<u8>,
start_time: Option<i64>,
end_time: Option<i64>,
total_claimants: Option<u64>,
name: Option<String>,
distribution_type: Option<DistributionType>,
subsidize_receipts: Option<bool>,
allowed_distributor: Option<AllowedDistributor>,
permissioned_distributor: Option<Pubkey>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}
impl CreateDistributionBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn distribution(&mut self, distribution: solana_program::pubkey::Pubkey) -> &mut Self {
self.distribution = Some(distribution);
self
}
#[inline(always)]
pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self {
self.mint = Some(mint);
self
}
#[inline(always)]
pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
self.payer = Some(payer);
self
}
#[inline(always)]
pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
self.authority = authority;
self
}
#[inline(always)]
pub fn fee_wallet(&mut self, fee_wallet: solana_program::pubkey::Pubkey) -> &mut Self {
self.fee_wallet = Some(fee_wallet);
self
}
#[inline(always)]
pub fn seed(&mut self, seed: solana_program::pubkey::Pubkey) -> &mut Self {
self.seed = Some(seed);
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 merkle_root(&mut self, merkle_root: [u8; 32]) -> &mut Self {
self.merkle_root = Some(merkle_root);
self
}
#[inline(always)]
pub fn tree_height(&mut self, tree_height: u8) -> &mut Self {
self.tree_height = Some(tree_height);
self
}
#[inline(always)]
pub fn start_time(&mut self, start_time: i64) -> &mut Self {
self.start_time = Some(start_time);
self
}
#[inline(always)]
pub fn end_time(&mut self, end_time: i64) -> &mut Self {
self.end_time = Some(end_time);
self
}
#[inline(always)]
pub fn total_claimants(&mut self, total_claimants: u64) -> &mut Self {
self.total_claimants = Some(total_claimants);
self
}
#[inline(always)]
pub fn name(&mut self, name: String) -> &mut Self {
self.name = Some(name);
self
}
#[inline(always)]
pub fn distribution_type(&mut self, distribution_type: DistributionType) -> &mut Self {
self.distribution_type = Some(distribution_type);
self
}
#[inline(always)]
pub fn subsidize_receipts(&mut self, subsidize_receipts: bool) -> &mut Self {
self.subsidize_receipts = Some(subsidize_receipts);
self
}
#[inline(always)]
pub fn allowed_distributor(&mut self, allowed_distributor: AllowedDistributor) -> &mut Self {
self.allowed_distributor = Some(allowed_distributor);
self
}
#[inline(always)]
pub fn permissioned_distributor(&mut self, permissioned_distributor: Pubkey) -> &mut Self {
self.permissioned_distributor = Some(permissioned_distributor);
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 = CreateDistribution {
distribution: self.distribution.expect("distribution is not set"),
mint: self.mint.expect("mint is not set"),
payer: self.payer.expect("payer is not set"),
authority: self.authority,
fee_wallet: self.fee_wallet.unwrap_or(solana_program::pubkey!(
"9kFjQsxtpBsaw8s7aUyiY3wazYDNgFP4Lj5rsBVVF8tb"
)),
seed: self.seed.expect("seed is not set"),
system_program: self
.system_program
.unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
};
let args = CreateDistributionInstructionArgs {
merkle_root: self.merkle_root.clone().expect("merkle_root is not set"),
tree_height: self.tree_height.clone().expect("tree_height is not set"),
start_time: self.start_time.clone().expect("start_time is not set"),
end_time: self.end_time.clone().expect("end_time is not set"),
total_claimants: self
.total_claimants
.clone()
.expect("total_claimants is not set"),
name: self.name.clone().expect("name is not set"),
distribution_type: self
.distribution_type
.clone()
.unwrap_or(DistributionType::Wallet),
subsidize_receipts: self.subsidize_receipts.clone().unwrap_or(false),
allowed_distributor: self
.allowed_distributor
.clone()
.unwrap_or(AllowedDistributor::Permissionless),
permissioned_distributor: self
.permissioned_distributor
.clone()
.unwrap_or(pubkey!("11111111111111111111111111111111")),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct CreateDistributionCpiAccounts<'a, 'b> {
pub distribution: &'b solana_program::account_info::AccountInfo<'a>,
pub mint: &'b solana_program::account_info::AccountInfo<'a>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub fee_wallet: &'b solana_program::account_info::AccountInfo<'a>,
pub seed: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
}
pub struct CreateDistributionCpi<'a, 'b> {
pub __program: &'b solana_program::account_info::AccountInfo<'a>,
pub distribution: &'b solana_program::account_info::AccountInfo<'a>,
pub mint: &'b solana_program::account_info::AccountInfo<'a>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub fee_wallet: &'b solana_program::account_info::AccountInfo<'a>,
pub seed: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
pub __args: CreateDistributionInstructionArgs,
}
impl<'a, 'b> CreateDistributionCpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: CreateDistributionCpiAccounts<'a, 'b>,
args: CreateDistributionInstructionArgs,
) -> Self {
Self {
__program: program,
distribution: accounts.distribution,
mint: accounts.mint,
payer: accounts.payer,
authority: accounts.authority,
fee_wallet: accounts.fee_wallet,
seed: accounts.seed,
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(7 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
*self.distribution.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.mint.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.payer.key,
true,
));
if let Some(authority) = self.authority {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*authority.key,
true,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_DISTRO_ID,
false,
));
}
accounts.push(solana_program::instruction::AccountMeta::new(
*self.fee_wallet.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.seed.key,
true,
));
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_signer: remaining_account.1,
is_writable: remaining_account.2,
})
});
let mut data = CreateDistributionInstructionData::new()
.try_to_vec()
.unwrap();
let mut args = self.__args.try_to_vec().unwrap();
data.append(&mut args);
let instruction = solana_program::instruction::Instruction {
program_id: crate::MPL_DISTRO_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(7 + 1 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.distribution.clone());
account_infos.push(self.mint.clone());
account_infos.push(self.payer.clone());
if let Some(authority) = self.authority {
account_infos.push(authority.clone());
}
account_infos.push(self.fee_wallet.clone());
account_infos.push(self.seed.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 CreateDistributionCpiBuilder<'a, 'b> {
instruction: Box<CreateDistributionCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> CreateDistributionCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(CreateDistributionCpiBuilderInstruction {
__program: program,
distribution: None,
mint: None,
payer: None,
authority: None,
fee_wallet: None,
seed: None,
system_program: None,
merkle_root: None,
tree_height: None,
start_time: None,
end_time: None,
total_claimants: None,
name: None,
distribution_type: None,
subsidize_receipts: None,
allowed_distributor: None,
permissioned_distributor: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn distribution(
&mut self,
distribution: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.distribution = Some(distribution);
self
}
#[inline(always)]
pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.mint = Some(mint);
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 authority(
&mut self,
authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.authority = authority;
self
}
#[inline(always)]
pub fn fee_wallet(
&mut self,
fee_wallet: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.fee_wallet = Some(fee_wallet);
self
}
#[inline(always)]
pub fn seed(&mut self, seed: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.seed = Some(seed);
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 merkle_root(&mut self, merkle_root: [u8; 32]) -> &mut Self {
self.instruction.merkle_root = Some(merkle_root);
self
}
#[inline(always)]
pub fn tree_height(&mut self, tree_height: u8) -> &mut Self {
self.instruction.tree_height = Some(tree_height);
self
}
#[inline(always)]
pub fn start_time(&mut self, start_time: i64) -> &mut Self {
self.instruction.start_time = Some(start_time);
self
}
#[inline(always)]
pub fn end_time(&mut self, end_time: i64) -> &mut Self {
self.instruction.end_time = Some(end_time);
self
}
#[inline(always)]
pub fn total_claimants(&mut self, total_claimants: u64) -> &mut Self {
self.instruction.total_claimants = Some(total_claimants);
self
}
#[inline(always)]
pub fn name(&mut self, name: String) -> &mut Self {
self.instruction.name = Some(name);
self
}
#[inline(always)]
pub fn distribution_type(&mut self, distribution_type: DistributionType) -> &mut Self {
self.instruction.distribution_type = Some(distribution_type);
self
}
#[inline(always)]
pub fn subsidize_receipts(&mut self, subsidize_receipts: bool) -> &mut Self {
self.instruction.subsidize_receipts = Some(subsidize_receipts);
self
}
#[inline(always)]
pub fn allowed_distributor(&mut self, allowed_distributor: AllowedDistributor) -> &mut Self {
self.instruction.allowed_distributor = Some(allowed_distributor);
self
}
#[inline(always)]
pub fn permissioned_distributor(&mut self, permissioned_distributor: Pubkey) -> &mut Self {
self.instruction.permissioned_distributor = Some(permissioned_distributor);
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 = CreateDistributionInstructionArgs {
merkle_root: self
.instruction
.merkle_root
.clone()
.expect("merkle_root is not set"),
tree_height: self
.instruction
.tree_height
.clone()
.expect("tree_height is not set"),
start_time: self
.instruction
.start_time
.clone()
.expect("start_time is not set"),
end_time: self
.instruction
.end_time
.clone()
.expect("end_time is not set"),
total_claimants: self
.instruction
.total_claimants
.clone()
.expect("total_claimants is not set"),
name: self.instruction.name.clone().expect("name is not set"),
distribution_type: self
.instruction
.distribution_type
.clone()
.unwrap_or(DistributionType::Wallet),
subsidize_receipts: self.instruction.subsidize_receipts.clone().unwrap_or(false),
allowed_distributor: self
.instruction
.allowed_distributor
.clone()
.unwrap_or(AllowedDistributor::Permissionless),
permissioned_distributor: self
.instruction
.permissioned_distributor
.clone()
.unwrap_or(pubkey!("11111111111111111111111111111111")),
};
let instruction = CreateDistributionCpi {
__program: self.instruction.__program,
distribution: self
.instruction
.distribution
.expect("distribution is not set"),
mint: self.instruction.mint.expect("mint is not set"),
payer: self.instruction.payer.expect("payer is not set"),
authority: self.instruction.authority,
fee_wallet: self.instruction.fee_wallet.expect("fee_wallet is not set"),
seed: self.instruction.seed.expect("seed 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 CreateDistributionCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
distribution: Option<&'b solana_program::account_info::AccountInfo<'a>>,
mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
fee_wallet: Option<&'b solana_program::account_info::AccountInfo<'a>>,
seed: Option<&'b solana_program::account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
merkle_root: Option<[u8; 32]>,
tree_height: Option<u8>,
start_time: Option<i64>,
end_time: Option<i64>,
total_claimants: Option<u64>,
name: Option<String>,
distribution_type: Option<DistributionType>,
subsidize_receipts: Option<bool>,
allowed_distributor: Option<AllowedDistributor>,
permissioned_distributor: Option<Pubkey>,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}