-
Notifications
You must be signed in to change notification settings - Fork 26
/
hardhat.config.ts
71 lines (66 loc) · 2.28 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
import * as path from "path";
import { task } from "hardhat/config";
import {
TASK_COMPILE,
TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT,
} from "hardhat/builtin-tasks/task-names";
import { runTypeChain, glob } from "typechain";
import "@nomiclabs/hardhat-ethers";
// You have to export an object to set up your config
// This object can have the following optional entries:
// defaultNetwork, networks, solc, and paths.
// Go to https://hardhat.org/config/ to learn more
export default {
// This is a sample solc configuration that specifies which version of solc to use
solidity: {
version: "0.7.6",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
};
// Additional contracts to generate TypeScript bindings for.
// Only contracts never used in .sol files should be listed here to avoid conflicts.
const contracts = [
"node_modules/@ensdomains/ens/build/contracts/ENSRegistry.json",
"ethregistrar/build/contracts/BaseRegistrar.json",
"ethregistrar/build/contracts/BaseRegistrarImplementation.json",
];
task(TASK_COMPILE).setAction(async (_, runtime, runSuper) => {
await runSuper();
const artifacts = await runtime.artifacts.getArtifactPaths();
artifacts.push(...contracts.map((contract) => path.resolve(contract)));
const artifactsGlob = "{" + artifacts.join(",") + "}";
await typeChain(artifactsGlob, ".");
console.log(`Successfully generated Typechain artifacts!`);
});
task(TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT).setAction(async (_, __, runSuper) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const input = await runSuper();
// eslint-disable-next-line
input.settings.outputSelection["*"]["*"].push("storageLayout");
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return input;
});
async function typeChain(filesGlob: string, modulePath: string): Promise<void> {
const outDir = "./contract-bindings";
const cwd = process.cwd();
const allFiles = glob(cwd, [filesGlob]);
await runTypeChain({
cwd,
filesToProcess: allFiles,
allFiles,
outDir: path.join(outDir, "ethers", modulePath),
target: "ethers-v5",
});
await runTypeChain({
cwd,
filesToProcess: allFiles,
allFiles,
outDir: path.join(outDir, "web3", modulePath),
target: "web3-v1",
});
}