forked from wighawag/hardhat-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buidler.config.js
108 lines (99 loc) · 3.33 KB
/
buidler.config.js
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
const fs = require("fs");
const path = require("path");
const { internalTask, task } = require("@nomiclabs/buidler/config");
const {
TASK_COMPILE_GET_COMPILER_INPUT,
TASK_COMPILE
} = require("@nomiclabs/buidler/builtin-tasks/task-names");
function addIfNotPresent(array, value) {
if (array.indexOf(value) === -1) {
array.push(value);
}
}
function setupExtraSolcSettings(settings) {
settings.metadata = settings.metadata || {};
settings.metadata.useLiteralContent = true;
if (settings.outputSelection === undefined) {
settings.outputSelection = {
"*": {
"*": [],
"": []
}
};
}
if (settings.outputSelection["*"] === undefined) {
settings.outputSelection["*"] = {
"*": [],
"": []
};
}
if (settings.outputSelection["*"]["*"] === undefined) {
settings.outputSelection["*"]["*"] = [];
}
if (settings.outputSelection["*"][""] === undefined) {
settings.outputSelection["*"][""] = [];
}
addIfNotPresent(settings.outputSelection["*"]["*"], "abi");
addIfNotPresent(settings.outputSelection["*"]["*"], "evm.bytecode");
addIfNotPresent(settings.outputSelection["*"]["*"], "evm.deployedBytecode");
addIfNotPresent(settings.outputSelection["*"]["*"], "metadata");
addIfNotPresent(settings.outputSelection["*"]["*"], "devdoc");
addIfNotPresent(settings.outputSelection["*"]["*"], "userdoc");
addIfNotPresent(settings.outputSelection["*"]["*"], "storageLayout");
addIfNotPresent(settings.outputSelection["*"]["*"], "evm.methodIdentifiers");
addIfNotPresent(settings.outputSelection["*"]["*"], "evm.gasEstimates");
// addIfNotPresent(settings.outputSelection["*"][""], "ir");
// addIfNotPresent(settings.outputSelection["*"][""], "irOptimized");
// addIfNotPresent(settings.outputSelection["*"][""], "ast");
}
internalTask(TASK_COMPILE_GET_COMPILER_INPUT).setAction(
async (_, __, runSuper) => {
const input = await runSuper();
setupExtraSolcSettings(input.settings);
return input;
}
);
task(TASK_COMPILE).setAction(async (args, __, runSuper) => {
await runSuper(args);
const solcOutputString = fs.readFileSync("./cache/solc-output.json");
const solcOutput = JSON.parse(solcOutputString);
const artifactFolderpath = "./artifacts";
const files = fs.readdirSync(artifactFolderpath);
for (const file of files) {
const artifactFilepath = path.join(artifactFolderpath, file);
const artifactString = fs.readFileSync(artifactFilepath);
const artifact = JSON.parse(artifactString);
let contractFilepath;
let contractSolcOutput;
for (const fileEntry of Object.entries(solcOutput.contracts)) {
for (const contractEntry of Object.entries(fileEntry[1])) {
if (contractEntry[0] === artifact.contractName) {
if (
artifact.bytecode ===
"0x" + contractEntry[1].evm.bytecode.object
) {
contractSolcOutput = contractEntry[1];
contractFilepath = fileEntry[0];
}
}
}
}
if (contractSolcOutput) {
artifact.metadata = contractSolcOutput.metadata;
artifact.contractFilepath = contractFilepath;
}
fs.writeFileSync(artifactFilepath, JSON.stringify(artifact, null, " "));
}
});
module.exports = {
solc: {
version: "0.6.5",
optimizer: {
enabled: true,
runs: 2000
}
},
paths: {
sources: "solc_0.6"
}
};