Skip to content

Commit ec045d1

Browse files
committed
started moving to hardhat
1 parent cd89cc4 commit ec045d1

8 files changed

+19625
-11573
lines changed

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ node_modules
1313
/spec_hbbft.json
1414
/spec_validatorset.json
1515

16+
#hardhat specific files
17+
artifacts
18+
cache
19+
src
20+
1621
# Emacs backups
1722
\#*#
1823
.#*
@@ -24,4 +29,5 @@ node_modules
2429
# hbbft-posdao-contracts specific files
2530
.network
2631
.pk
27-
.mnemonic*
32+
.mnemonic*
33+
.env*

hardhat.config.ts

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
import "@nomicfoundation/hardhat-toolbox";
2+
import "@nomicfoundation/hardhat-chai-matchers";
3+
import "@nomiclabs/hardhat-ethers";
4+
import "@nomiclabs/hardhat-etherscan";
5+
import "@typechain/hardhat";
6+
import "hardhat-gas-reporter";
7+
import "solidity-coverage";
8+
import "hardhat-contract-sizer";
9+
import "@openzeppelin/hardhat-upgrades";
10+
import { config as dotenvConfig } from "dotenv";
11+
import type { NetworkUserConfig } from "hardhat/types";
12+
// ToDo::check why config excluding gas reporter and typechain
13+
import type { HardhatUserConfig } from "hardhat/config";
14+
import { resolve } from "path";
15+
16+
const dotenvConfigPath: string = process.env.DOTENV_CONFIG_PATH || "./.env";
17+
dotenvConfig({ path: resolve(__dirname, dotenvConfigPath) });
18+
19+
// ToDo::change require to smth more suitable
20+
require('./tasks');
21+
22+
// Ensure that we have all the environment variables we need.
23+
const mnemonic: string | undefined = process.env.MNEMONIC;
24+
if (!mnemonic) {
25+
throw new Error("Please set your MNEMONIC in a .env file");
26+
}
27+
28+
const infuraApiKey: string | undefined = process.env.INFURA_API_KEY;
29+
if (!infuraApiKey) {
30+
throw new Error("Please set your INFURA_API_KEY in a .env file");
31+
}
32+
33+
const chainIds = {
34+
"arbitrum-mainnet": 42161,
35+
avalanche: 43114,
36+
bsc: 56,
37+
ganache: 1337,
38+
goerli: 5,
39+
kovan: 42,
40+
hardhat: 31337,
41+
mainnet: 1,
42+
"optimism-mainnet": 10,
43+
"polygon-mainnet": 137,
44+
"polygon-mumbai": 80001,
45+
};
46+
47+
function getChainConfig(chain: keyof typeof chainIds): NetworkUserConfig {
48+
let jsonRpcUrl: string;
49+
switch (chain) {
50+
case "avalanche":
51+
jsonRpcUrl = "https://api.avax.network/ext/bc/C/rpc";
52+
break;
53+
case "bsc":
54+
jsonRpcUrl = "https://bsc-dataseed1.binance.org";
55+
break;
56+
default:
57+
jsonRpcUrl = "https://" + chain + ".infura.io/v3/" + infuraApiKey;
58+
}
59+
return {
60+
accounts: {
61+
count: 10,
62+
mnemonic,
63+
path: "m/44'/60'/0'/0",
64+
},
65+
chainId: chainIds[chain],
66+
gas: 21_000_000_000,
67+
gasPrice: 8000000000,
68+
allowUnlimitedContractSize: true,
69+
blockGasLimit: 100000000429720,
70+
url: jsonRpcUrl,
71+
};
72+
}
73+
74+
const config: {} = {
75+
defaultNetwork: "hardhat",
76+
etherscan: {
77+
apiKey: {
78+
arbitrumOne: process.env.ARBISCAN_API_KEY || "",
79+
avalanche: process.env.SNOWTRACE_API_KEY || "",
80+
bsc: process.env.BSCSCAN_API_KEY || "",
81+
goerli: process.env.ETHERSCAN_API_KEY || "",
82+
mainnet: process.env.ETHERSCAN_API_KEY || "",
83+
optimisticEthereum: process.env.OPTIMISM_API_KEY || "",
84+
polygon: process.env.POLYGONSCAN_API_KEY || "",
85+
polygonMumbai: process.env.POLYGONSCAN_API_KEY || "",
86+
},
87+
},
88+
contractSizer: {
89+
alphaSort: true,
90+
runOnCompile: true,
91+
disambiguatePaths: false,
92+
},
93+
gasReporter: {
94+
currency: "USD",
95+
enabled: process.env.REPORT_GAS ? true : false,
96+
excludeContracts: [],
97+
src: "./contracts",
98+
},
99+
networks: {
100+
hardhat: {
101+
accounts: {
102+
mnemonic,
103+
},
104+
chainId: chainIds.hardhat,
105+
},
106+
arbitrum: getChainConfig("arbitrum-mainnet"),
107+
avalanche: getChainConfig("avalanche"),
108+
bsc: getChainConfig("bsc"),
109+
goerli: getChainConfig("goerli"),
110+
mainnet: getChainConfig("mainnet"),
111+
optimism: getChainConfig("optimism-mainnet"),
112+
"polygon-mainnet": getChainConfig("polygon-mainnet"),
113+
"polygon-mumbai": getChainConfig("polygon-mumbai"),
114+
},
115+
paths: {
116+
artifacts: "./artifacts",
117+
cache: "./cache",
118+
sources: "./contracts",
119+
tests: "./test",
120+
},
121+
solidity: {
122+
version: "0.5.16",
123+
settings: {
124+
// viaIR: true,
125+
metadata: {
126+
// Not including the metadata hash
127+
// https://github.com/paulrberg/hardhat-template/issues/31
128+
bytecodeHash: "none",
129+
},
130+
// Disable the optimizer when debugging
131+
// https://hardhat.org/hardhat-network/#solidity-optimizer-support
132+
optimizer: {
133+
enabled: true,
134+
runs: 0,
135+
},
136+
},
137+
},
138+
typechain: {
139+
outDir: "src/types",
140+
target: "ethers-v5",
141+
},
142+
};
143+
144+
export default config;

0 commit comments

Comments
 (0)