git.delta.rocks / unique-network / refs/commits / 8dd063b578e3

difftreelog

Merge pull request #869 from UniqueNetwork/feature/generalize_2_methods

Yaroslav Bolyukin2023-02-03parents: #f1a5ba7 #ccafa37.patch.diff
in: master
Feature/generalize_2_methods

34 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6361,7 +6361,7 @@
 
 [[package]]
 name = "pallet-fungible"
-version = "0.1.9"
+version = "0.1.10"
 dependencies = [
  "evm-coder",
  "frame-benchmarking",
@@ -6774,7 +6774,7 @@
 
 [[package]]
 name = "pallet-refungible"
-version = "0.2.12"
+version = "0.2.13"
 dependencies = [
  "evm-coder",
  "frame-benchmarking",
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
--- a/pallets/common/src/eth.rs
+++ b/pallets/common/src/eth.rs
@@ -18,7 +18,10 @@
 
 use alloc::format;
 use sp_std::{vec, vec::Vec};
-use evm_coder::{AbiCoder, types::Address};
+use evm_coder::{
+	AbiCoder,
+	types::{Address, String},
+};
 pub use pallet_evm::{Config, account::CrossAccountId};
 use sp_core::{H160, U256};
 use up_data_structs::CollectionId;
@@ -390,6 +393,16 @@
 	}
 }
 
+/// Data for creation token with uri.
+#[derive(Debug, AbiCoder)]
+pub struct TokenUri {
+	/// Id of new token.
+	pub id: U256,
+
+	/// Uri of new token.
+	pub uri: String,
+}
+
 /// Nested collections.
 #[derive(Debug, Default, AbiCoder)]
 pub struct CollectionNesting {
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -66,10 +66,11 @@
 	ensure,
 	traits::{Imbalance, Get, Currency, WithdrawReasons, ExistenceRequirement},
 	dispatch::Pays,
-	transactional,
+	transactional, fail,
 };
 use pallet_evm::GasWeightMapping;
 use up_data_structs::{
+	AccessMode,
 	COLLECTION_NUMBER_LIMIT,
 	Collection,
 	RpcCollection,
@@ -124,6 +125,8 @@
 pub use pallet::*;
 use sp_core::H160;
 use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
+
+use crate::erc::CollectionHelpersEvents;
 #[cfg(feature = "runtime-benchmarks")]
 pub mod benchmarking;
 pub mod dispatch;
@@ -1264,6 +1267,133 @@
 		Ok(())
 	}
 
+	/// A batch operation to add, edit or remove properties for a token.
+	/// It sets or removes a token's properties according to
+	/// `properties_updates` contents:
+	/// * sets a property under the <key> with the value provided `(<key>, Some(<value>))`
+	/// * removes a property under the <key> if the value is `None` `(<key>, None)`.
+	///
+	/// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
+	/// - `is_token_create`: Indicates that method is called during token initialization.
+	///   Allows to bypass ownership check.
+	///
+	/// All affected properties should have `mutable` permission
+	/// to be **deleted** or to be **set more than once**,
+	/// and the sender should have permission to edit those properties.
+	///
+	/// This function fires an event for each property change.
+	/// In case of an error, all the changes (including the events) will be reverted
+	/// since the function is transactional.
+	pub fn modify_token_properties(
+		collection: &CollectionHandle<T>,
+		sender: &T::CrossAccountId,
+		token_id: TokenId,
+		properties_updates: impl Iterator<Item = (PropertyKey, Option<PropertyValue>)>,
+		is_token_create: bool,
+		mut stored_properties: Properties,
+		is_token_owner: impl Fn() -> Result<bool, DispatchError>,
+		set_token_properties: impl FnOnce(Properties),
+	) -> DispatchResult {
+		let is_collection_admin = collection.is_owner_or_admin(sender);
+		let permissions = Self::property_permissions(collection.id);
+
+		let mut token_owner_result = None;
+		let mut is_token_owner = || -> Result<bool, DispatchError> {
+			*token_owner_result.get_or_insert_with(&is_token_owner)
+		};
+
+		for (key, value) in properties_updates {
+			let permission = permissions
+				.get(&key)
+				.cloned()
+				.unwrap_or_else(PropertyPermission::none);
+
+			let is_property_exists = stored_properties.get(&key).is_some();
+
+			match permission {
+				PropertyPermission { mutable: false, .. } if is_property_exists => {
+					return Err(<Error<T>>::NoPermission.into());
+				}
+
+				PropertyPermission {
+					collection_admin,
+					token_owner,
+					..
+				} => {
+					//TODO: investigate threats during public minting.
+					let is_token_create =
+						is_token_create && (collection_admin || token_owner) && value.is_some();
+					if !(is_token_create
+						|| (collection_admin && is_collection_admin)
+						|| (token_owner && is_token_owner()?))
+					{
+						fail!(<Error<T>>::NoPermission);
+					}
+				}
+			}
+
+			match value {
+				Some(value) => {
+					stored_properties
+						.try_set(key.clone(), value)
+						.map_err(<Error<T>>::from)?;
+
+					Self::deposit_event(Event::TokenPropertySet(collection.id, token_id, key));
+				}
+				None => {
+					stored_properties.remove(&key).map_err(<Error<T>>::from)?;
+
+					Self::deposit_event(Event::TokenPropertyDeleted(collection.id, token_id, key));
+				}
+			}
+
+			<PalletEvm<T>>::deposit_log(
+				CollectionHelpersEvents::TokenChanged {
+					collection_id: eth::collection_id_to_address(collection.id),
+					token_id: token_id.into(),
+				}
+				.to_log(T::ContractAddress::get()),
+			);
+		}
+
+		set_token_properties(stored_properties);
+
+		Ok(())
+	}
+
+	/// Sets or unsets the approval of a given operator.
+	///
+	/// The `operator` is allowed to transfer all token pieces of the `owner` on their behalf.
+	/// - `owner`: Token owner
+	/// - `operator`: Operator
+	/// - `approve`: Should operator status be granted or revoked?
+	pub fn set_allowance_for_all(
+		collection: &CollectionHandle<T>,
+		owner: &T::CrossAccountId,
+		operator: &T::CrossAccountId,
+		approve: bool,
+		set_allowance: impl FnOnce(),
+		log: evm_coder::ethereum::Log,
+	) -> DispatchResult {
+		if collection.permissions.access() == AccessMode::AllowList {
+			collection.check_allowlist(owner)?;
+			collection.check_allowlist(operator)?;
+		}
+
+		Self::ensure_correct_receiver(operator)?;
+
+		set_allowance();
+
+		<PalletEvm<T>>::deposit_log(log);
+		Self::deposit_event(Event::ApprovedForAll(
+			collection.id,
+			owner.clone(),
+			operator.clone(),
+			approve,
+		));
+		Ok(())
+	}
+
 	/// Set collection property.
 	///
 	/// * `collection` - Collection handler.
modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/fungible/CHANGELOG.md
+++ b/pallets/fungible/CHANGELOG.md
@@ -4,6 +4,12 @@
 
 <!-- bureaucrate goes here -->
 
+## [0.1.10] - 2023-02-01
+
+### Added
+
+- The functions `allowanceCross` to `ERC20UniqueExtensions` interface.
+
 ## [0.1.9] - 2022-12-01
 
 ### Added
modifiedpallets/fungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/fungible/Cargo.toml
+++ b/pallets/fungible/Cargo.toml
@@ -2,7 +2,7 @@
 edition = "2021"
 license = "GPLv3"
 name = "pallet-fungible"
-version = "0.1.9"
+version = "0.1.10"
 
 [dependencies]
 # Note: `package = "parity-scale-codec"` must be supplied since the `Encode` macro searches for it.
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -19,6 +19,7 @@
 extern crate alloc;
 use core::char::{REPLACEMENT_CHARACTER, decode_utf16};
 use core::convert::TryInto;
+use evm_coder::AbiCoder;
 use evm_coder::{
 	abi::AbiType, ToLog, execution::*, generate_stubgen, solidity, solidity_interface, types::*,
 	weight,
@@ -27,6 +28,7 @@
 use pallet_common::{
 	CollectionHandle,
 	erc::{CommonEvmHandler, PrecompileResult, CollectionCall},
+	eth::CrossAddress,
 };
 use sp_std::vec::Vec;
 use pallet_evm::{account::CrossAccountId, PrecompileHandle};
@@ -57,6 +59,12 @@
 	},
 }
 
