This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
NFTs fractionalization #12565
Merged
Merged
NFTs fractionalization #12565
Changes from all commits
Commits
Show all changes
131 commits
Select commit
Hold shift + click to select a range
10c6230
Copy Uniques into Nfts
af8875d
Connect new pallet
cd15630
Merge branch 'master' into js/uniques-v2-main-branch
69edfb2
Update weights
028ea38
Nfts: Multiple approvals (#12178)
Szegoo e337c5a
Merge remote-tracking branch 'origin/master' into js/uniques-v2-main-…
KiChjang 4930d81
Fixes
KiChjang f369ba9
cargo fmt
KiChjang ae5561e
Fixes
KiChjang f34b0ff
Fixes
KiChjang 0edd25b
Merge branch 'master' into js/uniques-v2-main-branch
c62ec92
Merge branch 'master' into js/uniques-v2-main-branch
d09df86
Fix CI
3ab3356
Nfts: Fix Auto-Increment (#12223)
Szegoo e5a31cf
Merge branch 'master' into js/uniques-v2-main-branch
6434da8
Rename Origin to RuntimeOrigin
61dee82
[Uniques V2] Tips (#12168)
jsidorenko 490a0fa
[Uniques V2] Atomic NFTs swap (#12285)
jsidorenko 3137791
Merge branch 'master' into js/uniques-v2-main-branch
ef16fd2
[Uniques V2] Feature flags (#12367)
jsidorenko 6763dd6
[Uniques V2] Refactor roles (#12437)
jsidorenko fef9b48
Fix copy
799cdf3
Remove storage_prefix
83a601d
Remove transactional
cbffb27
Initial commit SFT pallet.
lana-shanghai e1b24d7
Update comment
0c3f77f
Merge branch 'master' into js/uniques-v2-main-branch
3c12fed
Merge branch 'master' into js/uniques-v2-main-branch
c3d9a60
Merge uniques v2
lana-shanghai 1813960
Merge branch 'master' into js/uniques-v2-main-branch
afd4c18
[Uniques V2] Minting options (#12483)
jsidorenko 090cd18
Merge branch 'js/uniques-v2-main-branch' into li/sft-main-branch
lana-shanghai 841574f
Rename module to NFT fractionalisation
lana-shanghai eab8e04
Loose coupling for pallet-assets
lana-shanghai a37f8d1
cargo fmt
lana-shanghai 8b95f6b
Merge branch 'master' into js/uniques-v2-main-branch
8caecbb
[Uniques V2] Smart attributes (#12702)
jsidorenko b4ff566
[Uniques V2] Final improvements (#12736)
jsidorenko 4c1b7f7
Update frame/nfts/src/lib.rs
jsidorenko f94926b
Merge branch 'master' of https://github.com/paritytech/substrate into…
beb8caa
".git/.scripts/bench-bot.sh" pallet dev pallet_nfts
6e651a8
Update docs
b051fd8
Typo
0556185
Fix benchmarks
992601b
Add more docs
5732492
Replace uniques with nfts, add minted volume storage
lana-shanghai e907e15
DepositRequired setting should affect only the attributes within the …
524c336
Merge branch 'master' into js/uniques-v2-main-branch
3ad4980
Add unlock functionality
lana-shanghai 9f27e91
[NFTs] Implement missed methods to set the attributes from other pall…
jsidorenko ea37f25
Revert snapshot changes
b15c602
Merge branch 'master' into js/uniques-v2-main-branch
c057f02
Update snapshots
5aaa37f
Yet another snapshot update..
0482d19
Asset to NFT id storage mutations
lana-shanghai 9a0e3b2
Merge branch 'js/uniques-v2-main-branch' into li/sft-main-branch
lana-shanghai 6fea293
Minor fixes
lana-shanghai 0f9f4a9
Minor comments
lana-shanghai 6814a94
cargo fmt
lana-shanghai 95493ad
Remove benchmarking, unused clone()
lana-shanghai f07e7d0
Update frame/support/src/traits/tokens/nonfungible_v2.rs
jsidorenko b1fe6f7
Update frame/support/src/traits/tokens/nonfungible_v2.rs
jsidorenko 917bb1e
Update frame/support/src/traits/tokens/nonfungible_v2.rs
jsidorenko 92f43f6
Update frame/support/src/traits/tokens/nonfungibles_v2.rs
jsidorenko 30985da
Update frame/nfts/src/lib.rs
jsidorenko 0d1a442
Update frame/nfts/src/lib.rs
jsidorenko d429d6e
Update frame/nfts/src/lib.rs
jsidorenko 5de99c8
Update frame/nfts/src/lib.rs
jsidorenko dcbce57
Update frame/nfts/src/lib.rs
jsidorenko 1db5061
Update frame/support/src/traits/tokens/nonfungible_v2.rs
jsidorenko 7653b99
Update frame/nfts/src/lib.rs
jsidorenko 46f6451
Update frame/support/src/traits/tokens/nonfungibles_v2.rs
jsidorenko 91ffabb
Update frame/nfts/src/lib.rs
jsidorenko 8057d72
Update frame/nfts/src/lib.rs
jsidorenko d082300
Update frame/nfts/src/lib.rs
jsidorenko 8f18f08
Update frame/nfts/src/lib.rs
jsidorenko 27e2f38
Address comments
56f228d
[NFTs] Add the new `owner` param to mint() method (#12997)
jsidorenko 105c8f5
Merge branch 'master' of https://github.com/paritytech/substrate into…
a8c69a9
".git/.scripts/bench-bot.sh" pallet dev pallet_nfts
08c1205
Merge branch 'js/uniques-v2-main-branch' into li/sft-main-branch
72501e4
Fmt
7df1e2c
Update frame/nfts/src/common_functions.rs
jsidorenko 2323614
Update frame/nfts/src/types.rs
jsidorenko 08f0ea2
Update frame/nfts/src/types.rs
jsidorenko 66cbec6
Update frame/nfts/src/types.rs
jsidorenko 3218b20
Update frame/nfts/src/types.rs
jsidorenko 40ecc60
Update frame/nfts/src/types.rs
jsidorenko 30c0f23
Add call indexes
f618543
Update snapshots
3fb7c72
Merge branch 'js/uniques-v2-main-branch' into li/sft-main-branch
39d5c0c
Merge branch 'master' into li/sft-main-branch
84587d0
Merge branch 'master' into li/sft-main-branch
e8e3bed
Merge branch 'master' into li/sft-main-branch
553d262
Refactor nft fractionalisation pallet (#13008)
jsidorenko 92f860b
Merge branch 'master' into li/sft-main-branch
c4ab35c
fmt
8e00a6b
Add fee reserved before creating an asset
lana-shanghai 9df16c3
Use ReservableCurrency for fee deposit
lana-shanghai ea81d24
Improvements
e27331b
Revert fmt changes
4a13b27
A bit more cleanup
bd619d2
Consistent naming
98236e1
Make it more generic
caccb14
Leftover
96ec9a3
Use Vec<u8> instead of String
a172c1c
Merge branch 'master' into li/sft-main-branch
ed16d14
Update to the latest + improve the Locker trait
aabff98
Refactor NFTs locker
447df48
Replace Vec with BoundedVec, add clearer errors
lana-shanghai 50212e3
cargo fmt
lana-shanghai 14bb74d
Add README about unlocking NFTs
lana-shanghai 9aa89e3
add constant definition
lana-shanghai f2ff0f7
Merge branch 'master' into li/sft-main-branch
lana-shanghai d539da0
add fortitude & precision to asset related functions
lana-shanghai ab7ad4a
fix mock and tests
lana-shanghai 200ff45
transfer ExistentialDeposit to pallet if it's balance is below
lana-shanghai 2b01abe
Merge branch 'master' into li/sft-main-branch
lana-shanghai 6b28757
Merge remote-tracking branch 'origin/master' into li/sft-main-branch
af4725d
Refactoring
0fa54b0
Simplify the locking mechanism
4990242
Use PalletAttributes enum instead of the LOCKED_NFT_KEY
2bd4dc9
Fix benchmark
5631060
Merge remote-tracking branch 'origin/master' into li/sft-main-branch
7e54a89
Add missing licence details
042d152
Update Cargo.toml
507d485
Merge branch 'master' of https://github.com/paritytech/substrate into…
16f256f
".git/.scripts/commands/bench/bench.sh" pallet dev pallet_nft_fractio…
594b2cb
Apply suggestions from code review
jsidorenko e4cb5ac
Update frame/nft-fractionalization/README.md
jsidorenko 9d34086
Merge remote-tracking branch 'origin/master' into li/sft-main-branch
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,52 @@ | ||
| [package] | ||
| name = "pallet-nft-fractionalization" | ||
| 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 pallet to convert non-fungible to fungible tokens." | ||
| readme = "README.md" | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = ["x86_64-unknown-linux-gnu"] | ||
|
|
||
| [dependencies] | ||
| codec = { package = "parity-scale-codec", version = "3.2.2", default-features = false } | ||
| log = { version = "0.4.17", default-features = false } | ||
| scale-info = { version = "2.5.0", 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" } | ||
| pallet-assets = { version = "4.0.0-dev", default-features = false, path = "../assets" } | ||
| pallet-nfts = { version = "4.0.0-dev", default-features = false, path = "../nfts" } | ||
| 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", | ||
| "pallet-assets/std", | ||
| "pallet-nfts/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"] |
This file contains hidden or 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,6 @@ | ||
| ### Lock NFT | ||
|
|
||
| Lock an NFT from `pallet-nfts` and mint fungible assets from `pallet-assets`. | ||
|
|
||
| The NFT gets locked by putting a system-level attribute named `Locked`. This prevents the NFT from being transferred further. | ||
| The NFT becomes unlocked when the `Locked` attribute is removed. In order to unify the fungible asset and unlock the NFT, an account must hold the full issuance of the asset the NFT was fractionalised into. Holding less of the fungible asset will not allow the unlocking of the NFT. | ||
This file contains hidden or 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,135 @@ | ||
| // This file is part of Substrate. | ||
|
|
||
| // Copyright (C) 2020-2022 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. | ||
|
|
||
| //! Nft fractionalization pallet benchmarking. | ||
|
|
||
| #![cfg(feature = "runtime-benchmarks")] | ||
|
|
||
| use super::*; | ||
| use frame_benchmarking::{benchmarks, whitelisted_caller}; | ||
| use frame_support::{ | ||
| assert_ok, | ||
| traits::{ | ||
| fungible::{Inspect as InspectFungible, Mutate as MutateFungible}, | ||
| tokens::nonfungibles_v2::{Create, Mutate}, | ||
| Get, | ||
| }, | ||
| }; | ||
| use frame_system::RawOrigin as SystemOrigin; | ||
| use pallet_nfts::{CollectionConfig, CollectionSettings, ItemConfig, MintSettings}; | ||
| use sp_runtime::traits::StaticLookup; | ||
| use sp_std::prelude::*; | ||
|
|
||
| use crate::Pallet as NftFractionalization; | ||
|
|
||
| type BalanceOf<T> = | ||
| <<T as Config>::Currency as InspectFungible<<T as SystemConfig>::AccountId>>::Balance; | ||
|
|
||
| type CollectionConfigOf<T> = CollectionConfig< | ||
| BalanceOf<T>, | ||
| <T as SystemConfig>::BlockNumber, | ||
| <T as Config>::NftCollectionId, | ||
| >; | ||
|
|
||
| fn default_collection_config<T: Config>() -> CollectionConfigOf<T> | ||
| where | ||
| T::Currency: InspectFungible<T::AccountId>, | ||
| { | ||
| CollectionConfig { | ||
| settings: CollectionSettings::all_enabled(), | ||
| max_supply: None, | ||
| mint_settings: MintSettings::default(), | ||
| } | ||
| } | ||
|
|
||
| fn mint_nft<T: Config>(nft_id: T::NftId) -> (T::AccountId, AccountIdLookupOf<T>) | ||
| where | ||
| T::Nfts: Create<T::AccountId, CollectionConfig<BalanceOf<T>, T::BlockNumber, T::NftCollectionId>> | ||
| + Mutate<T::AccountId, ItemConfig>, | ||
| { | ||
| let caller: T::AccountId = whitelisted_caller(); | ||
| let caller_lookup = T::Lookup::unlookup(caller.clone()); | ||
| let ed = T::Currency::minimum_balance(); | ||
| let multiplier = BalanceOf::<T>::from(100u8); | ||
| T::Currency::set_balance(&caller, ed * multiplier + T::Deposit::get() * multiplier); | ||
|
|
||
| assert_ok!(T::Nfts::create_collection(&caller, &caller, &default_collection_config::<T>())); | ||
| let collection = T::BenchmarkHelper::collection(0); | ||
| assert_ok!(T::Nfts::mint_into(&collection, &nft_id, &caller, &ItemConfig::default(), true)); | ||
| (caller, caller_lookup) | ||
| } | ||
|
|
||
| fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) { | ||
| let events = frame_system::Pallet::<T>::events(); | ||
| let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into(); | ||
| // compare to the last event record | ||
| let frame_system::EventRecord { event, .. } = &events[events.len() - 1]; | ||
| assert_eq!(event, &system_event); | ||
| } | ||
|
|
||
| benchmarks! { | ||
| where_clause { | ||
| where | ||
| T::Nfts: Create<T::AccountId, CollectionConfig<BalanceOf<T>, T::BlockNumber, T::NftCollectionId>> | ||
| + Mutate<T::AccountId, ItemConfig>, | ||
| } | ||
|
|
||
| fractionalize { | ||
| let asset = T::BenchmarkHelper::asset(0); | ||
| let collection = T::BenchmarkHelper::collection(0); | ||
| let nft = T::BenchmarkHelper::nft(0); | ||
| let (caller, caller_lookup) = mint_nft::<T>(nft); | ||
| }: _(SystemOrigin::Signed(caller.clone()), collection, nft, asset, caller_lookup, 1000u32.into()) | ||
| verify { | ||
| assert_last_event::<T>( | ||
| Event::NftFractionalized { | ||
| nft_collection: collection, | ||
| nft, | ||
| fractions: 1000u32.into(), | ||
| asset, | ||
| beneficiary: caller, | ||
| }.into() | ||
| ); | ||
| } | ||
|
|
||
| unify { | ||
| let asset = T::BenchmarkHelper::asset(0); | ||
| let collection = T::BenchmarkHelper::collection(0); | ||
| let nft = T::BenchmarkHelper::nft(0); | ||
| let (caller, caller_lookup) = mint_nft::<T>(nft); | ||
| NftFractionalization::<T>::fractionalize( | ||
| SystemOrigin::Signed(caller.clone()).into(), | ||
| collection, | ||
| nft, | ||
| asset, | ||
| caller_lookup.clone(), | ||
| 1000u32.into(), | ||
| )?; | ||
| }: _(SystemOrigin::Signed(caller.clone()), collection, nft, asset, caller_lookup) | ||
| verify { | ||
| assert_last_event::<T>( | ||
| Event::NftUnified { | ||
| nft_collection: collection, | ||
| nft, | ||
| asset, | ||
| beneficiary: caller, | ||
| }.into() | ||
| ); | ||
| } | ||
|
|
||
| impl_benchmark_test_suite!(NftFractionalization, crate::mock::new_test_ext(), crate::mock::Test); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.