From d7799bbc5152ed3cc0f0f3044d3ab2b914194316 Mon Sep 17 00:00:00 2001 From: Oleh Hryb Date: Mon, 29 Jan 2024 17:13:08 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20refactor=20ERC721STD,=20?= =?UTF-8?q?script=20to=20generate=20data=20for=20STS=20dep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contracts/package/tokens/ERC721STD.sol | 18 ++++++------ hardhat.config.ts | 13 +++++++-- scripts/prepareContractData.ts | 39 ++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 scripts/prepareContractData.ts diff --git a/contracts/package/tokens/ERC721STD.sol b/contracts/package/tokens/ERC721STD.sol index ec2a80a..38838a3 100644 --- a/contracts/package/tokens/ERC721STD.sol +++ b/contracts/package/tokens/ERC721STD.sol @@ -10,8 +10,6 @@ import '../royalty/DerivedERC2981Royalty.sol'; import "@openzeppelin/contracts/access/extensions/AccessControlEnumerable.sol"; import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol"; -import "hardhat/console.sol"; - contract ERC721STD is ERC721Burnable, ERC5169, @@ -20,7 +18,7 @@ contract ERC721STD is ERC721URIStorage, ERC721Enumerable { - bytes32 private constant MINTER_ROLE = keccak256("MINTER_ROLE"); + bytes32 private constant _MINTER_ROLE = keccak256("MINTER_ROLE"); string public contractURI; string public baseURI; @@ -28,7 +26,7 @@ contract ERC721STD is uint public royaltyPercentage; uint public nextTokenId; - event contractUriChanged(string newURI); + event ContractUriChanged(string newURI); event RoyaltyDataChanged(address addr, uint percentage); error TooHighRoyaltyPercentage(); @@ -36,14 +34,14 @@ contract ERC721STD is constructor(string memory _name, string memory _symbol) ERC721(_name, _symbol) { _grantRole(DEFAULT_ADMIN_ROLE, msg.sender); - _grantRole(MINTER_ROLE, msg.sender); + _grantRole(_MINTER_ROLE, msg.sender); _setRoyaltyData(msg.sender, 5 * 100); } function _authorizeSetScripts(string[] memory) internal virtual override onlyRole(DEFAULT_ADMIN_ROLE) {} // function isMinter(address _account) public view returns (bool) { - // return hasRole(MINTER_ROLE, _account); + // return hasRole(_MINTER_ROLE, _account); // } function owner() public view returns (address) { @@ -76,7 +74,7 @@ contract ERC721STD is function setContractURI(string calldata newURI) external onlyRole(DEFAULT_ADMIN_ROLE){ contractURI = newURI; - emit contractUriChanged(newURI); + emit ContractUriChanged(newURI); } function royaltyInfo(uint256 tokenId, uint256 salePrice) external view override @@ -109,7 +107,7 @@ contract ERC721STD is baseURI = newBaseUri; } - function setTokenURI(uint256 tokenId, string memory _tokenURI) external onlyRole(MINTER_ROLE){ + function setTokenURI(uint256 tokenId, string memory _tokenURI) external onlyRole(_MINTER_ROLE){ _setTokenURI(tokenId, _tokenURI); } @@ -121,7 +119,7 @@ contract ERC721STD is @param uri - can be empty string, minter can set the value later tokenId auto-increase */ - function mint(address to, string memory uri) external onlyRole(MINTER_ROLE){ + function mint(address to, string memory uri) external onlyRole(_MINTER_ROLE){ _mint(to, nextTokenId); if (bytes(uri).length > 0){ _setTokenURI(nextTokenId, uri); @@ -130,6 +128,6 @@ contract ERC721STD is } // function contractURI() external pure returns (string memory){ - // return "https://resources.smarttokenlabs.com/contract/SLN.json"; + // return contractURI; // } } \ No newline at end of file diff --git a/hardhat.config.ts b/hardhat.config.ts index 544a71a..214ba38 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -127,8 +127,14 @@ let config = { url: `https://rinkeby.infura.io/v3/${INFURA_API_KEY}`, accounts: [`${PRIVATE_KEY}`], }, + // "https://rpc-mumbai.maticvigil.com", + // "https://polygon-mumbai-bor.publicnode.com", + // "wss://polygon-mumbai-bor.publicnode.com", + // "https://polygon-mumbai.gateway.tenderly.co", + // "wss://polygon-mumbai.gateway.tenderly.co" + // "https://matic-mumbai.chainstacklabs.com" polygonMumbai: { - url: `https://matic-mumbai.chainstacklabs.com`, //ths RPC seems to work more consistently + url: `https://rpc-mumbai.maticvigil.com`, //ths RPC seems to work more consistently accounts: [`${PRIVATE_KEY}`], }, mainnet: { @@ -167,8 +173,9 @@ let config = { accounts: [`${PRIVATE_KEY}`], }, }, - /* + etherscan: { + enabled: true, // Your API key for Etherscan // Obtain one at https://etherscan.io/ apiKey: { @@ -181,7 +188,7 @@ let config = { optimisticEthereum: `${OPTIMISM_API_KEY}`, }, }, - */ + }; if (argv.gas) { diff --git a/scripts/prepareContractData.ts b/scripts/prepareContractData.ts new file mode 100644 index 0000000..42c6971 --- /dev/null +++ b/scripts/prepareContractData.ts @@ -0,0 +1,39 @@ +import * as fs from 'fs'; +const hre = require("hardhat"); + +async function main(){ + + const contractPath = "contracts/package/tokens/" + const contractName = "ERC721STD" + + const sourceJSON = await hre.run("verify:etherscan-get-minimal-input", { + sourceName: `${contractPath}${contractName}.sol`, + }) + + let contractMeta = { + // title to show on STS + title: "ERC721", + // contract NAME + name: contractName, + verificationName: `${contractPath}${contractName}.sol:${contractName}`, + git: "https://github.com/AlphaWallet/stl-contracts/blob/main/contracts/package/tokens/ERC721STD.sol", + description: "This ERC721 implementation is Mintable, Burnable, Enumerable, use AccessControl, has Metadata control, can change ContractURI, supports ERC5169", + compiler: "v0.8.20+commit.a1b79de6", + codeformat: "solidity-standard-json-input", + // uncomment next line to disable this contract + // disabled: false, + // "0" or "1" + optimizationused: "1", + runs: "200", + content: sourceJSON + } + + const contractJSONData = await fs.promises.readFile(`artifacts/${contractPath}/${contractName}.sol/${contractName}.json`, 'utf8'); + const contractJSON = JSON.parse(contractJSONData) + + contractMeta = Object.assign(contractMeta, contractJSON) + + await fs.promises.writeFile(`./${contractName}.json`, JSON.stringify([contractMeta])); +} +main() +