forked from lidofinance/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardhat.config.js
285 lines (265 loc) · 7.38 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
const fs = require('fs')
const path = require('path')
const { TASK_COMPILE } = require('hardhat/builtin-tasks/task-names')
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')
const NETWORK_NAME = getNetworkName()
const ETH_ACCOUNT_NAME = process.env.ETH_ACCOUNT_NAME
// 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 || {}
const base = {
accounts:
ethAccountName === 'remote'
? 'remote'
: ethAccts[ethAccountName] || ethAccts[networkName] || ethAccts.dev || 'remote',
ensAddress: netState.ensAddress,
timeout: 60000,
}
const localhost = {
...base,
url: 'http://localhost:8545',
chainId: 31337,
gas: 80000000, // the same as in Görli
}
const mainnetfork = {
...base,
url: 'http://127.0.0.1:8545',
chainId: 1337,
gas: 80000000, // the same as in Görli
}
const byNetName = {
localhost,
mainnetfork,
local: {
...base,
accounts: {
mnemonic: 'explain tackle mirror kit van hammer degree position ginger unfair soup bonus',
count: 30,
},
url: 'http://localhost:8545',
chainId: 1337,
},
hardhat: {
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,
},
},
'goerli-pyrmont': {
...base,
url: 'http://206.81.31.11/rpc',
chainId: 5,
},
rinkeby: {
...base,
url: 'https://rinkeby.infura.io/v3/' + accounts.infura.projectId,
chainId: 4,
timeout: 60000 * 10,
},
goerli: {
...base,
url: 'https://goerli.infura.io/v3/' + accounts.infura.projectId,
chainId: 5,
timeout: 60000 * 10,
},
'mainnet-test': {
...base,
url: 'https://mainnet.infura.io/v3/' + accounts.infura.projectId,
chainId: 1,
timeout: 60000 * 10,
},
mainnet: {
...base,
url: 'https://mainnet.infura.io/v3/' + accounts.infura.projectId,
chainId: 1,
timeout: 60000 * 10,
},
fork: {
...base,
chainId: 1,
timeout: 60000 * 10,
forking: {
url: 'https://mainnet.infura.io/v3/' + accounts.infura.projectId,
// url: 'https://eth-mainnet.alchemyapi.io/v2/' + accounts.alchemy.apiKey
},
},
}
const netConfig = byNetName[networkName]
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),
solidity: {
compilers: [
{
version: '0.4.24',
settings: solcSettings4,
},
{
version: '0.6.11',
settings: solcSettings6,
},
{
version: '0.6.12',
settings: solcSettings6,
},
{
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: accounts.etherscan,
aragon: {
ipfsApi: process.env.IPFS_API_URL || 'https://ipfs.infura.io:5001/api/v0',
ipfsGateway: process.env.IPFS_GATEWAY_URL || 'https://ipfs.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)
})