git.delta.rocks / unique-network / refs/commits / 73817f448a72

difftreelog

test upgrade benchmarks for new substrate

Yaroslav Bolyukin2022-02-26parent: #c9e84df.patch.diff
in: master

12 files changed

modified.maintain/frame-weight-template.hbsdiffbeforeafterboth
--- a/.maintain/frame-weight-template.hbs
+++ b/.maintain/frame-weight-template.hbs
@@ -7,7 +7,7 @@
 //! EXECUTION: {{cmd.execution}}, WASM-EXECUTION: {{cmd.wasm_execution}}, CHAIN: {{cmd.chain}}, DB CACHE: {{cmd.db_cache}}
 
 // Executed Command:
-{{#each args as |arg|~}}
+{{#each args as |arg|}}
 // {{arg}}
 {{/each}}
 
@@ -21,76 +21,80 @@
 
 /// Weight functions needed for {{pallet}}.
 pub trait WeightInfo {
-	{{~#each benchmarks as |benchmark|}}
+	{{#each benchmarks as |benchmark|}}
 	fn {{benchmark.name~}}
 	(
 		{{~#each benchmark.components as |c| ~}}
 		{{c.name}}: u32, {{/each~}}
 	) -> Weight;
-	{{~/each}}
+	{{/each}}
 }
 
 /// Weights for {{pallet}} using the Substrate node and recommended hardware.
 pub struct SubstrateWeight<T>(PhantomData<T>);
+{{#if (eq pallet "frame_system")}}
+impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
+{{else}}
 impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
-	{{~#each benchmarks as |benchmark|}}
-	{{~#each benchmark.comments as |comment|}}
+{{/if}}
+	{{#each benchmarks as |benchmark|}}
+	{{#each benchmark.comments as |comment|}}
 	// {{comment}}
-	{{~/each}}
+	{{/each}}
 	fn {{benchmark.name~}}
 	(
 		{{~#each benchmark.components as |c| ~}}
 		{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
 	) -> Weight {
 		({{underscore benchmark.base_weight}} as Weight)
-			{{~#each benchmark.component_weight as |cw|}}
+			{{#each benchmark.component_weight as |cw|}}
 			// Standard Error: {{underscore cw.error}}
 			.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
-			{{~/each}}
-			{{~#if (ne benchmark.base_reads "0")}}
+			{{/each}}
+			{{#if (ne benchmark.base_reads "0")}}
 			.saturating_add(T::DbWeight::get().reads({{benchmark.base_reads}} as Weight))
-			{{~/if}}
-			{{~#each benchmark.component_reads as |cr|}}
+			{{/if}}
+			{{#each benchmark.component_reads as |cr|}}
 			.saturating_add(T::DbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
-			{{~/each}}
-			{{~#if (ne benchmark.base_writes "0")}}
+			{{/each}}
+			{{#if (ne benchmark.base_writes "0")}}
 			.saturating_add(T::DbWeight::get().writes({{benchmark.base_writes}} as Weight))
-			{{~/if}}
-			{{~#each benchmark.component_writes as |cw|}}
+			{{/if}}
+			{{#each benchmark.component_writes as |cw|}}
 			.saturating_add(T::DbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
-			{{~/each}}
+			{{/each}}
 	}
-	{{~/each}}
+	{{/each}}
 }
 
 // For backwards compatibility and tests
 impl WeightInfo for () {
-	{{~#each benchmarks as |benchmark|}}
-	{{~#each benchmark.comments as |comment|}}
+	{{#each benchmarks as |benchmark|}}
+	{{#each benchmark.comments as |comment|}}
 	// {{comment}}
-	{{~/each}}
+	{{/each}}
 	fn {{benchmark.name~}}
 	(
 		{{~#each benchmark.components as |c| ~}}
 		{{~#if (not c.is_used)}}_{{/if}}{{c.name}}: u32, {{/each~}}
 	) -> Weight {
 		({{underscore benchmark.base_weight}} as Weight)
-			{{~#each benchmark.component_weight as |cw|}}
+			{{#each benchmark.component_weight as |cw|}}
 			// Standard Error: {{underscore cw.error}}
 			.saturating_add(({{underscore cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight))
-			{{~/each}}
-			{{~#if (ne benchmark.base_reads "0")}}
+			{{/each}}
+			{{#if (ne benchmark.base_reads "0")}}
 			.saturating_add(RocksDbWeight::get().reads({{benchmark.base_reads}} as Weight))
-			{{~/if}}
-			{{~#each benchmark.component_reads as |cr|}}
+			{{/if}}
+			{{#each benchmark.component_reads as |cr|}}
 			.saturating_add(RocksDbWeight::get().reads(({{cr.slope}} as Weight).saturating_mul({{cr.name}} as Weight)))
-			{{~/each}}
-			{{~#if (ne benchmark.base_writes "0")}}
+			{{/each}}
+			{{#if (ne benchmark.base_writes "0")}}
 			.saturating_add(RocksDbWeight::get().writes({{benchmark.base_writes}} as Weight))
-			{{~/if}}
-			{{~#each benchmark.component_writes as |cw|}}
+			{{/if}}
+			{{#each benchmark.component_writes as |cw|}}
 			.saturating_add(RocksDbWeight::get().writes(({{cw.slope}} as Weight).saturating_mul({{cw.name}} as Weight)))
-			{{~/each}}
+			{{/each}}
 	}
-	{{~/each}}
+	{{/each}}
 }
modifiedpallets/common/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -1,64 +1,87 @@
 use sp_std::vec::Vec;
 use crate::{Config, CollectionHandle};
 use up_data_structs::{
-	CollectionMode, Collection, CollectionId, MAX_COLLECTION_NAME_LENGTH,
+	CollectionMode, CreateCollectionData, CollectionId, MAX_COLLECTION_NAME_LENGTH,
 	MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH, OFFCHAIN_SCHEMA_LIMIT,
 	VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT,
 };
-use frame_support::traits::{Currency, Get};
+use frame_support::{
+	traits::{Currency, Get},
+	pallet_prelude::ConstU32,
+	BoundedVec,
+};
 use core::convert::TryInto;
 use sp_runtime::DispatchError;
 
-pub fn create_data(size: usize) -> Vec<u8> {
-	(0..size).map(|v| (v & 0xff) as u8).collect()
+pub fn create_data<const S: u32>() -> BoundedVec<u8, ConstU32<S>> {
+	create_var_data::<S>(S)
 }
-pub fn create_u16_data(size: usize) -> Vec<u16> {
-	(0..size).map(|v| (v & 0xffff) as u16).collect()
+pub fn create_u16_data<const S: u32>() -> BoundedVec<u16, ConstU32<S>> {
+	(0..S)
+		.map(|v| (v & 0xffff) as u16)
+		.collect::<Vec<_>>()
+		.try_into()
+		.unwrap()
+}
+pub fn create_var_data<const S: u32>(size: u32) -> BoundedVec<u8, ConstU32<S>> {
+	assert!(
+		size <= S,
+		"size ({}) should be less within bound ({})",
+		size,
+		S
+	);
+	(0..size)
+		.map(|v| (v & 0xff) as u8)
+		.collect::<Vec<_>>()
+		.try_into()
+		.unwrap()
 }
 
 pub fn create_collection_raw<T: Config, R>(
 	owner: T::AccountId,
 	mode: CollectionMode,
-	handler: impl FnOnce(Collection<T::AccountId>) -> Result<CollectionId, DispatchError>,
+	handler: impl FnOnce(
+		T::AccountId,
+		CreateCollectionData<T::AccountId>,
+	) -> Result<CollectionId, DispatchError>,
 	cast: impl FnOnce(CollectionHandle<T>) -> R,
 ) -> Result<R, DispatchError> {
 	T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());
-	let name = create_u16_data(MAX_COLLECTION_NAME_LENGTH)
-		.try_into()
-		.unwrap();
-	let description = create_u16_data(MAX_COLLECTION_DESCRIPTION_LENGTH)
-		.try_into()
-		.unwrap();
-	let token_prefix = create_data(MAX_TOKEN_PREFIX_LENGTH).try_into().unwrap();
-	let offchain_schema = create_data(OFFCHAIN_SCHEMA_LIMIT as usize)
-		.try_into()
-		.unwrap();
-	let variable_on_chain_schema = create_data(VARIABLE_ON_CHAIN_SCHEMA_LIMIT as usize)
-		.try_into()
-		.unwrap();
-	let const_on_chain_schema = create_data(CONST_ON_CHAIN_SCHEMA_LIMIT as usize)
-		.try_into()
-		.unwrap();
-	handler(Collection {
+	let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
+	let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
+	let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
+	let offchain_schema = create_data::<OFFCHAIN_SCHEMA_LIMIT>();
+	let variable_on_chain_schema = create_data::<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>();
+	let const_on_chain_schema = create_data::<CONST_ON_CHAIN_SCHEMA_LIMIT>();
+	handler(
 		owner,
-		mode,
-		access: Default::default(),
-		name,
-		description,
-		token_prefix,
-		mint_mode: true,
-		offchain_schema,
-		schema_version: Default::default(),
-		sponsorship: Default::default(),
-		limits: Default::default(),
-		variable_on_chain_schema,
-		const_on_chain_schema,
-		meta_update_permission: Default::default(),
-	})
+		CreateCollectionData {
+			mode,
+			name,
+			description,
+			token_prefix,
+			offchain_schema,
+			variable_on_chain_schema,
+			const_on_chain_schema,
+			..Default::default()
+		},
+	)
 	.and_then(CollectionHandle::try_get)
 	.map(cast)
 }
 
+/// Helper macros, which handles all benchmarking preparation in semi-declarative way
+///
+/// `name` is a substrate account
+/// - name: sub[(id)]
+/// `name` is a collection with owner `owner`
+/// - name: collection(owner)
+/// `name` is a cross account based on substrate
+/// - name: cross_sub[(id)]
+/// `name` is a cross account, which maps to substrate account `name`
+/// - name: cross_from_sub
+/// `name` is a cross account, which maps to substrate account `other_name`
+/// - name: cross_from_sub(other_name)
 #[macro_export]
 macro_rules! bench_init {
 	($name:ident: sub $(($id:expr))?; $($rest:tt)*) => {
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -12,7 +12,7 @@
 };
 
 pub struct CommonWeights<T: Config>(PhantomData<T>);
-impl<T: Config> CommonWeightInfo for CommonWeights<T> {
+impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
 	fn create_item() -> Weight {
 		<SelfWeightOf<T>>::create_item()
 	}
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
before · pallets/fungible/src/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]23use core::ops::Deref;4use frame_support::{ensure};5use up_data_structs::{AccessMode, CollectionId, TokenId, CreateCollectionData};6use pallet_common::{7	Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,8};9use pallet_evm_coder_substrate::WithRecorder;10use sp_core::H160;11use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};12use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};1314pub use pallet::*;1516use crate::erc::ERC20Events;17#[cfg(feature = "runtime-benchmarks")]18pub mod benchmarking;19pub mod common;20pub mod erc;21pub mod weights;2223pub type CreateItemData<T> = (<T as pallet_common::Config>::CrossAccountId, u128);24pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;2526#[frame_support::pallet]27pub mod pallet {28	use frame_support::{Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};29	use up_data_structs::CollectionId;30	use super::weights::WeightInfo;3132	#[pallet::error]33	pub enum Error<T> {34		/// Not Fungible item data used to mint in Fungible collection.35		NotFungibleDataUsedToMintFungibleCollectionToken,36		/// Not default id passed as TokenId argument37		FungibleItemsHaveNoId,38		/// Tried to set data for fungible item39		FungibleItemsDontHaveData,40	}4142	#[pallet::config]43	pub trait Config: frame_system::Config + pallet_common::Config {44		type WeightInfo: WeightInfo;45	}4647	#[pallet::pallet]48	#[pallet::generate_store(pub(super) trait Store)]49	pub struct Pallet<T>(_);5051	#[pallet::storage]52	pub type TotalSupply<T: Config> =53		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;5455	#[pallet::storage]56	pub type Balance<T: Config> = StorageNMap<57		Key = (58			Key<Twox64Concat, CollectionId>,59			Key<Blake2_128Concat, T::CrossAccountId>,60		),61		Value = u128,62		QueryKind = ValueQuery,63	>;6465	#[pallet::storage]66	pub type Allowance<T: Config> = StorageNMap<67		Key = (68			Key<Twox64Concat, CollectionId>,69			Key<Blake2_128, T::CrossAccountId>,70			Key<Blake2_128Concat, T::CrossAccountId>,71		),72		Value = u128,73		QueryKind = ValueQuery,74	>;75}7677pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);78impl<T: Config> FungibleHandle<T> {79	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {80		Self(inner)81	}82	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {83		self.084	}85}86impl<T: Config> WithRecorder<T> for FungibleHandle<T> {87	fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {88		self.0.recorder()89	}90	fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {91		self.0.into_recorder()92	}93}94impl<T: Config> Deref for FungibleHandle<T> {95	type Target = pallet_common::CollectionHandle<T>;9697	fn deref(&self) -> &Self::Target {98		&self.099	}100}101102impl<T: Config> Pallet<T> {103	pub fn init_collection(104		owner: T::AccountId,105		data: CreateCollectionData<T::AccountId>,106	) -> Result<CollectionId, DispatchError> {107		<PalletCommon<T>>::init_collection(owner, data)108	}109	pub fn destroy_collection(110		collection: FungibleHandle<T>,111		sender: &T::CrossAccountId,112	) -> DispatchResult {113		let id = collection.id;114115		// =========116117		PalletCommon::destroy_collection(collection.0, sender)?;118119		<TotalSupply<T>>::remove(id);120		<Balance<T>>::remove_prefix((id,), None);121		<Allowance<T>>::remove_prefix((id,), None);122		Ok(())123	}124125	pub fn burn(126		collection: &FungibleHandle<T>,127		owner: &T::CrossAccountId,128		amount: u128,129	) -> DispatchResult {130		let total_supply = <TotalSupply<T>>::get(collection.id)131			.checked_sub(amount)132			.ok_or(<CommonError<T>>::TokenValueTooLow)?;133134		let balance = <Balance<T>>::get((collection.id, owner))135			.checked_sub(amount)136			.ok_or(<CommonError<T>>::TokenValueTooLow)?;137138		if collection.access == AccessMode::AllowList {139			collection.check_allowlist(owner)?;140		}141142		// =========143144		if balance == 0 {145			<Balance<T>>::remove((collection.id, owner));146		} else {147			<Balance<T>>::insert((collection.id, owner), balance);148		}149		<TotalSupply<T>>::insert(collection.id, total_supply);150151		collection.log_mirrored(ERC20Events::Transfer {152			from: *owner.as_eth(),153			to: H160::default(),154			value: amount.into(),155		});156		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(157			collection.id,158			TokenId::default(),159			owner.clone(),160			amount,161		));162		Ok(())163	}164165	pub fn transfer(166		collection: &FungibleHandle<T>,167		from: &T::CrossAccountId,168		to: &T::CrossAccountId,169		amount: u128,170	) -> DispatchResult {171		ensure!(172			collection.limits.transfers_enabled(),173			<CommonError<T>>::TransferNotAllowed,174		);175176		if collection.access == AccessMode::AllowList {177			collection.check_allowlist(from)?;178			collection.check_allowlist(to)?;179		}180		<PalletCommon<T>>::ensure_correct_receiver(to)?;181182		let balance_from = <Balance<T>>::get((collection.id, from))183			.checked_sub(amount)184			.ok_or(<CommonError<T>>::TokenValueTooLow)?;185		let balance_to = if from != to {186			Some(187				<Balance<T>>::get((collection.id, to))188					.checked_add(amount)189					.ok_or(ArithmeticError::Overflow)?,190			)191		} else {192			None193		};194195		// =========196197		if let Some(balance_to) = balance_to {198			// from != to199			if balance_from == 0 {200				<Balance<T>>::remove((collection.id, from));201			} else {202				<Balance<T>>::insert((collection.id, from), balance_from);203			}204			<Balance<T>>::insert((collection.id, to), balance_to);205		}206207		collection.log_mirrored(ERC20Events::Transfer {208			from: *from.as_eth(),209			to: *to.as_eth(),210			value: amount.into(),211		});212		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(213			collection.id,214			TokenId::default(),215			from.clone(),216			to.clone(),217			amount,218		));219		Ok(())220	}221222	pub fn create_multiple_items(223		collection: &FungibleHandle<T>,224		sender: &T::CrossAccountId,225		data: Vec<CreateItemData<T>>,226	) -> DispatchResult {227		if !collection.is_owner_or_admin(sender) {228			ensure!(229				collection.mint_mode,230				<CommonError<T>>::PublicMintingNotAllowed231			);232			collection.check_allowlist(sender)?;233234			for (owner, _) in data.iter() {235				collection.check_allowlist(owner)?;236			}237		}238239		let mut balances = BTreeMap::new();240241		let total_supply = data242			.iter()243			.map(|u| u.1)244			.try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {245				acc.checked_add(v)246			})247			.ok_or(ArithmeticError::Overflow)?;248249		for (user, amount) in data.into_iter() {250			let balance = balances251				.entry(user.clone())252				.or_insert_with(|| <Balance<T>>::get((collection.id, user)));253			*balance = (*balance)254				.checked_add(amount)255				.ok_or(ArithmeticError::Overflow)?;256		}257258		// =========259260		<TotalSupply<T>>::insert(collection.id, total_supply);261		for (user, amount) in balances {262			<Balance<T>>::insert((collection.id, &user), amount);263264			collection.log_mirrored(ERC20Events::Transfer {265				from: H160::default(),266				to: *user.as_eth(),267				value: amount.into(),268			});269			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(270				collection.id,271				TokenId::default(),272				user.clone(),273				amount,274			));275		}276277		Ok(())278	}279280	fn set_allowance_unchecked(281		collection: &FungibleHandle<T>,282		owner: &T::CrossAccountId,283		spender: &T::CrossAccountId,284		amount: u128,285	) {286		if amount == 0 {287			<Allowance<T>>::remove((collection.id, owner, spender));288		} else {289			<Allowance<T>>::insert((collection.id, owner, spender), amount);290		}291292		collection.log_mirrored(ERC20Events::Approval {293			owner: *owner.as_eth(),294			spender: *spender.as_eth(),295			value: amount.into(),296		});297		<PalletCommon<T>>::deposit_event(CommonEvent::Approved(298			collection.id,299			TokenId(0),300			owner.clone(),301			spender.clone(),302			amount,303		));304	}305306	pub fn set_allowance(307		collection: &FungibleHandle<T>,308		owner: &T::CrossAccountId,309		spender: &T::CrossAccountId,310		amount: u128,311	) -> DispatchResult {312		if collection.access == AccessMode::AllowList {313			collection.check_allowlist(owner)?;314			collection.check_allowlist(spender)?;315		}316317		if <Balance<T>>::get((collection.id, owner)) < amount {318			ensure!(319				collection.ignores_owned_amount(owner),320				<CommonError<T>>::CantApproveMoreThanOwned321			);322		}323324		// =========325326		Self::set_allowance_unchecked(collection, owner, spender, amount);327		Ok(())328	}329330	pub fn transfer_from(331		collection: &FungibleHandle<T>,332		spender: &T::CrossAccountId,333		from: &T::CrossAccountId,334		to: &T::CrossAccountId,335		amount: u128,336	) -> DispatchResult {337		if spender.conv_eq(from) {338			return Self::transfer(collection, from, to, amount);339		}340		if collection.access == AccessMode::AllowList {341			// `from`, `to` checked in [`transfer`]342			collection.check_allowlist(spender)?;343		}344345		let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);346		if allowance.is_none() {347			ensure!(348				collection.ignores_allowance(spender),349				<CommonError<T>>::ApprovedValueTooLow350			);351		}352353		// =========354355		Self::transfer(collection, from, to, amount)?;356		if let Some(allowance) = allowance {357			Self::set_allowance_unchecked(collection, from, spender, allowance);358		}359		Ok(())360	}361362	pub fn burn_from(363		collection: &FungibleHandle<T>,364		spender: &T::CrossAccountId,365		from: &T::CrossAccountId,366		amount: u128,367	) -> DispatchResult {368		if spender.conv_eq(from) {369			return Self::burn(collection, from, amount);370		}371		if collection.access == AccessMode::AllowList {372			// `from` checked in [`burn`]373			collection.check_allowlist(spender)?;374		}375376		let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);377		if allowance.is_none() {378			ensure!(379				collection.ignores_allowance(spender),380				<CommonError<T>>::ApprovedValueTooLow381			);382		}383384		// =========385386		Self::burn(collection, from, amount)?;387		if let Some(allowance) = allowance {388			Self::set_allowance_unchecked(collection, from, spender, allowance);389		}390		Ok(())391	}392393	/// Delegated to `create_multiple_items`394	pub fn create_item(395		collection: &FungibleHandle<T>,396		sender: &T::CrossAccountId,397		data: CreateItemData<T>,398	) -> DispatchResult {399		Self::create_multiple_items(collection, sender, vec![data])400	}401}
after · pallets/fungible/src/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]23use core::ops::Deref;4use frame_support::{ensure};5use up_data_structs::{AccessMode, CollectionId, TokenId, CreateCollectionData};6use pallet_common::{7	Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,8};9use pallet_evm_coder_substrate::WithRecorder;10use sp_core::H160;11use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};12use sp_std::collections::btree_map::BTreeMap;1314pub use pallet::*;1516use crate::erc::ERC20Events;17#[cfg(feature = "runtime-benchmarks")]18pub mod benchmarking;19pub mod common;20pub mod erc;21pub mod weights;2223pub type CreateItemData<T> = (<T as pallet_common::Config>::CrossAccountId, u128);24pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;2526#[frame_support::pallet]27pub mod pallet {28	use frame_support::{Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};29	use up_data_structs::CollectionId;30	use super::weights::WeightInfo;3132	#[pallet::error]33	pub enum Error<T> {34		/// Not Fungible item data used to mint in Fungible collection.35		NotFungibleDataUsedToMintFungibleCollectionToken,36		/// Not default id passed as TokenId argument37		FungibleItemsHaveNoId,38		/// Tried to set data for fungible item39		FungibleItemsDontHaveData,40	}4142	#[pallet::config]43	pub trait Config: frame_system::Config + pallet_common::Config {44		type WeightInfo: WeightInfo;45	}4647	#[pallet::pallet]48	#[pallet::generate_store(pub(super) trait Store)]49	pub struct Pallet<T>(_);5051	#[pallet::storage]52	pub type TotalSupply<T: Config> =53		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;5455	#[pallet::storage]56	pub type Balance<T: Config> = StorageNMap<57		Key = (58			Key<Twox64Concat, CollectionId>,59			Key<Blake2_128Concat, T::CrossAccountId>,60		),61		Value = u128,62		QueryKind = ValueQuery,63	>;6465	#[pallet::storage]66	pub type Allowance<T: Config> = StorageNMap<67		Key = (68			Key<Twox64Concat, CollectionId>,69			Key<Blake2_128, T::CrossAccountId>,70			Key<Blake2_128Concat, T::CrossAccountId>,71		),72		Value = u128,73		QueryKind = ValueQuery,74	>;75}7677pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);78impl<T: Config> FungibleHandle<T> {79	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {80		Self(inner)81	}82	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {83		self.084	}85}86impl<T: Config> WithRecorder<T> for FungibleHandle<T> {87	fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {88		self.0.recorder()89	}90	fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {91		self.0.into_recorder()92	}93}94impl<T: Config> Deref for FungibleHandle<T> {95	type Target = pallet_common::CollectionHandle<T>;9697	fn deref(&self) -> &Self::Target {98		&self.099	}100}101102impl<T: Config> Pallet<T> {103	pub fn init_collection(104		owner: T::AccountId,105		data: CreateCollectionData<T::AccountId>,106	) -> Result<CollectionId, DispatchError> {107		<PalletCommon<T>>::init_collection(owner, data)108	}109	pub fn destroy_collection(110		collection: FungibleHandle<T>,111		sender: &T::CrossAccountId,112	) -> DispatchResult {113		let id = collection.id;114115		// =========116117		PalletCommon::destroy_collection(collection.0, sender)?;118119		<TotalSupply<T>>::remove(id);120		<Balance<T>>::remove_prefix((id,), None);121		<Allowance<T>>::remove_prefix((id,), None);122		Ok(())123	}124125	pub fn burn(126		collection: &FungibleHandle<T>,127		owner: &T::CrossAccountId,128		amount: u128,129	) -> DispatchResult {130		let total_supply = <TotalSupply<T>>::get(collection.id)131			.checked_sub(amount)132			.ok_or(<CommonError<T>>::TokenValueTooLow)?;133134		let balance = <Balance<T>>::get((collection.id, owner))135			.checked_sub(amount)136			.ok_or(<CommonError<T>>::TokenValueTooLow)?;137138		if collection.access == AccessMode::AllowList {139			collection.check_allowlist(owner)?;140		}141142		// =========143144		if balance == 0 {145			<Balance<T>>::remove((collection.id, owner));146		} else {147			<Balance<T>>::insert((collection.id, owner), balance);148		}149		<TotalSupply<T>>::insert(collection.id, total_supply);150151		collection.log_mirrored(ERC20Events::Transfer {152			from: *owner.as_eth(),153			to: H160::default(),154			value: amount.into(),155		});156		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(157			collection.id,158			TokenId::default(),159			owner.clone(),160			amount,161		));162		Ok(())163	}164165	pub fn transfer(166		collection: &FungibleHandle<T>,167		from: &T::CrossAccountId,168		to: &T::CrossAccountId,169		amount: u128,170	) -> DispatchResult {171		ensure!(172			collection.limits.transfers_enabled(),173			<CommonError<T>>::TransferNotAllowed,174		);175176		if collection.access == AccessMode::AllowList {177			collection.check_allowlist(from)?;178			collection.check_allowlist(to)?;179		}180		<PalletCommon<T>>::ensure_correct_receiver(to)?;181182		let balance_from = <Balance<T>>::get((collection.id, from))183			.checked_sub(amount)184			.ok_or(<CommonError<T>>::TokenValueTooLow)?;185		let balance_to = if from != to {186			Some(187				<Balance<T>>::get((collection.id, to))188					.checked_add(amount)189					.ok_or(ArithmeticError::Overflow)?,190			)191		} else {192			None193		};194195		// =========196197		if let Some(balance_to) = balance_to {198			// from != to199			if balance_from == 0 {200				<Balance<T>>::remove((collection.id, from));201			} else {202				<Balance<T>>::insert((collection.id, from), balance_from);203			}204			<Balance<T>>::insert((collection.id, to), balance_to);205		}206207		collection.log_mirrored(ERC20Events::Transfer {208			from: *from.as_eth(),209			to: *to.as_eth(),210			value: amount.into(),211		});212		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(213			collection.id,214			TokenId::default(),215			from.clone(),216			to.clone(),217			amount,218		));219		Ok(())220	}221222	pub fn create_multiple_items(223		collection: &FungibleHandle<T>,224		sender: &T::CrossAccountId,225		data: BTreeMap<T::CrossAccountId, u128>,226	) -> DispatchResult {227		if !collection.is_owner_or_admin(sender) {228			ensure!(229				collection.mint_mode,230				<CommonError<T>>::PublicMintingNotAllowed231			);232			collection.check_allowlist(sender)?;233234			for (owner, _) in data.iter() {235				collection.check_allowlist(owner)?;236			}237		}238239		let total_supply = data240			.iter()241			.map(|(_, v)| *v)242			.try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {243				acc.checked_add(v)244			})245			.ok_or(ArithmeticError::Overflow)?;246247		let mut balances = data;248		for (k, v) in balances.iter_mut() {249			*v = <Balance<T>>::get((collection.id, &k))250				.checked_add(*v)251				.ok_or(ArithmeticError::Overflow)?;252		}253254		// =========255256		<TotalSupply<T>>::insert(collection.id, total_supply);257		for (user, amount) in balances {258			<Balance<T>>::insert((collection.id, &user), amount);259260			collection.log_mirrored(ERC20Events::Transfer {261				from: H160::default(),262				to: *user.as_eth(),263				value: amount.into(),264			});265			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(266				collection.id,267				TokenId::default(),268				user.clone(),269				amount,270			));271		}272273		Ok(())274	}275276	fn set_allowance_unchecked(277		collection: &FungibleHandle<T>,278		owner: &T::CrossAccountId,279		spender: &T::CrossAccountId,280		amount: u128,281	) {282		if amount == 0 {283			<Allowance<T>>::remove((collection.id, owner, spender));284		} else {285			<Allowance<T>>::insert((collection.id, owner, spender), amount);286		}287288		collection.log_mirrored(ERC20Events::Approval {289			owner: *owner.as_eth(),290			spender: *spender.as_eth(),291			value: amount.into(),292		});293		<PalletCommon<T>>::deposit_event(CommonEvent::Approved(294			collection.id,295			TokenId(0),296			owner.clone(),297			spender.clone(),298			amount,299		));300	}301302	pub fn set_allowance(303		collection: &FungibleHandle<T>,304		owner: &T::CrossAccountId,305		spender: &T::CrossAccountId,306		amount: u128,307	) -> DispatchResult {308		if collection.access == AccessMode::AllowList {309			collection.check_allowlist(owner)?;310			collection.check_allowlist(spender)?;311		}312313		if <Balance<T>>::get((collection.id, owner)) < amount {314			ensure!(315				collection.ignores_owned_amount(owner),316				<CommonError<T>>::CantApproveMoreThanOwned317			);318		}319320		// =========321322		Self::set_allowance_unchecked(collection, owner, spender, amount);323		Ok(())324	}325326	pub fn transfer_from(327		collection: &FungibleHandle<T>,328		spender: &T::CrossAccountId,329		from: &T::CrossAccountId,330		to: &T::CrossAccountId,331		amount: u128,332	) -> DispatchResult {333		if spender.conv_eq(from) {334			return Self::transfer(collection, from, to, amount);335		}336		if collection.access == AccessMode::AllowList {337			// `from`, `to` checked in [`transfer`]338			collection.check_allowlist(spender)?;339		}340341		let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);342		if allowance.is_none() {343			ensure!(344				collection.ignores_allowance(spender),345				<CommonError<T>>::ApprovedValueTooLow346			);347		}348349		// =========350351		Self::transfer(collection, from, to, amount)?;352		if let Some(allowance) = allowance {353			Self::set_allowance_unchecked(collection, from, spender, allowance);354		}355		Ok(())356	}357358	pub fn burn_from(359		collection: &FungibleHandle<T>,360		spender: &T::CrossAccountId,361		from: &T::CrossAccountId,362		amount: u128,363	) -> DispatchResult {364		if spender.conv_eq(from) {365			return Self::burn(collection, from, amount);366		}367		if collection.access == AccessMode::AllowList {368			// `from` checked in [`burn`]369			collection.check_allowlist(spender)?;370		}371372		let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);373		if allowance.is_none() {374			ensure!(375				collection.ignores_allowance(spender),376				<CommonError<T>>::ApprovedValueTooLow377			);378		}379380		// =========381382		Self::burn(collection, from, amount)?;383		if let Some(allowance) = allowance {384			Self::set_allowance_unchecked(collection, from, spender, allowance);385		}386		Ok(())387	}388389	/// Delegated to `create_multiple_items`390	pub fn create_item(391		collection: &FungibleHandle<T>,392		sender: &T::CrossAccountId,393		data: CreateItemData<T>,394	) -> DispatchResult {395		Self::create_multiple_items(collection, sender, vec![data])396	}397}
modifiedpallets/inflation/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/inflation/src/benchmarking.rs
+++ b/pallets/inflation/src/benchmarking.rs
@@ -1,7 +1,7 @@
 #![cfg(feature = "runtime-benchmarks")]
 
 use super::*;
-use crate::Module as Inflation;
+use crate::Pallet as Inflation;
 
 use frame_benchmarking::{benchmarks};
 use frame_support::traits::OnInitialize;
modifiedpallets/nonfungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/benchmarking.rs
+++ b/pallets/nonfungible/src/benchmarking.rs
@@ -2,18 +2,18 @@
 use crate::{Pallet, Config, NonfungibleHandle};
 
 use sp_std::prelude::*;
-use pallet_common::benchmarking::{create_collection_raw, create_data};
+use pallet_common::benchmarking::{create_collection_raw, create_data, create_var_data};
 use frame_benchmarking::{benchmarks, account};
-use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH};
+use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, CUSTOM_DATA_LIMIT};
 use pallet_common::bench_init;
 use core::convert::TryInto;
 
 const SEED: u32 = 1;
 
 fn create_max_item_data<T: Config>(owner: T::CrossAccountId) -> CreateItemData<T> {
-	let const_data = create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap();
-	let variable_data = create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap();
-	CreateItemData {
+	let const_data = create_data::<CUSTOM_DATA_LIMIT>();
+	let variable_data = create_data::<CUSTOM_DATA_LIMIT>();
+	CreateItemData::<T> {
 		const_data,
 		variable_data,
 		owner,
@@ -24,7 +24,7 @@
 	sender: &T::CrossAccountId,
 	owner: T::CrossAccountId,
 ) -> Result<TokenId, DispatchError> {
-	<Pallet<T>>::create_item(&collection, sender, create_max_item_data(owner))?;
+	<Pallet<T>>::create_item(&collection, sender, create_max_item_data::<T>(owner))?;
 	Ok(TokenId(<TokensMinted<T>>::get(&collection.id)))
 }
 
@@ -53,7 +53,9 @@
 			owner: sub; collection: collection(owner);
 			sender: cross_from_sub(owner); to: cross_sub;
 		};
-		let data = (0..b).map(|_| create_max_item_data(to.clone())).collect();
+		let data = (0..b).map(|_| create_max_item_data::<T>(to.clone())).collect();
+	}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
+
 	}: {<Pallet<T>>::create_multiple_items(&collection, &sender, data)?}
 
 	burn_item {
@@ -105,6 +107,6 @@
 			owner: cross_from_sub; sender: cross_sub;
 		};
 		let item = create_max_item(&collection, &owner, sender.clone())?;
-		let data = create_data(b as usize);
+		let data = create_var_data(b).try_into().unwrap();
 	}: {<Pallet<T>>::set_variable_metadata(&collection, &sender, item, data)?}
 }
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -12,7 +12,7 @@
 };
 
 pub struct CommonWeights<T: Config>(PhantomData<T>);
-impl<T: Config> CommonWeightInfo for CommonWeights<T> {
+impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
 	fn create_item() -> Weight {
 		<SelfWeightOf<T>>::create_item()
 	}
@@ -51,7 +51,7 @@
 	to: &T::CrossAccountId,
 ) -> Result<CreateItemData<T>, DispatchError> {
 	match data {
-		up_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData {
+		up_data_structs::CreateItemData::NFT(data) => Ok(CreateItemData::<T> {
 			const_data: data.const_data,
 			variable_data: data.variable_data,
 			owner: to.clone(),
@@ -68,7 +68,7 @@
 		data: up_data_structs::CreateItemData,
 	) -> DispatchResultWithPostInfo {
 		with_weight(
-			<Pallet<T>>::create_item(self, &sender, map_create_data(data, &to)?),
+			<Pallet<T>>::create_item(self, &sender, map_create_data::<T>(data, &to)?),
 			<CommonWeights<T>>::create_item(),
 		)
 	}
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -232,7 +232,7 @@
 		<Pallet<T>>::create_item(
 			self,
 			&caller,
-			CreateItemData {
+			CreateItemData::<T> {
 				const_data: BoundedVec::default(),
 				variable_data: BoundedVec::default(),
 				owner: to,
@@ -268,7 +268,7 @@
 		<Pallet<T>>::create_item(
 			self,
 			&caller,
-			CreateItemData {
+			CreateItemData::<T> {
 				const_data: Vec::<u8>::from(token_uri)
 					.try_into()
 					.map_err(|_| "token uri is too long")?,
@@ -376,7 +376,7 @@
 			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;
 		}
 		let data = (0..total_tokens)
-			.map(|_| CreateItemData {
+			.map(|_| CreateItemData::<T> {
 				const_data: BoundedVec::default(),
 				variable_data: BoundedVec::default(),
 				owner: to.clone(),
@@ -409,7 +409,7 @@
 			}
 			expected_index = expected_index.checked_add(1).ok_or("item id overflow")?;
 
-			data.push(CreateItemData {
+			data.push(CreateItemData::<T> {
 				const_data: Vec::<u8>::from(token_uri)
 					.try_into()
 					.map_err(|_| "token uri is too long")?,
modifiedpallets/refungible/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/refungible/src/benchmarking.rs
+++ b/pallets/refungible/src/benchmarking.rs
@@ -2,24 +2,28 @@
 use crate::{Pallet, Config, RefungibleHandle};
 
 use sp_std::prelude::*;
-use pallet_common::benchmarking::{create_collection_raw, create_data};
+use pallet_common::benchmarking::{create_collection_raw, create_data, create_var_data};
 use frame_benchmarking::{benchmarks, account};
-use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH};
+use up_data_structs::{CollectionMode, MAX_ITEMS_PER_BATCH, CUSTOM_DATA_LIMIT};
 use pallet_common::bench_init;
 use core::convert::TryInto;
 use core::iter::IntoIterator;
 
 const SEED: u32 = 1;
 
-fn create_max_item_data<T: Config>(
-	users: impl IntoIterator<Item = (T::CrossAccountId, u128)>,
-) -> CreateItemData<T> {
-	let const_data = create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap();
-	let variable_data = create_data(CUSTOM_DATA_LIMIT as usize).try_into().unwrap();
-	CreateItemData {
+fn create_max_item_data<CrossAccountId: Ord>(
+	users: impl IntoIterator<Item = (CrossAccountId, u128)>,
+) -> CreateRefungibleExData<CrossAccountId> {
+	let const_data = create_data::<CUSTOM_DATA_LIMIT>();
+	let variable_data = create_data::<CUSTOM_DATA_LIMIT>();
+	CreateRefungibleExData {
 		const_data,
 		variable_data,
-		users: users.into_iter().collect(),
+		users: users
+			.into_iter()
+			.collect::<BTreeMap<_, _>>()
+			.try_into()
+			.unwrap(),
 	}
 }
 fn create_max_item<T: Config>(
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -8,8 +8,8 @@
 use sp_std::vec::Vec;
 
 use crate::{
-	AccountBalance, Allowance, Balance, Config, CreateItemData, Error, Owned, Pallet,
-	RefungibleHandle, SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,
+	AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,
+	SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,
 };
 
 macro_rules! max_weight_of {
@@ -22,7 +22,7 @@
 }
 
 pub struct CommonWeights<T: Config>(PhantomData<T>);
-impl<T: Config> CommonWeightInfo for CommonWeights<T> {
+impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
 	fn create_item() -> Weight {
 		<SelfWeightOf<T>>::create_item()
 	}
modifiedpallets/unique/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/unique/src/benchmarking.rs
+++ b/pallets/unique/src/benchmarking.rs
@@ -5,9 +5,8 @@
 use frame_system::RawOrigin;
 use frame_benchmarking::{benchmarks, account};
 use up_data_structs::*;
-use core::convert::TryInto;
 use sp_runtime::DispatchError;
-use pallet_common::benchmarking::{create_data, create_u16_data};
+use pallet_common::benchmarking::{create_data, create_var_data, create_u16_data};
 
 const SEED: u32 = 1;
 
@@ -16,13 +15,9 @@
 	mode: CollectionMode,
 ) -> Result<CollectionId, DispatchError> {
 	T::Currency::deposit_creating(&owner, T::CollectionCreationPrice::get());
-	let col_name = create_u16_data(MAX_COLLECTION_NAME_LENGTH)
-		.try_into()
-		.unwrap();
-	let col_desc = create_u16_data(MAX_COLLECTION_DESCRIPTION_LENGTH)
-		.try_into()
-		.unwrap();
-	let token_prefix = create_data(MAX_TOKEN_PREFIX_LENGTH).try_into().unwrap();
+	let col_name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
+	let col_desc = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
+	let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
 	<Pallet<T>>::create_collection(
 		RawOrigin::Signed(owner).into(),
 		col_name,
@@ -37,11 +32,10 @@
 }
 
 benchmarks! {
-
 	create_collection {
-		let col_name: Vec<u16> = create_u16_data(MAX_COLLECTION_NAME_LENGTH);
-		let col_desc: Vec<u16> = create_u16_data(MAX_COLLECTION_DESCRIPTION_LENGTH);
-		let token_prefix: Vec<u8> = create_data(MAX_TOKEN_PREFIX_LENGTH);
+		let col_name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
+		let col_desc = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
+		let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
 		let mode: CollectionMode = CollectionMode::NFT;
 		let caller: T::AccountId = account("caller", 0, SEED);
 		T::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());
@@ -125,7 +119,7 @@
 
 		let caller: T::AccountId = account("caller", 0, SEED);
 		let collection = create_nft_collection::<T>(caller.clone())?;
-		let data = create_data(b as usize);
+		let data = create_var_data(b);
 	}: set_offchain_schema(RawOrigin::Signed(caller.clone()), collection, data)
 
 	set_const_on_chain_schema {
@@ -133,7 +127,7 @@
 
 		let caller: T::AccountId = account("caller", 0, SEED);
 		let collection = create_nft_collection::<T>(caller.clone())?;
-		let data = create_data(b as usize);
+		let data = create_var_data(b);
 	}: set_const_on_chain_schema(RawOrigin::Signed(caller.clone()), collection, data)
 
 	set_variable_on_chain_schema {
@@ -141,7 +135,7 @@
 
 		let caller: T::AccountId = account("caller", 0, SEED);
 		let collection = create_nft_collection::<T>(caller.clone())?;
-		let data = create_data(b as usize);
+		let data = create_var_data(b);
 	}: set_variable_on_chain_schema(RawOrigin::Signed(caller.clone()), collection, data)
 
 	set_schema_version {
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -76,9 +76,7 @@
 /// create_many call
 pub const MAX_ITEMS_PER_BATCH: u32 = 200;
 
-parameter_types! {
-	pub const CustomDataLimit: u32 = CUSTOM_DATA_LIMIT;
-}
+pub type CustomDataLimit = ConstU32<CUSTOM_DATA_LIMIT>;
 
 #[derive(
 	Encode,
@@ -417,15 +415,72 @@
 	}
 }
 
+fn bounded_debug<V, S>(v: &BoundedVec<V, S>, f: &mut fmt::Formatter) -> Result<(), fmt::Error>
+where
+	V: fmt::Debug,
+{
+	use core::fmt::Debug;
+	(&v as &Vec<V>).fmt(f)
+}
+
+#[cfg(feature = "serde1")]
+#[allow(dead_code)]
+mod bounded_map_serde {
+	use core::convert::TryFrom;
+	use sp_std::collections::btree_map::BTreeMap;
+	use frame_support::{traits::Get, storage::bounded_btree_map::BoundedBTreeMap};
+	use serde::{
+		ser::{self, Serialize},
+		de::{self, Deserialize, Error},
+	};
+	pub fn serialize<D, K, V, S>(
+		value: &BoundedBTreeMap<K, V, S>,
+		serializer: D,
+	) -> Result<D::Ok, D::Error>
+	where
+		D: ser::Serializer,
+		K: Serialize + Ord,
+		V: Serialize,
+	{
+		(value as &BTreeMap<_, _>).serialize(serializer)
+	}
+
+	pub fn deserialize<'de, D, K, V, S>(
+		deserializer: D,
+	) -> Result<BoundedBTreeMap<K, V, S>, D::Error>
+	where
+		D: de::Deserializer<'de>,
+		K: de::Deserialize<'de> + Ord,
+		V: de::Deserialize<'de>,
+		S: Get<u32>,
+	{
+		let map = <BTreeMap<K, V>>::deserialize(deserializer)?;
+		let len = map.len();
+		TryFrom::try_from(map).map_err(|_| D::Error::invalid_length(len, &"lesser size"))
+	}
+}
+
+fn bounded_map_debug<K, V, S>(
+	v: &BoundedBTreeMap<K, V, S>,
+	f: &mut fmt::Formatter,
+) -> Result<(), fmt::Error>
+where
+	K: fmt::Debug + Ord,
+	V: fmt::Debug,
+{
+	use core::fmt::Debug;
+	(&v as &BTreeMap<K, V>).fmt(f)
+}
+
 #[derive(Encode, Decode, MaxEncodedLen, Default, PartialEq, Clone, Derivative, TypeInfo)]
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
 #[derivative(Debug)]
 pub struct CreateNftData {
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
-	#[derivative(Debug = "ignore")]
+	#[derivative(Debug(format_with = "bounded_debug"))]
 	pub const_data: BoundedVec<u8, CustomDataLimit>,
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
-	#[derivative(Debug = "ignore")]
+	#[derivative(Debug(format_with = "bounded_debug"))]
 	pub variable_data: BoundedVec<u8, CustomDataLimit>,
 }
 
@@ -440,10 +495,10 @@
 #[derivative(Debug)]
 pub struct CreateReFungibleData {
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
-	#[derivative(Debug = "ignore")]
+	#[derivative(Debug(format_with = "bounded_debug"))]
 	pub const_data: BoundedVec<u8, CustomDataLimit>,
 	#[cfg_attr(feature = "serde1", serde(with = "bounded_serde"))]
-	#[derivative(Debug = "ignore")]
+	#[derivative(Debug(format_with = "bounded_debug"))]
 	pub variable_data: BoundedVec<u8, CustomDataLimit>,
 	pub pieces: u128,
 }