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
27 changes: 22 additions & 5 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
[default]
src = 'contracts'
out = 'out'
libs = [
'lib'
libs = ['lib']
remappings = ['@forge-std/=lib/forge-std/', '@contracts/=contracts/']
ffi = true
auto_detect_solc = true
verbosity = 5

[build]
src = 'src'
out = 'bout' # output directory conflicts with dapptools
libs = ['lib']
auto_detect_solc = true
remappings = [
'@utils/=src/utils/',
'@openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/',
'@contracts/=src/contracts/',
'@openzeppelin/=lib/openzeppelin-contracts/',
'ds-test/=lib/ds-test/src/',
'openzeppelin-contracts/=lib/openzeppelin-contracts/',
]
ffi=true
verbosity=5
optimizer = true
optimizer_runs = 200
via_ir = true

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
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"
}
}
2 changes: 2 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@contracts/=/contracts/
@forge-std/=lib/forge-std/
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);
});
3 changes: 2 additions & 1 deletion test/deployDiamond.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import "../contracts/interfaces/IDiamondCut.sol";
import "../contracts/facets/DiamondCutFacet.sol";
import "../contracts/facets/DiamondLoupeFacet.sol";
import "../contracts/facets/OwnershipFacet.sol";
import "../../lib/forge-std/src/Test.sol";

import "../contracts/Diamond.sol";
import "@forge-std/src/Test.sol";

contract DiamondDeployer is Test, IDiamondCut {
//contract types of facets to be deployed
Expand Down