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

difftreelog

Add first draft of Properties

Daniel Shiposha2022-04-29parent: #c01b00c.patch.diff
in: master

14 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -18,7 +18,7 @@
 
 use core::ops::{Deref, DerefMut};
 use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-use sp_std::vec::Vec;
+use sp_std::{vec::Vec, collections::btree_map::BTreeMap};
 use pallet_evm::account::CrossAccountId;
 use frame_support::{
 	dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Weight, PostDispatchInfo},
@@ -35,7 +35,8 @@
 	FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, MAX_SPONSOR_TIMEOUT,
 	CUSTOM_DATA_LIMIT, CollectionLimits, CustomDataLimit, CreateCollectionData, SponsorshipState,
 	CreateItemExData, SponsoringRateLimit, budget::Budget, COLLECTION_FIELD_LIMIT, CollectionField,
-	PhantomType,
+	PhantomType, Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyPermission,
+	PropertiesError,
 };
 pub use pallet::*;
 use sp_core::H160;
@@ -288,6 +289,10 @@
 			T::CrossAccountId,
 			u128,
 		),
+
+		CollectionPropertySet(CollectionId, Property),
+
+		TokenPropertySet(CollectionId, TokenId, Property),
 	}
 
 	#[pallet::error]
@@ -319,7 +324,6 @@
 		CollectionLimitBoundsExceeded,
 		/// Tried to enable permissions which are only permitted to be disabled
 		OwnerPermissionsCantBeReverted,
-
 		/// Collection settings not allowing items transferring
 		TransferNotAllowed,
 		/// Account token limit exceeded per collection
@@ -372,6 +376,25 @@
 		QueryKind = OptionQuery,
 	>;
 
+	/// Collection properties
+	#[pallet::storage]
+	pub type CollectionProperties<T> = StorageMap<
+		Hasher = Blake2_128Concat,
+		Key = CollectionId,
+		Value = Properties,
+		QueryKind = ValueQuery,
+		OnEmpty = up_data_structs::CollectionProperties,
+	>;
+
+	#[pallet::storage]
+	#[pallet::getter(fn property_permission)]
+	pub type CollectionPropertyPermissions<T> = StorageMap<
+		Hasher = Blake2_128Concat,
+		Key = CollectionId,
+		Value = PropertiesPermissionMap,
+		QueryKind = ValueQuery,
+	>;
+
 	/// Large variable-size collection fields are extracted here
 	#[pallet::storage]
 	pub type CollectionData<T> = StorageNMap<
@@ -538,6 +561,7 @@
 			sponsorship,
 			limits,
 			meta_update_permission,
+			..
 		} = <CollectionById<T>>::get(collection)?;
 		Some(RpcCollection {
 			name: name.into_inner(),
@@ -615,8 +639,25 @@
 				.map(|limits| Self::clamp_limits(data.mode.clone(), &Default::default(), limits))
 				.unwrap_or_else(|| Ok(CollectionLimits::default()))?,
 			meta_update_permission: data.meta_update_permission.unwrap_or_default(),
+			// token_property_permissions: data.token_property_permissions.unwrap_or_default(),
+			// properties: Properties::from_collection_props_vec(data.properties)?
 		};
 
+		CollectionProperties::<T>::insert(
+			id,
+			Properties::from_collection_props_vec(data.properties)?,
+		);
+
+		let token_props_permissions: PropertiesPermissionMap = data
+			.token_property_permissions
+			.into_iter()
+			.map(|property| (property.key, property.permission))
+			.collect::<BTreeMap<_, _>>()
+			.try_into()
+			.map_err(|_| PropertiesError::PropertyLimitReached)?;
+
+		CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);
+
 		// Take a (non-refundable) deposit of collection creation
 		{
 			let mut imbalance =
@@ -688,6 +729,34 @@
 		Ok(())
 	}
 
+	pub fn change_collection_property(
+		collection: &CollectionHandle<T>,
+		sender: &T::CrossAccountId,
+		property: Property,
+	) -> DispatchResult {
+		collection.check_is_owner_or_admin(sender)?;
+
+		CollectionProperties::<T>::get(collection.id).try_change_property(property)?;
+
+		Ok(())
+	}
+
+	pub fn change_property_permission(
+		collection: &CollectionHandle<T>,
+		sender: &T::CrossAccountId,
+		property_key: PropertyKey,
+		permission: PropertyPermission,
+	) -> DispatchResult {
+		collection.check_is_owner_or_admin(sender)?;
+
+		CollectionPropertyPermissions::<T>::try_mutate(collection.id, |permissions| {
+			permissions.try_insert(property_key, permission)
+		})
+		.map_err(|_| PropertiesError::PropertyLimitReached)?;
+
+		Ok(())
+	}
+
 	fn set_field_raw(
 		collection_id: CollectionId,
 		field: CollectionField,
@@ -840,6 +909,7 @@
 	fn create_multiple_items(amount: u32) -> Weight;
 	fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;
 	fn burn_item() -> Weight;
+	fn set_property() -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
@@ -875,6 +945,19 @@
 		amount: u128,
 	) -> DispatchResultWithPostInfo;
 
+	fn change_collection_property(
+		&self,
+		sender: T::CrossAccountId,
+		property: Property,
+	) -> DispatchResultWithPostInfo;
+
+	fn change_token_property(
+		&self,
+		sender: T::CrossAccountId,
+		token_id: TokenId,
+		property: Property,
+	) -> DispatchResultWithPostInfo;
+
 	fn transfer(
 		&self,
 		sender: T::CrossAccountId,
modifiedpallets/fungible/src/common.rsdiffbeforeafterboth
--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -21,7 +21,7 @@
 use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
 use sp_runtime::ArithmeticError;
 use sp_std::{vec::Vec, vec};
-use up_data_structs::CustomDataLimit;
+use up_data_structs::{CustomDataLimit, Property};
 
 use crate::{
 	Allowance, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf, weights::WeightInfo,
@@ -50,6 +50,10 @@
 		<SelfWeightOf<T>>::burn_item()
 	}
 
+	fn set_property() -> Weight {
+		<SelfWeightOf<T>>::set_property()
+	}
+
 	fn transfer() -> Weight {
 		<SelfWeightOf<T>>::transfer()
 	}
@@ -225,6 +229,23 @@
 		)
 	}
 
