git.delta.rocks / unique-network / refs/commits / 0d4bed32f053

difftreelog

Merge pull request #574 from UniqueNetwork/feature/eth_passthrought

Yaroslav Bolyukin2022-09-14parents: #a711701 #d8d2ace.patch.diff
in: master
Feature/eth passthrought

19 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -20,6 +20,7 @@
 	solidity_interface, solidity, ToLog,
 	types::*,
 	execution::{Result, Error},
+	weight,
 };
 pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};
 use pallet_evm_coder_substrate::dispatch_to_evm;
@@ -31,8 +32,12 @@
 use alloc::format;
 
 use crate::{
-	Pallet, CollectionHandle, Config, CollectionProperties,
-	eth::{convert_cross_account_to_uint256, convert_uint256_to_cross_account},
+	Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,
+	eth::{
+		convert_cross_account_to_uint256, convert_uint256_to_cross_account,
+		convert_cross_account_to_tuple,
+	},
+	weights::WeightInfo,
 };
 
 /// Events for ethereum collection helper.
@@ -69,6 +74,7 @@
 	///
 	/// @param key Property key.
 	/// @param value Propery value.
+	#[weight(<SelfWeightOf<T>>::set_collection_properties(1))]
 	fn set_collection_property(
 		&mut self,
 		caller: caller,
@@ -88,7 +94,10 @@
 	/// Delete collection property.
 	///
 	/// @param key Property key.
+	#[weight(<SelfWeightOf<T>>::delete_collection_properties(1))]
 	fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {
+		self.consume_store_reads_and_writes(1, 1)?;
+
 		let caller = T::CrossAccountId::from_eth(caller);
 		let key = <Vec<u8>>::from(key)
 			.try_into()
@@ -120,6 +129,8 @@
 	///
 	/// @param sponsor Address of the sponsor from whose account funds will be debited for operations with the contract.
 	fn set_collection_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {
+		self.consume_store_reads_and_writes(1, 1)?;
+
 		check_is_owner_or_admin(caller, self)?;
 
 		let sponsor = T::CrossAccountId::from_eth(sponsor);
@@ -138,6 +149,8 @@
 		caller: caller,
 		sponsor: uint256,
 	) -> Result<void> {
+		self.consume_store_reads_and_writes(1, 1)?;
+
 		check_is_owner_or_admin(caller, self)?;
 
 		let sponsor = convert_uint256_to_cross_account::<T>(sponsor);
@@ -146,7 +159,7 @@
 		save(self)
 	}
 
-	// /// Whether there is a pending sponsor.
+	/// Whether there is a pending sponsor.
 	fn has_collection_pending_sponsor(&self) -> Result<bool> {
 		Ok(matches!(
 			self.collection.sponsorship,
@@ -158,6 +171,8 @@
 	///
 	/// @dev After setting the sponsor for the collection, it must be confirmed with this function.
 	fn confirm_collection_sponsorship(&mut self, caller: caller) -> Result<void> {
+		self.consume_store_writes(1)?;
+
 		let caller = T::CrossAccountId::from_eth(caller);
 		if !self
 			.confirm_sponsorship(caller.as_sub())
@@ -170,6 +185,7 @@
 
 	/// Remove collection sponsor.
 	fn remove_collection_sponsor(&mut self, caller: caller) -> Result<void> {
+		self.consume_store_reads_and_writes(1, 1)?;
 		check_is_owner_or_admin(caller, self)?;
 		self.remove_sponsor().map_err(dispatch_to_evm::<T>)?;
 		save(self)
@@ -206,6 +222,8 @@
 	/// @param value Value of the limit.
 	#[solidity(rename_selector = "setCollectionLimit")]
 	fn set_int_limit(&mut self, caller: caller, limit: string, value: uint32) -> Result<void> {
+		self.consume_store_reads_and_writes(1, 1)?;
+
 		check_is_owner_or_admin(caller, self)?;
 		let mut limits = self.limits.clone();
 
@@ -249,6 +267,8 @@
 	/// @param value Value of the limit.
 	#[solidity(rename_selector = "setCollectionLimit")]
 	fn set_bool_limit(&mut self, caller: caller, limit: string, value: bool) -> Result<void> {
+		self.consume_store_reads_and_writes(1, 1)?;
+
 		check_is_owner_or_admin(caller, self)?;
 		let mut limits = self.limits.clone();
 
@@ -275,7 +295,7 @@
 	}
 
 	/// Get contract address.
-	fn contract_address(&self, _caller: caller) -> Result<address> {
+	fn contract_address(&self) -> Result<address> {
 		Ok(crate::eth::collection_id_to_address(self.id))
 	}
 
@@ -286,6 +306,8 @@
 		caller: caller,
 		new_admin: uint256,
 	) -> Result<void> {
+		self.consume_store_writes(2)?;
+
 		let caller = T::CrossAccountId::from_eth(caller);
 		let new_admin = convert_uint256_to_cross_account::<T>(new_admin);
 		<Pallet<T>>::toggle_admin(self, &caller, &new_admin, true).map_err(dispatch_to_evm::<T>)?;
@@ -299,6 +321,8 @@
 		caller: caller,
 		admin: uint256,
 	) -> Result<void> {
+		self.consume_store_writes(2)?;
+
 		let caller = T::CrossAccountId::from_eth(caller);
 		let admin = convert_uint256_to_cross_account::<T>(admin);
 		<Pallet<T>>::toggle_admin(self, &caller, &admin, false).map_err(dispatch_to_evm::<T>)?;
@@ -308,6 +332,8 @@
 	/// Add collection admin.
 	/// @param newAdmin Address of the added administrator.
 	fn add_collection_admin(&mut self, caller: caller, new_admin: address) -> Result<void> {
+		self.consume_store_writes(2)?;
+
 		let caller = T::CrossAccountId::from_eth(caller);
 		let new_admin = T::CrossAccountId::from_eth(new_admin);
 		<Pallet<T>>::toggle_admin(self, &caller, &new_admin, true).map_err(dispatch_to_evm::<T>)?;
@@ -318,6 +344,8 @@
 	///
 	/// @param admin Address of the removed administrator.
 	fn remove_collection_admin(&mut self, caller: caller, admin: address) -> Result<void> {
+		self.consume_store_writes(2)?;
+
 		let caller = T::CrossAccountId::from_eth(caller);
 		let admin = T::CrossAccountId::from_eth(admin);
 		<Pallet<T>>::toggle_admin(self, &caller, &admin, false).map_err(dispatch_to_evm::<T>)?;
@@ -329,6 +357,8 @@
 	/// @param enable If "true" degenerates to nesting: 'Owner' else to nesting: 'Disabled'
 	#[solidity(rename_selector = "setCollectionNesting")]
 	fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {
+		self.consume_store_reads_and_writes(1, 1)?;
+
 		check_is_owner_or_admin(caller, self)?;
 
 		let mut permissions = self.collection.permissions.clone();
@@ -358,6 +388,8 @@
 		enable: bool,
 		collections: Vec<address>,
 	) -> Result<void> {
+		self.consume_store_reads_and_writes(1, 1)?;
+
 		if collections.is_empty() {
 			return Err("no addresses provided".into());
 		}
@@ -401,6 +433,8 @@
 	/// 	0 for Normal
 	/// 	1 for AllowList
 	fn set_collection_access(&mut self, caller: caller, mode: uint8) -> Result<void> {
+		self.consume_store_reads_and_writes(1, 1)?;
+
 		check_is_owner_or_admin(caller, self)?;
 		let permissions = CollectionPermissions {
 			access: Some(match mode {
@@ -420,30 +454,78 @@
 		save(self)
 	}
 
+	/// Checks that user allowed to operate with collection.
+	///
+	/// @param user User address to check.
+	fn allowed(&self, user: address) -> Result<bool> {
+		Ok(Pallet::<T>::allowed(
+			self.id,
+			T::CrossAccountId::from_eth(user),
+		))
+	}
+
 	/// Add the user to the allowed list.
 	///
 	/// @param user Address of a trusted user.
 	fn add_to_collection_allow_list(&mut self, caller: caller, user: address) -> Result<void> {
+		self.consume_store_writes(1)?;
+
 		let caller = T::CrossAccountId::from_eth(caller);
 		let user = T::CrossAccountId::from_eth(user);
 		<Pallet<T>>::toggle_allowlist(self, &caller, &user, true).map_err(dispatch_to_evm::<T>)?;
 		Ok(())
 	}
 
+	/// Add substrate user to allowed list.
+	///
+	/// @param user User substrate address.
+	fn add_to_collection_allow_list_substrate(
+		&mut self,
+		caller: caller,
+		user: uint256,
+	) -> Result<void> {
+		self.consume_store_writes(1)?;
+
+		let caller = T::CrossAccountId::from_eth(caller);
+		let user = convert_uint256_to_cross_account::<T>(user);
+		Pallet::<T>::toggle_allowlist(self, &caller, &user, true).map_err(dispatch_to_evm::<T>)?;
+		Ok(())
+	}
+
 	/// Remove the user from the allowed list.
 	///
 	/// @param user Address of a removed user.
 	fn remove_from_collection_allow_list(&mut self, caller: caller, user: address) -> Result<void> {
+		self.consume_store_writes(1)?;
+
 		let caller = T::CrossAccountId::from_eth(caller);
 		let user = T::CrossAccountId::from_eth(user);
 		<Pallet<T>>::toggle_allowlist(self, &caller, &user, false).map_err(dispatch_to_evm::<T>)?;
 		Ok(())
 	}
 
+	/// Remove substrate user from allowed list.
+	///
+	/// @param user User substrate address.
+	fn remove_from_collection_allow_list_substrate(
+		&mut self,
+		caller: caller,
+		user: uint256,
+	) -> Result<void> {
+		self.consume_store_writes(1)?;
+
+		let caller = T::CrossAccountId::from_eth(caller);
+		let user = convert_uint256_to_cross_account::<T>(user);
+		Pallet::<T>::toggle_allowlist(self, &caller, &user, false).map_err(dispatch_to_evm::<T>)?;
+		Ok(())
+	}
+
 	/// Switch permission for minting.
 	///
 	/// @param mode Enable if "true".
 	fn set_collection_mint_mode(&mut self, caller: caller, mode: bool) -> Result<void> {
+		self.consume_store_reads_and_writes(1, 1)?;
+
 		check_is_owner_or_admin(caller, self)?;
 		let permissions = CollectionPermissions {
 			mint_mode: Some(mode),
@@ -481,7 +563,7 @@
 	/// Returns collection type
 	///
 	/// @return `Fungible` or `NFT` or `ReFungible`
-	fn unique_collection_type(&mut self) -> Result<string> {
+	fn unique_collection_type(&self) -> Result<string> {
 		let mode = match self.collection.mode {
 			CollectionMode::Fungible(_) => "Fungible",
 			CollectionMode::NFT => "NFT",
@@ -490,11 +572,23 @@
 		Ok(mode.into())
 	}
 
+	/// Get collection owner.
+	///
+	/// @return Tuble with sponsor address and his substrate mirror.
+	/// If address is canonical then substrate mirror is zero and vice versa.
+	fn collection_owner(&self) -> Result<(address, uint256)> {
+		Ok(convert_cross_account_to_tuple::<T>(
+			&T::CrossAccountId::from_sub(self.owner.clone()),
+		))
+	}
+
 	/// Changes collection owner to another account
 	///
 	/// @dev Owner can be changed only by current owner
 	/// @param newOwner new owner account
 	fn set_owner(&mut self, caller: caller, new_owner: address) -> Result<void> {
+		self.consume_store_writes(1)?;
+
 		let caller = T::CrossAccountId::from_eth(caller);
 		let new_owner = T::CrossAccountId::from_eth(new_owner);
 		self.set_owner_internal(caller, new_owner)
@@ -506,13 +600,25 @@
 	/// @dev Owner can be changed only by current owner
 	/// @param newOwner new owner substrate account
 	fn set_owner_substrate(&mut self, caller: caller, new_owner: uint256) -> Result<void> {
+		self.consume_store_writes(1)?;
+
 		let caller = T::CrossAccountId::from_eth(caller);
 		let new_owner = convert_uint256_to_cross_account::<T>(new_owner);
 		self.set_owner_internal(caller, new_owner)
 			.map_err(dispatch_to_evm::<T>)
 	}
+
+	// TODO: need implement AbiWriter for &Vec<T>
+	// fn collection_admins(&self) -> Result<Vec<(address, uint256)>> {
+	// 	let result = pallet_common::IsAdmin::<T>::iter_prefix((self.id,))
+	// 		.map(|(admin, _)| pallet_common::eth::convert_cross_account_to_tuple::<T>(&admin))
+	// 		.collect();
+	// 	Ok(result)
+	// }
 }
 
+/// ### Note
+/// Do not forget to add: `self.consume_store_reads(1)?;`
 fn check_is_owner_or_admin<T: Config>(
 	caller: caller,
 	collection: &CollectionHandle<T>,
@@ -524,9 +630,9 @@
 	Ok(caller)
 }
 
+/// ### Note
+/// Do not forget to add: `self.consume_store_writes(1)?;`
 fn save<T: Config>(collection: &CollectionHandle<T>) -> Result<void> {
-	// TODO possibly delete for the lack of transaction
-	collection.consume_store_writes(1)?;
 	collection
 		.check_is_internal()
 		.map_err(dispatch_to_evm::<T>)?;
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -16,7 +16,7 @@
 
 //! The module contains a number of functions for converting and checking ethereum identifiers.
 
-use evm_coder::types::uint256;
+use evm_coder::types::{uint256, address};
 pub use pallet_evm::account::{Config, CrossAccountId};
 use sp_core::H160;
 use up_data_structs::CollectionId;
@@ -69,3 +69,19 @@
 	let account_id = T::AccountId::from(new_admin_arr);
 	T::CrossAccountId::from_sub(account_id)
 }
+
+/// Convert `CrossAccountId` to `(address, uint256)`.
+pub fn convert_cross_account_to_tuple<T: Config>(
+	cross_account_id: &T::CrossAccountId,
+) -> (address, uint256)
+where
+	T::AccountId: AsRef<[u8; 32]>,
+{
+	if cross_account_id.is_canonical_substrate() {
+		let sub = convert_cross_account_to_uint256::<T>(cross_account_id);
+		(Default::default(), sub)
+	} else {
+		let eth = *cross_account_id.as_eth();
+		(eth, Default::default())
+	}
+}
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -112,7 +112,6 @@
 	RmrkBoundedTheme,
 	RmrkNftChild,
 	CollectionPermissions,
-	SchemaVersion,
 };
 
 pub use pallet::*;
@@ -202,6 +201,21 @@
 			))
 	}
 
+	/// Consume gas for reading and writing.
+	pub fn consume_store_reads_and_writes(
+		&self,
+		reads: u64,
+		writes: u64,
+	) -> evm_coder::execution::Result<()> {
+		let weight = <T as frame_system::Config>::DbWeight::get();
+		let reads = weight.read.saturating_mul(reads);
+		let writes = weight.read.saturating_mul(writes);
+		self.recorder
+			.consume_gas(T::GasWeightMapping::weight_to_gas(
+				reads.saturating_add(writes),
+			))
+	}
+
 	/// Save collection to storage.
 	pub fn save(&self) -> DispatchResult {
 		<CollectionById<T>>::insert(self.id, &self.collection);
@@ -310,6 +324,8 @@
 	}
 
 	/// Changes collection owner to another account
+	/// #### Store read/writes
+	/// 1 writes
 	fn set_owner_internal(
 		&mut self,
 		caller: T::CrossAccountId,
@@ -1292,6 +1308,8 @@
 	}
 
 	/// Toggle `user` participation in the `collection`'s allow list.
+	/// #### Store read/writes
+	/// 1 writes
 	pub fn toggle_allowlist(
 		collection: &CollectionHandle<T>,
 		sender: &T::CrossAccountId,
@@ -1312,6 +1330,8 @@
 	}
 
 	/// Toggle `user` participation in the `collection`'s admin list.
+	/// #### Store read/writes
+	/// 2 writes
 	pub fn toggle_admin(
 		collection: &CollectionHandle<T>,
 		sender: &T::CrossAccountId,
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
before · pallets/evm-contract-helpers/src/eth.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//! Implementation of magic contract1819use core::marker::PhantomData;20use evm_coder::{21	abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*, ToLog,22};23use pallet_evm::{24	ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure, PrecompileHandle,25	account::CrossAccountId,26};27use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder, dispatch_to_evm};28use pallet_evm_transaction_payment::CallContext;29use sp_core::{H160, U256};30use up_data_structs::SponsorshipState;31use crate::{32	AllowlistEnabled, Config, Owner, Pallet, SponsorBasket, SponsoringFeeLimit,33	SponsoringRateLimit, SponsoringModeT, Sponsoring,34};35use frame_support::traits::Get;36use up_sponsorship::SponsorshipHandler;37use sp_std::vec::Vec;3839/// Pallet events.40#[derive(ToLog)]41pub enum ContractHelpersEvents {42	/// Contract sponsor was set.43	ContractSponsorSet {44		/// Contract address of the affected collection.45		#[indexed]46		contract_address: address,47		/// New sponsor address.48		sponsor: address,49	},5051	/// New sponsor was confirm.52	ContractSponsorshipConfirmed {53		/// Contract address of the affected collection.54		#[indexed]55		contract_address: address,56		/// New sponsor address.57		sponsor: address,58	},5960	/// Collection sponsor was removed.61	ContractSponsorRemoved {62		/// Contract address of the affected collection.63		#[indexed]64		contract_address: address,65	},66}6768/// See [`ContractHelpersCall`]69pub struct ContractHelpers<T: Config>(SubstrateRecorder<T>);70impl<T: Config> WithRecorder<T> for ContractHelpers<T> {71	fn recorder(&self) -> &SubstrateRecorder<T> {72		&self.073	}7475	fn into_recorder(self) -> SubstrateRecorder<T> {76		self.077	}78}7980/// @title Magic contract, which allows users to reconfigure other contracts81#[solidity_interface(name = ContractHelpers, events(ContractHelpersEvents))]82impl<T: Config> ContractHelpers<T>83where84	T::AccountId: AsRef<[u8; 32]>,85{86	/// Get user, which deployed specified contract87	/// @dev May return zero address in case if contract is deployed88	///  using uniquenetwork evm-migration pallet, or using other terms not89	///  intended by pallet-evm90	/// @dev Returns zero address if contract does not exists91	/// @param contractAddress Contract to get owner of92	/// @return address Owner of contract93	fn contract_owner(&self, contract_address: address) -> Result<address> {94		Ok(<Owner<T>>::get(contract_address))95	}9697	/// Set sponsor.98	/// @param contractAddress Contract for which a sponsor is being established.99	/// @param sponsor User address who set as pending sponsor.100	fn set_sponsor(101		&mut self,102		caller: caller,103		contract_address: address,104		sponsor: address,105	) -> Result<void> {106		self.recorder().consume_sload()?;107		self.recorder().consume_sstore()?;108109		Pallet::<T>::set_sponsor(110			&T::CrossAccountId::from_eth(caller),111			contract_address,112			&T::CrossAccountId::from_eth(sponsor),113		)114		.map_err(dispatch_to_evm::<T>)?;115116		Ok(())117	}118119	/// Set contract as self sponsored.120	///121	/// @param contractAddress Contract for which a self sponsoring is being enabled.122	fn self_sponsored_enable(&mut self, caller: caller, contract_address: address) -> Result<void> {123		self.recorder().consume_sload()?;124		self.recorder().consume_sstore()?;125126		let caller = T::CrossAccountId::from_eth(caller);127128		Pallet::<T>::ensure_owner(contract_address, *caller.as_eth())129			.map_err(dispatch_to_evm::<T>)?;130131		Pallet::<T>::force_set_sponsor(132			contract_address,133			&T::CrossAccountId::from_eth(contract_address),134		)135		.map_err(dispatch_to_evm::<T>)?;136137		Ok(())138	}139140	/// Remove sponsor.141	///142	/// @param contractAddress Contract for which a sponsorship is being removed.143	fn remove_sponsor(&mut self, caller: caller, contract_address: address) -> Result<void> {144		self.recorder().consume_sload()?;145		self.recorder().consume_sstore()?;146147		Pallet::<T>::remove_sponsor(&T::CrossAccountId::from_eth(caller), contract_address)148			.map_err(dispatch_to_evm::<T>)?;149150		Ok(())151	}152153	/// Confirm sponsorship.154	///155	/// @dev Caller must be same that set via [`setSponsor`].156	///157	/// @param contractAddress Сontract for which need to confirm sponsorship.158	fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {159		self.recorder().consume_sload()?;160		self.recorder().consume_sstore()?;161162		Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)163			.map_err(dispatch_to_evm::<T>)?;164165		Ok(())166	}167168	/// Get current sponsor.169	///170	/// @param contractAddress The contract for which a sponsor is requested.171	/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.172	fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {173		let sponsor =174			Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;175		let result: (address, uint256) = if sponsor.is_canonical_substrate() {176			let sponsor = pallet_common::eth::convert_cross_account_to_uint256::<T>(&sponsor);177			(Default::default(), sponsor)178		} else {179			let sponsor = *sponsor.as_eth();180			(sponsor, Default::default())181		};182		Ok(result)183	}184185	/// Check tat contract has confirmed sponsor.186	///187	/// @param contractAddress The contract for which the presence of a confirmed sponsor is checked.188	/// @return **true** if contract has confirmed sponsor.189	fn has_sponsor(&self, contract_address: address) -> Result<bool> {190		Ok(Pallet::<T>::get_sponsor(contract_address).is_some())191	}192193	/// Check tat contract has pending sponsor.194	///195	/// @param contractAddress The contract for which the presence of a pending sponsor is checked.196	/// @return **true** if contract has pending sponsor.197	fn has_pending_sponsor(&self, contract_address: address) -> Result<bool> {198		Ok(match Sponsoring::<T>::get(contract_address) {199			SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => false,200			SponsorshipState::Unconfirmed(_) => true,201		})202	}203204	fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {205		Ok(<Pallet<T>>::sponsoring_mode(contract_address) != SponsoringModeT::Disabled)206	}207208	fn set_sponsoring_mode(209		&mut self,210		caller: caller,211		contract_address: address,212		// TODO: implement support for enums in evm-coder213		mode: uint8,214	) -> Result<void> {215		self.recorder().consume_sload()?;216		self.recorder().consume_sstore()?;217218		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;219		let mode = SponsoringModeT::from_eth(mode).ok_or("unknown mode")?;220		<Pallet<T>>::set_sponsoring_mode(contract_address, mode);221222		Ok(())223	}224225	/// Get current contract sponsoring rate limit226	/// @param contractAddress Contract to get sponsoring rate limit of227	/// @return uint32 Amount of blocks between two sponsored transactions228	fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {229		self.recorder().consume_sload()?;230231		Ok(<SponsoringRateLimit<T>>::get(contract_address)232			.try_into()233			.map_err(|_| "rate limit > u32::MAX")?)234	}235236	/// Set contract sponsoring rate limit237	/// @dev Sponsoring rate limit - is a minimum amount of blocks that should238	///  pass between two sponsored transactions239	/// @param contractAddress Contract to change sponsoring rate limit of240	/// @param rateLimit Target rate limit241	/// @dev Only contract owner can change this setting242	fn set_sponsoring_rate_limit(243		&mut self,244		caller: caller,245		contract_address: address,246		rate_limit: uint32,247	) -> Result<void> {248		self.recorder().consume_sload()?;249		self.recorder().consume_sstore()?;250251		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;252		<Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());253		Ok(())254	}255256	/// Set contract sponsoring fee limit257	/// @dev Sponsoring fee limit - is maximum fee that could be spent by258	///  single transaction259	/// @param contractAddress Contract to change sponsoring fee limit of260	/// @param feeLimit Fee limit261	/// @dev Only contract owner can change this setting262	fn set_sponsoring_fee_limit(263		&mut self,264		caller: caller,265		contract_address: address,266		fee_limit: uint256,267	) -> Result<void> {268		self.recorder().consume_sload()?;269		self.recorder().consume_sstore()?;270271		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;272		<Pallet<T>>::set_sponsoring_fee_limit(contract_address, fee_limit.into())273			.map_err(dispatch_to_evm::<T>)?;274		Ok(())275	}276277	/// Get current contract sponsoring fee limit278	/// @param contractAddress Contract to get sponsoring fee limit of279	/// @return uint256 Maximum amount of fee that could be spent by single280	///  transaction281	fn get_sponsoring_fee_limit(&self, contract_address: address) -> Result<uint256> {282		self.recorder().consume_sload()?;283284		Ok(get_sponsoring_fee_limit::<T>(contract_address))285	}286287	/// Is specified user present in contract allow list288	/// @dev Contract owner always implicitly included289	/// @param contractAddress Contract to check allowlist of290	/// @param user User to check291	/// @return bool Is specified users exists in contract allowlist292	fn allowed(&self, contract_address: address, user: address) -> Result<bool> {293		self.0.consume_sload()?;294		Ok(<Pallet<T>>::allowed(contract_address, user))295	}296297	/// Toggle user presence in contract allowlist298	/// @param contractAddress Contract to change allowlist of299	/// @param user Which user presence should be toggled300	/// @param isAllowed `true` if user should be allowed to be sponsored301	///  or call this contract, `false` otherwise302	/// @dev Only contract owner can change this setting303	fn toggle_allowed(304		&mut self,305		caller: caller,306		contract_address: address,307		user: address,308		is_allowed: bool,309	) -> Result<void> {310		self.recorder().consume_sload()?;311		self.recorder().consume_sstore()?;312313		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;314		<Pallet<T>>::toggle_allowed(contract_address, user, is_allowed);315316		Ok(())317	}318319	/// Is this contract has allowlist access enabled320	/// @dev Allowlist always can have users, and it is used for two purposes:321	///  in case of allowlist sponsoring mode, users will be sponsored if they exist in allowlist322	///  in case of allowlist access enabled, only users from allowlist may call this contract323	/// @param contractAddress Contract to get allowlist access of324	/// @return bool Is specified contract has allowlist access enabled325	fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {326		Ok(<AllowlistEnabled<T>>::get(contract_address))327	}328329	/// Toggle contract allowlist access330	/// @param contractAddress Contract to change allowlist access of331	/// @param enabled Should allowlist access to be enabled?332	fn toggle_allowlist(333		&mut self,334		caller: caller,335		contract_address: address,336		enabled: bool,337	) -> Result<void> {338		self.recorder().consume_sload()?;339		self.recorder().consume_sstore()?;340341		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;342		<Pallet<T>>::toggle_allowlist(contract_address, enabled);343		Ok(())344	}345}346347/// Implements [`OnMethodCall`], which delegates call to [`ContractHelpers`]348pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);349impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T>350where351	T::AccountId: AsRef<[u8; 32]>,352{353	fn is_reserved(contract: &sp_core::H160) -> bool {354		contract == &T::ContractAddress::get()355	}356357	fn is_used(contract: &sp_core::H160) -> bool {358		contract == &T::ContractAddress::get()359	}360361	fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {362		// TODO: Extract to another OnMethodCall handler363		if <AllowlistEnabled<T>>::get(handle.code_address())364			&& !<Pallet<T>>::allowed(handle.code_address(), handle.context().caller)365		{366			return Some(Err(PrecompileFailure::Revert {367				exit_status: ExitRevert::Reverted,368				output: {369					let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));370					writer.string("Target contract is allowlisted");371					writer.finish()372				},373			}));374		}375376		if handle.code_address() != T::ContractAddress::get() {377			return None;378		}379380		let helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));381		pallet_evm_coder_substrate::call(handle, helpers)382	}383384	fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {385		(contract == &T::ContractAddress::get())386			.then(|| include_bytes!("./stubs/ContractHelpers.raw").to_vec())387	}388}389390/// Hooks into contract creation, storing owner of newly deployed contract391pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);392impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {393	fn on_create(owner: H160, contract: H160) {394		<Owner<T>>::insert(contract, owner);395	}396}397398/// Bridge to pallet-sponsoring399pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);400impl<T: Config> SponsorshipHandler<T::CrossAccountId, CallContext>401	for HelpersContractSponsoring<T>402{403	fn get_sponsor(404		who: &T::CrossAccountId,405		call_context: &CallContext,406	) -> Option<T::CrossAccountId> {407		let contract_address = call_context.contract_address;408		let mode = <Pallet<T>>::sponsoring_mode(contract_address);409		if mode == SponsoringModeT::Disabled {410			return None;411		}412413		let sponsor = match <Pallet<T>>::get_sponsor(contract_address) {414			Some(sponsor) => sponsor,415			None => return None,416		};417418		if mode == SponsoringModeT::Allowlisted419			&& !<Pallet<T>>::allowed(contract_address, *who.as_eth())420		{421			return None;422		}423		let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;424425		if let Some(last_tx_block) = <SponsorBasket<T>>::get(contract_address, who.as_eth()) {426			let limit = <SponsoringRateLimit<T>>::get(contract_address);427428			let timeout = last_tx_block + limit;429			if block_number < timeout {430				return None;431			}432		}433434		let sponsored_fee_limit = get_sponsoring_fee_limit::<T>(contract_address);435436		if call_context.max_fee > sponsored_fee_limit {437			return None;438		}439440		<SponsorBasket<T>>::insert(contract_address, who.as_eth(), block_number);441442		Some(sponsor)443	}444}445446fn get_sponsoring_fee_limit<T: Config>(contract_address: address) -> uint256 {447	<SponsoringFeeLimit<T>>::get(contract_address)448		.get(&0xffffffff)449		.cloned()450		.unwrap_or(U256::MAX)451}452453generate_stubgen!(contract_helpers_impl, ContractHelpersCall<()>, true);454generate_stubgen!(contract_helpers_iface, ContractHelpersCall<()>, false);
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
@@ -22,7 +22,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0xe54be640
+/// @dev the ERC-165 identifier for this interface is 0x9f70d4e0
 contract Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -255,6 +255,18 @@
 		dummy = 0;
 	}
 
+	/// Checks that user allowed to operate with collection.
+	///
+	/// @param user User address to check.
+	/// @dev EVM selector for this function is: 0xd63a8e11,
+	///  or in textual repr: allowed(address)
+	function allowed(address user) public view returns (bool) {
+		require(false, stub_error);
+		user;
+		dummy;
+		return false;
+	}
+
 	/// Add the user to the allowed list.
 	///
 	/// @param user Address of a trusted user.
@@ -266,6 +278,17 @@
 		dummy = 0;
 	}
 
+	/// Add substrate user to allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xd06ad267,
+	///  or in textual repr: addToCollectionAllowListSubstrate(uint256)
+	function addToCollectionAllowListSubstrate(uint256 user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
 	/// Remove the user from the allowed list.
 	///
 	/// @param user Address of a removed user.
@@ -277,6 +300,17 @@
 		dummy = 0;
 	}
 
+	/// Remove substrate user from allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xa31913ed,
+	///  or in textual repr: removeFromCollectionAllowListSubstrate(uint256)
+	function removeFromCollectionAllowListSubstrate(uint256 user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
 	/// Switch permission for minting.
 	///
 	/// @param mode Enable if "true".
@@ -325,6 +359,18 @@
 		return "";
 	}
 
+	/// Get collection owner.
+	///
+	/// @return Tuble with sponsor address and his substrate mirror.
+	/// If address is canonical then substrate mirror is zero and vice versa.
+	/// @dev EVM selector for this function is: 0xdf727d3b,
+	///  or in textual repr: collectionOwner()
+	function collectionOwner() public view returns (Tuple6 memory) {
+		require(false, stub_error);
+		dummy;
+		return Tuple6(0x0000000000000000000000000000000000000000, 0);
+	}
+
 	/// Changes collection owner to another account
 	///
 	/// @dev Owner can be changed only by current owner
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
@@ -99,7 +99,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0xe54be640
+/// @dev the ERC-165 identifier for this interface is 0x9f70d4e0
 contract Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -332,6 +332,18 @@
 		dummy = 0;
 	}
 
+	/// Checks that user allowed to operate with collection.
+	///
+	/// @param user User address to check.
+	/// @dev EVM selector for this function is: 0xd63a8e11,
+	///  or in textual repr: allowed(address)
+	function allowed(address user) public view returns (bool) {
+		require(false, stub_error);
+		user;
+		dummy;
+		return false;
+	}
+
 	/// Add the user to the allowed list.
 	///
 	/// @param user Address of a trusted user.
@@ -343,6 +355,17 @@
 		dummy = 0;
 	}
 
+	/// Add substrate user to allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xd06ad267,
+	///  or in textual repr: addToCollectionAllowListSubstrate(uint256)
+	function addToCollectionAllowListSubstrate(uint256 user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
 	/// Remove the user from the allowed list.
 	///
 	/// @param user Address of a removed user.
@@ -354,6 +377,17 @@
 		dummy = 0;
 	}
 
+	/// Remove substrate user from allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xa31913ed,
+	///  or in textual repr: removeFromCollectionAllowListSubstrate(uint256)
+	function removeFromCollectionAllowListSubstrate(uint256 user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
 	/// Switch permission for minting.
 	///
 	/// @param mode Enable if "true".
@@ -402,6 +436,18 @@
 		return "";
 	}
 
+	/// Get collection owner.
+	///
+	/// @return Tuble with sponsor address and his substrate mirror.
+	/// If address is canonical then substrate mirror is zero and vice versa.
+	/// @dev EVM selector for this function is: 0xdf727d3b,
+	///  or in textual repr: collectionOwner()
+	function collectionOwner() public view returns (Tuple17 memory) {
+		require(false, stub_error);
+		dummy;
+		return Tuple17(0x0000000000000000000000000000000000000000, 0);
+	}
+
 	/// Changes collection owner to another account
 	///
 	/// @dev Owner can be changed only by current owner
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
@@ -99,7 +99,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0xe54be640
+/// @dev the ERC-165 identifier for this interface is 0x9f70d4e0
 contract Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -332,6 +332,18 @@
 		dummy = 0;
 	}
 
+	/// Checks that user allowed to operate with collection.
+	///
+	/// @param user User address to check.
+	/// @dev EVM selector for this function is: 0xd63a8e11,
+	///  or in textual repr: allowed(address)
+	function allowed(address user) public view returns (bool) {
+		require(false, stub_error);
+		user;
+		dummy;
+		return false;
+	}
+
 	/// Add the user to the allowed list.
 	///
 	/// @param user Address of a trusted user.
@@ -343,6 +355,17 @@
 		dummy = 0;
 	}
 
+	/// Add substrate user to allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xd06ad267,
+	///  or in textual repr: addToCollectionAllowListSubstrate(uint256)
+	function addToCollectionAllowListSubstrate(uint256 user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
 	/// Remove the user from the allowed list.
 	///
 	/// @param user Address of a removed user.
@@ -354,6 +377,17 @@
 		dummy = 0;
 	}
 
+	/// Remove substrate user from allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xa31913ed,
+	///  or in textual repr: removeFromCollectionAllowListSubstrate(uint256)
+	function removeFromCollectionAllowListSubstrate(uint256 user) public {
+		require(false, stub_error);
+		user;
+		dummy = 0;
+	}
+
 	/// Switch permission for minting.
 	///
 	/// @param mode Enable if "true".
@@ -402,6 +436,18 @@
 		return "";
 	}
 
+	/// Get collection owner.
+	///
+	/// @return Tuble with sponsor address and his substrate mirror.
+	/// If address is canonical then substrate mirror is zero and vice versa.
+	/// @dev EVM selector for this function is: 0xdf727d3b,
+	///  or in textual repr: collectionOwner()
+	function collectionOwner() public view returns (Tuple17 memory) {
+		require(false, stub_error);
+		dummy;
+		return Tuple17(0x0000000000000000000000000000000000000000, 0);
+	}
+
 	/// Changes collection owner to another account
 	///
 	/// @dev Owner can be changed only by current owner
modifiedtests/src/eth/allowlist.test.tsdiffbeforeafterboth
--- a/tests/src/eth/allowlist.test.ts
+++ b/tests/src/eth/allowlist.test.ts
@@ -14,10 +14,22 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
+import {IKeyringPair} from '@polkadot/types/types';
 import {expect} from 'chai';
-import {contractHelpers, createEthAccountWithBalance, deployFlipper, itWeb3} from './util/helpers';
+import {isAllowlisted, normalizeAccountId} from '../util/helpers';
+import {
+  contractHelpers,
+  createEthAccount,
+  createEthAccountWithBalance,
+  deployFlipper,
+  evmCollection,
+  evmCollectionHelpers,
+  getCollectionAddressFromResult,
+  itWeb3,
+} from './util/helpers';
+import {itEth, usingEthPlaygrounds} from './util/playgrounds';
 
-describe('EVM allowlist', () => {
+describe('EVM contract allowlist', () => {
   itWeb3('Contract allowlist can be toggled', async ({api, web3, privateKeyWrapper}) => {
     const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
     const flipper = await deployFlipper(web3, owner);
@@ -58,3 +70,79 @@
     expect(await flipper.methods.getValue().call()).to.be.false;
   });
 });
+
+describe('EVM collection allowlist', () => {
+  let donor: IKeyringPair;
+
+  before(async function() {
+    await usingEthPlaygrounds(async (_helper, privateKey) => {
+      donor = privateKey('//Alice');
+    });
+  });
+  
+  itEth('Collection allowlist can be added and removed by [eth] address', async ({helper}) => {
+    const owner = await helper.eth.createAccountWithBalance(donor);
+    const user = helper.eth.createAccount();
+    
+    const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
+    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+    
+    expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;
+    await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});
+    expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.true;
+    
+    await collectionEvm.methods.removeFromCollectionAllowList(user).send({from: owner});
+    expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;
+  });
+
+  itEth('Collection allowlist can be added and removed by [sub] address', async ({helper}) => {
+    const owner = await helper.eth.createAccountWithBalance(donor);
+    const user = donor;
+    
+    const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
+    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+    
+    expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
+    await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner});
+    expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;
+    
+    await collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).send({from: owner});
+    expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
+  });
+
+  itEth('Collection allowlist can not be add and remove [eth] address by not owner', async ({helper}) => {
+    const owner = await helper.eth.createAccountWithBalance(donor);
+    const notOwner = await helper.eth.createAccountWithBalance(donor);
+    const user = helper.eth.createAccount();
+    
+    const {collectionAddress} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
+    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+    
+    expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;
+    await expect(collectionEvm.methods.addToCollectionAllowList(user).call({from: notOwner})).to.be.rejectedWith('NoPermission');
+    expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.false;
+    await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});
+    
+    expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.true;
+    await expect(collectionEvm.methods.removeFromCollectionAllowList(user).call({from: notOwner})).to.be.rejectedWith('NoPermission');
+    expect(await collectionEvm.methods.allowed(user).call({from: owner})).to.be.true;
+  });
+
+  itEth('Collection allowlist can not be add and remove [sub] address by not owner', async ({helper}) => {
+    const owner = await helper.eth.createAccountWithBalance(donor);
+    const notOwner = await helper.eth.createAccountWithBalance(donor);
+    const user = donor;
+    
+    const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
+    const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
+    
+    expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
+    await expect(collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission');
+    expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.false;
+    await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner});
+    
+    expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;
+    await expect(collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission');
+    expect(await helper.collection.allowed(collectionId, {Substrate: user.address})).to.be.true;
+  });
+});
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -13,7 +13,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0xe54be640
+/// @dev the ERC-165 identifier for this interface is 0x9f70d4e0
 interface Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -164,6 +164,13 @@
 	///  or in textual repr: setCollectionAccess(uint8)
 	function setCollectionAccess(uint8 mode) external;
 
+	/// Checks that user allowed to operate with collection.
+	///
+	/// @param user User address to check.
+	/// @dev EVM selector for this function is: 0xd63a8e11,
+	///  or in textual repr: allowed(address)
+	function allowed(address user) external view returns (bool);
+
 	/// Add the user to the allowed list.
 	///
 	/// @param user Address of a trusted user.
@@ -171,6 +178,13 @@
 	///  or in textual repr: addToCollectionAllowList(address)
 	function addToCollectionAllowList(address user) external;
 
+	/// Add substrate user to allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xd06ad267,
+	///  or in textual repr: addToCollectionAllowListSubstrate(uint256)
+	function addToCollectionAllowListSubstrate(uint256 user) external;
+
 	/// Remove the user from the allowed list.
 	///
 	/// @param user Address of a removed user.
@@ -178,6 +192,13 @@
 	///  or in textual repr: removeFromCollectionAllowList(address)
 	function removeFromCollectionAllowList(address user) external;
 
+	/// Remove substrate user from allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xa31913ed,
+	///  or in textual repr: removeFromCollectionAllowListSubstrate(uint256)
+	function removeFromCollectionAllowListSubstrate(uint256 user) external;
+
 	/// Switch permission for minting.
 	///
 	/// @param mode Enable if "true".
@@ -208,6 +229,14 @@
 	///  or in textual repr: uniqueCollectionType()
 	function uniqueCollectionType() external returns (string memory);
 
+	/// Get collection owner.
+	///
+	/// @return Tuble with sponsor address and his substrate mirror.
+	/// If address is canonical then substrate mirror is zero and vice versa.
+	/// @dev EVM selector for this function is: 0xdf727d3b,
+	///  or in textual repr: collectionOwner()
+	function collectionOwner() external view returns (Tuple6 memory);
+
 	/// Changes collection owner to another account
 	///
 	/// @dev Owner can be changed only by current owner
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -65,7 +65,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0xe54be640
+/// @dev the ERC-165 identifier for this interface is 0x9f70d4e0
 interface Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -216,6 +216,13 @@
 	///  or in textual repr: setCollectionAccess(uint8)
 	function setCollectionAccess(uint8 mode) external;
 
+	/// Checks that user allowed to operate with collection.
+	///
+	/// @param user User address to check.
+	/// @dev EVM selector for this function is: 0xd63a8e11,
+	///  or in textual repr: allowed(address)
+	function allowed(address user) external view returns (bool);
+
 	/// Add the user to the allowed list.
 	///
 	/// @param user Address of a trusted user.
@@ -223,6 +230,13 @@
 	///  or in textual repr: addToCollectionAllowList(address)
 	function addToCollectionAllowList(address user) external;
 
+	/// Add substrate user to allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xd06ad267,
+	///  or in textual repr: addToCollectionAllowListSubstrate(uint256)
+	function addToCollectionAllowListSubstrate(uint256 user) external;
+
 	/// Remove the user from the allowed list.
 	///
 	/// @param user Address of a removed user.
@@ -230,6 +244,13 @@
 	///  or in textual repr: removeFromCollectionAllowList(address)
 	function removeFromCollectionAllowList(address user) external;
 
+	/// Remove substrate user from allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xa31913ed,
+	///  or in textual repr: removeFromCollectionAllowListSubstrate(uint256)
+	function removeFromCollectionAllowListSubstrate(uint256 user) external;
+
 	/// Switch permission for minting.
 	///
 	/// @param mode Enable if "true".
@@ -260,6 +281,14 @@
 	///  or in textual repr: uniqueCollectionType()
 	function uniqueCollectionType() external returns (string memory);
 
+	/// Get collection owner.
+	///
+	/// @return Tuble with sponsor address and his substrate mirror.
+	/// If address is canonical then substrate mirror is zero and vice versa.
+	/// @dev EVM selector for this function is: 0xdf727d3b,
+	///  or in textual repr: collectionOwner()
+	function collectionOwner() external view returns (Tuple17 memory);
+
 	/// Changes collection owner to another account
 	///
 	/// @dev Owner can be changed only by current owner
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -65,7 +65,7 @@
 }
 
 /// @title A contract that allows you to work with collections.
-/// @dev the ERC-165 identifier for this interface is 0xe54be640
+/// @dev the ERC-165 identifier for this interface is 0x9f70d4e0
 interface Collection is Dummy, ERC165 {
 	/// Set collection property.
 	///
@@ -216,6 +216,13 @@
 	///  or in textual repr: setCollectionAccess(uint8)
 	function setCollectionAccess(uint8 mode) external;
 
+	/// Checks that user allowed to operate with collection.
+	///
+	/// @param user User address to check.
+	/// @dev EVM selector for this function is: 0xd63a8e11,
+	///  or in textual repr: allowed(address)
+	function allowed(address user) external view returns (bool);
+
 	/// Add the user to the allowed list.
 	///
 	/// @param user Address of a trusted user.
@@ -223,6 +230,13 @@
 	///  or in textual repr: addToCollectionAllowList(address)
 	function addToCollectionAllowList(address user) external;
 
+	/// Add substrate user to allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xd06ad267,
+	///  or in textual repr: addToCollectionAllowListSubstrate(uint256)
+	function addToCollectionAllowListSubstrate(uint256 user) external;
+
 	/// Remove the user from the allowed list.
 	///
 	/// @param user Address of a removed user.
@@ -230,6 +244,13 @@
 	///  or in textual repr: removeFromCollectionAllowList(address)
 	function removeFromCollectionAllowList(address user) external;
 
+	/// Remove substrate user from allowed list.
+	///
+	/// @param user User substrate address.
+	/// @dev EVM selector for this function is: 0xa31913ed,
+	///  or in textual repr: removeFromCollectionAllowListSubstrate(uint256)
+	function removeFromCollectionAllowListSubstrate(uint256 user) external;
+
 	/// Switch permission for minting.
 	///
 	/// @param mode Enable if "true".
@@ -260,6 +281,14 @@
 	///  or in textual repr: uniqueCollectionType()
 	function uniqueCollectionType() external returns (string memory);
 
+	/// Get collection owner.
+	///
+	/// @return Tuble with sponsor address and his substrate mirror.
+	/// If address is canonical then substrate mirror is zero and vice versa.
+	/// @dev EVM selector for this function is: 0xdf727d3b,
+	///  or in textual repr: collectionOwner()
+	function collectionOwner() external view returns (Tuple17 memory);
+
 	/// Changes collection owner to another account
 	///
 	/// @dev Owner can be changed only by current owner
modifiedtests/src/eth/fungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/fungibleAbi.json
+++ b/tests/src/eth/fungibleAbi.json
@@ -78,6 +78,15 @@
   },
   {
     "inputs": [
+      { "internalType": "uint256", "name": "user", "type": "uint256" }
+    ],
+    "name": "addToCollectionAllowListSubstrate",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "address", "name": "owner", "type": "address" },
       { "internalType": "address", "name": "spender", "type": "address" }
     ],
@@ -88,6 +97,15 @@
   },
   {
     "inputs": [
+      { "internalType": "address", "name": "user", "type": "address" }
+    ],
+    "name": "allowed",
+    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "address", "name": "spender", "type": "address" },
       { "internalType": "uint256", "name": "amount", "type": "uint256" }
     ],
