Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions contracts/interfaces/IDiamondInit.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IDiamondInit {
function init() external;
}
5 changes: 2 additions & 3 deletions contracts/upgradeInitializers/DiamondInit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}


}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "hardhat-project",
"dependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.6"
"@nomiclabs/hardhat-ethers": "^2.0.6",
"ethers": "^5.6.9"
}
}
47 changes: 28 additions & 19 deletions scripts/genSelectors.js
Original file line number Diff line number Diff line change
@@ -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);
});