--- a/pallets/fungible/src/erc.rs +++ b/pallets/fungible/src/erc.rs @@ -30,6 +30,7 @@ use pallet_evm_coder_substrate::{call, dispatch_to_evm}; use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _}; use pallet_common::{CollectionHandle, erc::CollectionCall}; +use sp_core::Get; use crate::{ Allowance, Balance, Config, FungibleHandle, Pallet, SelfWeightOf, TotalSupply, @@ -132,6 +133,11 @@ Ok(>::get((self.id, owner, spender)).into()) } + + /// @notice Returns collection helper contract address + fn collection_helper_address(&self) -> Result
{ + Ok(T::ContractAddress::get()) + } } #[solidity_interface(name = ERC20Mintable)] --- a/pallets/fungible/src/stubs/UniqueFungible.sol +++ b/pallets/fungible/src/stubs/UniqueFungible.sol @@ -547,7 +547,7 @@ event Approval(address indexed owner, address indexed spender, uint256 value); } -/// @dev the ERC-165 identifier for this interface is 0x942e8b22 +/// @dev the ERC-165 identifier for this interface is 0x8cb847c4 contract ERC20 is Dummy, ERC165, ERC20Events { /// @dev EVM selector for this function is: 0x06fdde03, /// or in textual repr: name() @@ -634,6 +634,15 @@ dummy; return 0; } + + /// @notice Returns collection helper contract address + /// @dev EVM selector for this function is: 0x1896cce6, + /// or in textual repr: collectionHelperAddress() + function collectionHelperAddress() public view returns (address) { + require(false, stub_error); + dummy; + return 0x0000000000000000000000000000000000000000; + } } contract UniqueFungible is Dummy, ERC165, ERC20, ERC20Mintable, ERC20UniqueExtensions, Collection {} --- a/pallets/nonfungible/src/erc.rs +++ b/pallets/nonfungible/src/erc.rs @@ -42,6 +42,7 @@ use pallet_evm::{account::CrossAccountId, PrecompileHandle}; use pallet_evm_coder_substrate::call; use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _}; +use sp_core::Get; use crate::{ AccountBalance, Config, CreateItemData, NonfungibleHandle, Pallet, TokenData, TokensMinted, @@ -489,6 +490,11 @@ // TODO: Not implemetable Err("not implemented".into()) } + + /// @notice Returns collection helper contract address + fn collection_helper_address(&self) -> Result
{ + Ok(T::ContractAddress::get()) + } } /// @title ERC721 Token that can be irreversibly burned (destroyed). --- a/pallets/nonfungible/src/stubs/UniqueNFT.sol +++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol @@ -920,7 +920,7 @@ /// @title ERC-721 Non-Fungible Token Standard /// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md -/// @dev the ERC-165 identifier for this interface is 0x80ac58cd +/// @dev the ERC-165 identifier for this interface is 0x983a942b contract ERC721 is Dummy, ERC165, ERC721Events { /// @notice Count all NFTs assigned to an owner /// @dev NFTs assigned to the zero address are considered invalid, and this @@ -1050,6 +1050,15 @@ dummy; return 0x0000000000000000000000000000000000000000; } + + /// @notice Returns collection helper contract address + /// @dev EVM selector for this function is: 0x1896cce6, + /// or in textual repr: collectionHelperAddress() + function collectionHelperAddress() public view returns (address) { + require(false, stub_error); + dummy; + return 0x0000000000000000000000000000000000000000; + } } contract UniqueNFT is --- a/pallets/refungible/src/erc.rs +++ b/pallets/refungible/src/erc.rs @@ -38,7 +38,7 @@ use pallet_evm::{account::CrossAccountId, PrecompileHandle}; use pallet_evm_coder_substrate::{call, dispatch_to_evm}; use pallet_structure::{SelfWeightOf as StructureWeight, weights::WeightInfo as _}; -use sp_core::H160; +use sp_core::{H160, Get}; use sp_std::{collections::btree_map::BTreeMap, vec::Vec, vec}; use up_data_structs::{ CollectionId, CollectionPropertiesVec, mapping::TokenAddressMapping, Property, PropertyKey, @@ -482,6 +482,11 @@ // TODO: Not implemetable Err("not implemented".into()) } + + /// @notice Returns collection helper contract address + fn collection_helper_address(&self) -> Result
{ + Ok(T::ContractAddress::get()) + } } /// Returns amount of pieces of `token` that `owner` have --- a/pallets/refungible/src/stubs/UniqueRefungible.sol +++ b/pallets/refungible/src/stubs/UniqueRefungible.sol @@ -919,7 +919,7 @@ /// @title ERC-721 Non-Fungible Token Standard /// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md -/// @dev the ERC-165 identifier for this interface is 0x58800161 +/// @dev the ERC-165 identifier for this interface is 0x4016cd87 contract ERC721 is Dummy, ERC165, ERC721Events { /// @notice Count all RFTs assigned to an owner /// @dev RFTs assigned to the zero address are considered invalid, and this @@ -1047,6 +1047,15 @@ dummy; return 0x0000000000000000000000000000000000000000; } + + /// @notice Returns collection helper contract address + /// @dev EVM selector for this function is: 0x1896cce6, + /// or in textual repr: collectionHelperAddress() + function collectionHelperAddress() public view returns (address) { + require(false, stub_error); + dummy; + return 0x0000000000000000000000000000000000000000; + } } contract UniqueRefungible is --- a/tests/src/apiConsts.test.ts +++ b/tests/src/apiConsts.test.ts @@ -117,4 +117,4 @@ function checkConst(constValue: any, expectedValue: T) { expect(constValue.toBigInt()).equal(expectedValue); -} +} \ No newline at end of file --- a/tests/src/eth/abi/fungible.json +++ b/tests/src/eth/abi/fungible.json @@ -201,6 +201,13 @@ }, { "inputs": [], + "name": "collectionHelperAddress", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], "name": "collectionOwner", "outputs": [ { --- a/tests/src/eth/abi/nonFungible.json +++ b/tests/src/eth/abi/nonFungible.json @@ -231,6 +231,13 @@ }, { "inputs": [], + "name": "collectionHelperAddress", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], "name": "collectionOwner", "outputs": [ { --- a/tests/src/eth/abi/reFungible.json +++ b/tests/src/eth/abi/reFungible.json @@ -213,6 +213,13 @@ }, { "inputs": [], + "name": "collectionHelperAddress", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], "name": "collectionOwner", "outputs": [ { --- a/tests/src/eth/api/UniqueFungible.sol +++ b/tests/src/eth/api/UniqueFungible.sol @@ -354,7 +354,7 @@ event Approval(address indexed owner, address indexed spender, uint256 value); } -/// @dev the ERC-165 identifier for this interface is 0x942e8b22 +/// @dev the ERC-165 identifier for this interface is 0x8cb847c4 interface ERC20 is Dummy, ERC165, ERC20Events { /// @dev EVM selector for this function is: 0x06fdde03, /// or in textual repr: name() @@ -395,6 +395,11 @@ /// @dev EVM selector for this function is: 0xdd62ed3e, /// or in textual repr: allowance(address,address) function allowance(address owner, address spender) external view returns (uint256); + + /// @notice Returns collection helper contract address + /// @dev EVM selector for this function is: 0x1896cce6, + /// or in textual repr: collectionHelperAddress() + function collectionHelperAddress() external view returns (address); } interface UniqueFungible is Dummy, ERC165, ERC20, ERC20Mintable, ERC20UniqueExtensions, Collection {} --- a/tests/src/eth/api/UniqueNFT.sol +++ b/tests/src/eth/api/UniqueNFT.sol @@ -605,7 +605,7 @@ /// @title ERC-721 Non-Fungible Token Standard /// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md -/// @dev the ERC-165 identifier for this interface is 0x80ac58cd +/// @dev the ERC-165 identifier for this interface is 0x983a942b interface ERC721 is Dummy, ERC165, ERC721Events { /// @notice Count all NFTs assigned to an owner /// @dev NFTs assigned to the zero address are considered invalid, and this @@ -685,6 +685,11 @@ /// @dev EVM selector for this function is: 0xe985e9c5, /// or in textual repr: isApprovedForAll(address,address) function isApprovedForAll(address owner, address operator) external view returns (address); + + /// @notice Returns collection helper contract address + /// @dev EVM selector for this function is: 0x1896cce6, + /// or in textual repr: collectionHelperAddress() + function collectionHelperAddress() external view returns (address); } interface UniqueNFT is --- a/tests/src/eth/api/UniqueRefungible.sol +++ b/tests/src/eth/api/UniqueRefungible.sol @@ -604,7 +604,7 @@ /// @title ERC-721 Non-Fungible Token Standard /// @dev See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md -/// @dev the ERC-165 identifier for this interface is 0x58800161 +/// @dev the ERC-165 identifier for this interface is 0x4016cd87 interface ERC721 is Dummy, ERC165, ERC721Events { /// @notice Count all RFTs assigned to an owner /// @dev RFTs assigned to the zero address are considered invalid, and this @@ -682,6 +682,11 @@ /// @dev EVM selector for this function is: 0xe985e9c5, /// or in textual repr: isApprovedForAll(address,address) function isApprovedForAll(address owner, address operator) external view returns (address); + + /// @notice Returns collection helper contract address + /// @dev EVM selector for this function is: 0x1896cce6, + /// or in textual repr: collectionHelperAddress() + function collectionHelperAddress() external view returns (address); } interface UniqueRefungible is --- /dev/null +++ b/tests/src/eth/collectionHelperAddress.test.ts @@ -0,0 +1,57 @@ +// Copyright 2019-2022 Unique Network (Gibraltar) Ltd. +// This file is part of Unique Network. + +// Unique Network is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Unique Network is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Unique Network. If not, see . + +import {itEth, usingEthPlaygrounds, expect} from './util'; +import {IKeyringPair} from '@polkadot/types/types'; + +const EVM_COLLECTION_HELPERS_ADDRESS = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f'; + +describe('[eth]CollectionHelerpAddress test: ERC721 ', () => { + let donor: IKeyringPair; + + before(async function() { + await usingEthPlaygrounds(async (helper, privateKey) => { + donor = await privateKey({filename: __filename}); + }); + }); + + itEth('NFT\\RFT', async ({helper}) => { + const owner = await helper.eth.createAccountWithBalance(donor); + + const {collectionAddress: nftCollectionAddress} = await helper.eth.createNFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC'); + const nftCollection = helper.ethNativeContract.collection(nftCollectionAddress, 'nft', owner); + + const {collectionAddress: rftCollectionAddress} = await helper.eth.createRFTCollection(owner, 'Sponsor', 'absolutely anything', 'ROC'); + const rftCollection = helper.ethNativeContract.collection(rftCollectionAddress, 'rft', owner); + + expect((await nftCollection.methods.collectionHelperAddress().call()) + .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS); + + expect((await rftCollection.methods.collectionHelperAddress().call()) + .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS); + }); + + itEth('FT', async ({helper}) => { + const owner = await helper.eth.createAccountWithBalance(donor); + + const {collectionAddress} = await helper.eth.createFungibleCollection(owner, 'Sponsor', 18, 'absolutely anything', 'ROC'); + const collection = helper.ethNativeContract.collection(collectionAddress, 'ft', owner); + + expect((await collection.methods.collectionHelperAddress().call()) + .toString().toLowerCase()).to.be.equal(EVM_COLLECTION_HELPERS_ADDRESS); + }); + +});