@skalenetwork/upgrade-tools 4.0.0-develop.3 → 4.0.0-develop.5
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/src/contractVerifier.d.ts +1 -0
- package/dist/src/contractVerifier.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/ownership-transfer/constants.d.ts +8 -0
- package/dist/src/ownership-transfer/constants.js +33 -0
- package/dist/src/ownership-transfer/constants.js.map +1 -0
- package/dist/src/ownership-transfer/contractAdmin.d.ts +55 -0
- package/dist/src/ownership-transfer/contractAdmin.js +206 -0
- package/dist/src/ownership-transfer/contractAdmin.js.map +1 -0
- package/dist/src/ownership-transfer/instanceAdmin.d.ts +51 -0
- package/dist/src/ownership-transfer/instanceAdmin.js +223 -0
- package/dist/src/ownership-transfer/instanceAdmin.js.map +1 -0
- package/dist/src/ownership-transfer/permission-utils.d.ts +32 -0
- package/dist/src/ownership-transfer/permission-utils.js +192 -0
- package/dist/src/ownership-transfer/permission-utils.js.map +1 -0
- package/dist/src/ownership-transfer/utils.d.ts +19 -0
- package/dist/src/ownership-transfer/utils.js +201 -0
- package/dist/src/ownership-transfer/utils.js.map +1 -0
- package/dist/src/proxyUpgrader.js +4 -3
- package/dist/src/proxyUpgrader.js.map +1 -1
- package/dist/src/upgrader.js +2 -2
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/verification.d.ts +1 -1
- package/dist/src/verification.js +2 -1
- package/dist/src/verification.js.map +1 -1
- package/dist/src/verifiers/blockscoutVerifier.js +4 -0
- package/dist/src/verifiers/blockscoutVerifier.js.map +1 -1
- package/dist/src/verifiers/etherscanVerifier.js +1 -1
- package/dist/src/verifiers/etherscanVerifier.js.map +1 -1
- package/dist/src/verifiers/skaleBlockscoutVerifier.js +2 -2
- package/dist/src/verifiers/skaleBlockscoutVerifier.js.map +1 -1
- package/package.json +2 -2
|
@@ -2,6 +2,7 @@ import { ValidationResponse } from "@nomicfoundation/hardhat-verify/internal/uti
|
|
|
2
2
|
export interface VerificationTarget {
|
|
3
3
|
contractName: string;
|
|
4
4
|
contractAddress: string;
|
|
5
|
+
constructorArguments?: string;
|
|
5
6
|
}
|
|
6
7
|
export interface VerificationRequestParameters {
|
|
7
8
|
solcInputJson: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractVerifier.js","sourceRoot":"","sources":["../../src/contractVerifier.ts"],"names":[],"mappings":";;;;;;AACA,qCAAkC;AAClC,kDAA0B;AAC1B,2NACsJ;AACtJ,kHAAsF;AAEtF,MAAM,sBAAsB,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"contractVerifier.js","sourceRoot":"","sources":["../../src/contractVerifier.ts"],"names":[],"mappings":";;;;;;AACA,qCAAkC;AAClC,kDAA0B;AAC1B,2NACsJ;AACtJ,kHAAsF;AAEtF,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAcjC,MAAsB,gBAAgB;IAAtC;QAEqB,wBAAmB,GAAG,6BAA6B,CAAC;QAE9D,WAAM,GAAG,KAAK,EACjB,kBAAsC,EACtC,WAAmB,sBAAsB,EAC3C,EAAE;YACA,MAAM,KAAK,GAAG,CAAC,CAAC;YAChB,IAAI,QAAQ,GAAG,KAAK,EAAE,CAAC;gBACnB,IAAI,CAAC,MAAM,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,EAAE,CAAC;oBACtD,MAAM,cAAc,GAAG,CAAC,CAAC;oBACzB,MAAM,IAAI,CAAC,MAAM,CAAC,kBAAkB,EAChC,QAAQ,GAAG,cAAc,CAC5B,CAAC;gBACN,CAAC;YACL,CAAC;QACL,CAAC,CAAC;IA+EN,CAAC;IA7EU,KAAK,CAAC,mBAAmB,CAAC,kBAAsC;QACnE,IAAI,MAAM,IAAI,CAAC,iBAAiB,CAAC,kBAAkB,CAAC,EAAE,CAAC;YACnD,OAAO,CAAC,GAAG,CAC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,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,qBAAqB,YAAY,EAAE,CAAC,CAAC;QACzD,CAAC;QACD,OAAO;YACH,eAAe,EAAE,SAAS,CAAC,eAAe;YAC1C,gBAAgB;YAChB,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,CAAC;SACjD,CAAC;IACN,CAAC;IAED,UAAU;IAEF,uBAAuB,CAAC,kBAAsC,EAAC,QAA4B;QAC/F,IAAI,QAAQ,CAAC,SAAS,EAAwB,EAAE,CAAC;YAC7C,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,GAAG,CAAC,6BAA6B,kBAAkB,CAAC,YAAY,EAAE,CAAC,CAC5E,CAAC;YACF,OAAO,KAAK,CAAC;QACjB,CAAC;QACD,OAAO,CAAC,GAAG,CACP,eAAK,CAAC,IAAI,CACN,GAAG,kBAAkB,CAAC,YAAY,gCAAgC,IAAI,CAAC,IAAI,MAAM,IAAI,CAAC,cAAc,CAChG,kBAAkB,CACrB,EAAE,CACN,CACJ,CAAC;QACF,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAhGD,4CAgGC"}
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -24,4 +24,5 @@ __exportStar(require("./version"), exports);
|
|
|
24
24
|
__exportStar(require("./upgrader"), exports);
|
|
25
25
|
__exportStar(require("./upgraders/abstractTransparentProxyUpgrader"), exports);
|
|
26
26
|
__exportStar(require("./upgraders/beaconUpgrader"), exports);
|
|
27
|
+
__exportStar(require("./ownership-transfer/instanceAdmin"), exports);
|
|
27
28
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,2CAAyB;AACzB,gDAA8B;AAC9B,kDAAgC;AAChC,+CAA6B;AAC7B,iDAA+B;AAC/B,4CAA0B;AAC1B,6CAA2B;AAC3B,+EAA6D;AAC7D,6DAA0C"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB;AACtB,2CAAyB;AACzB,gDAA8B;AAC9B,kDAAgC;AAChC,+CAA6B;AAC7B,iDAA+B;AAC/B,4CAA0B;AAC1B,6CAA2B;AAC3B,+EAA6D;AAC7D,6DAA0C;AAC1C,qEAAmD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const ERC1967_ADMIN_SLOT = "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103";
|
|
2
|
+
export declare const ERC1967_IMPLEMENTATION_SLOT = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
|
|
3
|
+
export declare const UPGRADEABLE_BEACON_ABI: string[];
|
|
4
|
+
export declare const OWNABLE_ABI: string[];
|
|
5
|
+
export declare const ACCESS_CONTROL_ABI: string[];
|
|
6
|
+
export declare const ACCESS_MANAGER_ABI: string[];
|
|
7
|
+
export declare const ACCESS_MANAGED_ABI: string[];
|
|
8
|
+
export declare const MULTISIG_ABI: string[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MULTISIG_ABI = exports.ACCESS_MANAGED_ABI = exports.ACCESS_MANAGER_ABI = exports.ACCESS_CONTROL_ABI = exports.OWNABLE_ABI = exports.UPGRADEABLE_BEACON_ABI = exports.ERC1967_IMPLEMENTATION_SLOT = exports.ERC1967_ADMIN_SLOT = void 0;
|
|
4
|
+
exports.ERC1967_ADMIN_SLOT = "0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103";
|
|
5
|
+
exports.ERC1967_IMPLEMENTATION_SLOT = "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc";
|
|
6
|
+
exports.UPGRADEABLE_BEACON_ABI = [
|
|
7
|
+
"function owner() view returns (address)",
|
|
8
|
+
"function implementation() view returns (address)",
|
|
9
|
+
"function upgradeTo(address newImplementation)"
|
|
10
|
+
];
|
|
11
|
+
exports.OWNABLE_ABI = [
|
|
12
|
+
"function transferOwnership(address newOwner)",
|
|
13
|
+
"function owner() view returns (address)"
|
|
14
|
+
];
|
|
15
|
+
exports.ACCESS_CONTROL_ABI = [
|
|
16
|
+
"function hasRole(bytes32 role, address account) view returns (bool)",
|
|
17
|
+
"function grantRole(bytes32 role, address account)",
|
|
18
|
+
"function renounceRole(bytes32 role, address account)",
|
|
19
|
+
"function getRoleMemberCount(bytes32 role) view returns (uint256)"
|
|
20
|
+
];
|
|
21
|
+
exports.ACCESS_MANAGER_ABI = [
|
|
22
|
+
"function hasRole(uint64 role, address account) view returns (bool)",
|
|
23
|
+
"function grantRole(uint64 role, address account, uint32 executionDelay)",
|
|
24
|
+
"function renounceRole(uint64 role, address account)"
|
|
25
|
+
];
|
|
26
|
+
exports.ACCESS_MANAGED_ABI = [
|
|
27
|
+
"function authority() view returns (address)"
|
|
28
|
+
];
|
|
29
|
+
exports.MULTISIG_ABI = [
|
|
30
|
+
"function getOwners() view returns (address[])",
|
|
31
|
+
"function getThreshold() view returns (uint256)"
|
|
32
|
+
];
|
|
33
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/ownership-transfer/constants.ts"],"names":[],"mappings":";;;AAEa,QAAA,kBAAkB,GAAG,oEAAoE,CAAC;AAC1F,QAAA,2BAA2B,GAAG,oEAAoE,CAAC;AAGnG,QAAA,sBAAsB,GAAG;IAClC,yCAAyC;IACzC,kDAAkD;IAClD,+CAA+C;CAClD,CAAC;AAEW,QAAA,WAAW,GAAG;IACvB,8CAA8C;IAC9C,yCAAyC;CAC5C,CAAC;AAEW,QAAA,kBAAkB,GAAG;IAC9B,qEAAqE;IACrE,mDAAmD;IACnD,sDAAsD;IACtD,kEAAkE;CACrE,CAAC;AAEW,QAAA,kBAAkB,GAAG;IAC9B,oEAAoE;IACpE,yEAAyE;IACzE,qDAAqD;CACxD,CAAC;AAEW,QAAA,kBAAkB,GAAG;IAC9B,6CAA6C;CAChD,CAAC;AAEW,QAAA,YAAY,GAAG;IACxB,+CAA+C;IAC/C,gDAAgD;CACnD,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Pattern } from "./utils";
|
|
2
|
+
import { PermissionModel } from "./permission-utils";
|
|
3
|
+
import { Transaction } from "ethers";
|
|
4
|
+
export interface BytesRole {
|
|
5
|
+
name: string;
|
|
6
|
+
identifier: string;
|
|
7
|
+
}
|
|
8
|
+
export interface UintRole {
|
|
9
|
+
name: string;
|
|
10
|
+
identifier: bigint;
|
|
11
|
+
}
|
|
12
|
+
export interface ContractMetadataDetails {
|
|
13
|
+
name: string;
|
|
14
|
+
address: string;
|
|
15
|
+
pattern?: Pattern;
|
|
16
|
+
permissionModel?: PermissionModel[];
|
|
17
|
+
}
|
|
18
|
+
export interface TransactionData {
|
|
19
|
+
transaction: Transaction;
|
|
20
|
+
description?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare class ContractAdmin {
|
|
23
|
+
contractName: string;
|
|
24
|
+
pattern?: Pattern;
|
|
25
|
+
address: string;
|
|
26
|
+
permissionModel: PermissionModel[];
|
|
27
|
+
private oldOwner;
|
|
28
|
+
private newOwner;
|
|
29
|
+
private grantOwnershipRoleTxs;
|
|
30
|
+
private renounceOwnershipTxs;
|
|
31
|
+
constructor(details: ContractMetadataDetails, oldOwner: string, newOwner: string);
|
|
32
|
+
scanPatternAndPermissionModels(): Promise<void>;
|
|
33
|
+
createGrantOwnershipTransactions(bytes32RolesToCheck: BytesRole[], managerRolesToCheck: UintRole[]): Promise<void>;
|
|
34
|
+
createRenounceOwnershipTransactions(bytes32RolesToCheck: BytesRole[], managerRolesToCheck: UintRole[]): Promise<void>;
|
|
35
|
+
getGrantOwnershipTransactions(): TransactionData[];
|
|
36
|
+
getRenounceOwnershipTransactions(): TransactionData[];
|
|
37
|
+
clearRenounceTransactions(): void;
|
|
38
|
+
clearGrantTransactions(): void;
|
|
39
|
+
requiresGrantingOwnership(): boolean;
|
|
40
|
+
requiresRenouncingOwnership(): boolean;
|
|
41
|
+
displayData(columnWidths: {
|
|
42
|
+
maxNameWidth: number;
|
|
43
|
+
maxAddressWidth: number;
|
|
44
|
+
maxPermissionsWidth: number;
|
|
45
|
+
}): void;
|
|
46
|
+
private checkFindings;
|
|
47
|
+
private createTUPPGrantOwnershipTransaction;
|
|
48
|
+
private createOwnableOwnershipTransaction;
|
|
49
|
+
private createAssignUint64RolesTransactions;
|
|
50
|
+
private handleRenounceOwnershipTransaction;
|
|
51
|
+
private createRenounceUint64RolesTransactions;
|
|
52
|
+
private createAssignBytes32RolesTransactions;
|
|
53
|
+
private createRenounceBytes32RolesTransactions;
|
|
54
|
+
private isDuplicateTransaction;
|
|
55
|
+
}
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ContractAdmin = void 0;
|
|
7
|
+
// Cspell:words TUPP
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const permission_utils_1 = require("./permission-utils");
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
class ContractAdmin {
|
|
12
|
+
constructor(details, oldOwner, newOwner) {
|
|
13
|
+
this.permissionModel = [];
|
|
14
|
+
this.grantOwnershipRoleTxs = [];
|
|
15
|
+
this.renounceOwnershipTxs = [];
|
|
16
|
+
this.contractName = details.name;
|
|
17
|
+
this.pattern = details.pattern;
|
|
18
|
+
this.address = details.address;
|
|
19
|
+
this.permissionModel = details.permissionModel ?? [];
|
|
20
|
+
this.oldOwner = oldOwner;
|
|
21
|
+
this.newOwner = newOwner;
|
|
22
|
+
// Validate manual inputs if any
|
|
23
|
+
this.checkFindings();
|
|
24
|
+
}
|
|
25
|
+
async scanPatternAndPermissionModels() {
|
|
26
|
+
if (!this.pattern || !this.permissionModel.length) {
|
|
27
|
+
this.pattern = await (0, utils_1.detectPattern)(this.address);
|
|
28
|
+
this.permissionModel = await (0, permission_utils_1.getPermissionModels)(this.address);
|
|
29
|
+
this.checkFindings();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async createGrantOwnershipTransactions(bytes32RolesToCheck, managerRolesToCheck) {
|
|
33
|
+
this.clearGrantTransactions();
|
|
34
|
+
console.log(chalk_1.default.white(`* Creating Transactions to grant Ownership in ${this.contractName}.`));
|
|
35
|
+
if (this.pattern === utils_1.Pattern.TUPP) {
|
|
36
|
+
await this.createTUPPGrantOwnershipTransaction();
|
|
37
|
+
}
|
|
38
|
+
// UpgradeableBeacon is detected also as OWNABLE
|
|
39
|
+
if (this.permissionModel.includes(permission_utils_1.PermissionModel.OWNABLE)) {
|
|
40
|
+
await this.createOwnableOwnershipTransaction();
|
|
41
|
+
}
|
|
42
|
+
if (this.permissionModel.includes(permission_utils_1.PermissionModel.ROLE_BASED)) {
|
|
43
|
+
await this.createAssignBytes32RolesTransactions(bytes32RolesToCheck);
|
|
44
|
+
}
|
|
45
|
+
if (this.permissionModel.includes(permission_utils_1.PermissionModel.ACCESS_MANAGER)) {
|
|
46
|
+
await this.createAssignUint64RolesTransactions(managerRolesToCheck);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async createRenounceOwnershipTransactions(bytes32RolesToCheck, managerRolesToCheck) {
|
|
50
|
+
this.clearRenounceTransactions();
|
|
51
|
+
console.log(chalk_1.default.white(`* Creating Transactions to renounce Ownership in ${this.contractName}.`));
|
|
52
|
+
if (this.permissionModel.includes(permission_utils_1.PermissionModel.ROLE_BASED)) {
|
|
53
|
+
await this.createRenounceBytes32RolesTransactions(bytes32RolesToCheck);
|
|
54
|
+
}
|
|
55
|
+
if (this.permissionModel.includes(permission_utils_1.PermissionModel.ACCESS_MANAGER)) {
|
|
56
|
+
await this.createRenounceUint64RolesTransactions(managerRolesToCheck);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
getGrantOwnershipTransactions() {
|
|
60
|
+
return this.grantOwnershipRoleTxs;
|
|
61
|
+
}
|
|
62
|
+
getRenounceOwnershipTransactions() {
|
|
63
|
+
return this.renounceOwnershipTxs;
|
|
64
|
+
}
|
|
65
|
+
clearRenounceTransactions() {
|
|
66
|
+
this.renounceOwnershipTxs = [];
|
|
67
|
+
}
|
|
68
|
+
clearGrantTransactions() {
|
|
69
|
+
this.grantOwnershipRoleTxs = [];
|
|
70
|
+
}
|
|
71
|
+
requiresGrantingOwnership() {
|
|
72
|
+
return Boolean(this.grantOwnershipRoleTxs.length);
|
|
73
|
+
}
|
|
74
|
+
requiresRenouncingOwnership() {
|
|
75
|
+
return Boolean(this.renounceOwnershipTxs.length);
|
|
76
|
+
}
|
|
77
|
+
displayData(columnWidths) {
|
|
78
|
+
const { maxNameWidth, maxAddressWidth, maxPermissionsWidth } = columnWidths;
|
|
79
|
+
const name = this.contractName.padEnd(maxNameWidth);
|
|
80
|
+
const address = this.address.padEnd(maxAddressWidth);
|
|
81
|
+
const permissions = (this.permissionModel?.join(", ") || "None").padEnd(maxPermissionsWidth);
|
|
82
|
+
let status = chalk_1.default.green("ALL DONE");
|
|
83
|
+
if (this.grantOwnershipRoleTxs.length) {
|
|
84
|
+
status = chalk_1.default.yellow("GRANT OWNERSHIP REQUIRED");
|
|
85
|
+
}
|
|
86
|
+
else if (this.renounceOwnershipTxs.length) {
|
|
87
|
+
status = chalk_1.default.yellow("REVOKE ROLES REQUIRED");
|
|
88
|
+
}
|
|
89
|
+
console.log(chalk_1.default.gray(` ${name} ${address} ${permissions} `) + status);
|
|
90
|
+
}
|
|
91
|
+
checkFindings() {
|
|
92
|
+
const maxPermissionsIfBeacon = 1;
|
|
93
|
+
if (this.pattern === utils_1.Pattern.BEACON &&
|
|
94
|
+
!this.permissionModel?.includes(permission_utils_1.PermissionModel.OWNABLE) &&
|
|
95
|
+
this.permissionModel?.length !== maxPermissionsIfBeacon) {
|
|
96
|
+
throw new Error(`UpgradeableBeacon at address ${this.address} should ONLY have OWNABLE permission model.`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async createTUPPGrantOwnershipTransaction() {
|
|
100
|
+
const admin = await (0, utils_1.getAdminAddress)(this.address);
|
|
101
|
+
await this.createOwnableOwnershipTransaction({ address: admin, name: `${this.contractName} Proxy Admin` });
|
|
102
|
+
}
|
|
103
|
+
async createOwnableOwnershipTransaction(contractId = { address: this.address, name: this.contractName }) {
|
|
104
|
+
const tx = await (0, permission_utils_1.transferOwnership)(contractId.address, this.newOwner, this.oldOwner);
|
|
105
|
+
if (tx) {
|
|
106
|
+
if (this.isDuplicateTransaction({ transaction: tx })) {
|
|
107
|
+
throw new Error(`Error: Duplicate transaction to transfer ownership of ${contractId.name} at ${contractId.address} was already created.`);
|
|
108
|
+
}
|
|
109
|
+
const description = `-> Tx to change ${contractId.name} Owner at ${contractId.address} to ${this.newOwner}`;
|
|
110
|
+
console.log(chalk_1.default.yellow(` ${description} created.`));
|
|
111
|
+
this.grantOwnershipRoleTxs.push({
|
|
112
|
+
description,
|
|
113
|
+
transaction: tx
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async createAssignUint64RolesTransactions(managerRolesToCheck) {
|
|
118
|
+
for (const role of managerRolesToCheck) {
|
|
119
|
+
// Required to process sequentially as it access shared memory state and RPC rate limits
|
|
120
|
+
// eslint-disable-next-line no-await-in-loop
|
|
121
|
+
const tx = await (0, permission_utils_1.grantAccessManagerRole)({
|
|
122
|
+
contractAddress: this.address,
|
|
123
|
+
newAccount: this.newOwner,
|
|
124
|
+
oldAccount: this.oldOwner,
|
|
125
|
+
role: role.identifier,
|
|
126
|
+
});
|
|
127
|
+
if (tx) {
|
|
128
|
+
if (this.isDuplicateTransaction({ transaction: tx })) {
|
|
129
|
+
throw new Error(`Error: Transaction to grant manager role ${role.name} in ${this.contractName} was already created.`);
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
const description = `-> Tx to grant role ${role.name} to ${this.newOwner} in ${this.contractName}`;
|
|
133
|
+
console.log(chalk_1.default.yellow(` ${description} created.`));
|
|
134
|
+
this.grantOwnershipRoleTxs.push({ description, transaction: tx });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
handleRenounceOwnershipTransaction(tx, roleName) {
|
|
140
|
+
if (typeof tx !== "boolean" && tx) {
|
|
141
|
+
if (this.isDuplicateTransaction({ transaction: tx })) {
|
|
142
|
+
throw new Error(`Error: Transaction to renounce role ${roleName} in ${this.contractName} was already created.`);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const description = `-> Tx to renounce role ${roleName} from ${this.oldOwner} in ${this.contractName}`;
|
|
146
|
+
console.log(chalk_1.default.yellow(` ${description} created.`));
|
|
147
|
+
this.renounceOwnershipTxs.push({ description, transaction: tx });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else if (!tx) {
|
|
151
|
+
console.log(chalk_1.default.yellow(` WARNING: Skipping revocation of role ${roleName} in ${this.contractName} as it requires at least 1 member left.`));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async createRenounceUint64RolesTransactions(managerRolesToCheck) {
|
|
155
|
+
for (const role of managerRolesToCheck) {
|
|
156
|
+
// Required to process sequentially as it access shared memory state and RPC rate limits
|
|
157
|
+
// eslint-disable-next-line no-await-in-loop
|
|
158
|
+
const tx = await (0, permission_utils_1.renounceAccessManagerRole)({
|
|
159
|
+
contractAddress: this.address,
|
|
160
|
+
newAccount: this.newOwner,
|
|
161
|
+
oldAccount: this.oldOwner,
|
|
162
|
+
role: role.identifier,
|
|
163
|
+
});
|
|
164
|
+
this.handleRenounceOwnershipTransaction(tx, role.name);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
async createAssignBytes32RolesTransactions(bytes32RolesToCheck) {
|
|
168
|
+
for (const role of bytes32RolesToCheck) {
|
|
169
|
+
// Required to process sequentially as it access shared memory state and RPC rate limits
|
|
170
|
+
// eslint-disable-next-line no-await-in-loop
|
|
171
|
+
const tx = await (0, permission_utils_1.grantRole)({
|
|
172
|
+
contractAddress: this.address,
|
|
173
|
+
newAccount: this.newOwner,
|
|
174
|
+
oldAccount: this.oldOwner,
|
|
175
|
+
role: role.identifier,
|
|
176
|
+
});
|
|
177
|
+
if (tx) {
|
|
178
|
+
if (this.isDuplicateTransaction({ transaction: tx })) {
|
|
179
|
+
throw new Error(`Error: Transaction to grant role ${role.name} in ${this.contractName} was already created.`);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
const description = `-> Tx to grant role ${role.name} to ${this.newOwner} in ${this.contractName}`;
|
|
183
|
+
console.log(chalk_1.default.yellow(` ${description} created.`));
|
|
184
|
+
this.grantOwnershipRoleTxs.push({ description, transaction: tx });
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async createRenounceBytes32RolesTransactions(bytes32RolesToCheck) {
|
|
190
|
+
for (const role of bytes32RolesToCheck) {
|
|
191
|
+
// Required to process sequentially as it access shared memory state and due to RPC rate limits
|
|
192
|
+
// eslint-disable-next-line no-await-in-loop
|
|
193
|
+
const tx = await (0, permission_utils_1.renounceRole)(this.address, role.identifier, this.oldOwner);
|
|
194
|
+
this.handleRenounceOwnershipTransaction(tx, role.name);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
isDuplicateTransaction(transaction) {
|
|
198
|
+
const isGrantDuplicate = this.grantOwnershipRoleTxs.some((existingTx) => existingTx.transaction.to === transaction.transaction.to &&
|
|
199
|
+
existingTx.transaction.data === transaction.transaction.data);
|
|
200
|
+
const isRenounceDuplicate = this.renounceOwnershipTxs.some((existingTx) => existingTx.transaction.to === transaction.transaction.to &&
|
|
201
|
+
existingTx.transaction.data === transaction.transaction.data);
|
|
202
|
+
return isGrantDuplicate || isRenounceDuplicate;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.ContractAdmin = ContractAdmin;
|
|
206
|
+
//# sourceMappingURL=contractAdmin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contractAdmin.js","sourceRoot":"","sources":["../../../src/ownership-transfer/contractAdmin.ts"],"names":[],"mappings":";;;;;;AAAA,oBAAoB;AACpB,mCAAgE;AAChE,yDAQ4B;AAE5B,kDAA0B;AAwB1B,MAAa,aAAa;IAWtB,YAAY,OAAgC,EAAE,QAAgB,EAAE,QAAgB;QAPzE,oBAAe,GAAsB,EAAE,CAAC;QAIvC,0BAAqB,GAAsB,EAAE,CAAC;QAC9C,yBAAoB,GAAsB,EAAE,CAAC;QAGjD,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAC;QACrD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,gCAAgC;QAChC,IAAI,CAAC,aAAa,EAAE,CAAC;IACzB,CAAC;IAEM,KAAK,CAAC,8BAA8B;QACvC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC;YAChD,IAAI,CAAC,OAAO,GAAG,MAAM,IAAA,qBAAa,EAAC,IAAI,CAAC,OAA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AAI,mBAAmB,EAAE,CAAC;YACrC,+FAA+F;YAC/F,4CAA4C;YAC5C,MAAM,EAAE,GAAG,MAAM,IAAA,+BAAY,EAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;YAC5E,IAAI,CAAC,kCAAkC,CAAC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3D,CAAC;IACL,CAAC;IAEO,sBAAsB,CAAC,WAA4B;QACvD,MAAM,gBAAgB,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAI,CACpD,CAAC,UAAU,EAAE,EAAE,CACX,UAAU,CAAC,WAAW,CAAC,EAAE,KAAK,WAAW,CAAC,WAAW,CAAC,EAAE;YACxD,UAAU,CAAC,WAAW,CAAC,IAAI,KAAK,WAAW,CAAC,WAAW,CAAC,IAAI,CACnE,CAAC;QACF,MAAM,mBAAmB,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,CACtD,CAAC,UAAU,EAAE,EAAE,CACX,UAAU,CAAC,WAAW,CAAC,EAAE,KAAK,WAAW,CAAC,WAAW,CAAC,EAAE;YACxD,UAAU,CAAC,WAAW,CAAC,IAAI,KAAK,WAAW,CAAC,WAAW,CAAC,IAAI,CACnE,CAAC;QACF,OAAQ,gBAAgB,IAAI,mBAAmB,CAAC;IACpD,CAAC;CACJ;AAlQD,sCAkQC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { EoaSubmitter, SafeSubmitter } from "../submitters";
|
|
2
|
+
import { Instance } from "@skalenetwork/skale-contracts-ethers-v6";
|
|
3
|
+
export interface InstanceAdminOptions {
|
|
4
|
+
oldOwner: string;
|
|
5
|
+
submitter: SafeSubmitter | EoaSubmitter;
|
|
6
|
+
renounceRoles: boolean;
|
|
7
|
+
newOwner: string;
|
|
8
|
+
readonly: boolean;
|
|
9
|
+
testMode: boolean;
|
|
10
|
+
rolesToCheck?: string[];
|
|
11
|
+
managerRolesToCheck?: bigint[];
|
|
12
|
+
}
|
|
13
|
+
interface ContractId {
|
|
14
|
+
name: string;
|
|
15
|
+
address?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare class InstanceAdmin {
|
|
18
|
+
private instance?;
|
|
19
|
+
private contractMetadata;
|
|
20
|
+
private contractIds;
|
|
21
|
+
private bytes32RolesToCheck;
|
|
22
|
+
private managerRolesToCheck;
|
|
23
|
+
private oldOwner;
|
|
24
|
+
private newOwner;
|
|
25
|
+
private readonly;
|
|
26
|
+
private submitter;
|
|
27
|
+
private renounceRoles;
|
|
28
|
+
private testMode;
|
|
29
|
+
constructor(contractIds: ContractId[], options: InstanceAdminOptions, instance?: Instance);
|
|
30
|
+
executeOwnershipTransfer(): Promise<void>;
|
|
31
|
+
private initialize;
|
|
32
|
+
private processGrantStepIfRequired;
|
|
33
|
+
private processRenounceStepIfRequired;
|
|
34
|
+
private submitRenounceRolesTransactions;
|
|
35
|
+
private confirmAndSubmitTransactions;
|
|
36
|
+
private submitGrantOwnershipTransactions;
|
|
37
|
+
private ownershipGrantingRequired;
|
|
38
|
+
private ownershipRevokingRequired;
|
|
39
|
+
private resolveContractAddress;
|
|
40
|
+
private loadContractMetadataAndCreateTransactions;
|
|
41
|
+
private confirmData;
|
|
42
|
+
private processOptions;
|
|
43
|
+
private createRequiredTransactions;
|
|
44
|
+
private getColumnWidths;
|
|
45
|
+
private displayPatternGroup;
|
|
46
|
+
private displayFindings;
|
|
47
|
+
private handleUserRejection;
|
|
48
|
+
private groupMetadataByPattern;
|
|
49
|
+
private promptConfirmation;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.InstanceAdmin = void 0;
|
|
7
|
+
// Cspell:words keccak
|
|
8
|
+
const contractAdmin_1 = require("./contractAdmin");
|
|
9
|
+
const submitters_1 = require("../submitters");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
12
|
+
const hardhat_1 = require("hardhat");
|
|
13
|
+
const ZERO = 0;
|
|
14
|
+
class InstanceAdmin {
|
|
15
|
+
constructor(contractIds, options, instance) {
|
|
16
|
+
this.contractMetadata = new Map();
|
|
17
|
+
this.bytes32RolesToCheck = [];
|
|
18
|
+
this.managerRolesToCheck = [];
|
|
19
|
+
this.instance = instance;
|
|
20
|
+
this.contractIds = contractIds;
|
|
21
|
+
this.readonly = options.readonly;
|
|
22
|
+
this.newOwner = options.newOwner;
|
|
23
|
+
this.submitter = options.submitter;
|
|
24
|
+
this.oldOwner = options.oldOwner;
|
|
25
|
+
this.renounceRoles = options.renounceRoles;
|
|
26
|
+
this.testMode = options.testMode;
|
|
27
|
+
this.processOptions(options);
|
|
28
|
+
}
|
|
29
|
+
async executeOwnershipTransfer() {
|
|
30
|
+
// Confirm data found in initialization
|
|
31
|
+
await this.initialize();
|
|
32
|
+
if (this.readonly) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
await this.processGrantStepIfRequired();
|
|
36
|
+
await this.processRenounceStepIfRequired();
|
|
37
|
+
this.displayFindings();
|
|
38
|
+
if (this.ownershipGrantingRequired() || (this.ownershipRevokingRequired() && this.renounceRoles)) {
|
|
39
|
+
console.error(chalk_1.default.red("Unexpected state: There are still actions required."));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log(chalk_1.default.green("Ownership transfer process completed. - Nothing more to do."));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async initialize() {
|
|
46
|
+
await this.loadContractMetadataAndCreateTransactions();
|
|
47
|
+
await this.confirmData();
|
|
48
|
+
}
|
|
49
|
+
async processGrantStepIfRequired() {
|
|
50
|
+
if (this.ownershipGrantingRequired()) {
|
|
51
|
+
await this.submitGrantOwnershipTransactions();
|
|
52
|
+
if (this.renounceRoles) {
|
|
53
|
+
await this.createRequiredTransactions();
|
|
54
|
+
}
|
|
55
|
+
await this.confirmData();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async processRenounceStepIfRequired() {
|
|
59
|
+
if (this.renounceRoles && this.ownershipRevokingRequired() === true) {
|
|
60
|
+
await this.submitRenounceRolesTransactions();
|
|
61
|
+
await this.createRequiredTransactions();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async submitRenounceRolesTransactions() {
|
|
65
|
+
const txsToSubmit = [];
|
|
66
|
+
for (const contract of this.contractMetadata.values()) {
|
|
67
|
+
txsToSubmit.push(...contract.getRenounceOwnershipTransactions());
|
|
68
|
+
contract.clearRenounceTransactions();
|
|
69
|
+
}
|
|
70
|
+
console.log(chalk_1.default.green(`Submitting ${txsToSubmit.length} renounce ownership transactions...`));
|
|
71
|
+
for (const [index, txData] of txsToSubmit.entries()) {
|
|
72
|
+
console.log(chalk_1.default.grey(` -> Transaction ${index}: ${txData.description || "No description"}`));
|
|
73
|
+
}
|
|
74
|
+
await this.confirmAndSubmitTransactions(txsToSubmit);
|
|
75
|
+
}
|
|
76
|
+
async confirmAndSubmitTransactions(txsToSubmit) {
|
|
77
|
+
const confirmation = await this.promptConfirmation("Do you want to proceed with submitting these transactions?");
|
|
78
|
+
if (!confirmation) {
|
|
79
|
+
throw new Error("Transaction submission aborted by user.");
|
|
80
|
+
}
|
|
81
|
+
await this.submitter.submit(txsToSubmit.map(tx => tx.transaction));
|
|
82
|
+
if (this.submitter instanceof submitters_1.SafeSubmitter) {
|
|
83
|
+
await this.promptConfirmation("Please proceed only AFTER the Safe transactions have been executed on-chain.\n" +
|
|
84
|
+
"Do you want to proceed?");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async submitGrantOwnershipTransactions() {
|
|
88
|
+
const txsToSubmit = [];
|
|
89
|
+
for (const contract of this.contractMetadata.values()) {
|
|
90
|
+
txsToSubmit.push(...contract.getGrantOwnershipTransactions());
|
|
91
|
+
contract.clearGrantTransactions();
|
|
92
|
+
}
|
|
93
|
+
// Required for ProxyAdmins shared among multiple contracts
|
|
94
|
+
const txsToSubmitFiltered = (0, utils_1.removeDuplicateTransactions)(txsToSubmit);
|
|
95
|
+
console.log(chalk_1.default.green(`Submitting ${txsToSubmitFiltered.length} unique grant ownership transactions...`));
|
|
96
|
+
for (const [index, txData] of txsToSubmitFiltered.entries()) {
|
|
97
|
+
console.log(chalk_1.default.grey(` -> Transaction ${index}: ${txData.description || "No description"}`));
|
|
98
|
+
}
|
|
99
|
+
await this.confirmAndSubmitTransactions(txsToSubmit);
|
|
100
|
+
}
|
|
101
|
+
ownershipGrantingRequired() {
|
|
102
|
+
return Array.from(this.contractMetadata.values()).some(contract => contract.requiresGrantingOwnership());
|
|
103
|
+
}
|
|
104
|
+
ownershipRevokingRequired() {
|
|
105
|
+
return Array.from(this.contractMetadata.values()).some(contract => contract.requiresRenouncingOwnership());
|
|
106
|
+
}
|
|
107
|
+
async resolveContractAddress(contractName) {
|
|
108
|
+
if (!this.instance) {
|
|
109
|
+
throw new Error(`Instance is not defined. Cannot resolve ${contractName} address.`);
|
|
110
|
+
}
|
|
111
|
+
return await this.instance.getContractAddress(contractName);
|
|
112
|
+
}
|
|
113
|
+
async loadContractMetadataAndCreateTransactions() {
|
|
114
|
+
/* eslint-disable no-await-in-loop */
|
|
115
|
+
// Do not parallelize to avoid rate limit issues which CAN produce wrong outputs - sensitive
|
|
116
|
+
for (const { name: contractName, address } of this.contractIds) {
|
|
117
|
+
const resolvedAddress = address || await this.resolveContractAddress(contractName);
|
|
118
|
+
if (!this.contractMetadata.has(resolvedAddress)) {
|
|
119
|
+
const details = {
|
|
120
|
+
address: resolvedAddress,
|
|
121
|
+
name: contractName,
|
|
122
|
+
};
|
|
123
|
+
const contractAdmin = new contractAdmin_1.ContractAdmin(details, this.oldOwner, this.newOwner);
|
|
124
|
+
await contractAdmin.scanPatternAndPermissionModels();
|
|
125
|
+
this.contractMetadata.set(resolvedAddress, contractAdmin);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/* eslint-enable no-await-in-loop */
|
|
129
|
+
await this.createRequiredTransactions();
|
|
130
|
+
}
|
|
131
|
+
async confirmData() {
|
|
132
|
+
this.displayFindings();
|
|
133
|
+
const userConfirmed = await this.promptConfirmation();
|
|
134
|
+
if (!userConfirmed) {
|
|
135
|
+
this.handleUserRejection();
|
|
136
|
+
}
|
|
137
|
+
console.log(chalk_1.default.green("\nUser confirmed. Proceeding...\n"));
|
|
138
|
+
}
|
|
139
|
+
processOptions(options) {
|
|
140
|
+
this.bytes32RolesToCheck = (options.rolesToCheck ?? []).map(role => ({
|
|
141
|
+
// Never will include "0x00..." as role - default admin handled separately
|
|
142
|
+
identifier: hardhat_1.ethers.id(role),
|
|
143
|
+
name: role
|
|
144
|
+
}));
|
|
145
|
+
this.bytes32RolesToCheck.push({ identifier: hardhat_1.ethers.ZeroHash, name: "DEFAULT_ADMIN_ROLE" });
|
|
146
|
+
if (!this.readonly && this.newOwner === hardhat_1.ethers.ZeroAddress) {
|
|
147
|
+
throw new Error("New owner address must be provided in options when in write mode.");
|
|
148
|
+
}
|
|
149
|
+
this.managerRolesToCheck = (options.managerRolesToCheck ?? []).map(role => {
|
|
150
|
+
if (typeof role !== "bigint" || role <= ZERO) {
|
|
151
|
+
throw new Error(`Invalid manager role: ${role}. Must be a non-zero bigint.`);
|
|
152
|
+
}
|
|
153
|
+
return { identifier: role, name: `Role ${role}` };
|
|
154
|
+
});
|
|
155
|
+
this.managerRolesToCheck.push({ identifier: BigInt(ZERO), name: "ADMIN_ROLE" });
|
|
156
|
+
}
|
|
157
|
+
async createRequiredTransactions() {
|
|
158
|
+
console.log(chalk_1.default.grey("INFO: The next Following steps will NOT submit any transactions to the blockchain."));
|
|
159
|
+
// Preferred to create sequentially due to rate limits of RPC providers - sensitive
|
|
160
|
+
/* eslint-disable no-await-in-loop */
|
|
161
|
+
for (const contract of this.contractMetadata.values()) {
|
|
162
|
+
await contract.createGrantOwnershipTransactions(this.bytes32RolesToCheck, this.managerRolesToCheck);
|
|
163
|
+
if (!contract.requiresGrantingOwnership()) {
|
|
164
|
+
await contract.createRenounceOwnershipTransactions(this.bytes32RolesToCheck, this.managerRolesToCheck);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
/* eslint-enable no-await-in-loop */
|
|
168
|
+
}
|
|
169
|
+
getColumnWidths() {
|
|
170
|
+
let maxNameWidth = 0;
|
|
171
|
+
let maxAddressWidth = 0;
|
|
172
|
+
let maxPermissionsWidth = 0;
|
|
173
|
+
for (const contract of this.contractMetadata.values()) {
|
|
174
|
+
maxNameWidth = Math.max(maxNameWidth, contract.contractName.length);
|
|
175
|
+
maxAddressWidth = Math.max(maxAddressWidth, contract.address.length);
|
|
176
|
+
const permissions = contract.permissionModel?.join(", ") || "None";
|
|
177
|
+
maxPermissionsWidth = Math.max(maxPermissionsWidth, permissions.length);
|
|
178
|
+
}
|
|
179
|
+
return { maxAddressWidth, maxNameWidth, maxPermissionsWidth };
|
|
180
|
+
}
|
|
181
|
+
displayPatternGroup(pattern, contracts) {
|
|
182
|
+
const columnWidths = this.getColumnWidths();
|
|
183
|
+
console.log(chalk_1.default.bold(`\n${pattern} Pattern (${contracts.length} contracts):`));
|
|
184
|
+
for (const contract of contracts) {
|
|
185
|
+
contract.displayData(columnWidths);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
displayFindings() {
|
|
189
|
+
console.log(chalk_1.default.cyan("\n=== Ownership Status Results ===\n"));
|
|
190
|
+
const groupedByPattern = this.groupMetadataByPattern();
|
|
191
|
+
for (const [pattern, contracts] of Object.entries(groupedByPattern)) {
|
|
192
|
+
if (contracts.length) {
|
|
193
|
+
this.displayPatternGroup(pattern, contracts);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
console.log(chalk_1.default.cyan("\n==========================================\n"));
|
|
197
|
+
}
|
|
198
|
+
handleUserRejection() {
|
|
199
|
+
console.log(chalk_1.default.red("User did not confirm. Aborting and clearing all data..."));
|
|
200
|
+
this.contractMetadata.clear();
|
|
201
|
+
throw new Error("User aborted because some data was inaccurate. Data has been cleared.");
|
|
202
|
+
}
|
|
203
|
+
groupMetadataByPattern() {
|
|
204
|
+
const grouped = Object.values(utils_1.Pattern).
|
|
205
|
+
reduce((acc, pattern) => {
|
|
206
|
+
acc[pattern] = [];
|
|
207
|
+
return acc;
|
|
208
|
+
}, {});
|
|
209
|
+
for (const metadata of this.contractMetadata.values()) {
|
|
210
|
+
// Used only after scan - will be defined if it reaches here
|
|
211
|
+
grouped[metadata.pattern].push(metadata);
|
|
212
|
+
}
|
|
213
|
+
return grouped;
|
|
214
|
+
}
|
|
215
|
+
async promptConfirmation(msg) {
|
|
216
|
+
if (this.testMode) {
|
|
217
|
+
return true;
|
|
218
|
+
}
|
|
219
|
+
return await (0, utils_1.promptUserConfirmation)(msg);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
exports.InstanceAdmin = InstanceAdmin;
|
|
223
|
+
//# sourceMappingURL=instanceAdmin.js.map
|