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

difftreelog

feature(common-pallet): add changeOwnerSubstrate and verifyOwnerOrAdminSubstrate methods

Grigoriy Simonov2022-08-23parent: #b24c73b.patch.diff
in: master

15 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -232,10 +232,7 @@
 		new_admin: uint256,
 	) -> Result<void> {
 		let caller = T::CrossAccountId::from_eth(caller);
-		let mut new_admin_arr: [u8; 32] = Default::default();
-		new_admin.to_big_endian(&mut new_admin_arr);
-		let account_id = T::AccountId::from(new_admin_arr);
-		let new_admin = T::CrossAccountId::from_sub(account_id);
+		let new_admin = convert_substrate_address_to_cross_account_id::<T>(new_admin);
 		<Pallet<T>>::toggle_admin(self, &caller, &new_admin, true).map_err(dispatch_to_evm::<T>)?;
 		Ok(())
 	}
@@ -248,10 +245,7 @@
 		admin: uint256,
 	) -> Result<void> {
 		let caller = T::CrossAccountId::from_eth(caller);
-		let mut admin_arr: [u8; 32] = Default::default();
-		admin.to_big_endian(&mut admin_arr);
-		let account_id = T::AccountId::from(admin_arr);
-		let admin = T::CrossAccountId::from_sub(account_id);
+		let admin = convert_substrate_address_to_cross_account_id::<T>(admin);
 		<Pallet<T>>::toggle_admin(self, &caller, &admin, false).map_err(dispatch_to_evm::<T>)?;
 		Ok(())
 	}
@@ -415,11 +409,25 @@
 	/// @param user account to verify
 	/// @return "true" if account is the owner or admin
 	fn verify_owner_or_admin(&self, user: address) -> Result<bool> {
-		Ok(check_is_owner_or_admin(user, self)
+		let user = T::CrossAccountId::from_eth(user);
+		Ok(self
+			.check_is_owner_or_admin(&user)
 			.map(|_| true)
 			.unwrap_or(false))
 	}
 
+	/// Check that substrate account is the owner or admin of the collection
+	///
+	/// @param user account to verify
+	/// @return "true" if account is the owner or admin
+	fn verify_owner_or_admin_substrate(&self, user: uint256) -> Result<bool> {
+		let user = convert_substrate_address_to_cross_account_id::<T>(user);
+		Ok(self
+			.check_is_owner_or_admin(&user)
+			.map(|_| true)
+			.unwrap_or(false))
+	}
+
 	/// Returns collection type
 	///
 	/// @return `Fungible` or `NFT` or `ReFungible`
@@ -432,26 +440,37 @@
 		Ok(mode.into())
 	}
 
-	/// Changes collection owner
+	/// Changes collection owner to another account
 	///
 	/// @dev Owner can be changed only by current owner
-	/// @param newOwner new owner
+	/// @param newOwner new owner account
 	fn change_owner(&mut self, caller: caller, new_owner: address) -> Result<void> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let new_owner = T::CrossAccountId::from_eth(new_owner);
 		self.change_owner_internal(caller, new_owner)
+			.map_err(dispatch_to_evm::<T>)
+	}
+
+	/// Changes collection owner to another substrate account
+	///
+	/// @dev Owner can be changed only by current owner
+	/// @param newOwner new owner substrate account
+	fn change_owner_substrate(&mut self, caller: caller, new_owner: uint256) -> Result<void> {
+		let caller = T::CrossAccountId::from_eth(caller);
+		let new_owner = convert_substrate_address_to_cross_account_id::<T>(new_owner);
+		self.change_owner_internal(caller, new_owner)
+			.map_err(dispatch_to_evm::<T>)
 	}
+}
 
