|
| 1 | +use crate::*; |
| 2 | +use mpl_bubblegum::{ |
| 3 | + state::{ |
| 4 | + TreeConfig, |
| 5 | + COLLECTION_CPI_PREFIX, |
| 6 | + metaplex_adapter::{Collection, Creator, MetadataArgs, TokenProgramVersion, TokenStandard}, |
| 7 | + metaplex_anchor::{ |
| 8 | + TokenMetadata, MplTokenMetadata |
| 9 | + }, |
| 10 | + } |
| 11 | +}; |
| 12 | + |
| 13 | +#[derive(Accounts)] |
| 14 | +#[instruction(params: MintParams)] |
| 15 | +pub struct Mint<'info> { |
| 16 | + // #[account( |
| 17 | + // init, |
| 18 | + // seeds = [ |
| 19 | + // SEED_DATA, |
| 20 | + // data.tree, |
| 21 | + // data.tree_nonce |
| 22 | + // // assetId directly? |
| 23 | + // ], |
| 24 | + // bump, |
| 25 | + // payer = payer, |
| 26 | + // space = Data::LEN, |
| 27 | + // )] |
| 28 | + // pub data: Account<'info, Data>, |
| 29 | + |
| 30 | + pub payer: Signer<'info>, |
| 31 | + |
| 32 | + // Bubblegum cNFT stuff MintToCollectionV1 |
| 33 | + #[account( |
| 34 | + mut, |
| 35 | + seeds = [merkle_tree.key().as_ref()], |
| 36 | + seeds::program = bubblegum_program.key(), |
| 37 | + bump, |
| 38 | + )] |
| 39 | + pub tree_authority: Box<Account<'info, TreeConfig>>, |
| 40 | + |
| 41 | + /// CHECK: This account is neither written to nor read from. |
| 42 | + pub leaf_owner: AccountInfo<'info>, |
| 43 | + |
| 44 | + /// CHECK: This account is neither written to nor read from. |
| 45 | + pub leaf_delegate: AccountInfo<'info>, |
| 46 | + |
| 47 | + #[account(mut)] |
| 48 | + /// CHECK: unsafe |
| 49 | + pub merkle_tree: UncheckedAccount<'info>, |
| 50 | + |
| 51 | + pub tree_delegate: Signer<'info>, |
| 52 | + |
| 53 | + pub collection_authority: Signer<'info>, |
| 54 | + |
| 55 | + /// CHECK: Optional collection authority record PDA. |
| 56 | + /// If there is no collecton authority record PDA then |
| 57 | + /// this must be the Bubblegum program address. |
| 58 | + pub collection_authority_record_pda: UncheckedAccount<'info>, |
| 59 | + |
| 60 | + /// CHECK: This account is checked in the instruction |
| 61 | + pub collection_mint: UncheckedAccount<'info>, |
| 62 | + |
| 63 | + #[account(mut)] |
| 64 | + pub collection_metadata: Box<Account<'info, TokenMetadata>>, |
| 65 | + |
| 66 | + /// CHECK: This account is checked in the instruction |
| 67 | + pub edition_account: UncheckedAccount<'info>, |
| 68 | + |
| 69 | + /// CHECK: This is just used as a signing PDA. |
| 70 | + #[account( |
| 71 | + seeds = [COLLECTION_CPI_PREFIX.as_ref()], |
| 72 | + seeds::program = bubblegum_program.key(), |
| 73 | + bump, |
| 74 | + )] |
| 75 | + pub bubblegum_signer: UncheckedAccount<'info>, |
| 76 | + pub log_wrapper: Program<'info, Noop>, |
| 77 | + pub compression_program: Program<'info, SplAccountCompression>, |
| 78 | + pub token_metadata_program: Program<'info, MplTokenMetadata>, |
| 79 | + pub bubblegum_program: Program<'info, MplBubblegum>, |
| 80 | + pub system_program: Program<'info, System>, |
| 81 | +} |
| 82 | + |
| 83 | +#[derive(Clone, AnchorSerialize, AnchorDeserialize)] |
| 84 | +pub struct MintParams { |
| 85 | + uri: String, |
| 86 | +} |
| 87 | + |
| 88 | +impl Mint<'_> { |
| 89 | + pub fn validate( |
| 90 | + &self, |
| 91 | + _ctx: &Context<Self>, |
| 92 | + _params: &MintParams, |
| 93 | + ) -> Result<()> { |
| 94 | + Ok(()) |
| 95 | + } |
| 96 | + |
| 97 | + pub fn actuate<'info>( |
| 98 | + ctx: Context<'_, '_, '_, 'info, Mint<'info>>, |
| 99 | + params: MintParams |
| 100 | + ) -> Result<()> { |
| 101 | + mpl_bubblegum::cpi::mint_to_collection_v1( |
| 102 | + CpiContext::new( |
| 103 | + ctx.accounts.bubblegum_program.to_account_info(), |
| 104 | + mpl_bubblegum::cpi::accounts::MintToCollectionV1 { |
| 105 | + tree_authority: ctx.accounts.tree_authority.to_account_info(), |
| 106 | + leaf_owner: ctx.accounts.leaf_owner.to_account_info(), |
| 107 | + leaf_delegate: ctx.accounts.leaf_delegate.to_account_info(), |
| 108 | + merkle_tree: ctx.accounts.merkle_tree.to_account_info(), |
| 109 | + payer: ctx.accounts.payer.to_account_info(), |
| 110 | + tree_delegate: ctx.accounts.tree_delegate.to_account_info(), |
| 111 | + collection_authority: ctx.accounts.collection_authority.to_account_info(), |
| 112 | + collection_authority_record_pda: ctx.accounts.collection_authority_record_pda.to_account_info(), |
| 113 | + collection_mint: ctx.accounts.collection_mint.to_account_info(), |
| 114 | + collection_metadata: ctx.accounts.collection_metadata.to_account_info(), |
| 115 | + edition_account: ctx.accounts.edition_account.to_account_info(), |
| 116 | + bubblegum_signer: ctx.accounts.bubblegum_signer.to_account_info(), |
| 117 | + log_wrapper: ctx.accounts.log_wrapper.to_account_info(), |
| 118 | + compression_program: ctx.accounts.compression_program.to_account_info(), |
| 119 | + token_metadata_program: ctx.accounts.token_metadata_program.to_account_info(), |
| 120 | + system_program: ctx.accounts.system_program.to_account_info(), |
| 121 | + } |
| 122 | + ), |
| 123 | + MetadataArgs { |
| 124 | + name: "BURGER".to_string(), |
| 125 | + symbol: "BURG".to_string(), |
| 126 | + uri: params.uri, |
| 127 | + creators: vec![ |
| 128 | + Creator {address: ctx.accounts.collection_authority.key(), verified: false, share: 100}, |
| 129 | + ], |
| 130 | + seller_fee_basis_points: 0, |
| 131 | + primary_sale_happened: false, |
| 132 | + is_mutable: false, |
| 133 | + edition_nonce: Some(0), |
| 134 | + uses: None, |
| 135 | + collection: Some(Collection {verified: false, key: ctx.accounts.collection_mint.key()}), |
| 136 | + token_program_version: TokenProgramVersion::Original, |
| 137 | + token_standard: Some(TokenStandard::NonFungible), |
| 138 | + } |
| 139 | + )?; |
| 140 | + |
| 141 | + Ok(()) |
| 142 | + } |
| 143 | +} |
0 commit comments