git.delta.rocks / unique-network / refs/commits / 12f11314c194

difftreelog

style fix formatting

Yaroslav Bolyukin2023-02-05parent: #586a87e.patch.diff
in: master

4 files changed

modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -70,46 +70,15 @@
 };
 use pallet_evm::GasWeightMapping;
 use up_data_structs::{
-	AccessMode,
-	COLLECTION_NUMBER_LIMIT,
-	Collection,
-	RpcCollection,
-	CollectionFlags,
-	RpcCollectionFlags,
-	CollectionId,
-	CreateItemData,
-	MAX_TOKEN_PREFIX_LENGTH,
-	COLLECTION_ADMINS_LIMIT,
-	TokenId,
-	TokenChild,
-	CollectionStats,
-	MAX_TOKEN_OWNERSHIP,
-	CollectionMode,
-	NFT_SPONSOR_TRANSFER_TIMEOUT,
-	FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
-	REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
-	MAX_SPONSOR_TIMEOUT,
-	CUSTOM_DATA_LIMIT,
-	CollectionLimits,
-	CreateCollectionData,
-	SponsorshipState,
-	CreateItemExData,
-	SponsoringRateLimit,
-	budget::Budget,
-	PhantomType,
-	Property,
-	Properties,
-	PropertiesPermissionMap,
-	PropertyKey,
-	PropertyValue,
-	PropertyPermission,
-	PropertiesError,
-	TokenOwnerError,
-	PropertyKeyPermission,
-	TokenData,
-	TrySetProperty,
-	PropertyScope,
-	CollectionPermissions,
+	AccessMode, COLLECTION_NUMBER_LIMIT, Collection, RpcCollection, CollectionFlags,
+	RpcCollectionFlags, CollectionId, CreateItemData, MAX_TOKEN_PREFIX_LENGTH,
+	COLLECTION_ADMINS_LIMIT, TokenId, TokenChild, CollectionStats, MAX_TOKEN_OWNERSHIP,
+	CollectionMode, NFT_SPONSOR_TRANSFER_TIMEOUT, FUNGIBLE_SPONSOR_TRANSFER_TIMEOUT,
+	REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, MAX_SPONSOR_TIMEOUT, CUSTOM_DATA_LIMIT, CollectionLimits,
+	CreateCollectionData, SponsorshipState, CreateItemExData, SponsoringRateLimit, budget::Budget,
+	PhantomType, Property, Properties, PropertiesPermissionMap, PropertyKey, PropertyValue,
+	PropertyPermission, PropertiesError, TokenOwnerError, PropertyKeyPermission, TokenData,
+	TrySetProperty, PropertyScope, CollectionPermissions,
 };
 use up_pov_estimate_rpc::PovInfo;
 
