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

NFT Fractionalization on Westmint #2600

Merged
merged 12 commits into from
May 23, 2023
4 changes: 4 additions & 0 deletions parachains/runtimes/assets/westmint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
49 changes: 45 additions & 4 deletions parachains/runtimes/assets/westmint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ use frame_support::{
InstanceFilter,
},
weights::{ConstantMultiplier, Weight},
PalletId, RuntimeDebug,
BoundedVec, PalletId, RuntimeDebug,
};
use frame_system::{
limits::{BlockLength, BlockWeights},
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -191,9 +201,9 @@ impl pallet_balances::Config for Runtime {
type WeightInfo = weights::pallet_balances::WeightInfo<Runtime>;
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>;
}

Expand Down Expand Up @@ -376,6 +386,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
c,
RuntimeCall::Balances { .. } |
RuntimeCall::Assets { .. } |
RuntimeCall::NftFractionalization { .. } |
RuntimeCall::Nfts { .. } |
RuntimeCall::Uniques { .. }
),
Expand All @@ -391,6 +402,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
RuntimeCall::Assets { .. } |
RuntimeCall::Utility { .. } |
RuntimeCall::Multisig { .. } |
RuntimeCall::NftFractionalization { .. } |
RuntimeCall::Nfts { .. } | RuntimeCall::Uniques { .. }
)
},
Expand Down Expand Up @@ -624,6 +636,33 @@ impl pallet_uniques::Config for Runtime {
type Locker = ();
}

parameter_types! {
pub const NftFractionalizationPalletId: PalletId = PalletId(*b"fraction");
pub NewAssetSymbol: BoundedVec<u8, AssetsStringLimit> = (*b"FRAC").to_vec().try_into().unwrap();
pub NewAssetName: BoundedVec<u8, AssetsStringLimit> = (*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 = <Self as pallet_nfts::Config>::CollectionId;
type NftId = <Self as pallet_nfts::Config>::ItemId;
type AssetBalance = <Self as pallet_balances::Config>::Balance;
type AssetId = <Self as pallet_assets::Config<TrustBackedAssetsInstance>>::AssetId;
type Assets = Assets;
type Nfts = Nfts;
type PalletId = NftFractionalizationPalletId;
type WeightInfo = pallet_nft_fractionalization::weights::SubstrateWeight<Runtime>;
type HoldReason = NftFractionalizationHoldReason;
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = ();
}

parameter_types! {
pub NftsPalletFeatures: PalletFeatures = PalletFeatures::all_enabled();
pub const NftsMaxDeadlineDuration: BlockNumber = 12 * 30 * DAYS;
Expand Down Expand Up @@ -708,6 +747,7 @@ construct_runtime!(
Uniques: pallet_uniques::{Pallet, Call, Storage, Event<T>} = 51,
Nfts: pallet_nfts::{Pallet, Call, Storage, Event<T>} = 52,
ForeignAssets: pallet_assets::<Instance2>::{Pallet, Call, Storage, Event<T>} = 53,
NftFractionalization: pallet_nft_fractionalization::{Pallet, Call, Storage, Event<T>} = 54,
}
);

Expand Down Expand Up @@ -736,7 +776,7 @@ pub type UncheckedExtrinsic =
/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic = generic::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra>;
/// Migrations to apply on runtime upgrade.
pub type Migrations = (pallet_nfts::migration::v1::MigrateToV1<Runtime>,);
pub type Migrations = ();

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Expand All @@ -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::<Runtime>]
Expand Down
1 change: 1 addition & 0 deletions parachains/runtimes/assets/westmint/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

//! 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<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_nft_fractionalization::WeightInfo for WeightInfo<T> {
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))
}
}
3 changes: 3 additions & 0 deletions parachains/runtimes/assets/westmint/src/xcm_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ impl Contains<RuntimeCall> 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 { .. } |
Expand Down