+	fn change_collection_property(
+		&self,
+		_sender: T::CrossAccountId,
+		_property: Property,
+	) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::PropertiesNotAllowed)
+	}
+
+	fn change_token_property(
+		&self,
+		_sender: T::CrossAccountId,
+		_token_id: TokenId,
+		_property: Property,
+	) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::PropertiesNotAllowed)
+	}
+
 	fn set_variable_metadata(
 		&self,
 		_sender: T::CrossAccountId,
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
before · pallets/fungible/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use core::ops::Deref;20use frame_support::{ensure};21use pallet_evm::account::CrossAccountId;22use up_data_structs::{23	AccessMode, CollectionId, TokenId, CreateCollectionData, mapping::TokenAddressMapping,24	budget::Budget,25};26use pallet_common::{27	Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, CollectionHandle,28	dispatch::CollectionDispatch,29};30use pallet_structure::Pallet as PalletStructure;31use pallet_evm_coder_substrate::WithRecorder;32use sp_core::H160;33use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};34use sp_std::collections::btree_map::BTreeMap;3536pub use pallet::*;3738use crate::erc::ERC20Events;39#[cfg(feature = "runtime-benchmarks")]40pub mod benchmarking;41pub mod common;42pub mod erc;43pub mod weights;4445pub type CreateItemData<T> = (<T as pallet_evm::account::Config>::CrossAccountId, u128);46pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;4748#[frame_support::pallet]49pub mod pallet {50	use frame_support::{Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};51	use up_data_structs::CollectionId;52	use super::weights::WeightInfo;5354	#[pallet::error]55	pub enum Error<T> {56		/// Not Fungible item data used to mint in Fungible collection.57		NotFungibleDataUsedToMintFungibleCollectionToken,58		/// Not default id passed as TokenId argument59		FungibleItemsHaveNoId,60		/// Tried to set data for fungible item61		FungibleItemsDontHaveData,62		/// Fungible token does not support nested63		FungibleDisallowsNesting,64	}6566	#[pallet::config]67	pub trait Config:68		frame_system::Config + pallet_common::Config + pallet_structure::Config69	{70		type WeightInfo: WeightInfo;71	}7273	#[pallet::pallet]74	#[pallet::generate_store(pub(super) trait Store)]75	pub struct Pallet<T>(_);7677	#[pallet::storage]78	pub type TotalSupply<T: Config> =79		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;8081	#[pallet::storage]82	pub type Balance<T: Config> = StorageNMap<83		Key = (84			Key<Twox64Concat, CollectionId>,85			Key<Blake2_128Concat, T::CrossAccountId>,86		),87		Value = u128,88		QueryKind = ValueQuery,89	>;9091	#[pallet::storage]92	pub type Allowance<T: Config> = StorageNMap<93		Key = (94			Key<Twox64Concat, CollectionId>,95			Key<Blake2_128, T::CrossAccountId>,96			Key<Blake2_128Concat, T::CrossAccountId>,97		),98		Value = u128,99		QueryKind = ValueQuery,100	>;101}102103pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);104impl<T: Config> FungibleHandle<T> {105	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {106		Self(inner)107	}108	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {109		self.0110	}111}112impl<T: Config> WithRecorder<T> for FungibleHandle<T> {113	fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {114		self.0.recorder()115	}116	fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {117		self.0.into_recorder()118	}119}120impl<T: Config> Deref for FungibleHandle<T> {121	type Target = pallet_common::CollectionHandle<T>;122123	fn deref(&self) -> &Self::Target {124		&self.0125	}126}127128impl<T: Config> Pallet<T> {129	pub fn init_collection(130		owner: T::AccountId,131		data: CreateCollectionData<T::AccountId>,132	) -> Result<CollectionId, DispatchError> {133		<PalletCommon<T>>::init_collection(owner, data)134	}135	pub fn destroy_collection(136		collection: FungibleHandle<T>,137		sender: &T::CrossAccountId,138	) -> DispatchResult {139		let id = collection.id;140141		// =========142143		PalletCommon::destroy_collection(collection.0, sender)?;144145		<TotalSupply<T>>::remove(id);146		<Balance<T>>::remove_prefix((id,), None);147		<Allowance<T>>::remove_prefix((id,), None);148		Ok(())149	}150151	pub fn burn(152		collection: &FungibleHandle<T>,153		owner: &T::CrossAccountId,154		amount: u128,155	) -> DispatchResult {156		let total_supply = <TotalSupply<T>>::get(collection.id)157			.checked_sub(amount)158			.ok_or(<CommonError<T>>::TokenValueTooLow)?;159160		let balance = <Balance<T>>::get((collection.id, owner))161			.checked_sub(amount)162			.ok_or(<CommonError<T>>::TokenValueTooLow)?;163164		if collection.access == AccessMode::AllowList {165			collection.check_allowlist(owner)?;166		}167168		// =========169170		if balance == 0 {171			<Balance<T>>::remove((collection.id, owner));172		} else {173			<Balance<T>>::insert((collection.id, owner), balance);174		}175		<TotalSupply<T>>::insert(collection.id, total_supply);176177		collection.log_mirrored(ERC20Events::Transfer {178			from: *owner.as_eth(),179			to: H160::default(),180			value: amount.into(),181		});182		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(183			collection.id,184			TokenId::default(),185			owner.clone(),186			amount,187		));188		Ok(())189	}190191	pub fn transfer(192		collection: &FungibleHandle<T>,193		from: &T::CrossAccountId,194		to: &T::CrossAccountId,195		amount: u128,196		nesting_budget: &dyn Budget,197	) -> DispatchResult {198		ensure!(199			collection.limits.transfers_enabled(),200			<CommonError<T>>::TransferNotAllowed,201		);202203		if collection.access == AccessMode::AllowList {204			collection.check_allowlist(from)?;205			collection.check_allowlist(to)?;206		}207		<PalletCommon<T>>::ensure_correct_receiver(to)?;208209		let balance_from = <Balance<T>>::get((collection.id, from))210			.checked_sub(amount)211			.ok_or(<CommonError<T>>::TokenValueTooLow)?;212		let balance_to = if from != to {213			Some(214				<Balance<T>>::get((collection.id, to))215					.checked_add(amount)216					.ok_or(ArithmeticError::Overflow)?,217			)218		} else {219			None220		};221222		if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {223			let handle = <CollectionHandle<T>>::try_get(target.0)?;224			let dispatch = T::CollectionDispatch::dispatch(handle);225			let dispatch = dispatch.as_dyn();226227			dispatch.check_nesting(228				from.clone(),229				(collection.id, TokenId::default()),230				target.1,231				nesting_budget,232			)?;233		}234235		// =========236237		if let Some(balance_to) = balance_to {238			// from != to239			if balance_from == 0 {240				<Balance<T>>::remove((collection.id, from));241			} else {242				<Balance<T>>::insert((collection.id, from), balance_from);243			}244			<Balance<T>>::insert((collection.id, to), balance_to);245		}246247		collection.log_mirrored(ERC20Events::Transfer {248			from: *from.as_eth(),249			to: *to.as_eth(),250			value: amount.into(),251		});252		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(253			collection.id,254			TokenId::default(),255			from.clone(),256			to.clone(),257			amount,258		));259		Ok(())260	}261262	pub fn create_multiple_items(263		collection: &FungibleHandle<T>,264		sender: &T::CrossAccountId,265		data: BTreeMap<T::CrossAccountId, u128>,266		nesting_budget: &dyn Budget,267	) -> DispatchResult {268		if !collection.is_owner_or_admin(sender) {269			ensure!(270				collection.mint_mode,271				<CommonError<T>>::PublicMintingNotAllowed272			);273			collection.check_allowlist(sender)?;274275			for (owner, _) in data.iter() {276				collection.check_allowlist(owner)?;277			}278		}279280		let total_supply = data281			.iter()282			.map(|(_, v)| *v)283			.try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {284				acc.checked_add(v)285			})286			.ok_or(ArithmeticError::Overflow)?;287288		let mut balances = data;289		for (k, v) in balances.iter_mut() {290			*v = <Balance<T>>::get((collection.id, &k))291				.checked_add(*v)292				.ok_or(ArithmeticError::Overflow)?;293		}294295		for (to, _) in balances.iter() {296			if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {297				let handle = <CollectionHandle<T>>::try_get(target.0)?;298				let dispatch = T::CollectionDispatch::dispatch(handle);299				let dispatch = dispatch.as_dyn();300301				dispatch.check_nesting(302					sender.clone(),303					(collection.id, TokenId::default()),304					target.1,305					nesting_budget,306				)?;307			}308		}309310		// =========311312		<TotalSupply<T>>::insert(collection.id, total_supply);313		for (user, amount) in balances {314			<Balance<T>>::insert((collection.id, &user), amount);315316			collection.log_mirrored(ERC20Events::Transfer {317				from: H160::default(),318				to: *user.as_eth(),319				value: amount.into(),320			});321			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(322				collection.id,323				TokenId::default(),324				user.clone(),325				amount,326			));327		}328329		Ok(())330	}331332	fn set_allowance_unchecked(333		collection: &FungibleHandle<T>,334		owner: &T::CrossAccountId,335		spender: &T::CrossAccountId,336		amount: u128,337	) {338		if amount == 0 {339			<Allowance<T>>::remove((collection.id, owner, spender));340		} else {341			<Allowance<T>>::insert((collection.id, owner, spender), amount);342		}343344		collection.log_mirrored(ERC20Events::Approval {345			owner: *owner.as_eth(),346			spender: *spender.as_eth(),347			value: amount.into(),348		});349		<PalletCommon<T>>::deposit_event(CommonEvent::Approved(350			collection.id,351			TokenId(0),352			owner.clone(),353			spender.clone(),354			amount,355		));356	}357358	pub fn set_allowance(359		collection: &FungibleHandle<T>,360		owner: &T::CrossAccountId,361		spender: &T::CrossAccountId,362		amount: u128,363	) -> DispatchResult {364		if collection.access == AccessMode::AllowList {365			collection.check_allowlist(owner)?;366			collection.check_allowlist(spender)?;367		}368369		if <Balance<T>>::get((collection.id, owner)) < amount {370			ensure!(371				collection.ignores_owned_amount(owner),372				<CommonError<T>>::CantApproveMoreThanOwned373			);374		}375376		// =========377378		Self::set_allowance_unchecked(collection, owner, spender, amount);379		Ok(())380	}381382	fn check_allowed(383		collection: &FungibleHandle<T>,384		spender: &T::CrossAccountId,385		from: &T::CrossAccountId,386		amount: u128,387		nesting_budget: &dyn Budget,388	) -> Result<Option<u128>, DispatchError> {389		if spender.conv_eq(from) {390			return Ok(None);391		}392		if collection.access == AccessMode::AllowList {393			// `from`, `to` checked in [`transfer`]394			collection.check_allowlist(spender)?;395		}396		if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {397			// TODO: should collection owner be allowed to perform this transfer?398			ensure!(399				<PalletStructure<T>>::check_indirectly_owned(400					spender.clone(),401					source.0,402					source.1,403					None,404					nesting_budget405				)?,406				<CommonError<T>>::ApprovedValueTooLow,407			);408			return Ok(None);409		}410		let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);411		if allowance.is_none() {412			ensure!(413				collection.ignores_allowance(spender),414				<CommonError<T>>::ApprovedValueTooLow415			);416		}417418		Ok(allowance)419	}420421	pub fn transfer_from(422		collection: &FungibleHandle<T>,423		spender: &T::CrossAccountId,424		from: &T::CrossAccountId,425		to: &T::CrossAccountId,426		amount: u128,427		nesting_budget: &dyn Budget,428	) -> DispatchResult {429		let allowance = Self::check_allowed(collection, spender, from, amount, nesting_budget)?;430431		// =========432433		Self::transfer(collection, from, to, amount, nesting_budget)?;434		if let Some(allowance) = allowance {435			Self::set_allowance_unchecked(collection, from, spender, allowance);436		}437		Ok(())438	}439440	pub fn burn_from(441		collection: &FungibleHandle<T>,442		spender: &T::CrossAccountId,443		from: &T::CrossAccountId,444		amount: u128,445		nesting_budget: &dyn Budget,446	) -> DispatchResult {447		let allowance = Self::check_allowed(collection, spender, from, amount, nesting_budget)?;448449		// =========450451		Self::burn(collection, from, amount)?;452		if let Some(allowance) = allowance {453			Self::set_allowance_unchecked(collection, from, spender, allowance);454		}455		Ok(())456	}457458	/// Delegated to `create_multiple_items`459	pub fn create_item(460		collection: &FungibleHandle<T>,461		sender: &T::CrossAccountId,462		data: CreateItemData<T>,463		nesting_budget: &dyn Budget,464	) -> DispatchResult {465		Self::create_multiple_items(466			collection,467			sender,468			[(data.0, data.1)].into_iter().collect(),469			nesting_budget,470		)471	}472}
after · pallets/fungible/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use core::ops::Deref;20use frame_support::{ensure};21use pallet_evm::account::CrossAccountId;22use up_data_structs::{23	AccessMode, CollectionId, TokenId, CreateCollectionData, mapping::TokenAddressMapping,24	budget::Budget,25};26use pallet_common::{27	Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, CollectionHandle,28	dispatch::CollectionDispatch,29};30use pallet_structure::Pallet as PalletStructure;31use pallet_evm_coder_substrate::WithRecorder;32use sp_core::H160;33use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};34use sp_std::collections::btree_map::BTreeMap;3536pub use pallet::*;3738use crate::erc::ERC20Events;39#[cfg(feature = "runtime-benchmarks")]40pub mod benchmarking;41pub mod common;42pub mod erc;43pub mod weights;4445pub type CreateItemData<T> = (<T as pallet_evm::account::Config>::CrossAccountId, u128);46pub(crate) type SelfWeightOf<T> = <T as Config>::WeightInfo;4748#[frame_support::pallet]49pub mod pallet {50	use frame_support::{Blake2_128, Blake2_128Concat, Twox64Concat, pallet_prelude::*, storage::Key};51	use up_data_structs::CollectionId;52	use super::weights::WeightInfo;5354	#[pallet::error]55	pub enum Error<T> {56		/// Not Fungible item data used to mint in Fungible collection.57		NotFungibleDataUsedToMintFungibleCollectionToken,58		/// Not default id passed as TokenId argument59		FungibleItemsHaveNoId,60		/// Tried to set data for fungible item61		FungibleItemsDontHaveData,62		/// Fungible token does not support nested63		FungibleDisallowsNesting,64		/// Item properties are not allowed65		PropertiesNotAllowed,66	}6768	#[pallet::config]69	pub trait Config:70		frame_system::Config + pallet_common::Config + pallet_structure::Config71	{72		type WeightInfo: WeightInfo;73	}7475	#[pallet::pallet]76	#[pallet::generate_store(pub(super) trait Store)]77	pub struct Pallet<T>(_);7879	#[pallet::storage]80	pub type TotalSupply<T: Config> =81		StorageMap<Hasher = Twox64Concat, Key = CollectionId, Value = u128, QueryKind = ValueQuery>;8283	#[pallet::storage]84	pub type Balance<T: Config> = StorageNMap<85		Key = (86			Key<Twox64Concat, CollectionId>,87			Key<Blake2_128Concat, T::CrossAccountId>,88		),89		Value = u128,90		QueryKind = ValueQuery,91	>;9293	#[pallet::storage]94	pub type Allowance<T: Config> = StorageNMap<95		Key = (96			Key<Twox64Concat, CollectionId>,97			Key<Blake2_128, T::CrossAccountId>,98			Key<Blake2_128Concat, T::CrossAccountId>,99		),100		Value = u128,101		QueryKind = ValueQuery,102	>;103}104105pub struct FungibleHandle<T: Config>(pallet_common::CollectionHandle<T>);106impl<T: Config> FungibleHandle<T> {107	pub fn cast(inner: pallet_common::CollectionHandle<T>) -> Self {108		Self(inner)109	}110	pub fn into_inner(self) -> pallet_common::CollectionHandle<T> {111		self.0112	}113}114impl<T: Config> WithRecorder<T> for FungibleHandle<T> {115	fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {116		self.0.recorder()117	}118	fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {119		self.0.into_recorder()120	}121}122impl<T: Config> Deref for FungibleHandle<T> {123	type Target = pallet_common::CollectionHandle<T>;124125	fn deref(&self) -> &Self::Target {126		&self.0127	}128}129130impl<T: Config> Pallet<T> {131	pub fn init_collection(132		owner: T::AccountId,133		data: CreateCollectionData<T::AccountId>,134	) -> Result<CollectionId, DispatchError> {135		<PalletCommon<T>>::init_collection(owner, data)136	}137	pub fn destroy_collection(138		collection: FungibleHandle<T>,139		sender: &T::CrossAccountId,140	) -> DispatchResult {141		let id = collection.id;142143		// =========144145		PalletCommon::destroy_collection(collection.0, sender)?;146147		<TotalSupply<T>>::remove(id);148		<Balance<T>>::remove_prefix((id,), None);149		<Allowance<T>>::remove_prefix((id,), None);150		Ok(())151	}152153	pub fn burn(154		collection: &FungibleHandle<T>,155		owner: &T::CrossAccountId,156		amount: u128,157	) -> DispatchResult {158		let total_supply = <TotalSupply<T>>::get(collection.id)159			.checked_sub(amount)160			.ok_or(<CommonError<T>>::TokenValueTooLow)?;161162		let balance = <Balance<T>>::get((collection.id, owner))163			.checked_sub(amount)164			.ok_or(<CommonError<T>>::TokenValueTooLow)?;165166		if collection.access == AccessMode::AllowList {167			collection.check_allowlist(owner)?;168		}169170		// =========171172		if balance == 0 {173			<Balance<T>>::remove((collection.id, owner));174		} else {175			<Balance<T>>::insert((collection.id, owner), balance);176		}177		<TotalSupply<T>>::insert(collection.id, total_supply);178179		collection.log_mirrored(ERC20Events::Transfer {180			from: *owner.as_eth(),181			to: H160::default(),182			value: amount.into(),183		});184		<PalletCommon<T>>::deposit_event(CommonEvent::ItemDestroyed(185			collection.id,186			TokenId::default(),187			owner.clone(),188			amount,189		));190		Ok(())191	}192193	pub fn transfer(194		collection: &FungibleHandle<T>,195		from: &T::CrossAccountId,196		to: &T::CrossAccountId,197		amount: u128,198		nesting_budget: &dyn Budget,199	) -> DispatchResult {200		ensure!(201			collection.limits.transfers_enabled(),202			<CommonError<T>>::TransferNotAllowed,203		);204205		if collection.access == AccessMode::AllowList {206			collection.check_allowlist(from)?;207			collection.check_allowlist(to)?;208		}209		<PalletCommon<T>>::ensure_correct_receiver(to)?;210211		let balance_from = <Balance<T>>::get((collection.id, from))212			.checked_sub(amount)213			.ok_or(<CommonError<T>>::TokenValueTooLow)?;214		let balance_to = if from != to {215			Some(216				<Balance<T>>::get((collection.id, to))217					.checked_add(amount)218					.ok_or(ArithmeticError::Overflow)?,219			)220		} else {221			None222		};223224		if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {225			let handle = <CollectionHandle<T>>::try_get(target.0)?;226			let dispatch = T::CollectionDispatch::dispatch(handle);227			let dispatch = dispatch.as_dyn();228229			dispatch.check_nesting(230				from.clone(),231				(collection.id, TokenId::default()),232				target.1,233				nesting_budget,234			)?;235		}236237		// =========238239		if let Some(balance_to) = balance_to {240			// from != to241			if balance_from == 0 {242				<Balance<T>>::remove((collection.id, from));243			} else {244				<Balance<T>>::insert((collection.id, from), balance_from);245			}246			<Balance<T>>::insert((collection.id, to), balance_to);247		}248249		collection.log_mirrored(ERC20Events::Transfer {250			from: *from.as_eth(),251			to: *to.as_eth(),252			value: amount.into(),253		});254		<PalletCommon<T>>::deposit_event(CommonEvent::Transfer(255			collection.id,256			TokenId::default(),257			from.clone(),258			to.clone(),259			amount,260		));261		Ok(())262	}263264	pub fn create_multiple_items(265		collection: &FungibleHandle<T>,266		sender: &T::CrossAccountId,267		data: BTreeMap<T::CrossAccountId, u128>,268		nesting_budget: &dyn Budget,269	) -> DispatchResult {270		if !collection.is_owner_or_admin(sender) {271			ensure!(272				collection.mint_mode,273				<CommonError<T>>::PublicMintingNotAllowed274			);275			collection.check_allowlist(sender)?;276277			for (owner, _) in data.iter() {278				collection.check_allowlist(owner)?;279			}280		}281282		let total_supply = data283			.iter()284			.map(|(_, v)| *v)285			.try_fold(<TotalSupply<T>>::get(collection.id), |acc, v| {286				acc.checked_add(v)287			})288			.ok_or(ArithmeticError::Overflow)?;289290		let mut balances = data;291		for (k, v) in balances.iter_mut() {292			*v = <Balance<T>>::get((collection.id, &k))293				.checked_add(*v)294				.ok_or(ArithmeticError::Overflow)?;295		}296297		for (to, _) in balances.iter() {298			if let Some(target) = T::CrossTokenAddressMapping::address_to_token(to) {299				let handle = <CollectionHandle<T>>::try_get(target.0)?;300				let dispatch = T::CollectionDispatch::dispatch(handle);301				let dispatch = dispatch.as_dyn();302303				dispatch.check_nesting(304					sender.clone(),305					(collection.id, TokenId::default()),306					target.1,307					nesting_budget,308				)?;309			}310		}311312		// =========313314		<TotalSupply<T>>::insert(collection.id, total_supply);315		for (user, amount) in balances {316			<Balance<T>>::insert((collection.id, &user), amount);317318			collection.log_mirrored(ERC20Events::Transfer {319				from: H160::default(),320				to: *user.as_eth(),321				value: amount.into(),322			});323			<PalletCommon<T>>::deposit_event(CommonEvent::ItemCreated(324				collection.id,325				TokenId::default(),326				user.clone(),327				amount,328			));329		}330331		Ok(())332	}333334	fn set_allowance_unchecked(335		collection: &FungibleHandle<T>,336		owner: &T::CrossAccountId,337		spender: &T::CrossAccountId,338		amount: u128,339	) {340		if amount == 0 {341			<Allowance<T>>::remove((collection.id, owner, spender));342		} else {343			<Allowance<T>>::insert((collection.id, owner, spender), amount);344		}345346		collection.log_mirrored(ERC20Events::Approval {347			owner: *owner.as_eth(),348			spender: *spender.as_eth(),349			value: amount.into(),350		});351		<PalletCommon<T>>::deposit_event(CommonEvent::Approved(352			collection.id,353			TokenId(0),354			owner.clone(),355			spender.clone(),356			amount,357		));358	}359360	pub fn set_allowance(361		collection: &FungibleHandle<T>,362		owner: &T::CrossAccountId,363		spender: &T::CrossAccountId,364		amount: u128,365	) -> DispatchResult {366		if collection.access == AccessMode::AllowList {367			collection.check_allowlist(owner)?;368			collection.check_allowlist(spender)?;369		}370371		if <Balance<T>>::get((collection.id, owner)) < amount {372			ensure!(373				collection.ignores_owned_amount(owner),374				<CommonError<T>>::CantApproveMoreThanOwned375			);376		}377378		// =========379380		Self::set_allowance_unchecked(collection, owner, spender, amount);381		Ok(())382	}383384	fn check_allowed(385		collection: &FungibleHandle<T>,386		spender: &T::CrossAccountId,387		from: &T::CrossAccountId,388		amount: u128,389		nesting_budget: &dyn Budget,390	) -> Result<Option<u128>, DispatchError> {391		if spender.conv_eq(from) {392			return Ok(None);393		}394		if collection.access == AccessMode::AllowList {395			// `from`, `to` checked in [`transfer`]396			collection.check_allowlist(spender)?;397		}398		if let Some(source) = T::CrossTokenAddressMapping::address_to_token(from) {399			// TODO: should collection owner be allowed to perform this transfer?400			ensure!(401				<PalletStructure<T>>::check_indirectly_owned(402					spender.clone(),403					source.0,404					source.1,405					None,406					nesting_budget407				)?,408				<CommonError<T>>::ApprovedValueTooLow,409			);410			return Ok(None);411		}412		let allowance = <Allowance<T>>::get((collection.id, from, spender)).checked_sub(amount);413		if allowance.is_none() {414			ensure!(415				collection.ignores_allowance(spender),416				<CommonError<T>>::ApprovedValueTooLow417			);418		}419420		Ok(allowance)421	}422423	pub fn transfer_from(424		collection: &FungibleHandle<T>,425		spender: &T::CrossAccountId,426		from: &T::CrossAccountId,427		to: &T::CrossAccountId,428		amount: u128,429		nesting_budget: &dyn Budget,430	) -> DispatchResult {431		let allowance = Self::check_allowed(collection, spender, from, amount, nesting_budget)?;432433		// =========434435		Self::transfer(collection, from, to, amount, nesting_budget)?;436		if let Some(allowance) = allowance {437			Self::set_allowance_unchecked(collection, from, spender, allowance);438		}439		Ok(())440	}441442	pub fn burn_from(443		collection: &FungibleHandle<T>,444		spender: &T::CrossAccountId,445		from: &T::CrossAccountId,446		amount: u128,447		nesting_budget: &dyn Budget,448	) -> DispatchResult {449		let allowance = Self::check_allowed(collection, spender, from, amount, nesting_budget)?;450451		// =========452453		Self::burn(collection, from, amount)?;454		if let Some(allowance) = allowance {455			Self::set_allowance_unchecked(collection, from, spender, allowance);456		}457		Ok(())458	}459460	/// Delegated to `create_multiple_items`461	pub fn create_item(462		collection: &FungibleHandle<T>,463		sender: &T::CrossAccountId,464		data: CreateItemData<T>,465		nesting_budget: &dyn Budget,466	) -> DispatchResult {467		Self::create_multiple_items(468			collection,469			sender,470			[(data.0, data.1)].into_iter().collect(),471			nesting_budget,472		)473	}474}
modifiedpallets/fungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/fungible/src/weights.rs
+++ b/pallets/fungible/src/weights.rs
@@ -35,6 +35,7 @@
 	fn create_item() -> Weight;
 	fn create_multiple_items_ex(b: u32, ) -> Weight;
 	fn burn_item() -> Weight;