modifiedpallets/fungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -38,8 +38,8 @@
 use sp_core::{U256, Get};
 
 use crate::{
-	Allowance, Balance, Config, FungibleHandle, Pallet, TotalSupply,
-	SelfWeightOf, weights::WeightInfo,	
+	Allowance, Balance, Config, FungibleHandle, Pallet, TotalSupply, SelfWeightOf,
+	weights::WeightInfo,
 };
 
 frontier_contract! {
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -48,8 +48,8 @@
 };
 
 use crate::{
-	AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle, 
-	TokenProperties, TokensMinted, TotalSupply, SelfWeightOf, weights::WeightInfo,
+	AccountBalance, Balance, Config, CreateItemData, Pallet, RefungibleHandle, TokenProperties,
+	TokensMinted, TotalSupply, SelfWeightOf, weights::WeightInfo,
 };
 
 frontier_contract! {
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::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};28use pallet_common::{29	erc::{CommonEvmHandler, PrecompileResult},30	eth::{collection_id_to_address, CrossAddress},31	CommonWeightInfo,32};33use pallet_evm::{account::CrossAccountId, PrecompileHandle};34use pallet_evm_coder_substrate::{35	call, dispatch_to_evm, WithRecorder, frontier_contract,36	execution::{Result, PreDispatch},37};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::{Allowance, Balance, Config, Pallet, RefungibleHandle, TotalSupply, common::CommonWeights, SelfWeightOf, weights::WeightInfo};4445/// Refungible token handle contains information about token's collection and id46///47/// RefungibleTokenHandle doesn't check token's existance upon creation48pub struct RefungibleTokenHandle<T: Config>(pub RefungibleHandle<T>, pub TokenId);4950frontier_contract! {51	macro_rules! RefungibleTokenHandle_result {...}52	impl<T: Config> Contract for RefungibleTokenHandle<T> {...}53}5455#[solidity_interface(name = ERC1633, enum(derive(PreDispatch)), enum_attr(weight))]56impl<T: Config> RefungibleTokenHandle<T> {57	fn parent_token(&self) -> Address {58		collection_id_to_address(self.id)59	}6061	fn parent_token_id(&self) -> U256 {62		self.1.into()63	}64}6566#[derive(ToLog)]67pub enum ERC20Events {68	/// @dev This event is emitted when the amount of tokens (value) is sent69	/// from the from address to the to address. In the case of minting new70	/// tokens, the transfer is usually from the 0 address while in the case71	/// of burning tokens the transfer is to 0.72	Transfer {73		#[indexed]74		from: Address,75		#[indexed]76		to: Address,77		value: U256,78	},79	/// @dev This event is emitted when the amount of tokens (value) is approved80	/// by the owner to be used by the spender.81	Approval {82		#[indexed]83		owner: Address,84		#[indexed]85		spender: Address,86		value: U256,87	},88}8990/// @title Standard ERC20 token91///92/// @dev Implementation of the basic standard token.93/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md94#[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight))]95impl<T: Config> RefungibleTokenHandle<T> {96	/// @return the name of the token.97	fn name(&self) -> String {98		decode_utf16(self.name.iter().copied())99			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))100			.collect::<String>()101	}102103	/// @return the symbol of the token.104	fn symbol(&self) -> String {105		String::from_utf8_lossy(&self.token_prefix).into()106	}107108	/// @dev Total number of tokens in existence109	fn total_supply(&self) -> Result<U256> {110		self.consume_store_reads(1)?;111		Ok(<TotalSupply<T>>::get((self.id, self.1)).into())112	}113114	/// @dev Not supported115	fn decimals(&self) -> Result<u8> {116		// Decimals aren't supported for refungible tokens117		Ok(0)118	}119120	/// @dev Gets the balance of the specified address.121	/// @param owner The address to query the balance of.122	/// @return An uint256 representing the amount owned by the passed address.123	fn balance_of(&self, owner: Address) -> Result<U256> {124		self.consume_store_reads(1)?;125		let owner = T::CrossAccountId::from_eth(owner);126		let balance = <Balance<T>>::get((self.id, self.1, owner));127		Ok(balance.into())128	}129130	/// @dev Transfer token for a specified address131	/// @param to The address to transfer to.132	/// @param amount The amount to be transferred.133	#[weight(<CommonWeights<T>>::transfer())]134	fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {135		let caller = T::CrossAccountId::from_eth(caller);136		let to = T::CrossAccountId::from_eth(to);137		let amount = amount.try_into().map_err(|_| "amount overflow")?;138		let budget = self139			.recorder140			.weight_calls_budget(<StructureWeight<T>>::find_parent());141142		<Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)143			.map_err(dispatch_to_evm::<T>)?;144		Ok(true)145	}146147	/// @dev Transfer tokens from one address to another148	/// @param from address The address which you want to send tokens from149	/// @param to address The address which you want to transfer to150	/// @param amount uint256 the amount of tokens to be transferred151	#[weight(<CommonWeights<T>>::transfer_from())]152	fn transfer_from(153		&mut self,154		caller: Caller,155		from: Address,156		to: Address,157		amount: U256,158	) -> Result<bool> {159		let caller = T::CrossAccountId::from_eth(caller);160		let from = T::CrossAccountId::from_eth(from);161		let to = T::CrossAccountId::from_eth(to);162		let amount = amount.try_into().map_err(|_| "amount overflow")?;163		let budget = self164			.recorder165			.weight_calls_budget(<StructureWeight<T>>::find_parent());166167		<Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)168			.map_err(dispatch_to_evm::<T>)?;169		Ok(true)170	}171172	/// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.173	/// Beware that changing an allowance with this method brings the risk that someone may use both the old174	/// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this175	/// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:176	/// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729177	/// @param spender The address which will spend the funds.178	/// @param amount The amount of tokens to be spent.179	#[weight(<SelfWeightOf<T>>::approve())]180	fn approve(&mut self, caller: Caller, spender: Address, amount: U256) -> Result<bool> {181		let caller = T::CrossAccountId::from_eth(caller);182		let spender = T::CrossAccountId::from_eth(spender);183		let amount = amount.try_into().map_err(|_| "amount overflow")?;184185		<Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)186			.map_err(dispatch_to_evm::<T>)?;187		Ok(true)188	}189190	/// @dev Function to check the amount of tokens that an owner allowed to a spender.191	/// @param owner address The address which owns the funds.192	/// @param spender address The address which will spend the funds.193	/// @return A uint256 specifying the amount of tokens still available for the spender.194	fn allowance(&self, owner: Address, spender: Address) -> Result<U256> {195		self.consume_store_reads(1)?;196		let owner = T::CrossAccountId::from_eth(owner);197		let spender = T::CrossAccountId::from_eth(spender);198199		Ok(<Allowance<T>>::get((self.id, self.1, owner, spender)).into())200	}201}202203#[solidity_interface(name = ERC20UniqueExtensions, enum(derive(PreDispatch)), enum_attr(weight))]204impl<T: Config> RefungibleTokenHandle<T>205where206	T::AccountId: From<[u8; 32]>,207{208	/// @dev Function to check the amount of tokens that an owner allowed to a spender.209	/// @param owner crossAddress The address which owns the funds.210	/// @param spender crossAddress The address which will spend the funds.211	/// @return A uint256 specifying the amount of tokens still available for the spender.212	fn allowance_cross(&self, owner: CrossAddress, spender: CrossAddress) -> Result<U256> {213		let owner = owner.into_sub_cross_account::<T>()?;214		let spender = spender.into_sub_cross_account::<T>()?;215216		Ok(<Allowance<T>>::get((self.id, self.1, owner, spender)).into())217	}218219	/// @dev Function that burns an amount of the token of a given account,220	/// deducting from the sender's allowance for said account.221	/// @param from The account whose tokens will be burnt.222	/// @param amount The amount that will be burnt.223	#[weight(<SelfWeightOf<T>>::burn_from())]224	#[solidity(hide)]225	fn burn_from(&mut self, caller: Caller, from: Address, amount: U256) -> Result<bool> {226		let caller = T::CrossAccountId::from_eth(caller);227		let from = T::CrossAccountId::from_eth(from);228		let amount = amount.try_into().map_err(|_| "amount overflow")?;229		let budget = self230			.recorder231			.weight_calls_budget(<StructureWeight<T>>::find_parent());232233		<Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)234			.map_err(dispatch_to_evm::<T>)?;235		Ok(true)236	}237238	/// @dev Function that burns an amount of the token of a given account,239	/// deducting from the sender's allowance for said account.240	/// @param from The account whose tokens will be burnt.241	/// @param amount The amount that will be burnt.242	#[weight(<SelfWeightOf<T>>::burn_from())]243	fn burn_from_cross(244		&mut self,245		caller: Caller,246		from: CrossAddress,247		amount: U256,248	) -> Result<bool> {249		let caller = T::CrossAccountId::from_eth(caller);250		let from = from.into_sub_cross_account::<T>()?;251		let amount = amount.try_into().map_err(|_| "amount overflow")?;252		let budget = self253			.recorder254			.weight_calls_budget(<StructureWeight<T>>::find_parent());255256		<Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)257			.map_err(dispatch_to_evm::<T>)?;258		Ok(true)259	}260261	/// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.262	/// Beware that changing an allowance with this method brings the risk that someone may use both the old263	/// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this264	/// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:265	/// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729266	/// @param spender The crossaccount which will spend the funds.267	/// @param amount The amount of tokens to be spent.268	#[weight(<SelfWeightOf<T>>::approve())]269	fn approve_cross(270		&mut self,271		caller: Caller,272		spender: CrossAddress,273		amount: U256,274	) -> Result<bool> {275		let caller = T::CrossAccountId::from_eth(caller);276		let spender = spender.into_sub_cross_account::<T>()?;277		let amount = amount.try_into().map_err(|_| "amount overflow")?;278279		<Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)280			.map_err(dispatch_to_evm::<T>)?;281		Ok(true)282	}283	/// @dev Function that changes total amount of the tokens.284	///  Throws if `msg.sender` doesn't owns all of the tokens.285	/// @param amount New total amount of the tokens.286	#[weight(<SelfWeightOf<T>>::repartition_item())]287	fn repartition(&mut self, caller: Caller, amount: U256) -> Result<bool> {288		let caller = T::CrossAccountId::from_eth(caller);289		let amount = amount.try_into().map_err(|_| "amount overflow")?;290291		<Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;292		Ok(true)293	}294295	/// @dev Transfer token for a specified address296	/// @param to The crossaccount to transfer to.297	/// @param amount The amount to be transferred.298	#[weight(<CommonWeights<T>>::transfer())]299	fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {300		let caller = T::CrossAccountId::from_eth(caller);301		let to = to.into_sub_cross_account::<T>()?;302		let amount = amount.try_into().map_err(|_| "amount overflow")?;303		let budget = self304			.recorder305			.weight_calls_budget(<StructureWeight<T>>::find_parent());306307		<Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)308			.map_err(dispatch_to_evm::<T>)?;309		Ok(true)310	}311312	/// @dev Transfer tokens from one address to another313	/// @param from The address which you want to send tokens from314	/// @param to The address which you want to transfer to315	/// @param amount the amount of tokens to be transferred316	#[weight(<CommonWeights<T>>::transfer_from())]317	fn transfer_from_cross(318		&mut self,319		caller: Caller,320		from: CrossAddress,321		to: CrossAddress,322		amount: U256,323	) -> Result<bool> {324		let caller = T::CrossAccountId::from_eth(caller);325		let from = from.into_sub_cross_account::<T>()?;326		let to = to.into_sub_cross_account::<T>()?;327		let amount = amount.try_into().map_err(|_| "amount overflow")?;328		let budget = self329			.recorder330			.weight_calls_budget(<StructureWeight<T>>::find_parent());331332		<Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)333			.map_err(dispatch_to_evm::<T>)?;334		Ok(true)335	}336}337338impl<T: Config> RefungibleTokenHandle<T> {339	pub fn into_inner(self) -> RefungibleHandle<T> {340		self.0341	}342	pub fn common_mut(&mut self) -> &mut RefungibleHandle<T> {343		&mut self.0344	}345}346347impl<T: Config> WithRecorder<T> for RefungibleTokenHandle<T> {348	fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {349		self.0.recorder()350	}351	fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {352		self.0.into_recorder()353	}354}355356impl<T: Config> Deref for RefungibleTokenHandle<T> {357	type Target = RefungibleHandle<T>;358359	fn deref(&self) -> &Self::Target {360		&self.0361	}362}363364#[solidity_interface(365	name = UniqueRefungibleToken,366	is(ERC20, ERC20UniqueExtensions, ERC1633),367	enum(derive(PreDispatch)),368)]369impl<T: Config> RefungibleTokenHandle<T> where T::AccountId: From<[u8; 32]> {}370371generate_stubgen!(gen_impl, UniqueRefungibleTokenCall<()>, true);372generate_stubgen!(gen_iface, UniqueRefungibleTokenCall<()>, false);373374impl<T: Config> CommonEvmHandler for RefungibleTokenHandle<T>375where376	T::AccountId: From<[u8; 32]>,377{378	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungibleToken.raw");379380	fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {381		call::<T, UniqueRefungibleTokenCall<T>, _, _>(handle, self)382	}383}
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::{abi::AbiType, ToLog, generate_stubgen, solidity_interface, types::*};28use pallet_common::{29	erc::{CommonEvmHandler, PrecompileResult},30	eth::{collection_id_to_address, CrossAddress},31	CommonWeightInfo,32};33use pallet_evm::{account::CrossAccountId, PrecompileHandle};34use pallet_evm_coder_substrate::{35	call, dispatch_to_evm, WithRecorder, frontier_contract,36	execution::{Result, PreDispatch},37};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, Config, Pallet, RefungibleHandle, TotalSupply, common::CommonWeights,45	SelfWeightOf, 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);5253frontier_contract! {54	macro_rules! RefungibleTokenHandle_result {...}55	impl<T: Config> Contract for RefungibleTokenHandle<T> {...}56}5758#[solidity_interface(name = ERC1633, enum(derive(PreDispatch)), enum_attr(weight))]59impl<T: Config> RefungibleTokenHandle<T> {60	fn parent_token(&self) -> Address {61		collection_id_to_address(self.id)62	}6364	fn parent_token_id(&self) -> U256 {65		self.1.into()66	}67}6869#[derive(ToLog)]70pub enum ERC20Events {71	/// @dev This event is emitted when the amount of tokens (value) is sent72	/// from the from address to the to address. In the case of minting new73	/// tokens, the transfer is usually from the 0 address while in the case74	/// of burning tokens the transfer is to 0.75	Transfer {76		#[indexed]77		from: Address,78		#[indexed]79		to: Address,80		value: U256,81	},82	/// @dev This event is emitted when the amount of tokens (value) is approved83	/// by the owner to be used by the spender.84	Approval {85		#[indexed]86		owner: Address,87		#[indexed]88		spender: Address,89		value: U256,90	},91}9293/// @title Standard ERC20 token94///95/// @dev Implementation of the basic standard token.96/// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md97#[solidity_interface(name = ERC20, events(ERC20Events), enum(derive(PreDispatch)), enum_attr(weight))]98impl<T: Config> RefungibleTokenHandle<T> {99	/// @return the name of the token.100	fn name(&self) -> String {101		decode_utf16(self.name.iter().copied())102			.map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))103			.collect::<String>()104	}105106	/// @return the symbol of the token.107	fn symbol(&self) -> String {108		String::from_utf8_lossy(&self.token_prefix).into()109	}110111	/// @dev Total number of tokens in existence112	fn total_supply(&self) -> Result<U256> {113		self.consume_store_reads(1)?;114		Ok(<TotalSupply<T>>::get((self.id, self.1)).into())115	}116117	/// @dev Not supported118	fn decimals(&self) -> Result<u8> {119		// Decimals aren't supported for refungible tokens120		Ok(0)121	}122123	/// @dev Gets the balance of the specified address.124	/// @param owner The address to query the balance of.125	/// @return An uint256 representing the amount owned by the passed address.126	fn balance_of(&self, owner: Address) -> Result<U256> {127		self.consume_store_reads(1)?;128		let owner = T::CrossAccountId::from_eth(owner);129		let balance = <Balance<T>>::get((self.id, self.1, owner));130		Ok(balance.into())131	}132133	/// @dev Transfer token for a specified address134	/// @param to The address to transfer to.135	/// @param amount The amount to be transferred.136	#[weight(<CommonWeights<T>>::transfer())]137	fn transfer(&mut self, caller: Caller, to: Address, amount: U256) -> Result<bool> {138		let caller = T::CrossAccountId::from_eth(caller);139		let to = T::CrossAccountId::from_eth(to);140		let amount = amount.try_into().map_err(|_| "amount overflow")?;141		let budget = self142			.recorder143			.weight_calls_budget(<StructureWeight<T>>::find_parent());144145		<Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)146			.map_err(dispatch_to_evm::<T>)?;147		Ok(true)148	}149150	/// @dev Transfer tokens from one address to another151	/// @param from address The address which you want to send tokens from152	/// @param to address The address which you want to transfer to153	/// @param amount uint256 the amount of tokens to be transferred154	#[weight(<CommonWeights<T>>::transfer_from())]155	fn transfer_from(156		&mut self,157		caller: Caller,158		from: Address,159		to: Address,160		amount: U256,161	) -> Result<bool> {162		let caller = T::CrossAccountId::from_eth(caller);163		let from = T::CrossAccountId::from_eth(from);164		let to = T::CrossAccountId::from_eth(to);165		let amount = amount.try_into().map_err(|_| "amount overflow")?;166		let budget = self167			.recorder168			.weight_calls_budget(<StructureWeight<T>>::find_parent());169170		<Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)171			.map_err(dispatch_to_evm::<T>)?;172		Ok(true)173	}174175	/// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.176	/// Beware that changing an allowance with this method brings the risk that someone may use both the old177	/// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this178	/// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:179	/// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729180	/// @param spender The address which will spend the funds.181	/// @param amount The amount of tokens to be spent.182	#[weight(<SelfWeightOf<T>>::approve())]183	fn approve(&mut self, caller: Caller, spender: Address, amount: U256) -> Result<bool> {184		let caller = T::CrossAccountId::from_eth(caller);185		let spender = T::CrossAccountId::from_eth(spender);186		let amount = amount.try_into().map_err(|_| "amount overflow")?;187188		<Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)189			.map_err(dispatch_to_evm::<T>)?;190		Ok(true)191	}192193	/// @dev Function to check the amount of tokens that an owner allowed to a spender.194	/// @param owner address The address which owns the funds.195	/// @param spender address The address which will spend the funds.196	/// @return A uint256 specifying the amount of tokens still available for the spender.197	fn allowance(&self, owner: Address, spender: Address) -> Result<U256> {198		self.consume_store_reads(1)?;199		let owner = T::CrossAccountId::from_eth(owner);200		let spender = T::CrossAccountId::from_eth(spender);201202		Ok(<Allowance<T>>::get((self.id, self.1, owner, spender)).into())203	}204}205206#[solidity_interface(name = ERC20UniqueExtensions, enum(derive(PreDispatch)), enum_attr(weight))]207impl<T: Config> RefungibleTokenHandle<T>208where209	T::AccountId: From<[u8; 32]>,210{211	/// @dev Function to check the amount of tokens that an owner allowed to a spender.212	/// @param owner crossAddress The address which owns the funds.213	/// @param spender crossAddress The address which will spend the funds.214	/// @return A uint256 specifying the amount of tokens still available for the spender.215	fn allowance_cross(&self, owner: CrossAddress, spender: CrossAddress) -> Result<U256> {216		let owner = owner.into_sub_cross_account::<T>()?;217		let spender = spender.into_sub_cross_account::<T>()?;218219		Ok(<Allowance<T>>::get((self.id, self.1, owner, spender)).into())220	}221222	/// @dev Function that burns an amount of the token of a given account,223	/// deducting from the sender's allowance for said account.224	/// @param from The account whose tokens will be burnt.225	/// @param amount The amount that will be burnt.226	#[weight(<SelfWeightOf<T>>::burn_from())]227	#[solidity(hide)]228	fn burn_from(&mut self, caller: Caller, from: Address, amount: U256) -> Result<bool> {229		let caller = T::CrossAccountId::from_eth(caller);230		let from = T::CrossAccountId::from_eth(from);231		let amount = amount.try_into().map_err(|_| "amount overflow")?;232		let budget = self233			.recorder234			.weight_calls_budget(<StructureWeight<T>>::find_parent());235236		<Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)237			.map_err(dispatch_to_evm::<T>)?;238		Ok(true)239	}240241	/// @dev Function that burns an amount of the token of a given account,242	/// deducting from the sender's allowance for said account.243	/// @param from The account whose tokens will be burnt.244	/// @param amount The amount that will be burnt.245	#[weight(<SelfWeightOf<T>>::burn_from())]246	fn burn_from_cross(247		&mut self,248		caller: Caller,249		from: CrossAddress,250		amount: U256,251	) -> Result<bool> {252		let caller = T::CrossAccountId::from_eth(caller);253		let from = from.into_sub_cross_account::<T>()?;254		let amount = amount.try_into().map_err(|_| "amount overflow")?;255		let budget = self256			.recorder257			.weight_calls_budget(<StructureWeight<T>>::find_parent());258259		<Pallet<T>>::burn_from(self, &caller, &from, self.1, amount, &budget)260			.map_err(dispatch_to_evm::<T>)?;261		Ok(true)262	}263264	/// @dev Approve the passed address to spend the specified amount of tokens on behalf of `msg.sender`.265	/// Beware that changing an allowance with this method brings the risk that someone may use both the old266	/// and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this267	/// race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:268	/// https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729269	/// @param spender The crossaccount which will spend the funds.270	/// @param amount The amount of tokens to be spent.271	#[weight(<SelfWeightOf<T>>::approve())]272	fn approve_cross(273		&mut self,274		caller: Caller,275		spender: CrossAddress,276		amount: U256,277	) -> Result<bool> {278		let caller = T::CrossAccountId::from_eth(caller);279		let spender = spender.into_sub_cross_account::<T>()?;280		let amount = amount.try_into().map_err(|_| "amount overflow")?;281282		<Pallet<T>>::set_allowance(self, &caller, &spender, self.1, amount)283			.map_err(dispatch_to_evm::<T>)?;284		Ok(true)285	}286	/// @dev Function that changes total amount of the tokens.287	///  Throws if `msg.sender` doesn't owns all of the tokens.288	/// @param amount New total amount of the tokens.289	#[weight(<SelfWeightOf<T>>::repartition_item())]290	fn repartition(&mut self, caller: Caller, amount: U256) -> Result<bool> {291		let caller = T::CrossAccountId::from_eth(caller);292		let amount = amount.try_into().map_err(|_| "amount overflow")?;293294		<Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;295		Ok(true)296	}297298	/// @dev Transfer token for a specified address299	/// @param to The crossaccount to transfer to.300	/// @param amount The amount to be transferred.301	#[weight(<CommonWeights<T>>::transfer())]302	fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {303		let caller = T::CrossAccountId::from_eth(caller);304		let to = to.into_sub_cross_account::<T>()?;305		let amount = amount.try_into().map_err(|_| "amount overflow")?;306		let budget = self307			.recorder308			.weight_calls_budget(<StructureWeight<T>>::find_parent());309310		<Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)311			.map_err(dispatch_to_evm::<T>)?;312		Ok(true)313	}314315	/// @dev Transfer tokens from one address to another316	/// @param from The address which you want to send tokens from317	/// @param to The address which you want to transfer to318	/// @param amount the amount of tokens to be transferred319	#[weight(<CommonWeights<T>>::transfer_from())]320	fn transfer_from_cross(321		&mut self,322		caller: Caller,323		from: CrossAddress,324		to: CrossAddress,325		amount: U256,326	) -> Result<bool> {327		let caller = T::CrossAccountId::from_eth(caller);328		let from = from.into_sub_cross_account::<T>()?;329		let to = to.into_sub_cross_account::<T>()?;330		let amount = amount.try_into().map_err(|_| "amount overflow")?;331		let budget = self332			.recorder333			.weight_calls_budget(<StructureWeight<T>>::find_parent());334335		<Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)336			.map_err(dispatch_to_evm::<T>)?;337		Ok(true)338	}339}340341impl<T: Config> RefungibleTokenHandle<T> {342	pub fn into_inner(self) -> RefungibleHandle<T> {343		self.0344	}345	pub fn common_mut(&mut self) -> &mut RefungibleHandle<T> {346		&mut self.0347	}348}349350impl<T: Config> WithRecorder<T> for RefungibleTokenHandle<T> {351	fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {352		self.0.recorder()353	}354	fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {355		self.0.into_recorder()356	}357}358359impl<T: Config> Deref for RefungibleTokenHandle<T> {360	type Target = RefungibleHandle<T>;361362	fn deref(&self) -> &Self::Target {363		&self.0364	}365}366367#[solidity_interface(368	name = UniqueRefungibleToken,369	is(ERC20, ERC20UniqueExtensions, ERC1633),370	enum(derive(PreDispatch)),371)]372impl<T: Config> RefungibleTokenHandle<T> where T::AccountId: From<[u8; 32]> {}373374generate_stubgen!(gen_impl, UniqueRefungibleTokenCall<()>, true);375generate_stubgen!(gen_iface, UniqueRefungibleTokenCall<()>, false);376377impl<T: Config> CommonEvmHandler for RefungibleTokenHandle<T>378where379	T::AccountId: From<[u8; 32]>,380{381	const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungibleToken.raw");382383	fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {384		call::<T, UniqueRefungibleTokenCall<T>, _, _>(handle, self)385	}386}