difftreelog
CORE-386 Implement eth methods
in: master
5 files changed
pallets/common/src/erc.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/>.1617use evm_coder::{18 solidity_interface, solidity, ToLog,19 types::*,20 execution::{Result, Error},21};22pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};23use pallet_evm_coder_substrate::dispatch_to_evm;24use sp_core::{H160, U256, H256};25use sp_std::vec::Vec;26use up_data_structs::{Property, SponsoringRateLimit, NestingRule, OwnerRestrictedSet, AccessMode};27use alloc::format;2829use crate::{Pallet, CollectionHandle, Config, CollectionProperties};3031#[derive(ToLog)]32pub enum CollectionHelpersEvents {33 CollectionCreated {34 #[indexed]35 owner: address,36 #[indexed]37 collection_id: address,38 },39}4041/// Does not always represent a full collection, for RFT it is either42/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)43pub trait CommonEvmHandler {44 const CODE: &'static [u8];4546 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult>;47}4849#[solidity_interface(name = "Collection")]5051impl<T: Config> CollectionHandle<T> 52// where 53// T::AccountId: From<H256>54{55 fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {56 let caller = T::CrossAccountId::from_eth(caller);57 let key = <Vec<u8>>::from(key)58 .try_into()59 .map_err(|_| "key too large")?;60 let value = value.try_into().map_err(|_| "value too large")?;6162 <Pallet<T>>::set_collection_property(self, &caller, Property { key, value })63 .map_err(dispatch_to_evm::<T>)64 }6566 fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {67 let caller = T::CrossAccountId::from_eth(caller);68 let key = <Vec<u8>>::from(key)69 .try_into()70 .map_err(|_| "key too large")?;7172 <Pallet<T>>::delete_collection_property(self, &caller, key).map_err(dispatch_to_evm::<T>)73 }7475 /// Throws error if key not found76 fn collection_property(&self, key: string) -> Result<bytes> {77 let key = <Vec<u8>>::from(key)78 .try_into()79 .map_err(|_| "key too large")?;8081 let props = <CollectionProperties<T>>::get(self.id);82 let prop = props.get(&key).ok_or("key not found")?;8384 Ok(prop.to_vec())85 }8687 fn set_collection_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {88 check_is_owner(caller, self)?;8990 let sponsor = T::CrossAccountId::from_eth(sponsor);91 self.set_sponsor(sponsor.as_sub().clone())92 .map_err(dispatch_to_evm::<T>)?;93 save(self)94 }9596 fn confirm_collection_sponsorship(&mut self, caller: caller) -> Result<void> {97 let caller = T::CrossAccountId::from_eth(caller);98 if !self99 .confirm_sponsorship(caller.as_sub())100 .map_err(dispatch_to_evm::<T>)?101 {102 return Err(Error::Revert("Caller is not set as sponsor".into()));103 }104 save(self)105 }106107 #[solidity(rename_selector = "setCollectionLimit")]108 fn set_int_limit(&mut self, caller: caller, limit: string, value: uint32) -> Result<void> {109 check_is_owner(caller, self)?;110 let mut limits = self.limits.clone();111112 match limit.as_str() {113 "accountTokenOwnershipLimit" => {114 limits.account_token_ownership_limit = Some(value);115 }116 "sponsoredDataSize" => {117 limits.sponsored_data_size = Some(value);118 }119 "sponsoredDataRateLimit" => {120 limits.sponsored_data_rate_limit = Some(SponsoringRateLimit::Blocks(value));121 }122 "tokenLimit" => {123 limits.token_limit = Some(value);124 }125 "sponsorTransferTimeout" => {126 limits.sponsor_transfer_timeout = Some(value);127 }128 "sponsorApproveTimeout" => {129 limits.sponsor_approve_timeout = Some(value);130 }131 _ => {132 return Err(Error::Revert(format!(133 "Unknown integer limit \"{}\"",134 limit135 )))136 }137 }138 self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)139 .map_err(dispatch_to_evm::<T>)?;140 save(self)141 }142143 #[solidity(rename_selector = "setCollectionLimit")]144 fn set_bool_limit(&mut self, caller: caller, limit: string, value: bool) -> Result<void> {145 check_is_owner(caller, self)?;146 let mut limits = self.limits.clone();147148 match limit.as_str() {149 "ownerCanTransfer" => {150 limits.owner_can_transfer = Some(value);151 }152 "ownerCanDestroy" => {153 limits.owner_can_destroy = Some(value);154 }155 "transfersEnabled" => {156 limits.transfers_enabled = Some(value);157 }158 _ => {159 return Err(Error::Revert(format!(160 "Unknown boolean limit \"{}\"",161 limit162 )))163 }164 }165 self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)166 .map_err(dispatch_to_evm::<T>)?;167 save(self)168 }169170 fn contract_address(&self, _caller: caller) -> Result<address> {171 Ok(crate::eth::collection_id_to_address(self.id))172 }173174 // fn add_admin_substrate(&self, caller: caller, new_admin: uint256) -> Result<void> {175 // let mut new_admin_h256 = H256::default();176 // new_admin.to_little_endian(&mut new_admin_h256.0);177 // let account_id = T::AccountId::from(new_admin_h256);178 // let caller = T::CrossAccountId::from_eth(caller);179 // let new_admin = T::CrossAccountId::from_sub(account_id);180 // <Pallet<T>>::toggle_admin(&self, &caller, &new_admin, true)181 // .map_err(dispatch_to_evm::<T>)?;182 // Ok(())183 // }184185 // fn remove_admin_substrate(&self, caller: caller, new_admin: uint256) -> Result<void> {186 // let mut new_admin_h256 = H256::default();187 // new_admin.to_little_endian(&mut new_admin_h256.0);188 // let account_id = T::AccountId::from(new_admin_h256);189 // let caller = T::CrossAccountId::from_eth(caller);190 // let new_admin = T::CrossAccountId::from_sub(account_id);191 // <Pallet<T>>::toggle_admin(&self, &caller, &new_admin, false)192 // .map_err(dispatch_to_evm::<T>)?;193 // Ok(())194 // }195196 fn add_admin(&self, caller: caller, new_admin: address) -> Result<void> {197 let caller = T::CrossAccountId::from_eth(caller);198 self.check_is_owner_or_admin(&caller)199 .map_err(dispatch_to_evm::<T>)?;200 let new_admin = T::CrossAccountId::from_eth(new_admin);201 <Pallet<T>>::toggle_admin(&self, &caller, &new_admin, true)202 .map_err(dispatch_to_evm::<T>)?;203 Ok(())204 }205206 fn remove_admin(&self, caller: caller, admin: address) -> Result<void> {207 let caller = T::CrossAccountId::from_eth(caller);208 self.check_is_owner_or_admin(&caller)209 .map_err(dispatch_to_evm::<T>)?;210 let admin = T::CrossAccountId::from_eth(admin);211 <Pallet<T>>::toggle_admin(&self, &caller, &admin, false)212 .map_err(dispatch_to_evm::<T>)?;213 Ok(())214 }215216 #[solidity(rename_selector = "setNesting")]217 fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {218 let caller = T::CrossAccountId::from_eth(caller);219 self.check_is_owner_or_admin(&caller)220 .map_err(dispatch_to_evm::<T>)?;221 self.collection.permissions.nesting = Some(match enable {222 false => NestingRule::Disabled,223 true => NestingRule::Owner,224 });225 save(self);226 Ok(())227 }228229 #[solidity(rename_selector = "setNesting")]230 fn set_nesting(&mut self, caller: caller, enable: bool, collections: Vec<address>) -> Result<void> {231 if collections.is_empty() {232 return Err("No addresses provided".into());233 }234 if collections.len() >= OwnerRestrictedSet::bound() {235 return Err(Error::Revert(format!("Out of bound: {} >= {}", collections.len(), OwnerRestrictedSet::bound())));236 }237 let caller = T::CrossAccountId::from_eth(caller);238 self.check_is_owner_or_admin(&caller)239 .map_err(dispatch_to_evm::<T>)?;240 self.collection.permissions.nesting = Some(match enable {241 false => NestingRule::Disabled,242 true => {243 let mut bv = OwnerRestrictedSet::new();244 for i in collections {245 bv.try_insert(246 crate::eth::map_eth_to_id(&i)247 .ok_or(Error::Revert("Can't convert address into collection id".into()))?248 ).map_err(|e| Error::Revert(format!("{:?}", e)))?;249 }250 NestingRule::OwnerRestricted (bv)251 }252 });253 save(self);254 Ok(())255 }256}257258fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<void> {259 let caller = T::CrossAccountId::from_eth(caller);260 collection261 .check_is_owner(&caller)262 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;263 Ok(())264}265266fn check_is_owner_or_admin<T: Config>(267 caller: caller,268 collection: &CollectionHandle<T>,269) -> Result<T::CrossAccountId> {270 let caller = T::CrossAccountId::from_eth(caller);271 collection272 .check_is_owner_or_admin(&caller)273 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;274 Ok(caller)275}276277fn save<T: Config>(collection: &CollectionHandle<T>) -> Result<void> {278 // TODO possibly delete for the lack of transaction279 collection280 .check_is_internal()281 .map_err(dispatch_to_evm::<T>)?;282 <crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());283 Ok(())284}285286pub fn token_uri_key() -> up_data_structs::PropertyKey {287 b"tokenURI"288 .to_vec()289 .try_into()290 .expect("length < limit; qed")291}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/>.1617use evm_coder::{18 solidity_interface, solidity, ToLog,19 types::*,20 execution::{Result, Error},21};22pub use pallet_evm::{PrecompileOutput, PrecompileResult, PrecompileHandle, account::CrossAccountId};23use pallet_evm_coder_substrate::dispatch_to_evm;24use sp_core::{H160, U256, H256};25use sp_std::vec::Vec;26use up_data_structs::{Property, SponsoringRateLimit, NestingRule, OwnerRestrictedSet, AccessMode};27use alloc::format;2829use crate::{Pallet, CollectionHandle, Config, CollectionProperties};3031#[derive(ToLog)]32pub enum CollectionHelpersEvents {33 CollectionCreated {34 #[indexed]35 owner: address,36 #[indexed]37 collection_id: address,38 },39}4041/// Does not always represent a full collection, for RFT it is either42/// collection (Implementing ERC721), or specific collection token (Implementing ERC20)43pub trait CommonEvmHandler {44 const CODE: &'static [u8];4546 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult>;47}4849#[solidity_interface(name = "Collection")]5051impl<T: Config> CollectionHandle<T> 52// where 53// T::AccountId: From<H256>54{55 fn set_collection_property(&mut self, caller: caller, key: string, value: bytes) -> Result<()> {56 let caller = T::CrossAccountId::from_eth(caller);57 let key = <Vec<u8>>::from(key)58 .try_into()59 .map_err(|_| "key too large")?;60 let value = value.try_into().map_err(|_| "value too large")?;6162 <Pallet<T>>::set_collection_property(self, &caller, Property { key, value })63 .map_err(dispatch_to_evm::<T>)64 }6566 fn delete_collection_property(&mut self, caller: caller, key: string) -> Result<()> {67 let caller = T::CrossAccountId::from_eth(caller);68 let key = <Vec<u8>>::from(key)69 .try_into()70 .map_err(|_| "key too large")?;7172 <Pallet<T>>::delete_collection_property(self, &caller, key).map_err(dispatch_to_evm::<T>)73 }7475 /// Throws error if key not found76 fn collection_property(&self, key: string) -> Result<bytes> {77 let key = <Vec<u8>>::from(key)78 .try_into()79 .map_err(|_| "key too large")?;8081 let props = <CollectionProperties<T>>::get(self.id);82 let prop = props.get(&key).ok_or("key not found")?;8384 Ok(prop.to_vec())85 }8687 fn set_collection_sponsor(&mut self, caller: caller, sponsor: address) -> Result<void> {88 check_is_owner(caller, self)?;8990 let sponsor = T::CrossAccountId::from_eth(sponsor);91 self.set_sponsor(sponsor.as_sub().clone())92 .map_err(dispatch_to_evm::<T>)?;93 save(self)94 }9596 fn confirm_collection_sponsorship(&mut self, caller: caller) -> Result<void> {97 let caller = T::CrossAccountId::from_eth(caller);98 if !self99 .confirm_sponsorship(caller.as_sub())100 .map_err(dispatch_to_evm::<T>)?101 {102 return Err(Error::Revert("Caller is not set as sponsor".into()));103 }104 save(self)105 }106107 #[solidity(rename_selector = "setCollectionLimit")]108 fn set_int_limit(&mut self, caller: caller, limit: string, value: uint32) -> Result<void> {109 check_is_owner(caller, self)?;110 let mut limits = self.limits.clone();111112 match limit.as_str() {113 "accountTokenOwnershipLimit" => {114 limits.account_token_ownership_limit = Some(value);115 }116 "sponsoredDataSize" => {117 limits.sponsored_data_size = Some(value);118 }119 "sponsoredDataRateLimit" => {120 limits.sponsored_data_rate_limit = Some(SponsoringRateLimit::Blocks(value));121 }122 "tokenLimit" => {123 limits.token_limit = Some(value);124 }125 "sponsorTransferTimeout" => {126 limits.sponsor_transfer_timeout = Some(value);127 }128 "sponsorApproveTimeout" => {129 limits.sponsor_approve_timeout = Some(value);130 }131 _ => {132 return Err(Error::Revert(format!(133 "Unknown integer limit \"{}\"",134 limit135 )))136 }137 }138 self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)139 .map_err(dispatch_to_evm::<T>)?;140 save(self)141 }142143 #[solidity(rename_selector = "setCollectionLimit")]144 fn set_bool_limit(&mut self, caller: caller, limit: string, value: bool) -> Result<void> {145 check_is_owner(caller, self)?;146 let mut limits = self.limits.clone();147148 match limit.as_str() {149 "ownerCanTransfer" => {150 limits.owner_can_transfer = Some(value);151 }152 "ownerCanDestroy" => {153 limits.owner_can_destroy = Some(value);154 }155 "transfersEnabled" => {156 limits.transfers_enabled = Some(value);157 }158 _ => {159 return Err(Error::Revert(format!(160 "Unknown boolean limit \"{}\"",161 limit162 )))163 }164 }165 self.limits = <Pallet<T>>::clamp_limits(self.mode.clone(), &self.limits, limits)166 .map_err(dispatch_to_evm::<T>)?;167 save(self)168 }169170 fn contract_address(&self, _caller: caller) -> Result<address> {171 Ok(crate::eth::collection_id_to_address(self.id))172 }173174 // fn add_admin_substrate(&self, caller: caller, new_admin: uint256) -> Result<void> {175 // let mut new_admin_h256 = H256::default();176 // new_admin.to_little_endian(&mut new_admin_h256.0);177 // let account_id = T::AccountId::from(new_admin_h256);178 // let caller = T::CrossAccountId::from_eth(caller);179 // let new_admin = T::CrossAccountId::from_sub(account_id);180 // <Pallet<T>>::toggle_admin(&self, &caller, &new_admin, true)181 // .map_err(dispatch_to_evm::<T>)?;182 // Ok(())183 // }184185 // fn remove_admin_substrate(&self, caller: caller, new_admin: uint256) -> Result<void> {186 // let mut new_admin_h256 = H256::default();187 // new_admin.to_little_endian(&mut new_admin_h256.0);188 // let account_id = T::AccountId::from(new_admin_h256);189 // let caller = T::CrossAccountId::from_eth(caller);190 // let new_admin = T::CrossAccountId::from_sub(account_id);191 // <Pallet<T>>::toggle_admin(&self, &caller, &new_admin, false)192 // .map_err(dispatch_to_evm::<T>)?;193 // Ok(())194 // }195196 fn add_admin(&self, caller: caller, new_admin: address) -> Result<void> {197 let caller = T::CrossAccountId::from_eth(caller);198 self.check_is_owner_or_admin(&caller)199 .map_err(dispatch_to_evm::<T>)?;200 let new_admin = T::CrossAccountId::from_eth(new_admin);201 <Pallet<T>>::toggle_admin(&self, &caller, &new_admin, true)202 .map_err(dispatch_to_evm::<T>)?;203 Ok(())204 }205206 fn remove_admin(&self, caller: caller, admin: address) -> Result<void> {207 let caller = T::CrossAccountId::from_eth(caller);208 self.check_is_owner_or_admin(&caller)209 .map_err(dispatch_to_evm::<T>)?;210 let admin = T::CrossAccountId::from_eth(admin);211 <Pallet<T>>::toggle_admin(&self, &caller, &admin, false)212 .map_err(dispatch_to_evm::<T>)?;213 Ok(())214 }215216 #[solidity(rename_selector = "setNesting")]217 fn set_nesting_bool(&mut self, caller: caller, enable: bool) -> Result<void> {218 let caller = T::CrossAccountId::from_eth(caller);219 self.check_is_owner_or_admin(&caller)220 .map_err(dispatch_to_evm::<T>)?;221 self.collection.permissions.nesting = Some(match enable {222 false => NestingRule::Disabled,223 true => NestingRule::Owner,224 });225 save(self);226 Ok(())227 }228229 #[solidity(rename_selector = "setNesting")]230 fn set_nesting(&mut self, caller: caller, enable: bool, collections: Vec<address>) -> Result<void> {231 if collections.is_empty() {232 return Err("No addresses provided".into());233 }234 if collections.len() >= OwnerRestrictedSet::bound() {235 return Err(Error::Revert(format!("Out of bound: {} >= {}", collections.len(), OwnerRestrictedSet::bound())));236 }237 let caller = T::CrossAccountId::from_eth(caller);238 self.check_is_owner_or_admin(&caller)239 .map_err(dispatch_to_evm::<T>)?;240 self.collection.permissions.nesting = Some(match enable {241 false => NestingRule::Disabled,242 true => {243 let mut bv = OwnerRestrictedSet::new();244 for i in collections {245 bv.try_insert(246 crate::eth::map_eth_to_id(&i)247 .ok_or(Error::Revert("Can't convert address into collection id".into()))?248 ).map_err(|e| Error::Revert(format!("{:?}", e)))?;249 }250 NestingRule::OwnerRestricted (bv)251 }252 });253 save(self);254 Ok(())255 }256257 fn set_access(&mut self, caller: caller, mode: string) -> Result<void> {258 let caller = T::CrossAccountId::from_eth(caller);259 self.check_is_owner_or_admin(&caller)260 .map_err(dispatch_to_evm::<T>)?;261 self.collection.permissions.access = Some(match mode.as_str() {262 "Normal" => AccessMode::Normal,263 "AllowList" => AccessMode::AllowList,264 _ => return Err("Not supported access mode".into()),265 });266 save(self);267 Ok(())268 }269270 fn add_to_allow_list(&self, caller: caller, user: address) -> Result<void> {271 let caller = check_is_owner_or_admin(caller, self)?;272 let user = T::CrossAccountId::from_eth(user);273 <Pallet<T>>::toggle_allowlist(self, &caller, &user, true)274 .map_err(dispatch_to_evm::<T>)?;275 Ok(())276 }277278 fn remove_from_allow_list(&self, caller: caller, user: address) -> Result<void> {279 let caller = check_is_owner_or_admin(caller, self)?;280 let user = T::CrossAccountId::from_eth(user);281 <Pallet<T>>::toggle_allowlist(self, &caller, &user, false)282 .map_err(dispatch_to_evm::<T>)?;283 Ok(())284 }285286 fn set_mint_mode(&mut self, caller: caller, mode: bool) -> Result<void> {287 check_is_owner_or_admin(caller, self)?;288 self.collection.permissions.mint_mode = Some(mode);289 save(self);290 Ok(())291 }292}293294fn check_is_owner<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<void> {295 let caller = T::CrossAccountId::from_eth(caller);296 collection297 .check_is_owner(&caller)298 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;299 Ok(())300}301302fn check_is_owner_or_admin<T: Config>(caller: caller, collection: &CollectionHandle<T>) -> Result<T::CrossAccountId> {303 let caller = T::CrossAccountId::from_eth(caller);304 collection305 .check_is_owner_or_admin(&caller)306 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;307 Ok(caller)308}309310fn save<T: Config>(collection: &CollectionHandle<T>) {311 <crate::CollectionById<T>>::insert(collection.id, collection.collection.clone());312 Ok(())313}314315pub fn token_uri_key() -> up_data_structs::PropertyKey {316 b"tokenURI"317 .to_vec()318 .try_into()319 .expect("length < limit; qed")320}pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -51,105 +51,6 @@
event MintingFinished();
}
-// Selector: 3a54513b
-contract Collection is Dummy, ERC165 {
- // Selector: setCollectionProperty(string,bytes) 2f073f66
- function setCollectionProperty(string memory key, bytes memory value)
- public
- {
- require(false, stub_error);
- key;
- value;
- dummy = 0;
- }
-
- // Selector: deleteCollectionProperty(string) 7b7debce
- function deleteCollectionProperty(string memory key) public {
- require(false, stub_error);
- key;
- dummy = 0;
- }
-
- // Throws error if key not found
- //
- // Selector: collectionProperty(string) cf24fd6d
- function collectionProperty(string memory key)
- public
- view
- returns (bytes memory)
- {
- require(false, stub_error);
- key;
- dummy;
- return hex"";
- }
-
- // Selector: ethSetSponsor(address) 8f9af356
- function ethSetSponsor(address sponsor) public {
- require(false, stub_error);
- sponsor;
- dummy = 0;
- }
-
- // Selector: ethConfirmSponsorship() a8580d1a
- function ethConfirmSponsorship() public {
- require(false, stub_error);
- dummy = 0;
- }
-
- // Selector: setLimit(string,uint32) 68db30ca
- function setLimit(string memory limit, uint32 value) public {
- require(false, stub_error);
- limit;
- value;
- dummy = 0;
- }
-
- // Selector: setLimit(string,bool) ea67e4c2
- function setLimit(string memory limit, bool value) public {
- require(false, stub_error);
- limit;
- value;
- dummy = 0;
- }
-
- // Selector: contractAddress() f6b4dfb4
- function contractAddress() public view returns (address) {
- require(false, stub_error);
- dummy;
- return 0x0000000000000000000000000000000000000000;
- }
-
- // Selector: addAdmin(address) 70480275
- function addAdmin(address newAdmin) public view {
- require(false, stub_error);
- newAdmin;
- dummy;
- }
-
- // Selector: removeAdmin(address) 1785f53c
- function removeAdmin(address admin) public view {
- require(false, stub_error);
- admin;
- dummy;
- }
-
- // Selector: setNesting(bool) e8fc50dd
- function setNesting(bool enable) public {
- require(false, stub_error);
- enable;
- dummy = 0;
- }
-
- // Selector: setNesting(bool,address[]) 7df12a9a
- function setNesting(bool enable, address[] memory collections) public {
- require(false, stub_error);
- enable;
- collections;
- dummy = 0;
- }
-}
-
// Selector: 41369377
contract TokenProperties is Dummy, ERC165 {
// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
@@ -479,6 +380,133 @@
}
}
+// Selector: f56cd7fa
+contract Collection is Dummy, ERC165 {
+ // Selector: setCollectionProperty(string,bytes) 2f073f66
+ function setCollectionProperty(string memory key, bytes memory value)
+ public
+ {
+ require(false, stub_error);
+ key;
+ value;
+ dummy = 0;
+ }
+
+ // Selector: deleteCollectionProperty(string) 7b7debce
+ function deleteCollectionProperty(string memory key) public {
+ require(false, stub_error);
+ key;
+ dummy = 0;
+ }
+
+ // Throws error if key not found
+ //
+ // Selector: collectionProperty(string) cf24fd6d
+ function collectionProperty(string memory key)
+ public
+ view
+ returns (bytes memory)
+ {
+ require(false, stub_error);
+ key;
+ dummy;
+ return hex"";
+ }
+
+ // Selector: ethSetSponsor(address) 8f9af356
+ function ethSetSponsor(address sponsor) public {
+ require(false, stub_error);
+ sponsor;
+ dummy = 0;
+ }
+
+ // Selector: ethConfirmSponsorship() a8580d1a
+ function ethConfirmSponsorship() public {
+ require(false, stub_error);
+ dummy = 0;
+ }
+
+ // Selector: setLimit(string,uint32) 68db30ca
+ function setLimit(string memory limit, uint32 value) public {
+ require(false, stub_error);
+ limit;
+ value;
+ dummy = 0;
+ }
+
+ // Selector: setLimit(string,bool) ea67e4c2
+ function setLimit(string memory limit, bool value) public {
+ require(false, stub_error);
+ limit;
+ value;
+ dummy = 0;
+ }
+
+ // Selector: contractAddress() f6b4dfb4
+ function contractAddress() public view returns (address) {
+ require(false, stub_error);
+ dummy;
+ return 0x0000000000000000000000000000000000000000;
+ }
+
+ // Selector: addAdmin(address) 70480275
+ function addAdmin(address newAdmin) public view {
+ require(false, stub_error);
+ newAdmin;
+ dummy;
+ }
+
+ // Selector: removeAdmin(address) 1785f53c
+ function removeAdmin(address admin) public view {
+ require(false, stub_error);
+ admin;
+ dummy;
+ }
+
+ // Selector: setNesting(bool) e8fc50dd
+ function setNesting(bool enable) public {
+ require(false, stub_error);
+ enable;
+ dummy = 0;
+ }
+
+ // Selector: setNesting(bool,address[]) 7df12a9a
+ function setNesting(bool enable, address[] memory collections) public {
+ require(false, stub_error);
+ enable;
+ collections;
+ dummy = 0;
+ }
+
+ // Selector: setAccess(string) 488f56aa
+ function setAccess(string memory mode) public {
+ require(false, stub_error);
+ mode;
+ dummy = 0;
+ }
+
+ // Selector: addToAllowList(address) 31f59102
+ function addToAllowList(address user) public view {
+ require(false, stub_error);
+ user;
+ dummy;
+ }
+
+ // Selector: removeFromAllowList(address) eba8dabc
+ function removeFromAllowList(address user) public view {
+ require(false, stub_error);
+ user;
+ dummy;
+ }
+
+ // Selector: setMintMode(bool) 5dea9bd5
+ function setMintMode(bool mode) public {
+ require(false, stub_error);
+ mode;
+ dummy = 0;
+ }
+}
+
contract UniqueNFT is
Dummy,
ERC165,
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -42,51 +42,6 @@
event MintingFinished();
}
-// Selector: 3a54513b
-interface Collection is Dummy, ERC165 {
- // Selector: setCollectionProperty(string,bytes) 2f073f66
- function setCollectionProperty(string memory key, bytes memory value)
- external;
-
- // Selector: deleteCollectionProperty(string) 7b7debce
- function deleteCollectionProperty(string memory key) external;
-
- // Throws error if key not found
- //
- // Selector: collectionProperty(string) cf24fd6d
- function collectionProperty(string memory key)
- external
- view
- returns (bytes memory);
-
- // Selector: ethSetSponsor(address) 8f9af356
- function ethSetSponsor(address sponsor) external;
-
- // Selector: ethConfirmSponsorship() a8580d1a
- function ethConfirmSponsorship() external;
-
- // Selector: setLimit(string,uint32) 68db30ca
- function setLimit(string memory limit, uint32 value) external;
-
- // Selector: setLimit(string,bool) ea67e4c2
- function setLimit(string memory limit, bool value) external;
-
- // Selector: contractAddress() f6b4dfb4
- function contractAddress() external view returns (address);
-
- // Selector: addAdmin(address) 70480275
- function addAdmin(address newAdmin) external view;
-
- // Selector: removeAdmin(address) 1785f53c
- function removeAdmin(address admin) external view;
-
- // Selector: setNesting(bool) e8fc50dd
- function setNesting(bool enable) external;
-
- // Selector: setNesting(bool,address[]) 7df12a9a
- function setNesting(bool enable, address[] memory collections) external;
-}
-
// Selector: 41369377
interface TokenProperties is Dummy, ERC165 {
// Selector: setTokenPropertyPermission(string,bool,bool,bool) 222d97fa
@@ -258,6 +213,63 @@
returns (bool);
}
+// Selector: f56cd7fa
+interface Collection is Dummy, ERC165 {
+ // Selector: setCollectionProperty(string,bytes) 2f073f66
+ function setCollectionProperty(string memory key, bytes memory value)
+ external;
+
+ // Selector: deleteCollectionProperty(string) 7b7debce
+ function deleteCollectionProperty(string memory key) external;
+
+ // Throws error if key not found
+ //
+ // Selector: collectionProperty(string) cf24fd6d
+ function collectionProperty(string memory key)
+ external
+ view
+ returns (bytes memory);
+
+ // Selector: ethSetSponsor(address) 8f9af356
+ function ethSetSponsor(address sponsor) external;
+
+ // Selector: ethConfirmSponsorship() a8580d1a
+ function ethConfirmSponsorship() external;
+
+ // Selector: setLimit(string,uint32) 68db30ca
+ function setLimit(string memory limit, uint32 value) external;
+
+ // Selector: setLimit(string,bool) ea67e4c2
+ function setLimit(string memory limit, bool value) external;
+
+ // Selector: contractAddress() f6b4dfb4
+ function contractAddress() external view returns (address);
+
+ // Selector: addAdmin(address) 70480275
+ function addAdmin(address newAdmin) external view;
+
+ // Selector: removeAdmin(address) 1785f53c
+ function removeAdmin(address admin) external view;
+
+ // Selector: setNesting(bool) e8fc50dd
+ function setNesting(bool enable) external;
+
+ // Selector: setNesting(bool,address[]) 7df12a9a
+ function setNesting(bool enable, address[] memory collections) external;
+
+ // Selector: setAccess(string) 488f56aa
+ function setAccess(string memory mode) external;
+
+ // Selector: addToAllowList(address) 31f59102
+ function addToAllowList(address user) external view;
+
+ // Selector: removeFromAllowList(address) eba8dabc
+ function removeFromAllowList(address user) external view;
+
+ // Selector: setMintMode(bool) 5dea9bd5
+ function setMintMode(bool mode) external;
+}
+
interface UniqueNFT is
Dummy,
ERC165,
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth--- a/tests/src/eth/contractSponsoring.test.ts
+++ b/tests/src/eth/contractSponsoring.test.ts
@@ -221,6 +221,7 @@
expect(await helpers.methods.getSponsoringRateLimit(flipper.options.address).call()).to.be.equals('7200');
});
+ //TODO: CORE-302 add eth methods
itWeb3('Sponsoring collection from evm address via access list', async ({api, web3}) => {
const owner = await createEthAccountWithBalance(api, web3);
const collectionHelpers = evmCollectionHelpers(web3, owner);
@@ -228,65 +229,60 @@
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const sponsor = await createEthAccountWithBalance(api, web3);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
- result = await collectionEvm.methods.setCollectionSponsor(sponsor).send({from: owner});
+ result = await collectionEvm.methods.ethSetSponsor(sponsor).send({from: owner});
let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;
expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
- await collectionEvm.methods.confirmCollectionSponsorship().send({from: sponsor});
+ await collectionEvm.methods.ethConfirmSponsorship().send({from: sponsor});
collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
expect(collectionSub.sponsorship.isConfirmed).to.be.true;
expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
const user = createEthAccount(web3);
- let nextTokenId = await collectionEvm.methods.nextTokenId().call();
+ const nextTokenId = await collectionEvm.methods.nextTokenId().call();
expect(nextTokenId).to.be.equal('1');
const oldPermissions = (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
expect(oldPermissions.mintMode).to.be.false;
expect(oldPermissions.access).to.be.equal('Normal');
- //TODO: change value, when enum generated
- await collectionEvm.methods.setCollectionAccess(1 /*'AllowList'*/).send({from: owner});
- await collectionEvm.methods.addToCollectionAllowList(user).send({from: owner});
- await collectionEvm.methods.setCollectionMintMode(true).send({from: owner});
+ await collectionEvm.methods.setAccess('AllowList').send({from: owner});
+ await collectionEvm.methods.addToAllowList(user).send({from: owner});
+ await collectionEvm.methods.setMintMode(true).send({from: owner});
const newPermissions = (await getDetailedCollectionInfo(api, collectionId))!.permissions.toHuman();
expect(newPermissions.mintMode).to.be.true;
expect(newPermissions.access).to.be.equal('AllowList');
- const ownerBalanceBefore = await ethBalanceViaSub(api, owner);
- const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);
+ // const [alicesBalanceBefore] = await getBalance(api, [alicesPublicKey]);
- nextTokenId = await collectionEvm.methods.nextTokenId().call({from: user});
- expect(nextTokenId).to.be.equal('1');
- result = await collectionEvm.methods.mintWithTokenURI(
- user,
- nextTokenId,
- 'Test URI',
- ).send({from: user});
- const events = normalizeEvents(result.events);
- events[0].address = events[0].address.toLocaleLowerCase();
+ {
+ const nextTokenId = await collectionEvm.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ const result = await collectionEvm.methods.mintWithTokenURI(
+ user,
+ nextTokenId,
+ 'Test URI',
+ ).call({from: user});
+ console.log(result);
+ const events = normalizeEvents(result.events);
- expect(events).to.be.deep.equal([
- {
- address: collectionIdAddress.toLocaleLowerCase(),
- event: 'Transfer',
- args: {
- from: '0x0000000000000000000000000000000000000000',
- to: user,
- tokenId: nextTokenId,
+ expect(events).to.be.deep.equal([
+ {
+ collectionIdAddress,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: user,
+ tokenId: nextTokenId,
+ },
},
- },
- ]);
-
- expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
+ ]);
- const ownerBalanceAfter = await ethBalanceViaSub(api, owner);
- expect(ownerBalanceAfter).to.be.eq(ownerBalanceBefore);
- const sponsorBalanceAfter = await ethBalanceViaSub(api, sponsor);
- expect(sponsorBalanceAfter < sponsorBalanceBefore).to.be.true;
+ expect(await collectionEvm.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
+ }
});
itWeb3('Check that transaction via EVM spend money from sponsor address', async ({api, web3}) => {
@@ -296,22 +292,23 @@
const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
const sponsor = await createEthAccountWithBalance(api, web3);
const collectionEvm = evmCollection(web3, owner, collectionIdAddress);
- result = await collectionEvm.methods.setCollectionSponsor(sponsor).send();
+ result = await collectionEvm.methods.ethSetSponsor(sponsor).send();
let collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
expect(collectionSub.sponsorship.isUnconfirmed).to.be.true;
expect(collectionSub.sponsorship.asUnconfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
- await expect(collectionEvm.methods.confirmCollectionSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
+ await expect(collectionEvm.methods.ethConfirmSponsorship().call()).to.be.rejectedWith('Caller is not set as sponsor');
const sponsorCollection = evmCollection(web3, sponsor, collectionIdAddress);
- await sponsorCollection.methods.confirmCollectionSponsorship().send();
+ await sponsorCollection.methods.ethConfirmSponsorship().send();
collectionSub = (await getDetailedCollectionInfo(api, collectionId))!;
expect(collectionSub.sponsorship.isConfirmed).to.be.true;
expect(collectionSub.sponsorship.asConfirmed.toHuman()).to.be.eq(evmToAddress(sponsor));
const user = createEthAccount(web3);
- await collectionEvm.methods.addCollectionAdmin(user).send();
+ await collectionEvm.methods.addAdmin(user).send();
const ownerBalanceBefore = await ethBalanceViaSub(api, owner);
const sponsorBalanceBefore = await ethBalanceViaSub(api, sponsor);
+
const userCollectionEvm = evmCollection(web3, user, collectionIdAddress);
const nextTokenId = await userCollectionEvm.methods.nextTokenId().call();
tests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth--- a/tests/src/eth/nonFungibleAbi.json
+++ b/tests/src/eth/nonFungibleAbi.json
@@ -91,6 +91,15 @@
},
{
"inputs": [
+ { "internalType": "address", "name": "user", "type": "address" }
+ ],
+ "name": "addToAllowList",
+ "outputs": [],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "address", "name": "approved", "type": "address" },
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
@@ -291,6 +300,15 @@
},
{
"inputs": [
+ { "internalType": "address", "name": "user", "type": "address" }
+ ],
+ "name": "removeFromAllowList",
+ "outputs": [],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "address", "name": "from", "type": "address" },
{ "internalType": "address", "name": "to", "type": "address" },
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
@@ -313,6 +331,13 @@
"type": "function"
},
{
+ "inputs": [{ "internalType": "string", "name": "mode", "type": "string" }],
+ "name": "setAccess",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
"inputs": [
{ "internalType": "address", "name": "operator", "type": "address" },
{ "internalType": "bool", "name": "approved", "type": "bool" }
@@ -397,6 +422,13 @@
"type": "function"
},
{
+ "inputs": [{ "internalType": "bool", "name": "mode", "type": "bool" }],
+ "name": "setMintMode",
+ "outputs": [],
+ "stateMutability": "nonpayable",
+ "type": "function"
+ },
+ {
"inputs": [
{ "internalType": "bool", "name": "enable", "type": "bool" },
{