-impl<T: Config> CollectionHandle<T>
+fn convert_substrate_address_to_cross_account_id<T: Config>(address: uint256) -> T::CrossAccountId
 where
 	T::AccountId: From<[u8; 32]>,
 {
-
-	fn change_owner_internal(&mut self, caller: T::CrossAccountId, new_owner: T::CrossAccountId) -> Result<void> {
-		self.check_is_owner(&caller).map_err(dispatch_to_evm::<T>)?;
-		self.collection.owner = new_owner.as_sub().clone();
-		save(self)
-	}
+	let mut address_arr: [u8; 32] = Default::default();
+	address.to_big_endian(&mut address_arr);
+	let account_id = T::AccountId::from(address_arr);
+	T::CrossAccountId::from_sub(account_id)
 }
 
 fn check_is_owner_or_admin<T: Config>(
@@ -471,7 +490,7 @@
 	collection
 		.check_is_internal()
 		.map_err(dispatch_to_evm::<T>)?;
-	<crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());
+	collection.save().map_err(dispatch_to_evm::<T>)?;
 	Ok(())
 }
 
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
before · pallets/common/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//! # Common pallet18//!19//! The Common pallet provides functionality for handling collections.20//!21//! ## Overview22//!23//! The Common pallet provides an interface for common collection operations for different collection types24//! (see [CommonCollectionOperations]), as well as a generic dispatcher for these, see [dispatch] module.25//! It also provides this functionality to EVM, see [erc] and [eth] modules.26//!27//! The Common pallet provides functions for:28//!29//! - Setting and approving collection sponsor.30//! - Get\set\delete allow list.31//! - Get\set\delete collection properties.32//! - Get\set\delete collection property permissions.33//! - Get\set\delete token property permissions.34//! - Get\set\delete collection administrators.35//! - Checking access permissions.36//!37//! ### Terminology38//! **Collection sponsor** - For the collection, you can set a sponsor, at whose expense it will39//! be possible to mint tokens.40//!41//! **Allow list** - List of users who have the right to minting tokens.42//!43//! **Collection properties** - Collection properties are simply key-value stores where various44//! metadata can be placed.45//!46//! **Permissions on token properties** - For each property in the token can be set permission47//! to change, see [`PropertyPermission`].48//!49//! **Collection administrator** - For a collection, you can set administrators who have the right50//! to most actions on the collection.5152#![warn(missing_docs)]53#![cfg_attr(not(feature = "std"), no_std)]54extern crate alloc;5556use core::ops::{Deref, DerefMut};57use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};58use sp_std::vec::Vec;59use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};60use evm_coder::ToLog;61use frame_support::{62	dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Weight, PostDispatchInfo},63	ensure,64	traits::{Imbalance, Get, Currency, WithdrawReasons, ExistenceRequirement},65	weights::Pays,66	transactional,67};68use pallet_evm::GasWeightMapping;69use up_data_structs::{70	COLLECTION_NUMBER_LIMIT,71	Collection,72	RpcCollection,73	CollectionId,74	CreateItemData,75	MAX_TOKEN_PREFIX_LENGTH,76	COLLECTION_ADMINS_LIMIT,77	TokenId,78	TokenChild,79	CollectionStats,80	MAX_TOKEN_OWNERSHIP,81	CollectionMode,82	NFT_SPONSOR_TRANSFER_TIMEOUT,83	FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,84	REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,85	MAX_SPONSOR_TIMEOUT,86	CUSTOM_DATA_LIMIT,87	CollectionLimits,88	CreateCollectionData,89	SponsorshipState,90	CreateItemExData,91	SponsoringRateLimit,92	budget::Budget,93	PhantomType,94	Property,95	Properties,96	PropertiesPermissionMap,97	PropertyKey,98	PropertyValue,99	PropertyPermission,100	PropertiesError,101	PropertyKeyPermission,102	TokenData,103	TrySetProperty,104	PropertyScope,105	// RMRK106	RmrkCollectionInfo,107	RmrkInstanceInfo,108	RmrkResourceInfo,109	RmrkPropertyInfo,110	RmrkBaseInfo,111	RmrkPartType,112	RmrkBoundedTheme,113	RmrkNftChild,114	CollectionPermissions,115	SchemaVersion,116};117118pub use pallet::*;119use sp_core::H160;120use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};121#[cfg(feature = "runtime-benchmarks")]122pub mod benchmarking;123pub mod dispatch;124pub mod erc;125pub mod eth;126pub mod weights;127128/// Weight info.129pub type SelfWeightOf<T> = <T as Config>::WeightInfo;130131/// Collection handle contains information about collection data and id.132/// Also provides functionality to count consumed gas.133///134/// CollectionHandle is used as a generic wrapper for collections of all types.135/// It allows to perform common operations and queries on any collection type,136/// both completely general for all, as well as their respective implementations of [`CommonCollectionOperations`].137#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]138pub struct CollectionHandle<T: Config> {139	/// Collection id140	pub id: CollectionId,141	collection: Collection<T::AccountId>,142	/// Substrate recorder for counting consumed gas143	pub recorder: SubstrateRecorder<T>,144}145146impl<T: Config> WithRecorder<T> for CollectionHandle<T> {147	fn recorder(&self) -> &SubstrateRecorder<T> {148		&self.recorder149	}150	fn into_recorder(self) -> SubstrateRecorder<T> {151		self.recorder152	}153}154155impl<T: Config> CollectionHandle<T> {156	/// Same as [CollectionHandle::new] but with an explicit gas limit.157	pub fn new_with_gas_limit(id: CollectionId, gas_limit: u64) -> Option<Self> {158		<CollectionById<T>>::get(id).map(|collection| Self {159			id,160			collection,161			recorder: SubstrateRecorder::new(gas_limit),162		})163	}164165	/// Same as [CollectionHandle::new] but with an existed [`SubstrateRecorder`].166	pub fn new_with_recorder(id: CollectionId, recorder: SubstrateRecorder<T>) -> Option<Self> {167		<CollectionById<T>>::get(id).map(|collection| Self {168			id,169			collection,170			recorder,171		})172	}173174	/// Retrives collection data from storage and creates collection handle with default parameters.175	/// If collection not found return `None`176	pub fn new(id: CollectionId) -> Option<Self> {177		Self::new_with_gas_limit(id, u64::MAX)178	}179180	/// Same as [`CollectionHandle::new`] but if collection not found [CollectionNotFound](Error::CollectionNotFound) returned.181	pub fn try_get(id: CollectionId) -> Result<Self, DispatchError> {182		Ok(Self::new(id).ok_or(<Error<T>>::CollectionNotFound)?)183	}184185	/// Consume gas for reading.186	pub fn consume_store_reads(&self, reads: u64) -> evm_coder::execution::Result<()> {187		self.recorder188			.consume_gas(T::GasWeightMapping::weight_to_gas(189				<T as frame_system::Config>::DbWeight::get()190					.read191					.saturating_mul(reads),192			))193	}194195	/// Consume gas for writing.196	pub fn consume_store_writes(&self, writes: u64) -> evm_coder::execution::Result<()> {197		self.recorder198			.consume_gas(T::GasWeightMapping::weight_to_gas(199				<T as frame_system::Config>::DbWeight::get()200					.write201					.saturating_mul(writes),202			))203	}204205	/// Save collection to storage.206	pub fn save(self) -> DispatchResult {207		<CollectionById<T>>::insert(self.id, self.collection);208		Ok(())209	}210211	/// Set collection sponsor.212	///213	/// Unique collections allows sponsoring for certain actions.214	/// This method allows you to set the sponsor of the collection.215	/// In order for sponsorship to become active, it must be confirmed through [`Self::confirm_sponsorship`].216	pub fn set_sponsor(&mut self, sponsor: T::AccountId) -> DispatchResult {217		self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor);218		Ok(())219	}220221	/// Confirm sponsorship222	///223	/// In order for the sponsorship to become active, the user set as the sponsor must confirm their participation.224	/// Before confirming sponsorship, the user must be specified as the sponsor of the collection via [`Self::set_sponsor`].225	pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> Result<bool, DispatchError> {226		if self.collection.sponsorship.pending_sponsor() != Some(sender) {227			return Ok(false);228		}229230		self.collection.sponsorship = SponsorshipState::Confirmed(sender.clone());231		Ok(true)232	}233234	/// Checks that the collection was created with, and must be operated upon through **Unique API**.235	/// Now check only the `external_collection` flag and if it's **true**, then return [`Error::CollectionIsExternal`] error.236	pub fn check_is_internal(&self) -> DispatchResult {237		if self.external_collection {238			return Err(<Error<T>>::CollectionIsExternal)?;239		}240241		Ok(())242	}243244	/// Checks that the collection was created with, and must be operated upon through an **assimilated API**.245	/// Now check only the `external_collection` flag and if it's **false**, then return [`Error::CollectionIsInternal`] error.246	pub fn check_is_external(&self) -> DispatchResult {247		if !self.external_collection {248			return Err(<Error<T>>::CollectionIsInternal)?;249		}250251		Ok(())252	}253}254255impl<T: Config> Deref for CollectionHandle<T> {256	type Target = Collection<T::AccountId>;257258	fn deref(&self) -> &Self::Target {259		&self.collection260	}261}262263impl<T: Config> DerefMut for CollectionHandle<T> {264	fn deref_mut(&mut self) -> &mut Self::Target {265		&mut self.collection266	}267}268269impl<T: Config> CollectionHandle<T> {270	/// Checks if the `user` is the owner of the collection.271	pub fn check_is_owner(&self, user: &T::CrossAccountId) -> DispatchResult {272		ensure!(*user.as_sub() == self.owner, <Error<T>>::NoPermission);273		Ok(())274	}275276	/// Returns **true** if the `user` is the owner or administrator of the collection.277	pub fn is_owner_or_admin(&self, user: &T::CrossAccountId) -> bool {278		*user.as_sub() == self.owner || <IsAdmin<T>>::get((self.id, user))279	}280281	/// Checks if the `user` is the owner or administrator of the collection.282	pub fn check_is_owner_or_admin(&self, user: &T::CrossAccountId) -> DispatchResult {283		ensure!(self.is_owner_or_admin(user), <Error<T>>::NoPermission);284		Ok(())285	}286287	/// Return **true** if `user` was not allowed to have tokens, and he can ignore such restrictions.288	pub fn ignores_allowance(&self, user: &T::CrossAccountId) -> bool {289		self.limits.owner_can_transfer() && self.is_owner_or_admin(user)290	}291292	/// Return **true** if `user` does not have enough token parts, and he can ignore such restrictions.293	pub fn ignores_owned_amount(&self, user: &T::CrossAccountId) -> bool {294		self.limits.owner_can_transfer() && self.is_owner_or_admin(user)295	}296297	/// Checks if the user is in the allow list. If not [Error::AddressNotInAllowlist] returns.298	pub fn check_allowlist(&self, user: &T::CrossAccountId) -> DispatchResult {299		ensure!(300			<Allowlist<T>>::get((self.id, user)),301			<Error<T>>::AddressNotInAllowlist302		);303		Ok(())304	}305}306307#[frame_support::pallet]308pub mod pallet {309	use super::*;310	use pallet_evm::account;311	use dispatch::CollectionDispatch;312	use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key, traits::StorageVersion};313	use frame_system::pallet_prelude::*;314	use frame_support::traits::Currency;315	use up_data_structs::{TokenId, mapping::TokenAddressMapping};316	use scale_info::TypeInfo;317	use weights::WeightInfo;318319	#[pallet::config]320	pub trait Config:321		frame_system::Config322		+ pallet_evm_coder_substrate::Config323		+ pallet_evm::Config324		+ TypeInfo325		+ account::Config326	{327		/// Weight information for functions of this pallet.328		type WeightInfo: WeightInfo;329330		/// Events compatible with [`frame_system::Config::Event`].331		type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;332333		/// Handler of accounts and payment.334		type Currency: Currency<Self::AccountId>;335336		/// Set price to create a collection.337		#[pallet::constant]338		type CollectionCreationPrice: Get<339			<<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,340		>;341342		/// Dispatcher of operations on collections.343		type CollectionDispatch: CollectionDispatch<Self>;344345		/// Account which holds the chain's treasury.346		type TreasuryAccountId: Get<Self::AccountId>;347348		/// Address under which the CollectionHelper contract would be available.349		type ContractAddress: Get<H160>;350351		/// Mapper for token addresses to Ethereum addresses.352		type EvmTokenAddressMapping: TokenAddressMapping<H160>;353354		/// Mapper for token addresses to [`CrossAccountId`].355		type CrossTokenAddressMapping: TokenAddressMapping<Self::CrossAccountId>;356	}357358	const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);359360	#[pallet::pallet]361	#[pallet::storage_version(STORAGE_VERSION)]362	#[pallet::generate_store(pub(super) trait Store)]363	pub struct Pallet<T>(_);364365	#[pallet::extra_constants]366	impl<T: Config> Pallet<T> {367		/// Maximum admins per collection.368		pub fn collection_admins_limit() -> u32 {369			COLLECTION_ADMINS_LIMIT370		}371	}372373	#[pallet::event]374	#[pallet::generate_deposit(pub fn deposit_event)]375	pub enum Event<T: Config> {376		/// New collection was created377		CollectionCreated(378			/// Globally unique identifier of newly created collection.379			CollectionId,380			/// [`CollectionMode`] converted into _u8_.381			u8,382			/// Collection owner.383			T::AccountId,384		),385386		/// New collection was destroyed387		CollectionDestroyed(388			/// Globally unique identifier of collection.389			CollectionId,390		),391392		/// New item was created.393		ItemCreated(394			/// Id of the collection where item was created.395			CollectionId,396			/// Id of an item. Unique within the collection.397			TokenId,398			/// Owner of newly created item399			T::CrossAccountId,400			/// Always 1 for NFT401			u128,402		),403404		/// Collection item was burned.405		ItemDestroyed(406			/// Id of the collection where item was destroyed.407			CollectionId,408			/// Identifier of burned NFT.409			TokenId,410			/// Which user has destroyed its tokens.411			T::CrossAccountId,412			/// Amount of token pieces destroed. Always 1 for NFT.413			u128,414		),415416		/// Item was transferred417		Transfer(418			/// Id of collection to which item is belong.419			CollectionId,420			/// Id of an item.421			TokenId,422			/// Original owner of item.423			T::CrossAccountId,424			/// New owner of item.425			T::CrossAccountId,426			/// Amount of token pieces transfered. Always 1 for NFT.427			u128,428		),429430		/// Amount pieces of token owned by `sender` was approved for `spender`.431		Approved(432			/// Id of collection to which item is belong.433			CollectionId,434			/// Id of an item.435			TokenId,436			/// Original owner of item.437			T::CrossAccountId,438			/// Id for which the approval was granted.439			T::CrossAccountId,440			/// Amount of token pieces transfered. Always 1 for NFT.441			u128,442		),443444		/// The colletion property has been added or edited.445		CollectionPropertySet(446			/// Id of collection to which property has been set.447			CollectionId,448			/// The property that was set.449			PropertyKey,450		),451452		/// The property has been deleted.453		CollectionPropertyDeleted(454			/// Id of collection to which property has been deleted.455			CollectionId,456			/// The property that was deleted.457			PropertyKey,458		),459460		/// The token property has been added or edited.461		TokenPropertySet(462			/// Identifier of the collection whose token has the property set.463			CollectionId,464			/// The token for which the property was set.465			TokenId,466			/// The property that was set.467			PropertyKey,468		),469470		/// The token property has been deleted.471		TokenPropertyDeleted(472			/// Identifier of the collection whose token has the property deleted.473			CollectionId,474			/// The token for which the property was deleted.475			TokenId,476			/// The property that was deleted.477			PropertyKey,478		),479480		/// The token property permission of a collection has been set.481		PropertyPermissionSet(482			/// ID of collection to which property permission has been set.483			CollectionId,484			/// The property permission that was set.485			PropertyKey,486		),487	}488489	#[pallet::error]490	pub enum Error<T> {491		/// This collection does not exist.492		CollectionNotFound,493		/// Sender parameter and item owner must be equal.494		MustBeTokenOwner,495		/// No permission to perform action496		NoPermission,497		/// Destroying only empty collections is allowed498		CantDestroyNotEmptyCollection,499		/// Collection is not in mint mode.500		PublicMintingNotAllowed,501		/// Address is not in allow list.502		AddressNotInAllowlist,503504		/// Collection name can not be longer than 63 char.505		CollectionNameLimitExceeded,506		/// Collection description can not be longer than 255 char.507		CollectionDescriptionLimitExceeded,508		/// Token prefix can not be longer than 15 char.509		CollectionTokenPrefixLimitExceeded,510		/// Total collections bound exceeded.511		TotalCollectionsLimitExceeded,512		/// Exceeded max admin count513		CollectionAdminCountExceeded,514		/// Collection limit bounds per collection exceeded515		CollectionLimitBoundsExceeded,516		/// Tried to enable permissions which are only permitted to be disabled517		OwnerPermissionsCantBeReverted,518		/// Collection settings not allowing items transferring519		TransferNotAllowed,520		/// Account token limit exceeded per collection521		AccountTokenLimitExceeded,522		/// Collection token limit exceeded523		CollectionTokenLimitExceeded,524		/// Metadata flag frozen525		MetadataFlagFrozen,526527		/// Item does not exist528		TokenNotFound,529		/// Item is balance not enough530		TokenValueTooLow,531		/// Requested value is more than the approved532		ApprovedValueTooLow,533		/// Tried to approve more than owned534		CantApproveMoreThanOwned,535536		/// Can't transfer tokens to ethereum zero address537		AddressIsZero,538539		/// The operation is not supported540		UnsupportedOperation,541542		/// Insufficient funds to perform an action543		NotSufficientFounds,544545		/// User does not satisfy the nesting rule546		UserIsNotAllowedToNest,547		/// Only tokens from specific collections may nest tokens under this one548		SourceCollectionIsNotAllowedToNest,549550		/// Tried to store more data than allowed in collection field551		CollectionFieldSizeExceeded,552553		/// Tried to store more property data than allowed554		NoSpaceForProperty,555556		/// Tried to store more property keys than allowed557		PropertyLimitReached,558559		/// Property key is too long560		PropertyKeyIsTooLong,561562		/// Only ASCII letters, digits, and symbols `_`, `-`, and `.` are allowed563		InvalidCharacterInPropertyKey,564565		/// Empty property keys are forbidden566		EmptyPropertyKey,567568		/// Tried to access an external collection with an internal API569		CollectionIsExternal,570571		/// Tried to access an internal collection with an external API572		CollectionIsInternal,573	}574575	/// Storage of the count of created collections. Essentially contains the last collection ID.576	#[pallet::storage]577	pub type CreatedCollectionCount<T> = StorageValue<Value = CollectionId, QueryKind = ValueQuery>;578579	/// Storage of the count of deleted collections.580	#[pallet::storage]581	pub type DestroyedCollectionCount<T> =582		StorageValue<Value = CollectionId, QueryKind = ValueQuery>;583584	/// Storage of collection info.585	#[pallet::storage]586	pub type CollectionById<T> = StorageMap<587		Hasher = Blake2_128Concat,588		Key = CollectionId,589		Value = Collection<<T as frame_system::Config>::AccountId>,590		QueryKind = OptionQuery,591	>;592593	/// Storage of collection properties.594	#[pallet::storage]595	#[pallet::getter(fn collection_properties)]596	pub type CollectionProperties<T> = StorageMap<597		Hasher = Blake2_128Concat,598		Key = CollectionId,599		Value = Properties,600		QueryKind = ValueQuery,601		OnEmpty = up_data_structs::CollectionProperties,602	>;603604	/// Storage of token property permissions of a collection.605	#[pallet::storage]606	#[pallet::getter(fn property_permissions)]607	pub type CollectionPropertyPermissions<T> = StorageMap<608		Hasher = Blake2_128Concat,609		Key = CollectionId,610		Value = PropertiesPermissionMap,611		QueryKind = ValueQuery,612	>;613614	/// Storage of the amount of collection admins.615	#[pallet::storage]616	pub type AdminAmount<T> = StorageMap<617		Hasher = Blake2_128Concat,618		Key = CollectionId,619		Value = u32,620		QueryKind = ValueQuery,621	>;622623	/// List of collection admins.624	#[pallet::storage]625	pub type IsAdmin<T: Config> = StorageNMap<626		Key = (627			Key<Blake2_128Concat, CollectionId>,628			Key<Blake2_128Concat, T::CrossAccountId>,629		),630		Value = bool,631		QueryKind = ValueQuery,632	>;633634	/// Allowlisted collection users.635	#[pallet::storage]636	pub type Allowlist<T: Config> = StorageNMap<637		Key = (638			Key<Blake2_128Concat, CollectionId>,639			Key<Blake2_128Concat, T::CrossAccountId>,640		),641		Value = bool,642		QueryKind = ValueQuery,643	>;644645	/// Not used by code, exists only to provide some types to metadata.646	#[pallet::storage]647	pub type DummyStorageValue<T: Config> = StorageValue<648		Value = (649			CollectionStats,650			CollectionId,651			TokenId,652			TokenChild,653			PhantomType<(654				TokenData<T::CrossAccountId>,655				RpcCollection<T::AccountId>,656				// RMRK657				RmrkCollectionInfo<T::AccountId>,658				RmrkInstanceInfo<T::AccountId>,659				RmrkResourceInfo,660				RmrkPropertyInfo,661				RmrkBaseInfo<T::AccountId>,662				RmrkPartType,663				RmrkBoundedTheme,664				RmrkNftChild,665			)>,666		),667		QueryKind = OptionQuery,668	>;669670	#[pallet::hooks]671	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {672		fn on_runtime_upgrade() -> Weight {673			StorageVersion::new(1).put::<Pallet<T>>();674675			0676		}677	}678}679680impl<T: Config> Pallet<T> {681	/// Enshure that receiver address is correct.682	///683	/// Ethereum receiver 0x0000000000000000000000000000000000000000 is reserved, and shouldn't own tokens.684	pub fn ensure_correct_receiver(receiver: &T::CrossAccountId) -> DispatchResult {685		ensure!(686			&T::CrossAccountId::from_eth(H160([0; 20])) != receiver,687			<Error<T>>::AddressIsZero688		);689		Ok(())690	}691692	/// Get a vector of collection admins.693	pub fn adminlist(collection: CollectionId) -> Vec<T::CrossAccountId> {694		<IsAdmin<T>>::iter_prefix((collection,))695			.map(|(a, _)| a)696			.collect()697	}698699	/// Get a vector of users allowed to mint tokens.700	pub fn allowlist(collection: CollectionId) -> Vec<T::CrossAccountId> {701		<Allowlist<T>>::iter_prefix((collection,))702			.map(|(a, _)| a)703			.collect()704	}705706	/// Is `user` allowed to mint token in `collection`.707	pub fn allowed(collection: CollectionId, user: T::CrossAccountId) -> bool {708		<Allowlist<T>>::get((collection, user))709	}710711	/// Get statistics of collections.712	pub fn collection_stats() -> CollectionStats {713		let created = <CreatedCollectionCount<T>>::get();714		let destroyed = <DestroyedCollectionCount<T>>::get();715		CollectionStats {716			created: created.0,717			destroyed: destroyed.0,718			alive: created.0 - destroyed.0,719		}720	}721722	/// Get the effective limits for the collection.723	pub fn effective_collection_limits(collection: CollectionId) -> Option<CollectionLimits> {724		let collection = <CollectionById<T>>::get(collection);725		if collection.is_none() {726			return None;727		}728729		let collection = collection.unwrap();730		let limits = collection.limits;731		let effective_limits = CollectionLimits {732			account_token_ownership_limit: Some(limits.account_token_ownership_limit()),733			sponsored_data_size: Some(limits.sponsored_data_size()),734			sponsored_data_rate_limit: Some(735				limits736					.sponsored_data_rate_limit737					.unwrap_or(SponsoringRateLimit::SponsoringDisabled),738			),739			token_limit: Some(limits.token_limit()),740			sponsor_transfer_timeout: Some(limits.sponsor_transfer_timeout(741				match collection.mode {742					CollectionMode::NFT => NFT_SPONSOR_TRANSFER_TIMEOUT,743					CollectionMode::Fungible(_) => FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,744					CollectionMode::ReFungible => REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,745				},746			)),747			sponsor_approve_timeout: Some(limits.sponsor_approve_timeout()),748			owner_can_transfer: Some(limits.owner_can_transfer()),749			owner_can_destroy: Some(limits.owner_can_destroy()),750			transfers_enabled: Some(limits.transfers_enabled()),751		};752753		Some(effective_limits)754	}755756	/// Returns information about the `collection` adapted for rpc.757	pub fn rpc_collection(collection: CollectionId) -> Option<RpcCollection<T::AccountId>> {758		let Collection {759			name,760			description,761			owner,762			mode,763			token_prefix,764			sponsorship,765			limits,766			permissions,767			external_collection,768		} = <CollectionById<T>>::get(collection)?;769770		let token_property_permissions = <CollectionPropertyPermissions<T>>::get(collection)771			.into_iter()772			.map(|(key, permission)| PropertyKeyPermission { key, permission })773			.collect();774775		let properties = <CollectionProperties<T>>::get(collection)776			.into_iter()777			.map(|(key, value)| Property { key, value })778			.collect();779780		let permissions = CollectionPermissions {781			access: Some(permissions.access()),782			mint_mode: Some(permissions.mint_mode()),783			nesting: Some(permissions.nesting().clone()),784		};785786		Some(RpcCollection {787			name: name.into_inner(),788			description: description.into_inner(),789			owner,790			mode,791			token_prefix: token_prefix.into_inner(),792			sponsorship,793			limits,794			permissions,795			token_property_permissions,796			properties,797			read_only: external_collection,798		})799	}800}801802macro_rules! limit_default {803	($old:ident, $new:ident, $($field:ident $(($arg:expr))? => $check:expr),* $(,)?) => {{804		$(805			if let Some($new) = $new.$field {806				let $old = $old.$field($($arg)?);807				let _ = $new;808				let _ = $old;809				$check810			} else {811				$new.$field = $old.$field812			}813		)*814	}};815}816macro_rules! limit_default_clone {817	($old:ident, $new:ident, $($field:ident $(($arg:expr))? => $check:expr),* $(,)?) => {{818		$(819			if let Some($new) = $new.$field.clone() {820				let $old = $old.$field($($arg)?);821				let _ = $new;822				let _ = $old;823				$check824			} else {825				$new.$field = $old.$field.clone()826			}827		)*828	}};829}830831impl<T: Config> Pallet<T> {832	/// Create new collection.833	///834	/// * `owner` - The owner of the collection.835	/// * `data` - Description of the created collection.836	/// * `is_external` - Marks that collection managet by not "Unique network".837	pub fn init_collection(838		owner: T::CrossAccountId,839		data: CreateCollectionData<T::AccountId>,840		is_external: bool,841	) -> Result<CollectionId, DispatchError> {842		{843			ensure!(844				data.token_prefix.len() <= MAX_TOKEN_PREFIX_LENGTH as usize,845				Error::<T>::CollectionTokenPrefixLimitExceeded846			);847		}848849		let created_count = <CreatedCollectionCount<T>>::get()850			.0851			.checked_add(1)852			.ok_or(ArithmeticError::Overflow)?;853		let destroyed_count = <DestroyedCollectionCount<T>>::get().0;854		let id = CollectionId(created_count);855856		// bound Total number of collections857		ensure!(858			created_count - destroyed_count <= COLLECTION_NUMBER_LIMIT,859			<Error<T>>::TotalCollectionsLimitExceeded860		);861862		// =========863864		let collection = Collection {865			owner: owner.as_sub().clone(),866			name: data.name,867			mode: data.mode.clone(),868			description: data.description,869			token_prefix: data.token_prefix,870			sponsorship: data871				.pending_sponsor872				.map(SponsorshipState::Unconfirmed)873				.unwrap_or_default(),874			limits: data875				.limits876				.map(|limits| Self::clamp_limits(data.mode.clone(), &Default::default(), limits))877				.unwrap_or_else(|| Ok(CollectionLimits::default()))?,878			permissions: data879				.permissions880				.map(|permissions| {881					Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions)882				})883				.unwrap_or_else(|| Ok(CollectionPermissions::default()))?,884			external_collection: is_external,885		};886887		let mut collection_properties = up_data_structs::CollectionProperties::get();888		collection_properties889			.try_set_from_iter(data.properties.into_iter())890			.map_err(<Error<T>>::from)?;891892		CollectionProperties::<T>::insert(id, collection_properties);893894		let mut token_props_permissions = PropertiesPermissionMap::new();895		token_props_permissions896			.try_set_from_iter(data.token_property_permissions.into_iter())897			.map_err(<Error<T>>::from)?;898899		CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);900901		// Take a (non-refundable) deposit of collection creation902		{903			let mut imbalance =904				<<<T as Config>::Currency as Currency<T::AccountId>>::PositiveImbalance>::zero();905			imbalance.subsume(906				<<T as Config>::Currency as Currency<T::AccountId>>::deposit_creating(907					&T::TreasuryAccountId::get(),908					T::CollectionCreationPrice::get(),909				),910			);911			<T as Config>::Currency::settle(912				owner.as_sub(),913				imbalance,914				WithdrawReasons::TRANSFER,915				ExistenceRequirement::KeepAlive,916			)917			.map_err(|_| Error::<T>::NotSufficientFounds)?;918		}919920		<CreatedCollectionCount<T>>::put(created_count);921		<Pallet<T>>::deposit_event(Event::CollectionCreated(922			id,923			data.mode.id(),924			owner.as_sub().clone(),925		));926		<PalletEvm<T>>::deposit_log(927			erc::CollectionHelpersEvents::CollectionCreated {928				owner: *owner.as_eth(),929				collection_id: eth::collection_id_to_address(id),930			}931			.to_log(T::ContractAddress::get()),932		);933		<CollectionById<T>>::insert(id, collection);934		Ok(id)935	}936937	/// Destroy collection.938	///939	/// * `collection` - Collection handler.940	/// * `sender` - The owner or administrator of the collection.941	pub fn destroy_collection(942		collection: CollectionHandle<T>,943		sender: &T::CrossAccountId,944	) -> DispatchResult {945		ensure!(946			collection.limits.owner_can_destroy(),947			<Error<T>>::NoPermission,948		);949		collection.check_is_owner(sender)?;950951		let destroyed_collections = <DestroyedCollectionCount<T>>::get()952			.0953			.checked_add(1)954			.ok_or(ArithmeticError::Overflow)?;955956		// =========957958		<DestroyedCollectionCount<T>>::put(destroyed_collections);959		<CollectionById<T>>::remove(collection.id);960		<AdminAmount<T>>::remove(collection.id);961		let _ = <IsAdmin<T>>::clear_prefix((collection.id,), u32::MAX, None);962		let _ = <Allowlist<T>>::clear_prefix((collection.id,), u32::MAX, None);963		<CollectionProperties<T>>::remove(collection.id);964965		<Pallet<T>>::deposit_event(Event::CollectionDestroyed(collection.id));966		Ok(())967	}968969	/// Set collection property.970	///971	/// * `collection` - Collection handler.972	/// * `sender` - The owner or administrator of the collection.973	/// * `property` - The property to set.974	pub fn set_collection_property(975		collection: &CollectionHandle<T>,976		sender: &T::CrossAccountId,977		property: Property,978	) -> DispatchResult {979		collection.check_is_owner_or_admin(sender)?;980981		CollectionProperties::<T>::try_mutate(collection.id, |properties| {982			let property = property.clone();983			properties.try_set(property.key, property.value)984		})985		.map_err(<Error<T>>::from)?;986987		Self::deposit_event(Event::CollectionPropertySet(collection.id, property.key));988989		Ok(())990	}991992	/// Set scouped collection property.993	///994	/// * `collection_id` - ID of the collection for which the property is being set.995	/// * `scope` - Property scope.996	/// * `property` - The property to set.997	pub fn set_scoped_collection_property(998		collection_id: CollectionId,999		scope: PropertyScope,1000		property: Property,1001	) -> DispatchResult {1002		CollectionProperties::<T>::try_mutate(collection_id, |properties| {1003			properties.try_scoped_set(scope, property.key, property.value)1004		})1005		.map_err(<Error<T>>::from)?;10061007		Ok(())1008	}10091010	/// Set scouped collection properties.1011	///1012	/// * `collection_id` - ID of the collection for which the properties is being set.1013	/// * `scope` - Property scope.1014	/// * `properties` - The properties to set.1015	pub fn set_scoped_collection_properties(1016		collection_id: CollectionId,1017		scope: PropertyScope,1018		properties: impl Iterator<Item = Property>,1019	) -> DispatchResult {1020		CollectionProperties::<T>::try_mutate(collection_id, |stored_properties| {1021			stored_properties.try_scoped_set_from_iter(scope, properties)1022		})1023		.map_err(<Error<T>>::from)?;10241025		Ok(())1026	}10271028	/// Set collection properties.1029	///1030	/// * `collection` - Collection handler.1031	/// * `sender` - The owner or administrator of the collection.1032	/// * `properties` - The properties to set.1033	#[transactional]1034	pub fn set_collection_properties(1035		collection: &CollectionHandle<T>,1036		sender: &T::CrossAccountId,1037		properties: Vec<Property>,1038	) -> DispatchResult {1039		for property in properties {1040			Self::set_collection_property(collection, sender, property)?;1041		}10421043		Ok(())1044	}10451046	/// Delete collection property.1047	///1048	/// * `collection` - Collection handler.1049	/// * `sender` - The owner or administrator of the collection.1050	/// * `property` - The property to delete.1051	pub fn delete_collection_property(1052		collection: &CollectionHandle<T>,1053		sender: &T::CrossAccountId,1054		property_key: PropertyKey,1055	) -> DispatchResult {1056		collection.check_is_owner_or_admin(sender)?;10571058		CollectionProperties::<T>::try_mutate(collection.id, |properties| {1059			properties.remove(&property_key)1060		})1061		.map_err(<Error<T>>::from)?;10621063		Self::deposit_event(Event::CollectionPropertyDeleted(1064			collection.id,1065			property_key,1066		));10671068		Ok(())1069	}10701071	/// Delete collection properties.1072	///1073	/// * `collection` - Collection handler.1074	/// * `sender` - The owner or administrator of the collection.1075	/// * `properties` - The properties to delete.1076	#[transactional]1077	pub fn delete_collection_properties(1078		collection: &CollectionHandle<T>,1079		sender: &T::CrossAccountId,1080		property_keys: Vec<PropertyKey>,1081	) -> DispatchResult {1082		for key in property_keys {1083			Self::delete_collection_property(collection, sender, key)?;1084		}10851086		Ok(())1087	}10881089	/// Set collection propetry permission without any checks.1090	///1091	/// Used for migrations.1092	///1093	/// * `collection` - Collection handler.1094	/// * `property_permissions` - Property permissions.1095	pub fn set_property_permission_unchecked(1096		collection: CollectionId,1097		property_permission: PropertyKeyPermission,1098	) -> DispatchResult {1099		<CollectionPropertyPermissions<T>>::try_mutate(collection, |permissions| {1100			permissions.try_set(property_permission.key, property_permission.permission)1101		})1102		.map_err(<Error<T>>::from)?;1103		Ok(())1104	}11051106	/// Set collection property permission.1107	///1108	/// * `collection` - Collection handler.1109	/// * `sender` - The owner or administrator of the collection.1110	/// * `property_permission` - Property permission.1111	pub fn set_property_permission(1112		collection: &CollectionHandle<T>,1113		sender: &T::CrossAccountId,1114		property_permission: PropertyKeyPermission,1115	) -> DispatchResult {1116		Self::set_scoped_property_permission(1117			collection,1118			sender,1119			PropertyScope::None,1120			property_permission,1121		)1122	}11231124	/// Set collection property permission with scope.1125	///1126	/// * `collection` - Collection handler.1127	/// * `sender` - The owner or administrator of the collection.1128	/// * `scope` - Property scope.1129	/// * `property_permission` - Property permission.1130	pub fn set_scoped_property_permission(1131		collection: &CollectionHandle<T>,1132		sender: &T::CrossAccountId,1133		scope: PropertyScope,1134		property_permission: PropertyKeyPermission,1135	) -> DispatchResult {1136		collection.check_is_owner_or_admin(sender)?;11371138		let all_permissions = CollectionPropertyPermissions::<T>::get(collection.id);1139		let current_permission = all_permissions.get(&property_permission.key);1140		if matches![1141			current_permission,1142			Some(PropertyPermission { mutable: false, .. })1143		] {1144			return Err(<Error<T>>::NoPermission.into());1145		}11461147		CollectionPropertyPermissions::<T>::try_mutate(collection.id, |permissions| {1148			let property_permission = property_permission.clone();1149			permissions.try_scoped_set(1150				scope,1151				property_permission.key,1152				property_permission.permission,1153			)1154		})1155		.map_err(<Error<T>>::from)?;11561157		Self::deposit_event(Event::PropertyPermissionSet(1158			collection.id,1159			property_permission.key,1160		));11611162		Ok(())1163	}11641165	/// Set token property permission.1166	///1167	/// * `collection` - Collection handler.1168	/// * `sender` - The owner or administrator of the collection.1169	/// * `property_permissions` - Property permissions.1170	#[transactional]1171	pub fn set_token_property_permissions(1172		collection: &CollectionHandle<T>,1173		sender: &T::CrossAccountId,1174		property_permissions: Vec<PropertyKeyPermission>,1175	) -> DispatchResult {1176		Self::set_scoped_token_property_permissions(1177			collection,1178			sender,1179			PropertyScope::None,1180			property_permissions,1181		)1182	}11831184	/// Set token property permission with scope.1185	///1186	/// * `collection` - Collection handler.1187	/// * `sender` - The owner or administrator of the collection.1188	/// * `scope` - Property scope.1189	/// * `property_permissions` - Property permissions.1190	#[transactional]1191	pub fn set_scoped_token_property_permissions(1192		collection: &CollectionHandle<T>,1193		sender: &T::CrossAccountId,1194		scope: PropertyScope,1195		property_permissions: Vec<PropertyKeyPermission>,1196	) -> DispatchResult {1197		for prop_pemission in property_permissions {1198			Self::set_scoped_property_permission(collection, sender, scope, prop_pemission)?;1199		}12001201		Ok(())1202	}12031204	/// Get collection property.1205	pub fn get_collection_property(1206		collection_id: CollectionId,1207		key: &PropertyKey,1208	) -> Option<PropertyValue> {1209		Self::collection_properties(collection_id).get(key).cloned()1210	}12111212	/// Convert byte vector to property key vector.1213	pub fn bytes_keys_to_property_keys(1214		keys: Vec<Vec<u8>>,1215	) -> Result<Vec<PropertyKey>, DispatchError> {1216		keys.into_iter()1217			.map(|key| -> Result<PropertyKey, DispatchError> {1218				key.try_into()1219					.map_err(|_| <Error<T>>::PropertyKeyIsTooLong.into())1220			})1221			.collect::<Result<Vec<PropertyKey>, DispatchError>>()1222	}12231224	/// Get properties according to given keys.1225	pub fn filter_collection_properties(1226		collection_id: CollectionId,1227		keys: Option<Vec<PropertyKey>>,1228	) -> Result<Vec<Property>, DispatchError> {1229		let properties = Self::collection_properties(collection_id);12301231		let properties = keys1232			.map(|keys| {1233				keys.into_iter()1234					.filter_map(|key| {1235						properties.get(&key).map(|value| Property {1236							key,1237							value: value.clone(),1238						})1239					})1240					.collect()1241			})1242			.unwrap_or_else(|| {1243				properties1244					.into_iter()1245					.map(|(key, value)| Property { key, value })1246					.collect()1247			});12481249		Ok(properties)1250	}12511252	/// Get property permissions according to given keys.1253	pub fn filter_property_permissions(1254		collection_id: CollectionId,1255		keys: Option<Vec<PropertyKey>>,1256	) -> Result<Vec<PropertyKeyPermission>, DispatchError> {1257		let permissions = Self::property_permissions(collection_id);12581259		let key_permissions = keys1260			.map(|keys| {1261				keys.into_iter()1262					.filter_map(|key| {1263						permissions1264							.get(&key)1265							.map(|permission| PropertyKeyPermission {1266								key,1267								permission: permission.clone(),1268							})1269					})1270					.collect()1271			})1272			.unwrap_or_else(|| {1273				permissions1274					.into_iter()1275					.map(|(key, permission)| PropertyKeyPermission { key, permission })1276					.collect()1277			});12781279		Ok(key_permissions)1280	}12811282	/// Toggle `user` participation in the `collection`'s allow list.1283	pub fn toggle_allowlist(1284		collection: &CollectionHandle<T>,1285		sender: &T::CrossAccountId,1286		user: &T::CrossAccountId,1287		allowed: bool,1288	) -> DispatchResult {1289		collection.check_is_owner_or_admin(sender)?;12901291		// =========12921293		if allowed {1294			<Allowlist<T>>::insert((collection.id, user), true);1295		} else {1296			<Allowlist<T>>::remove((collection.id, user));1297		}12981299		Ok(())1300	}13011302	/// Toggle `user` participation in the `collection`'s admin list.1303	pub fn toggle_admin(1304		collection: &CollectionHandle<T>,1305		sender: &T::CrossAccountId,1306		user: &T::CrossAccountId,1307		admin: bool,1308	) -> DispatchResult {1309		collection.check_is_owner(sender)?;13101311		let was_admin = <IsAdmin<T>>::get((collection.id, user));1312		if was_admin == admin {1313			return Ok(());1314		}1315		let amount = <AdminAmount<T>>::get(collection.id);13161317		if admin {1318			let amount = amount1319				.checked_add(1)1320				.ok_or(<Error<T>>::CollectionAdminCountExceeded)?;1321			ensure!(1322				amount <= Self::collection_admins_limit(),1323				<Error<T>>::CollectionAdminCountExceeded,1324			);13251326			// =========13271328			<AdminAmount<T>>::insert(collection.id, amount);1329			<IsAdmin<T>>::insert((collection.id, user), true);1330		} else {1331			<AdminAmount<T>>::insert(collection.id, amount.saturating_sub(1));1332			<IsAdmin<T>>::remove((collection.id, user));1333		}13341335		Ok(())1336	}13371338	/// Merge set fields from `new_limit` to `old_limit`.1339	pub fn clamp_limits(1340		mode: CollectionMode,1341		old_limit: &CollectionLimits,1342		mut new_limit: CollectionLimits,1343	) -> Result<CollectionLimits, DispatchError> {1344		let limits = old_limit;1345		limit_default!(old_limit, new_limit,1346			account_token_ownership_limit => ensure!(1347				new_limit <= MAX_TOKEN_OWNERSHIP,1348				<Error<T>>::CollectionLimitBoundsExceeded,1349			),1350			sponsored_data_size => ensure!(1351				new_limit <= CUSTOM_DATA_LIMIT,1352				<Error<T>>::CollectionLimitBoundsExceeded,1353			),13541355			sponsored_data_rate_limit => {},1356			token_limit => ensure!(1357				old_limit >= new_limit && new_limit > 0,1358				<Error<T>>::CollectionTokenLimitExceeded1359			),13601361			sponsor_transfer_timeout(match mode {1362				CollectionMode::NFT => NFT_SPONSOR_TRANSFER_TIMEOUT,1363				CollectionMode::Fungible(_) => FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,1364				CollectionMode::ReFungible => REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,1365			}) => ensure!(1366				new_limit <= MAX_SPONSOR_TIMEOUT,1367				<Error<T>>::CollectionLimitBoundsExceeded,1368			),1369			sponsor_approve_timeout => {},1370			owner_can_transfer => ensure!(1371				!limits.owner_can_transfer_instaled() ||1372				old_limit || !new_limit,1373				<Error<T>>::OwnerPermissionsCantBeReverted,1374			),1375			owner_can_destroy => ensure!(1376				old_limit || !new_limit,1377				<Error<T>>::OwnerPermissionsCantBeReverted,1378			),1379			transfers_enabled => {},1380		);1381		Ok(new_limit)1382	}13831384	/// Merge set fields from `new_permission` to `old_permission`.1385	pub fn clamp_permissions(1386		_mode: CollectionMode,1387		old_permission: &CollectionPermissions,1388		mut new_permission: CollectionPermissions,1389	) -> Result<CollectionPermissions, DispatchError> {1390		limit_default_clone!(old_permission, new_permission,1391			access => {},1392			mint_mode => {},1393			nesting => { /* todo check for permissive, if only it gets out of benchmarks */ },1394		);1395		Ok(new_permission)1396	}1397}13981399/// Indicates unsupported methods by returning [Error::UnsupportedOperation].1400#[macro_export]1401macro_rules! unsupported {1402	($runtime:path) => {1403		Err($crate::Error::<$runtime>::UnsupportedOperation.into())1404	};1405}14061407/// Return weights for various worst-case operations.1408pub trait CommonWeightInfo<CrossAccountId> {1409	/// Weight of item creation.1410	fn create_item() -> Weight;14111412	/// Weight of items creation.1413	fn create_multiple_items(amount: &[CreateItemData]) -> Weight;14141415	/// Weight of items creation.1416	fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;14171418	/// The weight of the burning item.1419	fn burn_item() -> Weight;14201421	/// Property setting weight.1422	///1423	/// * `amount`- The number of properties to set.1424	fn set_collection_properties(amount: u32) -> Weight;14251426	/// Collection property deletion weight.1427	///1428	/// * `amount`- The number of properties to set.1429	fn delete_collection_properties(amount: u32) -> Weight;14301431	/// Token property setting weight.1432	///1433	/// * `amount`- The number of properties to set.1434	fn set_token_properties(amount: u32) -> Weight;14351436	/// Token property deletion weight.1437	///1438	/// * `amount`- The number of properties to delete.1439	fn delete_token_properties(amount: u32) -> Weight;14401441	/// Token property permissions set weight.1442	///1443	/// * `amount`- The number of property permissions to set.1444	fn set_token_property_permissions(amount: u32) -> Weight;14451446	/// Transfer price of the token or its parts.1447	fn transfer() -> Weight;14481449	/// The price of setting the permission of the operation from another user.1450	fn approve() -> Weight;14511452	/// Transfer price from another user.1453	fn transfer_from() -> Weight;14541455	/// The price of burning a token from another user.1456	fn burn_from() -> Weight;14571458	/// Differs from burn_item in case of Fungible and Refungible, as it should burn1459	/// whole users's balance.1460	///1461	/// This method shouldn't be used directly, as it doesn't count breadth price, use [burn_recursively](CommonWeightInfo::burn_recursively) instead1462	fn burn_recursively_self_raw() -> Weight;14631464	/// Cost of iterating over `amount` children while burning, without counting child burning itself.1465	///1466	/// This method shouldn't be used directly, as it doesn't count depth price, use [burn_recursively](CommonWeightInfo::burn_recursively) instead1467	fn burn_recursively_breadth_raw(amount: u32) -> Weight;14681469	/// The price of recursive burning a token.1470	///1471	/// `max_selfs` - The maximum burning weight of the token itself.1472	/// `max_breadth` - The maximum number of nested tokens to burn.1473	fn burn_recursively(max_selfs: u32, max_breadth: u32) -> Weight {1474		Self::burn_recursively_self_raw()1475			.saturating_mul(max_selfs.max(1) as u64)1476			.saturating_add(Self::burn_recursively_breadth_raw(max_breadth))1477	}14781479	/// The price of retrieving token owner1480	fn token_owner() -> Weight;1481}14821483/// Weight info extension trait for refungible pallet.1484pub trait RefungibleExtensionsWeightInfo {1485	/// Weight of token repartition.1486	fn repartition() -> Weight;1487}14881489/// Common collection operations.1490///1491/// It wraps methods in Fungible, Nonfungible and Refungible pallets1492/// and adds weight info.1493pub trait CommonCollectionOperations<T: Config> {1494	/// Create token.1495	///1496	/// * `sender` - The user who mint the token and pays for the transaction.1497	/// * `to` - The user who will own the token.1498	/// * `data` - Token data.1499	/// * `nesting_budget` - A budget that can be spent on nesting tokens.1500	fn create_item(1501		&self,1502		sender: T::CrossAccountId,1503		to: T::CrossAccountId,1504		data: CreateItemData,1505		nesting_budget: &dyn Budget,1506	) -> DispatchResultWithPostInfo;15071508	/// Create multiple tokens.1509	///1510	/// * `sender` - The user who mint the token and pays for the transaction.1511	/// * `to` - The user who will own the token.1512	/// * `data` - Token data.1513	/// * `nesting_budget` - A budget that can be spent on nesting tokens.1514	fn create_multiple_items(1515		&self,1516		sender: T::CrossAccountId,1517		to: T::CrossAccountId,1518		data: Vec<CreateItemData>,1519		nesting_budget: &dyn Budget,1520	) -> DispatchResultWithPostInfo;15211522	/// Create multiple tokens.1523	///1524	/// * `sender` - The user who mint the token and pays for the transaction.1525	/// * `to` - The user who will own the token.1526	/// * `data` - Token data.1527	/// * `nesting_budget` - A budget that can be spent on nesting tokens.1528	fn create_multiple_items_ex(1529		&self,1530		sender: T::CrossAccountId,1531		data: CreateItemExData<T::CrossAccountId>,1532		nesting_budget: &dyn Budget,1533	) -> DispatchResultWithPostInfo;15341535	/// Burn token.1536	///1537	/// * `sender` - The user who owns the token.1538	/// * `token` - Token id that will burned.1539	/// * `amount` - The number of parts of the token that will be burned.1540	fn burn_item(1541		&self,1542		sender: T::CrossAccountId,1543		token: TokenId,1544		amount: u128,1545	) -> DispatchResultWithPostInfo;15461547	/// Burn token and all nested tokens recursievly.1548	///1549	/// * `sender` - The user who owns the token.1550	/// * `token` - Token id that will burned.1551	/// * `self_budget` - The budget that can be spent on burning tokens.1552	/// * `breadth_budget` - The budget that can be spent on burning nested tokens.1553	fn burn_item_recursively(1554		&self,1555		sender: T::CrossAccountId,1556		token: TokenId,1557		self_budget: &dyn Budget,1558		breadth_budget: &dyn Budget,1559	) -> DispatchResultWithPostInfo;15601561	/// Set collection properties.1562	///1563	/// * `sender` - Must be either the owner of the collection or its admin.1564	/// * `properties` - Properties to be set.1565	fn set_collection_properties(1566		&self,1567		sender: T::CrossAccountId,1568		properties: Vec<Property>,1569	) -> DispatchResultWithPostInfo;15701571	/// Delete collection properties.1572	///1573	/// * `sender` - Must be either the owner of the collection or its admin.1574	/// * `properties` - The properties to be removed.1575	fn delete_collection_properties(1576		&self,1577		sender: &T::CrossAccountId,1578		property_keys: Vec<PropertyKey>,1579	) -> DispatchResultWithPostInfo;15801581	/// Set token properties.1582	///1583	/// The appropriate [`PropertyPermission`] for the token property1584	/// must be set with [`Self::set_token_property_permissions`].1585	///1586	/// * `sender` - Must be either the owner of the token or its admin.1587	/// * `token_id` - The token for which the properties are being set.1588	/// * `properties` - Properties to be set.1589	/// * `budget` - Budget for setting properties.1590	fn set_token_properties(1591		&self,1592		sender: T::CrossAccountId,1593		token_id: TokenId,1594		properties: Vec<Property>,1595		budget: &dyn Budget,1596	) -> DispatchResultWithPostInfo;15971598	/// Remove token properties.1599	///1600	/// The appropriate [`PropertyPermission`] for the token property1601	/// must be set with [`Self::set_token_property_permissions`].1602	///1603	/// * `sender` - Must be either the owner of the token or its admin.1604	/// * `token_id` - The token for which the properties are being remove.1605	/// * `property_keys` - Keys to remove corresponding properties.1606	/// * `budget` - Budget for removing properties.1607	fn delete_token_properties(1608		&self,1609		sender: T::CrossAccountId,1610		token_id: TokenId,1611		property_keys: Vec<PropertyKey>,1612		budget: &dyn Budget,1613	) -> DispatchResultWithPostInfo;16141615	/// Set token property permissions.1616	///1617	/// * `sender` - Must be either the owner of the token or its admin.1618	/// * `token_id` - The token for which the properties are being set.1619	/// * `property_permissions` - Property permissions to be set.1620	/// * `budget` - Budget for setting properties.1621	fn set_token_property_permissions(1622		&self,1623		sender: &T::CrossAccountId,1624		property_permissions: Vec<PropertyKeyPermission>,1625	) -> DispatchResultWithPostInfo;16261627	/// Transfer amount of token pieces.1628	///1629	/// * `sender` - Donor user.1630	/// * `to` - Recepient user.1631	/// * `token` - The token of which parts are being sent.1632	/// * `amount` - The number of parts of the token that will be transferred.1633	/// * `budget` - The maximum budget that can be spent on the transfer.1634	fn transfer(1635		&self,1636		sender: T::CrossAccountId,1637		to: T::CrossAccountId,1638		token: TokenId,1639		amount: u128,1640		budget: &dyn Budget,1641	) -> DispatchResultWithPostInfo;16421643	/// Grant access to another account to transfer parts of the token owned by the calling user via [Self::transfer_from].1644	///1645	/// * `sender` - The user who grants access to the token.1646	/// * `spender` - The user to whom the rights are granted.1647	/// * `token` - The token to which access is granted.1648	/// * `amount` - The amount of pieces that another user can dispose of.1649	fn approve(1650		&self,1651		sender: T::CrossAccountId,1652		spender: T::CrossAccountId,1653		token: TokenId,1654		amount: u128,1655	) -> DispatchResultWithPostInfo;16561657	/// Send parts of a token owned by another user.1658	///1659	/// Before calling this method, you must grant rights to the calling user via [`Self::approve`].1660	///1661	/// * `sender` - The user who must have access to the token (see [`Self::approve`]).1662	/// * `from` - The user who owns the token.1663	/// * `to` - Recepient user.1664	/// * `token` - The token of which parts are being sent.1665	/// * `amount` - The number of parts of the token that will be transferred.1666	/// * `budget` - The maximum budget that can be spent on the transfer.1667	fn transfer_from(1668		&self,1669		sender: T::CrossAccountId,1670		from: T::CrossAccountId,1671		to: T::CrossAccountId,1672		token: TokenId,1673		amount: u128,1674		budget: &dyn Budget,1675	) -> DispatchResultWithPostInfo;16761677	/// Burn parts of a token owned by another user.1678	///1679	/// Before calling this method, you must grant rights to the calling user via [`Self::approve`].1680	///1681	/// * `sender` - The user who must have access to the token (see [`Self::approve`]).1682	/// * `from` - The user who owns the token.1683	/// * `token` - The token of which parts are being sent.1684	/// * `amount` - The number of parts of the token that will be transferred.1685	/// * `budget` - The maximum budget that can be spent on the burn.1686	fn burn_from(1687		&self,1688		sender: T::CrossAccountId,1689		from: T::CrossAccountId,1690		token: TokenId,1691		amount: u128,1692		budget: &dyn Budget,1693	) -> DispatchResultWithPostInfo;16941695	/// Check permission to nest token.1696	///1697	/// * `sender` - The user who initiated the check.1698	/// * `from` - The token that is checked for embedding.1699	/// * `under` - Token under which to check.1700	/// * `budget` - The maximum budget that can be spent on the check.1701	fn check_nesting(1702		&self,1703		sender: T::CrossAccountId,1704		from: (CollectionId, TokenId),1705		under: TokenId,1706		budget: &dyn Budget,1707	) -> DispatchResult;17081709	/// Nest one token into another.1710	///1711	/// * `under` - Token holder.1712	/// * `to_nest` - Nested token.1713	fn nest(&self, under: TokenId, to_nest: (CollectionId, TokenId));17141715	/// Unnest token.1716	///1717	/// * `under` - Token holder.1718	/// * `to_nest` - Token to unnest.1719	fn unnest(&self, under: TokenId, to_nest: (CollectionId, TokenId));17201721	/// Get all user tokens.1722	///1723	/// * `account` - Account for which you need to get tokens.1724	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId>;17251726	/// Get all the tokens in the collection.1727	fn collection_tokens(&self) -> Vec<TokenId>;17281729	/// Check if the token exists.1730	///1731	/// * `token` - Id token to check.1732	fn token_exists(&self, token: TokenId) -> bool;17331734	/// Get the id of the last minted token.1735	fn last_token_id(&self) -> TokenId;17361737	/// Get the owner of the token.1738	///1739	/// * `token` - The token for which you need to find out the owner.1740	fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId>;17411742	/// Returns 10 tokens owners in no particular order.1743	///1744	/// * `token` - The token for which you need to find out the owners.1745	fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId>;17461747	/// Get the value of the token property by key.1748	///1749	/// * `token` - Token with the property to get.1750	/// * `key` - Property name.1751	fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue>;17521753	/// Get a set of token properties by key vector.1754	///1755	/// * `token` - Token with the property to get.1756	/// * `keys` - Vector of property keys. If this parameter is [None](sp_std::result::Result),1757	/// then all properties are returned.1758	fn token_properties(&self, token: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property>;17591760	/// Amount of unique collection tokens1761	fn total_supply(&self) -> u32;17621763	/// Amount of different tokens account has.1764	///1765	/// * `account` - The account for which need to get the balance.1766	fn account_balance(&self, account: T::CrossAccountId) -> u32;17671768	/// Amount of specific token account have.1769	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128;17701771	/// Amount of token pieces1772	fn total_pieces(&self, token: TokenId) -> Option<u128>;17731774	/// Get the number of parts of the token that a trusted user can manage.1775	///1776	/// * `sender` - Trusted user.1777	/// * `spender` - Owner of the token.1778	/// * `token` - The token for which to get the value.1779	fn allowance(1780		&self,1781		sender: T::CrossAccountId,1782		spender: T::CrossAccountId,1783		token: TokenId,1784	) -> u128;17851786	/// Get extension for RFT collection.1787	fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>>;1788}17891790/// Extension for RFT collection.1791pub trait RefungibleExtensions<T>1792where1793	T: Config,1794{1795	/// Change the number of parts of the token.1796	///1797	/// When the value changes down, this function is equivalent to burning parts of the token.1798	///1799	/// * `sender` - The user calling the repartition operation. Must be the owner of the token.1800	/// * `token` - The token for which you want to change the number of parts.1801	/// * `amount` - The new value of the parts of the token.1802	fn repartition(1803		&self,1804		sender: &T::CrossAccountId,1805		token: TokenId,1806		amount: u128,1807	) -> DispatchResultWithPostInfo;1808}18091810/// Merge [`DispatchResult`] with [`Weight`] into [`DispatchResultWithPostInfo`].1811///1812/// Used for [`CommonCollectionOperations`] implementations and flexible enough to do so.1813pub fn with_weight(res: DispatchResult, weight: Weight) -> DispatchResultWithPostInfo {1814	let post_info = PostDispatchInfo {1815		actual_weight: Some(weight),1816		pays_fee: Pays::Yes,1817	};1818	match res {1819		Ok(()) => Ok(post_info),1820		Err(error) => Err(DispatchErrorWithPostInfo { post_info, error }),1821	}1822}18231824impl<T: Config> From<PropertiesError> for Error<T> {1825	fn from(error: PropertiesError) -> Self {1826		match error {1827			PropertiesError::NoSpaceForProperty => Self::NoSpaceForProperty,1828			PropertiesError::PropertyLimitReached => Self::PropertyLimitReached,1829			PropertiesError::InvalidCharacterInPropertyKey => Self::InvalidCharacterInPropertyKey,1830			PropertiesError::PropertyKeyIsTooLong => Self::PropertyKeyIsTooLong,1831			PropertiesError::EmptyPropertyKey => Self::EmptyPropertyKey,1832		}1833	}1834}
after · pallets/common/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//! # Common pallet18//!19//! The Common pallet provides functionality for handling collections.20//!21//! ## Overview22//!23//! The Common pallet provides an interface for common collection operations for different collection types24//! (see [CommonCollectionOperations]), as well as a generic dispatcher for these, see [dispatch] module.25//! It also provides this functionality to EVM, see [erc] and [eth] modules.26//!27//! The Common pallet provides functions for:28//!29//! - Setting and approving collection sponsor.30//! - Get\set\delete allow list.31//! - Get\set\delete collection properties.32//! - Get\set\delete collection property permissions.33//! - Get\set\delete token property permissions.34//! - Get\set\delete collection administrators.35//! - Checking access permissions.36//!37//! ### Terminology38//! **Collection sponsor** - For the collection, you can set a sponsor, at whose expense it will39//! be possible to mint tokens.40//!41//! **Allow list** - List of users who have the right to minting tokens.42//!43//! **Collection properties** - Collection properties are simply key-value stores where various44//! metadata can be placed.45//!46//! **Permissions on token properties** - For each property in the token can be set permission47//! to change, see [`PropertyPermission`].48//!49//! **Collection administrator** - For a collection, you can set administrators who have the right50//! to most actions on the collection.5152#![warn(missing_docs)]53#![cfg_attr(not(feature = "std"), no_std)]54extern crate alloc;5556use core::ops::{Deref, DerefMut};57use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};58use sp_std::vec::Vec;59use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};60use evm_coder::ToLog;61use frame_support::{62	dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Weight, PostDispatchInfo},63	ensure,64	traits::{Imbalance, Get, Currency, WithdrawReasons, ExistenceRequirement},65	weights::Pays,66	transactional,67};68use pallet_evm::GasWeightMapping;69use up_data_structs::{70	COLLECTION_NUMBER_LIMIT,71	Collection,72	RpcCollection,73	CollectionId,74	CreateItemData,75	MAX_TOKEN_PREFIX_LENGTH,76	COLLECTION_ADMINS_LIMIT,77	TokenId,78	TokenChild,79	CollectionStats,80	MAX_TOKEN_OWNERSHIP,81	CollectionMode,82	NFT_SPONSOR_TRANSFER_TIMEOUT,83	FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,84	REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,85	MAX_SPONSOR_TIMEOUT,86	CUSTOM_DATA_LIMIT,87	CollectionLimits,88	CreateCollectionData,89	SponsorshipState,90	CreateItemExData,91	SponsoringRateLimit,92	budget::Budget,93	PhantomType,94	Property,95	Properties,96	PropertiesPermissionMap,97	PropertyKey,98	PropertyValue,99	PropertyPermission,100	PropertiesError,101	PropertyKeyPermission,102	TokenData,103	TrySetProperty,104	PropertyScope,105	// RMRK106	RmrkCollectionInfo,107	RmrkInstanceInfo,108	RmrkResourceInfo,109	RmrkPropertyInfo,110	RmrkBaseInfo,111	RmrkPartType,112	RmrkBoundedTheme,113	RmrkNftChild,114	CollectionPermissions,115	SchemaVersion,116};117118pub use pallet::*;119use sp_core::H160;120use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};121#[cfg(feature = "runtime-benchmarks")]122pub mod benchmarking;123pub mod dispatch;124pub mod erc;125pub mod eth;126pub mod weights;127128/// Weight info.129pub type SelfWeightOf<T> = <T as Config>::WeightInfo;130131/// Collection handle contains information about collection data and id.132/// Also provides functionality to count consumed gas.133///134/// CollectionHandle is used as a generic wrapper for collections of all types.135/// It allows to perform common operations and queries on any collection type,136/// both completely general for all, as well as their respective implementations of [`CommonCollectionOperations`].137#[must_use = "Should call submit_logs or save, otherwise some data will be lost for evm side"]138pub struct CollectionHandle<T: Config> {139	/// Collection id140	pub id: CollectionId,141	collection: Collection<T::AccountId>,142	/// Substrate recorder for counting consumed gas143	pub recorder: SubstrateRecorder<T>,144}145146impl<T: Config> WithRecorder<T> for CollectionHandle<T> {147	fn recorder(&self) -> &SubstrateRecorder<T> {148		&self.recorder149	}150	fn into_recorder(self) -> SubstrateRecorder<T> {151		self.recorder152	}153}154155impl<T: Config> CollectionHandle<T> {156	/// Same as [CollectionHandle::new] but with an explicit gas limit.157	pub fn new_with_gas_limit(id: CollectionId, gas_limit: u64) -> Option<Self> {158		<CollectionById<T>>::get(id).map(|collection| Self {159			id,160			collection,161			recorder: SubstrateRecorder::new(gas_limit),162		})163	}164165	/// Same as [CollectionHandle::new] but with an existed [`SubstrateRecorder`].166	pub fn new_with_recorder(id: CollectionId, recorder: SubstrateRecorder<T>) -> Option<Self> {167		<CollectionById<T>>::get(id).map(|collection| Self {168			id,169			collection,170			recorder,171		})172	}173174	/// Retrives collection data from storage and creates collection handle with default parameters.175	/// If collection not found return `None`176	pub fn new(id: CollectionId) -> Option<Self> {177		Self::new_with_gas_limit(id, u64::MAX)178	}179180	/// Same as [`CollectionHandle::new`] but if collection not found [CollectionNotFound](Error::CollectionNotFound) returned.181	pub fn try_get(id: CollectionId) -> Result<Self, DispatchError> {182		Ok(Self::new(id).ok_or(<Error<T>>::CollectionNotFound)?)183	}184185	/// Consume gas for reading.186	pub fn consume_store_reads(&self, reads: u64) -> evm_coder::execution::Result<()> {187		self.recorder188			.consume_gas(T::GasWeightMapping::weight_to_gas(189				<T as frame_system::Config>::DbWeight::get()190					.read191					.saturating_mul(reads),192			))193	}194195	/// Consume gas for writing.196	pub fn consume_store_writes(&self, writes: u64) -> evm_coder::execution::Result<()> {197		self.recorder198			.consume_gas(T::GasWeightMapping::weight_to_gas(199				<T as frame_system::Config>::DbWeight::get()200					.write201					.saturating_mul(writes),202			))203	}204205	/// Save collection to storage.206	pub fn save(&self) -> DispatchResult {207		<CollectionById<T>>::insert(self.id, self.collection.clone());208		Ok(())209	}210211	/// Set collection sponsor.212	///213	/// Unique collections allows sponsoring for certain actions.214	/// This method allows you to set the sponsor of the collection.215	/// In order for sponsorship to become active, it must be confirmed through [`Self::confirm_sponsorship`].216	pub fn set_sponsor(&mut self, sponsor: T::AccountId) -> DispatchResult {217		self.collection.sponsorship = SponsorshipState::Unconfirmed(sponsor);218		Ok(())219	}220221	/// Confirm sponsorship222	///223	/// In order for the sponsorship to become active, the user set as the sponsor must confirm their participation.224	/// Before confirming sponsorship, the user must be specified as the sponsor of the collection via [`Self::set_sponsor`].225	pub fn confirm_sponsorship(&mut self, sender: &T::AccountId) -> Result<bool, DispatchError> {226		if self.collection.sponsorship.pending_sponsor() != Some(sender) {227			return Ok(false);228		}229230		self.collection.sponsorship = SponsorshipState::Confirmed(sender.clone());231		Ok(true)232	}233234	/// Checks that the collection was created with, and must be operated upon through **Unique API**.235	/// Now check only the `external_collection` flag and if it's **true**, then return [`Error::CollectionIsExternal`] error.236	pub fn check_is_internal(&self) -> DispatchResult {237		if self.external_collection {238			return Err(<Error<T>>::CollectionIsExternal)?;239		}240241		Ok(())242	}243244	/// Checks that the collection was created with, and must be operated upon through an **assimilated API**.245	/// Now check only the `external_collection` flag and if it's **false**, then return [`Error::CollectionIsInternal`] error.246	pub fn check_is_external(&self) -> DispatchResult {247		if !self.external_collection {248			return Err(<Error<T>>::CollectionIsInternal)?;249		}250251		Ok(())252	}253}254255impl<T: Config> Deref for CollectionHandle<T> {256	type Target = Collection<T::AccountId>;257258	fn deref(&self) -> &Self::Target {259		&self.collection260	}261}262263impl<T: Config> DerefMut for CollectionHandle<T> {264	fn deref_mut(&mut self) -> &mut Self::Target {265		&mut self.collection266	}267}268269impl<T: Config> CollectionHandle<T> {270	/// Checks if the `user` is the owner of the collection.271	pub fn check_is_owner(&self, user: &T::CrossAccountId) -> DispatchResult {272		ensure!(*user.as_sub() == self.owner, <Error<T>>::NoPermission);273		Ok(())274	}275276	/// Returns **true** if the `user` is the owner or administrator of the collection.277	pub fn is_owner_or_admin(&self, user: &T::CrossAccountId) -> bool {278		*user.as_sub() == self.owner || <IsAdmin<T>>::get((self.id, user))279	}280281	/// Checks if the `user` is the owner or administrator of the collection.282	pub fn check_is_owner_or_admin(&self, user: &T::CrossAccountId) -> DispatchResult {283		ensure!(self.is_owner_or_admin(user), <Error<T>>::NoPermission);284		Ok(())285	}286287	/// Return **true** if `user` was not allowed to have tokens, and he can ignore such restrictions.288	pub fn ignores_allowance(&self, user: &T::CrossAccountId) -> bool {289		self.limits.owner_can_transfer() && self.is_owner_or_admin(user)290	}291292	/// Return **true** if `user` does not have enough token parts, and he can ignore such restrictions.293	pub fn ignores_owned_amount(&self, user: &T::CrossAccountId) -> bool {294		self.limits.owner_can_transfer() && self.is_owner_or_admin(user)295	}296297	/// Checks if the user is in the allow list. If not [Error::AddressNotInAllowlist] returns.298	pub fn check_allowlist(&self, user: &T::CrossAccountId) -> DispatchResult {299		ensure!(300			<Allowlist<T>>::get((self.id, user)),301			<Error<T>>::AddressNotInAllowlist302		);303		Ok(())304	}305306	/// Changes collection owner to another account307	fn change_owner_internal(308		&mut self,309		caller: T::CrossAccountId,310		new_owner: T::CrossAccountId,311	) -> DispatchResult {312		self.check_is_owner(&caller)?;313		self.collection.owner = new_owner.as_sub().clone();314		self.save()315	}316}317318#[frame_support::pallet]319pub mod pallet {320	use super::*;321	use pallet_evm::account;322	use dispatch::CollectionDispatch;323	use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key, traits::StorageVersion};324	use frame_system::pallet_prelude::*;325	use frame_support::traits::Currency;326	use up_data_structs::{TokenId, mapping::TokenAddressMapping};327	use scale_info::TypeInfo;328	use weights::WeightInfo;329330	#[pallet::config]331	pub trait Config:332		frame_system::Config333		+ pallet_evm_coder_substrate::Config334		+ pallet_evm::Config335		+ TypeInfo336		+ account::Config337	{338		/// Weight information for functions of this pallet.339		type WeightInfo: WeightInfo;340341		/// Events compatible with [`frame_system::Config::Event`].342		type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;343344		/// Handler of accounts and payment.345		type Currency: Currency<Self::AccountId>;346347		/// Set price to create a collection.348		#[pallet::constant]349		type CollectionCreationPrice: Get<350			<<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,351		>;352353		/// Dispatcher of operations on collections.354		type CollectionDispatch: CollectionDispatch<Self>;355356		/// Account which holds the chain's treasury.357		type TreasuryAccountId: Get<Self::AccountId>;358359		/// Address under which the CollectionHelper contract would be available.360		type ContractAddress: Get<H160>;361362		/// Mapper for token addresses to Ethereum addresses.363		type EvmTokenAddressMapping: TokenAddressMapping<H160>;364365		/// Mapper for token addresses to [`CrossAccountId`].366		type CrossTokenAddressMapping: TokenAddressMapping<Self::CrossAccountId>;367	}368369	const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);370371	#[pallet::pallet]372	#[pallet::storage_version(STORAGE_VERSION)]373	#[pallet::generate_store(pub(super) trait Store)]374	pub struct Pallet<T>(_);375376	#[pallet::extra_constants]377	impl<T: Config> Pallet<T> {378		/// Maximum admins per collection.379		pub fn collection_admins_limit() -> u32 {380			COLLECTION_ADMINS_LIMIT381		}382	}383384	#[pallet::event]385	#[pallet::generate_deposit(pub fn deposit_event)]386	pub enum Event<T: Config> {387		/// New collection was created388		CollectionCreated(389			/// Globally unique identifier of newly created collection.390			CollectionId,391			/// [`CollectionMode`] converted into _u8_.392			u8,393			/// Collection owner.394			T::AccountId,395		),396397		/// New collection was destroyed398		CollectionDestroyed(399			/// Globally unique identifier of collection.400			CollectionId,401		),402403		/// New item was created.404		ItemCreated(405			/// Id of the collection where item was created.406			CollectionId,407			/// Id of an item. Unique within the collection.408			TokenId,409			/// Owner of newly created item410			T::CrossAccountId,411			/// Always 1 for NFT412			u128,413		),414415		/// Collection item was burned.416		ItemDestroyed(417			/// Id of the collection where item was destroyed.418			CollectionId,419			/// Identifier of burned NFT.420			TokenId,421			/// Which user has destroyed its tokens.422			T::CrossAccountId,423			/// Amount of token pieces destroed. Always 1 for NFT.424			u128,425		),426427		/// Item was transferred428		Transfer(429			/// Id of collection to which item is belong.430			CollectionId,431			/// Id of an item.432			TokenId,433			/// Original owner of item.434			T::CrossAccountId,435			/// New owner of item.436			T::CrossAccountId,437			/// Amount of token pieces transfered. Always 1 for NFT.438			u128,439		),440441		/// Amount pieces of token owned by `sender` was approved for `spender`.442		Approved(443			/// Id of collection to which item is belong.444			CollectionId,445			/// Id of an item.446			TokenId,447			/// Original owner of item.448			T::CrossAccountId,449			/// Id for which the approval was granted.450			T::CrossAccountId,451			/// Amount of token pieces transfered. Always 1 for NFT.452			u128,453		),454455		/// The colletion property has been added or edited.456		CollectionPropertySet(457			/// Id of collection to which property has been set.458			CollectionId,459			/// The property that was set.460			PropertyKey,461		),462463		/// The property has been deleted.464		CollectionPropertyDeleted(465			/// Id of collection to which property has been deleted.466			CollectionId,467			/// The property that was deleted.468			PropertyKey,469		),470471		/// The token property has been added or edited.472		TokenPropertySet(473			/// Identifier of the collection whose token has the property set.474			CollectionId,475			/// The token for which the property was set.476			TokenId,477			/// The property that was set.478			PropertyKey,479		),480481		/// The token property has been deleted.482		TokenPropertyDeleted(483			/// Identifier of the collection whose token has the property deleted.484			CollectionId,485			/// The token for which the property was deleted.486			TokenId,487			/// The property that was deleted.488			PropertyKey,489		),490491		/// The token property permission of a collection has been set.492		PropertyPermissionSet(493			/// ID of collection to which property permission has been set.494			CollectionId,495			/// The property permission that was set.496			PropertyKey,497		),498	}499500	#[pallet::error]501	pub enum Error<T> {502		/// This collection does not exist.503		CollectionNotFound,504		/// Sender parameter and item owner must be equal.505		MustBeTokenOwner,506		/// No permission to perform action507		NoPermission,508		/// Destroying only empty collections is allowed509		CantDestroyNotEmptyCollection,510		/// Collection is not in mint mode.511		PublicMintingNotAllowed,512		/// Address is not in allow list.513		AddressNotInAllowlist,514515		/// Collection name can not be longer than 63 char.516		CollectionNameLimitExceeded,517		/// Collection description can not be longer than 255 char.518		CollectionDescriptionLimitExceeded,519		/// Token prefix can not be longer than 15 char.520		CollectionTokenPrefixLimitExceeded,521		/// Total collections bound exceeded.522		TotalCollectionsLimitExceeded,523		/// Exceeded max admin count524		CollectionAdminCountExceeded,525		/// Collection limit bounds per collection exceeded526		CollectionLimitBoundsExceeded,527		/// Tried to enable permissions which are only permitted to be disabled528		OwnerPermissionsCantBeReverted,529		/// Collection settings not allowing items transferring530		TransferNotAllowed,531		/// Account token limit exceeded per collection532		AccountTokenLimitExceeded,533		/// Collection token limit exceeded534		CollectionTokenLimitExceeded,535		/// Metadata flag frozen536		MetadataFlagFrozen,537538		/// Item does not exist539		TokenNotFound,540		/// Item is balance not enough541		TokenValueTooLow,542		/// Requested value is more than the approved543		ApprovedValueTooLow,544		/// Tried to approve more than owned545		CantApproveMoreThanOwned,546547		/// Can't transfer tokens to ethereum zero address548		AddressIsZero,549550		/// The operation is not supported551		UnsupportedOperation,552553		/// Insufficient funds to perform an action554		NotSufficientFounds,555556		/// User does not satisfy the nesting rule557		UserIsNotAllowedToNest,558		/// Only tokens from specific collections may nest tokens under this one559		SourceCollectionIsNotAllowedToNest,560561		/// Tried to store more data than allowed in collection field562		CollectionFieldSizeExceeded,563564		/// Tried to store more property data than allowed565		NoSpaceForProperty,566567		/// Tried to store more property keys than allowed568		PropertyLimitReached,569570		/// Property key is too long571		PropertyKeyIsTooLong,572573		/// Only ASCII letters, digits, and symbols `_`, `-`, and `.` are allowed574		InvalidCharacterInPropertyKey,575576		/// Empty property keys are forbidden577		EmptyPropertyKey,578579		/// Tried to access an external collection with an internal API580		CollectionIsExternal,581582		/// Tried to access an internal collection with an external API583		CollectionIsInternal,584	}585586	/// Storage of the count of created collections. Essentially contains the last collection ID.587	#[pallet::storage]588	pub type CreatedCollectionCount<T> = StorageValue<Value = CollectionId, QueryKind = ValueQuery>;589590	/// Storage of the count of deleted collections.591	#[pallet::storage]592	pub type DestroyedCollectionCount<T> =593		StorageValue<Value = CollectionId, QueryKind = ValueQuery>;594595	/// Storage of collection info.596	#[pallet::storage]597	pub type CollectionById<T> = StorageMap<598		Hasher = Blake2_128Concat,599		Key = CollectionId,600		Value = Collection<<T as frame_system::Config>::AccountId>,601		QueryKind = OptionQuery,602	>;603604	/// Storage of collection properties.605	#[pallet::storage]606	#[pallet::getter(fn collection_properties)]607	pub type CollectionProperties<T> = StorageMap<608		Hasher = Blake2_128Concat,609		Key = CollectionId,610		Value = Properties,611		QueryKind = ValueQuery,612		OnEmpty = up_data_structs::CollectionProperties,613	>;614615	/// Storage of token property permissions of a collection.616	#[pallet::storage]617	#[pallet::getter(fn property_permissions)]618	pub type CollectionPropertyPermissions<T> = StorageMap<619		Hasher = Blake2_128Concat,620		Key = CollectionId,621		Value = PropertiesPermissionMap,622		QueryKind = ValueQuery,623	>;624625	/// Storage of the amount of collection admins.626	#[pallet::storage]627	pub type AdminAmount<T> = StorageMap<628		Hasher = Blake2_128Concat,629		Key = CollectionId,630		Value = u32,631		QueryKind = ValueQuery,632	>;633634	/// List of collection admins.635	#[pallet::storage]636	pub type IsAdmin<T: Config> = StorageNMap<637		Key = (638			Key<Blake2_128Concat, CollectionId>,639			Key<Blake2_128Concat, T::CrossAccountId>,640		),641		Value = bool,642		QueryKind = ValueQuery,643	>;644645	/// Allowlisted collection users.646	#[pallet::storage]647	pub type Allowlist<T: Config> = StorageNMap<648		Key = (649			Key<Blake2_128Concat, CollectionId>,650			Key<Blake2_128Concat, T::CrossAccountId>,651		),652		Value = bool,653		QueryKind = ValueQuery,654	>;655656	/// Not used by code, exists only to provide some types to metadata.657	#[pallet::storage]658	pub type DummyStorageValue<T: Config> = StorageValue<659		Value = (660			CollectionStats,661			CollectionId,662			TokenId,663			TokenChild,664			PhantomType<(665				TokenData<T::CrossAccountId>,666				RpcCollection<T::AccountId>,667				// RMRK668				RmrkCollectionInfo<T::AccountId>,669				RmrkInstanceInfo<T::AccountId>,670				RmrkResourceInfo,671				RmrkPropertyInfo,672				RmrkBaseInfo<T::AccountId>,673				RmrkPartType,674				RmrkBoundedTheme,675				RmrkNftChild,676			)>,677		),678		QueryKind = OptionQuery,679	>;680681	#[pallet::hooks]682	impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {683		fn on_runtime_upgrade() -> Weight {684			StorageVersion::new(1).put::<Pallet<T>>();685686			0687		}688	}689}690691impl<T: Config> Pallet<T> {692	/// Enshure that receiver address is correct.693	///694	/// Ethereum receiver 0x0000000000000000000000000000000000000000 is reserved, and shouldn't own tokens.695	pub fn ensure_correct_receiver(receiver: &T::CrossAccountId) -> DispatchResult {696		ensure!(697			&T::CrossAccountId::from_eth(H160([0; 20])) != receiver,698			<Error<T>>::AddressIsZero699		);700		Ok(())701	}702703	/// Get a vector of collection admins.704	pub fn adminlist(collection: CollectionId) -> Vec<T::CrossAccountId> {705		<IsAdmin<T>>::iter_prefix((collection,))706			.map(|(a, _)| a)707			.collect()708	}709710	/// Get a vector of users allowed to mint tokens.711	pub fn allowlist(collection: CollectionId) -> Vec<T::CrossAccountId> {712		<Allowlist<T>>::iter_prefix((collection,))713			.map(|(a, _)| a)714			.collect()715	}716717	/// Is `user` allowed to mint token in `collection`.718	pub fn allowed(collection: CollectionId, user: T::CrossAccountId) -> bool {719		<Allowlist<T>>::get((collection, user))720	}721722	/// Get statistics of collections.723	pub fn collection_stats() -> CollectionStats {724		let created = <CreatedCollectionCount<T>>::get();725		let destroyed = <DestroyedCollectionCount<T>>::get();726		CollectionStats {727			created: created.0,728			destroyed: destroyed.0,729			alive: created.0 - destroyed.0,730		}731	}732733	/// Get the effective limits for the collection.734	pub fn effective_collection_limits(collection: CollectionId) -> Option<CollectionLimits> {735		let collection = <CollectionById<T>>::get(collection);736		if collection.is_none() {737			return None;738		}739740		let collection = collection.unwrap();741		let limits = collection.limits;742		let effective_limits = CollectionLimits {743			account_token_ownership_limit: Some(limits.account_token_ownership_limit()),744			sponsored_data_size: Some(limits.sponsored_data_size()),745			sponsored_data_rate_limit: Some(746				limits747					.sponsored_data_rate_limit748					.unwrap_or(SponsoringRateLimit::SponsoringDisabled),749			),750			token_limit: Some(limits.token_limit()),751			sponsor_transfer_timeout: Some(limits.sponsor_transfer_timeout(752				match collection.mode {753					CollectionMode::NFT => NFT_SPONSOR_TRANSFER_TIMEOUT,754					CollectionMode::Fungible(_) => FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,755					CollectionMode::ReFungible => REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,756				},757			)),758			sponsor_approve_timeout: Some(limits.sponsor_approve_timeout()),759			owner_can_transfer: Some(limits.owner_can_transfer()),760			owner_can_destroy: Some(limits.owner_can_destroy()),761			transfers_enabled: Some(limits.transfers_enabled()),762		};763764		Some(effective_limits)765	}766767	/// Returns information about the `collection` adapted for rpc.768	pub fn rpc_collection(collection: CollectionId) -> Option<RpcCollection<T::AccountId>> {769		let Collection {770			name,771			description,772			owner,773			mode,774			token_prefix,775			sponsorship,776			limits,777			permissions,778			external_collection,779		} = <CollectionById<T>>::get(collection)?;780781		let token_property_permissions = <CollectionPropertyPermissions<T>>::get(collection)782			.into_iter()783			.map(|(key, permission)| PropertyKeyPermission { key, permission })784			.collect();785786		let properties = <CollectionProperties<T>>::get(collection)787			.into_iter()788			.map(|(key, value)| Property { key, value })789			.collect();790791		let permissions = CollectionPermissions {792			access: Some(permissions.access()),793			mint_mode: Some(permissions.mint_mode()),794			nesting: Some(permissions.nesting().clone()),795		};796797		Some(RpcCollection {798			name: name.into_inner(),799			description: description.into_inner(),800			owner,801			mode,802			token_prefix: token_prefix.into_inner(),803			sponsorship,804			limits,805			permissions,806			token_property_permissions,807			properties,808			read_only: external_collection,809		})810	}811}812813macro_rules! limit_default {814	($old:ident, $new:ident, $($field:ident $(($arg:expr))? => $check:expr),* $(,)?) => {{815		$(816			if let Some($new) = $new.$field {817				let $old = $old.$field($($arg)?);818				let _ = $new;819				let _ = $old;820				$check821			} else {822				$new.$field = $old.$field823			}824		)*825	}};826}827macro_rules! limit_default_clone {828	($old:ident, $new:ident, $($field:ident $(($arg:expr))? => $check:expr),* $(,)?) => {{829		$(830			if let Some($new) = $new.$field.clone() {831				let $old = $old.$field($($arg)?);832				let _ = $new;833				let _ = $old;834				$check835			} else {836				$new.$field = $old.$field.clone()837			}838		)*839	}};840}841842impl<T: Config> Pallet<T> {843	/// Create new collection.844	///845	/// * `owner` - The owner of the collection.846	/// * `data` - Description of the created collection.847	/// * `is_external` - Marks that collection managet by not "Unique network".848	pub fn init_collection(849		owner: T::CrossAccountId,850		data: CreateCollectionData<T::AccountId>,851		is_external: bool,852	) -> Result<CollectionId, DispatchError> {853		{854			ensure!(855				data.token_prefix.len() <= MAX_TOKEN_PREFIX_LENGTH as usize,856				Error::<T>::CollectionTokenPrefixLimitExceeded857			);858		}859860		let created_count = <CreatedCollectionCount<T>>::get()861			.0862			.checked_add(1)863			.ok_or(ArithmeticError::Overflow)?;864		let destroyed_count = <DestroyedCollectionCount<T>>::get().0;865		let id = CollectionId(created_count);866867		// bound Total number of collections868		ensure!(869			created_count - destroyed_count <= COLLECTION_NUMBER_LIMIT,870			<Error<T>>::TotalCollectionsLimitExceeded871		);872873		// =========874875		let collection = Collection {876			owner: owner.as_sub().clone(),877			name: data.name,878			mode: data.mode.clone(),879			description: data.description,880			token_prefix: data.token_prefix,881			sponsorship: data882				.pending_sponsor883				.map(SponsorshipState::Unconfirmed)884				.unwrap_or_default(),885			limits: data886				.limits887				.map(|limits| Self::clamp_limits(data.mode.clone(), &Default::default(), limits))888				.unwrap_or_else(|| Ok(CollectionLimits::default()))?,889			permissions: data890				.permissions891				.map(|permissions| {892					Self::clamp_permissions(data.mode.clone(), &Default::default(), permissions)893				})894				.unwrap_or_else(|| Ok(CollectionPermissions::default()))?,895			external_collection: is_external,896		};897898		let mut collection_properties = up_data_structs::CollectionProperties::get();899		collection_properties900			.try_set_from_iter(data.properties.into_iter())901			.map_err(<Error<T>>::from)?;902903		CollectionProperties::<T>::insert(id, collection_properties);904905		let mut token_props_permissions = PropertiesPermissionMap::new();906		token_props_permissions907			.try_set_from_iter(data.token_property_permissions.into_iter())908			.map_err(<Error<T>>::from)?;909910		CollectionPropertyPermissions::<T>::insert(id, token_props_permissions);911912		// Take a (non-refundable) deposit of collection creation913		{914			let mut imbalance =915				<<<T as Config>::Currency as Currency<T::AccountId>>::PositiveImbalance>::zero();916			imbalance.subsume(917				<<T as Config>::Currency as Currency<T::AccountId>>::deposit_creating(918					&T::TreasuryAccountId::get(),919					T::CollectionCreationPrice::get(),920				),921			);922			<T as Config>::Currency::settle(923				owner.as_sub(),924				imbalance,925				WithdrawReasons::TRANSFER,926				ExistenceRequirement::KeepAlive,927			)928			.map_err(|_| Error::<T>::NotSufficientFounds)?;929		}930931		<CreatedCollectionCount<T>>::put(created_count);932		<Pallet<T>>::deposit_event(Event::CollectionCreated(933			id,934			data.mode.id(),935			owner.as_sub().clone(),936		));937		<PalletEvm<T>>::deposit_log(938			erc::CollectionHelpersEvents::CollectionCreated {939				owner: *owner.as_eth(),940				collection_id: eth::collection_id_to_address(id),941			}942			.to_log(T::ContractAddress::get()),943		);944		<CollectionById<T>>::insert(id, collection);945		Ok(id)946	}947948	/// Destroy collection.949	///950	/// * `collection` - Collection handler.951	/// * `sender` - The owner or administrator of the collection.952	pub fn destroy_collection(953		collection: CollectionHandle<T>,954		sender: &T::CrossAccountId,955	) -> DispatchResult {956		ensure!(957			collection.limits.owner_can_destroy(),958			<Error<T>>::NoPermission,959		);960		collection.check_is_owner(sender)?;961962		let destroyed_collections = <DestroyedCollectionCount<T>>::get()963			.0964			.checked_add(1)965			.ok_or(ArithmeticError::Overflow)?;966967		// =========968969		<DestroyedCollectionCount<T>>::put(destroyed_collections);970		<CollectionById<T>>::remove(collection.id);971		<AdminAmount<T>>::remove(collection.id);972		let _ = <IsAdmin<T>>::clear_prefix((collection.id,), u32::MAX, None);973		let _ = <Allowlist<T>>::clear_prefix((collection.id,), u32::MAX, None);974		<CollectionProperties<T>>::remove(collection.id);975976		<Pallet<T>>::deposit_event(Event::CollectionDestroyed(collection.id));977		Ok(())978	}979980	/// Set collection property.981	///982	/// * `collection` - Collection handler.983	/// * `sender` - The owner or administrator of the collection.984	/// * `property` - The property to set.985	pub fn set_collection_property(986		collection: &CollectionHandle<T>,987		sender: &T::CrossAccountId,988		property: Property,989	) -> DispatchResult {990		collection.check_is_owner_or_admin(sender)?;991992		CollectionProperties::<T>::try_mutate(collection.id, |properties| {993			let property = property.clone();994			properties.try_set(property.key, property.value)995		})996		.map_err(<Error<T>>::from)?;997998		Self::deposit_event(Event::CollectionPropertySet(collection.id, property.key));9991000		Ok(())1001	}10021003	/// Set scouped collection property.1004	///1005	/// * `collection_id` - ID of the collection for which the property is being set.1006	/// * `scope` - Property scope.1007	/// * `property` - The property to set.1008	pub fn set_scoped_collection_property(1009		collection_id: CollectionId,1010		scope: PropertyScope,1011		property: Property,1012	) -> DispatchResult {1013		CollectionProperties::<T>::try_mutate(collection_id, |properties| {1014			properties.try_scoped_set(scope, property.key, property.value)1015		})1016		.map_err(<Error<T>>::from)?;10171018		Ok(())1019	}10201021	/// Set scouped collection properties.1022	///1023	/// * `collection_id` - ID of the collection for which the properties is being set.1024	/// * `scope` - Property scope.1025	/// * `properties` - The properties to set.1026	pub fn set_scoped_collection_properties(1027		collection_id: CollectionId,1028		scope: PropertyScope,1029		properties: impl Iterator<Item = Property>,1030	) -> DispatchResult {1031		CollectionProperties::<T>::try_mutate(collection_id, |stored_properties| {1032			stored_properties.try_scoped_set_from_iter(scope, properties)1033		})1034		.map_err(<Error<T>>::from)?;10351036		Ok(())1037	}10381039	/// Set collection properties.1040	///1041	/// * `collection` - Collection handler.1042	/// * `sender` - The owner or administrator of the collection.1043	/// * `properties` - The properties to set.1044	#[transactional]1045	pub fn set_collection_properties(1046		collection: &CollectionHandle<T>,1047		sender: &T::CrossAccountId,1048		properties: Vec<Property>,1049	) -> DispatchResult {1050		for property in properties {1051			Self::set_collection_property(collection, sender, property)?;1052		}10531054		Ok(())1055	}10561057	/// Delete collection property.1058	///1059	/// * `collection` - Collection handler.1060	/// * `sender` - The owner or administrator of the collection.1061	/// * `property` - The property to delete.1062	pub fn delete_collection_property(1063		collection: &CollectionHandle<T>,1064		sender: &T::CrossAccountId,1065		property_key: PropertyKey,1066	) -> DispatchResult {1067		collection.check_is_owner_or_admin(sender)?;10681069		CollectionProperties::<T>::try_mutate(collection.id, |properties| {1070			properties.remove(&property_key)1071		})1072		.map_err(<Error<T>>::from)?;10731074		Self::deposit_event(Event::CollectionPropertyDeleted(1075			collection.id,1076			property_key,1077		));10781079		Ok(())1080	}10811082	/// Delete collection properties.1083	///1084	/// * `collection` - Collection handler.1085	/// * `sender` - The owner or administrator of the collection.1086	/// * `properties` - The properties to delete.1087	#[transactional]1088	pub fn delete_collection_properties(1089		collection: &CollectionHandle<T>,1090		sender: &T::CrossAccountId,1091		property_keys: Vec<PropertyKey>,1092	) -> DispatchResult {1093		for key in property_keys {1094			Self::delete_collection_property(collection, sender, key)?;1095		}10961097		Ok(())1098	}10991100	/// Set collection propetry permission without any checks.1101	///1102	/// Used for migrations.1103	///1104	/// * `collection` - Collection handler.1105	/// * `property_permissions` - Property permissions.1106	pub fn set_property_permission_unchecked(1107		collection: CollectionId,1108		property_permission: PropertyKeyPermission,1109	) -> DispatchResult {1110		<CollectionPropertyPermissions<T>>::try_mutate(collection, |permissions| {1111			permissions.try_set(property_permission.key, property_permission.permission)1112		})1113		.map_err(<Error<T>>::from)?;1114		Ok(())1115	}11161117	/// Set collection property permission.1118	///1119	/// * `collection` - Collection handler.1120	/// * `sender` - The owner or administrator of the collection.1121	/// * `property_permission` - Property permission.1122	pub fn set_property_permission(1123		collection: &CollectionHandle<T>,1124		sender: &T::CrossAccountId,1125		property_permission: PropertyKeyPermission,1126	) -> DispatchResult {1127		Self::set_scoped_property_permission(1128			collection,1129			sender,1130			PropertyScope::None,1131			property_permission,1132		)1133	}11341135	/// Set collection property permission with scope.1136	///1137	/// * `collection` - Collection handler.1138	/// * `sender` - The owner or administrator of the collection.1139	/// * `scope` - Property scope.1140	/// * `property_permission` - Property permission.1141	pub fn set_scoped_property_permission(1142		collection: &CollectionHandle<T>,1143		sender: &T::CrossAccountId,1144		scope: PropertyScope,1145		property_permission: PropertyKeyPermission,1146	) -> DispatchResult {1147		collection.check_is_owner_or_admin(sender)?;11481149		let all_permissions = CollectionPropertyPermissions::<T>::get(collection.id);1150		let current_permission = all_permissions.get(&property_permission.key);1151		if matches![1152			current_permission,1153			Some(PropertyPermission { mutable: false, .. })1154		] {1155			return Err(<Error<T>>::NoPermission.into());1156		}11571158		CollectionPropertyPermissions::<T>::try_mutate(collection.id, |permissions| {1159			let property_permission = property_permission.clone();1160			permissions.try_scoped_set(1161				scope,1162				property_permission.key,1163				property_permission.permission,1164			)1165		})1166		.map_err(<Error<T>>::from)?;11671168		Self::deposit_event(Event::PropertyPermissionSet(1169			collection.id,1170			property_permission.key,1171		));11721173		Ok(())1174	}11751176	/// Set token property permission.1177	///1178	/// * `collection` - Collection handler.1179	/// * `sender` - The owner or administrator of the collection.1180	/// * `property_permissions` - Property permissions.1181	#[transactional]1182	pub fn set_token_property_permissions(1183		collection: &CollectionHandle<T>,1184		sender: &T::CrossAccountId,1185		property_permissions: Vec<PropertyKeyPermission>,1186	) -> DispatchResult {1187		Self::set_scoped_token_property_permissions(1188			collection,1189			sender,1190			PropertyScope::None,1191			property_permissions,1192		)1193	}11941195	/// Set token property permission with scope.1196	///1197	/// * `collection` - Collection handler.1198	/// * `sender` - The owner or administrator of the collection.1199	/// * `scope` - Property scope.1200	/// * `property_permissions` - Property permissions.1201	#[transactional]1202	pub fn set_scoped_token_property_permissions(1203		collection: &CollectionHandle<T>,1204		sender: &T::CrossAccountId,1205		scope: PropertyScope,1206		property_permissions: Vec<PropertyKeyPermission>,1207	) -> DispatchResult {1208		for prop_pemission in property_permissions {1209			Self::set_scoped_property_permission(collection, sender, scope, prop_pemission)?;1210		}12111212		Ok(())1213	}12141215	/// Get collection property.1216	pub fn get_collection_property(1217		collection_id: CollectionId,1218		key: &PropertyKey,1219	) -> Option<PropertyValue> {1220		Self::collection_properties(collection_id).get(key).cloned()1221	}12221223	/// Convert byte vector to property key vector.1224	pub fn bytes_keys_to_property_keys(1225		keys: Vec<Vec<u8>>,1226	) -> Result<Vec<PropertyKey>, DispatchError> {1227		keys.into_iter()1228			.map(|key| -> Result<PropertyKey, DispatchError> {1229				key.try_into()1230					.map_err(|_| <Error<T>>::PropertyKeyIsTooLong.into())1231			})1232			.collect::<Result<Vec<PropertyKey>, DispatchError>>()1233	}12341235	/// Get properties according to given keys.1236	pub fn filter_collection_properties(1237		collection_id: CollectionId,1238		keys: Option<Vec<PropertyKey>>,1239	) -> Result<Vec<Property>, DispatchError> {1240		let properties = Self::collection_properties(collection_id);12411242		let properties = keys1243			.map(|keys| {1244				keys.into_iter()1245					.filter_map(|key| {1246						properties.get(&key).map(|value| Property {1247							key,1248							value: value.clone(),1249						})1250					})1251					.collect()1252			})1253			.unwrap_or_else(|| {1254				properties1255					.into_iter()1256					.map(|(key, value)| Property { key, value })1257					.collect()1258			});12591260		Ok(properties)1261	}12621263	/// Get property permissions according to given keys.1264	pub fn filter_property_permissions(1265		collection_id: CollectionId,1266		keys: Option<Vec<PropertyKey>>,1267	) -> Result<Vec<PropertyKeyPermission>, DispatchError> {1268		let permissions = Self::property_permissions(collection_id);12691270		let key_permissions = keys1271			.map(|keys| {1272				keys.into_iter()1273					.filter_map(|key| {1274						permissions1275							.get(&key)1276							.map(|permission| PropertyKeyPermission {1277								key,1278								permission: permission.clone(),1279							})1280					})1281					.collect()1282			})1283			.unwrap_or_else(|| {1284				permissions1285					.into_iter()1286					.map(|(key, permission)| PropertyKeyPermission { key, permission })1287					.collect()1288			});12891290		Ok(key_permissions)1291	}12921293	/// Toggle `user` participation in the `collection`'s allow list.1294	pub fn toggle_allowlist(1295		collection: &CollectionHandle<T>,1296		sender: &T::CrossAccountId,1297		user: &T::CrossAccountId,1298		allowed: bool,1299	) -> DispatchResult {1300		collection.check_is_owner_or_admin(sender)?;13011302		// =========13031304		if allowed {1305			<Allowlist<T>>::insert((collection.id, user), true);1306		} else {1307			<Allowlist<T>>::remove((collection.id, user));1308		}13091310		Ok(())1311	}13121313	/// Toggle `user` participation in the `collection`'s admin list.1314	pub fn toggle_admin(1315		collection: &CollectionHandle<T>,1316		sender: &T::CrossAccountId,1317		user: &T::CrossAccountId,1318		admin: bool,1319	) -> DispatchResult {1320		collection.check_is_owner(sender)?;13211322		let was_admin = <IsAdmin<T>>::get((collection.id, user));1323		if was_admin == admin {1324			return Ok(());1325		}1326		let amount = <AdminAmount<T>>::get(collection.id);13271328		if admin {1329			let amount = amount1330				.checked_add(1)1331				.ok_or(<Error<T>>::CollectionAdminCountExceeded)?;1332			ensure!(1333				amount <= Self::collection_admins_limit(),1334				<Error<T>>::CollectionAdminCountExceeded,1335			);13361337			// =========13381339			<AdminAmount<T>>::insert(collection.id, amount);1340			<IsAdmin<T>>::insert((collection.id, user), true);1341		} else {1342			<AdminAmount<T>>::insert(collection.id, amount.saturating_sub(1));1343			<IsAdmin<T>>::remove((collection.id, user));1344		}13451346		Ok(())1347	}13481349	/// Merge set fields from `new_limit` to `old_limit`.1350	pub fn clamp_limits(1351		mode: CollectionMode,1352		old_limit: &CollectionLimits,1353		mut new_limit: CollectionLimits,1354	) -> Result<CollectionLimits, DispatchError> {1355		let limits = old_limit;1356		limit_default!(old_limit, new_limit,1357			account_token_ownership_limit => ensure!(1358				new_limit <= MAX_TOKEN_OWNERSHIP,1359				<Error<T>>::CollectionLimitBoundsExceeded,1360			),1361			sponsored_data_size => ensure!(1362				new_limit <= CUSTOM_DATA_LIMIT,1363				<Error<T>>::CollectionLimitBoundsExceeded,1364			),13651366			sponsored_data_rate_limit => {},1367			token_limit => ensure!(1368				old_limit >= new_limit && new_limit > 0,1369				<Error<T>>::CollectionTokenLimitExceeded1370			),13711372			sponsor_transfer_timeout(match mode {1373				CollectionMode::NFT => NFT_SPONSOR_TRANSFER_TIMEOUT,1374				CollectionMode::Fungible(_) => FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,1375				CollectionMode::ReFungible => REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,1376			}) => ensure!(1377				new_limit <= MAX_SPONSOR_TIMEOUT,1378				<Error<T>>::CollectionLimitBoundsExceeded,1379			),1380			sponsor_approve_timeout => {},1381			owner_can_transfer => ensure!(1382				!limits.owner_can_transfer_instaled() ||1383				old_limit || !new_limit,1384				<Error<T>>::OwnerPermissionsCantBeReverted,1385			),1386			owner_can_destroy => ensure!(1387				old_limit || !new_limit,1388				<Error<T>>::OwnerPermissionsCantBeReverted,1389			),1390			transfers_enabled => {},1391		);1392		Ok(new_limit)1393	}13941395	/// Merge set fields from `new_permission` to `old_permission`.1396	pub fn clamp_permissions(1397		_mode: CollectionMode,1398		old_permission: &CollectionPermissions,1399		mut new_permission: CollectionPermissions,1400	) -> Result<CollectionPermissions, DispatchError> {1401		limit_default_clone!(old_permission, new_permission,1402			access => {},1403			mint_mode => {},1404			nesting => { /* todo check for permissive, if only it gets out of benchmarks */ },1405		);1406		Ok(new_permission)1407	}1408}14091410/// Indicates unsupported methods by returning [Error::UnsupportedOperation].1411#[macro_export]1412macro_rules! unsupported {1413	($runtime:path) => {1414		Err($crate::Error::<$runtime>::UnsupportedOperation.into())1415	};1416}14171418/// Return weights for various worst-case operations.1419pub trait CommonWeightInfo<CrossAccountId> {1420	/// Weight of item creation.1421	fn create_item() -> Weight;14221423	/// Weight of items creation.1424	fn create_multiple_items(amount: &[CreateItemData]) -> Weight;14251426	/// Weight of items creation.1427	fn create_multiple_items_ex(cost: &CreateItemExData<CrossAccountId>) -> Weight;14281429	/// The weight of the burning item.1430	fn burn_item() -> Weight;14311432	/// Property setting weight.1433	///1434	/// * `amount`- The number of properties to set.1435	fn set_collection_properties(amount: u32) -> Weight;14361437	/// Collection property deletion weight.1438	///1439	/// * `amount`- The number of properties to set.1440	fn delete_collection_properties(amount: u32) -> Weight;14411442	/// Token property setting weight.1443	///1444	/// * `amount`- The number of properties to set.1445	fn set_token_properties(amount: u32) -> Weight;14461447	/// Token property deletion weight.1448	///1449	/// * `amount`- The number of properties to delete.1450	fn delete_token_properties(amount: u32) -> Weight;14511452	/// Token property permissions set weight.1453	///1454	/// * `amount`- The number of property permissions to set.1455	fn set_token_property_permissions(amount: u32) -> Weight;14561457	/// Transfer price of the token or its parts.1458	fn transfer() -> Weight;14591460	/// The price of setting the permission of the operation from another user.1461	fn approve() -> Weight;14621463	/// Transfer price from another user.1464	fn transfer_from() -> Weight;14651466	/// The price of burning a token from another user.1467	fn burn_from() -> Weight;14681469	/// Differs from burn_item in case of Fungible and Refungible, as it should burn1470	/// whole users's balance.1471	///1472	/// This method shouldn't be used directly, as it doesn't count breadth price, use [burn_recursively](CommonWeightInfo::burn_recursively) instead1473	fn burn_recursively_self_raw() -> Weight;14741475	/// Cost of iterating over `amount` children while burning, without counting child burning itself.1476	///1477	/// This method shouldn't be used directly, as it doesn't count depth price, use [burn_recursively](CommonWeightInfo::burn_recursively) instead1478	fn burn_recursively_breadth_raw(amount: u32) -> Weight;14791480	/// The price of recursive burning a token.1481	///1482	/// `max_selfs` - The maximum burning weight of the token itself.1483	/// `max_breadth` - The maximum number of nested tokens to burn.1484	fn burn_recursively(max_selfs: u32, max_breadth: u32) -> Weight {1485		Self::burn_recursively_self_raw()1486			.saturating_mul(max_selfs.max(1) as u64)1487			.saturating_add(Self::burn_recursively_breadth_raw(max_breadth))1488	}14891490	/// The price of retrieving token owner1491	fn token_owner() -> Weight;1492}14931494/// Weight info extension trait for refungible pallet.1495pub trait RefungibleExtensionsWeightInfo {1496	/// Weight of token repartition.1497	fn repartition() -> Weight;1498}14991500/// Common collection operations.1501///1502/// It wraps methods in Fungible, Nonfungible and Refungible pallets1503/// and adds weight info.1504pub trait CommonCollectionOperations<T: Config> {1505	/// Create token.1506	///1507	/// * `sender` - The user who mint the token and pays for the transaction.1508	/// * `to` - The user who will own the token.1509	/// * `data` - Token data.1510	/// * `nesting_budget` - A budget that can be spent on nesting tokens.1511	fn create_item(1512		&self,1513		sender: T::CrossAccountId,1514		to: T::CrossAccountId,1515		data: CreateItemData,1516		nesting_budget: &dyn Budget,1517	) -> DispatchResultWithPostInfo;15181519	/// Create multiple tokens.1520	///1521	/// * `sender` - The user who mint the token and pays for the transaction.1522	/// * `to` - The user who will own the token.1523	/// * `data` - Token data.1524	/// * `nesting_budget` - A budget that can be spent on nesting tokens.1525	fn create_multiple_items(1526		&self,1527		sender: T::CrossAccountId,1528		to: T::CrossAccountId,1529		data: Vec<CreateItemData>,1530		nesting_budget: &dyn Budget,1531	) -> DispatchResultWithPostInfo;15321533	/// Create multiple tokens.1534	///1535	/// * `sender` - The user who mint the token and pays for the transaction.1536	/// * `to` - The user who will own the token.1537	/// * `data` - Token data.1538	/// * `nesting_budget` - A budget that can be spent on nesting tokens.1539	fn create_multiple_items_ex(1540		&self,1541		sender: T::CrossAccountId,1542		data: CreateItemExData<T::CrossAccountId>,1543		nesting_budget: &dyn Budget,1544	) -> DispatchResultWithPostInfo;15451546	/// Burn token.1547	///1548	/// * `sender` - The user who owns the token.1549	/// * `token` - Token id that will burned.1550	/// * `amount` - The number of parts of the token that will be burned.1551	fn burn_item(1552		&self,1553		sender: T::CrossAccountId,1554		token: TokenId,1555		amount: u128,1556	) -> DispatchResultWithPostInfo;15571558	/// Burn token and all nested tokens recursievly.1559	///1560	/// * `sender` - The user who owns the token.1561	/// * `token` - Token id that will burned.1562	/// * `self_budget` - The budget that can be spent on burning tokens.1563	/// * `breadth_budget` - The budget that can be spent on burning nested tokens.1564	fn burn_item_recursively(1565		&self,1566		sender: T::CrossAccountId,1567		token: TokenId,1568		self_budget: &dyn Budget,1569		breadth_budget: &dyn Budget,1570	) -> DispatchResultWithPostInfo;15711572	/// Set collection properties.1573	///1574	/// * `sender` - Must be either the owner of the collection or its admin.1575	/// * `properties` - Properties to be set.1576	fn set_collection_properties(1577		&self,1578		sender: T::CrossAccountId,1579		properties: Vec<Property>,1580	) -> DispatchResultWithPostInfo;15811582	/// Delete collection properties.1583	///1584	/// * `sender` - Must be either the owner of the collection or its admin.1585	/// * `properties` - The properties to be removed.1586	fn delete_collection_properties(1587		&self,1588		sender: &T::CrossAccountId,1589		property_keys: Vec<PropertyKey>,1590	) -> DispatchResultWithPostInfo;15911592	/// Set token properties.1593	///1594	/// The appropriate [`PropertyPermission`] for the token property1595	/// must be set with [`Self::set_token_property_permissions`].1596	///1597	/// * `sender` - Must be either the owner of the token or its admin.1598	/// * `token_id` - The token for which the properties are being set.1599	/// * `properties` - Properties to be set.1600	/// * `budget` - Budget for setting properties.1601	fn set_token_properties(1602		&self,1603		sender: T::CrossAccountId,1604		token_id: TokenId,1605		properties: Vec<Property>,1606		budget: &dyn Budget,1607	) -> DispatchResultWithPostInfo;16081609	/// Remove token properties.1610	///1611	/// The appropriate [`PropertyPermission`] for the token property1612	/// must be set with [`Self::set_token_property_permissions`].1613	///1614	/// * `sender` - Must be either the owner of the token or its admin.1615	/// * `token_id` - The token for which the properties are being remove.1616	/// * `property_keys` - Keys to remove corresponding properties.1617	/// * `budget` - Budget for removing properties.1618	fn delete_token_properties(1619		&self,1620		sender: T::CrossAccountId,1621		token_id: TokenId,1622		property_keys: Vec<PropertyKey>,1623		budget: &dyn Budget,1624	) -> DispatchResultWithPostInfo;16251626	/// Set token property permissions.1627	///1628	/// * `sender` - Must be either the owner of the token or its admin.1629	/// * `token_id` - The token for which the properties are being set.1630	/// * `property_permissions` - Property permissions to be set.1631	/// * `budget` - Budget for setting properties.1632	fn set_token_property_permissions(1633		&self,1634		sender: &T::CrossAccountId,1635		property_permissions: Vec<PropertyKeyPermission>,1636	) -> DispatchResultWithPostInfo;16371638	/// Transfer amount of token pieces.1639	///1640	/// * `sender` - Donor user.1641	/// * `to` - Recepient user.1642	/// * `token` - The token of which parts are being sent.1643	/// * `amount` - The number of parts of the token that will be transferred.1644	/// * `budget` - The maximum budget that can be spent on the transfer.1645	fn transfer(1646		&self,1647		sender: T::CrossAccountId,1648		to: T::CrossAccountId,1649		token: TokenId,1650		amount: u128,1651		budget: &dyn Budget,1652	) -> DispatchResultWithPostInfo;16531654	/// Grant access to another account to transfer parts of the token owned by the calling user via [Self::transfer_from].1655	///1656	/// * `sender` - The user who grants access to the token.1657	/// * `spender` - The user to whom the rights are granted.1658	/// * `token` - The token to which access is granted.1659	/// * `amount` - The amount of pieces that another user can dispose of.1660	fn approve(1661		&self,1662		sender: T::CrossAccountId,1663		spender: T::CrossAccountId,1664		token: TokenId,1665		amount: u128,1666	) -> DispatchResultWithPostInfo;16671668	/// Send parts of a token owned by another user.1669	///1670	/// Before calling this method, you must grant rights to the calling user via [`Self::approve`].1671	///1672	/// * `sender` - The user who must have access to the token (see [`Self::approve`]).1673	/// * `from` - The user who owns the token.1674	/// * `to` - Recepient user.1675	/// * `token` - The token of which parts are being sent.1676	/// * `amount` - The number of parts of the token that will be transferred.1677	/// * `budget` - The maximum budget that can be spent on the transfer.1678	fn transfer_from(1679		&self,1680		sender: T::CrossAccountId,1681		from: T::CrossAccountId,1682		to: T::CrossAccountId,1683		token: TokenId,1684		amount: u128,1685		budget: &dyn Budget,1686	) -> DispatchResultWithPostInfo;16871688	/// Burn parts of a token owned by another user.1689	///1690	/// Before calling this method, you must grant rights to the calling user via [`Self::approve`].1691	///1692	/// * `sender` - The user who must have access to the token (see [`Self::approve`]).1693	/// * `from` - The user who owns the token.1694	/// * `token` - The token of which parts are being sent.1695	/// * `amount` - The number of parts of the token that will be transferred.1696	/// * `budget` - The maximum budget that can be spent on the burn.1697	fn burn_from(1698		&self,1699		sender: T::CrossAccountId,1700		from: T::CrossAccountId,1701		token: TokenId,1702		amount: u128,1703		budget: &dyn Budget,1704	) -> DispatchResultWithPostInfo;17051706	/// Check permission to nest token.1707	///1708	/// * `sender` - The user who initiated the check.1709	/// * `from` - The token that is checked for embedding.1710	/// * `under` - Token under which to check.1711	/// * `budget` - The maximum budget that can be spent on the check.1712	fn check_nesting(1713		&self,1714		sender: T::CrossAccountId,1715		from: (CollectionId, TokenId),1716		under: TokenId,1717		budget: &dyn Budget,1718	) -> DispatchResult;17191720	/// Nest one token into another.1721	///1722	/// * `under` - Token holder.1723	/// * `to_nest` - Nested token.1724	fn nest(&self, under: TokenId, to_nest: (CollectionId, TokenId));17251726	/// Unnest token.1727	///1728	/// * `under` - Token holder.1729	/// * `to_nest` - Token to unnest.1730	fn unnest(&self, under: TokenId, to_nest: (CollectionId, TokenId));17311732	/// Get all user tokens.1733	///1734	/// * `account` - Account for which you need to get tokens.1735	fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId>;17361737	/// Get all the tokens in the collection.1738	fn collection_tokens(&self) -> Vec<TokenId>;17391740	/// Check if the token exists.1741	///1742	/// * `token` - Id token to check.1743	fn token_exists(&self, token: TokenId) -> bool;17441745	/// Get the id of the last minted token.1746	fn last_token_id(&self) -> TokenId;17471748	/// Get the owner of the token.1749	///1750	/// * `token` - The token for which you need to find out the owner.1751	fn token_owner(&self, token: TokenId) -> Option<T::CrossAccountId>;17521753	/// Returns 10 tokens owners in no particular order.1754	///1755	/// * `token` - The token for which you need to find out the owners.1756	fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId>;17571758	/// Get the value of the token property by key.1759	///1760	/// * `token` - Token with the property to get.1761	/// * `key` - Property name.1762	fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue>;17631764	/// Get a set of token properties by key vector.1765	///1766	/// * `token` - Token with the property to get.1767	/// * `keys` - Vector of property keys. If this parameter is [None](sp_std::result::Result),1768	/// then all properties are returned.1769	fn token_properties(&self, token: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property>;17701771	/// Amount of unique collection tokens1772	fn total_supply(&self) -> u32;17731774	/// Amount of different tokens account has.1775	///1776	/// * `account` - The account for which need to get the balance.1777	fn account_balance(&self, account: T::CrossAccountId) -> u32;17781779	/// Amount of specific token account have.1780	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128;17811782	/// Amount of token pieces1783	fn total_pieces(&self, token: TokenId) -> Option<u128>;17841785	/// Get the number of parts of the token that a trusted user can manage.1786	///1787	/// * `sender` - Trusted user.1788	/// * `spender` - Owner of the token.1789	/// * `token` - The token for which to get the value.1790	fn allowance(1791		&self,1792		sender: T::CrossAccountId,1793		spender: T::CrossAccountId,1794		token: TokenId,1795	) -> u128;17961797	/// Get extension for RFT collection.1798	fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>>;1799}18001801/// Extension for RFT collection.1802pub trait RefungibleExtensions<T>1803where1804	T: Config,1805{1806	/// Change the number of parts of the token.1807	///1808	/// When the value changes down, this function is equivalent to burning parts of the token.1809	///1810	/// * `sender` - The user calling the repartition operation. Must be the owner of the token.1811	/// * `token` - The token for which you want to change the number of parts.1812	/// * `amount` - The new value of the parts of the token.1813	fn repartition(1814		&self,1815		sender: &T::CrossAccountId,1816		token: TokenId,1817		amount: u128,1818	) -> DispatchResultWithPostInfo;1819}18201821/// Merge [`DispatchResult`] with [`Weight`] into [`DispatchResultWithPostInfo`].1822///1823/// Used for [`CommonCollectionOperations`] implementations and flexible enough to do so.1824pub fn with_weight(res: DispatchResult, weight: Weight) -> DispatchResultWithPostInfo {1825	let post_info = PostDispatchInfo {1826		actual_weight: Some(weight),1827		pays_fee: Pays::Yes,1828	};1829	match res {1830		Ok(()) => Ok(post_info),1831		Err(error) => Err(DispatchErrorWithPostInfo { post_info, error }),1832	}1833}18341835impl<T: Config> From<PropertiesError> for Error<T> {1836	fn from(error: PropertiesError) -> Self {1837		match error {1838			PropertiesError::NoSpaceForProperty => Self::NoSpaceForProperty,1839			PropertiesError::PropertyLimitReached => Self::PropertyLimitReached,1840			PropertiesError::InvalidCharacterInPropertyKey => Self::InvalidCharacterInPropertyKey,1841			PropertiesError::PropertyKeyIsTooLong => Self::PropertyKeyIsTooLong,1842			PropertiesError::EmptyPropertyKey => Self::EmptyPropertyKey,1843		}1844	}1845}
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
--- a/pallets/fungible/src/stubs/UniqueFungible.sol
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -31,103 +31,7 @@
 	);
 }
 
