diff --git a/contracts/interfaces/IDiamondInit.sol b/contracts/interfaces/IDiamondInit.sol new file mode 100644 index 0000000..8bdaa5b --- /dev/null +++ b/contracts/interfaces/IDiamondInit.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +interface IDiamondInit { + function init() external; +} \ No newline at end of file diff --git a/contracts/upgradeInitializers/DiamondInit.sol b/contracts/upgradeInitializers/DiamondInit.sol index 1a9ed48..7464748 100644 --- a/contracts/upgradeInitializers/DiamondInit.sol +++ b/contracts/upgradeInitializers/DiamondInit.sol @@ -13,12 +13,13 @@ import { IDiamondLoupe } from "../interfaces/IDiamondLoupe.sol"; import { IDiamondCut } from "../interfaces/IDiamondCut.sol"; import { IERC173 } from "../interfaces/IERC173.sol"; import { IERC165 } from "../interfaces/IERC165.sol"; +import {IDiamondInit} from "../interfaces/IDiamondInit.sol"; // It is exapected that this contract is customized if you want to deploy your diamond // with data from a deployment script. Use the init function to initialize state variables // of your diamond. Add parameters to the init funciton if you need to. -contract DiamondInit { +contract DiamondInit is IDiamondInit { // You can add parameters to this function in order to pass in // data to set your own state variables @@ -37,6 +38,4 @@ contract DiamondInit { // in order to set state variables in the diamond during deployment or an upgrade // More info here: https://eips.ethereum.org/EIPS/eip-2535#diamond-interface } - - } \ No newline at end of file diff --git a/package.json b/package.json index 9b18441..8712008 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { "name": "hardhat-project", "dependencies": { - "@nomiclabs/hardhat-ethers": "^2.0.6" + "@nomiclabs/hardhat-ethers": "^2.0.6", + "ethers": "^5.6.9" } } diff --git a/scripts/genSelectors.js b/scripts/genSelectors.js index a2108d8..6b9b979 100644 --- a/scripts/genSelectors.js +++ b/scripts/genSelectors.js @@ -1,36 +1,45 @@ -const { artifacts, ethers } = require('hardhat') -const hre = require('hardhat') -const args = process.argv.slice(2) +const ethers = require("ethers"); +const path = require("path/posix"); + +const args = process.argv.slice(2); if (args.length != 1) { console.log(`please supply the correct parameters: facetName - `) - process.exit(1) + `); + process.exit(1); } -async function printSelectors(contractName) { - const target = await ethers.getContractFactory(contractName) - const signatures = Object.keys(target.interface.functions) +async function printSelectors(contractName, artifactFolderPath = "../out") { + const contractFilePath = path.join( + artifactFolderPath, + `${contractName}.sol`, + `${contractName}.json` + ); + const contractArtifact = require(contractFilePath); + const abi = contractArtifact.abi; + const bytecode = contractArtifact.bytecode; + const target = new ethers.ContractFactory(abi, bytecode); + const signatures = Object.keys(target.interface.functions); const selectors = signatures.reduce((acc, val) => { - if (val !== 'init(bytes)') { - acc.push(target.interface.getSighash(val)) + if (val !== "init(bytes)") { + acc.push(target.interface.getSighash(val)); } - return acc - }, []) + return acc; + }, []); - const coder = ethers.utils.defaultAbiCoder - const coded = coder.encode(['bytes4[]'], [selectors]) + const coder = ethers.utils.defaultAbiCoder; + const coded = coder.encode(["bytes4[]"], [selectors]); - process.stdout.write(coded) + process.stdout.write(coded); } // We recommend this pattern to be able to use async/await everywhere // and properly handle errors. -printSelectors(args[0]) +printSelectors(args[0], args[1]) .then(() => process.exit(0)) .catch((error) => { - console.error(error) - process.exit(1) - }) + console.error(error); + process.exit(1); + });