generated from DeFiFoFum/hardhat-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhardhat.config.ts
361 lines (342 loc) · 13.2 KB
/
hardhat.config.ts
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
import { HardhatUserConfig } from 'hardhat/config'
// import '@nomicfoundation/hardhat-toolbox'
import 'solidity-coverage'
import 'hardhat-docgen'
import 'hardhat-contract-sizer'
import { task, types } from 'hardhat/config'
import { TASK_TEST } from 'hardhat/builtin-tasks/task-names'
import {
HardhatRuntimeEnvironment,
HttpNetworkAccountsUserConfig,
HttpNetworkUserConfig,
NetworkUserConfig,
SolcUserConfig,
} from 'hardhat/types'
import { Task, Verifier, Network } from './hardhat'
import { getEnv, Logger, logger, testRunner } from './hardhat/utils'
import solhintConfig from './solhint.config'
import '@openzeppelin/hardhat-upgrades'
import '@nomicfoundation/hardhat-verify'
/**
* Deploy contracts based on a directory ID in tasks/
*
* `npx hardhat deploy --id <task-id> --network <network-name> [--key <apiKey> --force --verbose]`
*/
task('deploy', '🫶 Run deployment task')
.addParam('id', 'Deployment task ID')
.addFlag('force', 'Ignore previous deployments')
.addOptionalParam('key', 'Etherscan API key to verify contracts')
.setAction(
async (args: { id: string; force?: boolean; key?: string; verbose?: boolean }, hre: HardhatRuntimeEnvironment) => {
// Logger.setDefaults(false, args.verbose || false)
const key = parseApiKey(hre.network.name as Network, args.key)
const verifier = key ? new Verifier(hre.network, key) : undefined
await Task.fromHRE(args.id, hre, verifier).run(args)
}
)
/**
* Verify contracts based on a directory ID in tasks/
*
* eg: `npx hardhat verify-contract --id <task-id> --network <network-name> --name <contract-name>
* [--address <contract-address> --args <constructor-args --key <apiKey> --force --verbose]`
*/
task('verify-contract', '🫶 Run verification for a given contract')
.addParam('id', 'Deployment task ID')
.addParam('name', 'Contract name')
.addOptionalParam('address', 'Contract address')
.addOptionalParam('args', 'ABI-encoded constructor arguments')
.addOptionalParam('key', 'Etherscan API key to verify contracts')
.setAction(
async (
args: {
id: string
name: string
address?: string
key?: string
args?: string
verbose?: boolean
},
hre: HardhatRuntimeEnvironment
) => {
// Logger.setDefaults(false, args.verbose || false)
const key = parseApiKey(hre.network.name as Network, args.key)
const verifier = key ? new Verifier(hre.network, key) : undefined
await Task.fromHRE(args.id, hre, verifier).verify(args.name, args.address, args.args)
}
)
task('print-tasks', '🫶 Prints available tasks in tasks/ directory').setAction(async (args: { verbose?: boolean }) => {
// Logger.setDefaults(false, args.verbose || false)
logger.log(
`Use the following tasks in a variety of ways \nnpx hardhat deploy --id <task-id> --network <network-name> \nnpx hardhat verify-contract --id <task-id> --network <network-name> --name <contract-name> \n`,
`🫶`
)
Task.printAllTask()
})
/**
* Example of accessing ethers and performing Web3 calls inside a task
* task action function receives the Hardhat Runtime Environment as second argument
*
* Docs regarding hardhat helper functions added to ethers object:
* https://github.com/NomicFoundation/hardhat/tree/master/packages/hardhat-ethers#helpers
*/
task('blockNumber', '🫶 Prints the current block number', async (_, hre: HardhatRuntimeEnvironment) => {
// A provider field is added to ethers, which is an
// ethers.providers.Provider automatically connected to the selected network
await hre.ethers.provider.getBlockNumber().then((blockNumber) => {
console.log('Current block number: ' + blockNumber)
})
})
/**
* Provide additional fork testing options
*
* eg: `npx hardhat test --fork <network-name> --blockNumber <block-number>`
*/
task(TASK_TEST, '🫶 Test Task')
.addOptionalParam('fork', 'Optional network name to be forked block number to fork in case of running fork tests.')
.addOptionalParam('blockNumber', 'Optional block number to fork in case of running fork tests.', undefined, types.int)
.setAction(testRunner)
const mainnetMnemonic = getEnv('MAINNET_MNEMONIC')
const mainnetPrivateKey = getEnv('MAINNET_PRIVATE_KEY')
const mainnetAccounts: HttpNetworkAccountsUserConfig | undefined = mainnetMnemonic
? { mnemonic: mainnetMnemonic }
: mainnetPrivateKey
? [mainnetPrivateKey] // Fallback to private key
: undefined
const testnetMnemonic = getEnv('TESTNET_MNEMONIC')
const testnetPrivateKey = getEnv('TESTNET_PRIVATE_KEY')
const testnetAccounts: HttpNetworkAccountsUserConfig | undefined = testnetMnemonic
? { mnemonic: testnetMnemonic }
: testnetPrivateKey
? [testnetPrivateKey] // Fallback to private key
: undefined
type ExtendedNetworkOptions = {
getExplorerUrl: (address: string) => string
}
type NetworkUserConfigExtended = HttpNetworkUserConfig & ExtendedNetworkOptions
// Custom type for the hardhat network
type ExtendedHardhatNetworkConfig = {
[K in Network]: K extends 'hardhat' ? HardhatUserConfig & ExtendedNetworkOptions : NetworkUserConfigExtended
}
const networkConfig: ExtendedHardhatNetworkConfig = {
mainnet: {
url: getEnv('MAINNET_RPC_URL') || 'https://rpc.ankr.com/eth',
getExplorerUrl: (address: string) => `https://etherscan.io/address/${address}`,
chainId: 1,
accounts: mainnetAccounts,
},
goerli: {
url: getEnv('GOERLI_RPC_URL') || '',
getExplorerUrl: (address: string) => `https://goerli.etherscan.io/address/${address}`,
chainId: 5,
accounts: testnetAccounts,
},
arbitrum: {
url: getEnv('ARBITRUM_RPC_URL') || 'https://arbitrum-one.publicnode.com',
getExplorerUrl: (address: string) => `https://arbiscan.io/address/${address}`,
chainId: 42161,
accounts: mainnetAccounts,
},
arbitrumGoerli: {
url: getEnv('ARBITRUM_GOERLI_RPC_URL') || '',
getExplorerUrl: (address: string) => `https://testnet.arbiscan.io/address/${address}`,
chainId: 421613,
accounts: testnetAccounts,
},
bsc: {
url: getEnv('BSC_RPC_URL') || 'https://binance.llamarpc.com',
getExplorerUrl: (address: string) => `https://bscscan.com/address/${address}`,
chainId: 56,
accounts: mainnetAccounts,
},
bscTestnet: {
url: getEnv('BSC_TESTNET_RPC_URL') || 'https://data-seed-prebsc-1-s1.binance.org:8545',
getExplorerUrl: (address: string) => `https://testnet.bscscan.com/address/${address}`,
chainId: 97,
accounts: testnetAccounts,
},
linea: {
url: getEnv('LINEA_RPC_URL') || 'https://rpc.linea.build',
getExplorerUrl: (address: string) => `https://lineascan.build/address/${address}`,
chainId: 59144,
accounts: mainnetAccounts,
},
lineaTestnet: {
url: getEnv('LINEA_TESTNET_RPC_URL') || 'https://rpc.goerli.linea.build',
getExplorerUrl: (address: string) => `https://goerli.lineascan.build/address/${address}`,
chainId: 59140,
accounts: testnetAccounts,
},
polygon: {
url: getEnv('POLYGON_RPC_URL') || 'https://polygon.llamarpc.com ',
getExplorerUrl: (address: string) => `https://polygonscan.com/address/${address}`,
chainId: 137,
accounts: mainnetAccounts,
},
polygonTestnet: {
url: getEnv('POLYGON_TESTNET_RPC_URL') || 'https://rpc-mumbai.maticvigil.com/',
getExplorerUrl: (address: string) => `https://mumbai.polygonscan.com/address/${address}`,
chainId: 80001,
accounts: testnetAccounts,
},
lightlink: {
url: 'https://replicator.phoenix.lightlink.io/rpc/v1',
getExplorerUrl: (address: string) => `https://phoenix.lightlink.io/address/${address}`,
chainId: 1890,
accounts: mainnetAccounts,
},
iota: {
url: 'https://json-rpc.evm.iotaledger.net',
getExplorerUrl: (address: string) => `https://explorer.evm.iota.org/address/${address}`,
chainId: 8822,
accounts: mainnetAccounts,
},
base: {
url: 'https://base-pokt.nodies.app',
getExplorerUrl: (address: string) => `https://basescan.org/address/${address}`,
chainId: 8453,
accounts: mainnetAccounts,
},
telos: {
url: getEnv('TELOS_RPC_URL') || 'https://mainnet.telos.net/evm',
getExplorerUrl: (address: string) => `https://www.teloscan.io/address/${address}`,
chainId: 40,
accounts: testnetAccounts,
},
telosTestnet: {
url: getEnv('TELOS_TESTNET_RPC_URL') || 'https://testnet.telos.net/evm',
getExplorerUrl: (address: string) => `https://testnet.teloscan.io/address/${address}`,
chainId: 41,
accounts: testnetAccounts,
},
// Placeholder for the configuration below.
hardhat: {
getExplorerUrl: (address: string) => `(NO DEV EXPLORER): ${address}`,
},
}
/**
* Configure compiler versions in ./solhint.config.js
*
* @returns SolcUserConfig[]
*/
function getSolcUserConfig(): SolcUserConfig[] {
return (solhintConfig.rules['compiler-version'][2] as string[]).map((compiler) => {
return {
// Adding multiple compiler versions
// https://hardhat.org/hardhat-runner/docs/advanced/multiple-solidity-versions#multiple-solidity-versions
version: compiler,
settings: {
optimizer: {
enabled: true,
runs: 5,
},
},
}
})
}
const config: HardhatUserConfig = {
solidity: { compilers: getSolcUserConfig() },
networks: {
...networkConfig,
hardhat: {
gas: 'auto',
gasPrice: 'auto',
forking: {
// url: process.env.FORK_RPC || 'https://bsc.blockpi.network/v1/rpc/public',
url: process.env.FORK_RPC || 'https://binance.llamarpc.com',
},
},
},
docgen: {
path: './docs',
clear: true,
// TODO: Enable for each compile (disabled for template to avoid unnecessary generation)
runOnCompile: false,
},
// typechain: {
// // outDir: 'src/types', // defaults to './typechain-types/'
// target: 'ethers-v5',
// // externalArtifacts: [], // optional array of glob patterns with external artifacts to process (for example external libs from node_modules)
// alwaysGenerateOverloads: false, // should overloads with full signatures like deposit(uint256) be generated always, even if there are no overloads?
// dontOverrideCompile: false, // defaults to false
// },
contractSizer: {
// https://github.com/ItsNickBarry/hardhat-contract-sizer#usage
alphaSort: false, // whether to sort results table alphabetically (default sort is by contract size)
disambiguatePaths: false, // whether to output the full path to the compilation artifact (relative to the Hardhat root directory)
runOnCompile: false, // whether to output contract sizes automatically after compilation
strict: false, // whether to throw an error if any contracts exceed the size limit
// only: [':ERC20$'], // Array of String matchers used to include contracts
// except: [':ERC20$'], // Array of String matchers used to exclude contracts
// outputFile: './contract-size.md', // Optional output file to write to
},
etherscan: {
/**
* // NOTE This is valid in the latest version of "@nomiclabs/hardhat-etherscan.
* This version breaks the src/task.ts file which hasn't been refactored yet
*/
apiKey: {
mainnet: getEnv('ETHERSCAN_API_KEY'),
// optimisticEthereum: getEnv('OPTIMISTIC_ETHERSCAN_API_KEY'),
arbitrumOne: getEnv('ARBISCAN_API_KEY'),
bsc: getEnv('BSCSCAN_API_KEY'),
// bscTestnet: getEnv('BSCSCAN_API_KEY'),
polygon: getEnv('POLYGONSCAN_API_KEY'),
// polygonTestnet: getEnv('POLYGONSCAN_API_KEY'),
linea: getEnv('LINEASCAN_API_KEY'),
lineaTestnet: getEnv('LINEASCAN_API_KEY'),
lightlink: getEnv('LIGHTLINK_API_KEY'),
base: getEnv('BASESCAN_API_KEY'),
iota: getEnv('IOTASCAN_API_KEY'),
},
// https://hardhat.org/hardhat-runner/plugins/nomicfoundation-hardhat-verify#adding-support-for-other-networks
customChains: [
{
network: "linea",
chainId: 59144,
urls: {
apiURL: "https://api.lineascan.build/api",
browserURL: "https://lineascan.build/"
}
},
{
network: 'lightlink',
chainId: 1890,
urls: {
apiURL: 'https://phoenix.lightlink.io/api',
browserURL: 'https://phoenix.lightlink.io',
},
}
]
},
}
const parseApiKey = (network: Network, key?: string): string | undefined => {
return key || verificationConfig.etherscan.apiKey[network]
}
/**
* // TODO: This has been deprecated
* Placeholder configuration for @nomiclabs/hardhat-etherscan to store verification API urls
*/
const verificationConfig: { etherscan: { apiKey: Record<Network, string> } } = {
etherscan: {
apiKey: {
hardhat: 'NO_API_KEY',
mainnet: getEnv('ETHERSCAN_API_KEY'),
goerli: getEnv('ETHERSCAN_API_KEY'),
arbitrum: getEnv('ARBITRUM_API_KEY'),
arbitrumGoerli: getEnv('ARBITRUM_API_KEY'),
bsc: getEnv('BSCSCAN_API_KEY'),
linea: getEnv("LINEASCAN_API_KEY"),
lineaTestnet: getEnv("LINEASCAN_API_KEY"),
bscTestnet: getEnv('BSCSCAN_API_KEY'),
polygon: getEnv('POLYGONSCAN_API_KEY'),
polygonTestnet: getEnv('POLYGONSCAN_API_KEY'),
// NOTE: I don't believe TELOS verification is supported
telos: getEnv('TELOSSCAN_API_KEY'),
telosTestnet: getEnv('TELOSSCAN_API_KEY_API_KEY'),
base: getEnv('BASESCAN_API_KEY'),
iota: getEnv('IOTASCAN_API_KEY'),
lightlink: getEnv('LIGHTLINK_API_KEY'),
},
},
}
export default config