Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cNft Burn anchor example #65

Merged
merged 11 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compression/cnft-burn/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.anchor
.DS_Store
target
**/*.rs.bk
node_modules
test-ledger
.yarn
8 changes: 8 additions & 0 deletions compression/cnft-burn/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

.anchor
.DS_Store
target
node_modules
dist
build
test-ledger
18 changes: 18 additions & 0 deletions compression/cnft-burn/Anchor.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[toolchain]

[features]
seeds = false
skip-lint = false

[programs.devnet]
cnft_burn = "FbeHkUEevbhKmdk5FE5orcTaJkCYn5drwZoZXaxQXXNn"

[registry]
url = "https://api.apr.dev"

[provider]
cluster = "devnet"
wallet = "~/.config/solana/id.json"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/cnft-burn.ts"
13 changes: 13 additions & 0 deletions compression/cnft-burn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[workspace]
members = [
"programs/*"
]

[profile.release]
overflow-checks = true
lto = "fat"
codegen-units = 1
[profile.release.build-override]
opt-level = 3
incremental = false
codegen-units = 1
26 changes: 26 additions & 0 deletions compression/cnft-burn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# cnft-burn

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.

## Components

- programs: Contains the anchor program
- tests: Contains the tests for the anchor program

## Deployment

The program is deployed on devnet at `FbeHkUEevbhKmdk5FE5orcTaJkCYn5drwZoZXaxQXXNn`. You can deploy it yourself by changing the respective values in lib.rs and Anchor.toml.

## How to run

1. Configure RPC path in cnft-burn.ts. Personal preference: Helius RPCs.
2. run `anchor build` at the root of the project i.e cnft-burn in this case.
3. run `anchor deploy` to deploy and test the program on your own cluster.
4. run `anchor test` to run the tests.

## Acknowledgements

This Example program would not have been possible without the work of:

- [Metaplex](https://github.com/metaplex-foundation/) for providing the Bubblegum program with ix builders.
- [@nickfrosty](https://twitter.com/nickfrosty) for providing the sample code for fetching and creating cNFTs.
12 changes: 12 additions & 0 deletions compression/cnft-burn/migrations/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Migrations are an early feature. Currently, they're nothing more than this
// single deploy script that's invoked from the CLI, injecting a provider
// configured from the workspace's Anchor.toml.

const anchor = require("@coral-xyz/anchor");

module.exports = async function (provider) {
// Configure client to use the provider.
anchor.setProvider(provider);

// Add your deploy script here.
};
26 changes: 26 additions & 0 deletions compression/cnft-burn/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"scripts": {
"lint:fix": "prettier */*.js \"*/**/*{.js,.ts}\" -w",
"lint": "prettier */*.js \"*/**/*{.js,.ts}\" --check"
},
"dependencies": {
"@coral-xyz/anchor": "^0.29.0",
"@metaplex-foundation/js": "^0.19.4",
"@metaplex-foundation/mpl-bubblegum": "^0.7.0",
"@metaplex-foundation/mpl-token-metadata": "^2.12.0",
"@metaplex-foundation/umi": "^0.9.0",
"@solana/spl-account-compression": "^0.2.0",
"@solana/web3.js": "^1.89.0",
"axios": "^1.6.5"
},
"devDependencies": {
"@types/bn.js": "^5.1.0",
"@types/chai": "^4.3.0",
"@types/mocha": "^9.0.0",
"chai": "^4.3.4",
"mocha": "^9.0.3",
"prettier": "^2.6.2",
"ts-mocha": "^10.0.0",
"typescript": "^4.3.5"
}
}
22 changes: 22 additions & 0 deletions compression/cnft-burn/programs/cnft-burn/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "cnft-burn"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "cnft_burn"

[features]
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = "0.29.0"
mpl-bubblegum = {version="1.1.0" }
spl-account-compression = { version="0.3.0",features = ["no-entrypoint","cpi"] }
ahash = "=0.8.6"
2 changes: 2 additions & 0 deletions compression/cnft-burn/programs/cnft-burn/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
86 changes: 86 additions & 0 deletions compression/cnft-burn/programs/cnft-burn/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
use anchor_lang::prelude::*;

declare_id!("FbeHkUEevbhKmdk5FE5orcTaJkCYn5drwZoZXaxQXXNn");

#[derive(Clone)]
pub struct SPLCompression;

impl anchor_lang::Id for SPLCompression {
fn id() -> Pubkey {
spl_account_compression::id()
}
}

#[program]
pub mod cnft_burn {
use super::*;

pub fn burn_cnft<'info>(
ctx: Context<'_, '_, '_, 'info, BurnCnft<'info>>,
root: [u8; 32],
data_hash: [u8; 32],
creator_hash: [u8; 32],
nonce: u64,
index: u32,
) -> Result<()> {
let tree_config = ctx.accounts.tree_authority.to_account_info();
let leaf_owner = ctx.accounts.leaf_owner.to_account_info();
let merkle_tree = ctx.accounts.merkle_tree.to_account_info();
let log_wrapper = ctx.accounts.log_wrapper.to_account_info();
let compression_program = ctx.accounts.compression_program.to_account_info();
let system_program = ctx.accounts.system_program.to_account_info();

let cnft_burn_cpi = mpl_bubblegum::instructions::BurnCpi::new(
&ctx.accounts.bubblegum_program,
mpl_bubblegum::instructions::BurnCpiAccounts {
tree_config: &tree_config,
leaf_owner: (&leaf_owner, true),
leaf_delegate: (&leaf_owner, false),
merkle_tree: &merkle_tree,
log_wrapper: &log_wrapper,
compression_program: &compression_program,
system_program: &system_program,
},
mpl_bubblegum::instructions::BurnInstructionArgs {
root,
data_hash,
creator_hash,
nonce,
index,
},
);

cnft_burn_cpi.invoke_with_remaining_accounts(
ctx.remaining_accounts
.iter()
.map(|account| (account, false, false))
.collect::<Vec<_>>()
.as_slice(),
)?;

Ok(())
}
}

#[derive(Accounts)]
pub struct BurnCnft<'info> {
#[account(mut)]
pub leaf_owner: Signer<'info>,
#[account(mut)]
#[account(
seeds = [merkle_tree.key().as_ref()],
bump,
seeds::program = bubblegum_program.key()
)]
/// CHECK: This account is modified in the downstream program
pub tree_authority: UncheckedAccount<'info>,
#[account(mut)]
/// CHECK: This account is neither written to nor read from.
pub merkle_tree: UncheckedAccount<'info>,
/// CHECK: This account is neither written to nor read from.
pub log_wrapper: UncheckedAccount<'info>,
pub compression_program: Program<'info, SPLCompression>,
/// CHECK: This account is neither written to nor read from.
pub bubblegum_program: UncheckedAccount<'info>,
pub system_program: Program<'info, System>,
}
Loading
Loading