+	fn set_property() -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
@@ -69,6 +70,12 @@
 			.saturating_add(T::DbWeight::get().reads(2 as Weight))
 			.saturating_add(T::DbWeight::get().writes(2 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// Error
+		0
+	}
+
 	// Storage: Fungible Balance (r:2 w:2)
 	fn transfer() -> Weight {
 		(17_713_000 as Weight)
@@ -126,6 +133,12 @@
 			.saturating_add(RocksDbWeight::get().reads(2 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(2 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// Error
+		0
+	}
+
 	// Storage: Fungible Balance (r:2 w:2)
 	fn transfer() -> Weight {
 		(17_713_000 as Weight)
modifiedpallets/nonfungible/src/common.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -17,7 +17,9 @@
 use core::marker::PhantomData;
 
 use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, BoundedVec};
-use up_data_structs::{TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget};
+use up_data_structs::{
+	TokenId, CustomDataLimit, CreateItemExData, CollectionId, budget::Budget, Property,
+};
 use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
 use sp_runtime::DispatchError;
 use sp_std::vec::Vec;
@@ -48,6 +50,10 @@
 		<SelfWeightOf<T>>::burn_item()
 	}
 
+	fn set_property() -> Weight {
+		<SelfWeightOf<T>>::set_property()
+	}
+
 	fn transfer() -> Weight {
 		<SelfWeightOf<T>>::transfer()
 	}
@@ -235,6 +241,32 @@
 		}
 	}
 
+	fn change_collection_property(
+		&self,
+		sender: T::CrossAccountId,
+		property: Property,
+	) -> DispatchResultWithPostInfo {
+		// let token_id = None;
+		with_weight(
+			// <Pallet<T>>::change_property(self, &sender, token_id, property),
+			Ok(()),
+			<CommonWeights<T>>::set_property(),
+		)
+	}
+
+	fn change_token_property(
+		&self,
+		sender: T::CrossAccountId,
+		token_id: TokenId,
+		property: Property,
+	) -> DispatchResultWithPostInfo {
+		with_weight(
+			// <Pallet<T>>::change_property(self, &sender, Some(token_id), property),
+			Ok(()),
+			<CommonWeights<T>>::set_property(),
+		)
+	}
+
 	fn set_variable_metadata(
 		&self,
 		sender: T::CrossAccountId,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -20,7 +20,7 @@
 use frame_support::{BoundedVec, ensure, fail};
 use up_data_structs::{
 	AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
-	mapping::TokenAddressMapping, NestingRule, budget::Budget,
+	mapping::TokenAddressMapping, NestingRule, budget::Budget, Property, PropertyPermission,
 };
 use pallet_evm::account::CrossAccountId;
 use pallet_common::{
@@ -94,6 +94,14 @@
 		QueryKind = OptionQuery,
 	>;
 
+	#[pallet::storage]
+	pub type TokenProperties<T: Config> = StorageNMap<
+		Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
+		Value = up_data_structs::Properties,
+		QueryKind = ValueQuery,
+		OnEmpty = up_data_structs::TokenProperties,
+	>;
+
 	/// Used to enumerate tokens owned by account
 	#[pallet::storage]
 	pub type Owned<T: Config> = StorageNMap<
@@ -246,6 +254,56 @@
 		Ok(())
 	}
 
+	pub fn change_token_property(
+		collection: &NonfungibleHandle<T>,
+		sender: &T::CrossAccountId,
+		token_id: TokenId,
+		property: Property,
+	) -> DispatchResult {
+		let permission = <PalletCommon<T>>::property_permission(collection.id)
+			.get(&property.key)
+			.map(|p| p.clone())
+			.unwrap_or(PropertyPermission::None);
+
+		let check_token_owner = || -> DispatchResult {
+			let token_data = <TokenData<T>>::get((collection.id, token_id))
+				.ok_or(<CommonError<T>>::TokenNotFound)?;
+
+			ensure!(&token_data.owner == sender, <CommonError<T>>::NoPermission);
+
+			Ok(())
+		};
+
+		let is_property_exists = TokenProperties::<T>::get((collection.id, token_id))
+			.get_property(&property.key)
+			.is_some();
+
+		match (permission, is_property_exists) {
+			(PropertyPermission::AdminConst, false) => {
+				collection.check_is_owner_or_admin(sender)?
+			}
+			(PropertyPermission::Admin, _) => collection.check_is_owner_or_admin(sender)?,
+			(PropertyPermission::ItemOwnerConst, false) => check_token_owner()?,
+			(PropertyPermission::ItemOwner, _) => check_token_owner()?,
+			(PropertyPermission::ItemOwnerOrAdmin, _) => {
+				check_token_owner().or(collection.check_is_owner_or_admin(sender))?;
+			}
+			_ => return Err(<CommonError<T>>::NoPermission.into()),
+		}
+
+		<TokenProperties<T>>::try_mutate((collection.id, token_id), |properties| {
+			properties.try_change_property(property.clone())
+		})?;
+
+		<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
+			collection.id,
+			token_id,
+			property,
+		));
+
+		Ok(())
+	}
+
 	pub fn transfer(
 		collection: &NonfungibleHandle<T>,
 		from: &T::CrossAccountId,
modifiedpallets/nonfungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/weights.rs
+++ b/pallets/nonfungible/src/weights.rs
@@ -36,6 +36,7 @@
 	fn create_multiple_items(b: u32, ) -> Weight;
 	fn create_multiple_items_ex(b: u32, ) -> Weight;
 	fn burn_item() -> Weight;
+	fn set_property() -> Weight;
 	fn transfer() -> Weight;
 	fn approve() -> Weight;
 	fn transfer_from() -> Weight;
@@ -90,6 +91,12 @@
 			.saturating_add(T::DbWeight::get().reads(4 as Weight))
 			.saturating_add(T::DbWeight::get().writes(4 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// TODO calculate appropriate weight
+		50_000_000 as Weight
+	}
+
 	// Storage: Nonfungible TokenData (r:1 w:1)
 	// Storage: Nonfungible AccountBalance (r:2 w:2)
 	// Storage: Nonfungible Allowance (r:1 w:0)
@@ -179,6 +186,12 @@
 			.saturating_add(RocksDbWeight::get().reads(4 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(4 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// TODO calculate appropriate weight
+		50_000_000 as Weight
+	}
+
 	// Storage: Nonfungible TokenData (r:1 w:1)
 	// Storage: Nonfungible AccountBalance (r:2 w:2)
 	// Storage: Nonfungible Allowance (r:1 w:0)
modifiedpallets/refungible/src/common.rsdiffbeforeafterboth
--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -20,7 +20,7 @@
 use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};
 use up_data_structs::{
 	CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,
-	budget::Budget,
+	budget::Budget, Property,
 };
 use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};
 use sp_runtime::DispatchError;
@@ -66,6 +66,10 @@
 		max_weight_of!(burn_item_partial(), burn_item_fully())
 	}
 
+	fn set_property() -> Weight {
+		<SelfWeightOf<T>>::set_property()
+	}
+
 	fn transfer() -> Weight {
 		max_weight_of!(
 			transfer_normal(),
@@ -244,6 +248,23 @@
 		)
 	}
 
+	fn change_collection_property(
+		&self,
+		_sender: T::CrossAccountId,
+		_property: Property,
+	) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::PropertiesNotAllowed)
+	}
+
+	fn change_token_property(
+		&self,
+		_sender: T::CrossAccountId,
+		_token_id: TokenId,
+		_property: Property,
+	) -> DispatchResultWithPostInfo {
+		fail!(<Error<T>>::PropertiesNotAllowed)
+	}
+
 	fn set_variable_metadata(
 		&self,
 		sender: T::CrossAccountId,
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -62,6 +62,8 @@
 		WrongRefungiblePieces,
 		/// Refungible token can't nest other tokens
 		RefungibleDisallowsNesting,
+		/// Item properties are not allowed
+		PropertiesNotAllowed,
 	}
 
 	#[pallet::config]
