-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathhardhat.config.js
154 lines (136 loc) · 4.09 KB
/
hardhat.config.js
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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');
require('@nomiclabs/hardhat-etherscan');
const BLOCK_NUMBER = 17769320;
const OPTIMIZER_RUNS = 5000000;
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) {
log(gray('Adding optimizer, runs', yellow(OPTIMIZER_RUNS.toString())));
}
// Use optimizer (slower) but simulates real contract size limits and gas usage
hre.config.solidity.compilers[0].settings.optimizer = {
enabled: true,
runs: OPTIMIZER_RUNS,
};
hre.config.networks.hardhat.allowUnlimitedContractSize = false;
} else {
if (hre.optimizer === undefined) {
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;
}
log(
gray('Mainnet fork with block number', yellow(BLOCK_NUMBER.toString()))
);
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);
});
task('coverage').setAction(async (taskArguments, hre, runSuper) => {
log(gray('Mainnet fork with block number', yellow(BLOCK_NUMBER.toString())));
await runSuper(taskArguments);
});
task('verify')
.addFlag('optimizer', 'Compile with the optimizer')
.setAction(async (taskArguments, hre, runSuper) => {
optimizeIfRequired({ hre, taskArguments });
await runSuper(taskArguments);
});
module.exports = {
solidity: {
version: '0.7.5',
},
networks: {
hardhat: {
forking: {
url: process.env.HARDHAT_FORK_API_URL,
blockNumber: BLOCK_NUMBER,
},
accounts: {
accountsBalance: '1000000000000000000000000',
},
},
local: {
url: 'http://localhost:8545',
},
},
throwOnTransactionFailures: true,
gasReporter: {
enabled: false,
showTimeSpent: true,
currency: 'USD',
maxMethodDiff: 25, // CI will fail if gas usage is > than this %
excludeContracts: ['mocks/'],
},
abiExporter: {
path: './abi',
only: [
'AccessControl',
'Oracles',
'IDepositContract',
'IERC20Upgradeable',
'Pool',
'PoolEscrow',
'PoolValidators',
'RewardEthToken',
'StakedEthToken',
'StakeWiseToken',
'VestingEscrow',
'VestingEscrowFactory',
'MerkleDrop',
'MerkleDistributor',
'ContractChecker',
'Roles',
'FeesEscrow',
],
clear: true,
flat: true,
},
etherscan: {
apiKey: 'api key goes here',
},
mocha: {
timeout: 1000000,
},
};