@@ -116,6 +134,23 @@
     "type": "function"
   },
   {
+    "inputs": [],
+    "name": "collectionOwner",
+    "outputs": [
+      {
+        "components": [
+          { "internalType": "address", "name": "field_0", "type": "address" },
+          { "internalType": "uint256", "name": "field_1", "type": "uint256" }
+        ],
+        "internalType": "struct Tuple6",
+        "name": "",
+        "type": "tuple"
+      }
+    ],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
     "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
     "name": "collectionProperty",
     "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }],
@@ -261,6 +296,15 @@
     "type": "function"
   },
   {
+    "inputs": [
+      { "internalType": "uint256", "name": "user", "type": "uint256" }
+    ],
+    "name": "removeFromCollectionAllowListSubstrate",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
     "inputs": [{ "internalType": "uint8", "name": "mode", "type": "uint8" }],
     "name": "setCollectionAccess",
     "outputs": [],
modifiedtests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -109,6 +109,24 @@
   },
   {
     "inputs": [
+      { "internalType": "uint256", "name": "user", "type": "uint256" }
+    ],
+    "name": "addToCollectionAllowListSubstrate",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [
+      { "internalType": "address", "name": "user", "type": "address" }
+    ],
+    "name": "allowed",
+    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "address", "name": "approved", "type": "address" },
       { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
     ],