modifiedpallets/refungible/src/weights.rsdiffbeforeafterboth
--- a/pallets/refungible/src/weights.rs
+++ b/pallets/refungible/src/weights.rs
@@ -38,6 +38,7 @@
 	fn create_multiple_items_ex_multiple_owners(b: u32, ) -> Weight;
 	fn burn_item_partial() -> Weight;
 	fn burn_item_fully() -> Weight;
+	fn set_property() -> Weight;
 	fn transfer_normal() -> Weight;
 	fn transfer_creating() -> Weight;
 	fn transfer_removing() -> Weight;
@@ -129,6 +130,12 @@
 			.saturating_add(T::DbWeight::get().reads(4 as Weight))
 			.saturating_add(T::DbWeight::get().writes(6 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// Error
+		0
+	}
+
 	// Storage: Refungible Balance (r:2 w:2)
 	fn transfer_normal() -> Weight {
 		(19_766_000 as Weight)
@@ -297,6 +304,12 @@
 			.saturating_add(RocksDbWeight::get().reads(4 as Weight))
 			.saturating_add(RocksDbWeight::get().writes(6 as Weight))
 	}
+
+	fn set_property() -> Weight {
+		// Error
+		0
+	}
+
 	// Storage: Refungible Balance (r:2 w:2)
 	fn transfer_normal() -> Weight {
 		(19_766_000 as Weight)
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -39,7 +39,7 @@
 	MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH, MAX_TOKEN_PREFIX_LENGTH,
 	AccessMode, CreateItemData, CollectionLimits, CollectionId, CollectionMode, TokenId,
 	SchemaVersion, SponsorshipState, MetaUpdatePermission, CreateCollectionData, CustomDataLimit,
-	CreateItemExData, budget, CollectionField,
+	CreateItemExData, budget, CollectionField, Property,
 };
 use pallet_evm::account::CrossAccountId;
 use pallet_common::{
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/lib.rs
+++ b/primitives/data-structs/src/lib.rs
@@ -22,13 +22,14 @@
 };
 use frame_support::{
 	storage::{bounded_btree_map::BoundedBTreeMap, bounded_btree_set::BoundedBTreeSet},
+	traits::Get,
 };
 
 #[cfg(feature = "serde")]
 use serde::{Serialize, Deserialize};
 
 use sp_core::U256;
-use sp_runtime::{ArithmeticError, sp_std::prelude::Vec};
+use sp_runtime::{ArithmeticError, sp_std::prelude::Vec, DispatchError};
 use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
 use frame_support::{BoundedVec, traits::ConstU32};
 use derivative::Derivative;
@@ -85,6 +86,26 @@
 pub const MAX_COLLECTION_DESCRIPTION_LENGTH: u32 = 256;
 pub const MAX_TOKEN_PREFIX_LENGTH: u32 = 16;
 
+pub const MAX_PROPERTY_KEY_LENGTH: u32 = 256;
+pub const MAX_PROPERTY_VALUE_LENGTH: u32 = 32768;
+pub const MAX_PROPERTIES_PER_ITEM: u32 = 64;
+
+// pub const MAX_PROPERTY_KEYS_OVERALL_LENGTH: u32 = MAX_PROPERTY_KEY_LENGTH * MAX_PROPERTIES_PER_ITEM;
+pub const MAX_COLLECTION_PROPERTIES_SIZE: u32 = 40960;
+pub const MAX_TOKEN_PROPERTIES_SIZE: u32 = 32768;
+
+pub const MAX_COLLECTION_PROPERTIES_ENCODE_LEN: u32 =
+	MAX_PROPERTIES_PER_ITEM * MAX_PROPERTY_KEY_LENGTH + MAX_COLLECTION_PROPERTIES_SIZE;
+
+pub struct MaxPropertiesPermissionsEncodeLen;
+
+impl Get<u32> for MaxPropertiesPermissionsEncodeLen {
+	fn get() -> u32 {
+		MAX_PROPERTIES_PER_ITEM * MAX_PROPERTY_KEY_LENGTH
+			+ <PropertyPermission as MaxEncodedLen>::max_encoded_len() as u32
+	}
+}
+
 /// How much items can be created per single
 /// create_many call
 pub const MAX_ITEMS_PER_BATCH: u32 = 200;
@@ -310,31 +331,32 @@
 	OffchainSchema,
 }
 
