Skip to content

Commit 4366669

Browse files
authored
Merge pull request #65 from 0xPratik/main
cNft Burn anchor example
2 parents 86ab1de + c969975 commit 4366669

20 files changed

+1803
-0
lines changed

compression/cnft-burn/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
.anchor
3+
.DS_Store
4+
target
5+
**/*.rs.bk
6+
node_modules
7+
test-ledger
8+
.yarn

compression/cnft-burn/.prettierignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
.anchor
3+
.DS_Store
4+
target
5+
node_modules
6+
dist
7+
build
8+
test-ledger

compression/cnft-burn/Anchor.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[toolchain]
2+
3+
[features]
4+
seeds = false
5+
skip-lint = false
6+
7+
[programs.devnet]
8+
cnft_burn = "FbeHkUEevbhKmdk5FE5orcTaJkCYn5drwZoZXaxQXXNn"
9+
10+
[registry]
11+
url = "https://api.apr.dev"
12+
13+
[provider]
14+
cluster = "devnet"
15+
wallet = "~/.config/solana/id.json"
16+
17+
[scripts]
18+
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/cnft-burn.ts"

compression/cnft-burn/Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[workspace]
2+
members = [
3+
"programs/*"
4+
]
5+
6+
[profile.release]
7+
overflow-checks = true
8+
lto = "fat"
9+
codegen-units = 1
10+
[profile.release.build-override]
11+
opt-level = 3
12+
incremental = false
13+
codegen-units = 1

compression/cnft-burn/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# cnft-burn
2+
3+
This repository contains the cnft-burn program, a Solana Anchor program that allows you to burn compressed NFTs (cNFTs) in your collection. The program interacts with the Metaplex Bubblegum program through CPI to burn cNFTs.
4+
5+
## Components
6+
7+
- programs: Contains the anchor program
8+
- tests: Contains the tests for the anchor program
9+
10+
## Deployment
11+
12+
The program is deployed on devnet at `FbeHkUEevbhKmdk5FE5orcTaJkCYn5drwZoZXaxQXXNn`. You can deploy it yourself by changing the respective values in lib.rs and Anchor.toml.
13+
14+
## How to run
15+
16+
1. Configure RPC path in cnft-burn.ts. Personal preference: Helius RPCs.
17+
2. run `anchor build` at the root of the project i.e cnft-burn in this case.
18+
3. run `anchor deploy` to deploy and test the program on your own cluster.
19+
4. run `anchor test` to run the tests.
20+
21+
## Acknowledgements
22+
23+
This Example program would not have been possible without the work of:
24+
25+
- [Metaplex](https://github.com/metaplex-foundation/) for providing the Bubblegum program with ix builders.
26+
- [@nickfrosty](https://twitter.com/nickfrosty) for providing the sample code for fetching and creating cNFTs.
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Migrations are an early feature. Currently, they're nothing more than this
2+
// single deploy script that's invoked from the CLI, injecting a provider
3+
// configured from the workspace's Anchor.toml.
4+
5+
const anchor = require("@coral-xyz/anchor");
6+
7+
module.exports = async function (provider) {
8+
// Configure client to use the provider.
9+
anchor.setProvider(provider);
10+
11+
// Add your deploy script here.
12+
};

compression/cnft-burn/package.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"scripts": {
3+
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
4+
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
5+
},
6+
"dependencies": {
7+
"@coral-xyz/anchor": "^0.29.0",
8+
"@metaplex-foundation/js": "^0.19.4",
9+
"@metaplex-foundation/mpl-bubblegum": "^0.7.0",
10+
"@metaplex-foundation/mpl-token-metadata": "^2.12.0",
11+
"@metaplex-foundation/umi": "^0.9.0",
12+
"@solana/spl-account-compression": "^0.2.0",
13+
"@solana/web3.js": "^1.89.0",
14+
"axios": "^1.6.5"
15+
},
16+
"devDependencies": {
17+
"@types/bn.js": "^5.1.0",
18+
"@types/chai": "^4.3.0",
19+
"@types/mocha": "^9.0.0",
20+
"chai": "^4.3.4",
21+
"mocha": "^9.0.3",
22+
"prettier": "^2.6.2",
23+
"ts-mocha": "^10.0.0",
24+
"typescript": "^4.3.5"
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "cnft-burn"
3+
version = "0.1.0"
4+
description = "Created with Anchor"
5+
edition = "2021"
6+
7+
[lib]
8+
crate-type = ["cdylib", "lib"]
9+
name = "cnft_burn"
10+
11+
[features]
12+
no-entrypoint = []
13+
no-idl = []
14+
no-log-ix-name = []
15+
cpi = ["no-entrypoint"]
16+
default = []
17+
18+
[dependencies]
19+
anchor-lang = "0.29.0"
20+
mpl-bubblegum = {version="1.1.0" }
21+
spl-account-compression = { version="0.3.0",features = ["no-entrypoint","cpi"] }
22+
ahash = "=0.8.6"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.bpfel-unknown-unknown.dependencies.std]
2+
features = []
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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

Comments
 (0)