-// Selector: 79cc6790
-contract ERC20UniqueExtensions is Dummy, ERC165 {
-	// Selector: burnFrom(address,uint256) 79cc6790
-	function burnFrom(address from, uint256 amount) public returns (bool) {
-		require(false, stub_error);
-		from;
-		amount;
-		dummy = 0;
-		return false;
-	}
-}
-
-// Selector: 942e8b22
-contract ERC20 is Dummy, ERC165, ERC20Events {
-	// Selector: name() 06fdde03
-	function name() public view returns (string memory) {
-		require(false, stub_error);
-		dummy;
-		return "";
-	}
-
-	// Selector: symbol() 95d89b41
-	function symbol() public view returns (string memory) {
-		require(false, stub_error);
-		dummy;
-		return "";
-	}
-
-	// Selector: totalSupply() 18160ddd
-	function totalSupply() public view returns (uint256) {
-		require(false, stub_error);
-		dummy;
-		return 0;
-	}
-
-	// Selector: decimals() 313ce567
-	function decimals() public view returns (uint8) {
-		require(false, stub_error);
-		dummy;
-		return 0;
-	}
-
-	// Selector: balanceOf(address) 70a08231
-	function balanceOf(address owner) public view returns (uint256) {
-		require(false, stub_error);
-		owner;
-		dummy;
-		return 0;
-	}
-
-	// Selector: transfer(address,uint256) a9059cbb
-	function transfer(address to, uint256 amount) public returns (bool) {
-		require(false, stub_error);
-		to;
-		amount;
-		dummy = 0;
-		return false;
-	}
-
-	// Selector: transferFrom(address,address,uint256) 23b872dd
-	function transferFrom(
-		address from,
-		address to,
-		uint256 amount
-	) public returns (bool) {
-		require(false, stub_error);
-		from;
-		to;
-		amount;
-		dummy = 0;
-		return false;
-	}
-
-	// Selector: approve(address,uint256) 095ea7b3
-	function approve(address spender, uint256 amount) public returns (bool) {
-		require(false, stub_error);
-		spender;
-		amount;
-		dummy = 0;
-		return false;
-	}
-
-	// Selector: allowance(address,address) dd62ed3e
-	function allowance(address owner, address spender)
-		public
-		view
-		returns (uint256)
-	{
-		require(false, stub_error);
-		owner;
-		spender;
-		dummy;
-		return 0;
-	}
-}
-
-// Selector: ca08c92c
+// Selector: 07f76b0c
 contract Collection is Dummy, ERC165 {
 	// Set collection property.
 	//
@@ -366,6 +270,23 @@
 		return false;
 	}
 
