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

difftreelog

feat Add events for set contract sponsoring.

Trubnikov Sergey2022-09-05parent: #ebc4cdb.patch.diff
in: master

7 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5735,6 +5735,7 @@
 name = "pallet-evm-contract-helpers"
 version = "0.2.0"
 dependencies = [
+ "ethereum",
  "evm-coder",
  "fp-evm-mapping",
  "frame-support",
modifiedpallets/evm-contract-helpers/Cargo.tomldiffbeforeafterboth
--- a/pallets/evm-contract-helpers/Cargo.toml
+++ b/pallets/evm-contract-helpers/Cargo.toml
@@ -9,6 +9,7 @@
     "derive",
 ] }
 log = { default-features = false, version = "0.4.14" }
+ethereum = { version = "0.12.0", default-features = false }
 
 # Substrate
 frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
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::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};21use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder, dispatch_to_evm};22use pallet_evm::{23	ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure, PrecompileHandle,24	account::CrossAccountId,25};26use sp_core::H160;27use up_data_structs::SponsorshipState;28use crate::{29	AllowlistEnabled, Config, Owner, Pallet, SponsorBasket, SponsoringRateLimit, SponsoringModeT,30	Sponsoring,31};32use frame_support::traits::Get;33use up_sponsorship::SponsorshipHandler;34use sp_std::vec::Vec;3536/// See [`ContractHelpersCall`]37pub struct ContractHelpers<T: Config>(SubstrateRecorder<T>);38impl<T: Config> WithRecorder<T> for ContractHelpers<T> {39	fn recorder(&self) -> &SubstrateRecorder<T> {40		&self.041	}4243	fn into_recorder(self) -> SubstrateRecorder<T> {44		self.045	}46}4748/// @title Magic contract, which allows users to reconfigure other contracts49#[solidity_interface(name = ContractHelpers)]50impl<T: Config> ContractHelpers<T>51where52	T::AccountId: AsRef<[u8; 32]>,53{54	/// Get user, which deployed specified contract55	/// @dev May return zero address in case if contract is deployed56	///  using uniquenetwork evm-migration pallet, or using other terms not57	///  intended by pallet-evm58	/// @dev Returns zero address if contract does not exists59	/// @param contractAddress Contract to get owner of60	/// @return address Owner of contract61	fn contract_owner(&self, contract_address: address) -> Result<address> {62		Ok(<Owner<T>>::get(contract_address))63	}6465	/// Set sponsor.66	/// @param contractAddress Contract for which a sponsor is being established.67	/// @param sponsor User address who set as pending sponsor.68	fn set_sponsor(69		&mut self,70		caller: caller,71		contract_address: address,72		sponsor: address,73	) -> Result<void> {74		self.recorder().consume_sload()?;75		self.recorder().consume_sstore()?;7677		Pallet::<T>::set_sponsor(78			&T::CrossAccountId::from_eth(caller),79			contract_address,80			&T::CrossAccountId::from_eth(sponsor),81		)82		.map_err(dispatch_to_evm::<T>)?;8384		Ok(())85	}8687	/// Set contract as self sponsored.88	///89	/// @param contractAddress Contract for which a self sponsoring is being enabled.90	fn self_sponsored_enable(&mut self, caller: caller, contract_address: address) -> Result<void> {91		self.recorder().consume_sload()?;92		self.recorder().consume_sstore()?;9394		Pallet::<T>::self_sponsored_enable(&T::CrossAccountId::from_eth(caller), contract_address)95			.map_err(dispatch_to_evm::<T>)?;9697		Ok(())98	}99100	/// Remove sponsor.101	///102	/// @param contractAddress Contract for which a sponsorship is being removed.103	fn remove_sponsor(&mut self, caller: caller, contract_address: address) -> Result<void> {104		self.recorder().consume_sload()?;105		self.recorder().consume_sstore()?;106107		Pallet::<T>::remove_sponsor(&T::CrossAccountId::from_eth(caller), contract_address)108			.map_err(dispatch_to_evm::<T>)?;109110		Ok(())111	}112113	/// Confirm sponsorship.114	///115	/// @dev Caller must be same that set via [`setSponsor`].116	///117	/// @param contractAddress Сontract for which need to confirm sponsorship.118	fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {119		self.recorder().consume_sload()?;120		self.recorder().consume_sstore()?;121122		Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)123			.map_err(dispatch_to_evm::<T>)?;124125		Ok(())126	}127128	/// Get current sponsor.129	///130	/// @param contractAddress The contract for which a sponsor is requested.131	/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.132	fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {133		let sponsor =134			Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;135		let result: (address, uint256) = if sponsor.is_canonical_substrate() {136			let sponsor = pallet_common::eth::convert_cross_account_to_uint256::<T>(&sponsor);137			(Default::default(), sponsor)138		} else {139			let sponsor = *sponsor.as_eth();140			(sponsor, Default::default())141		};142		Ok(result)143	}144145	/// Check tat contract has confirmed sponsor.146	///147	/// @param contractAddress The contract for which the presence of a confirmed sponsor is checked.148	/// @return **true** if contract has confirmed sponsor.149	fn has_sponsor(&self, contract_address: address) -> Result<bool> {150		Ok(Pallet::<T>::get_sponsor(contract_address).is_some())151	}152153	/// Check tat contract has pending sponsor.154	///155	/// @param contractAddress The contract for which the presence of a pending sponsor is checked.156	/// @return **true** if contract has pending sponsor.157	fn has_pending_sponsor(&self, contract_address: address) -> Result<bool> {158		Ok(match Sponsoring::<T>::get(contract_address) {159			SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => false,160			SponsorshipState::Unconfirmed(_) => true,161		})162	}163164	fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {165		Ok(<Pallet<T>>::sponsoring_mode(contract_address) != SponsoringModeT::Disabled)166	}167168	fn set_sponsoring_mode(169		&mut self,170		caller: caller,171		contract_address: address,172		// TODO: implement support for enums in evm-coder173		mode: uint8,174	) -> Result<void> {175		self.recorder().consume_sload()?;176		self.recorder().consume_sstore()?;177178		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;179		let mode = SponsoringModeT::from_eth(mode).ok_or("unknown mode")?;180		<Pallet<T>>::set_sponsoring_mode(contract_address, mode);181182		Ok(())183	}184185	/// Get current contract sponsoring rate limit186	/// @param contractAddress Contract to get sponsoring mode of187	/// @return uint32 Amount of blocks between two sponsored transactions188	fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {189		Ok(<SponsoringRateLimit<T>>::get(contract_address)190			.try_into()191			.map_err(|_| "rate limit > u32::MAX")?)192	}193194	/// Set contract sponsoring rate limit195	/// @dev Sponsoring rate limit - is a minimum amount of blocks that should196	///  pass between two sponsored transactions197	/// @param contractAddress Contract to change sponsoring rate limit of198	/// @param rateLimit Target rate limit199	/// @dev Only contract owner can change this setting200	fn set_sponsoring_rate_limit(201		&mut self,202		caller: caller,203		contract_address: address,204		rate_limit: uint32,205	) -> Result<void> {206		self.recorder().consume_sload()?;207		self.recorder().consume_sstore()?;208209		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;210		<Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());211		Ok(())212	}213214	/// Is specified user present in contract allow list215	/// @dev Contract owner always implicitly included216	/// @param contractAddress Contract to check allowlist of217	/// @param user User to check218	/// @return bool Is specified users exists in contract allowlist219	fn allowed(&self, contract_address: address, user: address) -> Result<bool> {220		self.0.consume_sload()?;221		Ok(<Pallet<T>>::allowed(contract_address, user))222	}223224	/// Toggle user presence in contract allowlist225	/// @param contractAddress Contract to change allowlist of226	/// @param user Which user presence should be toggled227	/// @param isAllowed `true` if user should be allowed to be sponsored228	///  or call this contract, `false` otherwise229	/// @dev Only contract owner can change this setting230	fn toggle_allowed(231		&mut self,232		caller: caller,233		contract_address: address,234		user: address,235		is_allowed: bool,236	) -> Result<void> {237		self.recorder().consume_sload()?;238		self.recorder().consume_sstore()?;239240		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;241		<Pallet<T>>::toggle_allowed(contract_address, user, is_allowed);242243		Ok(())244	}245246	/// Is this contract has allowlist access enabled247	/// @dev Allowlist always can have users, and it is used for two purposes:248	///  in case of allowlist sponsoring mode, users will be sponsored if they exist in allowlist249	///  in case of allowlist access enabled, only users from allowlist may call this contract250	/// @param contractAddress Contract to get allowlist access of251	/// @return bool Is specified contract has allowlist access enabled252	fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {253		Ok(<AllowlistEnabled<T>>::get(contract_address))254	}255256	/// Toggle contract allowlist access257	/// @param contractAddress Contract to change allowlist access of258	/// @param enabled Should allowlist access to be enabled?259	fn toggle_allowlist(260		&mut self,261		caller: caller,262		contract_address: address,263		enabled: bool,264	) -> Result<void> {265		self.recorder().consume_sload()?;266		self.recorder().consume_sstore()?;267268		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;269		<Pallet<T>>::toggle_allowlist(contract_address, enabled);270		Ok(())271	}272}273274/// Implements [`OnMethodCall`], which delegates call to [`ContractHelpers`]275pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);276impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T>277where278	T::AccountId: AsRef<[u8; 32]>,279{280	fn is_reserved(contract: &sp_core::H160) -> bool {281		contract == &T::ContractAddress::get()282	}283284	fn is_used(contract: &sp_core::H160) -> bool {285		contract == &T::ContractAddress::get()286	}287288	fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {289		// TODO: Extract to another OnMethodCall handler290		if <AllowlistEnabled<T>>::get(handle.code_address())291			&& !<Pallet<T>>::allowed(handle.code_address(), handle.context().caller)292		{293			return Some(Err(PrecompileFailure::Revert {294				exit_status: ExitRevert::Reverted,295				output: {296					let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));297					writer.string("Target contract is allowlisted");298					writer.finish()299				},300			}));301		}302303		if handle.code_address() != T::ContractAddress::get() {304			return None;305		}306307		let helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));308		pallet_evm_coder_substrate::call(handle, helpers)309	}310311	fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {312		(contract == &T::ContractAddress::get())313			.then(|| include_bytes!("./stubs/ContractHelpers.raw").to_vec())314	}315}316317/// Hooks into contract creation, storing owner of newly deployed contract318pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);319impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {320	fn on_create(owner: H160, contract: H160) {321		<Owner<T>>::insert(contract, owner);322	}323}324325/// Bridge to pallet-sponsoring326pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);327impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)>328	for HelpersContractSponsoring<T>329{330	fn get_sponsor(who: &T::CrossAccountId, call: &(H160, Vec<u8>)) -> Option<T::CrossAccountId> {331		let (contract_address, _) = call;332		let mode = <Pallet<T>>::sponsoring_mode(*contract_address);333		if mode == SponsoringModeT::Disabled {334			return None;335		}336337		let sponsor = match <Pallet<T>>::get_sponsor(*contract_address) {338			Some(sponsor) => sponsor,339			None => return None,340		};341342		if mode == SponsoringModeT::Allowlisted343			&& !<Pallet<T>>::allowed(*contract_address, *who.as_eth())344		{345			return None;346		}347		let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;348349		if let Some(last_tx_block) = <SponsorBasket<T>>::get(contract_address, who.as_eth()) {350			let limit = <SponsoringRateLimit<T>>::get(contract_address);351352			let timeout = last_tx_block + limit;353			if block_number < timeout {354				return None;355			}356		}357358		<SponsorBasket<T>>::insert(contract_address, who.as_eth(), block_number);359360		Some(sponsor)361	}362}363364generate_stubgen!(contract_helpers_impl, ContractHelpersCall<()>, true);365generate_stubgen!(contract_helpers_iface, ContractHelpersCall<()>, false);
after · 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_coder_substrate::{SubstrateRecorder, WithRecorder, dispatch_to_evm};24use pallet_evm::{25	ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure, PrecompileHandle,26	account::CrossAccountId,27};28use sp_core::H160;29use up_data_structs::SponsorshipState;30use crate::{31	AllowlistEnabled, Config, Owner, Pallet, SponsorBasket, SponsoringRateLimit, SponsoringModeT,32	Sponsoring,33};34use frame_support::traits::Get;35use up_sponsorship::SponsorshipHandler;36use sp_std::vec::Vec;3738/// Pallet events.39#[derive(ToLog)]40pub enum ContractHelpersEvents {41	/// Contract sponsor was set.42	ContractSponsorSet {43		/// Contract address of the affected collection.44		#[indexed]45		contract: address,46		/// New sponsor address.47		#[indexed]48		sponsor: address,49	},5051	/// New sponsor was confirm.52	ContractSponsorshipConfirmed {53		/// Contract address of the affected collection.54		#[indexed]55		contract: address,56		/// New sponsor address.57		#[indexed]58		sponsor: address,59	},6061	/// Collection sponsor was removed.62	ContractSponsorRemoved {63		/// Contract address of the affected collection.64		#[indexed]65		contract: address,66	},67}6869/// See [`ContractHelpersCall`]70pub struct ContractHelpers<T: Config>(SubstrateRecorder<T>);71impl<T: Config> WithRecorder<T> for ContractHelpers<T> {72	fn recorder(&self) -> &SubstrateRecorder<T> {73		&self.074	}7576	fn into_recorder(self) -> SubstrateRecorder<T> {77		self.078	}79}8081/// @title Magic contract, which allows users to reconfigure other contracts82#[solidity_interface(name = ContractHelpers, events(ContractHelpersEvents))]83impl<T: Config> ContractHelpers<T>84where85	T::AccountId: AsRef<[u8; 32]>,86{87	/// Get user, which deployed specified contract88	/// @dev May return zero address in case if contract is deployed89	///  using uniquenetwork evm-migration pallet, or using other terms not90	///  intended by pallet-evm91	/// @dev Returns zero address if contract does not exists92	/// @param contractAddress Contract to get owner of93	/// @return address Owner of contract94	fn contract_owner(&self, contract_address: address) -> Result<address> {95		Ok(<Owner<T>>::get(contract_address))96	}9798	/// Set sponsor.99	/// @param contractAddress Contract for which a sponsor is being established.100	/// @param sponsor User address who set as pending sponsor.101	fn set_sponsor(102		&mut self,103		caller: caller,104		contract_address: address,105		sponsor: address,106	) -> Result<void> {107		self.recorder().consume_sload()?;108		self.recorder().consume_sstore()?;109110		Pallet::<T>::set_sponsor(111			&T::CrossAccountId::from_eth(caller),112			contract_address,113			&T::CrossAccountId::from_eth(sponsor),114		)115		.map_err(dispatch_to_evm::<T>)?;116117		Ok(())118	}119120	/// Set contract as self sponsored.121	///122	/// @param contractAddress Contract for which a self sponsoring is being enabled.123	fn self_sponsored_enable(&mut self, caller: caller, contract_address: address) -> Result<void> {124		self.recorder().consume_sload()?;125		self.recorder().consume_sstore()?;126127		Pallet::<T>::force_set_sponsor(&T::CrossAccountId::from_eth(caller), contract_address)128			.map_err(dispatch_to_evm::<T>)?;129130		Ok(())131	}132133	/// Remove sponsor.134	///135	/// @param contractAddress Contract for which a sponsorship is being removed.136	fn remove_sponsor(&mut self, caller: caller, contract_address: address) -> Result<void> {137		self.recorder().consume_sload()?;138		self.recorder().consume_sstore()?;139140		Pallet::<T>::remove_sponsor(&T::CrossAccountId::from_eth(caller), contract_address)141			.map_err(dispatch_to_evm::<T>)?;142143		Ok(())144	}145146	/// Confirm sponsorship.147	///148	/// @dev Caller must be same that set via [`setSponsor`].149	///150	/// @param contractAddress Сontract for which need to confirm sponsorship.151	fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {152		self.recorder().consume_sload()?;153		self.recorder().consume_sstore()?;154155		Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)156			.map_err(dispatch_to_evm::<T>)?;157158		Ok(())159	}160161	/// Get current sponsor.162	///163	/// @param contractAddress The contract for which a sponsor is requested.164	/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.165	fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {166		let sponsor =167			Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;168		let result: (address, uint256) = if sponsor.is_canonical_substrate() {169			let sponsor = pallet_common::eth::convert_cross_account_to_uint256::<T>(&sponsor);170			(Default::default(), sponsor)171		} else {172			let sponsor = *sponsor.as_eth();173			(sponsor, Default::default())174		};175		Ok(result)176	}177178	/// Check tat contract has confirmed sponsor.179	///180	/// @param contractAddress The contract for which the presence of a confirmed sponsor is checked.181	/// @return **true** if contract has confirmed sponsor.182	fn has_sponsor(&self, contract_address: address) -> Result<bool> {183		Ok(Pallet::<T>::get_sponsor(contract_address).is_some())184	}185186	/// Check tat contract has pending sponsor.187	///188	/// @param contractAddress The contract for which the presence of a pending sponsor is checked.189	/// @return **true** if contract has pending sponsor.190	fn has_pending_sponsor(&self, contract_address: address) -> Result<bool> {191		Ok(match Sponsoring::<T>::get(contract_address) {192			SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => false,193			SponsorshipState::Unconfirmed(_) => true,194		})195	}196197	fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {198		Ok(<Pallet<T>>::sponsoring_mode(contract_address) != SponsoringModeT::Disabled)199	}200201	fn set_sponsoring_mode(202		&mut self,203		caller: caller,204		contract_address: address,205		// TODO: implement support for enums in evm-coder206		mode: uint8,207	) -> Result<void> {208		self.recorder().consume_sload()?;209		self.recorder().consume_sstore()?;210211		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;212		let mode = SponsoringModeT::from_eth(mode).ok_or("unknown mode")?;213		<Pallet<T>>::set_sponsoring_mode(contract_address, mode);214215		Ok(())216	}217218	/// Get current contract sponsoring rate limit219	/// @param contractAddress Contract to get sponsoring mode of220	/// @return uint32 Amount of blocks between two sponsored transactions221	fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {222		Ok(<SponsoringRateLimit<T>>::get(contract_address)223			.try_into()224			.map_err(|_| "rate limit > u32::MAX")?)225	}226227	/// Set contract sponsoring rate limit228	/// @dev Sponsoring rate limit - is a minimum amount of blocks that should229	///  pass between two sponsored transactions230	/// @param contractAddress Contract to change sponsoring rate limit of231	/// @param rateLimit Target rate limit232	/// @dev Only contract owner can change this setting233	fn set_sponsoring_rate_limit(234		&mut self,235		caller: caller,236		contract_address: address,237		rate_limit: uint32,238	) -> Result<void> {239		self.recorder().consume_sload()?;240		self.recorder().consume_sstore()?;241242		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;243		<Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());244		Ok(())245	}246247	/// Is specified user present in contract allow list248	/// @dev Contract owner always implicitly included249	/// @param contractAddress Contract to check allowlist of250	/// @param user User to check251	/// @return bool Is specified users exists in contract allowlist252	fn allowed(&self, contract_address: address, user: address) -> Result<bool> {253		self.0.consume_sload()?;254		Ok(<Pallet<T>>::allowed(contract_address, user))255	}256257	/// Toggle user presence in contract allowlist258	/// @param contractAddress Contract to change allowlist of259	/// @param user Which user presence should be toggled260	/// @param isAllowed `true` if user should be allowed to be sponsored261	///  or call this contract, `false` otherwise262	/// @dev Only contract owner can change this setting263	fn toggle_allowed(264		&mut self,265		caller: caller,266		contract_address: address,267		user: address,268		is_allowed: bool,269	) -> Result<void> {270		self.recorder().consume_sload()?;271		self.recorder().consume_sstore()?;272273		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;274		<Pallet<T>>::toggle_allowed(contract_address, user, is_allowed);275276		Ok(())277	}278279	/// Is this contract has allowlist access enabled280	/// @dev Allowlist always can have users, and it is used for two purposes:281	///  in case of allowlist sponsoring mode, users will be sponsored if they exist in allowlist282	///  in case of allowlist access enabled, only users from allowlist may call this contract283	/// @param contractAddress Contract to get allowlist access of284	/// @return bool Is specified contract has allowlist access enabled285	fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {286		Ok(<AllowlistEnabled<T>>::get(contract_address))287	}288289	/// Toggle contract allowlist access290	/// @param contractAddress Contract to change allowlist access of291	/// @param enabled Should allowlist access to be enabled?292	fn toggle_allowlist(293		&mut self,294		caller: caller,295		contract_address: address,296		enabled: bool,297	) -> Result<void> {298		self.recorder().consume_sload()?;299		self.recorder().consume_sstore()?;300301		<Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;302		<Pallet<T>>::toggle_allowlist(contract_address, enabled);303		Ok(())304	}305}306307/// Implements [`OnMethodCall`], which delegates call to [`ContractHelpers`]308pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);309impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T>310where311	T::AccountId: AsRef<[u8; 32]>,312{313	fn is_reserved(contract: &sp_core::H160) -> bool {314		contract == &T::ContractAddress::get()315	}316317	fn is_used(contract: &sp_core::H160) -> bool {318		contract == &T::ContractAddress::get()319	}320321	fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {322		// TODO: Extract to another OnMethodCall handler323		if <AllowlistEnabled<T>>::get(handle.code_address())324			&& !<Pallet<T>>::allowed(handle.code_address(), handle.context().caller)325		{326			return Some(Err(PrecompileFailure::Revert {327				exit_status: ExitRevert::Reverted,328				output: {329					let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));330					writer.string("Target contract is allowlisted");331					writer.finish()332				},333			}));334		}335336		if handle.code_address() != T::ContractAddress::get() {337			return None;338		}339340		let helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));341		pallet_evm_coder_substrate::call(handle, helpers)342	}343344	fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {345		(contract == &T::ContractAddress::get())346			.then(|| include_bytes!("./stubs/ContractHelpers.raw").to_vec())347	}348}349350/// Hooks into contract creation, storing owner of newly deployed contract351pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);352impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {353	fn on_create(owner: H160, contract: H160) {354		<Owner<T>>::insert(contract, owner);355	}356}357358/// Bridge to pallet-sponsoring359pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);360impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)>361	for HelpersContractSponsoring<T>362{363	fn get_sponsor(who: &T::CrossAccountId, call: &(H160, Vec<u8>)) -> Option<T::CrossAccountId> {364		let (contract_address, _) = call;365		let mode = <Pallet<T>>::sponsoring_mode(*contract_address);366		if mode == SponsoringModeT::Disabled {367			return None;368		}369370		let sponsor = match <Pallet<T>>::get_sponsor(*contract_address) {371			Some(sponsor) => sponsor,372			None => return None,373		};374375		if mode == SponsoringModeT::Allowlisted376			&& !<Pallet<T>>::allowed(*contract_address, *who.as_eth())377		{378			return None;379		}380		let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;381382		if let Some(last_tx_block) = <SponsorBasket<T>>::get(contract_address, who.as_eth()) {383			let limit = <SponsoringRateLimit<T>>::get(contract_address);384385			let timeout = last_tx_block + limit;386			if block_number < timeout {387				return None;388			}389		}390391		<SponsorBasket<T>>::insert(contract_address, who.as_eth(), block_number);392393		Some(sponsor)394	}395}396397generate_stubgen!(contract_helpers_impl, ContractHelpersCall<()>, true);398generate_stubgen!(contract_helpers_iface, ContractHelpersCall<()>, false);
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/lib.rs
+++ b/pallets/evm-contract-helpers/src/lib.rs
@@ -16,7 +16,7 @@
 
 #![doc = include_str!("../README.md")]
 #![cfg_attr(not(feature = "std"), no_std)]
