@skalenetwork/upgrade-tools 0.0.1-custom.3 → 0.0.1-custom.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/deploy.d.ts +3 -0
- package/dist/deploy.js +97 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +18 -0
- package/dist/upgrade.d.ts +2 -0
- package/dist/upgrade.js +2 -0
- package/package.json +1 -1
package/dist/deploy.d.ts
ADDED
package/dist/deploy.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getContractFactory = exports.getManifestFile = exports.getContractKeyInAbiFile = void 0;
|
|
13
|
+
const upgrades_core_1 = require("@openzeppelin/upgrades-core");
|
|
14
|
+
const hardhat_1 = require("hardhat");
|
|
15
|
+
const fs_1 = require("fs");
|
|
16
|
+
function _deployLibrary(libraryName) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const Library = yield hardhat_1.ethers.getContractFactory(libraryName);
|
|
19
|
+
const library = yield Library.deploy();
|
|
20
|
+
yield library.deployed();
|
|
21
|
+
return library.address;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function deployLibraries(libraryNames) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const libraries = new Map();
|
|
27
|
+
for (const libraryName of libraryNames) {
|
|
28
|
+
libraries.set(libraryName, yield _deployLibrary(libraryName));
|
|
29
|
+
}
|
|
30
|
+
return libraries;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function _linkBytecode(artifact, libraries) {
|
|
34
|
+
let bytecode = artifact.bytecode;
|
|
35
|
+
for (const [, fileReferences] of Object.entries(artifact.linkReferences)) {
|
|
36
|
+
for (const [libName, fixups] of Object.entries(fileReferences)) {
|
|
37
|
+
const addr = libraries.get(libName);
|
|
38
|
+
if (addr === undefined) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
for (const fixup of fixups) {
|
|
42
|
+
bytecode =
|
|
43
|
+
bytecode.substr(0, 2 + fixup.start * 2) +
|
|
44
|
+
addr.substr(2) +
|
|
45
|
+
bytecode.substr(2 + (fixup.start + fixup.length) * 2);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return bytecode;
|
|
50
|
+
}
|
|
51
|
+
function getLinkedContractFactory(contractName, libraries) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
const cArtifact = yield hardhat_1.artifacts.readArtifact(contractName);
|
|
54
|
+
const linkedBytecode = _linkBytecode(cArtifact, libraries);
|
|
55
|
+
const ContractFactory = yield hardhat_1.ethers.getContractFactory(cArtifact.abi, linkedBytecode);
|
|
56
|
+
return ContractFactory;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function getContractKeyInAbiFile(contract) {
|
|
60
|
+
return contract.replace(/([a-zA-Z])(?=[A-Z])/g, '$1_').toLowerCase();
|
|
61
|
+
}
|
|
62
|
+
exports.getContractKeyInAbiFile = getContractKeyInAbiFile;
|
|
63
|
+
function getManifestFile() {
|
|
64
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
return (yield upgrades_core_1.Manifest.forNetwork(hardhat_1.ethers.provider)).file;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
exports.getManifestFile = getManifestFile;
|
|
69
|
+
function getContractFactory(contract) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const { linkReferences } = yield hardhat_1.artifacts.readArtifact(contract);
|
|
72
|
+
if (!Object.keys(linkReferences).length)
|
|
73
|
+
return yield hardhat_1.ethers.getContractFactory(contract);
|
|
74
|
+
const libraryNames = [];
|
|
75
|
+
for (const key of Object.keys(linkReferences)) {
|
|
76
|
+
const libraryName = Object.keys(linkReferences[key])[0];
|
|
77
|
+
libraryNames.push(libraryName);
|
|
78
|
+
}
|
|
79
|
+
const libraries = yield deployLibraries(libraryNames);
|
|
80
|
+
const libraryArtifacts = {};
|
|
81
|
+
for (const [libraryName, libraryAddress] of libraries.entries()) {
|
|
82
|
+
const { bytecode } = yield hardhat_1.artifacts.readArtifact(libraryName);
|
|
83
|
+
libraryArtifacts[libraryName] = { "address": libraryAddress, "bytecodeHash": (0, upgrades_core_1.hashBytecode)(bytecode) };
|
|
84
|
+
}
|
|
85
|
+
let manifest;
|
|
86
|
+
try {
|
|
87
|
+
manifest = JSON.parse(yield fs_1.promises.readFile(yield getManifestFile(), "utf-8"));
|
|
88
|
+
Object.assign(libraryArtifacts, manifest.libraries);
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
Object.assign(manifest, { libraries: libraryArtifacts });
|
|
92
|
+
yield fs_1.promises.writeFile(yield getManifestFile(), JSON.stringify(manifest, null, 4));
|
|
93
|
+
}
|
|
94
|
+
return yield getLinkedContractFactory(contract, libraries);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
exports.getContractFactory = getContractFactory;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./abi"), exports);
|
|
14
|
+
__exportStar(require("./deploy"), exports);
|
|
15
|
+
__exportStar(require("./gnosis-safe"), exports);
|
|
16
|
+
__exportStar(require("./multiSend"), exports);
|
|
17
|
+
__exportStar(require("./upgrade"), exports);
|
|
18
|
+
__exportStar(require("./verification"), exports);
|
|
19
|
+
__exportStar(require("./version"), exports);
|
package/dist/upgrade.d.ts
CHANGED
package/dist/upgrade.js
CHANGED