+	// Check that substrate account is the owner or admin of the collection
+	//
+	// @param user account to verify
+	// @return "true" if account is the owner or admin
+	//
+	// Selector: verifyOwnerOrAdminSubstrate(uint256) fe818e40
+	function verifyOwnerOrAdminSubstrate(uint256 user)
+		public
+		view
+		returns (bool)
+	{
+		require(false, stub_error);
+		user;
+		dummy;
+		return false;
+	}
+
 	// Returns collection type
 	//
 	// @return `Fungible` or `NFT` or `ReFungible`
@@ -377,10 +298,10 @@
 		return "";
 	}
 
-	// Changes collection owner
+	// Changes collection owner to another account
 	//
 	// @dev Owner can be changed only by current owner
-	// @param newOwner new owner
+	// @param newOwner new owner account
 	//
 	// Selector: changeOwner(address) a6f9dae1
 	function changeOwner(address newOwner) public {
@@ -388,6 +309,114 @@
 		newOwner;
 		dummy = 0;
 	}
+
+	// Changes collection owner to another substrate account
+	//
+	// @dev Owner can be changed only by current owner
+	// @param newOwner new owner substrate account
+	//
+	// Selector: changeOwnerSubstrate(uint256) 337e2c60
+	function changeOwnerSubstrate(uint256 newOwner) public {
+		require(false, stub_error);
+		newOwner;
+		dummy = 0;
+	}
+}
+
+// Selector: 79cc6790
+contract ERC20UniqueExtensions is Dummy, ERC165 {
+	// Selector: burnFrom(address,uint256) 79cc6790
+	function burnFrom(address from, uint256 amount) public returns (bool) {
+		require(false, stub_error);
+		from;
+		amount;
+		dummy = 0;
+		return false;
+	}
+}
+
+// Selector: 942e8b22
+contract ERC20 is Dummy, ERC165, ERC20Events {
+	// Selector: name() 06fdde03
+	function name() public view returns (string memory) {
+		require(false, stub_error);
+		dummy;
+		return "";
+	}
+
+	// Selector: symbol() 95d89b41
+	function symbol() public view returns (string memory) {
+		require(false, stub_error);
+		dummy;
+		return "";
+	}
+
+	// Selector: totalSupply() 18160ddd
+	function totalSupply() public view returns (uint256) {
+		require(false, stub_error);
+		dummy;
+		return 0;
+	}
+
+	// Selector: decimals() 313ce567
+	function decimals() public view returns (uint8) {
+		require(false, stub_error);
+		dummy;
+		return 0;
+	}
+
+	// Selector: balanceOf(address) 70a08231
+	function balanceOf(address owner) public view returns (uint256) {
+		require(false, stub_error);
+		owner;
+		dummy;
+		return 0;
+	}
+
+	// Selector: transfer(address,uint256) a9059cbb
+	function transfer(address to, uint256 amount) public returns (bool) {
+		require(false, stub_error);
+		to;
+		amount;
+		dummy = 0;
+		return false;
+	}
+
+	// Selector: transferFrom(address,address,uint256) 23b872dd
+	function transferFrom(
+		address from,
+		address to,
+		uint256 amount
+	) public returns (bool) {
+		require(false, stub_error);
+		from;
+		to;
+		amount;
+		dummy = 0;
+		return false;
+	}
+
+	// Selector: approve(address,uint256) 095ea7b3
+	function approve(address spender, uint256 amount) public returns (bool) {
+		require(false, stub_error);
+		spender;
+		amount;
+		dummy = 0;
+		return false;
+	}
+
+	// Selector: allowance(address,address) dd62ed3e
+	function allowance(address owner, address spender)
+		public
+		view
+		returns (uint256)
+	{
+		require(false, stub_error);
+		owner;
+		spender;
+		dummy;
+		return 0;
+	}
 }
 
 contract UniqueFungible is
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -51,6 +51,298 @@
 	event MintingFinished();
 }
 
