-
Notifications
You must be signed in to change notification settings - Fork 3
/
hardhat.config.ts
145 lines (140 loc) · 3.78 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
import {HardhatUserConfig} from 'hardhat/types'
import '@nomicfoundation/hardhat-toolbox'
import 'hardhat-deploy'
import 'hardhat-log-remover'
import 'hardhat-contract-sizer'
import 'hardhat-spdx-license-identifier'
import './tasks/create-release'
import './tasks/impersonate-deployer'
import dotenv from 'dotenv'
dotenv.config()
const accounts = process.env.MNEMONIC ? {mnemonic: process.env.MNEMONIC} : undefined
const deployer = process.env.DEPLOYER || 0
// Hardhat do not support adding chainId at runtime. Only way to set it in hardhat-config.js
// More info https://github.com/NomicFoundation/hardhat/issues/2167
// To avoid creating a new ENV VAR to store chainId, this function resolves it based on provider url
function resolveChainId() {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const NODE_URL = process.env.NODE_URL!
if (NODE_URL.includes('eth.connect') || NODE_URL.includes('eth-mainnet')) {
return {chainId: 1, deploy: ['deploy/scripts/mainnet']}
}
if (NODE_URL.includes('avax')) {
return {chainId: 43114, deploy: ['deploy/scripts/avalanche']}
}
if (NODE_URL.includes('bsc')) {
return {chainId: 56, deploy: ['deploy/scripts/bsc']}
}
if (NODE_URL.includes('optimism') || NODE_URL.includes('opt-mainnet')) {
return {chainId: 10, deploy: ['deploy/scripts/optimism']}
}
if (NODE_URL.includes('base')) {
return {chainId: 8453, deploy: ['deploy/scripts/base']}
}
return {chainId: 31337, deploy: ['deploy/scripts/mainnet']}
}
const {chainId, deploy} = resolveChainId()
const config: HardhatUserConfig = {
defaultNetwork: 'hardhat',
networks: {
localhost: {
saveDeployments: true,
autoImpersonate: true,
chainId,
deploy,
},
hardhat: {
// Note: Forking is being made from those test suites that need it
// forking: {
// url: process.env.NODE_URL,
// blockNumber: process.env.BLOCK_NUMBER ? parseInt(process.env.BLOCK_NUMBER) : undefined,
// },
saveDeployments: true,
accounts,
chainId,
},
mainnet: {
url: process.env.NODE_URL,
chainId: 1,
gas: 6700000,
accounts,
deploy: ['deploy/scripts/mainnet'],
},
avalanche: {
url: process.env.NODE_URL,
chainId: 43114,
gas: 8000000,
accounts,
},
bsc: {
url: process.env.NODE_URL || '',
chainId: 56,
gas: 8000000,
deploy: ['deploy/scripts/bsc'],
accounts,
},
optimism: {
url: process.env.NODE_URL || '',
chainId: 10,
gas: 8000000,
deploy: ['deploy/scripts/optimism'],
accounts,
},
base: {
url: process.env.NODE_URL || '',
chainId: 8453,
gas: 8000000,
deploy: ['deploy/scripts/base'],
accounts,
},
},
paths: {
// Note: Uses mainnet folder as default
deploy: ['deploy/scripts/mainnet'],
},
namedAccounts: {
deployer,
},
contractSizer: {
alphaSort: true,
runOnCompile: process.env.RUN_CONTRACT_SIZER === 'true',
disambiguatePaths: false,
},
gasReporter: {
enabled: process.env.REPORT_GAS === 'true',
outputFile: 'gas-report.txt',
noColors: true,
excludeContracts: ['mock/'],
},
solidity: {
version: '0.8.9',
settings: {
optimizer: {
enabled: true,
runs: 200,
},
outputSelection: {
'*': {
'*': ['storageLayout'],
},
},
},
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
spdxLicenseIdentifier: {
overwrite: false,
runOnCompile: true,
},
typechain: {
outDir: 'typechain',
},
mocha: {
timeout: 200000,
// Note: We can enable parallelism here instead of using the `--parallel`
// flag on npm script but it would make coverage to fail
// parallel: true
},
}
export default config