git.delta.rocks / unique-network / refs/commits / fb1ebd6bb0f6

difftreelog

refactor move ChainLimits to runtime config

Yaroslav Bolyukin2021-08-10parent: #8c07465.patch.diff
in: master

6 files changed

modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -202,18 +202,6 @@
 			nft_item_id: vec![],
 			fungible_item_id: vec![],
 			refungible_item_id: vec![],
-			chain_limit: ChainLimits {
-				collection_numbers_limit: 100000,
-				account_token_ownership_limit: 1000000,
-				collections_admins_limit: 5,
-				custom_data_limit: 2048,
-				nft_sponsor_transfer_timeout: 15,
-				fungible_sponsor_transfer_timeout: 15,
-				refungible_sponsor_transfer_timeout: 15,
-				offchain_schema_limit: 1024,
-				variable_on_chain_schema_limit: 1024,
-				const_on_chain_schema_limit: 1024,
-			},
 		},
 		parachain_info: nft_runtime::ParachainInfoConfig { parachain_id: id },
 		aura: nft_runtime::AuraConfig {
modifiedpallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth
--- a/pallets/nft/src/eth/sponsoring.rs
+++ b/pallets/nft/src/eth/sponsoring.rs
@@ -1,12 +1,13 @@
 //! Implements EVM sponsoring logic via OnChargeEVMTransaction
 
 use crate::{
-	ChainLimit, Collection, CollectionById, Config, FungibleTransferBasket, NftTransferBasket,
-	eth::{account::EvmBackwardsAddressMapping, map_eth_to_id},
+	Collection, CollectionById, Config, FungibleTransferBasket, NftTransferBasket,
+	eth::{account::EvmBackwardsAddressMapping, map_eth_to_id}, limit,
 };
 use evm_coder::{Call, abi::AbiReader};
 use frame_support::{
-	storage::{StorageMap, StorageDoubleMap, StorageValue},
+	storage::{StorageMap, StorageDoubleMap},
+	traits::Get,
 };
 use sp_core::H160;
 use sp_std::prelude::*;
@@ -43,7 +44,7 @@
 					let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
 						collection_limits.sponsor_transfer_timeout
 					} else {
-						ChainLimit::get().nft_sponsor_transfer_timeout
+						<limit!(T, NftSponsorTransferTimeout)>::get()
 					};
 
 					let mut sponsor = true;
@@ -74,7 +75,7 @@
 					let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
 						collection_limits.sponsor_transfer_timeout
 					} else {
-						ChainLimit::get().fungible_sponsor_transfer_timeout
+						<limit!(T, FungibleSponsorTransferTimeout)>::get()
 					};
 
 					let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -31,7 +31,7 @@
 	StorageValue, transactional,
 };
 
-use frame_system::{self as system, ensure_signed, ensure_root};
+use frame_system::{self as system, ensure_signed};
 use sp_core::H160;
 use sp_std::vec;
 use sp_runtime::sp_std::prelude::Vec;
@@ -243,6 +243,15 @@
 		<<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,
 	>;
 	type TreasuryAccountId: Get<Self::AccountId>;
+	type ChainLimits: ChainLimits;
+}
+
+pub type ChainLimitsOf<T> = <T as Config>::ChainLimits;
+#[macro_export]
+macro_rules! limit {
+	($config:ty, $limit:ident) => {
+		<$crate::ChainLimitsOf<$config> as nft_data_structs::ChainLimits>::$limit
+	}
 }
 
 // # Used definitions
@@ -280,10 +289,6 @@
 		ItemListIndex: map hasher(blake2_128_concat) CollectionId => TokenId;
 		//#endregion
 
-		//#region Chain limits struct
-		pub ChainLimit get(fn chain_limit) config(): ChainLimits;
-		//#endregion
-
 		//#region Bound counters
 		/// Amount of collections destroyed, used for total amount tracking with
 		/// CreatedCollectionCount
@@ -485,14 +490,12 @@
 				CollectionMode::Fungible(points) => points,
 				_ => 0
 			};
-
-			let chain_limit = ChainLimit::get();
 
 			let created_count = CreatedCollectionCount::get();
 			let destroyed_count = DestroyedCollectionCount::get();
 
 			// bound Total number of collections
-			ensure!(created_count - destroyed_count < chain_limit.collection_numbers_limit, Error::<T>::TotalCollectionsLimitExceeded);
+			ensure!(created_count - destroyed_count < <limit!(T, CollectionNumberLimit)>::get(), Error::<T>::TotalCollectionsLimitExceeded);
 
 			// check params
 			ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);