+// Selector: 07f76b0c
+contract Collection is Dummy, ERC165 {
+	// Set collection property.
+	//
+	// @param key Property key.
+	// @param value Propery value.
+	//
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		public
+	{
+		require(false, stub_error);
+		key;
+		value;
+		dummy = 0;
+	}
+
+	// Delete collection property.
+	//
+	// @param key Property key.
+	//
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) public {
+		require(false, stub_error);
+		key;
+		dummy = 0;
+	}
+
+	// Get collection property.
+	//
+	// @dev Throws error if key not found.
+	//
+	// @param key Property key.
+	// @return bytes The property corresponding to the key.
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		public
+		view
+		returns (bytes memory)
+	{
+		require(false, stub_error);
+		key;
+		dummy;
+		return hex"";
+	}
+
+	// Set the sponsor of the collection.
+	//
+	// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
+	//
+	// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
+	//
+	// Selector: setCollectionSponsor(address) 7623402e
+	function setCollectionSponsor(address sponsor) public {
+		require(false, stub_error);
+		sponsor;
+		dummy = 0;
+	}
+
+	// Collection sponsorship confirmation.
+	//
+	// @dev After setting the sponsor for the collection, it must be confirmed with this function.
+	//
+	// Selector: confirmCollectionSponsorship() 3c50e97a
+	function confirmCollectionSponsorship() public {
+		require(false, stub_error);
+		dummy = 0;
+	}
+
+	// Set limits for the collection.
+	// @dev Throws error if limit not found.
+	// @param limit Name of the limit. Valid names:
+	// 	"accountTokenOwnershipLimit",
+	// 	"sponsoredDataSize",
+	// 	"sponsoredDataRateLimit",
+	// 	"tokenLimit",
+	// 	"sponsorTransferTimeout",
+	// 	"sponsorApproveTimeout"
+	// @param value Value of the limit.
+	//
+	// Selector: setCollectionLimit(string,uint32) 6a3841db
+	function setCollectionLimit(string memory limit, uint32 value) public {
+		require(false, stub_error);
+		limit;
+		value;
+		dummy = 0;
+	}
+
+	// Set limits for the collection.
+	// @dev Throws error if limit not found.
+	// @param limit Name of the limit. Valid names:
+	// 	"ownerCanTransfer",
+	// 	"ownerCanDestroy",
+	// 	"transfersEnabled"
+	// @param value Value of the limit.
+	//
+	// Selector: setCollectionLimit(string,bool) 993b7fba
+	function setCollectionLimit(string memory limit, bool value) public {
+		require(false, stub_error);
+		limit;
+		value;
+		dummy = 0;
+	}
+
+	// Get contract address.
+	//
+	// Selector: contractAddress() f6b4dfb4
+	function contractAddress() public view returns (address) {
+		require(false, stub_error);
+		dummy;
+		return 0x0000000000000000000000000000000000000000;
+	}
+
+	// Add collection admin by substrate address.
+	// @param new_admin Substrate administrator address.
+	//
+	// Selector: addCollectionAdminSubstrate(uint256) 5730062b
+	function addCollectionAdminSubstrate(uint256 newAdmin) public {
+		require(false, stub_error);
+		newAdmin;
+		dummy = 0;
+	}
+
+	// Remove collection admin by substrate address.
+	// @param admin Substrate administrator address.
+	//
+	// Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
+	function removeCollectionAdminSubstrate(uint256 admin) public {
+		require(false, stub_error);
+		admin;
+		dummy = 0;
+	}
+
+	// Add collection admin.
+	// @param new_admin Address of the added administrator.
+	//
+	// Selector: addCollectionAdmin(address) 92e462c7
+	function addCollectionAdmin(address newAdmin) public {
+		require(false, stub_error);
+		newAdmin;
+		dummy = 0;
+	}
+
+	// Remove collection admin.
+	//
+	// @param new_admin Address of the removed administrator.
+	//
+	// Selector: removeCollectionAdmin(address) fafd7b42
+	function removeCollectionAdmin(address admin) public {
+		require(false, stub_error);
+		admin;
+		dummy = 0;
+	}
+
+	// Toggle accessibility of collection nesting.
+	//
+	// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
+	//
+	// Selector: setCollectionNesting(bool) 112d4586
+	function setCollectionNesting(bool enable) public {
+		require(false, stub_error);
+		enable;
+		dummy = 0;
+	}
+
+	// Toggle accessibility of collection nesting.
+	//
+	// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
+	// @param collections Addresses of collections that will be available for nesting.
+	//
+	// Selector: setCollectionNesting(bool,address[]) 64872396
+	function setCollectionNesting(bool enable, address[] memory collections)
+		public
+	{
+		require(false, stub_error);
+		enable;
+		collections;
+		dummy = 0;
+	}
+
+	// Set the collection access method.
+	// @param mode Access mode
+	// 	0 for Normal
+	// 	1 for AllowList
+	//
+	// Selector: setCollectionAccess(uint8) 41835d4c
+	function setCollectionAccess(uint8 mode) public {
+		require(false, stub_error);
+		mode;
+		dummy = 0;
+	}
+
+	// Add the user to the allowed list.
+	//
+	// @param user Address of a trusted user.
+	//
+	// Selector: addToCollectionAllowList(address) 67844fe6
+	function addToCollectionAllowList(address user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
+	// Remove the user from the allowed list.
+	//
+	// @param user Address of a removed user.
+	//
+	// Selector: removeFromCollectionAllowList(address) 85c51acb
+	function removeFromCollectionAllowList(address user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
+	// Switch permission for minting.
+	//
+	// @param mode Enable if "true".
+	//
+	// Selector: setCollectionMintMode(bool) 00018e84
+	function setCollectionMintMode(bool mode) public {
+		require(false, stub_error);
+		mode;
+		dummy = 0;
+	}
+
+	// Check that account is the owner or admin of the collection
+	//
+	// @param user account to verify
+	// @return "true" if account is the owner or admin
+	//
+	// Selector: verifyOwnerOrAdmin(address) c2282493
+	function verifyOwnerOrAdmin(address user) public view returns (bool) {
+		require(false, stub_error);
+		user;
+		dummy;
+		return false;
+	}
+
+	// Check that substrate account is the owner or admin of the collection
+	//
+	// @param user account to verify
+	// @return "true" if account is the owner or admin
+	//
+	// Selector: verifyOwnerOrAdminSubstrate(uint256) fe818e40
+	function verifyOwnerOrAdminSubstrate(uint256 user)
+		public
+		view
+		returns (bool)
+	{
+		require(false, stub_error);
+		user;
+		dummy;
+		return false;
+	}
+
+	// Returns collection type
+	//
+	// @return `Fungible` or `NFT` or `ReFungible`
+	//
+	// Selector: uniqueCollectionType() d34b55b8
+	function uniqueCollectionType() public returns (string memory) {
+		require(false, stub_error);
+		dummy = 0;
+		return "";
+	}
+
+	// Changes collection owner to another account
+	//
+	// @dev Owner can be changed only by current owner
+	// @param newOwner new owner account
+	//
+	// Selector: changeOwner(address) a6f9dae1
+	function changeOwner(address newOwner) public {
+		require(false, stub_error);
+		newOwner;
+		dummy = 0;
+	}
+
+	// Changes collection owner to another substrate account
+	//
+	// @dev Owner can be changed only by current owner
+	// @param newOwner new owner substrate account
+	//
+	// Selector: changeOwnerSubstrate(uint256) 337e2c60
+	function changeOwnerSubstrate(uint256 newOwner) public {
+		require(false, stub_error);
+		newOwner;
+		dummy = 0;
+	}
+}
+
 // Selector: 41369377
 contract TokenProperties is Dummy, ERC165 {
 	// @notice Set permissions for token property.
@@ -412,269 +704,6 @@
 		require(false, stub_error);
 		dummy;
 		return 0;
-	}
-}
-
-// Selector: ca08c92c
-contract Collection is Dummy, ERC165 {
-	// Set collection property.
-	//
-	// @param key Property key.
-	// @param value Propery value.
-	//
-	// Selector: setCollectionProperty(string,bytes) 2f073f66
-	function setCollectionProperty(string memory key, bytes memory value)
-		public
-	{
-		require(false, stub_error);
-		key;
-		value;
-		dummy = 0;
-	}
-
-	// Delete collection property.
-	//
-	// @param key Property key.
-	//
-	// Selector: deleteCollectionProperty(string) 7b7debce
-	function deleteCollectionProperty(string memory key) public {
-		require(false, stub_error);
-		key;
-		dummy = 0;
-	}
-
-	// Get collection property.
-	//
-	// @dev Throws error if key not found.
-	//
-	// @param key Property key.
-	// @return bytes The property corresponding to the key.
-	//
-	// Selector: collectionProperty(string) cf24fd6d
-	function collectionProperty(string memory key)
-		public
-		view
-		returns (bytes memory)
-	{
-		require(false, stub_error);
-		key;
-		dummy;
-		return hex"";
-	}
-
-	// Set the sponsor of the collection.
-	//
-	// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
-	//
-	// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
-	//
-	// Selector: setCollectionSponsor(address) 7623402e
-	function setCollectionSponsor(address sponsor) public {
-		require(false, stub_error);
-		sponsor;
-		dummy = 0;
-	}
-
-	// Collection sponsorship confirmation.
-	//
-	// @dev After setting the sponsor for the collection, it must be confirmed with this function.
-	//
-	// Selector: confirmCollectionSponsorship() 3c50e97a
-	function confirmCollectionSponsorship() public {
-		require(false, stub_error);
-		dummy = 0;
-	}
-
-	// Set limits for the collection.
-	// @dev Throws error if limit not found.
-	// @param limit Name of the limit. Valid names:
-	// 	"accountTokenOwnershipLimit",
-	// 	"sponsoredDataSize",
-	// 	"sponsoredDataRateLimit",
-	// 	"tokenLimit",
-	// 	"sponsorTransferTimeout",
-	// 	"sponsorApproveTimeout"
-	// @param value Value of the limit.
-	//
-	// Selector: setCollectionLimit(string,uint32) 6a3841db
-	function setCollectionLimit(string memory limit, uint32 value) public {
-		require(false, stub_error);
-		limit;
-		value;
-		dummy = 0;
-	}
-
-	// Set limits for the collection.
-	// @dev Throws error if limit not found.
-	// @param limit Name of the limit. Valid names:
-	// 	"ownerCanTransfer",
-	// 	"ownerCanDestroy",
-	// 	"transfersEnabled"
-	// @param value Value of the limit.
-	//
-	// Selector: setCollectionLimit(string,bool) 993b7fba
-	function setCollectionLimit(string memory limit, bool value) public {
-		require(false, stub_error);
-		limit;
-		value;
-		dummy = 0;
-	}
-
-	// Get contract address.
-	//
-	// Selector: contractAddress() f6b4dfb4
-	function contractAddress() public view returns (address) {
-		require(false, stub_error);
-		dummy;
-		return 0x0000000000000000000000000000000000000000;
-	}
-
-	// Add collection admin by substrate address.
-	// @param new_admin Substrate administrator address.
-	//
-	// Selector: addCollectionAdminSubstrate(uint256) 5730062b
-	function addCollectionAdminSubstrate(uint256 newAdmin) public {
-		require(false, stub_error);
-		newAdmin;
-		dummy = 0;
-	}
-
-	// Remove collection admin by substrate address.
-	// @param admin Substrate administrator address.
-	//
-	// Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
-	function removeCollectionAdminSubstrate(uint256 admin) public {
-		require(false, stub_error);
-		admin;
-		dummy = 0;
-	}
-
-	// Add collection admin.
-	// @param new_admin Address of the added administrator.
-	//
-	// Selector: addCollectionAdmin(address) 92e462c7
-	function addCollectionAdmin(address newAdmin) public {
-		require(false, stub_error);
-		newAdmin;
-		dummy = 0;
-	}
-
-	// Remove collection admin.
-	//
-	// @param new_admin Address of the removed administrator.
-	//
-	// Selector: removeCollectionAdmin(address) fafd7b42
-	function removeCollectionAdmin(address admin) public {
-		require(false, stub_error);
-		admin;
-		dummy = 0;
-	}
-
-	// Toggle accessibility of collection nesting.
-	//
-	// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
-	//
-	// Selector: setCollectionNesting(bool) 112d4586
-	function setCollectionNesting(bool enable) public {
-		require(false, stub_error);
-		enable;
-		dummy = 0;
-	}
-
-	// Toggle accessibility of collection nesting.
-	//
-	// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
-	// @param collections Addresses of collections that will be available for nesting.
-	//
-	// Selector: setCollectionNesting(bool,address[]) 64872396
-	function setCollectionNesting(bool enable, address[] memory collections)
-		public
-	{
-		require(false, stub_error);
-		enable;
-		collections;
-		dummy = 0;
-	}
-
-	// Set the collection access method.
-	// @param mode Access mode
-	// 	0 for Normal
-	// 	1 for AllowList
-	//
-	// Selector: setCollectionAccess(uint8) 41835d4c
-	function setCollectionAccess(uint8 mode) public {
-		require(false, stub_error);
-		mode;
-		dummy = 0;
-	}
-
-	// Add the user to the allowed list.
-	//
-	// @param user Address of a trusted user.
-	//
-	// Selector: addToCollectionAllowList(address) 67844fe6
-	function addToCollectionAllowList(address user) public {
-		require(false, stub_error);
-		user;
-		dummy = 0;
-	}
-
-	// Remove the user from the allowed list.
-	//
-	// @param user Address of a removed user.
-	//
-	// Selector: removeFromCollectionAllowList(address) 85c51acb
-	function removeFromCollectionAllowList(address user) public {
-		require(false, stub_error);
-		user;
-		dummy = 0;
-	}
-
-	// Switch permission for minting.
-	//
-	// @param mode Enable if "true".
-	//
-	// Selector: setCollectionMintMode(bool) 00018e84
-	function setCollectionMintMode(bool mode) public {
-		require(false, stub_error);
-		mode;
-		dummy = 0;
-	}
-
-	// Check that account is the owner or admin of the collection
-	//
-	// @param user account to verify
-	// @return "true" if account is the owner or admin
-	//
-	// Selector: verifyOwnerOrAdmin(address) c2282493
-	function verifyOwnerOrAdmin(address user) public view returns (bool) {
-		require(false, stub_error);
-		user;
-		dummy;
-		return false;
-	}
-
-	// Returns collection type
-	//
-	// @return `Fungible` or `NFT` or `ReFungible`
-	//
-	// Selector: uniqueCollectionType() d34b55b8
-	function uniqueCollectionType() public returns (string memory) {
-		require(false, stub_error);
-		dummy = 0;
-		return "";
-	}
-
-	// Changes collection owner
-	//
-	// @dev Owner can be changed only by current owner
-	// @param newOwner new owner
-	//
-	// Selector: changeOwner(address) a6f9dae1
-	function changeOwner(address newOwner) public {
-		require(false, stub_error);
-		newOwner;
-		dummy = 0;
 	}
 }
 
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -51,6 +51,298 @@
 	event MintingFinished();
 }
 
