difftreelog
Merge pull request #919 from UniqueNetwork/feature/crossBalanceOf
in: master
26 files changed
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -327,6 +327,15 @@
fn collection_helper_address(&self) -> Result<Address> {
Ok(T::ContractAddress::get())
}
+
+ /// @notice Balance of account
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of fingibles owned by `owner`, possibly zero
+ fn balance_of_cross(&self, owner: CrossAddress) -> Result<U256> {
+ self.consume_store_reads(1)?;
+ let balance = <Balance<T>>::get((self.id, owner.into_sub_cross_account::<T>()?));
+ Ok(balance.into())
+ }
}
#[solidity_interface(
pallets/fungible/src/stubs/UniqueFungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/fungible/src/stubs/UniqueFungible.soldiffbeforeafterboth--- a/pallets/fungible/src/stubs/UniqueFungible.sol
+++ b/pallets/fungible/src/stubs/UniqueFungible.sol
@@ -511,7 +511,7 @@
bytes value;
}
-/// @dev the ERC-165 identifier for this interface is 0x85d7dea6
+/// @dev the ERC-165 identifier for this interface is 0x69d14d3e
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.
@@ -630,6 +630,18 @@
dummy;
return 0x0000000000000000000000000000000000000000;
}
+
+ /// @notice Balance of account
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of fingibles owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0xec069398,
+ /// or in textual repr: balanceOfCross((address,uint256))
+ function balanceOfCross(CrossAddress memory owner) public view returns (uint256) {
+ require(false, stub_error);
+ owner;
+ dummy;
+ return 0;
+ }
}
struct AmountForAddress {
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -749,12 +749,29 @@
/// Returns the owner (in cross format) of the token.
///
/// @param tokenId Id for the token.
+ #[solidity(hide)]
fn cross_owner_of(&self, token_id: U256) -> Result<eth::CrossAddress> {
+ Self::owner_of_cross(&self, token_id)
+ }
+
+ /// Returns the owner (in cross format) of the token.
+ ///
+ /// @param tokenId Id for the token.
+ fn owner_of_cross(&self, token_id: U256) -> Result<eth::CrossAddress> {
Self::token_owner(&self, token_id.try_into()?)
.map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))
.map_err(|_| Error::Revert("token not found".into()))
}
+ /// @notice Count all NFTs assigned to an owner
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of NFTs owned by `owner`, possibly zero
+ fn balance_of_cross(&self, owner: eth::CrossAddress) -> Result<U256> {
+ self.consume_store_reads(1)?;
+ let balance = <AccountBalance<T>>::get((self.id, owner.into_sub_cross_account::<T>()?));
+ Ok(balance.into())
+ }
+
/// Returns the token properties.
///
/// @param tokenId Id for the token.
pallets/nonfungible/src/stubs/UniqueNFT.rawdiffbeforeafterbothbinary blob — no preview
pallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth--- a/pallets/nonfungible/src/stubs/UniqueNFT.sol
+++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol
@@ -774,7 +774,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x16de3152
+/// @dev the ERC-165 identifier for this interface is 0x307b061a
contract ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -803,18 +803,42 @@
return "";
}
+ // /// Returns the owner (in cross format) of the token.
+ // ///
+ // /// @param tokenId Id for the token.
+ // /// @dev EVM selector for this function is: 0x2b29dace,
+ // /// or in textual repr: crossOwnerOf(uint256)
+ // function crossOwnerOf(uint256 tokenId) public view returns (CrossAddress memory) {
+ // require(false, stub_error);
+ // tokenId;
+ // dummy;
+ // return CrossAddress(0x0000000000000000000000000000000000000000,0);
+ // }
+
/// Returns the owner (in cross format) of the token.
///
/// @param tokenId Id for the token.
- /// @dev EVM selector for this function is: 0x2b29dace,
- /// or in textual repr: crossOwnerOf(uint256)
- function crossOwnerOf(uint256 tokenId) public view returns (CrossAddress memory) {
+ /// @dev EVM selector for this function is: 0xcaa3a4d0,
+ /// or in textual repr: ownerOfCross(uint256)
+ function ownerOfCross(uint256 tokenId) public view returns (CrossAddress memory) {
require(false, stub_error);
tokenId;
dummy;
return CrossAddress(0x0000000000000000000000000000000000000000, 0);
}
+ /// @notice Count all NFTs assigned to an owner
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of NFTs owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0xec069398,
+ /// or in textual repr: balanceOfCross((address,uint256))
+ function balanceOfCross(CrossAddress memory owner) public view returns (uint256) {
+ require(false, stub_error);
+ owner;
+ dummy;
+ return 0;
+ }
+
/// Returns the token properties.
///
/// @param tokenId Id for the token.
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -783,7 +783,15 @@
/// Returns the owner (in cross format) of the token.
///
/// @param tokenId Id for the token.
+ #[solidity(hide)]
fn cross_owner_of(&self, token_id: U256) -> Result<eth::CrossAddress> {
+ Self::owner_of_cross(&self, token_id)
+ }
+
+ /// Returns the owner (in cross format) of the token.
+ ///
+ /// @param tokenId Id for the token.
+ fn owner_of_cross(&self, token_id: U256) -> Result<eth::CrossAddress> {
Self::token_owner(&self, token_id.try_into()?)
.map(|o| eth::CrossAddress::from_sub_cross_account::<T>(&o))
.or_else(|err| match err {
@@ -794,6 +802,15 @@
})
}
+ /// @notice Count all RFTs assigned to an owner
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of RFTs owned by `owner`, possibly zero
+ fn balance_of_cross(&self, owner: eth::CrossAddress) -> Result<U256> {
+ self.consume_store_reads(1)?;
+ let balance = <AccountBalance<T>>::get((self.id, owner.into_sub_cross_account::<T>()?));
+ Ok(balance.into())
+ }
+
/// Returns the token properties.
///
/// @param tokenId Id for the token.
pallets/refungible/src/erc_token.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617//! # 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}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 }286287 /// @notice Balance of account288 /// @param owner An cross address for whom to query the balance289 /// @return The number of fingibles owned by `owner`, possibly zero290 fn balance_of_cross(&self, owner: CrossAddress) -> Result<U256> {291 self.consume_store_reads(1)?;292 let balance = <Balance<T>>::get((self.id, self.1, owner.into_sub_cross_account::<T>()?));293 Ok(balance.into())294 }295296 /// @dev Function that changes total amount of the tokens.297 /// Throws if `msg.sender` doesn't owns all of the tokens.298 /// @param amount New total amount of the tokens.299 #[weight(<SelfWeightOf<T>>::repartition_item())]300 fn repartition(&mut self, caller: Caller, amount: U256) -> Result<bool> {301 let caller = T::CrossAccountId::from_eth(caller);302 let amount = amount.try_into().map_err(|_| "amount overflow")?;303304 <Pallet<T>>::repartition(self, &caller, self.1, amount).map_err(dispatch_to_evm::<T>)?;305 Ok(true)306 }307308 /// @dev Transfer token for a specified address309 /// @param to The crossaccount to transfer to.310 /// @param amount The amount to be transferred.311 #[weight(<CommonWeights<T>>::transfer())]312 fn transfer_cross(&mut self, caller: Caller, to: CrossAddress, amount: U256) -> Result<bool> {313 let caller = T::CrossAccountId::from_eth(caller);314 let to = to.into_sub_cross_account::<T>()?;315 let amount = amount.try_into().map_err(|_| "amount overflow")?;316 let budget = self317 .recorder318 .weight_calls_budget(<StructureWeight<T>>::find_parent());319320 <Pallet<T>>::transfer(self, &caller, &to, self.1, amount, &budget)321 .map_err(dispatch_to_evm::<T>)?;322 Ok(true)323 }324325 /// @dev Transfer tokens from one address to another326 /// @param from The address which you want to send tokens from327 /// @param to The address which you want to transfer to328 /// @param amount the amount of tokens to be transferred329 #[weight(<CommonWeights<T>>::transfer_from())]330 fn transfer_from_cross(331 &mut self,332 caller: Caller,333 from: CrossAddress,334 to: CrossAddress,335 amount: U256,336 ) -> Result<bool> {337 let caller = T::CrossAccountId::from_eth(caller);338 let from = from.into_sub_cross_account::<T>()?;339 let to = to.into_sub_cross_account::<T>()?;340 let amount = amount.try_into().map_err(|_| "amount overflow")?;341 let budget = self342 .recorder343 .weight_calls_budget(<StructureWeight<T>>::find_parent());344345 <Pallet<T>>::transfer_from(self, &caller, &from, &to, self.1, amount, &budget)346 .map_err(dispatch_to_evm::<T>)?;347 Ok(true)348 }349}350351impl<T: Config> RefungibleTokenHandle<T> {352 pub fn into_inner(self) -> RefungibleHandle<T> {353 self.0354 }355 pub fn common_mut(&mut self) -> &mut RefungibleHandle<T> {356 &mut self.0357 }358}359360impl<T: Config> WithRecorder<T> for RefungibleTokenHandle<T> {361 fn recorder(&self) -> &pallet_evm_coder_substrate::SubstrateRecorder<T> {362 self.0.recorder()363 }364 fn into_recorder(self) -> pallet_evm_coder_substrate::SubstrateRecorder<T> {365 self.0.into_recorder()366 }367}368369impl<T: Config> Deref for RefungibleTokenHandle<T> {370 type Target = RefungibleHandle<T>;371372 fn deref(&self) -> &Self::Target {373 &self.0374 }375}376377#[solidity_interface(378 name = UniqueRefungibleToken,379 is(ERC20, ERC20UniqueExtensions, ERC1633),380 enum(derive(PreDispatch)),381)]382impl<T: Config> RefungibleTokenHandle<T> where T::AccountId: From<[u8; 32]> {}383384generate_stubgen!(gen_impl, UniqueRefungibleTokenCall<()>, true);385generate_stubgen!(gen_iface, UniqueRefungibleTokenCall<()>, false);386387impl<T: Config> CommonEvmHandler for RefungibleTokenHandle<T>388where389 T::AccountId: From<[u8; 32]>,390{391 const CODE: &'static [u8] = include_bytes!("./stubs/UniqueRefungibleToken.raw");392393 fn call(self, handle: &mut impl PrecompileHandle) -> Option<PrecompileResult> {394 call::<T, UniqueRefungibleTokenCall<T>, _, _>(handle, self)395 }396}pallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungible.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungible.sol
@@ -774,7 +774,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0xb365c124
+/// @dev the ERC-165 identifier for this interface is 0x95c0f66c
contract ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -803,18 +803,42 @@
return "";
}
+ // /// Returns the owner (in cross format) of the token.
+ // ///
+ // /// @param tokenId Id for the token.
+ // /// @dev EVM selector for this function is: 0x2b29dace,
+ // /// or in textual repr: crossOwnerOf(uint256)
+ // function crossOwnerOf(uint256 tokenId) public view returns (CrossAddress memory) {
+ // require(false, stub_error);
+ // tokenId;
+ // dummy;
+ // return CrossAddress(0x0000000000000000000000000000000000000000,0);
+ // }
+
/// Returns the owner (in cross format) of the token.
///
/// @param tokenId Id for the token.
- /// @dev EVM selector for this function is: 0x2b29dace,
- /// or in textual repr: crossOwnerOf(uint256)
- function crossOwnerOf(uint256 tokenId) public view returns (CrossAddress memory) {
+ /// @dev EVM selector for this function is: 0xcaa3a4d0,
+ /// or in textual repr: ownerOfCross(uint256)
+ function ownerOfCross(uint256 tokenId) public view returns (CrossAddress memory) {
require(false, stub_error);
tokenId;
dummy;
return CrossAddress(0x0000000000000000000000000000000000000000, 0);
}
+ /// @notice Count all RFTs assigned to an owner
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of RFTs owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0xec069398,
+ /// or in textual repr: balanceOfCross((address,uint256))
+ function balanceOfCross(CrossAddress memory owner) public view returns (uint256) {
+ require(false, stub_error);
+ owner;
+ dummy;
+ return 0;
+ }
+
/// Returns the token properties.
///
/// @param tokenId Id for the token.
pallets/refungible/src/stubs/UniqueRefungibleToken.rawdiffbeforeafterbothbinary blob — no preview
pallets/refungible/src/stubs/UniqueRefungibleToken.soldiffbeforeafterboth--- a/pallets/refungible/src/stubs/UniqueRefungibleToken.sol
+++ b/pallets/refungible/src/stubs/UniqueRefungibleToken.sol
@@ -36,7 +36,7 @@
}
}
-/// @dev the ERC-165 identifier for this interface is 0x01d536fc
+/// @dev the ERC-165 identifier for this interface is 0xedd3a564
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.
@@ -97,6 +97,18 @@
return false;
}
+ /// @notice Balance of account
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of fingibles owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0xec069398,
+ /// or in textual repr: balanceOfCross((address,uint256))
+ function balanceOfCross(CrossAddress memory owner) public view returns (uint256) {
+ require(false, stub_error);
+ owner;
+ dummy;
+ return 0;
+ }
+
/// @dev Function that changes total amount of the tokens.
/// Throws if `msg.sender` doesn't owns all of the tokens.
/// @param amount New total amount of the tokens.
runtime/common/ethereum/sponsoring/refungible.rsdiffbeforeafterboth--- a/runtime/common/ethereum/sponsoring/refungible.rs
+++ b/runtime/common/ethereum/sponsoring/refungible.rs
@@ -227,6 +227,8 @@
| Symbol
| Description
| CrossOwnerOf { .. }
+ | OwnerOfCross { .. }
+ | BalanceOfCross { .. }
| Properties { .. }
| NextTokenId
| TokenContractAddress { .. }
@@ -341,9 +343,11 @@
ERC165Call(_, _) => None,
// Not sponsored
- AllowanceCross { .. } | BurnFrom { .. } | BurnFromCross { .. } | Repartition { .. } => {
- None
- }
+ AllowanceCross { .. }
+ | BalanceOfCross { .. }
+ | BurnFrom { .. }
+ | BurnFromCross { .. }
+ | Repartition { .. } => None,
TransferCross { .. } | TransferFromCross { .. } => {
let RefungibleTokenHandle(handle, token_id) = token;
tests/src/eth/abi/fungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/fungible.json
+++ b/tests/src/eth/abi/fungible.json
@@ -181,6 +181,23 @@
{ "internalType": "uint256", "name": "sub", "type": "uint256" }
],
"internalType": "struct CrossAddress",
+ "name": "owner",
+ "type": "tuple"
+ }
+ ],
+ "name": "balanceOfCross",
+ "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": "from",
"type": "tuple"
},
tests/src/eth/abi/nonFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/nonFungible.json
+++ b/tests/src/eth/abi/nonFungible.json
@@ -177,6 +177,23 @@
},
{
"inputs": [
+ {
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct CrossAddress",
+ "name": "owner",
+ "type": "tuple"
+ }
+ ],
+ "name": "balanceOfCross",
+ "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
"name": "burn",
@@ -386,25 +403,6 @@
},
{
"inputs": [
- { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
- ],
- "name": "crossOwnerOf",
- "outputs": [
- {
- "components": [
- { "internalType": "address", "name": "eth", "type": "address" },
- { "internalType": "uint256", "name": "sub", "type": "uint256" }
- ],
- "internalType": "struct CrossAddress",
- "name": "",
- "type": "tuple"
- }
- ],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [
{ "internalType": "string[]", "name": "keys", "type": "string[]" }
],
"name": "deleteCollectionProperties",
@@ -540,6 +538,25 @@
},
{
"inputs": [
+ { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
+ ],
+ "name": "ownerOfCross",
+ "outputs": [
+ {
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct CrossAddress",
+ "name": "",
+ "type": "tuple"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" },
{ "internalType": "string[]", "name": "keys", "type": "string[]" }
],
tests/src/eth/abi/reFungible.jsondiffbeforeafterboth--- a/tests/src/eth/abi/reFungible.json
+++ b/tests/src/eth/abi/reFungible.json
@@ -159,6 +159,23 @@
},
{
"inputs": [
+ {
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct CrossAddress",
+ "name": "owner",
+ "type": "tuple"
+ }
+ ],
+ "name": "balanceOfCross",
+ "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" }
],
"name": "burn",
@@ -368,25 +385,6 @@
},
{
"inputs": [
- { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
- ],
- "name": "crossOwnerOf",
- "outputs": [
- {
- "components": [
- { "internalType": "address", "name": "eth", "type": "address" },
- { "internalType": "uint256", "name": "sub", "type": "uint256" }
- ],
- "internalType": "struct CrossAddress",
- "name": "",
- "type": "tuple"
- }
- ],
- "stateMutability": "view",
- "type": "function"
- },
- {
- "inputs": [
{ "internalType": "string[]", "name": "keys", "type": "string[]" }
],
"name": "deleteCollectionProperties",
@@ -522,6 +520,25 @@
},
{
"inputs": [
+ { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
+ ],
+ "name": "ownerOfCross",
+ "outputs": [
+ {
+ "components": [
+ { "internalType": "address", "name": "eth", "type": "address" },
+ { "internalType": "uint256", "name": "sub", "type": "uint256" }
+ ],
+ "internalType": "struct CrossAddress",
+ "name": "",
+ "type": "tuple"
+ }
+ ],
+ "stateMutability": "view",
+ "type": "function"
+ },
+ {
+ "inputs": [
{ "internalType": "uint256", "name": "tokenId", "type": "uint256" },
{ "internalType": "string[]", "name": "keys", "type": "string[]" }
],
tests/src/eth/abi/reFungibleToken.jsondiffbeforeafterboth--- a/tests/src/eth/abi/reFungibleToken.json
+++ b/tests/src/eth/abi/reFungibleToken.json
@@ -130,6 +130,23 @@
{ "internalType": "uint256", "name": "sub", "type": "uint256" }
],
"internalType": "struct CrossAddress",
+ "name": "owner",
+ "type": "tuple"
+ }
+ ],
+ "name": "balanceOfCross",
+ "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": "from",
"type": "tuple"
},
tests/src/eth/api/UniqueFungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueFungible.sol
+++ b/tests/src/eth/api/UniqueFungible.sol
@@ -353,7 +353,7 @@
bytes value;
}
-/// @dev the ERC-165 identifier for this interface is 0x85d7dea6
+/// @dev the ERC-165 identifier for this interface is 0x69d14d3e
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.
@@ -416,6 +416,13 @@
/// @dev EVM selector for this function is: 0x1896cce6,
/// or in textual repr: collectionHelperAddress()
function collectionHelperAddress() external view returns (address);
+
+ /// @notice Balance of account
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of fingibles owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0xec069398,
+ /// or in textual repr: balanceOfCross((address,uint256))
+ function balanceOfCross(CrossAddress memory owner) external view returns (uint256);
}
struct AmountForAddress {
tests/src/eth/api/UniqueNFT.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueNFT.sol
+++ b/tests/src/eth/api/UniqueNFT.sol
@@ -533,7 +533,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0x16de3152
+/// @dev the ERC-165 identifier for this interface is 0x307b061a
interface ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -550,12 +550,26 @@
/// or in textual repr: description()
function description() external view returns (string memory);
+ // /// Returns the owner (in cross format) of the token.
+ // ///
+ // /// @param tokenId Id for the token.
+ // /// @dev EVM selector for this function is: 0x2b29dace,
+ // /// or in textual repr: crossOwnerOf(uint256)
+ // function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
+
/// Returns the owner (in cross format) of the token.
///
/// @param tokenId Id for the token.
- /// @dev EVM selector for this function is: 0x2b29dace,
- /// or in textual repr: crossOwnerOf(uint256)
- function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
+ /// @dev EVM selector for this function is: 0xcaa3a4d0,
+ /// or in textual repr: ownerOfCross(uint256)
+ function ownerOfCross(uint256 tokenId) external view returns (CrossAddress memory);
+
+ /// @notice Count all NFTs assigned to an owner
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of NFTs owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0xec069398,
+ /// or in textual repr: balanceOfCross((address,uint256))
+ function balanceOfCross(CrossAddress memory owner) external view returns (uint256);
/// Returns the token properties.
///
tests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungible.sol
+++ b/tests/src/eth/api/UniqueRefungible.sol
@@ -533,7 +533,7 @@
}
/// @title Unique extensions for ERC721.
-/// @dev the ERC-165 identifier for this interface is 0xb365c124
+/// @dev the ERC-165 identifier for this interface is 0x95c0f66c
interface ERC721UniqueExtensions is Dummy, ERC165 {
/// @notice A descriptive name for a collection of NFTs in this contract
/// @dev EVM selector for this function is: 0x06fdde03,
@@ -550,12 +550,26 @@
/// or in textual repr: description()
function description() external view returns (string memory);
+ // /// Returns the owner (in cross format) of the token.
+ // ///
+ // /// @param tokenId Id for the token.
+ // /// @dev EVM selector for this function is: 0x2b29dace,
+ // /// or in textual repr: crossOwnerOf(uint256)
+ // function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
+
/// Returns the owner (in cross format) of the token.
///
/// @param tokenId Id for the token.
- /// @dev EVM selector for this function is: 0x2b29dace,
- /// or in textual repr: crossOwnerOf(uint256)
- function crossOwnerOf(uint256 tokenId) external view returns (CrossAddress memory);
+ /// @dev EVM selector for this function is: 0xcaa3a4d0,
+ /// or in textual repr: ownerOfCross(uint256)
+ function ownerOfCross(uint256 tokenId) external view returns (CrossAddress memory);
+
+ /// @notice Count all RFTs assigned to an owner
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of RFTs owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0xec069398,
+ /// or in textual repr: balanceOfCross((address,uint256))
+ function balanceOfCross(CrossAddress memory owner) external view returns (uint256);
/// Returns the token properties.
///
tests/src/eth/api/UniqueRefungibleToken.soldiffbeforeafterboth--- a/tests/src/eth/api/UniqueRefungibleToken.sol
+++ b/tests/src/eth/api/UniqueRefungibleToken.sol
@@ -23,7 +23,7 @@
function parentTokenId() external view returns (uint256);
}
-/// @dev the ERC-165 identifier for this interface is 0x01d536fc
+/// @dev the ERC-165 identifier for this interface is 0xedd3a564
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.
@@ -60,6 +60,13 @@
/// or in textual repr: approveCross((address,uint256),uint256)
function approveCross(CrossAddress memory spender, uint256 amount) external returns (bool);
+ /// @notice Balance of account
+ /// @param owner An cross address for whom to query the balance
+ /// @return The number of fingibles owned by `owner`, possibly zero
+ /// @dev EVM selector for this function is: 0xec069398,
+ /// or in textual repr: balanceOfCross((address,uint256))
+ function balanceOfCross(CrossAddress memory owner) external view returns (uint256);
+
/// @dev Function that changes total amount of the tokens.
/// Throws if `msg.sender` doesn't owns all of the tokens.
/// @param amount New total amount of the tokens.
tests/src/eth/fungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/fungible.test.ts
+++ b/tests/src/eth/fungible.test.ts
@@ -427,6 +427,33 @@
const toBalanceAfter = await collection.getBalance({Ethereum: receiver});
expect(toBalanceAfter - toBalanceBefore).to.be.eq(51n);
});
+
+ itEth('Check balanceOfCross()', async ({helper}) => {
+ const collection = await helper.ft.mintCollection(alice, {});
+ const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ const other = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'ft', owner.eth);
+
+ expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('0');
+ expect(await collectionEvm.methods.balanceOfCross(other).call({from: owner.eth})).to.be.eq('0');
+
+ await collection.mint(alice, 100n, {Ethereum: owner.eth});
+ expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('100');
+ expect(await collectionEvm.methods.balanceOfCross(other).call({from: owner.eth})).to.be.eq('0');
+
+ await collectionEvm.methods.transferCross(other, 50n).send({from: owner.eth});
+ expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('50');
+ expect(await collectionEvm.methods.balanceOfCross(other).call({from: owner.eth})).to.be.eq('50');
+
+ await collectionEvm.methods.transferCross(other, 50n).send({from: owner.eth});
+ expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('0');
+ expect(await collectionEvm.methods.balanceOfCross(other).call({from: owner.eth})).to.be.eq('100');
+
+ await collectionEvm.methods.transferCross(owner, 100n).send({from: other.eth});
+ expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('100');
+ expect(await collectionEvm.methods.balanceOfCross(other).call({from: owner.eth})).to.be.eq('0');
+ });
});
describe('Fungible: Fees', () => {
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -662,6 +662,38 @@
// Cannot transfer token if it does not exist:
await expect(collectionEvm.methods[testCase](receiver, 999999).send({from: sender})).to.be.rejected;
}));
+
+ itEth('Check balanceOfCross()', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(minter, {});
+ const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);
+
+ expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('0');
+
+ for (let i = 1; i < 10; i++) {
+ await collection.mintToken(minter, {Ethereum: owner.eth});
+ expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq(i.toString());
+ }
+ });
+
+ itEth('Check ownerOfCross()', async ({helper}) => {
+ const collection = await helper.nft.mintCollection(minter, {});
+ let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);
+ const {tokenId} = await collection.mintToken(minter, {Ethereum: owner.eth});
+
+ for (let i = 1n; i < 10n; i++) {
+ const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});
+ expect(ownerCross.eth).to.be.eq(owner.eth);
+ expect(ownerCross.sub).to.be.eq(owner.sub);
+
+ const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});
+ owner = newOwner;
+ }
+ });
});
describe('NFT: Fees', () => {
tests/src/eth/reFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungible.test.ts
+++ b/tests/src/eth/reFungible.test.ts
@@ -584,6 +584,46 @@
expect(event.returnValues.to).to.equal('0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF');
expect(event.returnValues.tokenId).to.equal(tokenId.toString());
});
+
+ itEth('Check balanceOfCross()', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(minter, {});
+ const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);
+
+ expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('0');
+
+ for (let i = 1n; i < 10n; i++) {
+ await collection.mintToken(minter, 100n, {Ethereum: owner.eth});
+ expect(await collectionEvm.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq(i.toString());
+ }
+ });
+
+ itEth('Check ownerOfCross()', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(minter, {});
+ let owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ const collectionAddress = helper.ethAddress.fromCollectionId(collection.collectionId);
+ const collectionEvm = await helper.ethNativeContract.collection(collectionAddress, 'nft', owner.eth);
+ const {tokenId} = await collection.mintToken(minter, 100n,{Ethereum: owner.eth});
+
+ for (let i = 1n; i < 10n; i++) {
+ const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});
+ expect(ownerCross.eth).to.be.eq(owner.eth);
+ expect(ownerCross.sub).to.be.eq(owner.sub);
+
+ const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ await collectionEvm.methods.transferCross(newOwner, tokenId).send({from: owner.eth});
+ owner = newOwner;
+ }
+
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner.eth, true);
+ const newOwner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ await tokenContract.methods.transferCross(newOwner, 50).send({from: owner.eth});
+ const ownerCross = await collectionEvm.methods.ownerOfCross(tokenId).call({from: owner.eth});
+ expect(ownerCross.eth.toUpperCase()).to.be.eq('0XFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF');
+ expect(ownerCross.sub).to.be.eq('0');
+ });
});
describe('RFT: Fees', () => {
tests/src/eth/reFungibleToken.test.tsdiffbeforeafterboth--- a/tests/src/eth/reFungibleToken.test.ts
+++ b/tests/src/eth/reFungibleToken.test.ts
@@ -466,6 +466,35 @@
expect(await collection.getTokenBalance(tokenId, {Substrate: ownerSub.address})).to.be.equal(150n);
}
});
+
+ itEth('Check balanceOfCross()', async ({helper}) => {
+ const collection = await helper.rft.mintCollection(alice, {});
+ const owner = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ const other = await helper.ethCrossAccount.createAccountWithBalance(donor);
+ const {tokenId} = await collection.mintToken(alice, 200n, {Ethereum: owner.eth});
+ const tokenAddress = helper.ethAddress.fromTokenId(collection.collectionId, tokenId);
+ const tokenContract = await helper.ethNativeContract.rftToken(tokenAddress, owner.eth);
+
+ expect(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('200');
+ expect(await tokenContract.methods.balanceOfCross(other).call({from: owner.eth})).to.be.eq('0');
+
+ await tokenContract.methods.repartition(100n).send({from: owner.eth});
+ expect(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('100');
+ expect(await tokenContract.methods.balanceOfCross(other).call({from: owner.eth})).to.be.eq('0');
+
+ await tokenContract.methods.transferCross(other, 50n).send({from: owner.eth});
+ expect(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('50');
+ expect(await tokenContract.methods.balanceOfCross(other).call({from: owner.eth})).to.be.eq('50');
+
+ await tokenContract.methods.transferCross(other, 50n).send({from: owner.eth});
+ expect(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('0');
+ expect(await tokenContract.methods.balanceOfCross(other).call({from: owner.eth})).to.be.eq('100');
+
+ await tokenContract.methods.repartition(1000n).send({from: other.eth});
+ await tokenContract.methods.transferCross(owner, 500n).send({from: other.eth});
+ expect(await tokenContract.methods.balanceOfCross(owner).call({from: owner.eth})).to.be.eq('500');
+ expect(await tokenContract.methods.balanceOfCross(other).call({from: owner.eth})).to.be.eq('500');
+ });
});
describe('Refungible: Fees', () => {
tests/src/eth/tokens/minting.test.tsdiffbeforeafterboth--- a/tests/src/eth/tokens/minting.test.ts
+++ b/tests/src/eth/tokens/minting.test.ts
@@ -63,7 +63,7 @@
const tokenId = event.returnValues.tokenId;
expect(tokenId).to.be.equal('1');
expect(await helper.collection.getLastTokenId(collection.collectionId)).to.eq(1);
- expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ expect(await contract.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);
}
});
});
@@ -97,7 +97,7 @@
const tokenId = event.returnValues.tokenId;
expect(tokenId).to.be.equal('1');
expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);
- expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ expect(await collection.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);
}
});
});
@@ -131,7 +131,7 @@
const tokenId = event.returnValues.tokenId;
expect(tokenId).to.be.equal('1');
expect(await helper.collection.getLastTokenId(collectionId)).to.eq(1);
- expect(await collection.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ expect(await collection.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);
}
});
});
@@ -157,7 +157,7 @@
expect(event.returnValues.to).to.be.equal(receiver);
expect(await contract.methods.tokenURI(tokenId).call()).to.be.equal('Test URI');
- expect(await contract.methods.crossOwnerOf(tokenId).call()).to.be.like([receiver, '0']);
+ expect(await contract.methods.ownerOfCross(tokenId).call()).to.be.like([receiver, '0']);
// TODO: this wont work right now, need release 919000 first
// await helper.methods.setOffchainSchema(collectionIdAddress, 'https://offchain-service.local/token-info/{id}').send();
// const tokenUri = await contract.methods.tokenURI(nextTokenId).call();