forked from stakewise/contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardhat.config.js
More file actions
136 lines (121 loc) · 3.59 KB
/
hardhat.config.js
File metadata and controls
136 lines (121 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
const { task, extendEnvironment } = require('hardhat/config');
const { gray, yellow } = require('chalk');
require('@nomiclabs/hardhat-ethers');
require('@openzeppelin/hardhat-upgrades');
require('@nomiclabs/hardhat-truffle5');
require('solidity-coverage');
require('hardhat-gas-reporter');
require('hardhat-contract-sizer');
require('hardhat-abi-exporter');
const optimizerRuns = 10000000;
const log = (...text) => console.log(gray(...['└─> [DEBUG]'].concat(text)));
extendEnvironment((hre) => {
hre.log = log;
});
function optimizeIfRequired({ hre, taskArguments: { optimizer } }) {
if (optimizer || hre.optimizer) {
// only show message once if re-run
if (hre.optimizer === undefined) {
console.log(
gray('Adding optimizer, runs', yellow(optimizerRuns.toString()))
);
}
// Use optimizer (slower) but simulates real contract size limits and gas usage
hre.config.solidity.compilers[0].settings.optimizer = {
enabled: true,
runs: optimizerRuns,
};
hre.config.networks.hardhat.allowUnlimitedContractSize = false;
} else {
if (hre.optimizer === undefined) {
console.log(
gray('Optimizer disabled. Unlimited contract sizes allowed.')
);
}
hre.config.solidity.compilers[0].settings.optimizer = { enabled: false };
hre.config.networks.hardhat.allowUnlimitedContractSize = true;
}
// flag here so that if invoked via "hardhat test" the argument will persist to the compile stage
hre.optimizer = !!optimizer;
}
task('compile')
.addFlag('optimizer', 'Compile with the optimizer')
.setAction(async (taskArguments, hre, runSuper) => {
optimizeIfRequired({ hre, taskArguments });
await runSuper(taskArguments);
});
task('test')
.addFlag('optimizer', 'Compile with the optimizer')
.addFlag('gas', 'Compile gas usage')
.addOptionalParam('grep', 'Filter tests to only those with given logic')
.setAction(async (taskArguments, hre, runSuper) => {
const { gas, grep } = taskArguments;
optimizeIfRequired({ hre, taskArguments });
if (grep) {
console.log(gray('Filtering tests to those containing'), yellow(grep));
hre.config.mocha.grep = grep;
}
if (gas) {
console.log(
gray(`Enabling ${yellow('gas')} reports, tests will run slower`)
);
hre.config.gasReporter.enabled = true;
hre.config.mocha.timeout = 180000;
}
// suppress logs for tests
hre.config.suppressLogs = true;
await runSuper(taskArguments);
});
const GAS_PRICE = 20e9; // 20 Gwei
module.exports = {
solidity: {
version: '0.7.5',
},
networks: {
hardhat: {
blockGasLimit: 0x1fffffffffffff,
gasPrice: GAS_PRICE,
allowUnlimitedContractSize: true,
},
coverage: {
url: 'http://localhost:8555',
blockGasLimit: 0x1fffffffffffff,
gasPrice: GAS_PRICE,
allowUnlimitedContractSize: true,
},
local: {
url: 'http://localhost:8545',
blockGasLimit: 0x1fffffffffffff,
gasPrice: GAS_PRICE,
allowUnlimitedContractSize: true,
},
},
throwOnTransactionFailures: true,
gasReporter: {
enabled: false,
showTimeSpent: true,
currency: 'USD',
maxMethodDiff: 25, // CI will fail if gas usage is > than this %
},
abiExporter: {
path: './abi',
only: [
'IAdmins',
'IBalanceReporters',
'IManagers',
'IOperators',
'IPayments',
'ISettings',
'IERC20',
'IStakedEthToken',
'IRewardEthToken',
'IStakedTokens',
'IValidatorRegistration',
'IValidators',
'ISolos',
'IPool',
],
clear: true,
flat: true,
},
};