-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from 0xPratik/main
cNft Burn anchor example
- Loading branch information
Showing
20 changed files
with
1,803 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
.anchor | ||
.DS_Store | ||
target | ||
node_modules | ||
dist | ||
build | ||
test-ledger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[target.bpfel-unknown-unknown.dependencies.std] | ||
features = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
} |
Oops, something went wrong.