Skip to content

Commit

Permalink
Add Operator Burn mode + tests (#250)
Browse files Browse the repository at this point in the history
* Add operator burn mode + tests

* Add burner to events

* Typo

* syntax

* Update readme

* Typo

* Bad merge

* Update docs/modalities.md

Co-authored-by: Adam Stone <97986246+ACStoneCL@users.noreply.github.com>

* Update docs/modalities.md

Co-authored-by: Adam Stone <97986246+ACStoneCL@users.noreply.github.com>

* Revert version change

---------

Co-authored-by: Adam Stone <97986246+ACStoneCL@users.noreply.github.com>
  • Loading branch information
gRoussac and ACStone-MTS authored Oct 3, 2023
1 parent b08ff4e commit 82ceccf
Show file tree
Hide file tree
Showing 18 changed files with 819 additions and 201 deletions.
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ All notable changes to this project will be documented in this file. The format
[comment]: <> (Fixed: any bug fixes)
[comment]: <> (Security: in case of vulnerabilities)

## Release 1.5.0
## [Unreleased]

### Changed

Expand All @@ -23,9 +23,11 @@ All notable changes to this project will be documented in this file. The format

### Added

- ACL package mode - Including a contract package in the `acl_whitelist` will result in automatic whitelisting for any future versions of that contract.
- ACL package mode - Including a contract package in the `acl_whitelist` will result in automatic whitelisting for any future versions of that contract. (#249)

- Package operator mode - Approving a package in `operators` allows any future version of that contract to act as an operator for transfer/approve/revoke entrypoints.
- Package operator mode - Approving a package in `operators` allows any future version of that contract to act as an operator for transfer/approve/revoke entrypoints. (#249)

- Operator burn mode. This modes adds the possibility for operators to burn NFTs. (#250)

## Release 1.4.0

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,5 @@ by using the provided `Makefile` and running the `make test` command.
| 164 | MissingACLPackageMode |
| 165 | InvalidPackageOperatorMode |
| 166 | MissingPackageOperatorMode |
| 167 | InvalidOperatorBurnMode |
| 168 | MissingOperatorBurnMode |
23 changes: 13 additions & 10 deletions contract/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,32 @@ pub const PREFIX_HASH_KEY_NAME: &str = "cep78_contract_package";
pub const PREFIX_PAGE_DICTIONARY: &str = "page";

pub const ARG_ACCESS_KEY_NAME_1_0_0: &str = "access_key_name";
pub const ARG_ACL_PACKAGE_MODE: &str = "acl_package_mode";
pub const ARG_ACL_WHITELIST: &str = "acl_whitelist";
pub const ARG_ADDITIONAL_REQUIRED_METADATA: &str = "additional_required_metadata";
pub const ARG_ALLOW_MINTING: &str = "allow_minting";
pub const ARG_APPROVE_ALL: &str = "approve_all";
pub const ARG_BURN_MODE: &str = "burn_mode";
pub const ARG_COLLECTION_NAME: &str = "collection_name";
pub const ARG_COLLECTION_SYMBOL: &str = "collection_symbol";
pub const ARG_CONTRACT_WHITELIST: &str = "contract_whitelist";
pub const ARG_ACL_WHITELIST: &str = "acl_whitelist";
pub const ARG_EVENTS_MODE: &str = "events_mode";
pub const ARG_ACL_PACKAGE_MODE: &str = "acl_package_mode";
pub const ARG_PACKAGE_OPERATOR_MODE: &str = "package_operator_mode";
pub const ARG_HASH_KEY_NAME_1_0_0: &str = "hash_key_name";
pub const ARG_HOLDER_MODE: &str = "holder_mode";
pub const ARG_IDENTIFIER_MODE: &str = "identifier_mode";
pub const ARG_JSON_SCHEMA: &str = "json_schema";
pub const ARG_OPERATOR: &str = "operator";
pub const ARG_METADATA_MUTABILITY: &str = "metadata_mutability";
pub const ARG_MINTING_MODE: &str = "minting_mode";
pub const ARG_NAMED_KEY_CONVENTION: &str = "named_key_convention";
pub const ARG_NFT_KIND: &str = "nft_kind";
pub const ARG_NFT_METADATA_KIND: &str = "nft_metadata_kind";
pub const ARG_NFT_PACKAGE_KEY: &str = "cep78_package_key";
pub const ARG_OPTIONAL_METADATA: &str = "optional_metadata";
pub const ARG_OPERATOR: &str = "operator";
pub const ARG_OPERATOR_BURN_MODE: &str = "operator_burn_mode";
pub const ARG_OWNERSHIP_MODE: &str = "ownership_mode";
pub const ARG_OWNER_LOOKUP_MODE: &str = "owner_reverse_lookup_mode";
pub const ARG_PACKAGE_OPERATOR_MODE: &str = "package_operator_mode";
pub const ARG_RECEIPT_NAME: &str = "receipt_name";
pub const ARG_SOURCE_KEY: &str = "source_key";
pub const ARG_SPENDER: &str = "spender";
Expand All @@ -40,8 +41,8 @@ pub const ARG_TOKEN_ID: &str = "token_id";
pub const ARG_TOKEN_META_DATA: &str = "token_meta_data";
pub const ARG_TOKEN_OWNER: &str = "token_owner";
pub const ARG_TOTAL_TOKEN_SUPPLY: &str = "total_token_supply";
pub const ARG_WHITELIST_MODE: &str = "whitelist_mode";
pub const ARG_TRANSFER_FILTER_CONTRACT: &str = "transfer_filter_contract";
pub const ARG_WHITELIST_MODE: &str = "whitelist_mode";

pub const ENTRY_POINT_APPROVE: &str = "approve";
pub const ENTRY_POINT_BALANCE_OF: &str = "balance_of";
Expand All @@ -61,19 +62,18 @@ pub const ENTRY_POINT_SET_VARIABLES: &str = "set_variables";
pub const ENTRY_POINT_TRANSFER: &str = "transfer";
pub const ENTRY_POINT_UPDATED_RECEIPTS: &str = "updated_receipts";

pub const ACL_PACKAGE_MODE: &str = "acl_package_mode";
pub const ACL_WHITELIST: &str = "acl_whitelist";
pub const ALLOW_MINTING: &str = "allow_minting";
pub const APPROVED: &str = "approved";
pub const BURN_MODE: &str = "burn_mode";
pub const BURNT_TOKENS: &str = "burnt_tokens";
pub const COLLECTION_NAME: &str = "collection_name";
pub const COLLECTION_SYMBOL: &str = "collection_symbol";
pub const CONTRACT_WHITELIST: &str = "contract_whitelist";
pub const ACL_WHITELIST: &str = "acl_whitelist";
pub const EVENT_TYPE: &str = "event_type";
pub const EVENTS: &str = "events";
pub const EVENTS_MODE: &str = "events_mode";
pub const ACL_PACKAGE_MODE: &str = "acl_package_mode";
pub const PACKAGE_OPERATOR_MODE: &str = "package_operator_mode";
pub const HASH_BY_INDEX: &str = "hash_by_index";
pub const HOLDER_MODE: &str = "holder_mode";
pub const IDENTIFIER_MODE: &str = "identifier_mode";
Expand All @@ -93,9 +93,12 @@ pub const NFT_METADATA_KINDS: &str = "nft_metadata_kinds";
pub const NUMBER_OF_MINTED_TOKENS: &str = "number_of_minted_tokens";
pub const OPERATOR: &str = "operator";
pub const OPERATORS: &str = "operators";
pub const OPERATOR_BURN_MODE: &str = "operator_burn_mode";
pub const OWNED_TOKENS: &str = "owned_tokens";
pub const OWNER: &str = "owner";
pub const BURNER: &str = "burner";
pub const OWNERSHIP_MODE: &str = "ownership_mode";
pub const PACKAGE_OPERATOR_MODE: &str = "package_operator_mode";
pub const PAGE_LIMIT: &str = "page_limit";
pub const PAGE_TABLE: &str = "page_table";
pub const RECEIPT_NAME: &str = "receipt_name";
Expand All @@ -109,10 +112,10 @@ pub const TOKEN_ID: &str = "token_id";
pub const TOKEN_ISSUERS: &str = "token_issuers";
pub const TOKEN_OWNERS: &str = "token_owners";
pub const TOTAL_TOKEN_SUPPLY: &str = "total_token_supply";
pub const UNMATCHED_HASH_COUNT: &str = "unmatched_hash_count";
pub const WHITELIST_MODE: &str = "whitelist_mode";
pub const TRANSFER_FILTER_CONTRACT: &str = "transfer_filter_contract";
pub const TRANSFER_FILTER_CONTRACT_METHOD: &str = "can_transfer";
pub const UNMATCHED_HASH_COUNT: &str = "unmatched_hash_count";
pub const WHITELIST_MODE: &str = "whitelist_mode";

// The cap on the amount of tokens within a given CEP-78 collection.
pub const MAX_TOTAL_TOKEN_SUPPLY: u64 = 1_000_000u64;
Expand Down
2 changes: 2 additions & 0 deletions contract/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ pub enum NFTCoreError {
MissingACLPackageMode = 164,
InvalidPackageOperatorMode = 165,
MissingPackageOperatorMode = 166,
InvalidOperatorBurnMode = 167,
MissingOperatorBurnMode = 168,
}

impl From<NFTCoreError> for ApiError {
Expand Down
12 changes: 9 additions & 3 deletions contract/src/events/events_cep47.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use casper_types::Key;

use crate::{
constants::{
EVENTS, EVENT_TYPE, OPERATOR, OWNER, PREFIX_CEP78, PREFIX_HASH_KEY_NAME, RECIPIENT, SENDER,
SPENDER, TOKEN_ID,
BURNER, EVENTS, EVENT_TYPE, OPERATOR, OWNER, PREFIX_CEP78, PREFIX_HASH_KEY_NAME, RECIPIENT,
SENDER, SPENDER, TOKEN_ID,
},
error::NFTCoreError,
modalities::TokenIdentifier,
Expand All @@ -28,6 +28,7 @@ pub enum CEP47Event {
Burn {
owner: Key,
token_id: TokenIdentifier,
burner: Key,
},
ApprovalGranted {
owner: Key,
Expand Down Expand Up @@ -83,12 +84,17 @@ pub fn record_cep47_event_dictionary(event: CEP47Event) {
event.insert(TOKEN_ID, token_id.to_string());
event
}
CEP47Event::Burn { owner, token_id } => {
CEP47Event::Burn {
owner,
token_id,
burner,
} => {
let mut event = BTreeMap::new();
event.insert(PREFIX_HASH_KEY_NAME, package);
event.insert(EVENT_TYPE, "Burn".to_string());
event.insert(OWNER, owner.to_string());
event.insert(TOKEN_ID, token_id.to_string());
event.insert(BURNER, burner.to_string());
event
}
CEP47Event::ApprovalGranted {
Expand Down
4 changes: 3 additions & 1 deletion contract/src/events/events_ces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ impl Mint {
pub struct Burn {
owner: Key,
token_id: String,
burner: Key,
}

impl Burn {
pub fn new(owner: Key, token_id: TokenIdentifier) -> Self {
pub fn new(owner: Key, token_id: TokenIdentifier, burner: Key) -> Self {
Self {
owner,
token_id: token_id.to_string(),
burner,
}
}
}
Expand Down
Loading

0 comments on commit 82ceccf

Please sign in to comment.