-#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, Debug, Derivative, MaxEncodedLen)]
-#[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
-#[derivative(Default(bound = ""))]
+#[derive(Encode, Decode, Clone, PartialEq, TypeInfo, Derivative, MaxEncodedLen)]
+#[derivative(Debug, Default(bound = ""))]
 pub struct CreateCollectionData<AccountId> {
 	#[derivative(Default(value = "CollectionMode::NFT"))]
 	pub mode: CollectionMode,
 	pub access: Option<AccessMode>,
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
 	pub name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
 	pub description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
 	pub token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
 	pub offchain_schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,
 	pub schema_version: Option<SchemaVersion>,
 	pub pending_sponsor: Option<AccountId>,
 	pub limits: Option<CollectionLimits>,
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
 	pub variable_on_chain_schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>,
-	#[cfg_attr(feature = "serde1", serde(with = "bounded::vec_serde"))]
 	pub const_on_chain_schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>,
 	pub meta_update_permission: Option<MetaUpdatePermission>,
+	pub token_property_permissions: CollectionPropertiesPermissionsVec,
+	pub properties: CollectionPropertiesVec,
 }
 
+pub type CollectionPropertiesPermissionsVec =
+	BoundedVec<PropertyKeyPermission, MaxPropertiesPermissionsEncodeLen>;
+
+pub type CollectionPropertiesVec =
+	BoundedVec<Property, ConstU32<MAX_COLLECTION_PROPERTIES_ENCODE_LEN>>;
+
 #[derive(Encode, Decode, Debug, Clone, PartialEq, TypeInfo)]
 #[cfg_attr(feature = "serde1", derive(Serialize, Deserialize))]
 pub struct NftItemType<AccountId> {
@@ -607,3 +629,128 @@
 		0
 	}
 }
