forked from RequestNetwork/requestNetwork
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hardhat.config.ts
251 lines (234 loc) · 7.45 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
import '@typechain/hardhat';
import '@nomiclabs/hardhat-waffle';
import '@nomiclabs/hardhat-ganache';
import '@nomiclabs/hardhat-etherscan';
import '@nomiclabs/hardhat-ethers';
import { subtask, task } from 'hardhat/config';
import { config } from 'dotenv';
import deployAllContracts from './scripts/test-deploy-all';
import { deployAllPaymentContracts } from './scripts/deploy-payments';
import { checkCreate2Deployer } from './scripts-create2/check-deployer';
import { deployDeployer } from './scripts-create2/deploy-request-deployer';
import { HardhatRuntimeEnvironmentExtended } from './scripts-create2/types';
import { computeCreate2DeploymentAddressesFromList } from './scripts-create2/compute-one-address';
import { VerifyCreate2FromList } from './scripts-create2/verify';
import { deployWithCreate2FromList } from './scripts-create2/deploy';
import utils from '@requestnetwork/utils';
import { NUMBER_ERRORS } from './scripts/utils';
config();
const accounts = process.env.DEPLOYMENT_PRIVATE_KEY
? [process.env.DEPLOYMENT_PRIVATE_KEY]
: process.env.DEPLOYER_MASTER_KEY
? [process.env.DEPLOYER_MASTER_KEY]
: process.env.ADMIN_PRIVATE_KEY
? [process.env.ADMIN_PRIVATE_KEY]
: undefined;
if (accounts && process.env.ADMIN_PRIVATE_KEY) {
accounts.push(process.env.ADMIN_PRIVATE_KEY);
}
const DEPLOYER_KEY_GUARD = 'DEPLOYER_KEY_GUARD';
// Request deployer address on local blockchain
const LOCAL_DEPLOYER_ADDRESS = '0x8CdaF0CD259887258Bc13a92C0a6dA92698644C0';
// Request deployer address on live blockchains
const LIVE_DEPLOYER_ADDRESS = '0xE99Ab70a5FAE59551544FA326fA048f7B95A24B2';
// Arbitrary data used to deploy our contracts at predefined addresses
const REQUEST_SALT = '0x0679724da7211bc62502a39f41cbf818fc7132c266e7c819fc2b06fad9593655';
const requestDeployer = process.env.REQUEST_DEPLOYER_LIVE
? LIVE_DEPLOYER_ADDRESS
: LOCAL_DEPLOYER_ADDRESS;
const url = (network: string): string =>
process.env.WEB3_PROVIDER_URL || utils.networkRpcs[network];
export default {
solidity: '0.8.9',
paths: {
sources: 'src/contracts',
tests: 'test/contracts',
artifacts: 'build',
},
networks: {
private: {
url: 'http://127.0.0.1:8545',
accounts: undefined,
},
mainnet: {
url: process.env.WEB3_PROVIDER_URL || 'https://mainnet.infura.io/v3/YOUR_API_KEY',
chainId: 1,
accounts,
},
rinkeby: {
url: process.env.WEB3_PROVIDER_URL || 'https://rinkeby.infura.io/v3/YOUR_API_KEY',
chainId: 4,
accounts,
},
goerli: {
url: process.env.WEB3_PROVIDER_URL || 'https://goerli.infura.io/v3/YOUR_API_KEY',
chainId: 5,
accounts,
},
matic: {
url: url('matic'),
chainId: 137,
accounts,
},
celo: {
url: url('celo'),
chainId: 42220,
accounts,
},
bsctest: {
url: url('bsctest'),
chainId: 97,
accounts,
},
bsc: {
url: url('bsc'),
chainId: 56,
accounts,
},
xdai: {
url: url('xdai'),
chainId: 100,
accounts,
},
fuse: {
url: url('fuse'),
chainId: 122,
accounts,
},
fantom: {
url: url('fantom'),
chainId: 250,
accounts,
},
'arbitrum-one': {
url: url('arbitrum-one'),
chainId: 42161,
accounts,
},
'arbitrum-rinkeby': {
url: url('arbitrum-rinkeby'),
chainId: 421611,
accounts,
},
avalanche: {
url: url('avalanche'),
chainId: 43114,
accounts,
},
optimism: {
url: url('optimism'),
chainId: 10,
accounts,
},
},
etherscan: {
apiKey: {
mainnet: process.env.ETHERSCAN_API_KEY,
rinkeby: process.env.ETHERSCAN_API_KEY,
goerli: process.env.ETHERSCAN_API_KEY,
// binance smart chain
bsc: process.env.BSCSCAN_API_KEY,
bscTestnet: process.env.BSCSCAN_API_KEY,
// fantom mainnet
opera: process.env.FTMSCAN_API_KEY,
// polygon
polygon: process.env.POLYGONSCAN_API_KEY,
polygonMumbai: process.env.POLYGONSCAN_API_KEY,
// arbitrum
arbitrumOne: process.env.ARBISCAN_API_KEY,
// avalanche
avalanche: process.env.SNOWTRACE_API_KEY,
// xdai
xdai: process.env.GNOSISSCAN_API_KEY,
// optimism
optimism: process.env.OPTIMISM_API_KEY,
// other networks don't need an API key, but you still need
// to specify one; any string placeholder will work
sokol: 'api-key',
aurora: 'api-key',
auroraTestnet: 'api-key',
},
customChains: [
{
network: 'optimism',
chainId: 10,
urls: {
apiURL: 'https://api-optimistic.etherscan.io/api',
browserURL: 'https://optimistic.etherscan.io/',
},
},
],
},
typechain: {
outDir: 'src/types',
target: 'ethers-v5',
alwaysGenerateOverloads: false, // should overloads with full signatures like deposit(uint256) be generated always, even if there are no overloads?
},
mocha: {
timeout: 60000, // Usefull on test networks
},
xdeploy: {
salt: REQUEST_SALT,
signer: process.env.ADMIN_PRIVATE_KEY,
networks: process.env.NETWORK
? [process.env.NETWORK]
: ['mainnet', 'matic', 'bsc', 'celo', 'xdai', 'fuse', 'arbitrum-one', 'fantom', 'avalanche'],
gasLimit: undefined,
deployerAddress: requestDeployer,
},
};
// FIXME: use deployAllPaymentContracts instead to test with the same deployments
task('deploy-local-env', 'Deploy a local environment').setAction(async (args, hre) => {
args.force = true;
await deployAllContracts(args, hre);
if (NUMBER_ERRORS > 0) {
console.log(`Deployment failed, please check the ${NUMBER_ERRORS} errors`);
} else {
console.log('All contracts (re)deployed locally');
}
});
task(
'deploy-live-payments',
'Deploy payment contracts on a live network. Make sure to update all artifacts before running.',
)
.addFlag('dryRun', 'to prevent any deployment')
.addFlag('force', 'to force re-deployment')
.setAction(async (args, hre) => {
args.force = args.force ?? false;
args.dryRun = args.dryRun ?? false;
args.simulate = args.dryRun;
await hre.run(DEPLOYER_KEY_GUARD);
await deployAllPaymentContracts(args, hre as HardhatRuntimeEnvironmentExtended);
});
// Tasks inherent to the CREATE2 deployment scheme
task(
'deploy-deployer-contract',
'Deploy request deployer contract on the specified network',
).setAction(async (_args, hre) => {
await deployDeployer(hre);
});
task(
'compute-contract-addresses',
'Compute the contract addresses from the Create2DeploymentList using the create2 scheme',
).setAction(async (_args, hre) => {
await hre.run('compile');
await computeCreate2DeploymentAddressesFromList(hre as HardhatRuntimeEnvironmentExtended);
});
task(
'deploy-contracts-through-deployer',
'Deploy the contracts from the Create2DeploymentList using the create2 scheme',
).setAction(async (_args, hre) => {
await checkCreate2Deployer(hre as HardhatRuntimeEnvironmentExtended);
await deployWithCreate2FromList(hre as HardhatRuntimeEnvironmentExtended);
});
task(
'verify-contract-from-deployer',
'Verify the contracts from the Create2DeploymentList for a specific network',
).setAction(async (_args, hre) => {
await VerifyCreate2FromList(hre as HardhatRuntimeEnvironmentExtended);
});
subtask(DEPLOYER_KEY_GUARD, 'prevent usage of the deployer master key').setAction(async () => {
if (accounts && accounts[0] === process.env.DEPLOYER_MASTER_KEY) {
throw new Error('The deployer master key should not be used for this action');
}
});