Skip to content

Commit

Permalink
chore: fork pallet nfts (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin authored Nov 18, 2024
1 parent 3cdb9b5 commit aff6408
Show file tree
Hide file tree
Showing 29 changed files with 12,480 additions and 6 deletions.
28 changes: 23 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ substrate-wasm-builder = "23.0.0"

# Local
pallet-api = { path = "pallets/api", default-features = false }
pallet-nfts = { path = "pallets/nfts", default-features = false }
pop-chain-extension = { path = "./extension", default-features = false }
pop-primitives = { path = "./primitives", default-features = false }
pop-runtime-common = { path = "runtime/common", default-features = false }
Expand All @@ -90,7 +91,6 @@ pallet-contracts = { version = "35.0.0", default-features = false }
pallet-message-queue = { version = "39.0.0", default-features = false }
pallet-multisig = { version = "36.0.0", default-features = false }
pallet-nft-fractionalization = { version = "18.0.0", default-features = false }
pallet-nfts = { version = "30.0.0", default-features = false }
pallet-nfts-runtime-api = { version = "22.0.0", default-features = false }
pallet-preimage = { version = "36.0.0", default-features = false }
pallet-proxy = { version = "36.0.0", default-features = false }
Expand Down
59 changes: 59 additions & 0 deletions pallets/nfts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[package]
authors = [ "Parity Technologies <[email protected]>", "R0GUE <[email protected]>" ]
description = "Fork of FRAME NFTs pallet"
edition.workspace = true
homepage = "https://substrate.io"
license.workspace = true
name = "pallet-nfts"
readme = "README.md"
repository.workspace = true
version = "31.0.0"

[package.metadata.docs.rs]
targets = [ "x86_64-unknown-linux-gnu" ]

[dependencies]
codec = { workspace = true }
enumflags2 = { workspace = true }
log = { workspace = true }
scale-info = { features = [ "derive" ], workspace = true }

# Substrate
frame-benchmarking = { optional = true, workspace = true }
frame-support.workspace = true
frame-system.workspace = true
sp-core.workspace = true
sp-io.workspace = true
sp-runtime.workspace = true

[dev-dependencies]
pallet-balances.workspace = true
sp-keystore.workspace = true

[features]
default = [ "std" ]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
std = [
"codec/std",
"enumflags2/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"pallet-balances/std",
"scale-info/std",
"sp-core/std",
"sp-io/std",
"sp-keystore/std",
"sp-runtime/std",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]
108 changes: 108 additions & 0 deletions pallets/nfts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# NFTs pallet

A pallet for dealing with non-fungible assets.

## Overview

The NFTs pallet provides functionality for non-fungible tokens' management, including:

* Collection Creation
* NFT Minting
* NFT Transfers and Atomic Swaps
* NFT Trading methods
* Attributes Management
* NFT Burning

To use it in your runtime, you need to implement
[`nfts::Config`](https://paritytech.github.io/substrate/master/pallet_nfts/pallet/trait.Config.html).

The supported dispatchable functions are documented in the
[`nfts::Call`](https://paritytech.github.io/substrate/master/pallet_nfts/pallet/enum.Call.html) enum.

### Terminology

* **Collection creation:** The creation of a new collection.
* **NFT minting:** The action of creating a new item within a collection.
* **NFT transfer:** The action of sending an item from one account to another.
* **Atomic swap:** The action of exchanging items between accounts without needing a 3rd party service.
* **NFT burning:** The destruction of an item.
* **Non-fungible token (NFT):** An item for which each unit has unique characteristics. There is exactly one instance of
such an item in existence and there is exactly one owning account (though that owning account could be a proxy account
or multi-sig account).
* **Soul Bound NFT:** An item that is non-transferable from the account which it is minted into.

### Goals

The NFTs pallet in Substrate is designed to make the following possible:

* Allow accounts to permissionlessly create nft collections.
* Allow a named (permissioned) account to mint and burn unique items within a collection.
* Move items between accounts permissionlessly.
* Allow a named (permissioned) account to freeze and unfreeze items within a collection or the entire collection.
* Allow the owner of an item to delegate the ability to transfer the item to some named third-party.
* Allow third-parties to store information in an NFT _without_ owning it (Eg. save game state).

## Interface

### Permissionless dispatchables

* `create`: Create a new collection by placing a deposit.
* `mint`: Mint a new item within a collection (when the minting is public).
* `transfer`: Send an item to a new owner.
* `redeposit`: Update the deposit amount of an item, potentially freeing funds.
* `approve_transfer`: Name a delegate who may authorize a transfer.
* `cancel_approval`: Revert the effects of a previous `approve_transfer`.
* `approve_item_attributes`: Name a delegate who may change item's attributes within a namespace.
* `cancel_item_attributes_approval`: Revert the effects of a previous `approve_item_attributes`.
* `set_price`: Set the price for an item.
* `buy_item`: Buy an item.
* `pay_tips`: Pay tips, could be used for paying the creator royalties.
* `create_swap`: Create an offer to swap an NFT for another NFT and optionally some fungibles.
* `cancel_swap`: Cancel previously created swap offer.
* `claim_swap`: Swap items in an atomic way.


### Permissioned dispatchables

* `destroy`: Destroy a collection. This destroys all the items inside the collection and refunds the deposit.
* `force_mint`: Mint a new item within a collection.
* `burn`: Destroy an item within a collection.
* `lock_item_transfer`: Prevent an individual item from being transferred.
* `unlock_item_transfer`: Revert the effects of a previous `lock_item_transfer`.
* `clear_all_transfer_approvals`: Clears all transfer approvals set by calling the `approve_transfer`.
* `lock_collection`: Prevent all items within a collection from being transferred (making them all `soul bound`).
* `lock_item_properties`: Lock item's metadata or attributes.
* `transfer_ownership`: Alter the owner of a collection, moving all associated deposits. (Ownership of individual items
will not be affected.)
* `set_team`: Alter the permissioned accounts of a collection.
* `set_collection_max_supply`: Change the max supply of a collection.
* `update_mint_settings`: Update the minting settings for collection.


### Metadata (permissioned) dispatchables

* `set_attribute`: Set a metadata attribute of an item or collection.
* `clear_attribute`: Remove a metadata attribute of an item or collection.
* `set_metadata`: Set general metadata of an item (E.g. an IPFS address of an image url).
* `clear_metadata`: Remove general metadata of an item.
* `set_collection_metadata`: Set general metadata of a collection.
* `clear_collection_metadata`: Remove general metadata of a collection.


### Force (i.e. governance) dispatchables

* `force_create`: Create a new collection (the collection id can not be chosen).
* `force_collection_owner`: Change collection's owner.
* `force_collection_config`: Change collection's config.
* `force_set_attribute`: Set an attribute.

Please refer to the [`Call`](https://paritytech.github.io/substrate/master/pallet_nfts/pallet/enum.Call.html) enum and
its associated variants for documentation on each function.

## Related Modules

* [`System`](https://docs.rs/frame-system/latest/frame_system/)
* [`Support`](https://docs.rs/frame-support/latest/frame_support/)
* [`Assets`](https://docs.rs/pallet-assets/latest/pallet_assets/)

License: Apache-2.0
25 changes: 25 additions & 0 deletions pallets/nfts/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
authors = [ "Parity Technologies <[email protected]>", "R0GUE <[email protected]>" ]
description = "Runtime API for the FRAME NFTs pallet."
edition.workspace = true
homepage = "https://substrate.io"
license = "Apache-2.0"
name = "pallet-nfts-runtime-api"
readme = "README.md"
repository.workspace = true
version = "23.0.0"

[lints]
workspace = true

[package.metadata.docs.rs]
targets = [ "x86_64-unknown-linux-gnu" ]

[dependencies]
codec = { features = [ "derive" ], workspace = true }
pallet-nfts.workspace = true
sp-api.workspace = true

[features]
default = [ "std" ]
std = [ "codec/std", "pallet-nfts/std", "sp-api/std" ]
3 changes: 3 additions & 0 deletions pallets/nfts/runtime-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RPC runtime API for the FRAME NFTs pallet.

License: Apache-2.0
59 changes: 59 additions & 0 deletions pallets/nfts/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Runtime API definition for the FRAME NFTs pallet.

#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

use alloc::vec::Vec;
use codec::{Decode, Encode};

sp_api::decl_runtime_apis! {
pub trait NftsApi<AccountId, CollectionId, ItemId>
where
AccountId: Encode + Decode,
CollectionId: Encode,
ItemId: Encode,
{
fn owner(collection: CollectionId, item: ItemId) -> Option<AccountId>;

fn collection_owner(collection: CollectionId) -> Option<AccountId>;

fn attribute(
collection: CollectionId,
item: ItemId,
key: Vec<u8>,
) -> Option<Vec<u8>>;

fn custom_attribute(
account: AccountId,
collection: CollectionId,
item: ItemId,
key: Vec<u8>,
) -> Option<Vec<u8>>;

fn system_attribute(
collection: CollectionId,
item: Option<ItemId>,
key: Vec<u8>,
) -> Option<Vec<u8>>;

fn collection_attribute(collection: CollectionId, key: Vec<u8>) -> Option<Vec<u8>>;
}
}
Loading

0 comments on commit aff6408

Please sign in to comment.