@@ -508,7 +511,7 @@
 			CreatedCollectionCount::put(next_id);
 
 			let limits = CollectionLimits {
-				sponsored_data_size: chain_limit.custom_data_limit,
+				sponsored_data_size: <limit!(T, CustomDataLimit)>::get(),
 				..Default::default()
 			};
 
@@ -737,8 +740,7 @@
 			match admin_arr.binary_search(&new_admin_id) {
 				Ok(_) => {},
 				Err(idx) => {
-					let limits = ChainLimit::get();
-					ensure!(admin_arr.len() < limits.collections_admins_limit as usize, Error::<T>::CollectionAdminsLimitExceeded);
+					ensure!(admin_arr.len() < <limit!(T, CollectionAdminsLimit)>::get() as usize, Error::<T>::CollectionAdminsLimitExceeded);
 					admin_arr.insert(idx, new_admin_id);
 					<AdminList<T>>::insert(collection_id, admin_arr);
 				}
@@ -862,7 +864,7 @@
 
 		#[weight = <T as Config>::WeightInfo::create_item(data.data_size())]
 		#[transactional]
-		pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResult {
+		pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData<ChainLimitsOf<T>>) -> DispatchResult {
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let collection = Self::get_collection(collection_id)?;
 
@@ -893,7 +895,7 @@
 							   .map(|data| { data.data_size() })
 							   .sum())]
 		#[transactional]
-		pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResult {
+		pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData<ChainLimitsOf<T>>>) -> DispatchResult {
 
 			ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
@@ -1138,7 +1140,7 @@
 			Self::check_owner_or_admin_permissions(&target_collection, &sender)?;
 
 			// check schema limit
-			ensure!(schema.len() as u32 <= ChainLimit::get().offchain_schema_limit, "");
+			ensure!(schema.len() as u32 <= <limit!(T, OffchainSchemaLimit)>::get(), "");
 
 			target_collection.offchain_schema = schema;
 			target_collection.save()
@@ -1168,7 +1170,7 @@
 			Self::check_owner_or_admin_permissions(&target_collection, &sender)?;
 
 			// check schema limit
-			ensure!(schema.len() as u32 <= ChainLimit::get().const_on_chain_schema_limit, "");
+			ensure!(schema.len() as u32 <= <limit!(T, ConstOnChainSchemaLimit)>::get(), "");
 
 			target_collection.const_on_chain_schema = schema;
 			target_collection.save()
@@ -1198,25 +1200,10 @@
 			Self::check_owner_or_admin_permissions(&target_collection, &sender)?;
 
 			// check schema limit
-			ensure!(schema.len() as u32 <= ChainLimit::get().variable_on_chain_schema_limit, "");
+			ensure!(schema.len() as u32 <= <limit!(T, VariableOnChainSchemaLimit)>::get(), "");
 
 			target_collection.variable_on_chain_schema = schema;
 			target_collection.save()
-		}
-
-		// Sudo permissions function
-		#[weight = <T as Config>::WeightInfo::set_chain_limits()]
-		#[transactional]
-		pub fn set_chain_limits(
-			origin,
-			limits: ChainLimits
-		) -> DispatchResult {
-
-			#[cfg(not(feature = "runtime-benchmarks"))]
-			ensure_root(origin)?;
-
-			<ChainLimit>::put(limits);
-			Ok(())
 		}
 
 		#[weight = <T as Config>::WeightInfo::set_collection_limits()]
@@ -1230,12 +1217,11 @@
 			let mut target_collection = Self::get_collection(collection_id)?;
 			Self::check_owner_permissions(&target_collection, sender.as_sub())?;
 			let old_limits = &target_collection.limits;
-			let chain_limits = ChainLimit::get();
 
 			// collection bounds
 			ensure!(new_limits.sponsor_transfer_timeout <= MAX_SPONSOR_TIMEOUT &&
 				new_limits.account_token_ownership_limit <= MAX_TOKEN_OWNERSHIP &&
-				new_limits.sponsored_data_size <= chain_limits.custom_data_limit,
+				new_limits.sponsored_data_size <= <ChainLimitsOf<T> as ChainLimits>::CustomDataLimit::get(),
 				Error::<T>::CollectionLimitBoundsExceeded);
 
 			// token_limit   check  prev
@@ -1260,7 +1246,7 @@
 		sender: &T::CrossAccountId,
 		collection: &CollectionHandle<T>,
 		owner: &T::CrossAccountId,
