Skip to content

Commit

Permalink
[CNft] CNft Collection Offer (#107)
Browse files Browse the repository at this point in the history
* set up test skeleton

* import mpl bubblegum

* basic cnft test set up

* imported bubblegum crate

* fulfill buy contract skeleton

* add cnft transfer to fulfill buy

* add collection offer creation in test

* Add basic fulfill buy operation

* successful cnft transfer

* remove metadata rehash

* fix CreatorRoyaltyConfig

* add using canopyDepth and handling truncated proofs. test passes

* pass metadata args in

* fix passing metadata args

* add collection metadata verification

* add fee cacluation, shared escrow support, reinvest buy support

* add creator verification and pay

* fix full logic

* pass basic test

* clean up redudent args and log

* use pub! macro

* remove test skips

* add allowlist verification

* propgate error

* fix collection verification for mcc

* fix allowlist check test

* add incorrect royalty test

* clean up tests log

* add comment

* clean up unused parameters

* use asset id as seed of sell state

* compute creator hash using metadata args

* address comments

* skip ocp test

* fix format

---------

Co-authored-by: swimricky <[email protected]>
  • Loading branch information
JeremyLi28 and swimricky authored Nov 22, 2024
1 parent 64051f3 commit 1d4ccd5
Show file tree
Hide file tree
Showing 21 changed files with 3,330 additions and 23 deletions.
9 changes: 9 additions & 0 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ address = "CZ1rQoAHSqWBoAEfqGsiLhgbM59dDrCWk3rnG5FXaoRV" # libreplex royalty enf
[[test.validator.clone]]
address = "CoREENxT6tW1HoK8ypY1SxRMZTcVPm7R94rH4PZNhX7d" # metaplex core program

[[test.validator.clone]]
address = "BGUMAp9Gq7iTEuizy4pqaxsTyUCBK68MDfK752saRPUY" # bubblegum

[[test.validator.clone]]
address = "noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV" # Noop logger for bubblegum

[[test.validator.clone]]
address = "cmtDvXumGCrqC1Age74AVPhSRVXJMd8PJS91L8KbNCK" # compression program

[[test.validator.account]]
address = "9V5HWD1ap6mCDMhBoXU5SVcZZn9ihqJtoMQZsw5MTnoD" # example payment proxy
filename = './tests/deps/proxy.json'
Expand Down
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"dependencies": {
"@magiceden-oss/open_creator_protocol": "^0.3.2",
"@metaplex-foundation/js": "^0.19.4",
"@metaplex-foundation/mpl-bubblegum": "^4.2.1",
"@metaplex-foundation/mpl-core": "^0.4.7",
"@metaplex-foundation/mpl-token-auth-rules": "^2.0.0",
"@metaplex-foundation/mpl-token-metadata": "^3.1.2",
"@metaplex-foundation/umi": "^0.8.10",
"@metaplex-foundation/umi-bundle-tests": "^0.8.2",
"@metaplex-foundation/umi-web3js-adapters": "^0.8.2",
"@project-serum/anchor": "^0.26.0",
"@solana/spl-account-compression": "0.1.8",
"@solana/spl-token": "^0.4.1",
"@solana/spl-token-group": "^0.0.1",
"@solana/web3.js": "^1.65.0",
Expand All @@ -22,15 +24,16 @@
},
"devDependencies": {
"@magiceden-oss/mmm": "file:sdk",
"@metaplex-foundation/digital-asset-standard-api": "^1.0.4",
"@metaplex-foundation/mpl-migration-validator": "^0.4.1",
"@msgpack/msgpack": "^2.8.0",
"@types/jest": "29.0.0",
"chai": "^4.3.4",
"eslint-config-standard-with-typescript": "^21.0.1",
"eslint-plugin-prettier": "^4.0.0",
"prettier": "^2.3.2",
"typescript": "^4.4.2",
"jest": "29.0.0",
"ts-jest": "^29.0.0"
"prettier": "^2.3.2",
"ts-jest": "^29.0.0",
"typescript": "^4.4.2"
}
}
1 change: 1 addition & 0 deletions programs/mmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ spl-associated-token-account = { version = "2.2.0", features = [
spl-token-2022 = {version = "1.0.0", features = ["no-entrypoint"] }
m2_interface = { path = "../m2_interface" }
mpl-core = "0.7.0"
mpl-bubblegum = "1.4.0"
4 changes: 4 additions & 0 deletions programs/mmm/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,8 @@ pub enum MMMErrorCode {
InvalidTokenExtension, // 0x1791
#[msg("Unsupported asset plugin")]
UnsupportedAssetPlugin, // 0x1792
#[msg("Invalid cnft metadata")]
InvalidCnftMetadata, // 0x1795
#[msg("Invalid cnft metadata args")]
InvalidCnftMetadataArgs, // 0x1796
}
63 changes: 63 additions & 0 deletions programs/mmm/src/instructions/cnft/metadata_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use anchor_lang::{prelude::*, AnchorDeserialize, AnchorSerialize};

// Below types are copied from mpl bubblegum crate so
// IDL will automatically include them
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)]
pub enum TokenStandard {
NonFungible,
FungibleAsset,
Fungible,
NonFungibleEdition,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct Collection {
pub verified: bool,
pub key: Pubkey,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)]
pub enum UseMethod {
Burn,
Multiple,
Single,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct Uses {
pub use_method: UseMethod,
pub remaining: u64,
pub total: u64,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq, PartialOrd, Hash)]
pub enum TokenProgramVersion {
Original,
Token2022,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct Creator {
pub address: Pubkey,
pub verified: bool,
/// The percentage share.
///
/// The value is a percentage, not basis points.
pub share: u8,
}

#[derive(AnchorSerialize, AnchorDeserialize, Clone)]
pub struct MetadataArgs {
pub name: String,
pub symbol: String, // Changed from Option<String> to String
pub uri: String,
pub seller_fee_basis_points: u16,
pub primary_sale_happened: bool, // Changed from Option<bool> to bool
pub is_mutable: bool, // Changed from Option<bool> to bool
pub edition_nonce: Option<u8>,
pub token_standard: Option<TokenStandard>, // Changed from Option<u8> to Option<TokenStandard>
pub collection: Option<Collection>,
pub uses: Option<Uses>,
pub token_program_version: TokenProgramVersion, // Assuming TokenProgramVersion is a simple u8
pub creators: Vec<Creator>,
}
5 changes: 5 additions & 0 deletions programs/mmm/src/instructions/cnft/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub mod metadata_args;
pub mod sol_cnft_fulfill_buy;

pub use metadata_args::*;
pub use sol_cnft_fulfill_buy::*;
Loading

0 comments on commit 1d4ccd5

Please sign in to comment.