git.delta.rocks / unique-network / refs/commits / 4efa9ce62081

difftreelog

doc(pallet-evm-contract-helpers): document public api

Yaroslav Bolyukin2022-07-12parent: #c098935.patch.diff
in: master

7 files changed

addedpallets/evm-contract-helpers/README.mddiffbeforeafterboth

no changes

modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
16
17//! Implementation of magic contract
1618
17use core::marker::PhantomData;19use core::marker::PhantomData;
18use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};20use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};
31use up_sponsorship::SponsorshipHandler;33use up_sponsorship::SponsorshipHandler;
32use sp_std::vec::Vec;34use sp_std::vec::Vec;
3335
36/// See [`ContractHelpersCall`]
34struct ContractHelpers<T: Config>(SubstrateRecorder<T>);37pub struct ContractHelpers<T: Config>(SubstrateRecorder<T>);
35impl<T: Config> WithRecorder<T> for ContractHelpers<T> {38impl<T: Config> WithRecorder<T> for ContractHelpers<T> {
36 fn recorder(&self) -> &SubstrateRecorder<T> {39 fn recorder(&self) -> &SubstrateRecorder<T> {
37 &self.040 &self.0
42 }45 }
43}46}
4447
48/// @title Magic contract, which allows users to reconfigure other contracts
45#[solidity_interface(name = ContractHelpers)]49#[solidity_interface(name = ContractHelpers)]
46impl<T: Config> ContractHelpers<T>50impl<T: Config> ContractHelpers<T>
47where51where
48 T::AccountId: AsRef<[u8; 32]>,52 T::AccountId: AsRef<[u8; 32]>,
49{53{
50 /// Get contract ovner54 /// Get user, which deployed specified contract
51 ///55 /// @dev May return zero address in case if contract is deployed
52 /// @param contractAddress contract for which the owner is being determined.56 /// using uniquenetwork evm-migration pallet, or using other terms not
57 /// intended by pallet-evm
58 /// @dev Returns zero address if contract does not exists
59 /// @param contractAddress Contract to get owner of
53 /// @return Contract owner.60 /// @return address Owner of contract
54 fn contract_owner(&self, contract_address: address) -> Result<address> {61 fn contract_owner(&self, contract_address: address) -> Result<address> {
55 Ok(<Owner<T>>::get(contract_address))62 Ok(<Owner<T>>::get(contract_address))
56 }63 }
5764
58 /// Set sponsor.65 /// Set sponsor.
59 ///
60 /// @param contractAddress Contract for which a sponsor is being established.66 /// @param contractAddress Contract for which a sponsor is being established.
61 /// @param sponsor User address who set as pending sponsor.67 /// @param sponsor User address who set as pending sponsor.
62 fn set_sponsor(68 fn set_sponsor(
163 &mut self,169 &mut self,
164 caller: caller,170 caller: caller,
165 contract_address: address,171 contract_address: address,
172 // TODO: implement support for enums in evm-coder
166 mode: uint8,173 mode: uint8,
167 ) -> Result<void> {174 ) -> Result<void> {
168 self.recorder().consume_sload()?;175 self.recorder().consume_sload()?;
175 Ok(())182 Ok(())
176 }183 }
177184
185 /// Get current contract sponsoring rate limit
186 /// @param contractAddress Contract to get sponsoring mode of
187 /// @return uint32 Amount of blocks between two sponsored transactions
178 fn sponsoring_mode(&self, contract_address: address) -> Result<uint8> {188 fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {
179 Ok(<Pallet<T>>::sponsoring_mode(contract_address).to_eth())189 Ok(<SponsoringRateLimit<T>>::get(contract_address)
190 .try_into()
191 .map_err(|_| "rate limit > u32::MAX")?)
180 }192 }
181193
194 /// Set contract sponsoring rate limit
195 /// @dev Sponsoring rate limit - is a minimum amount of blocks that should
196 /// pass between two sponsored transactions
197 /// @param contractAddress Contract to change sponsoring rate limit of
198 /// @param rateLimit Target rate limit
199 /// @dev Only contract owner can change this setting
182 fn set_sponsoring_rate_limit(200 fn set_sponsoring_rate_limit(
183 &mut self,201 &mut self,
184 caller: caller,202 caller: caller,
194 Ok(())211 Ok(())
195 }212 }
196213
197 fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {214 /// Is specified user present in contract allow list
198 Ok(<SponsoringRateLimit<T>>::get(contract_address)215 /// @dev Contract owner always implicitly included
199 .try_into()216 /// @param contractAddress Contract to check allowlist of
200 .map_err(|_| "rate limit > u32::MAX")?)217 /// @param user User to check
201 }218 /// @return bool Is specified users exists in contract allowlist
202
203 fn allowed(&self, contract_address: address, user: address) -> Result<bool> {219 fn allowed(&self, contract_address: address, user: address) -> Result<bool> {
204 self.0.consume_sload()?;220 self.0.consume_sload()?;
205 Ok(<Pallet<T>>::allowed(contract_address, user))221 Ok(<Pallet<T>>::allowed(contract_address, user))
206 }222 }
207223
208 fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {224 /// Toggle user presence in contract allowlist
209 Ok(<AllowlistEnabled<T>>::get(contract_address))225 /// @param contractAddress Contract to change allowlist of
210 }226 /// @param user Which user presence should be toggled
211227 /// @param isAllowed `true` if user should be allowed to be sponsored
228 /// or call this contract, `false` otherwise
229 /// @dev Only contract owner can change this setting
212 fn toggle_allowlist(230 fn toggle_allowed(
213 &mut self,231 &mut self,
214 caller: caller,232 caller: caller,
215 contract_address: address,233 contract_address: address,
234 user: address,
216 enabled: bool,235 is_allowed: bool,
217 ) -> Result<void> {236 ) -> Result<void> {
218 self.recorder().consume_sload()?;237 self.recorder().consume_sload()?;
219 self.recorder().consume_sstore()?;238 self.recorder().consume_sstore()?;
220239
221 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;240 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;
222 <Pallet<T>>::toggle_allowlist(contract_address, enabled);241 <Pallet<T>>::toggle_allowed(contract_address, user, is_allowed);
223242
224 Ok(())243 Ok(())
225 }244 }
226245
246 /// Is this contract has allowlist access enabled
247 /// @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 allowlist
249 /// in case of allowlist access enabled, only users from allowlist may call this contract
250 /// @param contractAddress Contract to get allowlist access of
251 /// @return bool Is specified contract has allowlist access enabled
252 fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {
253 Ok(<AllowlistEnabled<T>>::get(contract_address))
254 }
255
256 /// Toggle contract allowlist access
257 /// @param contractAddress Contract to change allowlist access of
258 /// @param enabled Should allowlist access to be enabled?
227 fn toggle_allowed(259 fn toggle_allowlist(
228 &mut self,260 &mut self,
229 caller: caller,261 caller: caller,
230 contract_address: address,262 contract_address: address,
231 user: address,
232 is_allowed: bool,263 enabled: bool,
233 ) -> Result<void> {264 ) -> Result<void> {
234 self.recorder().consume_sload()?;265 self.recorder().consume_sload()?;
235 self.recorder().consume_sstore()?;266 self.recorder().consume_sstore()?;
236267
237 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;268 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;
238 <Pallet<T>>::toggle_allowed(contract_address, user, is_allowed);269 <Pallet<T>>::toggle_allowlist(contract_address, enabled);
239
240 Ok(())270 Ok(())
241 }271 }
242}272}
243273
274/// Implements [`OnMethodCall`], which delegates call to [`ContractHelpers`]
244pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);275pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);
245impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T>276impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T>
246where277where
283 }314 }
284}315}
285316
317/// Hooks into contract creation, storing owner of newly deployed contract
286pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);318pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);
287impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {319impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {
288 fn on_create(owner: H160, contract: H160) {320 fn on_create(owner: H160, contract: H160) {
289 <Owner<T>>::insert(contract, owner);321 <Owner<T>>::insert(contract, owner);
290 }322 }
291}323}
292324
325/// Bridge to pallet-sponsoring
293pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);326pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);
294impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)>327impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)>
295 for HelpersContractSponsoring<T>328 for HelpersContractSponsoring<T>
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
14// You should have received a copy of the GNU General Public License14// You should have received a copy of the GNU General Public License
15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
1616
17#![doc = include_str!("../README.md")]
17#![cfg_attr(not(feature = "std"), no_std)]18#![cfg_attr(not(feature = "std"), no_std)]
19#![deny(missing_docs)]
1820
19use codec::{Decode, Encode, MaxEncodedLen};21use codec::{Decode, Encode, MaxEncodedLen};
20pub use pallet::*;22pub use pallet::*;
35 pub trait Config:37 pub trait Config:
36 frame_system::Config + pallet_evm_coder_substrate::Config + pallet_evm::account::Config38 frame_system::Config + pallet_evm_coder_substrate::Config + pallet_evm::account::Config
37 {39 {
40 /// Address, under which magic contract will be available
38 type ContractAddress: Get<H160>;41 type ContractAddress: Get<H160>;
42 /// In case of enabled sponsoring, but no sponsoring rate limit set,
43 /// this value will be used implicitly
39 type DefaultSponsoringRateLimit: Get<Self::BlockNumber>;44 type DefaultSponsoringRateLimit: Get<Self::BlockNumber>;
40 }45 }
4146
42 #[pallet::error]47 #[pallet::error]
43 pub enum Error<T> {48 pub enum Error<T> {
44 /// This method is only executable by owner.49 /// This method is only executable by contract owner
45 NoPermission,50 NoPermission,
4651
47 /// No pending sponsor for contract.52 /// No pending sponsor for contract.
217 }222 }
218 }223 }
219224
225 /// Get current sponsoring mode, performing lazy migration from legacy storage
220 pub fn sponsoring_mode(contract: H160) -> SponsoringModeT {226 pub fn sponsoring_mode(contract: H160) -> SponsoringModeT {
221 <SponsoringMode<T>>::get(contract)227 <SponsoringMode<T>>::get(contract)
222 .or_else(|| {228 .or_else(|| {
225 .unwrap_or_default()231 .unwrap_or_default()
226 }232 }
227233
234 /// Reconfigure contract sponsoring mode
228 pub fn set_sponsoring_mode(contract: H160, mode: SponsoringModeT) {235 pub fn set_sponsoring_mode(contract: H160, mode: SponsoringModeT) {
229 if mode == SponsoringModeT::Disabled {236 if mode == SponsoringModeT::Disabled {
230 <SponsoringMode<T>>::remove(contract);237 <SponsoringMode<T>>::remove(contract);
234 <SelfSponsoring<T>>::remove(contract)241 <SelfSponsoring<T>>::remove(contract)
235 }242 }
236243
244 /// Set duration between two sponsored contract calls
237 pub fn set_sponsoring_rate_limit(contract: H160, rate_limit: T::BlockNumber) {245 pub fn set_sponsoring_rate_limit(contract: H160, rate_limit: T::BlockNumber) {
238 <SponsoringRateLimit<T>>::insert(contract, rate_limit);246 <SponsoringRateLimit<T>>::insert(contract, rate_limit);
239 }247 }
240248
249 /// Is user added to allowlist, or he is owner of specified contract
241 pub fn allowed(contract: H160, user: H160) -> bool {250 pub fn allowed(contract: H160, user: H160) -> bool {
242 <Allowlist<T>>::get(&contract, &user) || <Owner<T>>::get(&contract) == user251 <Allowlist<T>>::get(&contract, &user) || <Owner<T>>::get(&contract) == user
243 }252 }
244253
254 /// Toggle contract allowlist access
245 pub fn toggle_allowlist(contract: H160, enabled: bool) {255 pub fn toggle_allowlist(contract: H160, enabled: bool) {
246 <AllowlistEnabled<T>>::insert(contract, enabled)256 <AllowlistEnabled<T>>::insert(contract, enabled)
247 }257 }
248258
259 /// Toggle user presence in contract's allowlist
249 pub fn toggle_allowed(contract: H160, user: H160, allowed: bool) {260 pub fn toggle_allowed(contract: H160, user: H160, allowed: bool) {
250 <Allowlist<T>>::insert(contract, user, allowed);261 <Allowlist<T>>::insert(contract, user, allowed);
251 }262 }
252263
264 /// Throw error if user is not allowed to reconfigure target contract
253 pub fn ensure_owner(contract: H160, user: H160) -> DispatchResult {265 pub fn ensure_owner(contract: H160, user: H160) -> DispatchResult {
254 ensure!(<Owner<T>>::get(&contract) == user, Error::<T>::NoPermission);266 ensure!(<Owner<T>>::get(&contract) == user, Error::<T>::NoPermission);
255 Ok(())267 Ok(())
256 }268 }
257 }269 }
258}270}
259271
272/// Available contract sponsoring modes
260#[derive(Encode, Decode, PartialEq, TypeInfo, MaxEncodedLen)]273#[derive(Encode, Decode, PartialEq, TypeInfo, MaxEncodedLen, Default)]
261pub enum SponsoringModeT {274pub enum SponsoringModeT {
275 /// Sponsoring is disabled
276 #[default]
262 Disabled,277 Disabled,
278 /// Only users from allowlist will be sponsored
263 Allowlisted,279 Allowlisted,
280 /// All users will be sponsored
264 Generous,281 Generous,
265}282}
266283
282 }299 }
283}300}
284
285impl Default for SponsoringModeT {
286 fn default() -> Self {
287 Self::Disabled
288 }
289}
290301
modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth
33
4pragma solidity >=0.8.0 <0.9.0;4pragma solidity >=0.8.0 <0.9.0;
5
6/// @dev anonymous struct
7struct Tuple0 {
8 address field_0;
9 uint256 field_1;
10}
115
12/// @dev common stubs holder6/// @dev common stubs holder
13contract Dummy {7contract Dummy {
27 }21 }
28}22}
2923
24/// @title Magic contract, which allows users to reconfigure other contracts
30/// @dev the ERC-165 identifier for this interface is 0x6073d91725/// @dev the ERC-165 identifier for this interface is 0xd77fab70
31contract ContractHelpers is Dummy, ERC165 {26contract ContractHelpers is Dummy, ERC165 {
32 /// Get contract ovner27 /// Get user, which deployed specified contract
33 ///28 /// @dev May return zero address in case if contract is deployed
34 /// @param contractAddress contract for which the owner is being determined.29 /// using uniquenetwork evm-migration pallet, or using other terms not
30 /// intended by pallet-evm
31 /// @dev Returns zero address if contract does not exists
32 /// @param contractAddress Contract to get owner of
35 /// @return Contract owner.33 /// @return address Owner of contract
36 ///34 /// @dev EVM selector for this function is: 0x5152b14c,
37 /// Selector: contractOwner(address) 5152b14c35 /// or in textual repr: contractOwner(address)
38 function contractOwner(address contractAddress)36 function contractOwner(address contractAddress)
39 public37 public
40 view38 view
47 }45 }
4846
49 /// Set sponsor.47 /// Set sponsor.
50 ///
51 /// @param contractAddress Contract for which a sponsor is being established.48 /// @param contractAddress Contract for which a sponsor is being established.
52 /// @param sponsor User address who set as pending sponsor.49 /// @param sponsor User address who set as pending sponsor.
53 ///50 /// @dev EVM selector for this function is: 0xf01fba93,
54 /// Selector: setSponsor(address,address) f01fba9351 /// or in textual repr: setSponsor(address,address)
55 function setSponsor(address contractAddress, address sponsor) public {52 function setSponsor(address contractAddress, address sponsor) public {
56 require(false, stub_error);53 require(false, stub_error);
57 contractAddress;54 contractAddress;
62 /// Set contract as self sponsored.59 /// Set contract as self sponsored.
63 ///60 ///
64 /// @param contractAddress Contract for which a self sponsoring is being enabled.61 /// @param contractAddress Contract for which a self sponsoring is being enabled.
65 ///62 /// @dev EVM selector for this function is: 0x89f7d9ae,
66 /// Selector: selfSponsoredEnable(address) 89f7d9ae63 /// or in textual repr: selfSponsoredEnable(address)
67 function selfSponsoredEnable(address contractAddress) public {64 function selfSponsoredEnable(address contractAddress) public {
68 require(false, stub_error);65 require(false, stub_error);
69 contractAddress;66 contractAddress;
73 /// Remove sponsor.70 /// Remove sponsor.
74 ///71 ///
75 /// @param contractAddress Contract for which a sponsorship is being removed.72 /// @param contractAddress Contract for which a sponsorship is being removed.
76 ///73 /// @dev EVM selector for this function is: 0xef784250,
77 /// Selector: removeSponsor(address) ef78425074 /// or in textual repr: removeSponsor(address)
78 function removeSponsor(address contractAddress) public {75 function removeSponsor(address contractAddress) public {
79 require(false, stub_error);76 require(false, stub_error);
80 contractAddress;77 contractAddress;
86 /// @dev Caller must be same that set via [`setSponsor`].83 /// @dev Caller must be same that set via [`setSponsor`].
87 ///84 ///
88 /// @param contractAddress Сontract for which need to confirm sponsorship.85 /// @param contractAddress Сontract for which need to confirm sponsorship.
89 ///86 /// @dev EVM selector for this function is: 0xabc00001,
90 /// Selector: confirmSponsorship(address) abc0000187 /// or in textual repr: confirmSponsorship(address)
91 function confirmSponsorship(address contractAddress) public {88 function confirmSponsorship(address contractAddress) public {
92 require(false, stub_error);89 require(false, stub_error);
93 contractAddress;90 contractAddress;
98 ///95 ///
99 /// @param contractAddress The contract for which a sponsor is requested.96 /// @param contractAddress The contract for which a sponsor is requested.
100 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.97 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
101 ///98 /// @dev EVM selector for this function is: 0x743fc745,
102 /// Selector: getSponsor(address) 743fc74599 /// or in textual repr: getSponsor(address)
103 function getSponsor(address contractAddress)100 function getSponsor(address contractAddress)
104 public101 public
105 view102 view
115 ///112 ///
116 /// @param contractAddress The contract for which the presence of a confirmed sponsor is checked.113 /// @param contractAddress The contract for which the presence of a confirmed sponsor is checked.
117 /// @return **true** if contract has confirmed sponsor.114 /// @return **true** if contract has confirmed sponsor.
118 ///115 /// @dev EVM selector for this function is: 0x97418603,
119 /// Selector: hasSponsor(address) 97418603116 /// or in textual repr: hasSponsor(address)
120 function hasSponsor(address contractAddress) public view returns (bool) {117 function hasSponsor(address contractAddress) public view returns (bool) {
121 require(false, stub_error);118 require(false, stub_error);
122 contractAddress;119 contractAddress;
128 ///125 ///
129 /// @param contractAddress The contract for which the presence of a pending sponsor is checked.126 /// @param contractAddress The contract for which the presence of a pending sponsor is checked.
130 /// @return **true** if contract has pending sponsor.127 /// @return **true** if contract has pending sponsor.
131 ///128 /// @dev EVM selector for this function is: 0x39b9b242,
132 /// Selector: hasPendingSponsor(address) 39b9b242129 /// or in textual repr: hasPendingSponsor(address)
133 function hasPendingSponsor(address contractAddress)130 function hasPendingSponsor(address contractAddress)
134 public131 public
135 view132 view
141 return false;138 return false;
142 }139 }
143140
141 /// @dev EVM selector for this function is: 0x6027dc61,
144 /// Selector: sponsoringEnabled(address) 6027dc61142 /// or in textual repr: sponsoringEnabled(address)
145 function sponsoringEnabled(address contractAddress)143 function sponsoringEnabled(address contractAddress)
146 public144 public
147 view145 view
153 return false;151 return false;
154 }152 }
155153
154 /// @dev EVM selector for this function is: 0xfde8a560,
156 /// Selector: setSponsoringMode(address,uint8) fde8a560155 /// or in textual repr: setSponsoringMode(address,uint8)
157 function setSponsoringMode(address contractAddress, uint8 mode) public {156 function setSponsoringMode(address contractAddress, uint8 mode) public {
158 require(false, stub_error);157 require(false, stub_error);
159 contractAddress;158 contractAddress;
160 mode;159 mode;
161 dummy = 0;160 dummy = 0;
162 }161 }
163162
164 /// Selector: sponsoringMode(address) b70c7267163 /// Get current contract sponsoring rate limit
164 /// @param contractAddress Contract to get sponsoring mode of
165 /// @return uint32 Amount of blocks between two sponsored transactions
166 /// @dev EVM selector for this function is: 0x610cfabd,
167 /// or in textual repr: getSponsoringRateLimit(address)
165 function sponsoringMode(address contractAddress)168 function getSponsoringRateLimit(address contractAddress)
166 public169 public
167 view170 view
168 returns (uint8)171 returns (uint32)
169 {172 {
170 require(false, stub_error);173 require(false, stub_error);
171 contractAddress;174 contractAddress;
172 dummy;175 dummy;
173 return 0;176 return 0;
174 }177 }
175178
179 /// Set contract sponsoring rate limit
180 /// @dev Sponsoring rate limit - is a minimum amount of blocks that should
181 /// pass between two sponsored transactions
182 /// @param contractAddress Contract to change sponsoring rate limit of
183 /// @param rateLimit Target rate limit
184 /// @dev Only contract owner can change this setting
185 /// @dev EVM selector for this function is: 0x77b6c908,
176 /// Selector: setSponsoringRateLimit(address,uint32) 77b6c908186 /// or in textual repr: setSponsoringRateLimit(address,uint32)
177 function setSponsoringRateLimit(address contractAddress, uint32 rateLimit)187 function setSponsoringRateLimit(address contractAddress, uint32 rateLimit)
178 public188 public
179 {189 {
183 dummy = 0;193 dummy = 0;
184 }194 }
185195
186 /// Selector: getSponsoringRateLimit(address) 610cfabd196 /// Is specified user present in contract allow list
197 /// @dev Contract owner always implicitly included
198 /// @param contractAddress Contract to check allowlist of
199 /// @param user User to check
200 /// @return bool Is specified users exists in contract allowlist
201 /// @dev EVM selector for this function is: 0x5c658165,
202 /// or in textual repr: allowed(address,address)
187 function getSponsoringRateLimit(address contractAddress)203 function allowed(address contractAddress, address user)
188 public204 public
189 view205 view
190 returns (uint32)206 returns (bool)
191 {207 {
192 require(false, stub_error);208 require(false, stub_error);
193 contractAddress;209 contractAddress;
210 user;
194 dummy;211 dummy;
195 return 0;212 return false;
196 }213 }
197214
215 /// Toggle user presence in contract allowlist
216 /// @param contractAddress Contract to change allowlist of
217 /// @param user Which user presence should be toggled
218 /// @param isAllowed `true` if user should be allowed to be sponsored
219 /// or call this contract, `false` otherwise
220 /// @dev Only contract owner can change this setting
221 /// @dev EVM selector for this function is: 0x4706cc1c,
198 /// Selector: allowed(address,address) 5c658165222 /// or in textual repr: toggleAllowed(address,address,bool)
199 function allowed(address contractAddress, address user)223 function toggleAllowed(
224 address contractAddress,
225 address user,
226 bool isAllowed
200 public227 ) public {
201 view
202 returns (bool)
203 {
204 require(false, stub_error);228 require(false, stub_error);
205 contractAddress;229 contractAddress;
206 user;230 user;
207 dummy;231 isAllowed;
208 return false;232 dummy = 0;
209 }233 }
210234
235 /// Is this contract has allowlist access enabled
236 /// @dev Allowlist always can have users, and it is used for two purposes:
237 /// in case of allowlist sponsoring mode, users will be sponsored if they exist in allowlist
238 /// in case of allowlist access enabled, only users from allowlist may call this contract
239 /// @param contractAddress Contract to get allowlist access of
240 /// @return bool Is specified contract has allowlist access enabled
241 /// @dev EVM selector for this function is: 0xc772ef6c,
211 /// Selector: allowlistEnabled(address) c772ef6c242 /// or in textual repr: allowlistEnabled(address)
212 function allowlistEnabled(address contractAddress)243 function allowlistEnabled(address contractAddress)
213 public244 public
214 view245 view
220 return false;251 return false;
221 }252 }
222253
254 /// Toggle contract allowlist access
255 /// @param contractAddress Contract to change allowlist access of
256 /// @param enabled Should allowlist access to be enabled?
257 /// @dev EVM selector for this function is: 0x36de20f5,
223 /// Selector: toggleAllowlist(address,bool) 36de20f5258 /// or in textual repr: toggleAllowlist(address,bool)
224 function toggleAllowlist(address contractAddress, bool enabled) public {259 function toggleAllowlist(address contractAddress, bool enabled) public {
225 require(false, stub_error);260 require(false, stub_error);
226 contractAddress;261 contractAddress;
227 enabled;262 enabled;
228 dummy = 0;263 dummy = 0;
229 }264 }
230
231 /// Selector: toggleAllowed(address,address,bool) 4706cc1c
232 function toggleAllowed(
233 address contractAddress,
234 address user,
235 bool isAllowed
236 ) public {
237 require(false, stub_error);
238 contractAddress;
239 user;
240 isAllowed;
241 dummy = 0;
242 }
243}265}
266
267/// @dev anonymous struct
268struct Tuple0 {
269 address field_0;
270 uint256 field_1;
271}
244272
modifiedtests/src/eth/api/ContractHelpers.soldiffbeforeafterboth
33
4pragma solidity >=0.8.0 <0.9.0;4pragma solidity >=0.8.0 <0.9.0;
5
6/// @dev anonymous struct
7struct Tuple0 {
8 address field_0;
9 uint256 field_1;
10}
115
12/// @dev common stubs holder6/// @dev common stubs holder
13interface Dummy {7interface Dummy {
18 function supportsInterface(bytes4 interfaceID) external view returns (bool);12 function supportsInterface(bytes4 interfaceID) external view returns (bool);
19}13}
2014
15/// @title Magic contract, which allows users to reconfigure other contracts
21/// @dev the ERC-165 identifier for this interface is 0x6073d91716/// @dev the ERC-165 identifier for this interface is 0xd77fab70
22interface ContractHelpers is Dummy, ERC165 {17interface ContractHelpers is Dummy, ERC165 {
23 /// Get contract ovner18 /// Get user, which deployed specified contract
24 ///19 /// @dev May return zero address in case if contract is deployed
25 /// @param contractAddress contract for which the owner is being determined.20 /// using uniquenetwork evm-migration pallet, or using other terms not
21 /// intended by pallet-evm
22 /// @dev Returns zero address if contract does not exists
23 /// @param contractAddress Contract to get owner of
26 /// @return Contract owner.24 /// @return address Owner of contract
27 ///25 /// @dev EVM selector for this function is: 0x5152b14c,
28 /// Selector: contractOwner(address) 5152b14c26 /// or in textual repr: contractOwner(address)
29 function contractOwner(address contractAddress)27 function contractOwner(address contractAddress)
30 external28 external
31 view29 view
32 returns (address);30 returns (address);
3331
34 /// Set sponsor.32 /// Set sponsor.
35 ///
36 /// @param contractAddress Contract for which a sponsor is being established.33 /// @param contractAddress Contract for which a sponsor is being established.
37 /// @param sponsor User address who set as pending sponsor.34 /// @param sponsor User address who set as pending sponsor.
38 ///35 /// @dev EVM selector for this function is: 0xf01fba93,
39 /// Selector: setSponsor(address,address) f01fba9336 /// or in textual repr: setSponsor(address,address)
40 function setSponsor(address contractAddress, address sponsor) external;37 function setSponsor(address contractAddress, address sponsor) external;
4138
42 /// Set contract as self sponsored.39 /// Set contract as self sponsored.
43 ///40 ///
44 /// @param contractAddress Contract for which a self sponsoring is being enabled.41 /// @param contractAddress Contract for which a self sponsoring is being enabled.
45 ///42 /// @dev EVM selector for this function is: 0x89f7d9ae,
46 /// Selector: selfSponsoredEnable(address) 89f7d9ae43 /// or in textual repr: selfSponsoredEnable(address)
47 function selfSponsoredEnable(address contractAddress) external;44 function selfSponsoredEnable(address contractAddress) external;
4845
49 /// Remove sponsor.46 /// Remove sponsor.
50 ///47 ///
51 /// @param contractAddress Contract for which a sponsorship is being removed.48 /// @param contractAddress Contract for which a sponsorship is being removed.
52 ///49 /// @dev EVM selector for this function is: 0xef784250,
53 /// Selector: removeSponsor(address) ef78425050 /// or in textual repr: removeSponsor(address)
54 function removeSponsor(address contractAddress) external;51 function removeSponsor(address contractAddress) external;
5552
56 /// Confirm sponsorship.53 /// Confirm sponsorship.
57 ///54 ///
58 /// @dev Caller must be same that set via [`setSponsor`].55 /// @dev Caller must be same that set via [`setSponsor`].
59 ///56 ///
60 /// @param contractAddress Сontract for which need to confirm sponsorship.57 /// @param contractAddress Сontract for which need to confirm sponsorship.
61 ///58 /// @dev EVM selector for this function is: 0xabc00001,
62 /// Selector: confirmSponsorship(address) abc0000159 /// or in textual repr: confirmSponsorship(address)
63 function confirmSponsorship(address contractAddress) external;60 function confirmSponsorship(address contractAddress) external;
6461
65 /// Get current sponsor.62 /// Get current sponsor.
66 ///63 ///
67 /// @param contractAddress The contract for which a sponsor is requested.64 /// @param contractAddress The contract for which a sponsor is requested.
68 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.65 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
69 ///66 /// @dev EVM selector for this function is: 0x743fc745,
70 /// Selector: getSponsor(address) 743fc74567 /// or in textual repr: getSponsor(address)
71 function getSponsor(address contractAddress)68 function getSponsor(address contractAddress)
72 external69 external
73 view70 view
77 ///74 ///
78 /// @param contractAddress The contract for which the presence of a confirmed sponsor is checked.75 /// @param contractAddress The contract for which the presence of a confirmed sponsor is checked.
79 /// @return **true** if contract has confirmed sponsor.76 /// @return **true** if contract has confirmed sponsor.
80 ///77 /// @dev EVM selector for this function is: 0x97418603,
81 /// Selector: hasSponsor(address) 9741860378 /// or in textual repr: hasSponsor(address)
82 function hasSponsor(address contractAddress) external view returns (bool);79 function hasSponsor(address contractAddress) external view returns (bool);
8380
84 /// Check tat contract has pending sponsor.81 /// Check tat contract has pending sponsor.
85 ///82 ///
86 /// @param contractAddress The contract for which the presence of a pending sponsor is checked.83 /// @param contractAddress The contract for which the presence of a pending sponsor is checked.
87 /// @return **true** if contract has pending sponsor.84 /// @return **true** if contract has pending sponsor.
88 ///85 /// @dev EVM selector for this function is: 0x39b9b242,
89 /// Selector: hasPendingSponsor(address) 39b9b24286 /// or in textual repr: hasPendingSponsor(address)
90 function hasPendingSponsor(address contractAddress)87 function hasPendingSponsor(address contractAddress)
91 external88 external
92 view89 view
93 returns (bool);90 returns (bool);
9491
92 /// @dev EVM selector for this function is: 0x6027dc61,
95 /// Selector: sponsoringEnabled(address) 6027dc6193 /// or in textual repr: sponsoringEnabled(address)
96 function sponsoringEnabled(address contractAddress)94 function sponsoringEnabled(address contractAddress)
97 external95 external
98 view96 view
99 returns (bool);97 returns (bool);
10098
99 /// @dev EVM selector for this function is: 0xfde8a560,
101 /// Selector: setSponsoringMode(address,uint8) fde8a560100 /// or in textual repr: setSponsoringMode(address,uint8)
102 function setSponsoringMode(address contractAddress, uint8 mode) external;101 function setSponsoringMode(address contractAddress, uint8 mode) external;
103102
104 /// Selector: sponsoringMode(address) b70c7267103 /// Get current contract sponsoring rate limit
104 /// @param contractAddress Contract to get sponsoring mode of
105 /// @return uint32 Amount of blocks between two sponsored transactions
106 /// @dev EVM selector for this function is: 0x610cfabd,
107 /// or in textual repr: getSponsoringRateLimit(address)
105 function sponsoringMode(address contractAddress)108 function getSponsoringRateLimit(address contractAddress)
106 external109 external
107 view110 view
108 returns (uint8);111 returns (uint32);
109112
113 /// Set contract sponsoring rate limit
114 /// @dev Sponsoring rate limit - is a minimum amount of blocks that should
115 /// pass between two sponsored transactions
116 /// @param contractAddress Contract to change sponsoring rate limit of
117 /// @param rateLimit Target rate limit
118 /// @dev Only contract owner can change this setting
119 /// @dev EVM selector for this function is: 0x77b6c908,
110 /// Selector: setSponsoringRateLimit(address,uint32) 77b6c908120 /// or in textual repr: setSponsoringRateLimit(address,uint32)
111 function setSponsoringRateLimit(address contractAddress, uint32 rateLimit)121 function setSponsoringRateLimit(address contractAddress, uint32 rateLimit)
112 external;122 external;
113123
114 /// Selector: getSponsoringRateLimit(address) 610cfabd124 /// Is specified user present in contract allow list
125 /// @dev Contract owner always implicitly included
126 /// @param contractAddress Contract to check allowlist of
127 /// @param user User to check
128 /// @return bool Is specified users exists in contract allowlist
129 /// @dev EVM selector for this function is: 0x5c658165,
130 /// or in textual repr: allowed(address,address)
115 function getSponsoringRateLimit(address contractAddress)131 function allowed(address contractAddress, address user)
116 external132 external
117 view133 view
118 returns (uint32);134 returns (bool);
119135
136 /// Toggle user presence in contract allowlist
137 /// @param contractAddress Contract to change allowlist of
138 /// @param user Which user presence should be toggled
139 /// @param isAllowed `true` if user should be allowed to be sponsored
140 /// or call this contract, `false` otherwise
141 /// @dev Only contract owner can change this setting
142 /// @dev EVM selector for this function is: 0x4706cc1c,
120 /// Selector: allowed(address,address) 5c658165143 /// or in textual repr: toggleAllowed(address,address,bool)
121 function allowed(address contractAddress, address user)144 function toggleAllowed(
145 address contractAddress,
146 address user,
147 bool isAllowed
122 external148 ) external;
123 view149
124 returns (bool);150 /// Is this contract has allowlist access enabled
125151 /// @dev Allowlist always can have users, and it is used for two purposes:
152 /// in case of allowlist sponsoring mode, users will be sponsored if they exist in allowlist
153 /// in case of allowlist access enabled, only users from allowlist may call this contract
154 /// @param contractAddress Contract to get allowlist access of
155 /// @return bool Is specified contract has allowlist access enabled
156 /// @dev EVM selector for this function is: 0xc772ef6c,
126 /// Selector: allowlistEnabled(address) c772ef6c157 /// or in textual repr: allowlistEnabled(address)
127 function allowlistEnabled(address contractAddress)158 function allowlistEnabled(address contractAddress)
128 external159 external
129 view160 view
130 returns (bool);161 returns (bool);
131162
163 /// Toggle contract allowlist access
164 /// @param contractAddress Contract to change allowlist access of
165 /// @param enabled Should allowlist access to be enabled?
166 /// @dev EVM selector for this function is: 0x36de20f5,
132 /// Selector: toggleAllowlist(address,bool) 36de20f5167 /// or in textual repr: toggleAllowlist(address,bool)
133 function toggleAllowlist(address contractAddress, bool enabled) external;168 function toggleAllowlist(address contractAddress, bool enabled) external;
134
135 /// Selector: toggleAllowed(address,address,bool) 4706cc1c
136 function toggleAllowed(
137 address contractAddress,
138 address user,
139 bool isAllowed
140 ) external;
141}169}
170
171/// @dev anonymous struct
172struct Tuple0 {
173 address field_0;
174 uint256 field_1;
175}
142176
modifiedtests/src/eth/util/contractHelpersAbi.jsondiffbeforeafterboth
195 "stateMutability": "view",195 "stateMutability": "view",
196 "type": "function"196 "type": "function"
197 },197 },
198 {
199 "inputs": [
200 {
201 "internalType": "address",
202 "name": "contractAddress",
203 "type": "address"
204 }
205 ],
206 "name": "sponsoringMode",
207 "outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
208 "stateMutability": "view",
209 "type": "function"
210 },
211 {198 {
212 "inputs": [199 "inputs": [
213 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }200 { "internalType": "bytes4", "name": "interfaceID", "type": "bytes4" }