--- /dev/null +++ b/.maintain/scripts/compile_stub.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -eu + +dir=$PWD + +tmp=$(mktemp -d) +cd $tmp +cp $dir/$INPUT input.sol +solcjs --optimize --bin input.sol + +mv input_sol_$(basename $OUTPUT .raw).bin out.bin +xxd -r -p out.bin out.raw + +mv out.raw $dir/$OUTPUT \ No newline at end of file --- /dev/null +++ b/.maintain/scripts/generate_api.sh @@ -0,0 +1,12 @@ +#!/bin/sh +set -eu + +tmp=$(mktemp) +cargo test --package $PACKAGE -- $NAME --exact --nocapture --ignored | tee $tmp +raw=$(mktemp --suffix .sol) +sed -n '/=== SNIP START ===/, /=== SNIP END ===/{ /=== SNIP START ===/! { /=== SNIP END ===/! p } }' $tmp > $raw +formatted=$(mktemp) +prettier --use-tabs $raw > $formatted +solhint --fix $formatted + +mv $formatted $OUTPUT \ No newline at end of file --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +.PHONY: _eth_codegen +_eth_codegen: + +.PHONY: regenerate_solidity +regenerate_solidity: + PACKAGE=pallet-nft NAME=eth::erc::fungible_iface OUTPUT=./tests/src/eth/api/UniqueFungible.sol ./.maintain/scripts/generate_api.sh + PACKAGE=pallet-nft NAME=eth::erc::nft_iface OUTPUT=./tests/src/eth/api/UniqueNFT.sol ./.maintain/scripts/generate_api.sh + PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_iface OUTPUT=./tests/src/eth/api/ContractHelpers.sol ./.maintain/scripts/generate_api.sh + + PACKAGE=pallet-nft NAME=eth::erc::fungible_impl OUTPUT=./pallets/nft/src/eth/stubs/UniqueFungible.sol ./.maintain/scripts/generate_api.sh + PACKAGE=pallet-nft NAME=eth::erc::nft_impl OUTPUT=./pallets/nft/src/eth/stubs/UniqueNFT.sol ./.maintain/scripts/generate_api.sh + PACKAGE=pallet-evm-contract-helpers NAME=eth::contract_helpers_impl OUTPUT=./pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol ./.maintain/scripts/generate_api.sh + +NFT_EVM_STUBS=./pallets/nft/src/eth/stubs +CONTRACT_HELPERS_STUBS=./pallets/evm-contract-helpers/src/stubs/ + +$(NFT_EVM_STUBS)/UniqueFungible.raw: $(NFT_EVM_STUBS)/UniqueFungible.sol + INPUT=$< OUTPUT=$@ ./.maintain/scripts/compile_stub.sh +$(NFT_EVM_STUBS)/UniqueNFT.raw: $(NFT_EVM_STUBS)/UniqueNFT.sol + INPUT=$< OUTPUT=$@ ./.maintain/scripts/compile_stub.sh +$(CONTRACT_HELPERS_STUBS)/ContractHelpers.raw: $(CONTRACT_HELPERS_STUBS)/ContractHelpers.sol + INPUT=$< OUTPUT=$@ ./.maintain/scripts/compile_stub.sh + +evm_stubs: $(NFT_EVM_STUBS)/UniqueFungible.raw $(NFT_EVM_STUBS)/UniqueNFT.raw $(CONTRACT_HELPERS_STUBS)/ContractHelpers.raw --- a/crates/evm-coder-macros/src/to_log.rs +++ b/crates/evm-coder-macros/src/to_log.rs @@ -34,8 +34,9 @@ fn expand_solidity_argument(&self) -> proc_macro2::TokenStream { let camel_name = &self.camel_name; let ty = &self.ty; + let indexed = self.indexed; quote! { - >::new(#camel_name) + >::new(#indexed, #camel_name) } } } --- a/crates/evm-coder/src/lib.rs +++ b/crates/evm-coder/src/lib.rs @@ -61,6 +61,29 @@ fn call(&mut self, call: types::Msg) -> execution::Result; } +#[macro_export] +macro_rules! generate_stubgen { + ($name:ident, $decl:ident, $is_impl:literal) => { + #[test] + #[ignore] + fn $name() { + use sp_std::collections::btree_set::BTreeSet; + let mut out = BTreeSet::new(); + $decl::generate_solidity_interface(&mut out, $is_impl); + println!("=== SNIP START ==="); + println!("// SPDX-License-Identifier: OTHER"); + println!("// This code is automatically generated"); + println!(); + println!("pragma solidity >=0.8.0 <0.9.0;"); + println!(); + for b in out { + println!("{}", b); + } + println!("=== SNIP END ==="); + } + }; +} + #[cfg(test)] mod tests { use super::*; --- a/crates/evm-coder/src/solidity.rs +++ b/crates/evm-coder/src/solidity.rs @@ -117,6 +117,41 @@ } } +pub struct SolidityEventArgument(pub bool, &'static str, PhantomData<*const T>); + +impl SolidityEventArgument { + pub fn new(indexed: bool, name: &'static str) -> Self { + Self(indexed, name, Default::default()) + } +} + +impl SolidityArguments for SolidityEventArgument { + fn solidity_name(&self, writer: &mut impl fmt::Write) -> fmt::Result { + if !T::is_void() { + T::solidity_name(writer)?; + if self.0 { + write!(writer, " indexed")?; + } + write!(writer, " {}", self.1) + } else { + Ok(()) + } + } + fn solidity_get(&self, writer: &mut impl fmt::Write) -> fmt::Result { + writeln!(writer, "\t\t{};", self.1) + } + fn solidity_default(&self, writer: &mut impl fmt::Write) -> fmt::Result { + T::solidity_default(writer) + } + fn len(&self) -> usize { + if T::is_void() { + 0 + } else { + 1 + } + } +} + impl SolidityArguments for () { fn solidity_name(&self, _writer: &mut impl fmt::Write) -> fmt::Result { Ok(()) --- a/pallets/evm-contract-helpers/src/eth.rs +++ b/pallets/evm-contract-helpers/src/eth.rs @@ -1,5 +1,5 @@ use core::marker::PhantomData; -use evm_coder::{abi::AbiWriter, execution::Result, solidity_interface, types::*}; +use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*}; use pallet_evm_coder_substrate::SubstrateRecorder; use pallet_evm::{ExitReason, ExitRevert, OnCreate, OnMethodCall, PrecompileOutput}; use sp_core::H160; @@ -14,76 +14,76 @@ #[solidity_interface(name = "ContractHelpers")] impl ContractHelpers { - fn contract_owner(&self, contract: address) -> Result
{ + fn contract_owner(&self, contract_address: address) -> Result
{ self.0.consume_sload()?; - Ok(>::get(contract)) + Ok(>::get(contract_address)) } - fn sponsoring_enabled(&self, contract: address) -> Result { + fn sponsoring_enabled(&self, contract_address: address) -> Result { self.0.consume_sload()?; - Ok(>::get(contract)) + Ok(>::get(contract_address)) } fn toggle_sponsoring( &mut self, caller: caller, - contract: address, + contract_address: address, enabled: bool, ) -> Result { self.0.consume_sload()?; - >::ensure_owner(contract, caller)?; + >::ensure_owner(contract_address, caller)?; self.0.consume_sstore()?; - >::toggle_sponsoring(contract, enabled); + >::toggle_sponsoring(contract_address, enabled); Ok(()) } fn set_sponsoring_rate_limit( &mut self, caller: caller, - contract: address, + contract_address: address, rate_limit: uint32, ) -> Result { self.0.consume_sload()?; - >::ensure_owner(contract, caller)?; + >::ensure_owner(contract_address, caller)?; self.0.consume_sstore()?; - >::set_sponsoring_rate_limit(contract, rate_limit.into()); + >::set_sponsoring_rate_limit(contract_address, rate_limit.into()); Ok(()) } - fn allowed(&self, contract: address, user: address) -> Result { + fn allowed(&self, contract_address: address, user: address) -> Result { self.0.consume_sload()?; - Ok(>::allowed(contract, user, true)) + Ok(>::allowed(contract_address, user, true)) } - fn allowlist_enabled(&self, contract: address) -> Result { + fn allowlist_enabled(&self, contract_address: address) -> Result { self.0.consume_sload()?; - Ok(>::get(contract)) + Ok(>::get(contract_address)) } fn toggle_allowlist( &mut self, caller: caller, - contract: address, + contract_address: address, enabled: bool, ) -> Result { self.0.consume_sload()?; - >::ensure_owner(contract, caller)?; + >::ensure_owner(contract_address, caller)?; self.0.consume_sstore()?; - >::toggle_allowlist(contract, enabled); + >::toggle_allowlist(contract_address, enabled); Ok(()) } fn toggle_allowed( &mut self, caller: caller, - contract: address, + contract_address: address, user: address, allowed: bool, ) -> Result { self.0.consume_sload()?; - >::ensure_owner(contract, caller)?; + >::ensure_owner(contract_address, caller)?; self.0.consume_sstore()?; - >::toggle_allowed(contract, user, allowed); + >::toggle_allowed(contract_address, user, allowed); Ok(()) } } @@ -130,7 +130,7 @@ fn get_code(contract: &sp_core::H160) -> Option> { (contract == &T::ContractAddress::get()) - .then(|| include_bytes!("./stubs/ContractHelpers.bin").to_vec()) + .then(|| include_bytes!("./stubs/ContractHelpers.raw").to_vec()) } } @@ -162,3 +162,6 @@ None } } + +generate_stubgen!(contract_helpers_impl, ContractHelpersCall, true); +generate_stubgen!(contract_helpers_iface, ContractHelpersCall, false); --- a/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol +++ b/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol @@ -1,40 +1,92 @@ -contract ContractHelpers { - uint8 _dummmy = 0; - address _dummy_addr = 0x0000000000000000000000000000000000000000; - string stub_error = "this contract does not exists, contract helpers are implemented on substrate chain side"; +// SPDX-License-Identifier: OTHER +// This code is automatically generated + +pragma solidity >=0.8.0 <0.9.0; + +// Common stubs holder +contract Dummy { + uint8 dummy; + string stub_error = "this contract is implemented in native"; +} + +contract ContractHelpers is Dummy { + function contractOwner(address contractAddress) + public + view + returns (address) + { + require(false, stub_error); + contractAddress; + dummy; + return 0x0000000000000000000000000000000000000000; + } + + function sponsoringEnabled(address contractAddress) + public + view + returns (bool) + { + require(false, stub_error); + contractAddress; + dummy; + return false; + } + + function toggleSponsoring(address contractAddress, bool enabled) public { + require(false, stub_error); + contractAddress; + enabled; + dummy = 0; + } + + function setSponsoringRateLimit(address contractAddress, uint32 rateLimit) + public + { + require(false, stub_error); + contractAddress; + rateLimit; + dummy = 0; + } + + function allowed(address contractAddress, address user) + public + view + returns (bool) + { + require(false, stub_error); + contractAddress; + user; + dummy; + return false; + } + + function allowlistEnabled(address contractAddress) + public + view + returns (bool) + { + require(false, stub_error); + contractAddress; + dummy; + return false; + } - function contractOwner(address contract_address) public view returns (address) { - require(false, stub_error); - contract_address; - return _dummy_addr; - } - - function sponsoringEnabled(address contract_address) public view returns (bool) { - require(false, stub_error); - contract_address; - _dummmy; - return false; - } - - function toggleSponsoring(address contract_address, bool enabled) public { - require(false, stub_error); - contract_address; - enabled; - _dummmy = 0; - } - - function toggleAllowlist(address contract_address, bool enabled) public { - require(false, stub_error); - contract_address; - enabled; - _dummmy = 0; - } - - function toggleAllowed(address contract_address, address user, bool allowed) public { - require(false, stub_error); - contract_address; - user; - allowed; - _dummmy = 0; - } -} \ No newline at end of file + function toggleAllowlist(address contractAddress, bool enabled) public { + require(false, stub_error); + contractAddress; + enabled; + dummy = 0; + } + + function toggleAllowed( + address contractAddress, + address user, + bool allowed + ) public { + require(false, stub_error); + contractAddress; + user; + allowed; + dummy = 0; + } +} --- a/pallets/nft/src/eth/erc.rs +++ b/pallets/nft/src/eth/erc.rs @@ -1,5 +1,5 @@ use core::char::{decode_utf16, REPLACEMENT_CHARACTER}; -use evm_coder::{ToLog, execution::Result, solidity, solidity_interface, types::*}; +use evm_coder::{ToLog, execution::Result, generate_stubgen, solidity, solidity_interface, types::*}; use nft_data_structs::{CreateItemData, CreateNftData}; use core::convert::TryInto; use crate::{ @@ -402,32 +402,10 @@ #[solidity_interface(name = "UniqueFungible", is(ERC165, ERC20))] impl CollectionHandle {} - -macro_rules! generate_code { - ($name:ident, $decl:ident, $is_impl:literal) => { - #[test] - #[ignore] - fn $name() { - use sp_std::collections::btree_set::BTreeSet; - let mut out = BTreeSet::new(); - $decl::generate_solidity_interface(&mut out, $is_impl); - println!("=== SNIP START ==="); - println!("// SPDX-License-Identifier: OTHER"); - println!("// This code is automatically generated with `cargo test --package pallet-nft -- eth::erc::{} --exact --nocapture --ignored`", stringify!(name)); - println!(); - println!("pragma solidity >=0.8.0 <0.9.0;"); - println!(); - for b in out { - println!("{}", b); - } - println!("=== SNIP END ==="); - } - }; -} // Not a tests, but code generators -generate_code!(nft_impl, UniqueNFTCall, true); -generate_code!(nft_iface, UniqueNFTCall, false); +generate_stubgen!(nft_impl, UniqueNFTCall, true); +generate_stubgen!(nft_iface, UniqueNFTCall, false); -generate_code!(fungible_impl, UniqueFungibleCall, true); -generate_code!(fungible_iface, UniqueFungibleCall, false); +generate_stubgen!(fungible_impl, UniqueFungibleCall, true); +generate_stubgen!(fungible_iface, UniqueFungibleCall, false); --- a/pallets/nft/src/eth/mod.rs +++ b/pallets/nft/src/eth/mod.rs @@ -96,10 +96,14 @@ .and_then(>::get) .map(|collection| { match collection.mode { - CollectionMode::NFT => include_bytes!("stubs/ERC721.bin") as &[u8], - CollectionMode::Fungible(_) => include_bytes!("stubs/ERC20.bin") as &[u8], - CollectionMode::ReFungible => include_bytes!("stubs/ERC1633.bin") as &[u8], - CollectionMode::Invalid => include_bytes!("stubs/Invalid.bin") as &[u8], + CollectionMode::NFT => include_bytes!("stubs/UniqueNFT.raw") as &[u8], + CollectionMode::Fungible(_) => { + include_bytes!("stubs/UniqueFungible.raw") as &[u8] + } + CollectionMode::ReFungible => { + include_bytes!("stubs/UniqueRefungible.raw") as &[u8] + } + CollectionMode::Invalid => include_bytes!("stubs/UniqueInvalid.raw") as &[u8], } .to_owned() }) --- a/pallets/nft/src/eth/stubs/ERC1633.bin +++ /dev/null @@ -1 +0,0 @@ -TODO \ No newline at end of file --- a/pallets/nft/src/eth/stubs/ERC20.sol +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: OTHER -// This code is automatically generated with `cargo test --package pallet-nft -- eth::erc::name --exact --nocapture --ignored` - -pragma solidity >=0.8.0 <0.9.0; - -// Common stubs holder -contract Dummy { - uint8 dummy; - string stub_error = "this contract is implemented in native"; -} - -// Inline -contract ERC20Events { - event Transfer(address from, address to, uint256 value); - event Approval(address owner, address spender, uint256 value); -} - -// Inline -contract InlineNameSymbol is Dummy { - function name() public view returns (string memory) { - require(false, stub_error); - dummy; - return ""; - } - function symbol() public view returns (string memory) { - require(false, stub_error); - dummy; - return ""; - } -} - -// Inline -contract InlineTotalSupply is Dummy { - function totalSupply() public view returns (uint256) { - require(false, stub_error); - dummy; - return 0; - } -} - -contract ERC165 is Dummy { - function supportsInterface(uint32 interfaceId) public view returns (bool) { - require(false, stub_error); - interfaceId; - dummy; - return false; - } -} - -contract ERC20 is Dummy, InlineNameSymbol, InlineTotalSupply, ERC20Events { - function decimals() public view returns (uint8) { - require(false, stub_error); - dummy; - return 0; - } - function balanceOf(address owner) public view returns (uint256) { - require(false, stub_error); - owner; - dummy; - return 0; - } - function transfer(address to, uint256 amount) public returns (bool) { - require(false, stub_error); - to; - amount; - dummy = 0; - return false; - } - function transferFrom(address from, address to, uint256 amount) public returns (bool) { - require(false, stub_error); - from; - to; - amount; - dummy = 0; - return false; - } - function approve(address spender, uint256 amount) public returns (bool) { - require(false, stub_error); - spender; - amount; - dummy = 0; - return false; - } - function allowance(address owner, address spender) public view returns (uint256) { - require(false, stub_error); - owner; - spender; - dummy; - return 0; - } -} - -contract UniqueFungible is Dummy, ERC165, ERC20 { -} \ No newline at end of file --- a/pallets/nft/src/eth/stubs/ERC721.sol +++ /dev/null @@ -1,194 +0,0 @@ -// SPDX-License-Identifier: OTHER -// This code is automatically generated with `cargo test --package pallet-nft -- eth::erc::name --exact --nocapture --ignored` - -pragma solidity >=0.8.0 <0.9.0; - -// Common stubs holder -contract Dummy { - uint8 dummy; - string stub_error = "this contract is implemented in native"; -} - -// Inline -contract ERC721Events { - event Transfer(address from, address to, uint256 tokenId); - event Approval(address owner, address approved, uint256 tokenId); - event ApprovalForAll(address owner, address operator, bool approved); -} - -// Inline -contract ERC721MintableEvents { - event MintingFinished(); -} - -// Inline -contract InlineNameSymbol is Dummy { - function name() public view returns (string memory) { - require(false, stub_error); - dummy; - return ""; - } - function symbol() public view returns (string memory) { - require(false, stub_error); - dummy; - return ""; - } -} - -// Inline -contract InlineTotalSupply is Dummy { - function totalSupply() public view returns (uint256) { - require(false, stub_error); - dummy; - return 0; - } -} - -contract ERC165 is Dummy { - function supportsInterface(uint32 interfaceId) public view returns (bool) { - require(false, stub_error); - interfaceId; - dummy; - return false; - } -} - -contract ERC721 is Dummy, ERC165, ERC721Events { - function balanceOf(address owner) public view returns (uint256) { - require(false, stub_error); - owner; - dummy; - return 0; - } - function ownerOf(uint256 tokenId) public view returns (address) { - require(false, stub_error); - tokenId; - dummy; - return 0x0000000000000000000000000000000000000000; - } - function safeTransferFromWithData(address from, address to, uint256 tokenId, bytes memory data) public { - require(false, stub_error); - from; - to; - tokenId; - data; - dummy = 0; - } - function safeTransferFrom(address from, address to, uint256 tokenId) public { - require(false, stub_error); - from; - to; - tokenId; - dummy = 0; - } - function transferFrom(address from, address to, uint256 tokenId) public { - require(false, stub_error); - from; - to; - tokenId; - dummy = 0; - } - function approve(address approved, uint256 tokenId) public { - require(false, stub_error); - approved; - tokenId; - dummy = 0; - } - function setApprovalForAll(address operator, bool approved) public { - require(false, stub_error); - operator; - approved; - dummy = 0; - } - function getApproved(uint256 tokenId) public view returns (address) { - require(false, stub_error); - tokenId; - dummy; - return 0x0000000000000000000000000000000000000000; - } - function isApprovedForAll(address owner, address operator) public view returns (address) { - require(false, stub_error); - owner; - operator; - dummy; - return 0x0000000000000000000000000000000000000000; - } -} - -contract ERC721Burnable is Dummy { - function burn(uint256 tokenId) public { - require(false, stub_error); - tokenId; - dummy = 0; - } -} - -contract ERC721Enumerable is Dummy, InlineTotalSupply { - function tokenByIndex(uint256 index) public view returns (uint256) { - require(false, stub_error); - index; - dummy; - return 0; - } - function tokenOfOwnerByIndex(address owner, uint256 index) public view returns (uint256) { - require(false, stub_error); - owner; - index; - dummy; - return 0; - } -} - -contract ERC721Metadata is Dummy, InlineNameSymbol { - function tokenURI(uint256 tokenId) public view returns (string memory) { - require(false, stub_error); - tokenId; - dummy; - return ""; - } -} - -contract ERC721Mintable is Dummy, ERC721MintableEvents { - function mintingFinished() public view returns (bool) { - require(false, stub_error); - dummy; - return false; - } - function mint(address to, uint256 tokenId) public returns (bool) { - require(false, stub_error); - to; - tokenId; - dummy = 0; - return false; - } - function mintWithTokenURI(address to, uint256 tokenId, string memory tokenUri) public returns (bool) { - require(false, stub_error); - to; - tokenId; - tokenUri; - dummy = 0; - return false; - } - function finishMinting() public returns (bool) { - require(false, stub_error); - dummy = 0; - return false; - } -} - -contract ERC721UniqueExtensions is Dummy { - function transfer(address to, uint256 tokenId) public { - require(false, stub_error); - to; - tokenId; - dummy = 0; - } - function nextTokenId() public view returns (uint256) { - require(false, stub_error); - dummy; - return 0; - } -} - -contract UniqueNFT is Dummy, ERC165, ERC721, ERC721Metadata, ERC721Enumerable, ERC721UniqueExtensions, ERC721Mintable, ERC721Burnable { -} \ No newline at end of file --- a/pallets/nft/src/eth/stubs/Invalid.bin +++ /dev/null @@ -1 +0,0 @@ -TODO \ No newline at end of file --- /dev/null +++ b/pallets/nft/src/eth/stubs/UniqueFungible.sol @@ -0,0 +1,111 @@ +// SPDX-License-Identifier: OTHER +// This code is automatically generated + +pragma solidity >=0.8.0 <0.9.0; + +// Common stubs holder +contract Dummy { + uint8 dummy; + string stub_error = "this contract is implemented in native"; +} + +// Inline +contract ERC20Events { + event Transfer(address indexed from, address indexed to, uint256 value); + event Approval( + address indexed owner, + address indexed spender, + uint256 value + ); +} + +// Inline +contract InlineNameSymbol is Dummy { + function name() public view returns (string memory) { + require(false, stub_error); + dummy; + return ""; + } + + function symbol() public view returns (string memory) { + require(false, stub_error); + dummy; + return ""; + } +} + +// Inline +contract InlineTotalSupply is Dummy { + function totalSupply() public view returns (uint256) { + require(false, stub_error); + dummy; + return 0; + } +} + +contract ERC165 is Dummy { + function supportsInterface(uint32 interfaceId) public view returns (bool) { + require(false, stub_error); + interfaceId; + dummy; + return false; + } +} + +contract ERC20 is Dummy, InlineNameSymbol, InlineTotalSupply, ERC20Events { + function decimals() public view returns (uint8) { + require(false, stub_error); + dummy; + return 0; + } + + function balanceOf(address owner) public view returns (uint256) { + require(false, stub_error); + owner; + dummy; + return 0; + } + + function transfer(address to, uint256 amount) public returns (bool) { + require(false, stub_error); + to; + amount; + dummy = 0; + return false; + } + + function transferFrom( + address from, + address to, + uint256 amount + ) public returns (bool) { + require(false, stub_error); + from; + to; + amount; + dummy = 0; + return false; + } + + function approve(address spender, uint256 amount) public returns (bool) { + require(false, stub_error); + spender; + amount; + dummy = 0; + return false; + } + + function allowance(address owner, address spender) + public + view + returns (uint256) + { + require(false, stub_error); + owner; + spender; + dummy; + return 0; + } +} + +contract UniqueFungible is Dummy, ERC165, ERC20 {} --- /dev/null +++ b/pallets/nft/src/eth/stubs/UniqueInvalid.raw @@ -0,0 +1 @@ +TODO \ No newline at end of file --- /dev/null +++ b/pallets/nft/src/eth/stubs/UniqueNFT.sol @@ -0,0 +1,253 @@ +// SPDX-License-Identifier: OTHER +// This code is automatically generated + +pragma solidity >=0.8.0 <0.9.0; + +// Common stubs holder +contract Dummy { + uint8 dummy; + string stub_error = "this contract is implemented in native"; +} + +// Inline +contract ERC721Events { + event Transfer( + address indexed from, + address indexed to, + uint256 indexed tokenId + ); + event Approval( + address indexed owner, + address indexed approved, + uint256 indexed tokenId + ); + event ApprovalForAll( + address indexed owner, + address indexed operator, + bool approved + ); +} + +// Inline +contract ERC721MintableEvents { + event MintingFinished(); +} + +// Inline +contract InlineNameSymbol is Dummy { + function name() public view returns (string memory) { + require(false, stub_error); + dummy; + return ""; + } + + function symbol() public view returns (string memory) { + require(false, stub_error); + dummy; + return ""; + } +} + +// Inline +contract InlineTotalSupply is Dummy { + function totalSupply() public view returns (uint256) { + require(false, stub_error); + dummy; + return 0; + } +} + +contract ERC165 is Dummy { + function supportsInterface(uint32 interfaceId) public view returns (bool) { + require(false, stub_error); + interfaceId; + dummy; + return false; + } +} + +contract ERC721 is Dummy, ERC165, ERC721Events { + function balanceOf(address owner) public view returns (uint256) { + require(false, stub_error); + owner; + dummy; + return 0; + } + + function ownerOf(uint256 tokenId) public view returns (address) { + require(false, stub_error); + tokenId; + dummy; + return 0x0000000000000000000000000000000000000000; + } + + function safeTransferFromWithData( + address from, + address to, + uint256 tokenId, + bytes memory data + ) public { + require(false, stub_error); + from; + to; + tokenId; + data; + dummy = 0; + } + + function safeTransferFrom( + address from, + address to, + uint256 tokenId + ) public { + require(false, stub_error); + from; + to; + tokenId; + dummy = 0; + } + + function transferFrom( + address from, + address to, + uint256 tokenId + ) public { + require(false, stub_error); + from; + to; + tokenId; + dummy = 0; + } + + function approve(address approved, uint256 tokenId) public { + require(false, stub_error); + approved; + tokenId; + dummy = 0; + } + + function setApprovalForAll(address operator, bool approved) public { + require(false, stub_error); + operator; + approved; + dummy = 0; + } + + function getApproved(uint256 tokenId) public view returns (address) { + require(false, stub_error); + tokenId; + dummy; + return 0x0000000000000000000000000000000000000000; + } + + function isApprovedForAll(address owner, address operator) + public + view + returns (address) + { + require(false, stub_error); + owner; + operator; + dummy; + return 0x0000000000000000000000000000000000000000; + } +} + +contract ERC721Burnable is Dummy { + function burn(uint256 tokenId) public { + require(false, stub_error); + tokenId; + dummy = 0; + } +} + +contract ERC721Enumerable is Dummy, InlineTotalSupply { + function tokenByIndex(uint256 index) public view returns (uint256) { + require(false, stub_error); + index; + dummy; + return 0; + } + + function tokenOfOwnerByIndex(address owner, uint256 index) + public + view + returns (uint256) + { + require(false, stub_error); + owner; + index; + dummy; + return 0; + } +} + +contract ERC721Metadata is Dummy, InlineNameSymbol { + function tokenURI(uint256 tokenId) public view returns (string memory) { + require(false, stub_error); + tokenId; + dummy; + return ""; + } +} + +contract ERC721Mintable is Dummy, ERC721MintableEvents { + function mintingFinished() public view returns (bool) { + require(false, stub_error); + dummy; + return false; + } + + function mint(address to, uint256 tokenId) public returns (bool) { + require(false, stub_error); + to; + tokenId; + dummy = 0; + return false; + } + + function mintWithTokenURI( + address to, + uint256 tokenId, + string memory tokenUri + ) public returns (bool) { + require(false, stub_error); + to; + tokenId; + tokenUri; + dummy = 0; + return false; + } + + function finishMinting() public returns (bool) { + require(false, stub_error); + dummy = 0; + return false; + } +} + +contract ERC721UniqueExtensions is Dummy { + function transfer(address to, uint256 tokenId) public { + require(false, stub_error); + to; + tokenId; + dummy = 0; + } + + function nextTokenId() public view returns (uint256) { + require(false, stub_error); + dummy; + return 0; + } +} + +contract UniqueNFT is + Dummy, + ERC165, + ERC721, + ERC721Metadata, + ERC721Enumerable, + ERC721UniqueExtensions, + ERC721Mintable, + ERC721Burnable +{} --- /dev/null +++ b/pallets/nft/src/eth/stubs/UniqueRefungible.raw @@ -0,0 +1 @@ +TODO \ No newline at end of file --- a/tests/src/eth/api/ContractHelpers.sol +++ b/tests/src/eth/api/ContractHelpers.sol @@ -9,22 +9,35 @@ } interface ContractHelpers is Dummy { - function contractOwner(address contr) external view returns (address); + function contractOwner(address contractAddress) + external + view + returns (address); - function sponsoringEnabled(address contr) external view returns (bool); + function sponsoringEnabled(address contractAddress) + external + view + returns (bool); - function toggleSponsoring(address contr, bool enabled) external; + function toggleSponsoring(address contractAddress, bool enabled) external; - function setSponsoringRateLimit(address contr, uint32 rateLimit) external; + function setSponsoringRateLimit(address contractAddress, uint32 rateLimit) + external; - function allowed(address contr, address user) external view returns (bool); + function allowed(address contractAddress, address user) + external + view + returns (bool); - function allowlistEnabled(address contr) external view returns (bool); + function allowlistEnabled(address contractAddress) + external + view + returns (bool); - function toggleAllowlist(address contr, bool enabled) external; + function toggleAllowlist(address contractAddress, bool enabled) external; function toggleAllowed( - address contr, + address contractAddress, address user, bool allowed ) external;