forked from SetProtocol/set-protocol-v2
-
Notifications
You must be signed in to change notification settings - Fork 5
/
hardhat.config.ts
226 lines (197 loc) · 5.99 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
require("dotenv").config();
require("hardhat-contract-sizer");
import chalk from "chalk";
import { HardhatUserConfig, task } from "hardhat/config";
import { privateKeys } from "./utils/wallets";
import "@nomiclabs/hardhat-waffle";
import "@typechain/hardhat";
import "solidity-coverage";
import "hardhat-deploy";
import {
TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE,
TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH,
TASK_COMPILE_SOLIDITY_COMPILE_JOB,
} from "hardhat/builtin-tasks/task-names";
import type { DependencyGraph, CompilationJob } from "hardhat/types/builtin-tasks";
import "./tasks";
const ethereumForkingConfig = {
url: `https://eth-mainnet.alchemyapi.io/v2/${process.env.ALCHEMY_TOKEN}`,
blockNumber: 16889000,
};
const arbitrumForkingConfig = {
url: process.env.ARBITRUM_RPC_URL ?? "",
blockNumber: 201830000,
};
export const forkingConfig =
process.env.FORK_NETWORK === "arbitrum" ? arbitrumForkingConfig : ethereumForkingConfig;
const mainnetForkMochaConfig = {
grep: "@forked-mainnet",
invert: false,
timeout: 200000,
} as Mocha.MochaOptions;
const arbitrumForkMochaConfig = {
grep: "@forked-arbitrum",
invert: false,
timeout: 200000,
} as Mocha.MochaOptions;
const unittestMochaConfig = {
grep: "@forked",
invert: true,
timeout: 200000,
} as Mocha.MochaOptions;
const mochaConfig = process.env.FORK
? process.env.FORK_NETWORK === "arbitrum"
? arbitrumForkMochaConfig
: mainnetForkMochaConfig
: unittestMochaConfig;
checkForkedProviderEnvironment();
const hardhatNetworks = {
kovan: {
url: "https://kovan.infura.io/v3/" + process.env.INFURA_TOKEN,
// @ts-ignore
accounts: [`0x${process.env.KOVAN_DEPLOY_PRIVATE_KEY}`],
},
staging_mainnet: {
url: "https://mainnet.infura.io/v3/" + process.env.INFURA_TOKEN,
// @ts-ignore
accounts: [`0x${process.env.STAGING_MAINNET_DEPLOY_PRIVATE_KEY}`],
},
production: {
url: "https://mainnet.infura.io/v3/" + process.env.INFURA_TOKEN,
// @ts-ignore
accounts: [`0x${process.env.PRODUCTION_MAINNET_DEPLOY_PRIVATE_KEY}`],
},
};
const config: HardhatUserConfig = {
solidity: {
compilers: [
{
version: "0.6.10",
settings: { optimizer: { enabled: true, runs: 200 } },
},
{
version: "0.8.17",
settings: { optimizer: { enabled: true, runs: 200 } },
},
],
},
networks: {
hardhat: {
allowUnlimitedContractSize: false,
forking: process.env.FORK ? forkingConfig : undefined,
accounts: getHardhatPrivateKeys(),
gas: 12000000,
blockGasLimit: 12000000,
},
localhost: {
url: "http://127.0.0.1:8545",
timeout: 200000,
gas: 12000000,
blockGasLimit: 12000000,
},
// To update coverage network configuration got o .solcover.js and update param in providerOptions field
coverage: {
url: "http://127.0.0.1:8555", // Coverage launches its own ganache-cli client
timeout: 200000,
},
...(process.env.KOVAN_DEPLOY_PRIVATE_KEY && hardhatNetworks),
},
// @ts-ignore
typechain: {
outDir: "typechain",
target: "ethers-v5",
externalArtifacts: ["external/**/*.json"],
},
// @ts-ignore
contractSizer: {
runOnCompile: false,
},
mocha: mochaConfig,
// These are external artifacts we don't compile but would like to improve
// test performance for by hardcoding the gas into the abi at runtime
// @ts-ignore
externalGasMods: ["external/abi/perp"],
};
function getHardhatPrivateKeys() {
return privateKeys.map(key => {
const ONE_MILLION_ETH = "1000000000000000000000000";
return {
privateKey: key,
balance: ONE_MILLION_ETH,
};
});
}
function checkForkedProviderEnvironment() {
if (
process.env.FORK &&
(!process.env.ALCHEMY_TOKEN || process.env.ALCHEMY_TOKEN === "fake_alchemy_token")
) {
console.log(
chalk.red(
"You are running forked provider tests with invalid Alchemy credentials.\n" +
"Update your ALCHEMY_TOKEN settings in the `.env` file.",
),
);
process.exit(1);
}
}
task("index:compile:one", "Compiles a single contract in isolation")
.addPositionalParam("contractName")
.setAction(async function (args, env) {
const sourceName = env.artifacts.readArtifactSync(args.contractName).sourceName;
const dependencyGraph: DependencyGraph = await env.run(
TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH,
{ sourceNames: [sourceName] },
);
const resolvedFiles = dependencyGraph.getResolvedFiles().filter(resolvedFile => {
return resolvedFile.sourceName === sourceName;
});
const compilationJob: CompilationJob = await env.run(
TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE,
{
dependencyGraph,
file: resolvedFiles[0],
},
);
await env.run(TASK_COMPILE_SOLIDITY_COMPILE_JOB, {
compilationJob,
compilationJobs: [compilationJob],
compilationJobIndex: 0,
emitsArtifacts: true,
quiet: true,
});
await env.run("typechain");
});
task("index:compile:all", "Compiles all contracts in isolation").setAction(async function (
_args,
env,
) {
const allArtifacts = await env.artifacts.getAllFullyQualifiedNames();
for (const contractName of allArtifacts) {
const sourceName = env.artifacts.readArtifactSync(contractName).sourceName;
const dependencyGraph: DependencyGraph = await env.run(
TASK_COMPILE_SOLIDITY_GET_DEPENDENCY_GRAPH,
{
sourceNames: [sourceName],
},
);
const resolvedFiles = dependencyGraph.getResolvedFiles().filter(resolvedFile => {
return resolvedFile.sourceName === sourceName;
});
const compilationJob: CompilationJob = await env.run(
TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE,
{
dependencyGraph,
file: resolvedFiles[0],
},
);
await env.run(TASK_COMPILE_SOLIDITY_COMPILE_JOB, {
compilationJob,
compilationJobs: [compilationJob],
compilationJobIndex: 0,
emitsArtifacts: true,
quiet: true,
});
}
});
export default config;