Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

NFTs 2.0 #12765

Merged
merged 74 commits into from
Dec 23, 2022
Merged

NFTs 2.0 #12765

Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
10c6230
Copy Uniques into Nfts
jsidorenko Aug 29, 2022
af8875d
Connect new pallet
jsidorenko Aug 29, 2022
cd15630
Merge branch 'master' into js/uniques-v2-main-branch
jsidorenko Sep 8, 2022
69edfb2
Update weights
jsidorenko Sep 9, 2022
028ea38
Nfts: Multiple approvals (#12178)
Szegoo Sep 13, 2022
e337c5a
Merge remote-tracking branch 'origin/master' into js/uniques-v2-main-…
KiChjang Sep 15, 2022
4930d81
Fixes
KiChjang Sep 15, 2022
f369ba9
cargo fmt
KiChjang Sep 15, 2022
ae5561e
Fixes
KiChjang Sep 15, 2022
f34b0ff
Fixes
KiChjang Sep 15, 2022
0edd25b
Merge branch 'master' into js/uniques-v2-main-branch
jsidorenko Sep 19, 2022
c62ec92
Merge branch 'master' into js/uniques-v2-main-branch
jsidorenko Sep 19, 2022
d09df86
Fix CI
jsidorenko Sep 19, 2022
3ab3356
Nfts: Fix Auto-Increment (#12223)
Szegoo Sep 23, 2022
e5a31cf
Merge branch 'master' into js/uniques-v2-main-branch
jsidorenko Sep 24, 2022
6434da8
Rename Origin to RuntimeOrigin
jsidorenko Sep 24, 2022
61dee82
[Uniques V2] Tips (#12168)
jsidorenko Sep 24, 2022
490a0fa
[Uniques V2] Atomic NFTs swap (#12285)
jsidorenko Oct 5, 2022
3137791
Merge branch 'master' into js/uniques-v2-main-branch
jsidorenko Oct 14, 2022
ef16fd2
[Uniques V2] Feature flags (#12367)
jsidorenko Oct 18, 2022
6763dd6
[Uniques V2] Refactor roles (#12437)
jsidorenko Oct 20, 2022
fef9b48
Fix copy
jsidorenko Oct 23, 2022
799cdf3
Remove storage_prefix
jsidorenko Oct 23, 2022
83a601d
Remove transactional
jsidorenko Oct 23, 2022
e1b24d7
Update comment
jsidorenko Oct 28, 2022
0c3f77f
Merge branch 'master' into js/uniques-v2-main-branch
jsidorenko Nov 8, 2022
3c12fed
Merge branch 'master' into js/uniques-v2-main-branch
jsidorenko Nov 14, 2022
1813960
Merge branch 'master' into js/uniques-v2-main-branch
jsidorenko Nov 16, 2022
afd4c18
[Uniques V2] Minting options (#12483)
jsidorenko Nov 16, 2022
8b95f6b
Merge branch 'master' into js/uniques-v2-main-branch
jsidorenko Nov 17, 2022
8caecbb
[Uniques V2] Smart attributes (#12702)
jsidorenko Nov 21, 2022
b4ff566
[Uniques V2] Final improvements (#12736)
jsidorenko Nov 23, 2022
4c1b7f7
Update frame/nfts/src/lib.rs
jsidorenko Nov 23, 2022
f94926b
Merge branch 'master' of https://github.com/paritytech/substrate into…
Nov 25, 2022
beb8caa
".git/.scripts/bench-bot.sh" pallet dev pallet_nfts
Nov 25, 2022
6e651a8
Update docs
jsidorenko Nov 28, 2022
b051fd8
Typo
jsidorenko Nov 28, 2022
0556185
Fix benchmarks
jsidorenko Nov 28, 2022
992601b
Add more docs
jsidorenko Nov 28, 2022
e907e15
DepositRequired setting should affect only the attributes within the …
jsidorenko Dec 8, 2022
524c336
Merge branch 'master' into js/uniques-v2-main-branch
jsidorenko Dec 13, 2022
9f27e91
[NFTs] Implement missed methods to set the attributes from other pall…
jsidorenko Dec 13, 2022
ea37f25
Revert snapshot changes
jsidorenko Dec 14, 2022
b15c602
Merge branch 'master' into js/uniques-v2-main-branch
jsidorenko Dec 14, 2022
c057f02
Update snapshots
jsidorenko Dec 14, 2022
5aaa37f
Yet another snapshot update..
jsidorenko Dec 14, 2022
f07e7d0
Update frame/support/src/traits/tokens/nonfungible_v2.rs
jsidorenko Dec 20, 2022
b1fe6f7
Update frame/support/src/traits/tokens/nonfungible_v2.rs
jsidorenko Dec 20, 2022
917bb1e
Update frame/support/src/traits/tokens/nonfungible_v2.rs
jsidorenko Dec 20, 2022
92f43f6
Update frame/support/src/traits/tokens/nonfungibles_v2.rs
jsidorenko Dec 20, 2022
30985da
Update frame/nfts/src/lib.rs
jsidorenko Dec 20, 2022
0d1a442
Update frame/nfts/src/lib.rs
jsidorenko Dec 20, 2022
d429d6e
Update frame/nfts/src/lib.rs
jsidorenko Dec 20, 2022
5de99c8
Update frame/nfts/src/lib.rs
jsidorenko Dec 20, 2022
dcbce57
Update frame/nfts/src/lib.rs
jsidorenko Dec 20, 2022
1db5061
Update frame/support/src/traits/tokens/nonfungible_v2.rs
jsidorenko Dec 20, 2022
7653b99
Update frame/nfts/src/lib.rs
jsidorenko Dec 20, 2022
46f6451
Update frame/support/src/traits/tokens/nonfungibles_v2.rs
jsidorenko Dec 20, 2022
91ffabb
Update frame/nfts/src/lib.rs
jsidorenko Dec 20, 2022
8057d72
Update frame/nfts/src/lib.rs
jsidorenko Dec 20, 2022
d082300
Update frame/nfts/src/lib.rs
jsidorenko Dec 20, 2022
8f18f08
Update frame/nfts/src/lib.rs
jsidorenko Dec 20, 2022
27e2f38
Address comments
jsidorenko Dec 20, 2022
56f228d
[NFTs] Add the new `owner` param to mint() method (#12997)
jsidorenko Dec 22, 2022
105c8f5
Merge branch 'master' of https://github.com/paritytech/substrate into…
Dec 22, 2022
a8c69a9
".git/.scripts/bench-bot.sh" pallet dev pallet_nfts
Dec 22, 2022
7df1e2c
Update frame/nfts/src/common_functions.rs
jsidorenko Dec 23, 2022
2323614
Update frame/nfts/src/types.rs
jsidorenko Dec 23, 2022
08f0ea2
Update frame/nfts/src/types.rs
jsidorenko Dec 23, 2022
66cbec6
Update frame/nfts/src/types.rs
jsidorenko Dec 23, 2022
3218b20
Update frame/nfts/src/types.rs
jsidorenko Dec 23, 2022
40ecc60
Update frame/nfts/src/types.rs
jsidorenko Dec 23, 2022
30c0f23
Add call indexes
jsidorenko Dec 23, 2022
f618543
Update snapshots
jsidorenko Dec 23, 2022
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
23 changes: 21 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ members = [
"frame/offences",
"frame/preimage",
"frame/proxy",
"frame/nfts",
"frame/nomination-pools",
"frame/nomination-pools/fuzzer",
"frame/nomination-pools/benchmarking",
Expand Down
4 changes: 4 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ pallet-lottery = { version = "4.0.0-dev", default-features = false, path = "../.
pallet-membership = { version = "4.0.0-dev", default-features = false, path = "../../../frame/membership" }
pallet-mmr = { version = "4.0.0-dev", default-features = false, path = "../../../frame/merkle-mountain-range" }
pallet-multisig = { version = "4.0.0-dev", default-features = false, path = "../../../frame/multisig" }
pallet-nfts = { version = "4.0.0-dev", default-features = false, path = "../../../frame/nfts" }
pallet-nomination-pools = { version = "1.0.0", default-features = false, path = "../../../frame/nomination-pools"}
pallet-nomination-pools-benchmarking = { version = "1.0.0", default-features = false, optional = true, path = "../../../frame/nomination-pools/benchmarking" }
pallet-nomination-pools-runtime-api = { version = "1.0.0-dev", default-features = false, path = "../../../frame/nomination-pools/runtime-api" }
Expand Down Expand Up @@ -196,6 +197,7 @@ std = [
"pallet-root-testing/std",
"pallet-recovery/std",
"pallet-uniques/std",
"pallet-nfts/std",
"pallet-vesting/std",
"log/std",
"frame-try-runtime?/std",
Expand Down Expand Up @@ -251,6 +253,7 @@ runtime-benchmarks = [
"pallet-treasury/runtime-benchmarks",
"pallet-utility/runtime-benchmarks",
"pallet-uniques/runtime-benchmarks",
"pallet-nfts/runtime-benchmarks",
"pallet-vesting/runtime-benchmarks",
"pallet-whitelist/runtime-benchmarks",
"frame-system-benchmarking/runtime-benchmarks",
Expand Down Expand Up @@ -309,6 +312,7 @@ try-runtime = [
"pallet-asset-tx-payment/try-runtime",
"pallet-transaction-storage/try-runtime",
"pallet-uniques/try-runtime",
"pallet-nfts/try-runtime",
"pallet-vesting/try-runtime",
"pallet-whitelist/try-runtime",
]
Expand Down
40 changes: 40 additions & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use pallet_grandpa::{
fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList,
};
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_nfts::PalletFeatures;
use pallet_session::historical::{self as pallet_session_historical};
pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment};
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
Expand Down Expand Up @@ -296,6 +297,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
RuntimeCall::Balances(..) |
RuntimeCall::Assets(..) |
RuntimeCall::Uniques(..) |
RuntimeCall::Nfts(..) |
RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. }) |
RuntimeCall::Indices(pallet_indices::Call::transfer { .. })
),
Expand Down Expand Up @@ -1488,6 +1490,10 @@ parameter_types! {
pub const ItemDeposit: Balance = 1 * DOLLARS;
pub const KeyLimit: u32 = 32;
pub const ValueLimit: u32 = 256;
pub const ApprovalsLimit: u32 = 20;
pub const ItemAttributesApprovalsLimit: u32 = 20;
pub const MaxTips: u32 = 10;
pub const MaxDeadlineDuration: BlockNumber = 12 * 30 * DAYS;
}

impl pallet_uniques::Config for Runtime {
Expand All @@ -1511,6 +1517,38 @@ impl pallet_uniques::Config for Runtime {
type Locker = ();
}

parameter_types! {
pub Features: PalletFeatures = PalletFeatures::all_enabled();
pub const NftsPalletId: PalletId = PalletId(*b"py/nfts_");
}

impl pallet_nfts::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type CollectionId = u32;
type ItemId = u32;
type Currency = Balances;
type ForceOrigin = frame_system::EnsureRoot<AccountId>;
type CollectionDeposit = CollectionDeposit;
type ItemDeposit = ItemDeposit;
type MetadataDepositBase = MetadataDepositBase;
type AttributeDepositBase = MetadataDepositBase;
type DepositPerByte = MetadataDepositPerByte;
type StringLimit = StringLimit;
type KeyLimit = KeyLimit;
type ValueLimit = ValueLimit;
type ApprovalsLimit = ApprovalsLimit;
type ItemAttributesApprovalsLimit = ItemAttributesApprovalsLimit;
type MaxTips = MaxTips;
type MaxDeadlineDuration = MaxDeadlineDuration;
type Features = Features;
type WeightInfo = pallet_nfts::weights::SubstrateWeight<Runtime>;
type PalletId = NftsPalletId;
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type Locker = ();
}

impl pallet_transaction_storage::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
Expand Down Expand Up @@ -1665,6 +1703,7 @@ construct_runtime!(
Lottery: pallet_lottery,
Gilt: pallet_gilt,
Uniques: pallet_uniques,
Nfts: pallet_nfts,
TransactionStorage: pallet_transaction_storage,
VoterList: pallet_bags_list::<Instance1>,
StateTrieMigration: pallet_state_trie_migration,
Expand Down Expand Up @@ -1794,6 +1833,7 @@ mod benches {
[pallet_transaction_storage, TransactionStorage]
[pallet_treasury, Treasury]
[pallet_uniques, Uniques]
[pallet_nfts, Nfts]
[pallet_utility, Utility]
[pallet_vesting, Vesting]
[pallet_whitelist, Whitelist]
Expand Down
49 changes: 49 additions & 0 deletions frame/nfts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[package]
name = "pallet-nfts"
version = "4.0.0-dev"
authors = ["Parity Technologies <[email protected]>"]
edition = "2021"
license = "Apache-2.0"
homepage = "https://substrate.io"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME NFTs pallet"
readme = "README.md"

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

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
enumflags2 = { version = "0.7.5" }
log = { version = "0.4.17", default-features = false }
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, path = "../benchmarking" }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../system" }
sp-runtime = { version = "7.0.0", default-features = false, path = "../../primitives/runtime" }
sp-std = { version = "5.0.0", default-features = false, path = "../../primitives/std" }

[dev-dependencies]
pallet-balances = { version = "4.0.0-dev", path = "../balances" }
sp-core = { version = "7.0.0", path = "../../primitives/core" }
sp-io = { version = "7.0.0", path = "../../primitives/io" }
sp-std = { version = "5.0.0", path = "../../primitives/std" }

[features]
default = ["std"]
std = [
"codec/std",
"frame-benchmarking?/std",
"frame-support/std",
"frame-system/std",
"log/std",
"scale-info/std",
"sp-runtime/std",
"sp-std/std",
]
runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = ["frame-support/try-runtime"]
106 changes: 106 additions & 0 deletions frame/nfts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# 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
Loading