difftreelog
feat Add some collection methods to eth.
in: master
17 files changed
pallets/common/src/erc.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -32,7 +32,10 @@
use crate::{
Pallet, CollectionHandle, Config, CollectionProperties,
- eth::{convert_cross_account_to_uint256, convert_uint256_to_cross_account},
+ eth::{
+ convert_cross_account_to_uint256, convert_uint256_to_cross_account,
+ convert_cross_account_to_tuple,
+ },
};
/// Events for ethereum collection helper.
@@ -146,7 +149,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,
@@ -275,7 +278,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))
}
@@ -420,6 +423,16 @@
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.
@@ -430,6 +443,20 @@
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> {
+ 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.
@@ -440,6 +467,20 @@
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> {
+ 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".
@@ -481,7 +522,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,6 +531,16 @@
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
@@ -511,6 +562,14 @@
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)
+ // }
}
fn check_is_owner_or_admin<T: Config>(
pallets/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,17 @@
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())
+ }
+}
\ No newline at end of file
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth1// 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: address,46 /// New sponsor address.47 sponsor: address,48 },4950 /// New sponsor was confirm.51 ContractSponsorshipConfirmed {52 /// Contract address of the affected collection.53 #[indexed]54 contract_address: address,55 /// New sponsor address.56 sponsor: address,57 },5859 /// Collection sponsor was removed.60 ContractSponsorRemoved {61 /// Contract address of the affected collection.62 #[indexed]63 contract_address: address,64 },65}6667/// See [`ContractHelpersCall`]68pub struct ContractHelpers<T: Config>(SubstrateRecorder<T>);69impl<T: Config> WithRecorder<T> for ContractHelpers<T> {70 fn recorder(&self) -> &SubstrateRecorder<T> {71 &self.072 }7374 fn into_recorder(self) -> SubstrateRecorder<T> {75 self.076 }77}7879/// @title Magic contract, which allows users to reconfigure other contracts80#[solidity_interface(name = ContractHelpers, events(ContractHelpersEvents))]81impl<T: Config> ContractHelpers<T>82where83 T::AccountId: AsRef<[u8; 32]>,84{85 /// Get user, which deployed specified contract86 /// @dev May return zero address in case if contract is deployed87 /// using uniquenetwork evm-migration pallet, or using other terms not88 /// intended by pallet-evm89 /// @dev Returns zero address if contract does not exists90 /// @param contractAddress Contract to get owner of91 /// @return address Owner of contract92 fn contract_owner(&self, contract_address: address) -> Result<address> {93 Ok(<Owner<T>>::get(contract_address))94 }9596 /// Set sponsor.97 /// @param contractAddress Contract for which a sponsor is being established.98 /// @param sponsor User address who set as pending sponsor.99 fn set_sponsor(100 &mut self,101 caller: caller,102 contract_address: address,103 sponsor: address,104 ) -> Result<void> {105 self.recorder().consume_sload()?;106 self.recorder().consume_sstore()?;107108 Pallet::<T>::set_sponsor(109 &T::CrossAccountId::from_eth(caller),110 contract_address,111 &T::CrossAccountId::from_eth(sponsor),112 )113 .map_err(dispatch_to_evm::<T>)?;114115 Ok(())116 }117118 /// Set contract as self sponsored.119 ///120 /// @param contractAddress Contract for which a self sponsoring is being enabled.121 fn self_sponsored_enable(&mut self, caller: caller, contract_address: address) -> Result<void> {122 self.recorder().consume_sload()?;123 self.recorder().consume_sstore()?;124125 let caller = T::CrossAccountId::from_eth(caller);126127 Pallet::<T>::ensure_owner(contract_address, *caller.as_eth())128 .map_err(dispatch_to_evm::<T>)?;129130 Pallet::<T>::force_set_sponsor(131 contract_address,132 &T::CrossAccountId::from_eth(contract_address),133 )134 .map_err(dispatch_to_evm::<T>)?;135136 Ok(())137 }138139 /// Remove sponsor.140 ///141 /// @param contractAddress Contract for which a sponsorship is being removed.142 fn remove_sponsor(&mut self, caller: caller, contract_address: address) -> Result<void> {143 self.recorder().consume_sload()?;144 self.recorder().consume_sstore()?;145146 Pallet::<T>::remove_sponsor(&T::CrossAccountId::from_eth(caller), contract_address)147 .map_err(dispatch_to_evm::<T>)?;148149 Ok(())150 }151152 /// Confirm sponsorship.153 ///154 /// @dev Caller must be same that set via [`setSponsor`].155 ///156 /// @param contractAddress Сontract for which need to confirm sponsorship.157 fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {158 self.recorder().consume_sload()?;159 self.recorder().consume_sstore()?;160161 Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)162 .map_err(dispatch_to_evm::<T>)?;163164 Ok(())165 }166167 /// Get current sponsor.168 ///169 /// @param contractAddress The contract for which a sponsor is requested.170 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.171 fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {172 let sponsor =173 Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;174 let result: (address, uint256) = if sponsor.is_canonical_substrate() {175 let sponsor = pallet_common::eth::convert_cross_account_to_uint256::<T>(&sponsor);176 (Default::default(), sponsor)177 } else {178 let sponsor = *sponsor.as_eth();179 (sponsor, Default::default())180 };181 Ok(result)182 }183184 /// Check tat contract has confirmed sponsor.185 ///186 /// @param contractAddress The contract for which the presence of a confirmed sponsor is checked.187 /// @return **true** if contract has confirmed sponsor.188 fn has_sponsor(&self, contract_address: address) -> Result<bool> {189 Ok(Pallet::<T>::get_sponsor(contract_address).is_some())190 }191192 /// Check tat contract has pending sponsor.193 ///194 /// @param contractAddress The contract for which the presence of a pending sponsor is checked.195 /// @return **true** if contract has pending sponsor.196 fn has_pending_sponsor(&self, contract_address: address) -> Result<bool> {197 Ok(match Sponsoring::<T>::get(contract_address) {198 SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => false,199 SponsorshipState::Unconfirmed(_) => true,200 })201 }202203 fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {204 Ok(<Pallet<T>>::sponsoring_mode(contract_address) != SponsoringModeT::Disabled)205 }206207 fn set_sponsoring_mode(208 &mut self,209 caller: caller,210 contract_address: address,211 // TODO: implement support for enums in evm-coder212 mode: uint8,213 ) -> Result<void> {214 self.recorder().consume_sload()?;215 self.recorder().consume_sstore()?;216217 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;218 let mode = SponsoringModeT::from_eth(mode).ok_or("unknown mode")?;219 <Pallet<T>>::set_sponsoring_mode(contract_address, mode);220221 Ok(())222 }223224 /// Get current contract sponsoring rate limit225 /// @param contractAddress Contract to get sponsoring mode of226 /// @return uint32 Amount of blocks between two sponsored transactions227 fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {228 Ok(<SponsoringRateLimit<T>>::get(contract_address)229 .try_into()230 .map_err(|_| "rate limit > u32::MAX")?)231 }232233 /// Set contract sponsoring rate limit234 /// @dev Sponsoring rate limit - is a minimum amount of blocks that should235 /// pass between two sponsored transactions236 /// @param contractAddress Contract to change sponsoring rate limit of237 /// @param rateLimit Target rate limit238 /// @dev Only contract owner can change this setting239 fn set_sponsoring_rate_limit(240 &mut self,241 caller: caller,242 contract_address: address,243 rate_limit: uint32,244 ) -> Result<void> {245 self.recorder().consume_sload()?;246 self.recorder().consume_sstore()?;247248 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;249 <Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());250 Ok(())251 }252253 /// Is specified user present in contract allow list254 /// @dev Contract owner always implicitly included255 /// @param contractAddress Contract to check allowlist of256 /// @param user User to check257 /// @return bool Is specified users exists in contract allowlist258 fn allowed(&self, contract_address: address, user: address) -> Result<bool> {259 self.0.consume_sload()?;260 Ok(<Pallet<T>>::allowed(contract_address, user))261 }262263 /// Toggle user presence in contract allowlist264 /// @param contractAddress Contract to change allowlist of265 /// @param user Which user presence should be toggled266 /// @param isAllowed `true` if user should be allowed to be sponsored267 /// or call this contract, `false` otherwise268 /// @dev Only contract owner can change this setting269 fn toggle_allowed(270 &mut self,271 caller: caller,272 contract_address: address,273 user: address,274 is_allowed: bool,275 ) -> Result<void> {276 self.recorder().consume_sload()?;277 self.recorder().consume_sstore()?;278279 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;280 <Pallet<T>>::toggle_allowed(contract_address, user, is_allowed);281282 Ok(())283 }284285 /// Is this contract has allowlist access enabled286 /// @dev Allowlist always can have users, and it is used for two purposes:287 /// in case of allowlist sponsoring mode, users will be sponsored if they exist in allowlist288 /// in case of allowlist access enabled, only users from allowlist may call this contract289 /// @param contractAddress Contract to get allowlist access of290 /// @return bool Is specified contract has allowlist access enabled291 fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {292 Ok(<AllowlistEnabled<T>>::get(contract_address))293 }294295 /// Toggle contract allowlist access296 /// @param contractAddress Contract to change allowlist access of297 /// @param enabled Should allowlist access to be enabled?298 fn toggle_allowlist(299 &mut self,300 caller: caller,301 contract_address: address,302 enabled: bool,303 ) -> Result<void> {304 self.recorder().consume_sload()?;305 self.recorder().consume_sstore()?;306307 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;308 <Pallet<T>>::toggle_allowlist(contract_address, enabled);309 Ok(())310 }311}312313/// Implements [`OnMethodCall`], which delegates call to [`ContractHelpers`]314pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);315impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T>316where317 T::AccountId: AsRef<[u8; 32]>,318{319 fn is_reserved(contract: &sp_core::H160) -> bool {320 contract == &T::ContractAddress::get()321 }322323 fn is_used(contract: &sp_core::H160) -> bool {324 contract == &T::ContractAddress::get()325 }326327 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {328 // TODO: Extract to another OnMethodCall handler329 if <AllowlistEnabled<T>>::get(handle.code_address())330 && !<Pallet<T>>::allowed(handle.code_address(), handle.context().caller)331 {332 return Some(Err(PrecompileFailure::Revert {333 exit_status: ExitRevert::Reverted,334 output: {335 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));336 writer.string("Target contract is allowlisted");337 writer.finish()338 },339 }));340 }341342 if handle.code_address() != T::ContractAddress::get() {343 return None;344 }345346 let helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));347 pallet_evm_coder_substrate::call(handle, helpers)348 }349350 fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {351 (contract == &T::ContractAddress::get())352 .then(|| include_bytes!("./stubs/ContractHelpers.raw").to_vec())353 }354}355356/// Hooks into contract creation, storing owner of newly deployed contract357pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);358impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {359 fn on_create(owner: H160, contract: H160) {360 <Owner<T>>::insert(contract, owner);361 }362}363364/// Bridge to pallet-sponsoring365pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);366impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)>367 for HelpersContractSponsoring<T>368{369 fn get_sponsor(who: &T::CrossAccountId, call: &(H160, Vec<u8>)) -> Option<T::CrossAccountId> {370 let (contract_address, _) = call;371 let mode = <Pallet<T>>::sponsoring_mode(*contract_address);372 if mode == SponsoringModeT::Disabled {373 return None;374 }375376 let sponsor = match <Pallet<T>>::get_sponsor(*contract_address) {377 Some(sponsor) => sponsor,378 None => return None,379 };380381 if mode == SponsoringModeT::Allowlisted382 && !<Pallet<T>>::allowed(*contract_address, *who.as_eth())383 {384 return None;385 }386 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;387388 if let Some(last_tx_block) = <SponsorBasket<T>>::get(contract_address, who.as_eth()) {389 let limit = <SponsoringRateLimit<T>>::get(contract_address);390391 let timeout = last_tx_block + limit;392 if block_number < timeout {393 return None;394 }395 }396397 <SponsorBasket<T>>::insert(contract_address, who.as_eth(), block_number);398399 Some(sponsor)400 }401}402403generate_stubgen!(contract_helpers_impl, ContractHelpersCall<()>, true);404generate_stubgen!(contract_helpers_iface, ContractHelpersCall<()>, false);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: address,46 /// New sponsor address.47 sponsor: address,48 },4950 /// New sponsor was confirm.51 ContractSponsorshipConfirmed {52 /// Contract address of the affected collection.53 #[indexed]54 contract_address: address,55 /// New sponsor address.56 sponsor: address,57 },5859 /// Collection sponsor was removed.60 ContractSponsorRemoved {61 /// Contract address of the affected collection.62 #[indexed]63 contract_address: address,64 },65}6667/// See [`ContractHelpersCall`]68pub struct ContractHelpers<T: Config>(SubstrateRecorder<T>);69impl<T: Config> WithRecorder<T> for ContractHelpers<T> {70 fn recorder(&self) -> &SubstrateRecorder<T> {71 &self.072 }7374 fn into_recorder(self) -> SubstrateRecorder<T> {75 self.076 }77}7879/// @title Magic contract, which allows users to reconfigure other contracts80#[solidity_interface(name = ContractHelpers, events(ContractHelpersEvents))]81impl<T: Config> ContractHelpers<T>82where83 T::AccountId: AsRef<[u8; 32]>,84{85 /// Get user, which deployed specified contract86 /// @dev May return zero address in case if contract is deployed87 /// using uniquenetwork evm-migration pallet, or using other terms not88 /// intended by pallet-evm89 /// @dev Returns zero address if contract does not exists90 /// @param contractAddress Contract to get owner of91 /// @return address Owner of contract92 fn contract_owner(&self, contract_address: address) -> Result<address> {93 Ok(<Owner<T>>::get(contract_address))94 }9596 /// Set sponsor.97 /// @param contractAddress Contract for which a sponsor is being established.98 /// @param sponsor User address who set as pending sponsor.99 fn set_sponsor(100 &mut self,101 caller: caller,102 contract_address: address,103 sponsor: address,104 ) -> Result<void> {105 self.recorder().consume_sload()?;106 self.recorder().consume_sstore()?;107108 Pallet::<T>::set_sponsor(109 &T::CrossAccountId::from_eth(caller),110 contract_address,111 &T::CrossAccountId::from_eth(sponsor),112 )113 .map_err(dispatch_to_evm::<T>)?;114115 Ok(())116 }117118 /// Set contract as self sponsored.119 ///120 /// @param contractAddress Contract for which a self sponsoring is being enabled.121 fn self_sponsored_enable(&mut self, caller: caller, contract_address: address) -> Result<void> {122 self.recorder().consume_sload()?;123 self.recorder().consume_sstore()?;124125 let caller = T::CrossAccountId::from_eth(caller);126127 Pallet::<T>::ensure_owner(contract_address, *caller.as_eth())128 .map_err(dispatch_to_evm::<T>)?;129130 Pallet::<T>::force_set_sponsor(131 contract_address,132 &T::CrossAccountId::from_eth(contract_address),133 )134 .map_err(dispatch_to_evm::<T>)?;135136 Ok(())137 }138139 /// Remove sponsor.140 ///141 /// @param contractAddress Contract for which a sponsorship is being removed.142 fn remove_sponsor(&mut self, caller: caller, contract_address: address) -> Result<void> {143 self.recorder().consume_sload()?;144 self.recorder().consume_sstore()?;145146 Pallet::<T>::remove_sponsor(&T::CrossAccountId::from_eth(caller), contract_address)147 .map_err(dispatch_to_evm::<T>)?;148149 Ok(())150 }151152 /// Confirm sponsorship.153 ///154 /// @dev Caller must be same that set via [`setSponsor`].155 ///156 /// @param contractAddress Сontract for which need to confirm sponsorship.157 fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {158 self.recorder().consume_sload()?;159 self.recorder().consume_sstore()?;160161 Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)162 .map_err(dispatch_to_evm::<T>)?;163164 Ok(())165 }166167 /// Get current sponsor.168 ///169 /// @param contractAddress The contract for which a sponsor is requested.170 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.171 fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {172 let sponsor =173 Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;174 Ok(pallet_common::eth::convert_cross_account_to_tuple::<T>(&sponsor))175 }176177 /// Check tat contract has confirmed sponsor.178 ///179 /// @param contractAddress The contract for which the presence of a confirmed sponsor is checked.180 /// @return **true** if contract has confirmed sponsor.181 fn has_sponsor(&self, contract_address: address) -> Result<bool> {182 Ok(Pallet::<T>::get_sponsor(contract_address).is_some())183 }184185 /// Check tat contract has pending sponsor.186 ///187 /// @param contractAddress The contract for which the presence of a pending sponsor is checked.188 /// @return **true** if contract has pending sponsor.189 fn has_pending_sponsor(&self, contract_address: address) -> Result<bool> {190 Ok(match Sponsoring::<T>::get(contract_address) {191 SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => false,192 SponsorshipState::Unconfirmed(_) => true,193 })194 }195196 fn sponsoring_enabled(&self, contract_address: address) -> Result<bool> {197 Ok(<Pallet<T>>::sponsoring_mode(contract_address) != SponsoringModeT::Disabled)198 }199200 fn set_sponsoring_mode(201 &mut self,202 caller: caller,203 contract_address: address,204 // TODO: implement support for enums in evm-coder205 mode: uint8,206 ) -> Result<void> {207 self.recorder().consume_sload()?;208 self.recorder().consume_sstore()?;209210 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;211 let mode = SponsoringModeT::from_eth(mode).ok_or("unknown mode")?;212 <Pallet<T>>::set_sponsoring_mode(contract_address, mode);213214 Ok(())215 }216217 /// Get current contract sponsoring rate limit218 /// @param contractAddress Contract to get sponsoring mode of219 /// @return uint32 Amount of blocks between two sponsored transactions220 fn get_sponsoring_rate_limit(&self, contract_address: address) -> Result<uint32> {221 Ok(<SponsoringRateLimit<T>>::get(contract_address)222 .try_into()223 .map_err(|_| "rate limit > u32::MAX")?)224 }225226 /// Set contract sponsoring rate limit227 /// @dev Sponsoring rate limit - is a minimum amount of blocks that should228 /// pass between two sponsored transactions229 /// @param contractAddress Contract to change sponsoring rate limit of230 /// @param rateLimit Target rate limit231 /// @dev Only contract owner can change this setting232 fn set_sponsoring_rate_limit(233 &mut self,234 caller: caller,235 contract_address: address,236 rate_limit: uint32,237 ) -> Result<void> {238 self.recorder().consume_sload()?;239 self.recorder().consume_sstore()?;240241 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;242 <Pallet<T>>::set_sponsoring_rate_limit(contract_address, rate_limit.into());243 Ok(())244 }245246 /// Is specified user present in contract allow list247 /// @dev Contract owner always implicitly included248 /// @param contractAddress Contract to check allowlist of249 /// @param user User to check250 /// @return bool Is specified users exists in contract allowlist251 fn allowed(&self, contract_address: address, user: address) -> Result<bool> {252 self.0.consume_sload()?;253 Ok(<Pallet<T>>::allowed(contract_address, user))254 }255256 /// Toggle user presence in contract allowlist257 /// @param contractAddress Contract to change allowlist of258 /// @param user Which user presence should be toggled259 /// @param isAllowed `true` if user should be allowed to be sponsored260 /// or call this contract, `false` otherwise261 /// @dev Only contract owner can change this setting262 fn toggle_allowed(263 &mut self,264 caller: caller,265 contract_address: address,266 user: address,267 is_allowed: bool,268 ) -> Result<void> {269 self.recorder().consume_sload()?;270 self.recorder().consume_sstore()?;271272 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;273 <Pallet<T>>::toggle_allowed(contract_address, user, is_allowed);274275 Ok(())276 }277278 /// Is this contract has allowlist access enabled279 /// @dev Allowlist always can have users, and it is used for two purposes:280 /// in case of allowlist sponsoring mode, users will be sponsored if they exist in allowlist281 /// in case of allowlist access enabled, only users from allowlist may call this contract282 /// @param contractAddress Contract to get allowlist access of283 /// @return bool Is specified contract has allowlist access enabled284 fn allowlist_enabled(&self, contract_address: address) -> Result<bool> {285 Ok(<AllowlistEnabled<T>>::get(contract_address))286 }287288 /// Toggle contract allowlist access289 /// @param contractAddress Contract to change allowlist access of290 /// @param enabled Should allowlist access to be enabled?291 fn toggle_allowlist(292 &mut self,293 caller: caller,294 contract_address: address,295 enabled: bool,296 ) -> Result<void> {297 self.recorder().consume_sload()?;298 self.recorder().consume_sstore()?;299300 <Pallet<T>>::ensure_owner(contract_address, caller).map_err(dispatch_to_evm::<T>)?;301 <Pallet<T>>::toggle_allowlist(contract_address, enabled);302 Ok(())303 }304}305306/// Implements [`OnMethodCall`], which delegates call to [`ContractHelpers`]307pub struct HelpersOnMethodCall<T: Config>(PhantomData<*const T>);308impl<T: Config> OnMethodCall<T> for HelpersOnMethodCall<T>309where310 T::AccountId: AsRef<[u8; 32]>,311{312 fn is_reserved(contract: &sp_core::H160) -> bool {313 contract == &T::ContractAddress::get()314 }315316 fn is_used(contract: &sp_core::H160) -> bool {317 contract == &T::ContractAddress::get()318 }319320 fn call(handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {321 // TODO: Extract to another OnMethodCall handler322 if <AllowlistEnabled<T>>::get(handle.code_address())323 && !<Pallet<T>>::allowed(handle.code_address(), handle.context().caller)324 {325 return Some(Err(PrecompileFailure::Revert {326 exit_status: ExitRevert::Reverted,327 output: {328 let mut writer = AbiWriter::new_call(evm_coder::fn_selector!(Error(string)));329 writer.string("Target contract is allowlisted");330 writer.finish()331 },332 }));333 }334335 if handle.code_address() != T::ContractAddress::get() {336 return None;337 }338339 let helpers = ContractHelpers::<T>(SubstrateRecorder::<T>::new(handle.remaining_gas()));340 pallet_evm_coder_substrate::call(handle, helpers)341 }342343 fn get_code(contract: &sp_core::H160) -> Option<Vec<u8>> {344 (contract == &T::ContractAddress::get())345 .then(|| include_bytes!("./stubs/ContractHelpers.raw").to_vec())346 }347}348349/// Hooks into contract creation, storing owner of newly deployed contract350pub struct HelpersOnCreate<T: Config>(PhantomData<*const T>);351impl<T: Config> OnCreate<T> for HelpersOnCreate<T> {352 fn on_create(owner: H160, contract: H160) {353 <Owner<T>>::insert(contract, owner);354 }355}356357/// Bridge to pallet-sponsoring358pub struct HelpersContractSponsoring<T: Config>(PhantomData<*const T>);359impl<T: Config> SponsorshipHandler<T::CrossAccountId, (H160, Vec<u8>)>360 for HelpersContractSponsoring<T>361{362 fn get_sponsor(who: &T::CrossAccountId, call: &(H160, Vec<u8>)) -> Option<T::CrossAccountId> {363 let (contract_address, _) = call;364 let mode = <Pallet<T>>::sponsoring_mode(*contract_address);365 if mode == SponsoringModeT::Disabled {366 return None;367 }368369 let sponsor = match <Pallet<T>>::get_sponsor(*contract_address) {370 Some(sponsor) => sponsor,371 None => return None,372 };373374 if mode == SponsoringModeT::Allowlisted375 && !<Pallet<T>>::allowed(*contract_address, *who.as_eth())376 {377 return None;378 }379 let block_number = <frame_system::Pallet<T>>::block_number() as T::BlockNumber;380381 if let Some(last_tx_block) = <SponsorBasket<T>>::get(contract_address, who.as_eth()) {382 let limit = <SponsoringRateLimit<T>>::get(contract_address);383384 let timeout = last_tx_block + limit;385 if block_number < timeout {386 return None;387 }388 }389390 <SponsorBasket<T>>::insert(contract_address, who.as_eth(), block_number);391392 Some(sponsor)393 }394}395396generate_stubgen!(contract_helpers_impl, ContractHelpersCall<()>, true);397generate_stubgen!(contract_helpers_iface, ContractHelpersCall<()>, false);pallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/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
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/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
pallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/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
tests/src/eth/allowlist.test.tsdiffbeforeafterboth--- a/tests/src/eth/allowlist.test.ts
+++ b/tests/src/eth/allowlist.test.ts
@@ -15,9 +15,19 @@
// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
import {expect} from 'chai';
-import {contractHelpers, createEthAccountWithBalance, deployFlipper, itWeb3} from './util/helpers';
+import {isAllowlisted} from '../util/helpers';
+import {
+ contractHelpers,
+ createEthAccount,
+ createEthAccountWithBalance,
+ deployFlipper,
+ evmCollection,
+ evmCollectionHelpers,
+ getCollectionAddressFromResult,
+ itWeb3,
+} from './util/helpers';
-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 +68,79 @@
expect(await flipper.methods.getValue().call()).to.be.false;
});
});
+
+describe('EVM collection allowlist', () => {
+ itWeb3('Collection allowlist can be added and removed by [eth] address', async ({api, web3, privateKeyWrapper}) => {
+ const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const user = createEthAccount(web3);
+
+ const collectionHelpers = evmCollectionHelpers(web3, owner);
+ const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();
+ const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
+ const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+
+ 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;
+ });
+
+ itWeb3('Collection allowlist can be added and removed by [sub] address', async ({api, web3, privateKeyWrapper}) => {
+ const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const user = privateKeyWrapper('//Alice');
+
+ const collectionHelpers = evmCollectionHelpers(web3, owner);
+ const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();
+ const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+ const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+
+ expect(await isAllowlisted(api, collectionId, user)).to.be.false;
+ await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner});
+ expect(await isAllowlisted(api, collectionId, user)).to.be.true;
+
+ await collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).send({from: owner});
+ expect(await isAllowlisted(api, collectionId, user)).to.be.false;
+ });
+
+ itWeb3('Collection allowlist can not be add and remove [eth] address by not owner', async ({api, web3, privateKeyWrapper}) => {
+ const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const user = createEthAccount(web3);
+
+ const collectionHelpers = evmCollectionHelpers(web3, owner);
+ const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();
+ const {collectionIdAddress} = await getCollectionAddressFromResult(api, result);
+ const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+
+ 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;
+ });
+
+ itWeb3('Collection allowlist can not be add and remove [sub] address by not owner', async ({api, web3, privateKeyWrapper}) => {
+ const owner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const notOwner = await createEthAccountWithBalance(api, web3, privateKeyWrapper);
+ const user = privateKeyWrapper('//Alice');
+
+ const collectionHelpers = evmCollectionHelpers(web3, owner);
+ const result = await collectionHelpers.methods.createNonfungibleCollection('Sponsor collection', '1', '1').send();
+ const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
+ const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
+
+ expect(await isAllowlisted(api, collectionId, user)).to.be.false;
+ await expect(collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission');
+ expect(await isAllowlisted(api, collectionId, user)).to.be.false;
+ await collectionEvm.methods.addToCollectionAllowListSubstrate(user.addressRaw).send({from: owner});
+
+ expect(await isAllowlisted(api, collectionId, user)).to.be.true;
+ await expect(collectionEvm.methods.removeFromCollectionAllowListSubstrate(user.addressRaw).call({from: notOwner})).to.be.rejectedWith('NoPermission');
+ expect(await isAllowlisted(api, collectionId, user)).to.be.true;
+ });
+});
tests/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
tests/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
tests/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
tests/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": [],
tests/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" }
tests/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" }
tests/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();
}