+
+pub type PropertyKey = BoundedVec<u8, ConstU32<MAX_PROPERTY_KEY_LENGTH>>;
+pub type PropertyValue = BoundedVec<u8, ConstU32<MAX_PROPERTY_VALUE_LENGTH>>;
+
+#[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen, PartialEq, Clone)]
+pub enum PropertyPermission {
+	None,
+	AdminConst,
+	Admin,
+	ItemOwnerConst,
+	ItemOwner,
+	ItemOwnerOrAdmin,
+}
+
+#[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq, MaxEncodedLen)]
+pub struct Property {
+	pub key: PropertyKey,
+	pub value: PropertyValue,
+}
+
+#[derive(Encode, Decode, TypeInfo, Debug, MaxEncodedLen, PartialEq, Clone)]
+pub struct PropertyKeyPermission {
+	pub key: PropertyKey,
+	pub permission: PropertyPermission,
+}
+
+pub enum PropertiesError {
+	NoSpaceForProperty,
+	PropertyLimitReached,
+}
+
+impl From<PropertiesError> for DispatchError {
+	fn from(error: PropertiesError) -> Self {
+		match error {
+			PropertiesError::NoSpaceForProperty => DispatchError::Other("no space for property"),
+			PropertiesError::PropertyLimitReached => {
+				DispatchError::Other("property key limit reached")
+			}
+		}
+	}
+}
+
+pub type PropertiesMap =
+	BoundedBTreeMap<PropertyKey, PropertyValue, ConstU32<MAX_PROPERTIES_PER_ITEM>>;
+pub type PropertiesPermissionMap =
+	BoundedBTreeMap<PropertyKey, PropertyPermission, ConstU32<MAX_PROPERTIES_PER_ITEM>>;
+
+#[derive(Encode, Decode, TypeInfo, Clone, PartialEq, MaxEncodedLen)]
+pub struct Properties {
+	map: PropertiesMap,
+	consumed_space: u32,
+	space_limit: u32,
+}
+
+impl Properties {
+	pub fn new(space_limit: u32) -> Self {
+		Self {
+			map: BoundedBTreeMap::new(),
+			consumed_space: 0,
+			space_limit,
+		}
+	}
+
+	pub fn from_collection_props_vec(
+		data: CollectionPropertiesVec,
+	) -> Result<Self, PropertiesError> {
+		let mut props = Self::new(MAX_COLLECTION_PROPERTIES_SIZE);
+
+		for property in data.into_iter() {
+			props.try_change_property(property)?;
+		}
+
+		Ok(props)
+	}
+
+	pub fn try_change_property(&mut self, property: Property) -> Result<(), PropertiesError> {
+		let value_len = property.value.len();
+
+		if self.consumed_space as usize + value_len > self.space_limit as usize {
+			return Err(PropertiesError::NoSpaceForProperty);
+		}
+
+		self.map
+			.try_insert(property.key, property.value)
+			.map_err(|_| PropertiesError::PropertyLimitReached)?;
+
+		self.consumed_space += value_len as u32;
+
+		Ok(())
+	}
+
+	pub fn get_property(&self, key: &PropertyKey) -> Option<&PropertyValue> {
+		self.map.get(key)
+	}
+}
+
+pub struct CollectionProperties;
+
+impl Get<Properties> for CollectionProperties {
+	fn get() -> Properties {
+		Properties::new(MAX_COLLECTION_PROPERTIES_SIZE)
+	}
+}
+
+pub struct TokenProperties;
+
+impl Get<Properties> for TokenProperties {
+	fn get() -> Properties {
+		Properties::new(MAX_TOKEN_PROPERTIES_SIZE)
+	}
+}
+
+// #[cfg(not(feature = "std"))]
+// fn properties_map_debug(_properties: &PropertiesMap, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
+// 	write!(f, "<properties>")
+// }
+
+// #[cfg(not(feature = "std"))]
+// fn opt_properties_permissions_map_debug(properties: &Option<PropertiesPermissionMap>, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
+// 	if properties.is_some() {
+// 		write!(f, "Some(<properties permissions>)")
+// 	 } else {
+// 		write!(f, "None")
+// 	}
+// }
modifiedprimitives/rpc/src/lib.rsdiffbeforeafterboth
--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -16,7 +16,9 @@
 
 #![cfg_attr(not(feature = "std"), no_std)]
 
-use up_data_structs::{CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits};
+use up_data_structs::{
+	CollectionId, TokenId, RpcCollection, CollectionStats, CollectionLimits, Property,
+};
 use sp_std::vec::Vec;
 use codec::Decode;
 use sp_runtime::DispatchError;
modifiedruntime/common/src/weights.rsdiffbeforeafterboth
--- a/runtime/common/src/weights.rs
+++ b/runtime/common/src/weights.rs
@@ -54,6 +54,10 @@
 		dispatch_weight::<T>() + max_weight_of!(burn_item())
 	}
 
+	fn set_property() -> Weight {
+		dispatch_weight::<T>() + max_weight_of!(set_property())
+	}
+
 	fn transfer() -> Weight {
 		dispatch_weight::<T>() + max_weight_of!(transfer())
 	}