This repository has been archived by the owner on Nov 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhardhat.config.ts
225 lines (212 loc) · 6.75 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
import { HardhatUserConfig } from 'hardhat/config'
import '@nomicfoundation/hardhat-toolbox'
import 'solidity-coverage'
import 'solidity-docgen'
import { task, types } from 'hardhat/config'
import { TASK_TEST } from 'hardhat/builtin-tasks/task-names'
import { HardhatRuntimeEnvironment, NetworkUserConfig } from 'hardhat/types'
import { Task, Verifier, Network } from './hardhat'
import { getEnv, Logger, logger, testRunner } from './hardhat/utils'
import solhintConfig from './solhint.config'
/**
* Deploy contracts based on a directory ID in tasks/
*
* `npx hardhat deploy --id <task-id> --network <network-name> [--key <apiKey> --force --verbose]`
*/
task(
'deploy',
'hardhat deploy --id <task-id> --network <network-name> [--key <apiKey> --force --verbose]'
)
.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',
'hardhat verify-contract --id <task-id> --network <network-name> --name <contract-name> [--address <contract-address> --args <constructor-args --key <apiKey> --force --verbose]'
)
.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 deployment tasks in tasks/').setAction(
async (args: { verbose?: boolean }) => {
Logger.setDefaults(false, args.verbose || false)
Task.printAllTask()
}
)
/**
* Provide additional fork testing options
*
* eg: `npx hardhat test --fork <network-name> --blockNumber <block-number>`
*/
task(TASK_TEST)
.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)
export const mainnetMnemonic = getEnv('MAINNET_MNEMONIC')
export const testnetMnemonic = getEnv('TESTNET_MNEMONIC')
const networkConfig: Record<Network, NetworkUserConfig> = {
mainnet: {
// TODO: Add default network url
url: getEnv('MAINNET_RPC_URL') || '',
chainId: 1,
accounts: {
mnemonic: mainnetMnemonic,
},
},
ropsten: {
// TODO: Add default network url
url: getEnv('ROPSTEN_RPC_URL') || '',
chainId: 3,
accounts: {
mnemonic: testnetMnemonic,
},
},
bsc: {
url: getEnv('BSC_RPC_URL') || 'https://bsc-dataseed1.binance.org',
chainId: 56,
accounts: {
mnemonic: mainnetMnemonic,
},
},
bscTestnet: {
url:
getEnv('BSC_TESTNET_RPC_URL') ||
'https://data-seed-prebsc-1-s1.binance.org:8545',
chainId: 97,
accounts: {
mnemonic: testnetMnemonic,
},
},
polygon: {
url:
getEnv('POLYGON_RPC_URL') || 'https://matic-mainnet.chainstacklabs.com',
chainId: 137,
accounts: {
mnemonic: mainnetMnemonic,
},
},
polygonTestnet: {
url:
getEnv('POLYGON_TESTNET_RPC_URL') || 'https://rpc-mumbai.maticvigil.com/',
chainId: 80001,
accounts: {
mnemonic: testnetMnemonic,
},
},
// Placeholder for the configuration below.
hardhat: {},
}
const config: HardhatUserConfig = {
// Storing this single source of truth in `solhint.config.js`
solidity: solhintConfig.rules['compiler-version'][1],
networks: {
...networkConfig,
hardhat: {
gas: 'auto',
gasPrice: 'auto',
},
},
gasReporter: {
// More options can be found here:
// https://www.npmjs.com/package/hardhat-gas-reporter
enabled: getEnv('REPORT_GAS') ? true : false,
currency: 'USD',
excludeContracts: [],
},
docgen: {
outputDir: './docs',
pages: 'items',
exclude: ['Migrations.sol', '/mocks'],
},
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
},
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'),
// },
},
}
const parseApiKey = (network: Network, key?: string): string | undefined => {
return key || verificationConfig.etherscan.apiKey[network]
}
/**
* 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'),
ropsten: getEnv('ETHERSCAN_API_KEY'),
bsc: getEnv('BSCSCAN_API_KEY'),
bscTestnet: getEnv('BSCSCAN_API_KEY'),
polygon: getEnv('POLYGONSCAN_API_KEY'),
polygonTestnet: getEnv('POLYGONSCAN_API_KEY'),
},
},
}
export default config