From 175643f6abcd2238545cea544a937bfae8d0d940 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko <5252494+jsidorenko@users.noreply.github.com> Date: Tue, 23 May 2023 13:04:44 +0200 Subject: [PATCH] NFT Fractionalization on Westmint (#2600) * NFT Fractionalization on Westmint * Typos * One more typo * Undo Cargo.lock * Point to master * Referense the first instance of the assets pallet * Update cargo.lock --------- Co-authored-by: parity-processbot <> --- Cargo.lock | 48 +++++++++----- .../runtimes/assets/westmint/Cargo.toml | 4 ++ .../runtimes/assets/westmint/src/lib.rs | 49 +++++++++++++-- .../assets/westmint/src/weights/mod.rs | 1 + .../weights/pallet_nft_fractionalization.rs | 63 +++++++++++++++++++ .../assets/westmint/src/xcm_config.rs | 3 + 6 files changed, 149 insertions(+), 19 deletions(-) create mode 100644 parachains/runtimes/assets/westmint/src/weights/pallet_nft_fractionalization.rs diff --git a/Cargo.lock b/Cargo.lock index 70040aae764..e8f126ed221 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6707,7 +6707,7 @@ dependencies = [ [[package]] name = "pallet-alliance" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "array-bytes 4.2.0", "frame-benchmarking", @@ -6728,7 +6728,7 @@ dependencies = [ [[package]] name = "pallet-asset-tx-payment" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "frame-benchmarking", "frame-support", @@ -6746,7 +6746,7 @@ dependencies = [ [[package]] name = "pallet-assets" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "frame-benchmarking", "frame-support", @@ -6761,7 +6761,7 @@ dependencies = [ [[package]] name = "pallet-aura" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "frame-support", "frame-system", @@ -7076,7 +7076,7 @@ dependencies = [ [[package]] name = "pallet-contracts" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "bitflags", "environmental", @@ -7106,7 +7106,7 @@ dependencies = [ [[package]] name = "pallet-contracts-primitives" version = "7.0.0" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "bitflags", "parity-scale-codec", @@ -7119,7 +7119,7 @@ dependencies = [ [[package]] name = "pallet-contracts-proc-macro" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "proc-macro2", "quote", @@ -7236,7 +7236,7 @@ dependencies = [ [[package]] name = "pallet-glutton" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "blake2", "frame-benchmarking", @@ -7330,7 +7330,7 @@ dependencies = [ [[package]] name = "pallet-insecure-randomness-collective-flip" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "frame-support", "frame-system", @@ -7410,10 +7410,27 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-nft-fractionalization" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-assets", + "pallet-nfts", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-nfts" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "enumflags2", "frame-benchmarking", @@ -7431,7 +7448,7 @@ dependencies = [ [[package]] name = "pallet-nfts-runtime-api" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "frame-support", "pallet-nfts", @@ -7896,7 +7913,7 @@ dependencies = [ [[package]] name = "pallet-uniques" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "frame-benchmarking", "frame-support", @@ -11300,7 +11317,7 @@ dependencies = [ [[package]] name = "sc-consensus-aura" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "async-trait", "futures", @@ -13924,7 +13941,7 @@ dependencies = [ [[package]] name = "substrate-test-utils" version = "4.0.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "futures", "substrate-test-utils-derive", @@ -13934,7 +13951,7 @@ dependencies = [ [[package]] name = "substrate-test-utils-derive" version = "0.10.0-dev" -source = "git+https://github.com/paritytech/substrate?branch=master#784ac7e9cf42a88cf5ad105281633f705688bae9" +source = "git+https://github.com/paritytech/substrate?branch=master#bc3ce835964347166414203d68dccc26b9e9044f" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -15678,6 +15695,7 @@ dependencies = [ "pallet-balances", "pallet-collator-selection", "pallet-multisig", + "pallet-nft-fractionalization", "pallet-nfts", "pallet-nfts-runtime-api", "pallet-proxy", diff --git a/parachains/runtimes/assets/westmint/Cargo.toml b/parachains/runtimes/assets/westmint/Cargo.toml index b7484ec3122..16d7e606221 100644 --- a/parachains/runtimes/assets/westmint/Cargo.toml +++ b/parachains/runtimes/assets/westmint/Cargo.toml @@ -26,6 +26,7 @@ pallet-aura = { git = "https://github.com/paritytech/substrate", default-feature pallet-authorship = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-balances = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-multisig = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } +pallet-nft-fractionalization = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-nfts = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-nfts-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } pallet-proxy = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "master" } @@ -91,6 +92,7 @@ runtime-benchmarks = [ "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-multisig/runtime-benchmarks", + "pallet-nft-fractionalization/runtime-benchmarks", "pallet-nfts/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", @@ -121,6 +123,7 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-collator-selection/try-runtime", "pallet-multisig/try-runtime", + "pallet-nft-fractionalization/try-runtime", "pallet-nfts/try-runtime", "pallet-proxy/try-runtime", "pallet-session/try-runtime", @@ -145,6 +148,7 @@ std = [ "pallet-authorship/std", "pallet-balances/std", "pallet-multisig/std", + "pallet-nft-fractionalization/std", "pallet-nfts/std", "pallet-nfts-runtime-api/std", "pallet-proxy/std", diff --git a/parachains/runtimes/assets/westmint/src/lib.rs b/parachains/runtimes/assets/westmint/src/lib.rs index 83762145cf6..d4c714b0fa6 100644 --- a/parachains/runtimes/assets/westmint/src/lib.rs +++ b/parachains/runtimes/assets/westmint/src/lib.rs @@ -54,7 +54,7 @@ use frame_support::{ InstanceFilter, }, weights::{ConstantMultiplier, Weight}, - PalletId, RuntimeDebug, + BoundedVec, PalletId, RuntimeDebug, }; use frame_system::{ limits::{BlockLength, BlockWeights}, @@ -68,6 +68,7 @@ use parachains_common::{ Index, Signature, AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO, SLOT_DURATION, }; +use scale_info::TypeInfo; use xcm_config::{ ForeignAssetsConvertedConcreteId, TrustBackedAssetsConvertedConcreteId, WestendLocation, XcmConfig, XcmOriginToTransactDispatchOrigin, @@ -179,6 +180,15 @@ parameter_types! { pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT; } +/// A reason for placing a hold on funds. +#[derive( + Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, Debug, TypeInfo, +)] +pub enum HoldReason { + /// Used by the NFT Fractionalization Pallet. + NftFractionalization, +} + impl pallet_balances::Config for Runtime { type MaxLocks = ConstU32<50>; /// The type for recording an account's balance. @@ -191,9 +201,9 @@ impl pallet_balances::Config for Runtime { type WeightInfo = weights::pallet_balances::WeightInfo; type MaxReserves = ConstU32<50>; type ReserveIdentifier = [u8; 8]; - type HoldIdentifier = (); + type HoldIdentifier = HoldReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; + type MaxHolds = ConstU32<1>; type MaxFreezes = ConstU32<0>; } @@ -376,6 +386,7 @@ impl InstanceFilter for ProxyType { c, RuntimeCall::Balances { .. } | RuntimeCall::Assets { .. } | + RuntimeCall::NftFractionalization { .. } | RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ), @@ -391,6 +402,7 @@ impl InstanceFilter for ProxyType { RuntimeCall::Assets { .. } | RuntimeCall::Utility { .. } | RuntimeCall::Multisig { .. } | + RuntimeCall::NftFractionalization { .. } | RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. } ) }, @@ -624,6 +636,33 @@ impl pallet_uniques::Config for Runtime { type Locker = (); } +parameter_types! { + pub const NftFractionalizationPalletId: PalletId = PalletId(*b"fraction"); + pub NewAssetSymbol: BoundedVec = (*b"FRAC").to_vec().try_into().unwrap(); + pub NewAssetName: BoundedVec = (*b"Frac").to_vec().try_into().unwrap(); + pub const NftFractionalizationHoldReason: HoldReason = HoldReason::NftFractionalization; +} + +impl pallet_nft_fractionalization::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Deposit = AssetDeposit; + type Currency = Balances; + type NewAssetSymbol = NewAssetSymbol; + type NewAssetName = NewAssetName; + type StringLimit = AssetsStringLimit; + type NftCollectionId = ::CollectionId; + type NftId = ::ItemId; + type AssetBalance = ::Balance; + type AssetId = >::AssetId; + type Assets = Assets; + type Nfts = Nfts; + type PalletId = NftFractionalizationPalletId; + type WeightInfo = pallet_nft_fractionalization::weights::SubstrateWeight; + type HoldReason = NftFractionalizationHoldReason; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = (); +} + parameter_types! { pub NftsPalletFeatures: PalletFeatures = PalletFeatures::all_enabled(); pub const NftsMaxDeadlineDuration: BlockNumber = 12 * 30 * DAYS; @@ -708,6 +747,7 @@ construct_runtime!( Uniques: pallet_uniques::{Pallet, Call, Storage, Event} = 51, Nfts: pallet_nfts::{Pallet, Call, Storage, Event} = 52, ForeignAssets: pallet_assets::::{Pallet, Call, Storage, Event} = 53, + NftFractionalization: pallet_nft_fractionalization::{Pallet, Call, Storage, Event} = 54, } ); @@ -736,7 +776,7 @@ pub type UncheckedExtrinsic = /// Extrinsic type that has already been checked. pub type CheckedExtrinsic = generic::CheckedExtrinsic; /// Migrations to apply on runtime upgrade. -pub type Migrations = (pallet_nfts::migration::v1::MigrateToV1,); +pub type Migrations = (); /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< @@ -760,6 +800,7 @@ mod benches { [pallet_assets, ForeignAssets] [pallet_balances, Balances] [pallet_multisig, Multisig] + [pallet_nft_fractionalization, NftFractionalization] [pallet_nfts, Nfts] [pallet_proxy, Proxy] [pallet_session, SessionBench::] diff --git a/parachains/runtimes/assets/westmint/src/weights/mod.rs b/parachains/runtimes/assets/westmint/src/weights/mod.rs index 92af360ced1..0a0188da823 100644 --- a/parachains/runtimes/assets/westmint/src/weights/mod.rs +++ b/parachains/runtimes/assets/westmint/src/weights/mod.rs @@ -6,6 +6,7 @@ pub mod pallet_assets; pub mod pallet_balances; pub mod pallet_collator_selection; pub mod pallet_multisig; +pub mod pallet_nft_fractionalization; pub mod pallet_nfts; pub mod pallet_proxy; pub mod pallet_session; diff --git a/parachains/runtimes/assets/westmint/src/weights/pallet_nft_fractionalization.rs b/parachains/runtimes/assets/westmint/src/weights/pallet_nft_fractionalization.rs new file mode 100644 index 00000000000..d8db24f50e6 --- /dev/null +++ b/parachains/runtimes/assets/westmint/src/weights/pallet_nft_fractionalization.rs @@ -0,0 +1,63 @@ +// Copyright Parity Technologies (UK) Ltd. +// This file is part of Cumulus. + +// Cumulus is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Cumulus is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Cumulus. If not, see . + +//! Autogenerated weights for `pallet_nfts` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-05-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `bm6`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("westmint-dev"), DB CACHE: 1024 + +// Executed Command: +// ./artifacts/polkadot-parachain +// benchmark +// pallet +// --chain=westmint-dev +// --execution=wasm +// --wasm-execution=compiled +// --pallet=pallet_nft_fractionalization +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --json +// --header=./file_header.txt +// --output=./parachains/runtimes/assets/westmint/src/weights/pallet_nft_fractionalization.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_nfts`. +pub struct WeightInfo(PhantomData); +impl pallet_nft_fractionalization::WeightInfo for WeightInfo { + fn fractionalize() -> Weight { + // Minimum execution time: 44_312 nanoseconds. + Weight::from_parts(25_147_000, 3549) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + fn unify() -> Weight { + // Minimum execution time: 31_654 nanoseconds. + Weight::from_parts(25_147_000, 3549) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } +} diff --git a/parachains/runtimes/assets/westmint/src/xcm_config.rs b/parachains/runtimes/assets/westmint/src/xcm_config.rs index c183d6c2676..c802e99e26b 100644 --- a/parachains/runtimes/assets/westmint/src/xcm_config.rs +++ b/parachains/runtimes/assets/westmint/src/xcm_config.rs @@ -271,6 +271,9 @@ impl Contains for SafeCallFilter { pallet_assets::Call::transfer_approved { .. } | pallet_assets::Call::touch { .. } | pallet_assets::Call::refund { .. }, + ) | RuntimeCall::NftFractionalization( + pallet_nft_fractionalization::Call::fractionalize { .. } | + pallet_nft_fractionalization::Call::unify { .. }, ) | RuntimeCall::Nfts( pallet_nfts::Call::create { .. } | pallet_nfts::Call::force_create { .. } |