-#![deny(missing_docs)]
+#![warn(missing_docs)]
 
 use codec::{Decode, Encode, MaxEncodedLen};
 pub use pallet::*;
@@ -27,18 +27,24 @@
 #[frame_support::pallet]
 pub mod pallet {
 	pub use super::*;
+	use crate::eth::ContractHelpersEvents;
 	use frame_support::pallet_prelude::*;
 	use pallet_evm_coder_substrate::DispatchResult;
 	use sp_core::H160;
-	use pallet_evm::account::CrossAccountId;
+	use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
 	use up_data_structs::SponsorshipState;
+	use evm_coder::ToLog;
 
 	#[pallet::config]
 	pub trait Config:
 		frame_system::Config + pallet_evm_coder_substrate::Config + pallet_evm::account::Config
 	{
+		/// Overarching event type.
+		type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;
+
 		/// Address, under which magic contract will be available
 		type ContractAddress: Get<H160>;
+
 		/// In case of enabled sponsoring, but no sponsoring rate limit set,
 		/// this value will be used implicitly
 		type DefaultSponsoringRateLimit: Get<Self::BlockNumber>;
@@ -150,6 +156,32 @@
 		QueryKind = ValueQuery,
 	>;
 
+	#[pallet::event]
+	#[pallet::generate_deposit(pub fn deposit_event)]
+	pub enum Event<T: Config> {
+		/// Contract sponsor was set.
+		ContractSponsorSet(
+			/// Contract address of the affected collection.
+			H160,
+			/// New sponsor address.
+			T::AccountId,
+		),
+
+		/// New sponsor was confirm.
+		ContractSponsorshipConfirmed(
+			/// Contract address of the affected collection.
+			H160,
+			/// New sponsor address.
+			T::AccountId,
+		),
+
+		/// Collection sponsor was removed.
+		ContractSponsorRemoved(
+			/// Contract address of the affected collection.
+			H160,
+		),
+	}
+
 	impl<T: Config> Pallet<T> {
 		/// Get contract owner.
 		pub fn contract_owner(contract: H160) -> H160 {
@@ -169,13 +201,25 @@
 				contract,
 				SponsorshipState::<T::CrossAccountId>::Unconfirmed(sponsor.clone()),
 			);
+
+			<Pallet<T>>::deposit_event(Event::<T>::ContractSponsorSet(
+				contract,
+				sponsor.as_sub().clone(),
+			));
+			<PalletEvm<T>>::deposit_log(
+				ContractHelpersEvents::ContractSponsorSet {
+					contract,
+					sponsor: *sponsor.as_eth(),
+				}
+				.to_log(contract),
+			);
 			Ok(())
 		}
 
-		/// Set `contract` as self sponsored.
+		/// Set sponsor as already confirmed.
 		///
 		/// `sender` must be owner of contract.
-		pub fn self_sponsored_enable(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
+		pub fn force_set_sponsor(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
 			Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;
 			Sponsoring::<T>::insert(
 				contract,
@@ -192,6 +236,12 @@
 		pub fn remove_sponsor(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
 			Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;
 			Sponsoring::<T>::remove(contract);
+
+			<Pallet<T>>::deposit_event(Event::<T>::ContractSponsorRemoved(contract));
+			<PalletEvm<T>>::deposit_log(
+				ContractHelpersEvents::ContractSponsorRemoved { contract }.to_log(contract),
+			);
+
 			Ok(())
 		}
 
@@ -202,10 +252,25 @@
 			match Sponsoring::<T>::get(contract) {
 				SponsorshipState::Unconfirmed(sponsor) => {
 					ensure!(sponsor == *sender, Error::<T>::NoPermission);
+					let eth_sponsor = *sponsor.as_eth();
+					let sub_sponsor = sponsor.as_sub().clone();
 					Sponsoring::<T>::insert(
 						contract,
 						SponsorshipState::<T::CrossAccountId>::Confirmed(sponsor),
 					);
+
+					<Pallet<T>>::deposit_event(Event::<T>::ContractSponsorshipConfirmed(
+						contract,
+						sub_sponsor,
+					));
+					<PalletEvm<T>>::deposit_log(
+						ContractHelpersEvents::ContractSponsorshipConfirmed {
+							contract,
+							sponsor: eth_sponsor,
+						}
+						.to_log(contract),
+					);
+
 					Ok(())
 				}
 				SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => {
modifiedruntime/common/config/ethereum.rsdiffbeforeafterboth
--- a/runtime/common/config/ethereum.rs
+++ b/runtime/common/config/ethereum.rs
@@ -112,6 +112,7 @@
 }
 
 impl pallet_evm_contract_helpers::Config for Runtime {
+	type Event = Event;
 	type ContractAddress = HelpersContractAddress;
 	type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
 }
modifiedruntime/common/config/pallets/app_promotion.rsdiffbeforeafterboth
--- a/runtime/common/config/pallets/app_promotion.rs
+++ b/runtime/common/config/pallets/app_promotion.rs
@@ -22,7 +22,7 @@
 use frame_support::{parameter_types, PalletId};
 use sp_arithmetic::Perbill;
 use up_common::{
-	constants::{ UNIQUE, RELAY_DAYS},
+	constants::{UNIQUE, RELAY_DAYS},
 	types::Balance,
 };
 
modifiedruntime/common/construct_runtime/mod.rsdiffbeforeafterboth
--- a/runtime/common/construct_runtime/mod.rs
+++ b/runtime/common/construct_runtime/mod.rs
@@ -85,7 +85,7 @@
                 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,
 
                 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,
-                EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,
+                EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage, Event<T>} = 151,
                 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,
                 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,
             }