|
| 1 | +use anchor_lang::prelude::*; |
| 2 | + |
| 3 | +declare_id!("FbeHkUEevbhKmdk5FE5orcTaJkCYn5drwZoZXaxQXXNn"); |
| 4 | + |
| 5 | +#[derive(Clone)] |
| 6 | +pub struct SPLCompression; |
| 7 | + |
| 8 | +impl anchor_lang::Id for SPLCompression { |
| 9 | + fn id() -> Pubkey { |
| 10 | + spl_account_compression::id() |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | +#[program] |
| 15 | +pub mod cnft_burn { |
| 16 | + use super::*; |
| 17 | + |
| 18 | + pub fn burn_cnft<'info>( |
| 19 | + ctx: Context<'_, '_, '_, 'info, BurnCnft<'info>>, |
| 20 | + root: [u8; 32], |
| 21 | + data_hash: [u8; 32], |
| 22 | + creator_hash: [u8; 32], |
| 23 | + nonce: u64, |
| 24 | + index: u32, |
| 25 | + ) -> Result<()> { |
| 26 | + let tree_config = ctx.accounts.tree_authority.to_account_info(); |
| 27 | + let leaf_owner = ctx.accounts.leaf_owner.to_account_info(); |
| 28 | + let merkle_tree = ctx.accounts.merkle_tree.to_account_info(); |
| 29 | + let log_wrapper = ctx.accounts.log_wrapper.to_account_info(); |
| 30 | + let compression_program = ctx.accounts.compression_program.to_account_info(); |
| 31 | + let system_program = ctx.accounts.system_program.to_account_info(); |
| 32 | + |
| 33 | + let cnft_burn_cpi = mpl_bubblegum::instructions::BurnCpi::new( |
| 34 | + &ctx.accounts.bubblegum_program, |
| 35 | + mpl_bubblegum::instructions::BurnCpiAccounts { |
| 36 | + tree_config: &tree_config, |
| 37 | + leaf_owner: (&leaf_owner, true), |
| 38 | + leaf_delegate: (&leaf_owner, false), |
| 39 | + merkle_tree: &merkle_tree, |
| 40 | + log_wrapper: &log_wrapper, |
| 41 | + compression_program: &compression_program, |
| 42 | + system_program: &system_program, |
| 43 | + }, |
| 44 | + mpl_bubblegum::instructions::BurnInstructionArgs { |
| 45 | + root, |
| 46 | + data_hash, |
| 47 | + creator_hash, |
| 48 | + nonce, |
| 49 | + index, |
| 50 | + }, |
| 51 | + ); |
| 52 | + |
| 53 | + cnft_burn_cpi.invoke_with_remaining_accounts( |
| 54 | + ctx.remaining_accounts |
| 55 | + .iter() |
| 56 | + .map(|account| (account, false, false)) |
| 57 | + .collect::<Vec<_>>() |
| 58 | + .as_slice(), |
| 59 | + )?; |
| 60 | + |
| 61 | + Ok(()) |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +#[derive(Accounts)] |
| 66 | +pub struct BurnCnft<'info> { |
| 67 | + #[account(mut)] |
| 68 | + pub leaf_owner: Signer<'info>, |
| 69 | + #[account(mut)] |
| 70 | + #[account( |
| 71 | + seeds = [merkle_tree.key().as_ref()], |
| 72 | + bump, |
| 73 | + seeds::program = bubblegum_program.key() |
| 74 | + )] |
| 75 | + /// CHECK: This account is modified in the downstream program |
| 76 | + pub tree_authority: UncheckedAccount<'info>, |
| 77 | + #[account(mut)] |
| 78 | + /// CHECK: This account is neither written to nor read from. |
| 79 | + pub merkle_tree: UncheckedAccount<'info>, |
| 80 | + /// CHECK: This account is neither written to nor read from. |
| 81 | + pub log_wrapper: UncheckedAccount<'info>, |
| 82 | + pub compression_program: Program<'info, SPLCompression>, |
| 83 | + /// CHECK: This account is neither written to nor read from. |
| 84 | + pub bubblegum_program: UncheckedAccount<'info>, |
| 85 | + pub system_program: Program<'info, System>, |
| 86 | +} |
0 commit comments