-		data: CreateItemData,
+		data: CreateItemData<ChainLimitsOf<T>>,
 	) -> DispatchResult {
 		Self::can_create_items_in_collection(collection, sender, owner, 1)?;
 		Self::validate_create_item_args(collection, &data)?;
@@ -1471,7 +1457,7 @@
 		Self::token_exists(collection, item_id)?;
 
 		ensure!(
-			ChainLimit::get().custom_data_limit >= data.len() as u32,
+			<limit!(T, CustomDataLimit)>::get() >= data.len() as u32,
 			Error::<T>::TokenVariableDataLimitExceeded
 		);
 
@@ -1498,7 +1484,7 @@
 		sender: &T::CrossAccountId,
 		collection: &CollectionHandle<T>,
 		owner: &T::CrossAccountId,
-		items_data: Vec<CreateItemData>,
+		items_data: Vec<CreateItemData<ChainLimitsOf<T>>>,
 	) -> DispatchResult {
 		Self::can_create_items_in_collection(collection, sender, owner, items_data.len() as u32)?;
 
@@ -1612,18 +1598,18 @@
 
 	fn validate_create_item_args(
 		target_collection: &CollectionHandle<T>,
-		data: &CreateItemData,
+		data: &CreateItemData<ChainLimitsOf<T>>,
 	) -> DispatchResult {
 		match target_collection.mode {
 			CollectionMode::NFT => {
 				if let CreateItemData::NFT(data) = data {
 					// check sizes
 					ensure!(
-						ChainLimit::get().custom_data_limit >= data.const_data.len() as u32,
+						<limit!(T, CustomDataLimit)>::get() >= data.const_data.len() as u32,
 						Error::<T>::TokenConstDataLimitExceeded
 					);
 					ensure!(
-						ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32,
+						<limit!(T, CustomDataLimit)>::get() >= data.variable_data.len() as u32,
 						Error::<T>::TokenVariableDataLimitExceeded
 					);
 				} else {
@@ -1640,11 +1626,11 @@
 				if let CreateItemData::ReFungible(data) = data {
 					// check sizes
 					ensure!(
-						ChainLimit::get().custom_data_limit >= data.const_data.len() as u32,
+						<limit!(T, CustomDataLimit)>::get() >= data.const_data.len() as u32,
 						Error::<T>::TokenConstDataLimitExceeded
 					);
 					ensure!(
-						ChainLimit::get().custom_data_limit >= data.variable_data.len() as u32,
+						<limit!(T, CustomDataLimit)>::get() >= data.variable_data.len() as u32,
 						Error::<T>::TokenVariableDataLimitExceeded
 					);
 
@@ -1669,7 +1655,7 @@
 	fn create_item_no_validation(
 		collection: &CollectionHandle<T>,
 		owner: &T::CrossAccountId,
-		data: CreateItemData,
+		data: CreateItemData<ChainLimitsOf<T>>,
 	) -> DispatchResult {
 		match data {
 			CreateItemData::NFT(data) => {
@@ -2292,7 +2278,7 @@
 			// bound Owned tokens by a single address
 			let count = <AccountItemCount<T>>::get(owner.as_sub());
 			ensure!(
-				count < ChainLimit::get().account_token_ownership_limit,
+				count < <limit!(T, AccountTokenOwnershipLimit)>::get(),
 				Error::<T>::AddressOwnershipLimitExceeded
 			);
 
modifiedpallets/nft/src/sponsorship.rsdiffbeforeafterboth
before · pallets/nft/src/sponsorship.rs
1use crate::{2	Config, Call, CollectionById, CreateItemBasket, VariableMetaDataBasket,3	ReFungibleTransferBasket, FungibleTransferBasket, NftTransferBasket, ChainLimit,4	CreateItemData, CollectionMode,5};6use core::marker::PhantomData;7use up_sponsorship::SponsorshipHandler;8use frame_support::{9	traits::IsSubType,10	storage::{StorageMap, StorageDoubleMap, StorageValue},11};12use nft_data_structs::{TokenId, CollectionId};1314pub struct NftSponsorshipHandler<T>(PhantomData<T>);15impl<T: Config> NftSponsorshipHandler<T> {16	pub fn withdraw_create_item(17		who: &T::AccountId,18		collection_id: &CollectionId,19		_properties: &CreateItemData,20	) -> Option<T::AccountId> {21		let collection = CollectionById::<T>::get(collection_id)?;2223		// sponsor timeout24		let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;2526		let limit = collection.limits.sponsor_transfer_timeout;27		if CreateItemBasket::<T>::contains_key((collection_id, &who)) {28			let last_tx_block = CreateItemBasket::<T>::get((collection_id, &who));29			let limit_time = last_tx_block + limit.into();30			if block_number <= limit_time {31				return None;32			}33		}34		CreateItemBasket::<T>::insert((collection_id, who.clone()), block_number);3536		// check free create limit37		if collection.limits.sponsored_data_size >= (_properties.data_size() as u32) {38			collection.sponsorship.sponsor().cloned()39		} else {40			None41		}42	}4344	pub fn withdraw_transfer(45		who: &T::AccountId,46		collection_id: &CollectionId,47		item_id: &TokenId,48	) -> Option<T::AccountId> {49		let collection = CollectionById::<T>::get(collection_id)?;50		let limits = ChainLimit::get();5152		let mut sponsor_transfer = false;53		if collection.sponsorship.confirmed() {54			let collection_limits = collection.limits.clone();55			let collection_mode = collection.mode.clone();5657			// sponsor timeout58			let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;59			sponsor_transfer = match collection_mode {60				CollectionMode::NFT => {61					// get correct limit62					let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {63						collection_limits.sponsor_transfer_timeout64					} else {65						limits.nft_sponsor_transfer_timeout66					};6768					let mut sponsored = true;69					if NftTransferBasket::<T>::contains_key(collection_id, item_id) {70						let last_tx_block = NftTransferBasket::<T>::get(collection_id, item_id);71						let limit_time = last_tx_block + limit.into();72						if block_number <= limit_time {73							sponsored = false;74						}75					}76					if sponsored {77						NftTransferBasket::<T>::insert(collection_id, item_id, block_number);78					}7980					sponsored81				}82				CollectionMode::Fungible(_) => {83					// get correct limit84					let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {85						collection_limits.sponsor_transfer_timeout86					} else {87						limits.fungible_sponsor_transfer_timeout88					};8990					let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;91					let mut sponsored = true;92					if FungibleTransferBasket::<T>::contains_key(collection_id, who) {93						let last_tx_block = FungibleTransferBasket::<T>::get(collection_id, who);94						let limit_time = last_tx_block + limit.into();95						if block_number <= limit_time {96							sponsored = false;97						}98					}99					if sponsored {100						FungibleTransferBasket::<T>::insert(collection_id, who, block_number);101					}102103					sponsored104				}105				CollectionMode::ReFungible => {106					// get correct limit107					let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {108						collection_limits.sponsor_transfer_timeout109					} else {110						limits.refungible_sponsor_transfer_timeout111					};112113					let mut sponsored = true;114					if ReFungibleTransferBasket::<T>::contains_key(collection_id, item_id) {115						let last_tx_block =116							ReFungibleTransferBasket::<T>::get(collection_id, item_id);117						let limit_time = last_tx_block + limit.into();118						if block_number <= limit_time {119							sponsored = false;120						}121					}122					if sponsored {123						ReFungibleTransferBasket::<T>::insert(collection_id, item_id, block_number);124					}125126					sponsored127				}128				_ => false,129			};130		}131132		if !sponsor_transfer {133			None134		} else {135			collection.sponsorship.sponsor().cloned()136		}137	}138139	pub fn withdraw_set_variable_meta_data(140		collection_id: &CollectionId,141		item_id: &TokenId,142		data: &[u8],143	) -> Option<T::AccountId> {144		let mut sponsor_metadata_changes = false;145146		let collection = CollectionById::<T>::get(collection_id)?;147148		if collection.sponsorship.confirmed() &&149			// Can't sponsor fungible collection, this tx will be rejected150			// as invalid151			!matches!(collection.mode, CollectionMode::Fungible(_)) &&152			data.len() <= collection.limits.sponsored_data_size as usize153		{154			if let Some(rate_limit) = collection.limits.sponsored_data_rate_limit {155				let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;156157				if VariableMetaDataBasket::<T>::get(collection_id, item_id)158					.map(|last_block| block_number - last_block > rate_limit)159					.unwrap_or(true)160				{161					sponsor_metadata_changes = true;162					VariableMetaDataBasket::<T>::insert(collection_id, item_id, block_number);163				}164			}165		}166167		if !sponsor_metadata_changes {168			None169		} else {170			collection.sponsorship.sponsor().cloned()171		}172	}173}174175impl<T, C> SponsorshipHandler<T::AccountId, C> for NftSponsorshipHandler<T>176where177	T: Config,178	C: IsSubType<Call<T>>,179{180	fn get_sponsor(who: &T::AccountId, call: &C) -> Option<T::AccountId> {181		match IsSubType::<Call<T>>::is_sub_type(call)? {182			Call::create_item(collection_id, _owner, properties) => {183				Self::withdraw_create_item(who, collection_id, properties)184			}185			Call::transfer(_new_owner, collection_id, item_id, _value) => {186				Self::withdraw_transfer(who, collection_id, item_id)187			}188			Call::set_variable_meta_data(collection_id, item_id, data) => {189				Self::withdraw_set_variable_meta_data(collection_id, item_id, data)190			}191			_ => None,192		}193	}194}
modifiedprimitives/nft/src/lib.rsdiffbeforeafterboth
--- a/primitives/nft/src/lib.rs
+++ b/primitives/nft/src/lib.rs
@@ -28,14 +28,6 @@
 pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;
 pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;
 
-// TODO: Somehow use ChainLimits for BoundedVec len calculation?
-// Do we need ChainLimits anyway, if we can change them via forkless upgrades?
-parameter_types! {
-pub const MaxDataSize: u32 = 2048;
-// TODO: This limit isn't checked for substrate create_multiple_items call
-pub const MaxItemsPerBatch: u32 = 200;
-}
-
 pub type CollectionId = u32;
 pub type TokenId = u32;
 pub type DecimalPoints = u8;
@@ -211,23 +203,25 @@
 	}
 }
 
-#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
-#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
-pub struct ChainLimits {
-	pub collection_numbers_limit: u32,
-	pub account_token_ownership_limit: u32,
-	pub collections_admins_limit: u64,
-	pub custom_data_limit: u32,
+pub trait ChainLimits {
+	type CollectionNumberLimit: Get<u32>;
+	type AccountTokenOwnershipLimit: Get<u32>;
+	type CollectionAdminsLimit: Get<u64>;
+	type CustomDataLimit: Get<u32>;
 
 	// Timeouts for item types in passed blocks
-	pub nft_sponsor_transfer_timeout: u32,
-	pub fungible_sponsor_transfer_timeout: u32,
-	pub refungible_sponsor_transfer_timeout: u32,
+	type NftSponsorTransferTimeout: Get<u32>;
+	type FungibleSponsorTransferTimeout: Get<u32>;
+	type ReFungibleSponsorTransferTimeout: Get<u32>;
 
 	// Schema limits
-	pub offchain_schema_limit: u32,
-	pub variable_on_chain_schema_limit: u32,
-	pub const_on_chain_schema_limit: u32,
+	type OffchainSchemaLimit: Get<u32>;
+	type VariableOnChainSchemaLimit: Get<u32>;
+	type ConstOnChainSchemaLimit: Get<u32>;
+
+	/// How much items can be created per single
+	/// create_many call
+	type MaxItemsPerBatch: Get<u32>;
 }
 
 /// BoundedVec doesn't supports serde
@@ -263,16 +257,16 @@
 	}
 }
 
-#[derive(Encode, Decode, MaxEncodedLen, Default, Derivative, Clone, PartialEq)]
+#[derive(Encode, Decode, MaxEncodedLen, Default, Derivative)]
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
-#[derivative(Debug)]
-pub struct CreateNftData {
+#[derivative(Debug(bound = ""), PartialEq(bound = ""), Clone(bound = ""))]
+pub struct CreateNftData<T: ChainLimits> {
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
 	#[derivative(Debug = "ignore")]
-	pub const_data: BoundedVec<u8, MaxDataSize>,
+	pub const_data: BoundedVec<u8, T::CustomDataLimit>,
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
 	#[derivative(Debug = "ignore")]
-	pub variable_data: BoundedVec<u8, MaxDataSize>,
+	pub variable_data: BoundedVec<u8, T::CustomDataLimit>,
 }
 
 #[derive(Encode, Decode, MaxEncodedLen, Default, Debug, Clone, PartialEq)]
@@ -281,28 +275,29 @@
 	pub value: u128,
 }
 
-#[derive(Encode, Decode, MaxEncodedLen, Default, Derivative, Clone, PartialEq)]
+#[derive(Encode, Decode, MaxEncodedLen, Default, Derivative)]
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
-#[derivative(Debug)]
-pub struct CreateReFungibleData {
+#[derivative(Debug(bound = ""), PartialEq(bound = ""), Clone(bound = ""))]
+pub struct CreateReFungibleData<T: ChainLimits> {
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
 	#[derivative(Debug = "ignore")]
-	pub const_data: BoundedVec<u8, MaxDataSize>,
+	pub const_data: BoundedVec<u8, T::CustomDataLimit>,
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
 	#[derivative(Debug = "ignore")]
-	pub variable_data: BoundedVec<u8, MaxDataSize>,
+	pub variable_data: BoundedVec<u8, T::CustomDataLimit>,
 	pub pieces: u128,
 }
 
-#[derive(Encode, Decode, MaxEncodedLen, Debug, Clone, PartialEq)]
+#[derive(Encode, Decode, MaxEncodedLen, Derivative)]
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
-pub enum CreateItemData {
-	NFT(CreateNftData),
+#[derivative(Debug(bound = ""), PartialEq(bound = ""), Clone(bound = ""))]
+pub enum CreateItemData<T: ChainLimits> {
+	NFT(CreateNftData<T>),
 	Fungible(CreateFungibleData),
-	ReFungible(CreateReFungibleData),
+	ReFungible(CreateReFungibleData<T>),
 }
 
-impl CreateItemData {
+impl<T: ChainLimits> CreateItemData<T> {
 	pub fn data_size(&self) -> usize {
 		match self {
 			CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),
@@ -312,19 +307,19 @@
 	}
 }
 
-impl From<CreateNftData> for CreateItemData {
-	fn from(item: CreateNftData) -> Self {
+impl<T: ChainLimits> From<CreateNftData<T>> for CreateItemData<T> {
+	fn from(item: CreateNftData<T>) -> Self {
 		CreateItemData::NFT(item)
 	}
 }
 
-impl From<CreateReFungibleData> for CreateItemData {
-	fn from(item: CreateReFungibleData) -> Self {
+impl<T: ChainLimits> From<CreateReFungibleData<T>> for CreateItemData<T> {
+	fn from(item: CreateReFungibleData<T>) -> Self {
 		CreateItemData::ReFungible(item)
 	}
 }
 
-impl From<CreateFungibleData> for CreateItemData {
+impl<T: ChainLimits> From<CreateFungibleData> for CreateItemData<T> {
 	fn from(item: CreateFungibleData) -> Self {
 		CreateItemData::Fungible(item)
 	}
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -683,6 +683,35 @@
 }
 
 parameter_types! {
+	pub const CollectionNumberLimit: u32 = 100000;
+	pub const AccountTokenOwnershipLimit: u32 = 1000000;
+	pub const CollectionAdminsLimit: u64 = 5;
+	pub const CustomDataLimit: u32 = 2048;
+	pub const NftSponsorTransferTimeout: u32 = 5;
+	pub const FungibleSponsorTransferTimeout: u32 = 5;
+	pub const ReFungibleSponsorTransferTimeout: u32 = 5;
+	pub const OffchainSchemaLimit: u32 = 1024;
+	pub const VariableOnChainSchemaLimit: u32 = 1024;
+	pub const ConstOnChainSchemaLimit: u32 = 1024;
+	pub const MaxItemsPerBatch: u32 = 200;
+}
+
+pub struct ChainLimits;
+impl nft_data_structs::ChainLimits for ChainLimits {
+    type CollectionNumberLimit = CollectionNumberLimit;
+    type AccountTokenOwnershipLimit = AccountTokenOwnershipLimit;
+    type CollectionAdminsLimit = CollectionAdminsLimit;
+    type CustomDataLimit = CustomDataLimit;
+    type NftSponsorTransferTimeout = NftSponsorTransferTimeout;
+    type FungibleSponsorTransferTimeout = FungibleSponsorTransferTimeout;
+    type ReFungibleSponsorTransferTimeout = ReFungibleSponsorTransferTimeout;
+    type OffchainSchemaLimit = OffchainSchemaLimit;
+    type VariableOnChainSchemaLimit = VariableOnChainSchemaLimit;
+    type ConstOnChainSchemaLimit = ConstOnChainSchemaLimit;
+    type MaxItemsPerBatch = MaxItemsPerBatch;
+}
+
+parameter_types! {
 	pub TreasuryAccountId: AccountId = TreasuryModuleId::get().into_account();
 	pub const CollectionCreationPrice: Balance = 100 * UNIQUE;
 }
@@ -699,6 +728,7 @@
 	type Currency = Balances;
 	type CollectionCreationPrice = CollectionCreationPrice;
 	type TreasuryAccountId = TreasuryAccountId;
+	type ChainLimits = ChainLimits;
 }
 
 parameter_types! {