From c9578c88fd60edc13ada58ac285749073938c65d Mon Sep 17 00:00:00 2001 From: zoruka Date: Tue, 29 Nov 2022 11:59:19 -0300 Subject: [PATCH] fix: sintax wise issues for compilation --- contracts/Fleek.sol | 31 -------------- contracts/FleekAccessControl.sol | 19 +-------- contracts/FleekBuilds.sol | 2 +- contracts/FleekERC721.sol | 70 +++++++++++++++++++++++--------- contracts/FleekSite.sol | 35 ---------------- hardhat.config.js | 12 ++++-- interfaces/IFleek.sol | 14 ------- interfaces/IFleekERC721.sol | 29 ------------- interfaces/IFleekSite.sol | 18 -------- package.json | 5 ++- scripts/deploy.js | 20 +++++++-- yarn.lock | 4 +- 12 files changed, 83 insertions(+), 176 deletions(-) delete mode 100644 contracts/Fleek.sol delete mode 100644 contracts/FleekSite.sol delete mode 100644 interfaces/IFleek.sol delete mode 100644 interfaces/IFleekERC721.sol delete mode 100644 interfaces/IFleekSite.sol diff --git a/contracts/Fleek.sol b/contracts/Fleek.sol deleted file mode 100644 index d2879a5..0000000 --- a/contracts/Fleek.sol +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.7; - -import "../interfaces/IFleek.sol"; -import "./FleekBuilds.sol"; -import "./FleekAccessControl.sol"; - -abstract contract Fleek is IFleek, FleekBuilds { - string public name; - string public description; - - constructor(string memory _name, string memory _description) { - name = _name; - description = _description; - } - - function setName( - string calldata _name - ) external override requireController { - name = _name; - emit MetadataUpdated(name, description); - } - - function setDescription( - string calldata _description - ) external override requireController { - description = _description; - emit MetadataUpdated(name, description); - } -} diff --git a/contracts/FleekAccessControl.sol b/contracts/FleekAccessControl.sol index ab8667c..3d6aac5 100644 --- a/contracts/FleekAccessControl.sol +++ b/contracts/FleekAccessControl.sol @@ -2,7 +2,6 @@ pragma solidity ^0.8.7; -import "../interfaces/IFleekSite.sol"; import "@openzeppelin/contracts/access/AccessControl.sol"; abstract contract FleekAccessControl is AccessControl { @@ -26,7 +25,7 @@ abstract contract FleekAccessControl is AccessControl { modifier requireCollectionController() { require( - hasRole(COOLECTION_OWNER_ROLE, msg.sender) || + hasRole(COLLECTION_OWNER_ROLE, msg.sender) || hasRole(COLLECTION_CONTROLLER_ROLE, msg.sender), "FleekAccessControl: must have collection controller role" ); @@ -41,23 +40,9 @@ abstract contract FleekAccessControl is AccessControl { _; } - function addTokenController( - uint256 tokenId, - address controller - ) public require requireMinted(tokenId) requireTokenOwner(tokenId) { - _grantRole(_tokenRole(tokenId, "CONTROLLER"), controller); - } - - function removeTokenController( - uint256 tokenId, - address controller - ) public require requireMinted(tokenId) requireTokenOwner(tokenId) { - _revokeRole(_tokenRole(tokenId, "CONTROLLER"), controller); - } - function _tokenRole( uint256 tokenId, - string role + string memory role ) internal pure returns (bytes32) { return keccak256(abi.encodePacked("TOKEN_", role, tokenId)); } diff --git a/contracts/FleekBuilds.sol b/contracts/FleekBuilds.sol index ecf0aed..0a3a1d1 100644 --- a/contracts/FleekBuilds.sol +++ b/contracts/FleekBuilds.sol @@ -10,7 +10,7 @@ abstract contract FleekBuilds is IFleekBuilds, FleekAccessControl { function update( build calldata _newBuild - ) external override requireController { + ) external override requireCollectionController { builds.push(_newBuild); emit Upgraded(_newBuild); } diff --git a/contracts/FleekERC721.sol b/contracts/FleekERC721.sol index 79acedc..e7be2d2 100644 --- a/contracts/FleekERC721.sol +++ b/contracts/FleekERC721.sol @@ -5,8 +5,6 @@ pragma solidity ^0.8.7; import "@openzeppelin/contracts/token/ERC721/ERC721.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "./FleekAccessControl.sol"; -import "../interfaces/IFleekERC721.sol"; -import "./FleekSite.sol"; contract FleekERC721 is ERC721, FleekAccessControl { using Strings for uint256; @@ -27,8 +25,17 @@ contract FleekERC721 is ERC721, FleekAccessControl { Counters.Counter private _tokenIds; mapping(uint256 => Site) private _sites; - modifier requireMinted(uint256 tokenId) { - require(_requireMinted(tokenId), "FleekERC721: token not minted"); + constructor( + string memory _name, + string memory _symbol + ) ERC721(_name, _symbol) {} + + modifier requireTokenOwner(uint256 tokenId) { + require( + msg.sender == ownerOf(tokenId), + "FleekERC721: must be token owner" + ); + _; } function mint( @@ -42,7 +49,10 @@ contract FleekERC721 is ERC721, FleekAccessControl { _mint(to, tokenId); addTokenController(tokenId, to); _tokenIds.increment(); - _sites[tokenId] = Site(URI, ENS, 0, [Build(commit, repository)]); + + Build[] memory _builds = new Build[](1); + _builds[0] = Build(commit, repository); + _sites[tokenId] = Site(URI, ENS, 0, _builds); return tokenId; } @@ -50,21 +60,16 @@ contract FleekERC721 is ERC721, FleekAccessControl { uint256 tokenId, string memory commit, string memory repository - ) public payable require requireMinted(tokenId) requireTokenOwner(tokenId) { - _setTokenBuild(commit, repository); + ) public payable requireTokenOwner(tokenId) { + _requireMinted(tokenId); + _setTokenBuild(tokenId, commit, repository); } function tokenURI( uint256 tokenId - ) - public - view - virtual - override - requireMinted(tokenId) - returns (string memory) - { - address memory owner = ownerOf(tokenId); + ) public view virtual override returns (string memory) { + _requireMinted(tokenId); + address owner = ownerOf(tokenId); Site memory site = _sites[tokenId]; // prettier-ignore @@ -84,6 +89,28 @@ contract FleekERC721 is ERC721, FleekAccessControl { return string(abi.encodePacked(_baseURI(), dataURI)); } + function addTokenController( + uint256 tokenId, + address controller + ) public requireTokenOwner(tokenId) { + _requireMinted(tokenId); + _grantRole(_tokenRole(tokenId, "CONTROLLER"), controller); + } + + function removeTokenController( + uint256 tokenId, + address controller + ) public requireTokenOwner(tokenId) { + _requireMinted(tokenId); + _revokeRole(_tokenRole(tokenId, "CONTROLLER"), controller); + } + + function supportsInterface( + bytes4 interfaceId + ) public view virtual override(ERC721, AccessControl) returns (bool) { + return super.supportsInterface(interfaceId); + } + function _baseURI() internal view virtual override returns (string memory) { return "data:application/json;base64,"; } @@ -91,14 +118,16 @@ contract FleekERC721 is ERC721, FleekAccessControl { function _setTokenURI( uint256 tokenId, string memory _tokenURI - ) internal virtual requireMinted(tokenId) requireTokenController(tokenId) { + ) internal virtual requireTokenController(tokenId) { + _requireMinted(tokenId); _sites[tokenId].URI = _tokenURI; } function _setTokenENS( uint256 tokenId, string memory _tokenENS - ) internal virtual requireMinted(tokenId) requireTokenController(tokenId) { + ) internal virtual requireTokenController(tokenId) { + _requireMinted(tokenId); _sites[tokenId].ENS = _tokenENS; } @@ -106,7 +135,8 @@ contract FleekERC721 is ERC721, FleekAccessControl { uint256 tokenId, string memory _commit, string memory _repository - ) internal virtual requireMinted(tokenId) requireTokenController(tokenId) { + ) internal virtual requireTokenController(tokenId) { + _requireMinted(tokenId); _sites[tokenId].builds.push(Build(_commit, _repository)); _sites[tokenId].currentBuild = _sites[tokenId].builds.length - 1; } @@ -118,7 +148,7 @@ contract FleekERC721 is ERC721, FleekAccessControl { ); super._burn(tokenId); - if (bytes(_sites[tokenId]).length != 0) { + if (bytes(_sites[tokenId].URI).length != 0) { delete _sites[tokenId]; } } diff --git a/contracts/FleekSite.sol b/contracts/FleekSite.sol deleted file mode 100644 index 15ff6d4..0000000 --- a/contracts/FleekSite.sol +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.7; - -import "./Fleek.sol"; -import "../interfaces/IFleekSite.sol"; - -contract FleekSite is IFleekSite, Fleek { - string public thumbnail; - string public external_url; - - constructor( - string memory _name, - string memory _description, - string memory _thumbnail, - string memory _external_url - ) Fleek(_name, _description) { - thumbnail = _thumbnail; - external_url = _external_url; - } - - function setThumbnail( - string calldata _thumbnail - ) external override requireController { - thumbnail = _thumbnail; - emit MetadataUpdated(name, description, thumbnail, external_url); - } - - function setExternalUrl( - string calldata _external_url - ) external override requireController { - external_url = _external_url; - emit MetadataUpdated(name, description, thumbnail, external_url); - } -} diff --git a/hardhat.config.js b/hardhat.config.js index 1bb40f9..b83d321 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -1,5 +1,6 @@ require('@nomiclabs/hardhat-waffle'); require('@nomiclabs/hardhat-etherscan'); +require('@nomiclabs/hardhat-ethers'); require('hardhat-deploy'); require('solidity-coverage'); require('hardhat-gas-reporter'); @@ -22,8 +23,7 @@ const POLYGON_MAINNET_RPC_URL = 'https://polygon-mainnet.alchemyapi.io/v2/your-api-key'; const POLYGON_MUMBAI_RPC_URL = - process.env.POLYGON_MUMBAI_RPC_URL || - 'https://polygon-mumbai.g.alchemy.com/v2/aIjNlC4r4aLYOHrdCTFT_JUX6OJsOsu0'; + process.env.API_KEY || 'https://polygon-mumbai.g.alchemy.com/v2/your-api-key'; const PRIVATE_KEY = process.env.PRIVATE_KEY || '0x'; // optional const MNEMONIC = process.env.MNEMONIC || 'your mnemonic'; @@ -36,14 +36,14 @@ const POLYGONSCAN_API_KEY = const REPORT_GAS = process.env.REPORT_GAS || false; module.exports = { - defaultNetwork: 'hardhat', + defaultNetwork: 'polygon_mumbai', networks: { hardhat: { // // If you want to do some forking, uncomment this // forking: { // url: MAINNET_RPC_URL // } - chainId: 31337, + // chainId: 31337, }, localhost: { chainId: 31337, @@ -78,6 +78,10 @@ module.exports = { // saveDeployments: true, // chainId: 80001, // } + polygon_mumbai: { + url: POLYGON_MUMBAI_RPC_URL, + accounts: [`0x${PRIVATE_KEY}`], + }, }, etherscan: { // npx hardhat verify --network diff --git a/interfaces/IFleek.sol b/interfaces/IFleek.sol deleted file mode 100644 index a0fd37f..0000000 --- a/interfaces/IFleek.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.7; - -import "./IFleekBuilds.sol"; -import "../node_modules/@openzeppelin/contracts/access/IAccessControl.sol"; - -interface IFleek is IFleekBuilds, IAccessControl { - event MetadataUpdated(string name, string description); - - function setName(string calldata _name) external; - - function setDescription(string calldata _description) external; -} diff --git a/interfaces/IFleekERC721.sol b/interfaces/IFleekERC721.sol deleted file mode 100644 index 877eed7..0000000 --- a/interfaces/IFleekERC721.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.7; - -import "../node_modules/@openzeppelin/contracts/interfaces/IERC721.sol"; -import "../node_modules/@openzeppelin/contracts/access/IAccessControl.sol"; - -/// @title IFleekERC721 - A contract for managing sites NFTs -interface IFleekERC721 is IERC721 { - enum FleekContract { - Site - } - - function mint( - uint8 fleekContract, - string memory base64EncodedMetadata, - address account - ) external returns (uint256); - - function updateTokenURI( - address tokenHolderAddress, - uint256 tokenId, - string memory base64EncodedMetadata - ) external; - - function getCurrentTokenId() external view returns (uint256); - - function tokenContract(uint256 tokenId) external view returns (address); -} diff --git a/interfaces/IFleekSite.sol b/interfaces/IFleekSite.sol deleted file mode 100644 index 997c8a6..0000000 --- a/interfaces/IFleekSite.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.7; - -import "./IFleek.sol"; - -interface IFleekSite is IFleek { - event MetadataUpdated( - string name, - string description, - string thumbnail, - string external_url - ); - - function setThumbnail(string calldata _thumbnail) external; - - function setExternalUrl(string calldata _external_url) external; -} diff --git a/package.json b/package.json index 9466ecc..9cc743f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "test": "hardhat test", - "format": "prettier --write \"./**/*.{js,ts,sol}\"" + "format": "prettier --write \"./**/*.{js,ts,sol}\"", + "deploy:mumbai": "node scripts/deploy.js --network polygon_mumbai --contract FleekERC721 --param \"Fleek Sites Test\" --param FST" }, "repository": { "type": "git", @@ -26,10 +27,12 @@ "chai": "^4.3.6", "dotenv": "^16.0.2", "ethereum-waffle": "^3.4.4", + "ethers": "^5.0.0", "hardhat": "^2.11.2", "hardhat-contract-sizer": "^2.6.1", "hardhat-deploy": "^0.11.15", "hardhat-gas-reporter": "^1.0.9", + "minimist": "^1.2.7", "prettier": "^2.7.1", "prettier-plugin-solidity": "^1.0.0", "solidity-coverage": "^0.8.2" diff --git a/scripts/deploy.js b/scripts/deploy.js index e02e118..fea61c0 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.js @@ -1,14 +1,26 @@ +const argv = require('minimist')(process.argv.slice(2)); +const contractName = argv.contract; +const params = argv.param || []; + +if (!contractName) { + console.log('No contract name provided'); + process.exit(1); +} + async function main() { + console.log('Deploying contract:', contractName); + console.log('With params:', params); + const [deployer] = await ethers.getSigners(); console.log('Deploying contracts with the account:', deployer.address); - console.log('Account balance:', (await deployer.getBalance()).toString()); - const SitesNFTs = await ethers.getContractFactory('SitesNFTs'); - const sitesNFTs = await SitesNFTs.deploy('Sites NFTs', 'SNFT'); + // const factory = await ethers.getContractFactory(contractName); - console.log('SitesNFTs address:', sitesNFTs.address); + // // Start deployment, returning a promise that resolves to a contract object + // const contract = await factory.deploy(...params); + // console.log('Contract deployed to address:', contract.address); } main() diff --git a/yarn.lock b/yarn.lock index 689137b..68e2085 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3759,7 +3759,7 @@ ethers@^4.0.40: uuid "2.0.1" xmlhttprequest "1.8.0" -ethers@^5.0.1, ethers@^5.0.2, ethers@^5.5.2, ethers@^5.5.3: +ethers@^5.0.0, ethers@^5.0.1, ethers@^5.0.2, ethers@^5.5.2, ethers@^5.5.3: version "5.7.2" resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.7.2.tgz#3a7deeabbb8c030d4126b24f84e525466145872e" integrity sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg== @@ -6056,7 +6056,7 @@ minimatch@5.0.1: dependencies: brace-expansion "^2.0.1" -minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6, minimist@~1.2.6: +minimist@^1.2.0, minimist@^1.2.5, minimist@^1.2.6, minimist@^1.2.7, minimist@~1.2.6: version "1.2.7" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.7.tgz#daa1c4d91f507390437c6a8bc01078e7000c4d18" integrity sha512-bzfL1YUZsP41gmu/qjrEk0Q6i2ix/cVeAhbCbqH9u3zYutS1cLg00qhrD0M2MVdCcx4Sc0UpP2eBWo9rotpq6g==