+// Selector: 07f76b0c
+contract Collection is Dummy, ERC165 {
+	// Set collection property.
+	//
+	// @param key Property key.
+	// @param value Propery value.
+	//
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		public
+	{
+		require(false, stub_error);
+		key;
+		value;
+		dummy = 0;
+	}
+
+	// Delete collection property.
+	//
+	// @param key Property key.
+	//
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) public {
+		require(false, stub_error);
+		key;
+		dummy = 0;
+	}
+
+	// Get collection property.
+	//
+	// @dev Throws error if key not found.
+	//
+	// @param key Property key.
+	// @return bytes The property corresponding to the key.
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		public
+		view
+		returns (bytes memory)
+	{
+		require(false, stub_error);
+		key;
+		dummy;
+		return hex"";
+	}
+
+	// Set the sponsor of the collection.
+	//
+	// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
+	//
+	// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
+	//
+	// Selector: setCollectionSponsor(address) 7623402e
+	function setCollectionSponsor(address sponsor) public {
+		require(false, stub_error);
+		sponsor;
+		dummy = 0;
+	}
+
+	// Collection sponsorship confirmation.
+	//
+	// @dev After setting the sponsor for the collection, it must be confirmed with this function.
+	//
+	// Selector: confirmCollectionSponsorship() 3c50e97a
+	function confirmCollectionSponsorship() public {
+		require(false, stub_error);
+		dummy = 0;
+	}
+
+	// Set limits for the collection.
+	// @dev Throws error if limit not found.
+	// @param limit Name of the limit. Valid names:
+	// 	"accountTokenOwnershipLimit",
+	// 	"sponsoredDataSize",
+	// 	"sponsoredDataRateLimit",
+	// 	"tokenLimit",
+	// 	"sponsorTransferTimeout",
+	// 	"sponsorApproveTimeout"
+	// @param value Value of the limit.
+	//
+	// Selector: setCollectionLimit(string,uint32) 6a3841db
+	function setCollectionLimit(string memory limit, uint32 value) public {
+		require(false, stub_error);
+		limit;
+		value;
+		dummy = 0;
+	}
+
+	// Set limits for the collection.
+	// @dev Throws error if limit not found.
+	// @param limit Name of the limit. Valid names:
+	// 	"ownerCanTransfer",
+	// 	"ownerCanDestroy",
+	// 	"transfersEnabled"
+	// @param value Value of the limit.
+	//
+	// Selector: setCollectionLimit(string,bool) 993b7fba
+	function setCollectionLimit(string memory limit, bool value) public {
+		require(false, stub_error);
+		limit;
+		value;
+		dummy = 0;
+	}
+
+	// Get contract address.
+	//
+	// Selector: contractAddress() f6b4dfb4
+	function contractAddress() public view returns (address) {
+		require(false, stub_error);
+		dummy;
+		return 0x0000000000000000000000000000000000000000;
+	}
+
+	// Add collection admin by substrate address.
+	// @param new_admin Substrate administrator address.
+	//
+	// Selector: addCollectionAdminSubstrate(uint256) 5730062b
+	function addCollectionAdminSubstrate(uint256 newAdmin) public {
+		require(false, stub_error);
+		newAdmin;
+		dummy = 0;
+	}
+
+	// Remove collection admin by substrate address.
+	// @param admin Substrate administrator address.
+	//
+	// Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
+	function removeCollectionAdminSubstrate(uint256 admin) public {
+		require(false, stub_error);
+		admin;
+		dummy = 0;
+	}
+
+	// Add collection admin.
+	// @param new_admin Address of the added administrator.
+	//
+	// Selector: addCollectionAdmin(address) 92e462c7
+	function addCollectionAdmin(address newAdmin) public {
+		require(false, stub_error);
+		newAdmin;
+		dummy = 0;
+	}
+
+	// Remove collection admin.
+	//
+	// @param new_admin Address of the removed administrator.
+	//
+	// Selector: removeCollectionAdmin(address) fafd7b42
+	function removeCollectionAdmin(address admin) public {
+		require(false, stub_error);
+		admin;
+		dummy = 0;
+	}
+
+	// Toggle accessibility of collection nesting.
+	//
+	// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
+	//
+	// Selector: setCollectionNesting(bool) 112d4586
+	function setCollectionNesting(bool enable) public {
+		require(false, stub_error);
+		enable;
+		dummy = 0;
+	}
+
+	// Toggle accessibility of collection nesting.
+	//
+	// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
+	// @param collections Addresses of collections that will be available for nesting.
+	//
+	// Selector: setCollectionNesting(bool,address[]) 64872396
+	function setCollectionNesting(bool enable, address[] memory collections)
+		public
+	{
+		require(false, stub_error);
+		enable;
+		collections;
+		dummy = 0;
+	}
+
+	// Set the collection access method.
+	// @param mode Access mode
+	// 	0 for Normal
+	// 	1 for AllowList
+	//
+	// Selector: setCollectionAccess(uint8) 41835d4c
+	function setCollectionAccess(uint8 mode) public {
+		require(false, stub_error);
+		mode;
+		dummy = 0;
+	}
+
+	// Add the user to the allowed list.
+	//
+	// @param user Address of a trusted user.
+	//
+	// Selector: addToCollectionAllowList(address) 67844fe6
+	function addToCollectionAllowList(address user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
+	// Remove the user from the allowed list.
+	//
+	// @param user Address of a removed user.
+	//
+	// Selector: removeFromCollectionAllowList(address) 85c51acb
+	function removeFromCollectionAllowList(address user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
+	// Switch permission for minting.
+	//
+	// @param mode Enable if "true".
+	//
+	// Selector: setCollectionMintMode(bool) 00018e84
+	function setCollectionMintMode(bool mode) public {
+		require(false, stub_error);
+		mode;
+		dummy = 0;
+	}
+
+	// Check that account is the owner or admin of the collection
+	//
+	// @param user account to verify
+	// @return "true" if account is the owner or admin
+	//
+	// Selector: verifyOwnerOrAdmin(address) c2282493
+	function verifyOwnerOrAdmin(address user) public view returns (bool) {
+		require(false, stub_error);
+		user;
+		dummy;
+		return false;
+	}
+
+	// Check that substrate account is the owner or admin of the collection
+	//
+	// @param user account to verify
+	// @return "true" if account is the owner or admin
+	//
+	// Selector: verifyOwnerOrAdminSubstrate(uint256) fe818e40
+	function verifyOwnerOrAdminSubstrate(uint256 user)
+		public
+		view
+		returns (bool)
+	{
+		require(false, stub_error);
+		user;
+		dummy;
+		return false;
+	}
+
+	// Returns collection type
+	//
+	// @return `Fungible` or `NFT` or `ReFungible`
+	//
+	// Selector: uniqueCollectionType() d34b55b8
+	function uniqueCollectionType() public returns (string memory) {
+		require(false, stub_error);
+		dummy = 0;
+		return "";
+	}
+
+	// Changes collection owner to another account
+	//
+	// @dev Owner can be changed only by current owner
+	// @param newOwner new owner account
+	//
+	// Selector: changeOwner(address) a6f9dae1
+	function changeOwner(address newOwner) public {
+		require(false, stub_error);
+		newOwner;
+		dummy = 0;
+	}
+
+	// Changes collection owner to another substrate account
+	//
+	// @dev Owner can be changed only by current owner
+	// @param newOwner new owner substrate account
+	//
+	// Selector: changeOwnerSubstrate(uint256) 337e2c60
+	function changeOwnerSubstrate(uint256 newOwner) public {
+		require(false, stub_error);
+		newOwner;
+		dummy = 0;
+	}
+}
+
 // Selector: 41369377
 contract TokenProperties is Dummy, ERC165 {
 	// @notice Set permissions for token property.
@@ -503,269 +795,6 @@
 		token;
 		dummy;
 		return 0x0000000000000000000000000000000000000000;
-	}
-}
-
-// Selector: ca08c92c
-contract Collection is Dummy, ERC165 {
-	// Set collection property.
-	//
-	// @param key Property key.
-	// @param value Propery value.
-	//
-	// Selector: setCollectionProperty(string,bytes) 2f073f66
-	function setCollectionProperty(string memory key, bytes memory value)
-		public
-	{
-		require(false, stub_error);
-		key;
-		value;
-		dummy = 0;
-	}
-
-	// Delete collection property.
-	//
-	// @param key Property key.
-	//
-	// Selector: deleteCollectionProperty(string) 7b7debce
-	function deleteCollectionProperty(string memory key) public {
-		require(false, stub_error);
-		key;
-		dummy = 0;
-	}
-
-	// Get collection property.
-	//
-	// @dev Throws error if key not found.
-	//
-	// @param key Property key.
-	// @return bytes The property corresponding to the key.
-	//
-	// Selector: collectionProperty(string) cf24fd6d
-	function collectionProperty(string memory key)
-		public
-		view
-		returns (bytes memory)
-	{
-		require(false, stub_error);
-		key;
-		dummy;
-		return hex"";
-	}
-
-	// Set the sponsor of the collection.
-	//
-	// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
-	//
-	// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
-	//
-	// Selector: setCollectionSponsor(address) 7623402e
-	function setCollectionSponsor(address sponsor) public {
-		require(false, stub_error);
-		sponsor;
-		dummy = 0;
-	}
-
-	// Collection sponsorship confirmation.
-	//
-	// @dev After setting the sponsor for the collection, it must be confirmed with this function.
-	//
-	// Selector: confirmCollectionSponsorship() 3c50e97a
-	function confirmCollectionSponsorship() public {
-		require(false, stub_error);
-		dummy = 0;
-	}
-
-	// Set limits for the collection.
-	// @dev Throws error if limit not found.
-	// @param limit Name of the limit. Valid names:
-	// 	"accountTokenOwnershipLimit",
-	// 	"sponsoredDataSize",
-	// 	"sponsoredDataRateLimit",
-	// 	"tokenLimit",
-	// 	"sponsorTransferTimeout",
-	// 	"sponsorApproveTimeout"
-	// @param value Value of the limit.
-	//
-	// Selector: setCollectionLimit(string,uint32) 6a3841db
-	function setCollectionLimit(string memory limit, uint32 value) public {
-		require(false, stub_error);
-		limit;
-		value;
-		dummy = 0;
-	}
-
-	// Set limits for the collection.
-	// @dev Throws error if limit not found.
-	// @param limit Name of the limit. Valid names:
-	// 	"ownerCanTransfer",
-	// 	"ownerCanDestroy",
-	// 	"transfersEnabled"
-	// @param value Value of the limit.
-	//
-	// Selector: setCollectionLimit(string,bool) 993b7fba
-	function setCollectionLimit(string memory limit, bool value) public {
-		require(false, stub_error);
-		limit;
-		value;
-		dummy = 0;
-	}
-
-	// Get contract address.
-	//
-	// Selector: contractAddress() f6b4dfb4
-	function contractAddress() public view returns (address) {
-		require(false, stub_error);
-		dummy;
-		return 0x0000000000000000000000000000000000000000;
-	}
-
-	// Add collection admin by substrate address.
-	// @param new_admin Substrate administrator address.
-	//
-	// Selector: addCollectionAdminSubstrate(uint256) 5730062b
-	function addCollectionAdminSubstrate(uint256 newAdmin) public {
-		require(false, stub_error);
-		newAdmin;
-		dummy = 0;
-	}
-
-	// Remove collection admin by substrate address.
-	// @param admin Substrate administrator address.
-	//
-	// Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
-	function removeCollectionAdminSubstrate(uint256 admin) public {
-		require(false, stub_error);
-		admin;
-		dummy = 0;
-	}
-
-	// Add collection admin.
-	// @param new_admin Address of the added administrator.
-	//
-	// Selector: addCollectionAdmin(address) 92e462c7
-	function addCollectionAdmin(address newAdmin) public {
-		require(false, stub_error);
-		newAdmin;
-		dummy = 0;
-	}
-
-	// Remove collection admin.
-	//
-	// @param new_admin Address of the removed administrator.
-	//
-	// Selector: removeCollectionAdmin(address) fafd7b42
-	function removeCollectionAdmin(address admin) public {
-		require(false, stub_error);
-		admin;
-		dummy = 0;
-	}
-
-	// Toggle accessibility of collection nesting.
-	//
-	// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
-	//
-	// Selector: setCollectionNesting(bool) 112d4586
-	function setCollectionNesting(bool enable) public {
-		require(false, stub_error);
-		enable;
-		dummy = 0;
-	}
-
-	// Toggle accessibility of collection nesting.
-	//
-	// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
-	// @param collections Addresses of collections that will be available for nesting.
-	//
-	// Selector: setCollectionNesting(bool,address[]) 64872396
-	function setCollectionNesting(bool enable, address[] memory collections)
-		public
-	{
-		require(false, stub_error);
-		enable;
-		collections;
-		dummy = 0;
-	}
-
-	// Set the collection access method.
-	// @param mode Access mode
-	// 	0 for Normal
-	// 	1 for AllowList
-	//
-	// Selector: setCollectionAccess(uint8) 41835d4c
-	function setCollectionAccess(uint8 mode) public {
-		require(false, stub_error);
-		mode;
-		dummy = 0;
-	}
-
-	// Add the user to the allowed list.
-	//
-	// @param user Address of a trusted user.
-	//
-	// Selector: addToCollectionAllowList(address) 67844fe6
-	function addToCollectionAllowList(address user) public {
-		require(false, stub_error);
-		user;
-		dummy = 0;
-	}
-
-	// Remove the user from the allowed list.
-	//
-	// @param user Address of a removed user.
-	//
-	// Selector: removeFromCollectionAllowList(address) 85c51acb
-	function removeFromCollectionAllowList(address user) public {
-		require(false, stub_error);
-		user;
-		dummy = 0;
-	}
-
-	// Switch permission for minting.
-	//
-	// @param mode Enable if "true".
-	//
-	// Selector: setCollectionMintMode(bool) 00018e84
-	function setCollectionMintMode(bool mode) public {
-		require(false, stub_error);
-		mode;
-		dummy = 0;
-	}
-
-	// Check that account is the owner or admin of the collection
-	//
-	// @param user account to verify
-	// @return "true" if account is the owner or admin
-	//
-	// Selector: verifyOwnerOrAdmin(address) c2282493
-	function verifyOwnerOrAdmin(address user) public view returns (bool) {
-		require(false, stub_error);
-		user;
-		dummy;
-		return false;
-	}
-
-	// Returns collection type
-	//
-	// @return `Fungible` or `NFT` or `ReFungible`
-	//
-	// Selector: uniqueCollectionType() d34b55b8
-	function uniqueCollectionType() public returns (string memory) {
-		require(false, stub_error);
-		dummy = 0;
-		return "";
-	}
-
-	// Changes collection owner
-	//
-	// @dev Owner can be changed only by current owner
-	// @param newOwner new owner
-	//
-	// Selector: changeOwner(address) a6f9dae1
-	function changeOwner(address newOwner) public {
-		require(false, stub_error);
-		newOwner;
-		dummy = 0;
 	}
 }
 
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -22,50 +22,7 @@
 	);
 }
 
