-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardhat.config.js
318 lines (297 loc) · 7.95 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
const fs = require('fs')
const path = require('path')
const { TASK_COMPILE } = require('hardhat/builtin-tasks/task-names')
const dotenv = require('dotenv');
dotenv.config()
require('@aragon/hardhat-aragon')
require('@nomiclabs/hardhat-web3')
require('@nomiclabs/hardhat-ethers')
require('@nomiclabs/hardhat-truffle5')
require('@nomiclabs/hardhat-ganache')
require('@nomiclabs/hardhat-etherscan')
require('hardhat-gas-reporter')
require('solidity-coverage')
require('hardhat-contract-sizer')
require('hardhat-ignore-warnings')
require('./foundry/skip-sol-tests-compilation')
require('./task/task')
const NETWORK_NAME = getNetworkName()
const DEPLOYER_PK = process.env.DEPLOYER_PK
const ETH_ACCOUNT_NAME = process.env.ETH_ACCOUNT_NAME
const RPC_URL = process.env.RPC_URL
// eslint-disable-next-line no-undef
task('accounts', 'Prints the list of accounts', async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners()
for (const account of accounts) {
console.log(account.address)
}
})
const accounts = readJson(`./accounts.json`) || {
eth: { dev: 'remote' },
etherscan: { apiKey: undefined },
infura: { projectId: undefined },
infura_ipfs: { projectId: undefined, projectSecret: undefined },
}
const getNetConfig = (networkName, ethAccountName) => {
const netState = readJson(`./deployed-${networkName}.json`) || {}
const ethAccts = accounts.eth || {}
if (RPC_URL === undefined && networkName !== 'hardhat') {
console.error('ERROR: RPC_URL env variable is not set')
process.exit(1)
}
const base = {
accounts:
ethAccountName === 'remote'
? 'remote'
: ethAccts[ethAccountName] || ethAccts[networkName] || ethAccts.dev || 'remote',
ensAddress: netState.ensAddress,
timeout: 60000,
}
const byNetName = {
mainnetfork: {
...base,
url: RPC_URL,
},
goerlifork: {
...base,
url: RPC_URL,
},
local: {
url: RPC_URL,
gasPrice: 10000,
},
hardhat: {
// NB!: forking get enabled if env variable HARDHAT_FORKING_URL is set, see code below
blockGasLimit: 30000000,
gasPrice: 0,
initialBaseFeePerGas: 0,
allowUnlimitedContractSize: true,
accounts: {
// default hardhat's node mnemonic
mnemonic: 'test test test test test test test test test test test junk',
count: 30,
accountsBalance: '100000000000000000000000',
gasPrice: 0,
},
},
ace_devnet: {
...base,
// url: 'http://20.197.51.29:8545',
url: RPC_URL,
// ensAddress: netState.ensAddress,
timeout: 60000 * 15,
chainId: 6480000002,
accounts: [process.env.DEPLOYER_PK],
// gasPrice: 1010000000,
// gas: 3000000,
},
ace_mainnet: {
...base,
// url: 'http://20.197.13.207:8545',
url: RPC_URL,
timeout: 60000 * 15,
chainId: 648,
// ensAddress: netState.ensAddress,
accounts: [process.env.DEPLOYER_PK],
// gasPrice: 10100,
// gas: 1000000,
},
goerli: {
...base,
url: RPC_URL,
chainId: 5,
timeout: 60000 * 10,
},
goerlidebug: {
...base,
url: RPC_URL,
chainId: 5,
timeout: 60000 * 15,
},
holesky: {
...base,
url: RPC_URL,
accounts: ['f11a771308f235a1331b098d0212db69ac049e56c9f1e0da739a39e8b743363c'],
chainId: 17000,
timeout: 60000 * 15,
},
mainnet: {
...base,
url: RPC_URL,
chainId: 1,
timeout: 60000 * 10,
},
fork: {
...base,
chainId: 1,
timeout: 60000 * 10,
forking: {
url: RPC_URL,
},
},
}
const netConfig = byNetName[networkName]
if (networkName === 'hardhat' && process.env.HARDHAT_FORKING_URL) {
netConfig.forking = { url: process.env.HARDHAT_FORKING_URL }
}
return netConfig ? { [networkName]: netConfig } : {}
}
const solcSettings4 = {
optimizer: {
enabled: true,
runs: 200,
},
evmVersion: 'constantinople',
}
const solcSettings6 = {
optimizer: {
enabled: true,
runs: 200,
},
evmVersion: 'istanbul',
}
const solcSettings8 = {
optimizer: {
enabled: true,
runs: 200,
},
evmVersion: 'istanbul',
}
module.exports = {
defaultNetwork: NETWORK_NAME,
networks: getNetConfig(NETWORK_NAME, ETH_ACCOUNT_NAME),
timeout: 100000,
solidity: {
compilers: [
{
version: '0.4.24',
settings: solcSettings4,
},
{
version: '0.6.11',
settings: solcSettings6,
},
{
version: '0.6.12',
settings: solcSettings6,
},
{
version: '0.8.4',
settings: solcSettings8,
},
{
version: '0.8.9',
settings: solcSettings8,
},
],
overrides: {
'contracts/0.6.11/deposit_contract.sol': {
version: '0.6.11',
settings: {
optimizer: {
enabled: true,
runs: 5000000, // https://etherscan.io/address/0x00000000219ab540356cbb839cbe05303d7705fa#code
},
},
},
'contracts/0.4.24/test_helpers/MinFirstAllocationStrategyConsumerMockLegacyVersion.sol': {
version: '0.4.24',
settings: {},
},
},
},
warnings: {
'@aragon/**/*': {
default: 'off',
},
'contracts/*/test_helpers/**/*': {
default: 'off',
},
},
gasReporter: {
enabled: !!process.env.REPORT_GAS,
currency: 'USD',
},
etherscan: {
apiKey: accounts.etherscan.apiKey,
customChains: [
{
network: 'holesky',
chainId: 17000,
urls: {
apiURL: 'https://api-holesky.etherscan.io/api',
browserURL: 'https://holesky.etherscan.io',
},
},
],
},
ipfs: {
url: process.env.IPFS_API_URL || 'https://ipfs.infura.io:5001/api/v0',
gateway: process.env.IPFS_GATEWAY_URL || 'https://ipfs.io/',
pinata: {
key: 'YOUR_PINATA_API_KEY',
secret: 'YOUR_PINATA_API_SECRET_KEY',
},
},
contractSizer: {
disambiguatePaths: false,
runOnCompile: true,
strict: true,
except: ['test_helpers', 'template', 'mocks', '@aragon', 'openzeppelin'],
},
}
function getNetworkName() {
if (process.env.HARDHAT_NETWORK) {
// Hardhat passes the network to its subprocesses via this env var
return process.env.HARDHAT_NETWORK
}
const networkArgIndex = process.argv.indexOf('--network')
return networkArgIndex !== -1 && networkArgIndex + 1 < process.argv.length
? process.argv[networkArgIndex + 1]
: process.env.NETWORK_NAME || 'hardhat'
}
function readJson(fileName) {
let data
try {
const filePath = path.join(__dirname, fileName)
data = fs.readFileSync(filePath)
} catch (err) {
return null
}
return JSON.parse(data)
}
if (typeof task === 'function') {
require('./scripts/hardhat-tasks')
}
// eslint-disable-next-line no-undef
task(TASK_COMPILE).setAction(async function (args, hre, runSuper) {
for (const compiler of hre.config.solidity.compilers) {
compiler.settings.outputSelection['*']['*'].push('userdoc')
}
await runSuper()
})
// eslint-disable-next-line no-undef
task('userdoc', 'Generate userdoc JSON files', async function (args, hre) {
await hre.run('compile')
const contractNames = await hre.artifacts.getAllFullyQualifiedNames()
const dirPath = path.join(__dirname, '/artifacts-userdoc')
if (fs.existsSync(dirPath)) {
fs.rmSync(dirPath, { recursive: true, force: true })
}
fs.mkdirSync(dirPath)
const contractHandlers = contractNames.map((contractName) =>
(async () => {
const [source, name] = contractName.split(':')
const { userdoc } = (await hre.artifacts.getBuildInfo(contractName)).output.contracts[source][name]
if (
!userdoc ||
(Object.values(userdoc.methods || {}).length === 0 && Object.values(userdoc.events || {}).length === 0)
) {
return
}
const filePath = path.join(dirPath, `${name}.json`)
await fs.promises.writeFile(filePath, JSON.stringify(userdoc, null, 2))
})()
)
await Promise.all(contractHandlers)
})