@@ -146,6 +164,23 @@
     "type": "function"
   },
   {
+    "inputs": [],
+    "name": "collectionOwner",
+    "outputs": [
+      {
+        "components": [
+          { "internalType": "address", "name": "field_0", "type": "address" },
+          { "internalType": "uint256", "name": "field_1", "type": "uint256" }
+        ],
+        "internalType": "struct Tuple17",
+        "name": "",
+        "type": "tuple"
+      }
+    ],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
     "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
     "name": "collectionProperty",
     "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }],
@@ -376,6 +411,15 @@
   },
   {
     "inputs": [
+      { "internalType": "uint256", "name": "user", "type": "uint256" }
+    ],
+    "name": "removeFromCollectionAllowListSubstrate",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "address", "name": "from", "type": "address" },
       { "internalType": "address", "name": "to", "type": "address" },
       { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
modifiedtests/src/eth/reFungibleAbi.jsondiffbeforeafterboth
--- a/tests/src/eth/reFungibleAbi.json
+++ b/tests/src/eth/reFungibleAbi.json
@@ -109,6 +109,24 @@
   },
   {
     "inputs": [
+      { "internalType": "uint256", "name": "user", "type": "uint256" }
+    ],
+    "name": "addToCollectionAllowListSubstrate",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [
+      { "internalType": "address", "name": "user", "type": "address" }
+    ],
+    "name": "allowed",
+    "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "address", "name": "approved", "type": "address" },
       { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
     ],
@@ -146,6 +164,23 @@
     "type": "function"
   },
   {
+    "inputs": [],
+    "name": "collectionOwner",
+    "outputs": [
+      {
+        "components": [
+          { "internalType": "address", "name": "field_0", "type": "address" },
+          { "internalType": "uint256", "name": "field_1", "type": "uint256" }
+        ],
+        "internalType": "struct Tuple17",
+        "name": "",
+        "type": "tuple"
+      }
+    ],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
     "inputs": [{ "internalType": "string", "name": "key", "type": "string" }],
     "name": "collectionProperty",
     "outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }],
@@ -376,6 +411,15 @@
   },
   {
     "inputs": [
+      { "internalType": "uint256", "name": "user", "type": "uint256" }
+    ],
+    "name": "removeFromCollectionAllowListSubstrate",
+    "outputs": [],
+    "stateMutability": "nonpayable",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "address", "name": "from", "type": "address" },
       { "internalType": "address", "name": "to", "type": "address" },
       { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
modifiedtests/src/util/helpers.tsdiffbeforeafterboth
--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -1651,7 +1651,7 @@
   });
 }
 
-export async function isAllowlisted(api: ApiPromise, collectionId: number, address: string | CrossAccountId) {
+export async function isAllowlisted(api: ApiPromise, collectionId: number, address: string | CrossAccountId | IKeyringPair) {
   return (await api.rpc.unique.allowed(collectionId, normalizeAccountId(address))).toJSON();
 }
 
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -730,6 +730,18 @@
   }
 
   /**
+   * Check if user is in allow list.
+   * 
+   * @param collectionId ID of collection
+   * @param user Account to check
+   * @example await getAdmins(1)
+   * @returns is user in allow list
+   */
+  async allowed(collectionId: number, user: ICrossAccountId): Promise<boolean> {
+    return (await this.helper.callRpc('api.rpc.unique.allowed', [collectionId, user])).toJSON();
+  }
+
+  /**
    * Adds an address to allow list
    * @param signer keyring of signer
    * @param collectionId ID of collection