-// Selector: 79cc6790
-interface ERC20UniqueExtensions is Dummy, ERC165 {
-	// Selector: burnFrom(address,uint256) 79cc6790
-	function burnFrom(address from, uint256 amount) external returns (bool);
-}
-
-// Selector: 942e8b22
-interface ERC20 is Dummy, ERC165, ERC20Events {
-	// Selector: name() 06fdde03
-	function name() external view returns (string memory);
-
-	// Selector: symbol() 95d89b41
-	function symbol() external view returns (string memory);
-
-	// Selector: totalSupply() 18160ddd
-	function totalSupply() external view returns (uint256);
-
-	// Selector: decimals() 313ce567
-	function decimals() external view returns (uint8);
-
-	// Selector: balanceOf(address) 70a08231
-	function balanceOf(address owner) external view returns (uint256);
-
-	// Selector: transfer(address,uint256) a9059cbb
-	function transfer(address to, uint256 amount) external returns (bool);
-
-	// Selector: transferFrom(address,address,uint256) 23b872dd
-	function transferFrom(
-		address from,
-		address to,
-		uint256 amount
-	) external returns (bool);
-
-	// Selector: approve(address,uint256) 095ea7b3
-	function approve(address spender, uint256 amount) external returns (bool);
-
-	// Selector: allowance(address,address) dd62ed3e
-	function allowance(address owner, address spender)
-		external
-		view
-		returns (uint256);
-}
-
-// Selector: ca08c92c
+// Selector: 07f76b0c
 interface Collection is Dummy, ERC165 {
 	// Set collection property.
 	//
@@ -220,6 +177,17 @@
 	// Selector: verifyOwnerOrAdmin(address) c2282493
 	function verifyOwnerOrAdmin(address user) external view returns (bool);
 
+	// Check that substrate account is the owner or admin of the collection
+	//
+	// @param user account to verify
+	// @return "true" if account is the owner or admin
+	//
+	// Selector: verifyOwnerOrAdminSubstrate(uint256) fe818e40
+	function verifyOwnerOrAdminSubstrate(uint256 user)
+		external
+		view
+		returns (bool);
+
 	// Returns collection type
 	//
 	// @return `Fungible` or `NFT` or `ReFungible`
@@ -227,13 +195,64 @@
 	// Selector: uniqueCollectionType() d34b55b8
 	function uniqueCollectionType() external returns (string memory);
 
-	// Changes collection owner
+	// Changes collection owner to another account
 	//
 	// @dev Owner can be changed only by current owner
-	// @param newOwner new owner
+	// @param newOwner new owner account
 	//
 	// Selector: changeOwner(address) a6f9dae1
 	function changeOwner(address newOwner) external;
+
+	// Changes collection owner to another substrate account
+	//
+	// @dev Owner can be changed only by current owner
+	// @param newOwner new owner substrate account
+	//
+	// Selector: changeOwnerSubstrate(uint256) 337e2c60
+	function changeOwnerSubstrate(uint256 newOwner) external;
+}
+
+// Selector: 79cc6790
+interface ERC20UniqueExtensions is Dummy, ERC165 {
+	// Selector: burnFrom(address,uint256) 79cc6790
+	function burnFrom(address from, uint256 amount) external returns (bool);
+}
+
+// Selector: 942e8b22
+interface ERC20 is Dummy, ERC165, ERC20Events {
+	// Selector: name() 06fdde03
+	function name() external view returns (string memory);
+
+	// Selector: symbol() 95d89b41
+	function symbol() external view returns (string memory);
+
+	// Selector: totalSupply() 18160ddd
+	function totalSupply() external view returns (uint256);
+
+	// Selector: decimals() 313ce567
+	function decimals() external view returns (uint8);
+
+	// Selector: balanceOf(address) 70a08231
+	function balanceOf(address owner) external view returns (uint256);
+
+	// Selector: transfer(address,uint256) a9059cbb
+	function transfer(address to, uint256 amount) external returns (bool);
+
+	// Selector: transferFrom(address,address,uint256) 23b872dd
+	function transferFrom(
+		address from,
+		address to,
+		uint256 amount
+	) external returns (bool);
+
+	// Selector: approve(address,uint256) 095ea7b3
+	function approve(address spender, uint256 amount) external returns (bool);
+
+	// Selector: allowance(address,address) dd62ed3e
+	function allowance(address owner, address spender)
+		external
+		view
+		returns (uint256);
 }
 
 interface UniqueFungible is
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -42,6 +42,196 @@
 	event MintingFinished();
 }
 
