Skip to content

Commit

Permalink
feat: 🎸 refactor ERC721STD, script to generate data for STS dep
Browse files Browse the repository at this point in the history
  • Loading branch information
oleggrib committed Jan 29, 2024
1 parent df7fe83 commit d7799bb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 13 deletions.
18 changes: 8 additions & 10 deletions contracts/package/tokens/ERC721STD.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -20,30 +18,30 @@ 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;
address public royaltyReceiver;
uint public royaltyPercentage;
uint public nextTokenId;

event contractUriChanged(string newURI);
event ContractUriChanged(string newURI);
event RoyaltyDataChanged(address addr, uint percentage);

error TooHighRoyaltyPercentage();
error OneAdminRequired();

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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
Expand All @@ -130,6 +128,6 @@ contract ERC721STD is
}

// function contractURI() external pure returns (string memory){
// return "https://resources.smarttokenlabs.com/contract/SLN.json";
// return contractURI;
// }
}
13 changes: 10 additions & 3 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -167,8 +173,9 @@ let config = {
accounts: [`${PRIVATE_KEY}`],
},
},
/*

etherscan: {
enabled: true,
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: {
Expand All @@ -181,7 +188,7 @@ let config = {
optimisticEthereum: `${OPTIMISM_API_KEY}`,
},
},
*/

};

if (argv.gas) {
Expand Down
39 changes: 39 additions & 0 deletions scripts/prepareContractData.ts
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit d7799bb

Please sign in to comment.