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
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -61,6 +61,8 @@
 		FungibleItemsDontHaveData,
 		/// Fungible token does not support nested
 		FungibleDisallowsNesting,
+		/// Item properties are not allowed
+		PropertiesNotAllowed,
 	}
 
 	#[pallet::config]
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
before · pallets/refungible/src/common.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/>.1617use core::marker::PhantomData;1819use sp_std::collections::btree_map::BTreeMap;20use frame_support::{dispatch::DispatchResultWithPostInfo, fail, weights::Weight, BoundedVec};21use up_data_structs::{22	CollectionId, TokenId, CustomDataLimit, CreateItemExData, CreateRefungibleExData,23	budget::Budget,24};25use pallet_common::{CommonCollectionOperations, CommonWeightInfo, with_weight};26use sp_runtime::DispatchError;27use sp_std::{vec::Vec, vec};2829use crate::{30	AccountBalance, Allowance, Balance, Config, Error, Owned, Pallet, RefungibleHandle,31	SelfWeightOf, TokenData, weights::WeightInfo, TokensMinted,32};3334macro_rules! max_weight_of {35	($($method:ident ($($args:tt)*)),*) => {36		037		$(38			.max(<SelfWeightOf<T>>::$method($($args)*))39		)*40	};41}4243pub struct CommonWeights<T: Config>(PhantomData<T>);44impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {45	fn create_item() -> Weight {46		<SelfWeightOf<T>>::create_item()47	}4849	fn create_multiple_items(amount: u32) -> Weight {50		<SelfWeightOf<T>>::create_multiple_items(amount)51	}5253	fn create_multiple_items_ex(call: &CreateItemExData<T::CrossAccountId>) -> Weight {54		match call {55			CreateItemExData::RefungibleMultipleOwners(i) => {56				<SelfWeightOf<T>>::create_multiple_items_ex_multiple_owners(i.users.len() as u32)57			}58			CreateItemExData::RefungibleMultipleItems(i) => {59				<SelfWeightOf<T>>::create_multiple_items_ex_multiple_items(i.len() as u32)60			}61			_ => 0,62		}63	}6465	fn burn_item() -> Weight {66		max_weight_of!(burn_item_partial(), burn_item_fully())67	}6869	fn transfer() -> Weight {70		max_weight_of!(71			transfer_normal(),72			transfer_creating(),73			transfer_removing(),74			transfer_creating_removing()75		)76	}7778	fn approve() -> Weight {79		<SelfWeightOf<T>>::approve()80	}8182	fn transfer_from() -> Weight {83		max_weight_of!(84			transfer_from_normal(),85			transfer_from_creating(),86			transfer_from_removing(),87			transfer_from_creating_removing()88		)89	}9091	fn burn_from() -> Weight {92		<SelfWeightOf<T>>::burn_from()93	}9495	fn set_variable_metadata(bytes: u32) -> Weight {96		<SelfWeightOf<T>>::set_variable_metadata(bytes)97	}98}99100fn map_create_data<T: Config>(101	data: up_data_structs::CreateItemData,102	to: &T::CrossAccountId,103) -> Result<CreateRefungibleExData<T::CrossAccountId>, DispatchError> {104	match data {105		up_data_structs::CreateItemData::ReFungible(data) => Ok(CreateRefungibleExData {106			const_data: data.const_data,107			variable_data: data.variable_data,108			users: {109				let mut out = BTreeMap::new();110				out.insert(to.clone(), data.pieces);111				out.try_into().expect("limit > 0")112			},113		}),114		_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),115	}116}117118impl<T: Config> CommonCollectionOperations<T> for RefungibleHandle<T> {119	fn create_item(120		&self,121		sender: T::CrossAccountId,122		to: T::CrossAccountId,123		data: up_data_structs::CreateItemData,124		nesting_budget: &dyn Budget,125	) -> DispatchResultWithPostInfo {126		with_weight(127			<Pallet<T>>::create_item(128				self,129				&sender,130				map_create_data::<T>(data, &to)?,131				nesting_budget,132			),133			<CommonWeights<T>>::create_item(),134		)135	}136137	fn create_multiple_items(138		&self,139		sender: T::CrossAccountId,140		to: T::CrossAccountId,141		data: Vec<up_data_structs::CreateItemData>,142		nesting_budget: &dyn Budget,143	) -> DispatchResultWithPostInfo {144		let data = data145			.into_iter()146			.map(|d| map_create_data::<T>(d, &to))147			.collect::<Result<Vec<_>, DispatchError>>()?;148149		let amount = data.len();150		with_weight(151			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),152			<CommonWeights<T>>::create_multiple_items(amount as u32),153		)154	}155156	fn create_multiple_items_ex(157		&self,158		sender: <T>::CrossAccountId,159		data: CreateItemExData<T::CrossAccountId>,160		nesting_budget: &dyn Budget,161	) -> DispatchResultWithPostInfo {162		let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);163		let data = match data {164			CreateItemExData::RefungibleMultipleOwners(r) => vec![r],165			CreateItemExData::RefungibleMultipleItems(r)166				if r.iter().all(|i| i.users.len() == 1) =>167			{168				r.into_inner()169			}170			_ => fail!(<Error<T>>::NotRefungibleDataUsedToMintFungibleCollectionToken),171		};172173		with_weight(174			<Pallet<T>>::create_multiple_items(self, &sender, data, nesting_budget),175			weight,176		)177	}178179	fn burn_item(180		&self,181		sender: T::CrossAccountId,182		token: TokenId,183		amount: u128,184	) -> DispatchResultWithPostInfo {185		with_weight(186			<Pallet<T>>::burn(self, &sender, token, amount),187			<CommonWeights<T>>::burn_item(),188		)189	}190191	fn transfer(192		&self,193		from: T::CrossAccountId,194		to: T::CrossAccountId,195		token: TokenId,196		amount: u128,197		nesting_budget: &dyn Budget,198	) -> DispatchResultWithPostInfo {199		with_weight(200			<Pallet<T>>::transfer(self, &from, &to, token, amount, nesting_budget),201			<CommonWeights<T>>::transfer(),202		)203	}204205	fn approve(206		&self,207		sender: T::CrossAccountId,208		spender: T::CrossAccountId,209		token: TokenId,210		amount: u128,211	) -> DispatchResultWithPostInfo {212		with_weight(213			<Pallet<T>>::set_allowance(self, &sender, &spender, token, amount),214			<CommonWeights<T>>::approve(),215		)216	}217218	fn transfer_from(219		&self,220		sender: T::CrossAccountId,221		from: T::CrossAccountId,222		to: T::CrossAccountId,223		token: TokenId,224		amount: u128,225		nesting_budget: &dyn Budget,226	) -> DispatchResultWithPostInfo {227		with_weight(228			<Pallet<T>>::transfer_from(self, &sender, &from, &to, token, amount, nesting_budget),229			<CommonWeights<T>>::transfer_from(),230		)231	}232233	fn burn_from(234		&self,235		sender: T::CrossAccountId,236		from: T::CrossAccountId,237		token: TokenId,238		amount: u128,239		nesting_budget: &dyn Budget,240	) -> DispatchResultWithPostInfo {241		with_weight(242			<Pallet<T>>::burn_from(self, &sender, &from, token, amount, nesting_budget),243			<CommonWeights<T>>::burn_from(),244		)245	}246247	fn set_variable_metadata(248		&self,249		sender: T::CrossAccountId,250		token: TokenId,251		data: BoundedVec<u8, CustomDataLimit>,252	) -> DispatchResultWithPostInfo {253		let len = data.len();254		with_weight(255			<Pallet<T>>::set_variable_metadata(self, &sender, token, data),256			<CommonWeights<T>>::set_variable_metadata(len as u32),257		)258	}259260	fn check_nesting(261		&self,262		_sender: <T>::CrossAccountId,263		_from: (CollectionId, TokenId),264		_under: TokenId,265		_budget: &dyn Budget,266	) -> sp_runtime::DispatchResult {267		fail!(<Error<T>>::RefungibleDisallowsNesting)268	}269270	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {271		<Owned<T>>::iter_prefix((self.id, account))272			.map(|(id, _)| id)273			.collect()274	}275276	fn collection_tokens(&self) -> Vec<TokenId> {277		<TokenData<T>>::iter_prefix((self.id,))278			.map(|(id, _)| id)279			.collect()280	}281282	fn token_exists(&self, token: TokenId) -> bool {283		<Pallet<T>>::token_exists(self, token)284	}285286	fn last_token_id(&self) -> TokenId {287		TokenId(<TokensMinted<T>>::get(self.id))288	}289290	fn token_owner(&self, _token: TokenId) -> Option<T::CrossAccountId> {291		None292	}293	fn const_metadata(&self, token: TokenId) -> Vec<u8> {294		<TokenData<T>>::get((self.id, token))295			.const_data296			.into_inner()297	}298	fn variable_metadata(&self, token: TokenId) -> Vec<u8> {299		<TokenData<T>>::get((self.id, token))300			.variable_data301			.into_inner()302	}303304	fn total_supply(&self) -> u32 {305		<Pallet<T>>::total_supply(self)306	}307308	fn account_balance(&self, account: T::CrossAccountId) -> u32 {309		<AccountBalance<T>>::get((self.id, account))310	}311312	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {313		<Balance<T>>::get((self.id, token, account))314	}315316	fn allowance(317		&self,318		sender: T::CrossAccountId,319		spender: T::CrossAccountId,320		token: TokenId,321	) -> u128 {322		<Allowance<T>>::get((self.id, token, sender, spender))323	}324}
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())
 	}