+// Selector: 07f76b0c
+interface Collection is Dummy, ERC165 {
+	// Set collection property.
+	//
+	// @param key Property key.
+	// @param value Propery value.
+	//
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		external;
+
+	// Delete collection property.
+	//
+	// @param key Property key.
+	//
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) external;
+
+	// Get collection property.
+	//
+	// @dev Throws error if key not found.
+	//
+	// @param key Property key.
+	// @return bytes The property corresponding to the key.
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		external
+		view
+		returns (bytes memory);
+
+	// Set the sponsor of the collection.
+	//
+	// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
+	//
+	// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
+	//
+	// Selector: setCollectionSponsor(address) 7623402e
+	function setCollectionSponsor(address sponsor) external;
+
+	// Collection sponsorship confirmation.
+	//
+	// @dev After setting the sponsor for the collection, it must be confirmed with this function.
+	//
+	// Selector: confirmCollectionSponsorship() 3c50e97a
+	function confirmCollectionSponsorship() external;
+
+	// Set limits for the collection.
+	// @dev Throws error if limit not found.
+	// @param limit Name of the limit. Valid names:
+	// 	"accountTokenOwnershipLimit",
+	// 	"sponsoredDataSize",
+	// 	"sponsoredDataRateLimit",
+	// 	"tokenLimit",
+	// 	"sponsorTransferTimeout",
+	// 	"sponsorApproveTimeout"
+	// @param value Value of the limit.
+	//
+	// Selector: setCollectionLimit(string,uint32) 6a3841db
+	function setCollectionLimit(string memory limit, uint32 value) external;
+
+	// Set limits for the collection.
+	// @dev Throws error if limit not found.
+	// @param limit Name of the limit. Valid names:
+	// 	"ownerCanTransfer",
+	// 	"ownerCanDestroy",
+	// 	"transfersEnabled"
+	// @param value Value of the limit.
+	//
+	// Selector: setCollectionLimit(string,bool) 993b7fba
+	function setCollectionLimit(string memory limit, bool value) external;
+
+	// Get contract address.
+	//
+	// Selector: contractAddress() f6b4dfb4
+	function contractAddress() external view returns (address);
+
+	// Add collection admin by substrate address.
+	// @param new_admin Substrate administrator address.
+	//
+	// Selector: addCollectionAdminSubstrate(uint256) 5730062b
+	function addCollectionAdminSubstrate(uint256 newAdmin) external;
+
+	// Remove collection admin by substrate address.
+	// @param admin Substrate administrator address.
+	//
+	// Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
+	function removeCollectionAdminSubstrate(uint256 admin) external;
+
+	// Add collection admin.
+	// @param new_admin Address of the added administrator.
+	//
+	// Selector: addCollectionAdmin(address) 92e462c7
+	function addCollectionAdmin(address newAdmin) external;
+
+	// Remove collection admin.
+	//
+	// @param new_admin Address of the removed administrator.
+	//
+	// Selector: removeCollectionAdmin(address) fafd7b42
+	function removeCollectionAdmin(address admin) external;
+
+	// Toggle accessibility of collection nesting.
+	//
+	// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
+	//
+	// Selector: setCollectionNesting(bool) 112d4586
+	function setCollectionNesting(bool enable) external;
+
+	// Toggle accessibility of collection nesting.
+	//
+	// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
+	// @param collections Addresses of collections that will be available for nesting.
+	//
+	// Selector: setCollectionNesting(bool,address[]) 64872396
+	function setCollectionNesting(bool enable, address[] memory collections)
+		external;
+
+	// Set the collection access method.
+	// @param mode Access mode
+	// 	0 for Normal
+	// 	1 for AllowList
+	//
+	// Selector: setCollectionAccess(uint8) 41835d4c
+	function setCollectionAccess(uint8 mode) external;
+
+	// Add the user to the allowed list.
+	//
+	// @param user Address of a trusted user.
+	//
+	// Selector: addToCollectionAllowList(address) 67844fe6
+	function addToCollectionAllowList(address user) external;
+
+	// Remove the user from the allowed list.
+	//
+	// @param user Address of a removed user.
+	//
+	// Selector: removeFromCollectionAllowList(address) 85c51acb
+	function removeFromCollectionAllowList(address user) external;
+
+	// Switch permission for minting.
+	//
+	// @param mode Enable if "true".
+	//
+	// Selector: setCollectionMintMode(bool) 00018e84
+	function setCollectionMintMode(bool mode) external;
+
+	// Check that account is the owner or admin of the collection
+	//
+	// @param user account to verify
+	// @return "true" if account is the owner or admin
+	//
+	// Selector: verifyOwnerOrAdmin(address) c2282493
+	function verifyOwnerOrAdmin(address user) external view returns (bool);
+
+	// Check that substrate account is the owner or admin of the collection
+	//
+	// @param user account to verify
+	// @return "true" if account is the owner or admin
+	//
+	// Selector: verifyOwnerOrAdminSubstrate(uint256) fe818e40
+	function verifyOwnerOrAdminSubstrate(uint256 user)
+		external
+		view
+		returns (bool);
+
+	// Returns collection type
+	//
+	// @return `Fungible` or `NFT` or `ReFungible`
+	//
+	// Selector: uniqueCollectionType() d34b55b8
+	function uniqueCollectionType() external returns (string memory);
+
+	// Changes collection owner to another account
+	//
+	// @dev Owner can be changed only by current owner
+	// @param newOwner new owner account
+	//
+	// Selector: changeOwner(address) a6f9dae1
+	function changeOwner(address newOwner) external;
+
+	// Changes collection owner to another substrate account
+	//
+	// @dev Owner can be changed only by current owner
+	// @param newOwner new owner substrate account
+	//
+	// Selector: changeOwnerSubstrate(uint256) 337e2c60
+	function changeOwnerSubstrate(uint256 newOwner) external;
+}
+
 // Selector: 41369377
 interface TokenProperties is Dummy, ERC165 {
 	// @notice Set permissions for token property.
@@ -274,177 +464,6 @@
 	//
 	// Selector: totalSupply() 18160ddd
 	function totalSupply() external view returns (uint256);
-}
-
-// Selector: ca08c92c
-interface Collection is Dummy, ERC165 {
-	// Set collection property.
-	//
-	// @param key Property key.
-	// @param value Propery value.
-	//
-	// Selector: setCollectionProperty(string,bytes) 2f073f66
-	function setCollectionProperty(string memory key, bytes memory value)
-		external;
-
-	// Delete collection property.
-	//
-	// @param key Property key.
-	//
-	// Selector: deleteCollectionProperty(string) 7b7debce
-	function deleteCollectionProperty(string memory key) external;
-
-	// Get collection property.
-	//
-	// @dev Throws error if key not found.
-	//
-	// @param key Property key.
-	// @return bytes The property corresponding to the key.
-	//
-	// Selector: collectionProperty(string) cf24fd6d
-	function collectionProperty(string memory key)
-		external
-		view
-		returns (bytes memory);
-
-	// Set the sponsor of the collection.
-	//
-	// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
-	//
-	// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
-	//
-	// Selector: setCollectionSponsor(address) 7623402e
-	function setCollectionSponsor(address sponsor) external;
-
-	// Collection sponsorship confirmation.
-	//
-	// @dev After setting the sponsor for the collection, it must be confirmed with this function.
-	//
-	// Selector: confirmCollectionSponsorship() 3c50e97a
-	function confirmCollectionSponsorship() external;
-
-	// Set limits for the collection.
-	// @dev Throws error if limit not found.
-	// @param limit Name of the limit. Valid names:
-	// 	"accountTokenOwnershipLimit",
-	// 	"sponsoredDataSize",
-	// 	"sponsoredDataRateLimit",
-	// 	"tokenLimit",
-	// 	"sponsorTransferTimeout",
-	// 	"sponsorApproveTimeout"
-	// @param value Value of the limit.
-	//
-	// Selector: setCollectionLimit(string,uint32) 6a3841db
-	function setCollectionLimit(string memory limit, uint32 value) external;
-
-	// Set limits for the collection.
-	// @dev Throws error if limit not found.
-	// @param limit Name of the limit. Valid names:
-	// 	"ownerCanTransfer",
-	// 	"ownerCanDestroy",
-	// 	"transfersEnabled"
-	// @param value Value of the limit.
-	//
-	// Selector: setCollectionLimit(string,bool) 993b7fba
-	function setCollectionLimit(string memory limit, bool value) external;
-
-	// Get contract address.
-	//
-	// Selector: contractAddress() f6b4dfb4
-	function contractAddress() external view returns (address);
-
-	// Add collection admin by substrate address.
-	// @param new_admin Substrate administrator address.
-	//
-	// Selector: addCollectionAdminSubstrate(uint256) 5730062b
-	function addCollectionAdminSubstrate(uint256 newAdmin) external;
-
-	// Remove collection admin by substrate address.
-	// @param admin Substrate administrator address.
-	//
-	// Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
-	function removeCollectionAdminSubstrate(uint256 admin) external;
-
-	// Add collection admin.
-	// @param new_admin Address of the added administrator.
-	//
-	// Selector: addCollectionAdmin(address) 92e462c7
-	function addCollectionAdmin(address newAdmin) external;
-
-	// Remove collection admin.
-	//
-	// @param new_admin Address of the removed administrator.
-	//
-	// Selector: removeCollectionAdmin(address) fafd7b42
-	function removeCollectionAdmin(address admin) external;
-
-	// Toggle accessibility of collection nesting.
-	//
-	// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
-	//
-	// Selector: setCollectionNesting(bool) 112d4586
-	function setCollectionNesting(bool enable) external;
-
-	// Toggle accessibility of collection nesting.
-	//
-	// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
-	// @param collections Addresses of collections that will be available for nesting.
-	//
-	// Selector: setCollectionNesting(bool,address[]) 64872396
-	function setCollectionNesting(bool enable, address[] memory collections)
-		external;
-
-	// Set the collection access method.
-	// @param mode Access mode
-	// 	0 for Normal
-	// 	1 for AllowList
-	//
-	// Selector: setCollectionAccess(uint8) 41835d4c
-	function setCollectionAccess(uint8 mode) external;
-
-	// Add the user to the allowed list.
-	//
-	// @param user Address of a trusted user.
-	//
-	// Selector: addToCollectionAllowList(address) 67844fe6
-	function addToCollectionAllowList(address user) external;
-
-	// Remove the user from the allowed list.
-	//
-	// @param user Address of a removed user.
-	//
-	// Selector: removeFromCollectionAllowList(address) 85c51acb
-	function removeFromCollectionAllowList(address user) external;
-
-	// Switch permission for minting.
-	//
-	// @param mode Enable if "true".
-	//
-	// Selector: setCollectionMintMode(bool) 00018e84
-	function setCollectionMintMode(bool mode) external;
-
-	// Check that account is the owner or admin of the collection
-	//
-	// @param user account to verify
-	// @return "true" if account is the owner or admin
-	//
-	// Selector: verifyOwnerOrAdmin(address) c2282493
-	function verifyOwnerOrAdmin(address user) external view returns (bool);
-
-	// Returns collection type
-	//
-	// @return `Fungible` or `NFT` or `ReFungible`
-	//
-	// Selector: uniqueCollectionType() d34b55b8
-	function uniqueCollectionType() external returns (string memory);
-
-	// Changes collection owner
-	//
-	// @dev Owner can be changed only by current owner
-	// @param newOwner new owner
-	//
-	// Selector: changeOwner(address) a6f9dae1
-	function changeOwner(address newOwner) external;
 }
 
 // Selector: d74d154f
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -42,6 +42,196 @@
 	event MintingFinished();
 }
 
+// Selector: 07f76b0c
+interface Collection is Dummy, ERC165 {
+	// Set collection property.
+	//
+	// @param key Property key.
+	// @param value Propery value.
+	//
+	// Selector: setCollectionProperty(string,bytes) 2f073f66
+	function setCollectionProperty(string memory key, bytes memory value)
+		external;
+
+	// Delete collection property.
+	//
+	// @param key Property key.
+	//
+	// Selector: deleteCollectionProperty(string) 7b7debce
+	function deleteCollectionProperty(string memory key) external;
+
+	// Get collection property.
+	//
+	// @dev Throws error if key not found.
+	//
+	// @param key Property key.
+	// @return bytes The property corresponding to the key.
+	//
+	// Selector: collectionProperty(string) cf24fd6d
+	function collectionProperty(string memory key)
+		external
+		view
+		returns (bytes memory);
+
+	// Set the sponsor of the collection.
+	//
+	// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
+	//
+	// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
+	//
+	// Selector: setCollectionSponsor(address) 7623402e
+	function setCollectionSponsor(address sponsor) external;
+
+	// Collection sponsorship confirmation.
+	//
+	// @dev After setting the sponsor for the collection, it must be confirmed with this function.
+	//
+	// Selector: confirmCollectionSponsorship() 3c50e97a
+	function confirmCollectionSponsorship() external;
+
+	// Set limits for the collection.
+	// @dev Throws error if limit not found.
+	// @param limit Name of the limit. Valid names:
+	// 	"accountTokenOwnershipLimit",
+	// 	"sponsoredDataSize",
+	// 	"sponsoredDataRateLimit",
+	// 	"tokenLimit",
+	// 	"sponsorTransferTimeout",
+	// 	"sponsorApproveTimeout"
+	// @param value Value of the limit.
+	//
+	// Selector: setCollectionLimit(string,uint32) 6a3841db
+	function setCollectionLimit(string memory limit, uint32 value) external;
+
+	// Set limits for the collection.
+	// @dev Throws error if limit not found.
+	// @param limit Name of the limit. Valid names:
+	// 	"ownerCanTransfer",
+	// 	"ownerCanDestroy",
+	// 	"transfersEnabled"
+	// @param value Value of the limit.
+	//
+	// Selector: setCollectionLimit(string,bool) 993b7fba
+	function setCollectionLimit(string memory limit, bool value) external;
+
+	// Get contract address.
+	//
+	// Selector: contractAddress() f6b4dfb4
+	function contractAddress() external view returns (address);
+
+	// Add collection admin by substrate address.
+	// @param new_admin Substrate administrator address.
+	//
+	// Selector: addCollectionAdminSubstrate(uint256) 5730062b
+	function addCollectionAdminSubstrate(uint256 newAdmin) external;
+
+	// Remove collection admin by substrate address.
+	// @param admin Substrate administrator address.
+	//
+	// Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
+	function removeCollectionAdminSubstrate(uint256 admin) external;
+
+	// Add collection admin.
+	// @param new_admin Address of the added administrator.
+	//
+	// Selector: addCollectionAdmin(address) 92e462c7
+	function addCollectionAdmin(address newAdmin) external;
+
+	// Remove collection admin.
+	//
+	// @param new_admin Address of the removed administrator.
+	//
+	// Selector: removeCollectionAdmin(address) fafd7b42
+	function removeCollectionAdmin(address admin) external;
+
+	// Toggle accessibility of collection nesting.
+	//
+	// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
+	//
+	// Selector: setCollectionNesting(bool) 112d4586
+	function setCollectionNesting(bool enable) external;
+
+	// Toggle accessibility of collection nesting.
+	//
+	// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
+	// @param collections Addresses of collections that will be available for nesting.
+	//
+	// Selector: setCollectionNesting(bool,address[]) 64872396
+	function setCollectionNesting(bool enable, address[] memory collections)
+		external;
+
+	// Set the collection access method.
+	// @param mode Access mode
+	// 	0 for Normal
+	// 	1 for AllowList
+	//
+	// Selector: setCollectionAccess(uint8) 41835d4c
+	function setCollectionAccess(uint8 mode) external;
+
+	// Add the user to the allowed list.
+	//
+	// @param user Address of a trusted user.
+	//
+	// Selector: addToCollectionAllowList(address) 67844fe6
+	function addToCollectionAllowList(address user) external;
+
+	// Remove the user from the allowed list.
+	//
+	// @param user Address of a removed user.
+	//
+	// Selector: removeFromCollectionAllowList(address) 85c51acb
+	function removeFromCollectionAllowList(address user) external;
+
+	// Switch permission for minting.
+	//
+	// @param mode Enable if "true".
+	//
+	// Selector: setCollectionMintMode(bool) 00018e84
+	function setCollectionMintMode(bool mode) external;
+
+	// Check that account is the owner or admin of the collection
+	//
+	// @param user account to verify
+	// @return "true" if account is the owner or admin
+	//
+	// Selector: verifyOwnerOrAdmin(address) c2282493
+	function verifyOwnerOrAdmin(address user) external view returns (bool);
+
+	// Check that substrate account is the owner or admin of the collection
+	//
+	// @param user account to verify
+	// @return "true" if account is the owner or admin
+	//
+	// Selector: verifyOwnerOrAdminSubstrate(uint256) fe818e40
+	function verifyOwnerOrAdminSubstrate(uint256 user)
+		external
+		view
+		returns (bool);
+
+	// Returns collection type
+	//
+	// @return `Fungible` or `NFT` or `ReFungible`
+	//
+	// Selector: uniqueCollectionType() d34b55b8
+	function uniqueCollectionType() external returns (string memory);
+
+	// Changes collection owner to another account
+	//
+	// @dev Owner can be changed only by current owner
+	// @param newOwner new owner account
+	//
+	// Selector: changeOwner(address) a6f9dae1
+	function changeOwner(address newOwner) external;
+
+	// Changes collection owner to another substrate account
+	//
+	// @dev Owner can be changed only by current owner
+	// @param newOwner new owner substrate account
+	//
+	// Selector: changeOwnerSubstrate(uint256) 337e2c60
+	function changeOwnerSubstrate(uint256 newOwner) external;
+}
+
 // Selector: 41369377
 interface TokenProperties is Dummy, ERC165 {
 	// @notice Set permissions for token property.
@@ -335,177 +525,6 @@
 		external
 		view
 		returns (address);
-}
-
-// Selector: ca08c92c
-interface Collection is Dummy, ERC165 {
-	// Set collection property.
-	//
-	// @param key Property key.
-	// @param value Propery value.
-	//
-	// Selector: setCollectionProperty(string,bytes) 2f073f66
-	function setCollectionProperty(string memory key, bytes memory value)
-		external;
-
-	// Delete collection property.
-	//
-	// @param key Property key.
-	//
-	// Selector: deleteCollectionProperty(string) 7b7debce
-	function deleteCollectionProperty(string memory key) external;
-
-	// Get collection property.
-	//
-	// @dev Throws error if key not found.
-	//
-	// @param key Property key.
-	// @return bytes The property corresponding to the key.
-	//
-	// Selector: collectionProperty(string) cf24fd6d
-	function collectionProperty(string memory key)
-		external
-		view
-		returns (bytes memory);
-
-	// Set the sponsor of the collection.
-	//
-	// @dev In order for sponsorship to work, it must be confirmed on behalf of the sponsor.
-	//
-	// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
-	//
-	// Selector: setCollectionSponsor(address) 7623402e
-	function setCollectionSponsor(address sponsor) external;
-
-	// Collection sponsorship confirmation.
-	//
-	// @dev After setting the sponsor for the collection, it must be confirmed with this function.
-	//
-	// Selector: confirmCollectionSponsorship() 3c50e97a
-	function confirmCollectionSponsorship() external;
-
-	// Set limits for the collection.
-	// @dev Throws error if limit not found.
-	// @param limit Name of the limit. Valid names:
-	// 	"accountTokenOwnershipLimit",
-	// 	"sponsoredDataSize",
-	// 	"sponsoredDataRateLimit",
-	// 	"tokenLimit",
-	// 	"sponsorTransferTimeout",
-	// 	"sponsorApproveTimeout"
-	// @param value Value of the limit.
-	//
-	// Selector: setCollectionLimit(string,uint32) 6a3841db
-	function setCollectionLimit(string memory limit, uint32 value) external;
-
-	// Set limits for the collection.
-	// @dev Throws error if limit not found.
-	// @param limit Name of the limit. Valid names:
-	// 	"ownerCanTransfer",
-	// 	"ownerCanDestroy",
-	// 	"transfersEnabled"
-	// @param value Value of the limit.
-	//
-	// Selector: setCollectionLimit(string,bool) 993b7fba
-	function setCollectionLimit(string memory limit, bool value) external;
-
-	// Get contract address.
-	//
-	// Selector: contractAddress() f6b4dfb4
-	function contractAddress() external view returns (address);
-
-	// Add collection admin by substrate address.
-	// @param new_admin Substrate administrator address.
-	//
-	// Selector: addCollectionAdminSubstrate(uint256) 5730062b
-	function addCollectionAdminSubstrate(uint256 newAdmin) external;
-
-	// Remove collection admin by substrate address.
-	// @param admin Substrate administrator address.
-	//
-	// Selector: removeCollectionAdminSubstrate(uint256) 4048fcf9
-	function removeCollectionAdminSubstrate(uint256 admin) external;
-
-	// Add collection admin.
-	// @param new_admin Address of the added administrator.
-	//
-	// Selector: addCollectionAdmin(address) 92e462c7
-	function addCollectionAdmin(address newAdmin) external;
-
-	// Remove collection admin.
-	//
-	// @param new_admin Address of the removed administrator.
-	//
-	// Selector: removeCollectionAdmin(address) fafd7b42
-	function removeCollectionAdmin(address admin) external;
-
-	// Toggle accessibility of collection nesting.
-	//
-	// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
-	//
-	// Selector: setCollectionNesting(bool) 112d4586
-	function setCollectionNesting(bool enable) external;
-
-	// Toggle accessibility of collection nesting.
-	//
-	// @param enable If "true" degenerates to nesting: {OwnerRestricted: [1, 2, 3]} else to nesting: 'Disabled'
-	// @param collections Addresses of collections that will be available for nesting.
-	//
-	// Selector: setCollectionNesting(bool,address[]) 64872396
-	function setCollectionNesting(bool enable, address[] memory collections)
-		external;
-
-	// Set the collection access method.
-	// @param mode Access mode
-	// 	0 for Normal
-	// 	1 for AllowList
-	//
-	// Selector: setCollectionAccess(uint8) 41835d4c
-	function setCollectionAccess(uint8 mode) external;
-
-	// Add the user to the allowed list.
-	//
-	// @param user Address of a trusted user.
-	//
-	// Selector: addToCollectionAllowList(address) 67844fe6
-	function addToCollectionAllowList(address user) external;
-
-	// Remove the user from the allowed list.
-	//
-	// @param user Address of a removed user.
-	//
-	// Selector: removeFromCollectionAllowList(address) 85c51acb
-	function removeFromCollectionAllowList(address user) external;
-
-	// Switch permission for minting.
-	//
-	// @param mode Enable if "true".
-	//
-	// Selector: setCollectionMintMode(bool) 00018e84
-	function setCollectionMintMode(bool mode) external;
-
-	// Check that account is the owner or admin of the collection
-	//
-	// @param user account to verify
-	// @return "true" if account is the owner or admin
-	//
-	// Selector: verifyOwnerOrAdmin(address) c2282493
-	function verifyOwnerOrAdmin(address user) external view returns (bool);
-
-	// Returns collection type
-	//
-	// @return `Fungible` or `NFT` or `ReFungible`
-	//
-	// Selector: uniqueCollectionType() d34b55b8
-	function uniqueCollectionType() external returns (string memory);
-
-	// Changes collection owner
-	//
-	// @dev Owner can be changed only by current owner
-	// @param newOwner new owner
-	//
-	// Selector: changeOwner(address) a6f9dae1
-	function changeOwner(address newOwner) external;
 }
 
 interface UniqueRefungible is
modifiedtests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth
--- a/tests/src/eth/collectionAdmin.test.ts
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -24,6 +24,7 @@
   getCollectionAddressFromResult, 
   itWeb3,
   recordEthFee,
+  subToEth,
 } from './util/helpers';
 
 describe('Add collection admins', () => {
@@ -358,4 +359,54 @@
     await expect(collectionEvm.methods.changeOwner(newOwner).send({from: newOwner})).to.be.rejected;
     expect(await collectionEvm.methods.verifyOwnerOrAdmin(newOwner).call()).to.be.false;
   });
+});
+
+describe('Change substrate owner tests', () => {
+  itWeb3('Change owner', async ({api, web3, privateKeyWrapper}) => {
+    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+    const newOwner = privateKeyWrapper('//Alice');
+    const collectionHelper = evmCollectionHelpers(web3, owner);
+    const result = await collectionHelper.methods
+      .createNonfungibleCollection('A', 'B', 'C')
+      .send();
+    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
+    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+  
+    expect(await collectionEvm.methods.verifyOwnerOrAdmin(owner).call()).to.be.true;
+    expect(await collectionEvm.methods.verifyOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;
+    await collectionEvm.methods.changeOwnerSubstrate(newOwner.addressRaw).send();
+  
+    expect(await collectionEvm.methods.verifyOwnerOrAdmin(owner).call()).to.be.false;
+    expect(await collectionEvm.methods.verifyOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.true;
+  });
+
+  itWeb3('change owner call fee', async ({web3, api, privateKeyWrapper}) => {
+    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+    const newOwner = privateKeyWrapper('//Alice');
+    const collectionHelper = evmCollectionHelpers(web3, owner);
+    const result = await collectionHelper.methods
+      .createNonfungibleCollection('A', 'B', 'C')
+      .send();
+    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
+    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+
+    const cost = await recordEthFee(api, owner, () => collectionEvm.methods.changeOwnerSubstrate(newOwner.addressRaw).send());
+    expect(cost < BigInt(0.2 * Number(UNIQUE)));
+    expect(cost > 0);
+  });
+
+  itWeb3('(!negative tests!) call changeOwner by not owner', async ({api, web3, privateKeyWrapper}) => {
+    const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+    const otherReceiver = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+    const newOwner = privateKeyWrapper('//Alice');
+    const collectionHelper = evmCollectionHelpers(web3, owner);
+    const result = await collectionHelper.methods
+      .createNonfungibleCollection('A', 'B', 'C')
+      .send();
+    const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
+    const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+  
+    await expect(collectionEvm.methods.changeOwnerSubstrate(newOwner.addressRaw).send({from: otherReceiver})).to.be.rejected;
+    expect(await collectionEvm.methods.verifyOwnerOrAdminSubstrate(newOwner.addressRaw).call()).to.be.false;
+  });
 });
\ No newline at end of file
modifiedtests/src/eth/fungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/fungibleAbi.json
+++ b/tests/src/eth/fungibleAbi.json
@@ -125,6 +125,15 @@
     "type": "function"
   },
   {
+    "inputs": [
+      { "internalType": "uint256", "name": "newOwner", "type": "uint256" }
+    ],
+    "name": "changeOwnerSubstrate",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
     "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
     "name": "collectionProperty",
     "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }],
@@ -326,5 +335,14 @@
     "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
     "stateMutability": "view",
     "type": "function"
+  },
+  {
+    "inputs": [
+      { "internalType": "uint256", "name": "user", "type": "uint256" }
+    ],
+    "name": "verifyOwnerOrAdminSubstrate",
+    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+    "stateMutability": "view",
+    "type": "function"
   }
 ]
modifiedtests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -155,6 +155,15 @@
     "type": "function"
   },
   {
+    "inputs": [
+      { "internalType": "uint256", "name": "newOwner", "type": "uint256" }
+    ],
+    "name": "changeOwnerSubstrate",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
     "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
     "name": "collectionProperty",
     "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }],
@@ -551,5 +560,14 @@
     "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
     "stateMutability": "view",
     "type": "function"
+  },
+  {
+    "inputs": [
+      { "internalType": "uint256", "name": "user", "type": "uint256" }
+    ],
+    "name": "verifyOwnerOrAdminSubstrate",
+    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+    "stateMutability": "view",
+    "type": "function"
   }
 ]
modifiedtests/src/eth/reFungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/reFungibleAbi.json
+++ b/tests/src/eth/reFungibleAbi.json
@@ -155,6 +155,15 @@
     "type": "function"
   },
   {
+    "inputs": [
+      { "internalType": "uint256", "name": "newOwner", "type": "uint256" }
+    ],
+    "name": "changeOwnerSubstrate",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
     "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
     "name": "collectionProperty",
     "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }],
@@ -560,5 +569,14 @@
     "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
     "stateMutability": "view",
     "type": "function"
+  },
+  {
+    "inputs": [
+      { "internalType": "uint256", "name": "user", "type": "uint256" }
+    ],
+    "name": "verifyOwnerOrAdminSubstrate",
+    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+    "stateMutability": "view",
+    "type": "function"
   }
 ]