+#[derive(AbiCoder, Debug)]
+pub struct AmountForAddress {
+	to: Address,
+	amount: U256,
+}
+
 #[solidity_interface(name = ERC20, events(ERC20Events), expect_selector = 0x942e8b22)]
 impl<T: Config> FungibleHandle<T> {
 	fn name(&self) -> Result<String> {
@@ -161,6 +169,17 @@
 where
 	T::AccountId: From<[u8; 32]>,
 {
+	/// @dev Function to check the amount of tokens that an owner allowed to a spender.
+	/// @param owner crossAddress The address which owns the funds.
+	/// @param spender crossAddress The address which will spend the funds.
+	/// @return A uint256 specifying the amount of tokens still available for the spender.
+	fn allowance_cross(&self, owner: CrossAddress, spender: CrossAddress) -> Result<U256> {
+		let owner = owner.into_sub_cross_account::<T>()?;
+		let spender = spender.into_sub_cross_account::<T>()?;
+
+		Ok(<Allowance<T>>::get((self.id, owner, spender)).into())
+	}
+
 	/// @notice A description for the collection.
 	fn description(&self) -> Result<String> {
 		Ok(decode_utf16(self.description.iter().copied())
@@ -169,12 +188,7 @@
 	}
 
 	#[weight(<SelfWeightOf<T>>::create_item())]
-	fn mint_cross(
-		&mut self,
-		caller: Caller,
-		to: pallet_common::eth::CrossAddress,
-		amount: U256,
-	) -> Result<bool> {
+	fn mint_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let to = to.into_sub_cross_account::<T>()?;
 		let amount = amount.try_into().map_err(|_| "amount overflow")?;
@@ -190,7 +204,7 @@
 	fn approve_cross(
 		&mut self,
 		caller: Caller,
-		spender: pallet_common::eth::CrossAddress,
+		spender: CrossAddress,
 		amount: U256,
 	) -> Result<bool> {
 		let caller = T::CrossAccountId::from_eth(caller);
@@ -231,7 +245,7 @@
 	fn burn_from_cross(
 		&mut self,
 		caller: Caller,
-		from: pallet_common::eth::CrossAddress,
+		from: CrossAddress,
 		amount: U256,
 	) -> Result<bool> {
 		let caller = T::CrossAccountId::from_eth(caller);
@@ -249,14 +263,14 @@
 	/// Mint tokens for multiple accounts.
 	/// @param amounts array of pairs of account address and amount
 	#[weight(<SelfWeightOf<T>>::create_multiple_items_ex(amounts.len() as u32))]
-	fn mint_bulk(&mut self, caller: Caller, amounts: Vec<(Address, U256)>) -> Result<bool> {
+	fn mint_bulk(&mut self, caller: Caller, amounts: Vec<AmountForAddress>) -> Result<bool> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let budget = self
 			.recorder
 			.weight_calls_budget(<StructureWeight<T>>::find_parent());
 		let amounts = amounts
 			.into_iter()
-			.map(|(to, amount)| {
+			.map(|AmountForAddress { to, amount }| {
 				Ok((
 					T::CrossAccountId::from_eth(to),
 					amount.try_into().map_err(|_| "amount overflow")?,
@@ -270,12 +284,7 @@
 	}
 
 	#[weight(<SelfWeightOf<T>>::transfer())]
-	fn transfer_cross(
-		&mut self,
-		caller: Caller,
-		to: pallet_common::eth::CrossAddress,
-		amount: U256,
-	) -> Result<bool> {
+	fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {
 		let caller = T::CrossAccountId::from_eth(caller);
 		let to = to.into_sub_cross_account::<T>()?;
 		let amount = amount.try_into().map_err(|_| "amount overflow")?;
@@ -291,8 +300,8 @@
 	fn transfer_from_cross(
 		&mut self,
 		caller: Caller,
-		from: pallet_common::eth::CrossAddress,
-		to: pallet_common::eth::CrossAddress,
+		from: CrossAddress,
+		to: CrossAddress,
 		amount: U256,
 	) -> Result<bool> {
 		let caller = T::CrossAccountId::from_eth(caller);
modifiedpallets/fungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -165,8 +165,8 @@
 	pub type Allowance<T: Config> = StorageNMap<
 		Key = (
 			Key<Twox64Concat, CollectionId>,
-			Key<Blake2_128, T::CrossAccountId>,
-			Key<Blake2_128Concat, T::CrossAccountId>,
+			Key<Blake2_128, T::CrossAccountId>,       // Owner
+			Key<Blake2_128Concat, T::CrossAccountId>, // Spender
 		),
 		Value = u128,
 		QueryKind = ValueQuery,
modifiedpallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth
--- a/pallets/fungible/src/stubs/UniqueFungible.sol
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -511,8 +511,22 @@
 	bytes value;
 }
 
-/// @dev the ERC-165 identifier for this interface is 0x65789571
+/// @dev the ERC-165 identifier for this interface is 0x85d7dea6
 contract ERC20UniqueExtensions is Dummy, ERC165 {
+	/// @dev Function to check the amount of tokens that an owner allowed to a spender.
+	/// @param owner crossAddress The address which owns the funds.
+	/// @param spender crossAddress The address which will spend the funds.
+	/// @return A uint256 specifying the amount of tokens still available for the spender.
+	/// @dev EVM selector for this function is: 0xe0af4bd7,
+	///  or in textual repr: allowanceCross((address,uint256),(address,uint256))
+	function allowanceCross(CrossAddress memory owner, CrossAddress memory spender) public view returns (uint256) {
+		require(false, stub_error);
+		owner;
+		spender;
+		dummy;
+		return 0;
+	}
+
 	/// @notice A description for the collection.
 	/// @dev EVM selector for this function is: 0x7284e416,
 	///  or in textual repr: description()
@@ -576,7 +590,7 @@
 	/// @param amounts array of pairs of account address and amount
 	/// @dev EVM selector for this function is: 0x1acf2d55,
 	///  or in textual repr: mintBulk((address,uint256)[])
-	function mintBulk(Tuple9[] memory amounts) public returns (bool) {
+	function mintBulk(AmountForAddress[] memory amounts) public returns (bool) {
 		require(false, stub_error);
 		amounts;
 		dummy = 0;
@@ -618,10 +632,9 @@
 	}
 }
 
-/// @dev anonymous struct
-struct Tuple9 {
-	address field_0;
-	uint256 field_1;
+struct AmountForAddress {
+	address to;
+	uint256 amount;
 }
 
 /// @dev the ERC-165 identifier for this interface is 0x40c10f19
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -38,7 +38,7 @@
 use pallet_common::{
 	CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
 	erc::{CommonEvmHandler, PrecompileResult, CollectionCall, static_property::key},
-	eth,
+	eth::{self, TokenUri},
 };
 use pallet_evm::{account::CrossAccountId, PrecompileHandle};
 use pallet_evm_coder_substrate::call;
@@ -948,7 +948,7 @@
 		&mut self,
 		caller: Caller,
 		to: Address,
-		tokens: Vec<(U256, String)>,
+		tokens: Vec<TokenUri>,
 	) -> Result<bool> {
 		let key = key::url();
 		let caller = T::CrossAccountId::from_eth(caller);
@@ -961,7 +961,7 @@
 			.weight_calls_budget(<StructureWeight<T>>::find_parent());
 
 		let mut data = Vec::with_capacity(tokens.len());
-		for (id, token_uri) in tokens {
+		for TokenUri { id, uri } in tokens {
 			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;
 			if id != expected_index {
 				return Err("item id should be next".into());
@@ -972,7 +972,7 @@
 			properties
 				.try_push(Property {
 					key: key.clone(),
-					value: token_uri
+					value: uri
 						.into_bytes()
 						.try_into()
 						.map_err(|_| "token uri is too long")?,
modifiedpallets/nonfungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -101,18 +101,18 @@
 };
 use up_data_structs::{
 	AccessMode, CollectionId, CollectionFlags, CustomDataLimit, TokenId, CreateCollectionData,
-	CreateNftExData, mapping::TokenAddressMapping, budget::Budget, Property, PropertyPermission,
-	PropertyKey, PropertyValue, PropertyKeyPermission, Properties, PropertyScope, TrySetProperty,
-	TokenChild, AuxPropertyValue, PropertiesPermissionMap,
+	CreateNftExData, mapping::TokenAddressMapping, budget::Budget, Property, PropertyKey,
+	PropertyValue, PropertyKeyPermission, Properties, PropertyScope, TrySetProperty, TokenChild,
+	AuxPropertyValue, PropertiesPermissionMap,
 };
 use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
 use pallet_common::{
 	Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, CollectionHandle,
-	eth::collection_id_to_address, erc::CollectionHelpersEvents,
+	eth::collection_id_to_address,
 };
 use pallet_structure::{Pallet as PalletStructure, Error as StructureError};
 use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
-use sp_core::{H160, Get};
+use sp_core::H160;
 use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
 use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
 use core::ops::Deref;
@@ -578,10 +578,6 @@
 	}
 
 	/// A batch operation to add, edit or remove properties for a token.
-	/// It sets or removes a token's properties according to
-	/// `properties_updates` contents:
-	/// * sets a property under the <key> with the value provided `(<key>, Some(<value>))`
-	/// * removes a property under the <key> if the value is `None` `(<key>, None)`.
 	///
 	/// - `nesting_budget`: Limit for searching parents in-depth to check ownership.
 	/// - `is_token_create`: Indicates that method is called during token initialization.
@@ -603,97 +599,30 @@
 		is_token_create: bool,
 		nesting_budget: &dyn Budget,
 	) -> DispatchResult {
-		let mut collection_admin_status = None;
-		let mut token_owner_result = None;
-
-		let mut is_collection_admin =
-			|| *collection_admin_status.get_or_insert_with(|| collection.is_owner_or_admin(sender));
+		let is_token_owner = || {
+			let is_owned = <PalletStructure<T>>::check_indirectly_owned(
+				sender.clone(),
+				collection.id,
+				token_id,
+				None,
+				nesting_budget,
+			)?;
 
-		let mut is_token_owner = || {
-			*token_owner_result.get_or_insert_with(|| -> Result<bool, DispatchError> {
-				let is_owned = <PalletStructure<T>>::check_indirectly_owned(
-					sender.clone(),
-					collection.id,
-					token_id,
-					None,
-					nesting_budget,
-				)?;
-
-				Ok(is_owned)
-			})
+			Ok(is_owned)
 		};
-
-		let mut stored_properties = <TokenProperties<T>>::get((collection.id, token_id));
-		let permissions = <PalletCommon<T>>::property_permissions(collection.id);
-
-		for (key, value) in properties_updates {
-			let permission = permissions
-				.get(&key)
-				.cloned()
-				.unwrap_or_else(PropertyPermission::none);
-
-			let is_property_exists = stored_properties.get(&key).is_some();
-
-			match permission {
-				PropertyPermission { mutable: false, .. } if is_property_exists => {
-					return Err(<CommonError<T>>::NoPermission.into());
-				}
-
-				PropertyPermission {
-					collection_admin,
-					token_owner,
-					..
-				} => {
-					//TODO: investigate threats during public minting.
-					if is_token_create && (collection_admin || token_owner) && value.is_some() {
-						// Pass
-					} else if collection_admin && is_collection_admin() {
-						// Pass
-					} else if token_owner && is_token_owner()? {
-						// Pass
-					} else {
-						fail!(<CommonError<T>>::NoPermission);
-					}
-				}
-			}
 
-			match value {
-				Some(value) => {
-					stored_properties
-						.try_set(key.clone(), value)
-						.map_err(<CommonError<T>>::from)?;
-
-					<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
-						collection.id,
-						token_id,
-						key,
-					));
-				}
-				None => {
-					stored_properties
-						.remove(&key)
-						.map_err(<CommonError<T>>::from)?;
-
-					<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(
-						collection.id,
-						token_id,
-						key,
-					));
-				}
-			}
-
-			<PalletEvm<T>>::deposit_log(
-				CollectionHelpersEvents::TokenChanged {
-					collection_id: collection_id_to_address(collection.id),
-					token_id: token_id.into(),
-				}
-				.to_log(T::ContractAddress::get()),
-			);
-		}
-
-		<TokenProperties<T>>::set((collection.id, token_id), stored_properties);
+		let stored_properties = <TokenProperties<T>>::get((collection.id, token_id));
 
-		Ok(())
+		<PalletCommon<T>>::modify_token_properties(
+			collection,
+			sender,
+			token_id,
+			properties_updates,
+			is_token_create,
+			stored_properties,
+			is_token_owner,
+			|properties| <TokenProperties<T>>::set((collection.id, token_id), properties),
+		)
 	}
 
 	/// Batch operation to add or edit properties for the token
@@ -1418,31 +1347,19 @@
 		operator: &T::CrossAccountId,
 		approve: bool,
 	) -> DispatchResult {
-		if collection.permissions.access() == AccessMode::AllowList {
-			collection.check_allowlist(owner)?;
-			collection.check_allowlist(operator)?;
-		}
-
-		<PalletCommon<T>>::ensure_correct_receiver(operator)?;
-
-		// =========
-
-		<CollectionAllowance<T>>::insert((collection.id, owner, operator), approve);
-		<PalletEvm<T>>::deposit_log(
+		<PalletCommon<T>>::set_allowance_for_all(
+			collection,
+			owner,
+			operator,
+			approve,
+			|| <CollectionAllowance<T>>::insert((collection.id, owner, operator), approve),
 			ERC721Events::ApprovalForAll {
 				owner: *owner.as_eth(),
 				operator: *operator.as_eth(),
 				approved: approve,
 			}
 			.to_log(collection_id_to_address(collection.id)),
-		);
-		<PalletCommon<T>>::deposit_event(CommonEvent::ApprovedForAll(
-			collection.id,
-			owner.clone(),
-			operator.clone(),
-			approve,
-		));
-		Ok(())
+		)
 	}
 
 	/// Tells whether the given `owner` approves the `operator`.
modifiedpallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -949,7 +949,7 @@
 	// /// @param tokens array of pairs of token ID and token URI for minted tokens
 	// /// @dev EVM selector for this function is: 0x36543006,
 	// ///  or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
-	// function mintBulkWithTokenURI(address to, Tuple15[] memory tokens) public returns (bool) {
+	// function mintBulkWithTokenURI(address to, TokenUri[] memory tokens) public returns (bool) {
 	// 	require(false, stub_error);
 	// 	to;
 	// 	tokens;
@@ -981,10 +981,12 @@
 	}
 }
 
-/// @dev anonymous struct
-struct Tuple15 {
-	uint256 field_0;
-	string field_1;
+/// Data for creation token with uri.
+struct TokenUri {
+	/// Id of new token.
+	uint256 id;
+	/// Uri of new token.
+	string uri;
 }
 
 /// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
modifiedpallets/refungible/CHANGELOG.mddiffbeforeafterboth
--- a/pallets/refungible/CHANGELOG.md
+++ b/pallets/refungible/CHANGELOG.md
@@ -4,6 +4,12 @@
 
 <!-- bureaucrate goes here -->
 
+## [0.2.13] - 2023-02-01
+
+### Added
+
+- The functions `allowanceCross` to `ERC20UniqueExtensions` interface.
+
 ## [0.2.12] - 2023-01-20
 
 ### Fixed
modifiedpallets/refungible/Cargo.tomldiffbeforeafterboth
--- a/pallets/refungible/Cargo.toml
+++ b/pallets/refungible/Cargo.toml
@@ -2,7 +2,7 @@
 edition = "2021"
 license = "GPLv3"
 name = "pallet-refungible"
-version = "0.2.12"
+version = "0.2.13"
 
 [dependencies]
 # Note: `package = "parity-scale-codec"` must be supplied since the `Encode` macro searches for it.
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -34,7 +34,7 @@
 	CollectionHandle, CollectionPropertyPermissions, CommonCollectionOperations,
 	Error as CommonError,
 	erc::{CommonEvmHandler, CollectionCall, static_property::key},
-	eth,
+	eth::{self, TokenUri},
 };
 use pallet_evm::{account::CrossAccountId, PrecompileHandle};
 use pallet_evm_coder_substrate::{call, dispatch_to_evm};
@@ -999,7 +999,7 @@
 		&mut self,
 		caller: Caller,
 		to: Address,
-		tokens: Vec<(U256, String)>,
+		tokens: Vec<TokenUri>,
 	) -> Result<bool> {
 		let key = key::url();
 		let caller = T::CrossAccountId::from_eth(caller);
@@ -1017,7 +1017,7 @@
 			.collect::<BTreeMap<_, _>>()
 			.try_into()
 			.unwrap();
-		for (id, token_uri) in tokens {
+		for TokenUri { id, uri } in tokens {
 			let id: u32 = id.try_into().map_err(|_| "token id overflow")?;
 			if id != expected_index {
 				return Err("item id should be next".into());
@@ -1028,7 +1028,7 @@
 			properties
 				.try_push(Property {
 					key: key.clone(),
-					value: token_uri
+					value: uri
 						.into_bytes()
 						.try_into()
 						.map_err(|_| "token uri is too long")?,
modifiedpallets/refungible/src/erc_token.rsdiffbeforeafterboth
before · pallets/refungible/src/erc_token.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Refungible Pallet EVM API for token pieces18//!19//! Provides ERC-20 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Nonfungible Pallet methods.2122use core::{23	char::{REPLACEMENT_CHARACTER, decode_utf16},24	convert::TryInto,25	ops::Deref,26};27use evm_coder::{28	abi::AbiType, ToLog, execution::*, generate_stubgen, solidity_interface, solidity, types::*,29	weight,30};31use pallet_common::{32	CommonWeightInfo,33	erc::{CommonEvmHandler, PrecompileResult},34	eth::collection_id_to_address,35};36use pallet_evm::{account::CrossAccountId, PrecompileHandle};37use pallet_evm_coder_substrate::{call, dispatch_to_evm, WithRecorder};38use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};39use sp_std::vec::Vec;40use sp_core::U256;41use up_data_structs::TokenId;4243use crate::{44	Allowance, Balance, common::CommonWeights, Config, Pallet, RefungibleHandle, SelfWeightOf,45	TotalSupply, weights::WeightInfo,46};4748/// Refungible token handle contains information about token's collection and id49///50/// RefungibleTokenHandle doesn't check token's existance upon creation51pub struct RefungibleTokenHandle<T: Config>(pub RefungibleHandle<T>, pub TokenId);5253#[solidity_interface(name = ERC1633)]54impl<T: Config> RefungibleTokenHandle<T> {55	fn parent_token(&self) -> Result<Address> {56		Ok(collection_id_to_address(self.id))57	}5859	fn parent_token_id(&self) -> Result<U256> {60		Ok(self.1.into())61	}62}6364#[derive(ToLog)]65pub enum ERC20Events {66	/// @dev This event is emitted when the amount of tokens (value) is sent67	/// from the from address to the to address. In the case of minting new68	/// tokens, the transfer is usually from the 0 address while in the case69	/// of burning tokens the transfer is to 0.70	Transfer {71		#[indexed]72		from: Address,73		#[indexed]74		to: Address,75		value: U256,76	},77	/// @dev This event is emitted when the amount of tokens (value) is approved78	/// by the owner to be used by the spender.79	Approval {80		#[indexed]81		owner: Address,82		#[indexed]83		spender: Address,84		value: U256,85	},86}8788/// @title Standard ERC20 token89///90/// @dev Implementation of the basic standard token.91/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md92#[solidity_interface(name = ERC20, events(ERC20Events))]93impl<T: Config> RefungibleTokenHandle<T> {94	/// @return the name of the token.95	fn name(&self) -> Result<String> {96		Ok(decode_utf16(self.name.iter().copied())97			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))98			.collect::<String>())99	}100101	/// @return the symbol of the token.102	fn symbol(&self) -> Result<String> {103		Ok(String::from_utf8_lossy(&self.token_prefix).into())104	}105106	/// @dev Total number of tokens in existence107	fn total_supply(&self) -> Result<U256> {108		self.consume_store_reads(1)?;109		Ok(<TotalSupply<T>>::get((self.id, self.1)).into())110	}111112	/// @dev Not supported113	fn decimals(&self) -> Result<u8> {114		// Decimals aren't supported for refungible tokens115		Ok(0)116	}117118	/// @dev Gets the balance of the specified address.119	/// @param owner The address to query the balance of.120	/// @return An uint256 representing the amount owned by the passed address.121	fn balance_of(&self, owner: Address) -> Result<U256> {122		self.consume_store_reads(1)?;123		let owner = T::CrossAccountId::from_eth(owner);124		let balance = <Balance<T>>::get((self.id, self.1, owner));125		Ok(balance.into())126	}127128	/// @dev Transfer token for a specified address129	/// @param to The address to transfer to.130	/// @param amount The amount to be transferred.131	#[weight(<CommonWeights<T>>::transfer())]132	fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {133		let caller = T::CrossAccountId::from_eth(caller);134		let to = T::CrossAccountId::from_eth(to);135		let amount = amount.try_into().map_err(|_| "amount overflow")?;136		let budget = self137			.recorder138			.weight_calls_budget(<StructureWeight<T>>::find_parent());139140		<Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)141			.map_err(dispatch_to_evm::<T>)?;142		Ok(true)143	}144145	/// @dev Transfer tokens from one address to another146	/// @param from address The address which you want to send tokens from147	/// @param to address The address which you want to transfer to148	/// @param amount uint256 the amount of tokens to be transferred149	#[weight(<CommonWeights<T>>::transfer_from())]150	fn transfer_from(151		&mut self,152		caller: Caller,153		from: Address,154		to: Address,155		amount: U256,156	) -> Result<bool> {157		let caller = T::CrossAccountId::from_eth(caller);158		let from = T::CrossAccountId::from_eth(from);159		let to = T::CrossAccountId::from_eth(to);160		let amount = amount.try_into().map_err(|_| "amount overflow")?;161		let budget = self162			.recorder163			.weight_calls_budget(<StructureWeight<T>>::find_parent());164165		<Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)166			.map_err(dispatch_to_evm::<T>)?;167		Ok(true)168	}169170	/// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.171	/// Beware that changing an allowance with this method brings the risk that someone may use both the old172	/// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this173	/// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:174	/// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729175	/// @param spender The address which will spend the funds.176	/// @param amount The amount of tokens to be spent.177	#[weight(<SelfWeightOf<T>>::approve())]178	fn approve(&mut self, caller: Caller, spender: Address, amount: U256) -> Result<bool> {179		let caller = T::CrossAccountId::from_eth(caller);180		let spender = T::CrossAccountId::from_eth(spender);181		let amount = amount.try_into().map_err(|_| "amount overflow")?;182183		<Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)184			.map_err(dispatch_to_evm::<T>)?;185		Ok(true)186	}187188	/// @dev Function to check the amount of tokens that an owner allowed to a spender.189	/// @param owner address The address which owns the funds.190	/// @param spender address The address which will spend the funds.191	/// @return A uint256 specifying the amount of tokens still available for the spender.192	fn allowance(&self, owner: Address, spender: Address) -> Result<U256> {193		self.consume_store_reads(1)?;194		let owner = T::CrossAccountId::from_eth(owner);195		let spender = T::CrossAccountId::from_eth(spender);196197		Ok(<Allowance<T>>::get((self.id, self.1, owner, spender)).into())198	}199}200201#[solidity_interface(name = ERC20UniqueExtensions)]202impl<T: Config> RefungibleTokenHandle<T>203where204	T::AccountId: From<[u8; 32]>,205{206	/// @dev Function that burns an amount of the token of a given account,207	/// deducting from the sender's allowance for said account.208	/// @param from The account whose tokens will be burnt.209	/// @param amount The amount that will be burnt.210	#[weight(<SelfWeightOf<T>>::burn_from())]211	#[solidity(hide)]212	fn burn_from(&mut self, caller: Caller, from: Address, amount: U256) -> Result<bool> {213		let caller = T::CrossAccountId::from_eth(caller);214		let from = T::CrossAccountId::from_eth(from);215		let amount = amount.try_into().map_err(|_| "amount overflow")?;216		let budget = self217			.recorder218			.weight_calls_budget(<StructureWeight<T>>::find_parent());219220		<Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)221			.map_err(dispatch_to_evm::<T>)?;222		Ok(true)223	}224225	/// @dev Function that burns an amount of the token of a given account,226	/// deducting from the sender's allowance for said account.227	/// @param from The account whose tokens will be burnt.228	/// @param amount The amount that will be burnt.229	#[weight(<SelfWeightOf<T>>::burn_from())]230	fn burn_from_cross(231		&mut self,232		caller: Caller,233		from: pallet_common::eth::CrossAddress,234		amount: U256,235	) -> Result<bool> {236		let caller = T::CrossAccountId::from_eth(caller);237		let from = from.into_sub_cross_account::<T>()?;238		let amount = amount.try_into().map_err(|_| "amount overflow")?;239		let budget = self240			.recorder241			.weight_calls_budget(<StructureWeight<T>>::find_parent());242243		<Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)244			.map_err(dispatch_to_evm::<T>)?;245		Ok(true)246	}247248	/// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.249	/// Beware that changing an allowance with this method brings the risk that someone may use both the old250	/// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this251	/// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:252	/// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729253	/// @param spender The crossaccount which will spend the funds.254	/// @param amount The amount of tokens to be spent.255	#[weight(<SelfWeightOf<T>>::approve())]256	fn approve_cross(257		&mut self,258		caller: Caller,259		spender: pallet_common::eth::CrossAddress,260		amount: U256,261	) -> Result<bool> {262		let caller = T::CrossAccountId::from_eth(caller);263		let spender = spender.into_sub_cross_account::<T>()?;264		let amount = amount.try_into().map_err(|_| "amount overflow")?;265266		<Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)267			.map_err(dispatch_to_evm::<T>)?;268		Ok(true)269	}270	/// @dev Function that changes total amount of the tokens.271	///  Throws if `msg.sender` doesn't owns all of the tokens.272	/// @param amount New total amount of the tokens.273	#[weight(<SelfWeightOf<T>>::repartition_item())]274	fn repartition(&mut self, caller: Caller, amount: U256) -> Result<bool> {275		let caller = T::CrossAccountId::from_eth(caller);276		let amount = amount.try_into().map_err(|_| "amount overflow")?;277278		<Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;279		Ok(true)280	}281282	/// @dev Transfer token for a specified address283	/// @param to The crossaccount to transfer to.284	/// @param amount The amount to be transferred.285	#[weight(<CommonWeights<T>>::transfer())]286	fn transfer_cross(287		&mut self,288		caller: Caller,289		to: pallet_common::eth::CrossAddress,290		amount: U256,291	) -> Result<bool> {292		let caller = T::CrossAccountId::from_eth(caller);293		let to = to.into_sub_cross_account::<T>()?;294		let amount = amount.try_into().map_err(|_| "amount overflow")?;295		let budget = self296			.recorder297			.weight_calls_budget(<StructureWeight<T>>::find_parent());298299		<Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)300			.map_err(dispatch_to_evm::<T>)?;301		Ok(true)302	}303304	/// @dev Transfer tokens from one address to another305	/// @param from The address which you want to send tokens from306	/// @param to The address which you want to transfer to307	/// @param amount the amount of tokens to be transferred308	#[weight(<CommonWeights<T>>::transfer_from())]309	fn transfer_from_cross(310		&mut self,311		caller: Caller,312		from: pallet_common::eth::CrossAddress,313		to: pallet_common::eth::CrossAddress,314		amount: U256,315	) -> Result<bool> {316		let caller = T::CrossAccountId::from_eth(caller);317		let from = from.into_sub_cross_account::<T>()?;318		let to = to.into_sub_cross_account::<T>()?;319		let amount = amount.try_into().map_err(|_| "amount overflow")?;320		let budget = self321			.recorder322			.weight_calls_budget(<StructureWeight<T>>::find_parent());323324		<Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)325			.map_err(dispatch_to_evm::<T>)?;326		Ok(true)327	}328}329330impl<T: Config> RefungibleTokenHandle<T> {331	pub fn into_inner(self) -> RefungibleHandle<T> {332		self.0333	}334	pub fn common_mut(&mut self) -> &mut RefungibleHandle<T> {335		&mut self.0336	}337}338339impl<T: Config> WithRecorder<T> for RefungibleTokenHandle<T> {340	fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {341		self.0.recorder()342	}343	fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {344		self.0.into_recorder()345	}346}347348impl<T: Config> Deref for RefungibleTokenHandle<T> {349	type Target = RefungibleHandle<T>;350351	fn deref(&self) -> &Self::Target {352		&self.0353	}354}355356#[solidity_interface(357	name = UniqueRefungibleToken,358	is(ERC20, ERC20UniqueExtensions, ERC1633)359)]360impl<T: Config> RefungibleTokenHandle<T> where T::AccountId: From<[u8; 32]> {}361362generate_stubgen!(gen_impl, UniqueRefungibleTokenCall<()>, true);363generate_stubgen!(gen_iface, UniqueRefungibleTokenCall<()>, false);364365impl<T: Config> CommonEvmHandler for RefungibleTokenHandle<T>366where367	T::AccountId: From<[u8; 32]>,368{369	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungibleToken.raw");370371	fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {372		call::<T, UniqueRefungibleTokenCall<T>, _, _>(handle, self)373	}374}
after · pallets/refungible/src/erc_token.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # Refungible Pallet EVM API for token pieces18//!19//! Provides ERC-20 standart support implementation and EVM API for unique extensions for Refungible Pallet.20//! Method implementations are mostly doing parameter conversion and calling Nonfungible Pallet methods.2122use core::{23	char::{REPLACEMENT_CHARACTER, decode_utf16},24	convert::TryInto,25	ops::Deref,26};27use evm_coder::{28	abi::AbiType, ToLog, execution::*, generate_stubgen, solidity_interface, solidity, types::*,29	weight,30};31use pallet_common::{32	CommonWeightInfo,33	erc::{CommonEvmHandler, PrecompileResult},34	eth::{collection_id_to_address, CrossAddress},35};36use pallet_evm::{account::CrossAccountId, PrecompileHandle};37use pallet_evm_coder_substrate::{call, dispatch_to_evm, WithRecorder};38use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _};39use sp_std::vec::Vec;40use sp_core::U256;41use up_data_structs::TokenId;4243use crate::{44	Allowance, Balance, common::CommonWeights, Config, Pallet, RefungibleHandle, SelfWeightOf,45	TotalSupply, weights::WeightInfo,46};4748/// Refungible token handle contains information about token's collection and id49///50/// RefungibleTokenHandle doesn't check token's existance upon creation51pub struct RefungibleTokenHandle<T: Config>(pub RefungibleHandle<T>, pub TokenId);5253#[solidity_interface(name = ERC1633)]54impl<T: Config> RefungibleTokenHandle<T> {55	fn parent_token(&self) -> Result<Address> {56		Ok(collection_id_to_address(self.id))57	}5859	fn parent_token_id(&self) -> Result<U256> {60		Ok(self.1.into())61	}62}6364#[derive(ToLog)]65pub enum ERC20Events {66	/// @dev This event is emitted when the amount of tokens (value) is sent67	/// from the from address to the to address. In the case of minting new68	/// tokens, the transfer is usually from the 0 address while in the case69	/// of burning tokens the transfer is to 0.70	Transfer {71		#[indexed]72		from: Address,73		#[indexed]74		to: Address,75		value: U256,76	},77	/// @dev This event is emitted when the amount of tokens (value) is approved78	/// by the owner to be used by the spender.79	Approval {80		#[indexed]81		owner: Address,82		#[indexed]83		spender: Address,84		value: U256,85	},86}8788/// @title Standard ERC20 token89///90/// @dev Implementation of the basic standard token.91/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md92#[solidity_interface(name = ERC20, events(ERC20Events))]93impl<T: Config> RefungibleTokenHandle<T> {94	/// @return the name of the token.95	fn name(&self) -> Result<String> {96		Ok(decode_utf16(self.name.iter().copied())97			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))98			.collect::<String>())99	}100101	/// @return the symbol of the token.102	fn symbol(&self) -> Result<String> {103		Ok(String::from_utf8_lossy(&self.token_prefix).into())104	}105106	/// @dev Total number of tokens in existence107	fn total_supply(&self) -> Result<U256> {108		self.consume_store_reads(1)?;109		Ok(<TotalSupply<T>>::get((self.id, self.1)).into())110	}111112	/// @dev Not supported113	fn decimals(&self) -> Result<u8> {114		// Decimals aren't supported for refungible tokens115		Ok(0)116	}117118	/// @dev Gets the balance of the specified address.119	/// @param owner The address to query the balance of.120	/// @return An uint256 representing the amount owned by the passed address.121	fn balance_of(&self, owner: Address) -> Result<U256> {122		self.consume_store_reads(1)?;123		let owner = T::CrossAccountId::from_eth(owner);124		let balance = <Balance<T>>::get((self.id, self.1, owner));125		Ok(balance.into())126	}127128	/// @dev Transfer token for a specified address129	/// @param to The address to transfer to.130	/// @param amount The amount to be transferred.131	#[weight(<CommonWeights<T>>::transfer())]132	fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {133		let caller = T::CrossAccountId::from_eth(caller);134		let to = T::CrossAccountId::from_eth(to);135		let amount = amount.try_into().map_err(|_| "amount overflow")?;136		let budget = self137			.recorder138			.weight_calls_budget(<StructureWeight<T>>::find_parent());139140		<Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)141			.map_err(dispatch_to_evm::<T>)?;142		Ok(true)143	}144145	/// @dev Transfer tokens from one address to another146	/// @param from address The address which you want to send tokens from147	/// @param to address The address which you want to transfer to148	/// @param amount uint256 the amount of tokens to be transferred149	#[weight(<CommonWeights<T>>::transfer_from())]150	fn transfer_from(151		&mut self,152		caller: Caller,153		from: Address,154		to: Address,155		amount: U256,156	) -> Result<bool> {157		let caller = T::CrossAccountId::from_eth(caller);158		let from = T::CrossAccountId::from_eth(from);159		let to = T::CrossAccountId::from_eth(to);160		let amount = amount.try_into().map_err(|_| "amount overflow")?;161		let budget = self162			.recorder163			.weight_calls_budget(<StructureWeight<T>>::find_parent());164165		<Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)166			.map_err(dispatch_to_evm::<T>)?;167		Ok(true)168	}169170	/// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.171	/// Beware that changing an allowance with this method brings the risk that someone may use both the old172	/// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this173	/// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:174	/// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729175	/// @param spender The address which will spend the funds.176	/// @param amount The amount of tokens to be spent.177	#[weight(<SelfWeightOf<T>>::approve())]178	fn approve(&mut self, caller: Caller, spender: Address, amount: U256) -> Result<bool> {179		let caller = T::CrossAccountId::from_eth(caller);180		let spender = T::CrossAccountId::from_eth(spender);181		let amount = amount.try_into().map_err(|_| "amount overflow")?;182183		<Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)184			.map_err(dispatch_to_evm::<T>)?;185		Ok(true)186	}187188	/// @dev Function to check the amount of tokens that an owner allowed to a spender.189	/// @param owner address The address which owns the funds.190	/// @param spender address The address which will spend the funds.191	/// @return A uint256 specifying the amount of tokens still available for the spender.192	fn allowance(&self, owner: Address, spender: Address) -> Result<U256> {193		self.consume_store_reads(1)?;194		let owner = T::CrossAccountId::from_eth(owner);195		let spender = T::CrossAccountId::from_eth(spender);196197		Ok(<Allowance<T>>::get((self.id, self.1, owner, spender)).into())198	}199}200201#[solidity_interface(name = ERC20UniqueExtensions)]202impl<T: Config> RefungibleTokenHandle<T>203where204	T::AccountId: From<[u8; 32]>,205{206	/// @dev Function to check the amount of tokens that an owner allowed to a spender.207	/// @param owner crossAddress The address which owns the funds.208	/// @param spender crossAddress The address which will spend the funds.209	/// @return A uint256 specifying the amount of tokens still available for the spender.210	fn allowance_cross(&self, owner: CrossAddress, spender: CrossAddress) -> Result<U256> {211		let owner = owner.into_sub_cross_account::<T>()?;212		let spender = spender.into_sub_cross_account::<T>()?;213214		Ok(<Allowance<T>>::get((self.id, self.1, owner, spender)).into())215	}216217	/// @dev Function that burns an amount of the token of a given account,218	/// deducting from the sender's allowance for said account.219	/// @param from The account whose tokens will be burnt.220	/// @param amount The amount that will be burnt.221	#[weight(<SelfWeightOf<T>>::burn_from())]222	#[solidity(hide)]223	fn burn_from(&mut self, caller: Caller, from: Address, amount: U256) -> Result<bool> {224		let caller = T::CrossAccountId::from_eth(caller);225		let from = T::CrossAccountId::from_eth(from);226		let amount = amount.try_into().map_err(|_| "amount overflow")?;227		let budget = self228			.recorder229			.weight_calls_budget(<StructureWeight<T>>::find_parent());230231		<Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)232			.map_err(dispatch_to_evm::<T>)?;233		Ok(true)234	}235236	/// @dev Function that burns an amount of the token of a given account,237	/// deducting from the sender's allowance for said account.238	/// @param from The account whose tokens will be burnt.239	/// @param amount The amount that will be burnt.240	#[weight(<SelfWeightOf<T>>::burn_from())]241	fn burn_from_cross(242		&mut self,243		caller: Caller,244		from: CrossAddress,245		amount: U256,246	) -> Result<bool> {247		let caller = T::CrossAccountId::from_eth(caller);248		let from = from.into_sub_cross_account::<T>()?;249		let amount = amount.try_into().map_err(|_| "amount overflow")?;250		let budget = self251			.recorder252			.weight_calls_budget(<StructureWeight<T>>::find_parent());253254		<Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)255			.map_err(dispatch_to_evm::<T>)?;256		Ok(true)257	}258259	/// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.260	/// Beware that changing an allowance with this method brings the risk that someone may use both the old261	/// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this262	/// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:263	/// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729264	/// @param spender The crossaccount which will spend the funds.265	/// @param amount The amount of tokens to be spent.266	#[weight(<SelfWeightOf<T>>::approve())]267	fn approve_cross(268		&mut self,269		caller: Caller,270		spender: CrossAddress,271		amount: U256,272	) -> Result<bool> {273		let caller = T::CrossAccountId::from_eth(caller);274		let spender = spender.into_sub_cross_account::<T>()?;275		let amount = amount.try_into().map_err(|_| "amount overflow")?;276277		<Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)278			.map_err(dispatch_to_evm::<T>)?;279		Ok(true)280	}281	/// @dev Function that changes total amount of the tokens.282	///  Throws if `msg.sender` doesn't owns all of the tokens.283	/// @param amount New total amount of the tokens.284	#[weight(<SelfWeightOf<T>>::repartition_item())]285	fn repartition(&mut self, caller: Caller, amount: U256) -> Result<bool> {286		let caller = T::CrossAccountId::from_eth(caller);287		let amount = amount.try_into().map_err(|_| "amount overflow")?;288289		<Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;290		Ok(true)291	}292293	/// @dev Transfer token for a specified address294	/// @param to The crossaccount to transfer to.295	/// @param amount The amount to be transferred.296	#[weight(<CommonWeights<T>>::transfer())]297	fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {298		let caller = T::CrossAccountId::from_eth(caller);299		let to = to.into_sub_cross_account::<T>()?;300		let amount = amount.try_into().map_err(|_| "amount overflow")?;301		let budget = self302			.recorder303			.weight_calls_budget(<StructureWeight<T>>::find_parent());304305		<Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)306			.map_err(dispatch_to_evm::<T>)?;307		Ok(true)308	}309310	/// @dev Transfer tokens from one address to another311	/// @param from The address which you want to send tokens from312	/// @param to The address which you want to transfer to313	/// @param amount the amount of tokens to be transferred314	#[weight(<CommonWeights<T>>::transfer_from())]315	fn transfer_from_cross(316		&mut self,317		caller: Caller,318		from: CrossAddress,319		to: CrossAddress,320		amount: U256,321	) -> Result<bool> {322		let caller = T::CrossAccountId::from_eth(caller);323		let from = from.into_sub_cross_account::<T>()?;324		let to = to.into_sub_cross_account::<T>()?;325		let amount = amount.try_into().map_err(|_| "amount overflow")?;326		let budget = self327			.recorder328			.weight_calls_budget(<StructureWeight<T>>::find_parent());329330		<Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)331			.map_err(dispatch_to_evm::<T>)?;332		Ok(true)333	}334}335336impl<T: Config> RefungibleTokenHandle<T> {337	pub fn into_inner(self) -> RefungibleHandle<T> {338		self.0339	}340	pub fn common_mut(&mut self) -> &mut RefungibleHandle<T> {341		&mut self.0342	}343}344345impl<T: Config> WithRecorder<T> for RefungibleTokenHandle<T> {346	fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {347		self.0.recorder()348	}349	fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {350		self.0.into_recorder()351	}352}353354impl<T: Config> Deref for RefungibleTokenHandle<T> {355	type Target = RefungibleHandle<T>;356357	fn deref(&self) -> &Self::Target {358		&self.0359	}360}361362#[solidity_interface(363	name = UniqueRefungibleToken,364	is(ERC20, ERC20UniqueExtensions, ERC1633)365)]366impl<T: Config> RefungibleTokenHandle<T> where T::AccountId: From<[u8; 32]> {}367368generate_stubgen!(gen_impl, UniqueRefungibleTokenCall<()>, true);369generate_stubgen!(gen_iface, UniqueRefungibleTokenCall<()>, false);370371impl<T: Config> CommonEvmHandler for RefungibleTokenHandle<T>372where373	T::AccountId: From<[u8; 32]>,374{375	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungibleToken.raw");376377	fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {378		call::<T, UniqueRefungibleTokenCall<T>, _, _>(handle, self)379	}380}
modifiedpallets/refungible/src/lib.rsdiffbeforeafterboth
--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -92,22 +92,22 @@
 
 use core::ops::Deref;
 use evm_coder::ToLog;
-use frame_support::{ensure, fail, storage::with_transaction, transactional};
+use frame_support::{ensure, storage::with_transaction, transactional};
 use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
 use pallet_evm_coder_substrate::WithRecorder;
 use pallet_common::{
 	CommonCollectionOperations, Error as CommonError, eth::collection_id_to_address,
-	Event as CommonEvent, Pallet as PalletCommon, erc::CollectionHelpersEvents,
+	Event as CommonEvent, Pallet as PalletCommon,
 };
 use pallet_structure::Pallet as PalletStructure;
-use sp_core::{Get, H160};
+use sp_core::H160;
 use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, TransactionOutcome};
 use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
 use up_data_structs::{
 	AccessMode, budget::Budget, CollectionId, CollectionFlags, CreateCollectionData,
 	mapping::TokenAddressMapping, MAX_REFUNGIBLE_PIECES, Property, PropertyKey,
-	PropertyKeyPermission, PropertyPermission, PropertyScope, PropertyValue, TokenId,
-	TrySetProperty, PropertiesPermissionMap, CreateRefungibleExMultipleOwners, TokenOwnerError,
+	PropertyKeyPermission, PropertyScope, PropertyValue, TokenId, TrySetProperty,
+	PropertiesPermissionMap, CreateRefungibleExMultipleOwners, TokenOwnerError,
 };
 
 pub use pallet::*;
@@ -240,13 +240,13 @@
 		QueryKind = ValueQuery,
 	>;
 
-	/// Operator set by a wallet owner that could perform certain transactions on all tokens in the wallet.
+	/// Spender set by a wallet owner that could perform certain transactions on all tokens in the wallet.
 	#[pallet::storage]
 	pub type CollectionAllowance<T: Config> = StorageNMap<
 		Key = (
 			Key<Twox64Concat, CollectionId>,
-			Key<Blake2_128Concat, T::CrossAccountId>,
-			Key<Blake2_128Concat, T::CrossAccountId>,
+			Key<Blake2_128Concat, T::CrossAccountId>, // Owner
+			Key<Blake2_128Concat, T::CrossAccountId>, // Spender
 		),
 		Value = bool,
 		QueryKind = ValueQuery,
@@ -541,7 +541,6 @@
 		is_token_create: bool,
 		nesting_budget: &dyn Budget,
 	) -> DispatchResult {
-		let is_collection_admin = || collection.is_owner_or_admin(sender);
 		let is_token_owner = || -> Result<bool, DispatchError> {
 			let balance = collection.balance(sender.clone(), token_id);
 			let total_pieces: u128 =
@@ -560,77 +559,19 @@
 
 			Ok(is_bundle_owner)
 		};
-
-		let mut stored_properties = <TokenProperties<T>>::get((collection.id, token_id));
-		let permissions = <PalletCommon<T>>::property_permissions(collection.id);
-
-		for (key, value) in properties_updates {
-			let permission = permissions
-				.get(&key)
-				.cloned()
-				.unwrap_or_else(PropertyPermission::none);
-
-			let is_property_exists = stored_properties.get(&key).is_some();
-
-			match permission {
-				PropertyPermission { mutable: false, .. } if is_property_exists => {
-					return Err(<CommonError<T>>::NoPermission.into());
-				}
 
-				PropertyPermission {
-					collection_admin,
-					token_owner,
-					..
-				} => {
-					//TODO: investigate threats during public minting.
-					let is_token_create =
-						is_token_create && (collection_admin || token_owner) && value.is_some();
-					if !(is_token_create
-						|| (collection_admin && is_collection_admin())
-						|| (token_owner && is_token_owner()?))
-					{
-						fail!(<CommonError<T>>::NoPermission);
-					}
-				}
-			}
-
-			match value {
-				Some(value) => {
-					stored_properties
-						.try_set(key.clone(), value)
-						.map_err(<CommonError<T>>::from)?;
-
-					<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertySet(
-						collection.id,
-						token_id,
-						key,
-					));
-				}
-				None => {
-					stored_properties
-						.remove(&key)
-						.map_err(<CommonError<T>>::from)?;
-
-					<PalletCommon<T>>::deposit_event(CommonEvent::TokenPropertyDeleted(
-						collection.id,
-						token_id,
-						key,
-					));
-				}
-			}
-
-			<PalletEvm<T>>::deposit_log(
-				CollectionHelpersEvents::TokenChanged {
-					collection_id: collection_id_to_address(collection.id),
-					token_id: token_id.into(),
-				}
-				.to_log(T::ContractAddress::get()),
-			);
-		}
+		let stored_properties = <TokenProperties<T>>::get((collection.id, token_id));
 
-		<TokenProperties<T>>::set((collection.id, token_id), stored_properties);
-
-		Ok(())
+		<PalletCommon<T>>::modify_token_properties(
+			collection,
+			sender,
+			token_id,
+			properties_updates,
+			is_token_create,
+			stored_properties,
+			is_token_owner,
+			|properties| <TokenProperties<T>>::set((collection.id, token_id), properties),
+		)
 	}
 
 	pub fn set_token_properties(
@@ -1462,43 +1403,31 @@
 	pub fn set_allowance_for_all(
 		collection: &RefungibleHandle<T>,
 		owner: &T::CrossAccountId,
-		operator: &T::CrossAccountId,
+		spender: &T::CrossAccountId,
 		approve: bool,
 	) -> DispatchResult {
-		if collection.permissions.access() == AccessMode::AllowList {
-			collection.check_allowlist(owner)?;
-			collection.check_allowlist(operator)?;
-		}
-
-		<PalletCommon<T>>::ensure_correct_receiver(operator)?;
-
-		// =========
-
-		<CollectionAllowance<T>>::insert((collection.id, owner, operator), approve);
-		<PalletEvm<T>>::deposit_log(
+		<PalletCommon<T>>::set_allowance_for_all(
+			collection,
+			owner,
+			spender,
+			approve,
+			|| <CollectionAllowance<T>>::insert((collection.id, owner, spender), approve),
 			ERC721Events::ApprovalForAll {
 				owner: *owner.as_eth(),
-				operator: *operator.as_eth(),
+				operator: *spender.as_eth(),
 				approved: approve,
 			}
 			.to_log(collection_id_to_address(collection.id)),
-		);
-		<PalletCommon<T>>::deposit_event(CommonEvent::ApprovedForAll(
-			collection.id,
-			owner.clone(),
-			operator.clone(),
-			approve,
-		));
-		Ok(())
+		)
 	}
 
 	/// Tells whether the given `owner` approves the `operator`.
 	pub fn allowance_for_all(
 		collection: &RefungibleHandle<T>,
 		owner: &T::CrossAccountId,
-		operator: &T::CrossAccountId,
+		spender: &T::CrossAccountId,
 	) -> bool {
-		<CollectionAllowance<T>>::get((collection.id, owner, operator))
+		<CollectionAllowance<T>>::get((collection.id, owner, spender))
 	}
 
 	pub fn repair_item(collection: &RefungibleHandle<T>, token: TokenId) -> DispatchResult {
modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -938,7 +938,7 @@
 	// /// @param tokens array of pairs of token ID and token URI for minted tokens
 	// /// @dev EVM selector for this function is: 0x36543006,
 	// ///  or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
-	// function mintBulkWithTokenURI(address to, Tuple14[] memory tokens) public returns (bool) {
+	// function mintBulkWithTokenURI(address to, TokenUri[] memory tokens) public returns (bool) {
 	// 	require(false, stub_error);
 	// 	to;
 	// 	tokens;
@@ -982,10 +982,12 @@
 	}
 }
 
-/// @dev anonymous struct
-struct Tuple14 {
-	uint256 field_0;
-	string field_1;
+/// Data for creation token with uri.
+struct TokenUri {
+	/// Id of new token.
+	uint256 id;
+	/// Uri of new token.
+	string uri;
 }
 
 /// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
modifiedpallets/refungible/src/stubs/UniqueRefungibleToken.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungibleToken.soldiffbeforeafterboth
--- a/pallets/refungible/src/stubs/UniqueRefungibleToken.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungibleToken.sol
@@ -36,8 +36,22 @@
 	}
 }
 
-/// @dev the ERC-165 identifier for this interface is 0xe17a7d2b
+/// @dev the ERC-165 identifier for this interface is 0x01d536fc
 contract ERC20UniqueExtensions is Dummy, ERC165 {
+	/// @dev Function to check the amount of tokens that an owner allowed to a spender.
+	/// @param owner crossAddress The address which owns the funds.
+	/// @param spender crossAddress The address which will spend the funds.
+	/// @return A uint256 specifying the amount of tokens still available for the spender.
+	/// @dev EVM selector for this function is: 0xe0af4bd7,
+	///  or in textual repr: allowanceCross((address,uint256),(address,uint256))
+	function allowanceCross(CrossAddress memory owner, CrossAddress memory spender) public view returns (uint256) {
+		require(false, stub_error);
+		owner;
+		spender;
+		dummy;
+		return 0;
+	}
+
 	// /// @dev Function that burns an amount of the token of a given account,
 	// /// deducting from the sender's allowance for said account.
 	// /// @param from The account whose tokens will be burnt.
modifiedpallets/unique/src/eth/stubs/CollectionHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedruntime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth
--- a/runtime/common/ethereum/sponsoring/refungible.rs
+++ b/runtime/common/ethereum/sponsoring/refungible.rs
@@ -341,7 +341,9 @@
 			ERC165Call(_, _) => None,
 
 			// Not sponsored
-			BurnFrom { .. } | BurnFromCross { .. } | Repartition { .. } => None,
+			AllowanceCross { .. } | BurnFrom { .. } | BurnFromCross { .. } | Repartition { .. } => {
+				None
+			}
 
 			TransferCross { .. } | TransferFromCross { .. } => {
 				let RefungibleTokenHandle(handle, token_id) = token;
modifiedtests/src/eth/abi/fungible.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/fungible.json
+++ b/tests/src/eth/abi/fungible.json
@@ -101,6 +101,32 @@
           { "internalType": "uint256", "name": "sub", "type": "uint256" }
         ],
         "internalType": "struct CrossAddress",
+        "name": "owner",
+        "type": "tuple"
+      },
+      {
+        "components": [
+          { "internalType": "address", "name": "eth", "type": "address" },
+          { "internalType": "uint256", "name": "sub", "type": "uint256" }
+        ],
+        "internalType": "struct CrossAddress",
+        "name": "spender",
+        "type": "tuple"
+      }
+    ],
+    "name": "allowanceCross",
+    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
+      {
+        "components": [
+          { "internalType": "address", "name": "eth", "type": "address" },
+          { "internalType": "uint256", "name": "sub", "type": "uint256" }
+        ],
+        "internalType": "struct CrossAddress",
         "name": "user",
         "type": "tuple"
       }
@@ -408,10 +434,10 @@
     "inputs": [
       {
         "components": [
-          { "internalType": "address", "name": "field_0", "type": "address" },
-          { "internalType": "uint256", "name": "field_1", "type": "uint256" }
+          { "internalType": "address", "name": "to", "type": "address" },
+          { "internalType": "uint256", "name": "amount", "type": "uint256" }
         ],
-        "internalType": "struct Tuple9[]",
+        "internalType": "struct AmountForAddress[]",
         "name": "amounts",
         "type": "tuple[]"
       }
modifiedtests/src/eth/abi/reFungibleToken.jsondiffbeforeafterboth
--- a/tests/src/eth/abi/reFungibleToken.json
+++ b/tests/src/eth/abi/reFungibleToken.json
@@ -61,6 +61,32 @@
   },
   {
     "inputs": [
+      {
+        "components": [
+          { "internalType": "address", "name": "eth", "type": "address" },
+          { "internalType": "uint256", "name": "sub", "type": "uint256" }
+        ],
+        "internalType": "struct CrossAddress",
+        "name": "owner",
+        "type": "tuple"
+      },
+      {
+        "components": [
+          { "internalType": "address", "name": "eth", "type": "address" },
+          { "internalType": "uint256", "name": "sub", "type": "uint256" }
+        ],
+        "internalType": "struct CrossAddress",
+        "name": "spender",
+        "type": "tuple"
+      }
+    ],
+    "name": "allowanceCross",
+    "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
+    "stateMutability": "view",
+    "type": "function"
+  },
+  {
+    "inputs": [
       { "internalType": "address", "name": "spender", "type": "address" },
       { "internalType": "uint256", "name": "amount", "type": "uint256" }
     ],
modifiedtests/src/eth/api/UniqueFungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -353,8 +353,16 @@
 	bytes value;
 }
 
-/// @dev the ERC-165 identifier for this interface is 0x65789571
+/// @dev the ERC-165 identifier for this interface is 0x85d7dea6
 interface ERC20UniqueExtensions is Dummy, ERC165 {
+	/// @dev Function to check the amount of tokens that an owner allowed to a spender.
+	/// @param owner crossAddress The address which owns the funds.
+	/// @param spender crossAddress The address which will spend the funds.
+	/// @return A uint256 specifying the amount of tokens still available for the spender.
+	/// @dev EVM selector for this function is: 0xe0af4bd7,
+	///  or in textual repr: allowanceCross((address,uint256),(address,uint256))
+	function allowanceCross(CrossAddress memory owner, CrossAddress memory spender) external view returns (uint256);
+
 	/// @notice A description for the collection.
 	/// @dev EVM selector for this function is: 0x7284e416,
 	///  or in textual repr: description()
@@ -390,7 +398,7 @@
 	/// @param amounts array of pairs of account address and amount
 	/// @dev EVM selector for this function is: 0x1acf2d55,
 	///  or in textual repr: mintBulk((address,uint256)[])
-	function mintBulk(Tuple9[] memory amounts) external returns (bool);
+	function mintBulk(AmountForAddress[] memory amounts) external returns (bool);
 
 	/// @dev EVM selector for this function is: 0x2ada85ff,
 	///  or in textual repr: transferCross((address,uint256),uint256)
@@ -410,10 +418,9 @@
 	function collectionHelperAddress() external view returns (address);
 }
 
-/// @dev anonymous struct
-struct Tuple9 {
-	address field_0;
-	uint256 field_1;
+struct AmountForAddress {
+	address to;
+	uint256 amount;
 }
 
 /// @dev the ERC-165 identifier for this interface is 0x40c10f19
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -644,7 +644,7 @@
 	// /// @param tokens array of pairs of token ID and token URI for minted tokens
 	// /// @dev EVM selector for this function is: 0x36543006,
 	// ///  or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
-	// function mintBulkWithTokenURI(address to, Tuple13[] memory tokens) external returns (bool);
+	// function mintBulkWithTokenURI(address to, TokenUri[] memory tokens) external returns (bool);
 
 	/// @notice Function to mint a token.
 	/// @param to The new owner crossAccountId
@@ -660,10 +660,12 @@
 	function collectionHelperAddress() external view returns (address);
 }
 
-/// @dev anonymous struct
-struct Tuple13 {
-	uint256 field_0;
-	string field_1;
+/// Data for creation token with uri.
+struct TokenUri {
+	/// Id of new token.
+	uint256 id;
+	/// Uri of new token.
+	string uri;
 }
 
 /// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -638,7 +638,7 @@
 	// /// @param tokens array of pairs of token ID and token URI for minted tokens
 	// /// @dev EVM selector for this function is: 0x36543006,
 	// ///  or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
-	// function mintBulkWithTokenURI(address to, Tuple12[] memory tokens) external returns (bool);
+	// function mintBulkWithTokenURI(address to, TokenUri[] memory tokens) external returns (bool);
 
 	/// @notice Function to mint a token.
 	/// @param to The new owner crossAccountId
@@ -661,10 +661,12 @@
 	function collectionHelperAddress() external view returns (address);
 }
 
-/// @dev anonymous struct
-struct Tuple12 {
-	uint256 field_0;
-	string field_1;
+/// Data for creation token with uri.
+struct TokenUri {
+	/// Id of new token.
+	uint256 id;
+	/// Uri of new token.
+	string uri;
 }
 
 /// @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
modifiedtests/src/eth/api/UniqueRefungibleToken.soldiffbeforeafterboth
--- a/tests/src/eth/api/UniqueRefungibleToken.sol
+++ b/tests/src/eth/api/UniqueRefungibleToken.sol
@@ -23,8 +23,16 @@
 	function parentTokenId() external view returns (uint256);
 }
 
-/// @dev the ERC-165 identifier for this interface is 0xe17a7d2b
+/// @dev the ERC-165 identifier for this interface is 0x01d536fc
 interface ERC20UniqueExtensions is Dummy, ERC165 {
+	/// @dev Function to check the amount of tokens that an owner allowed to a spender.
+	/// @param owner crossAddress The address which owns the funds.
+	/// @param spender crossAddress The address which will spend the funds.
+	/// @return A uint256 specifying the amount of tokens still available for the spender.
+	/// @dev EVM selector for this function is: 0xe0af4bd7,
+	///  or in textual repr: allowanceCross((address,uint256),(address,uint256))
+	function allowanceCross(CrossAddress memory owner, CrossAddress memory spender) external view returns (uint256);
+
 	// /// @dev Function that burns an amount of the token of a given account,
 	// /// deducting from the sender's allowance for said account.
 	// /// @param from The account whose tokens will be burnt.
modifiedtests/src/eth/fungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -134,6 +134,12 @@
       const allowance = await contract.methods.allowance(owner, spender).call();
       expect(+allowance).to.equal(100);
     }
+    {
+      const ownerCross = helper.ethCrossAccount.fromAddress(owner);
+      const spenderCross = helper.ethCrossAccount.fromAddress(spender);
+      const allowance = await contract.methods.allowanceCross(ownerCross, spenderCross).call();
+      expect(+allowance).to.equal(100);
+    }
   });
 
   itEth('Can perform approveCross()', async ({helper}) => {
modifiedtests/src/eth/proxy/UniqueNFTProxy.soldiffbeforeafterboth
--- a/tests/src/eth/proxy/UniqueNFTProxy.sol
+++ b/tests/src/eth/proxy/UniqueNFTProxy.sol
@@ -168,7 +168,7 @@
         return proxied.mintBulk(to, tokenIds);
     }
 
-    function mintBulkWithTokenURI(address to, Tuple6[] memory tokens)
+    function mintBulkWithTokenURI(address to, TokenUri[] memory tokens)
         external
         override
         returns (bool)
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -219,8 +219,16 @@
       await rftToken.methods.approve(operator, 15n).send({from: owner});
       await contract.methods.setApprovalForAll(operator, true).send({from: owner});
       await rftToken.methods.burnFrom(owner, 10n).send({from: operator});
+    }
+    {
       const allowance = await rftToken.methods.allowance(owner, operator).call();
-      expect(allowance).to.be.equal('5');
+      expect(+allowance).to.be.equal(5);
+    }
+    {
+      const ownerCross = helper.ethCrossAccount.fromAddress(owner);
+      const operatorCross = helper.ethCrossAccount.fromAddress(operator);
+      const allowance = await rftToken.methods.allowanceCross(ownerCross, operatorCross).call();
+      expect(+allowance).to.equal(5);
     }
   });