@skalenetwork/upgrade-tools 4.0.0-update-verify.5 → 4.0.0-update-gnosis-service.0
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 +23 -12
- package/dist/src/contractVerifier.js +47 -43
- package/dist/src/contractVerifier.js.map +1 -1
- package/dist/src/gnosis-safe.js +6 -37
- package/dist/src/gnosis-safe.js.map +1 -1
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/proxyUpgrader.d.ts +18 -0
- package/dist/src/proxyUpgrader.js +72 -0
- package/dist/src/proxyUpgrader.js.map +1 -0
- package/dist/src/upgrader.d.ts +11 -6
- package/dist/src/upgrader.js +61 -61
- package/dist/src/upgrader.js.map +1 -1
- package/dist/src/upgraders/abstractTransparentProxyUpgrader.d.ts +19 -0
- package/dist/src/upgraders/abstractTransparentProxyUpgrader.js +57 -0
- package/dist/src/upgraders/abstractTransparentProxyUpgrader.js.map +1 -0
- package/dist/src/upgraders/beaconUpgrader.d.ts +8 -0
- package/dist/src/upgraders/beaconUpgrader.js +37 -0
- package/dist/src/upgraders/beaconUpgrader.js.map +1 -0
- package/dist/src/upgraders/transparentProxyUpgrader.d.ts +5 -0
- package/dist/src/upgraders/transparentProxyUpgrader.js +20 -0
- package/dist/src/upgraders/transparentProxyUpgrader.js.map +1 -0
- package/dist/src/upgraders/v4TransparentProxyUpgrader.d.ts +5 -0
- package/dist/src/upgraders/v4TransparentProxyUpgrader.js +19 -0
- package/dist/src/upgraders/v4TransparentProxyUpgrader.js.map +1 -0
- package/dist/src/verification.d.ts +2 -17
- package/dist/src/verification.js +55 -206
- package/dist/src/verification.js.map +1 -1
- package/dist/src/verifiers/blockscoutVerifier.d.ts +11 -0
- package/dist/src/verifiers/blockscoutVerifier.js +65 -0
- package/dist/src/verifiers/blockscoutVerifier.js.map +1 -0
- package/dist/src/verifiers/etherscanVerifier.d.ts +19 -0
- package/dist/src/verifiers/etherscanVerifier.js +105 -0
- package/dist/src/verifiers/etherscanVerifier.js.map +1 -0
- package/dist/src/verifiers/skaleBlockscoutVerifier.d.ts +7 -0
- package/dist/src/verifiers/skaleBlockscoutVerifier.js +60 -0
- package/dist/src/verifiers/skaleBlockscoutVerifier.js.map +1 -0
- package/package.json +4 -4
- package/dist/src/proxyAdmin.d.ts +0 -4
- package/dist/src/proxyAdmin.js +0 -56
- package/dist/src/proxyAdmin.js.map +0 -1
|
@@ -1,14 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { ValidationResponse } from "@nomicfoundation/hardhat-verify/internal/utilities";
|
|
2
|
+
export interface VerificationTarget {
|
|
3
|
+
contractName: string;
|
|
4
|
+
contractAddress: string;
|
|
5
|
+
}
|
|
6
|
+
export interface VerificationRequestParameters {
|
|
7
|
+
solcInputJson: string;
|
|
8
|
+
fullContractName: string;
|
|
9
|
+
compilerVersion: string;
|
|
10
|
+
}
|
|
11
|
+
export declare abstract class ContractVerifier {
|
|
12
|
+
abstract name: string;
|
|
13
|
+
private readonly PROXY_CONTRACT_NAME;
|
|
14
|
+
verify: (verificationTarget: VerificationTarget, attempts?: number) => Promise<void>;
|
|
15
|
+
attemptVerification(verificationTarget: VerificationTarget): Promise<boolean>;
|
|
16
|
+
protected abstract isAlreadyVerified(verificationTarget: VerificationTarget): Promise<boolean>;
|
|
17
|
+
protected abstract submitVerificationRequest(target: VerificationTarget, params: VerificationRequestParameters): Promise<ValidationResponse>;
|
|
18
|
+
protected abstract getContractUrl(verificationTarget: VerificationTarget): string;
|
|
19
|
+
protected getVerifyParameters(contractName: string): Promise<{
|
|
20
|
+
compilerVersion: string;
|
|
21
|
+
fullContractName: string;
|
|
22
|
+
solcInputJson: string;
|
|
23
|
+
}>;
|
|
12
24
|
private checkVerificationStatus;
|
|
13
|
-
attempt(): Promise<boolean>;
|
|
14
25
|
}
|
|
@@ -4,63 +4,67 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ContractVerifier = void 0;
|
|
7
|
-
const
|
|
8
|
-
const etherscan_1 = require("@nomicfoundation/hardhat-verify/etherscan");
|
|
7
|
+
const hardhat_1 = require("hardhat");
|
|
9
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const TransparentUpgradeableProxy_json_1 = __importDefault(require("@openzeppelin/upgrades-core/artifacts/@openzeppelin/contracts-v5/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json"));
|
|
10
|
+
const build_info_v5_json_1 = __importDefault(require("@openzeppelin/upgrades-core/artifacts/build-info-v5.json"));
|
|
11
|
+
const DEFAULT_RETRIES_AMOUNT = 5;
|
|
10
12
|
class ContractVerifier {
|
|
11
|
-
constructor(
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
constructor() {
|
|
14
|
+
this.PROXY_CONTRACT_NAME = "TransparentUpgradeableProxy";
|
|
15
|
+
this.verify = async (verificationTarget, attempts = DEFAULT_RETRIES_AMOUNT) => {
|
|
16
|
+
const limit = 0;
|
|
17
|
+
if (attempts > limit) {
|
|
18
|
+
if (!await this.attemptVerification(verificationTarget)) {
|
|
19
|
+
const failedAttempts = 1;
|
|
20
|
+
await this.verify(verificationTarget, attempts - failedAttempts);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
18
24
|
}
|
|
19
|
-
async
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
if (!verified) {
|
|
25
|
-
verified = await (0, verification_1.isVerifiedOnBlockscout)(this.apiURL, this.contractAddress);
|
|
26
|
-
}
|
|
27
|
-
if (verified) {
|
|
28
|
-
console.log(`${this.contractName} is already verified on: ${this.etherscan.getContractUrl(this.contractAddress)}`);
|
|
25
|
+
async attemptVerification(verificationTarget) {
|
|
26
|
+
if (await this.isAlreadyVerified(verificationTarget)) {
|
|
27
|
+
console.log(chalk_1.default.cyan(`${verificationTarget.contractName} is already verified on ${this.name}:\n${this.getContractUrl(verificationTarget)}`));
|
|
28
|
+
return true;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
async submitVerification(params) {
|
|
30
|
+
const params = await this.getVerifyParameters(verificationTarget.contractName);
|
|
33
31
|
try {
|
|
34
|
-
const
|
|
35
|
-
return
|
|
32
|
+
const response = await this.submitVerificationRequest(verificationTarget, params);
|
|
33
|
+
return this.checkVerificationStatus(verificationTarget, response);
|
|
36
34
|
}
|
|
37
35
|
catch (error) {
|
|
38
|
-
console.log(chalk_1.default.yellow(`Verification attempt for ${
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
async checkVerificationStatus(guid) {
|
|
43
|
-
const status = await this.etherscan.getVerificationStatus(guid);
|
|
44
|
-
if (status.isFailure()) {
|
|
45
|
-
console.log(chalk_1.default.red(`Failed to verify contract ${this.contractName}`));
|
|
36
|
+
console.log(chalk_1.default.yellow(`Verification attempt for ${verificationTarget.contractName} failed on ${this.name} with error: ${error}`));
|
|
46
37
|
return false;
|
|
47
38
|
}
|
|
48
|
-
console.log(`${this.contractName} is successfully verified on: ${this.etherscan.getContractUrl(this.contractAddress)}`);
|
|
49
|
-
return true;
|
|
50
39
|
}
|
|
51
|
-
async
|
|
52
|
-
if (
|
|
53
|
-
return
|
|
40
|
+
async getVerifyParameters(contractName) {
|
|
41
|
+
if (contractName === this.PROXY_CONTRACT_NAME) {
|
|
42
|
+
return {
|
|
43
|
+
compilerVersion: build_info_v5_json_1.default.solcLongVersion,
|
|
44
|
+
fullContractName: `${TransparentUpgradeableProxy_json_1.default.sourceName}:${contractName}`,
|
|
45
|
+
solcInputJson: JSON.stringify(build_info_v5_json_1.default.input)
|
|
46
|
+
};
|
|
54
47
|
}
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
48
|
+
const artifact = await hardhat_1.artifacts.readArtifact(contractName);
|
|
49
|
+
const fullContractName = `${artifact.sourceName}:${contractName}`;
|
|
50
|
+
const buildInfo = await hardhat_1.artifacts.getBuildInfo(fullContractName);
|
|
51
|
+
if (!buildInfo) {
|
|
52
|
+
throw new Error(`No build-info for ${contractName}`);
|
|
58
53
|
}
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
return {
|
|
55
|
+
compilerVersion: buildInfo.solcLongVersion,
|
|
56
|
+
fullContractName,
|
|
57
|
+
solcInputJson: JSON.stringify(buildInfo.input)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
// Private
|
|
61
|
+
checkVerificationStatus(verificationTarget, response) {
|
|
62
|
+
if (response.isFailure()) {
|
|
63
|
+
console.log(chalk_1.default.red(`Failed to verify contract ${verificationTarget.contractName}`));
|
|
61
64
|
return false;
|
|
62
65
|
}
|
|
63
|
-
|
|
66
|
+
console.log(chalk_1.default.cyan(`${verificationTarget.contractName} is successfully verified on ${this.name}:\n${this.getContractUrl(verificationTarget)}`));
|
|
67
|
+
return true;
|
|
64
68
|
}
|
|
65
69
|
}
|
|
66
70
|
exports.ContractVerifier = ContractVerifier;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contractVerifier.js","sourceRoot":"","sources":["../../src/contractVerifier.ts"],"names":[],"mappings":";;;;;;
|
|
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;AAajC,MAAsB,gBAAgB;IAAtC;QAEqB,wBAAm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I,CAAC;IAChB,CAAC;CACJ;AAhGD,4CAgGC"}
|
package/dist/src/gnosis-safe.js
CHANGED
|
@@ -5,38 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createMultiSendTransaction = void 0;
|
|
7
7
|
const safe_core_sdk_types_1 = require("@safe-global/safe-core-sdk-types");
|
|
8
|
-
const ethers_1 = require("ethers");
|
|
9
8
|
const hardhat_1 = require("hardhat");
|
|
10
9
|
const protocol_kit_1 = __importDefault(require("@safe-global/protocol-kit"));
|
|
11
10
|
const api_kit_1 = __importDefault(require("@safe-global/api-kit"));
|
|
12
11
|
// Cspell:words arbitrum celo sepolia xdai holesky
|
|
13
|
-
// Constants
|
|
14
|
-
const URLS = {
|
|
15
|
-
"safe_transaction": {
|
|
16
|
-
[ethers_1.Network.from("mainnet").chainId.toString()]: "https://safe-transaction-mainnet.safe.global/api",
|
|
17
|
-
[ethers_1.Network.from("arbitrum").chainId.toString()]: "https://safe-transaction-arbitrum.safe.global/api",
|
|
18
|
-
[ethers_1.Network.from("base").chainId.toString()]: "https://safe-transaction-base.safe.global/api",
|
|
19
|
-
[ethers_1.Network.from("base-sepolia").chainId.toString()]: "https://safe-transaction-base-sepolia.safe.global/api",
|
|
20
|
-
[ethers_1.Network.from("bnb").chainId.toString()]: "https://safe-transaction-bsc.safe.global/api",
|
|
21
|
-
[ethers_1.Network.from("xdai").chainId.toString()]: "https://safe-transaction-gnosis-chain.safe.global/api",
|
|
22
|
-
[ethers_1.Network.from("optimism").chainId.toString()]: "https://safe-transaction-optimism.safe.global/api",
|
|
23
|
-
[ethers_1.Network.from("matic").chainId.toString()]: "https://safe-transaction-polygon.safe.global/api",
|
|
24
|
-
[ethers_1.Network.from("sepolia").chainId.toString()]: "https://safe-transaction-sepolia.safe.global/api",
|
|
25
|
-
[ethers_1.Network.from("holesky").chainId.toString()]: "https://transaction-holesky.holesky-safe.protofire.io/api",
|
|
26
|
-
// Aurora
|
|
27
|
-
"0x4e454152": "https://safe-transaction-aurora.safe.global/api",
|
|
28
|
-
// Polygon zkEVM
|
|
29
|
-
"1101": "https://safe-transaction-zkevm.safe.global/api",
|
|
30
|
-
// ZkSync Era Mainnet
|
|
31
|
-
"324": "https://safe-transaction-zksync.safe.global/api",
|
|
32
|
-
// Celo
|
|
33
|
-
"42220": "https://safe-transaction-celo.safe.global/api",
|
|
34
|
-
// Avalanche
|
|
35
|
-
"43114": "https://safe-transaction-avalanche.safe.global/api",
|
|
36
|
-
// Scroll
|
|
37
|
-
"534352": "https://safe-transaction-scroll.safe.global/api",
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
12
|
const defaultOptions = {
|
|
41
13
|
/*
|
|
42
14
|
* Gas costs not related to the transaction execution
|
|
@@ -69,17 +41,14 @@ const getSafeTransactionData = (transactions) => {
|
|
|
69
41
|
}
|
|
70
42
|
return safeTransactionData;
|
|
71
43
|
};
|
|
72
|
-
const getSafeTransactionUrl = (chainId) => {
|
|
73
|
-
if (Object.keys(URLS.safe_transaction).includes(chainId.toString())) {
|
|
74
|
-
return URLS.safe_transaction[Number(chainId)];
|
|
75
|
-
}
|
|
76
|
-
throw Error("Can't get Safe Transaction Service url" +
|
|
77
|
-
` at network with chainId = ${chainId}`);
|
|
78
|
-
};
|
|
79
44
|
const getSafeService = (chainId) => {
|
|
45
|
+
if (!process.env.GNOSIS_API_KEY) {
|
|
46
|
+
throw new Error("GNOSIS_API_KEY is not set");
|
|
47
|
+
}
|
|
80
48
|
const safeService = new api_kit_1.default({
|
|
49
|
+
apiKey: process.env.GNOSIS_API_KEY,
|
|
81
50
|
chainId,
|
|
82
|
-
|
|
51
|
+
// Does not need the URL because chainId is provided
|
|
83
52
|
});
|
|
84
53
|
return safeService;
|
|
85
54
|
};
|
|
@@ -111,7 +80,7 @@ const createMultiSendTransaction = async (safeAddress, chainId, transactions) =>
|
|
|
111
80
|
* Transaction cannot be executed until
|
|
112
81
|
* Safe's nonce is not equal to this nonce
|
|
113
82
|
*/
|
|
114
|
-
nonce
|
|
83
|
+
nonce: parseInt(nonce, 10)
|
|
115
84
|
}
|
|
116
85
|
};
|
|
117
86
|
const safeSdk = await protocol_kit_1.default.init({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gnosis-safe.js","sourceRoot":"","sources":["../../src/gnosis-safe.ts"],"names":[],"mappings":";;;;;;AAAA,0EAI0C;AAC1C,
|
|
1
|
+
{"version":3,"file":"gnosis-safe.js","sourceRoot":"","sources":["../../src/gnosis-safe.ts"],"names":[],"mappings":";;;;;;AAAA,0EAI0C;AAC1C,qCAAwC;AACxC,6EAA6C;AAC7C,mEAA8C;AAG9C,kDAAkD;AAElD,MAAM,cAAc,GAAG;IAEnB;;;OAGG;IACH,SAAS,EAAE,GAAG;IAEd,4CAA4C;IAC5C,UAAU,EAAE,GAAG;IAEf;;;;OAIG;IACH,UAAU,EAAE,gBAAM,CAAC,WAAW;IAE9B,8DAA8D;IAC9D,gBAAgB,EAAE,gBAAM,CAAC,WAAW;IAEpC,oCAAoC;IACpC,WAAW,EAAE,GAAG;CACnB,CAAC;AAEF,oBAAoB;AAEpB,MAAM,sBAAsB,GAAG,CAAC,YAA2B,EAAE,EAAE;IAC3D,MAAM,mBAAmB,GAA0B,EAAE,CAAC;IACtD,KAAK,MAAM,WAAW,IAAI,YAAY,EAAE,CAAC;QACrC,mBAAmB,CAAC,IAAI,CAAC;YACrB,MAAM,EAAE,WAAW,CAAC,IAAI;YACxB,WAAW,EAAE,mCAAa,CAAC,IAAI;YAC/B,IAAI,EAAE,WAAW,CAAC,EAAE,IAAI,gBAAM,CAAC,WAAW;YAC1C,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,QAAQ,EAAE;SACxC,CAAC,CAAC;IACP,CAAC;IACD,OAAO,mBAAmB,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,OAAe,EAAE,EAAE;IACvC,IAAG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AW,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CACP,mCAAmC,EACnC,KAAK,CACR,CAAC;IAEF,MAAM,OAAO,GAAG;QACZ,GAAG,cAAc;QACjB,GAAG;YAEC;;;;eAIG;YACH,KAAK,EAAE,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC;SAC7B;KACJ,CAAC;IACF,MAAM,OAAO,GAAG,MAAM,sBAAI,CAAC,IAAI,CAAC;QAC5B,QAAQ,EAAE,iBAAO,CAAC,QAAQ;QAC1B,WAAW;KACd,CAAC,CAAC;IACH,MAAM,eAAe,GAAG,MAAM,OAAO,CAAC,iBAAiB,CAAC;QACpD,OAAO;QACP,YAAY,EAAE,mBAAmB;KACpC,CAAC,CAAC;IAEH,MAAM,kBAAkB,CACpB,WAAW,EACX,OAAO,EACP,eAAe,CAClB,CAAC;AACN,CAAC,CAAC;AAvCW,QAAA,0BAA0B,8BAuCrC"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export * from "./abi";
|
|
2
2
|
export * from "./deploy";
|
|
3
3
|
export * from "./gnosis-safe";
|
|
4
|
+
export * from "./proxyUpgrader";
|
|
4
5
|
export * from "./submitters";
|
|
5
6
|
export * from "./verification";
|
|
6
7
|
export * from "./version";
|
|
7
8
|
export * from "./upgrader";
|
|
9
|
+
export * from "./upgraders/abstractTransparentProxyUpgrader";
|
|
10
|
+
export * from "./upgraders/beaconUpgrader";
|
package/dist/src/index.js
CHANGED
|
@@ -17,8 +17,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./abi"), exports);
|
|
18
18
|
__exportStar(require("./deploy"), exports);
|
|
19
19
|
__exportStar(require("./gnosis-safe"), exports);
|
|
20
|
+
__exportStar(require("./proxyUpgrader"), exports);
|
|
20
21
|
__exportStar(require("./submitters"), exports);
|
|
21
22
|
__exportStar(require("./verification"), exports);
|
|
22
23
|
__exportStar(require("./version"), exports);
|
|
23
24
|
__exportStar(require("./upgrader"), exports);
|
|
25
|
+
__exportStar(require("./upgraders/abstractTransparentProxyUpgrader"), exports);
|
|
26
|
+
__exportStar(require("./upgraders/beaconUpgrader"), exports);
|
|
24
27
|
//# 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,+CAA6B;AAC7B,iDAA+B;AAC/B,4CAA0B;AAC1B,6CAA2B"}
|
|
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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AddressLike, Transaction } from "ethers";
|
|
2
|
+
import { NonceProvider } from "./nonceProvider";
|
|
3
|
+
export declare abstract class ProxyUpgrader {
|
|
4
|
+
protected proxyAddress: AddressLike;
|
|
5
|
+
protected newImplementationAddress: AddressLike | null;
|
|
6
|
+
private contractName;
|
|
7
|
+
private nonceProvider?;
|
|
8
|
+
constructor(contractName: string, proxyAddress: AddressLike, nonceProvider?: NonceProvider);
|
|
9
|
+
deployNewImplementation(): Promise<void>;
|
|
10
|
+
needsUpgrade(): boolean;
|
|
11
|
+
getUpgradeTransaction(): Promise<Transaction>;
|
|
12
|
+
getContractName(): string;
|
|
13
|
+
getNewImplementationAddress(): AddressLike;
|
|
14
|
+
abstract getOwner(): Promise<string>;
|
|
15
|
+
protected abstract makeUpgradeTransaction(): Promise<Transaction>;
|
|
16
|
+
protected abstract getCurrentImplementationAddress(): Promise<AddressLike>;
|
|
17
|
+
private prepareUpgrade;
|
|
18
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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.ProxyUpgrader = void 0;
|
|
7
|
+
const hardhat_1 = require("hardhat");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const contractFactory_1 = require("./contractFactory");
|
|
10
|
+
// 10 minutes
|
|
11
|
+
const deployTimeout = 60e4;
|
|
12
|
+
class ProxyUpgrader {
|
|
13
|
+
constructor(contractName, proxyAddress, nonceProvider) {
|
|
14
|
+
this.newImplementationAddress = null;
|
|
15
|
+
this.contractName = contractName;
|
|
16
|
+
this.proxyAddress = proxyAddress;
|
|
17
|
+
this.nonceProvider = nonceProvider;
|
|
18
|
+
}
|
|
19
|
+
// Public
|
|
20
|
+
async deployNewImplementation() {
|
|
21
|
+
const contractFactory = await (0, contractFactory_1.getContractFactoryAndUpdateManifest)(this.contractName, this.nonceProvider);
|
|
22
|
+
console.log(`Prepare upgrade of ${this.contractName}`);
|
|
23
|
+
return this.prepareUpgrade(contractFactory);
|
|
24
|
+
}
|
|
25
|
+
needsUpgrade() {
|
|
26
|
+
return this.newImplementationAddress !== null;
|
|
27
|
+
}
|
|
28
|
+
async getUpgradeTransaction() {
|
|
29
|
+
if (this.newImplementationAddress === null) {
|
|
30
|
+
throw new Error(`Upgrade of ${this.contractName} is not prepared or not needed`);
|
|
31
|
+
}
|
|
32
|
+
const infoMessage = `Prepare transaction to upgrade ${this.contractName}` +
|
|
33
|
+
` at ${this.proxyAddress}` +
|
|
34
|
+
` to ${this.newImplementationAddress}`;
|
|
35
|
+
console.log(chalk_1.default.yellowBright(infoMessage));
|
|
36
|
+
return await this.makeUpgradeTransaction();
|
|
37
|
+
}
|
|
38
|
+
getContractName() {
|
|
39
|
+
return this.contractName;
|
|
40
|
+
}
|
|
41
|
+
getNewImplementationAddress() {
|
|
42
|
+
if (this.newImplementationAddress === null) {
|
|
43
|
+
throw new Error(`There is no new implementation address for ${this.contractName}`);
|
|
44
|
+
}
|
|
45
|
+
return this.newImplementationAddress;
|
|
46
|
+
}
|
|
47
|
+
// Private
|
|
48
|
+
async prepareUpgrade(contractFactory) {
|
|
49
|
+
const currentImplementationAddress = await this.getCurrentImplementationAddress();
|
|
50
|
+
const nonce = this.nonceProvider?.reserveNonce();
|
|
51
|
+
const newImplementationAddress = await hardhat_1.upgrades.prepareUpgrade(await hardhat_1.ethers.resolveAddress(this.proxyAddress), contractFactory, {
|
|
52
|
+
"timeout": deployTimeout,
|
|
53
|
+
"txOverrides": {
|
|
54
|
+
nonce
|
|
55
|
+
},
|
|
56
|
+
"unsafeAllowLinkedLibraries": true,
|
|
57
|
+
"unsafeAllowRenames": true
|
|
58
|
+
});
|
|
59
|
+
if (newImplementationAddress === currentImplementationAddress) {
|
|
60
|
+
console.log(chalk_1.default.gray(`Contract ${this.contractName} is up to date`));
|
|
61
|
+
// Release only if no upgrade is needed
|
|
62
|
+
if (nonce) {
|
|
63
|
+
this.nonceProvider?.releaseNonce(nonce);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
this.newImplementationAddress = newImplementationAddress;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.ProxyUpgrader = ProxyUpgrader;
|
|
72
|
+
//# sourceMappingURL=proxyUpgrader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxyUpgrader.js","sourceRoot":"","sources":["../../src/proxyUpgrader.ts"],"names":[],"mappings":";;;;;;AACA,qCAAyC;AAEzC,kDAA0B;AAC1B,uDAAsE;AAGtE,gCAAgC;AAChC,MAAM,aAAa,GAAG,IAAI,CAAC;A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,EAAE,CACpE,CAAC;QACN,CAAC;QACD,OAAO,IAAI,CAAC,wBAAwB,CAAC;IACzC,CAAC;IASD,UAAU;IAEF,KAAK,CAAC,cAAc,CAAC,eAAgC;QACzD,MAAM,4BAA4B,GAAG,MAAM,IAAI,CAAC,+BAA+B,EAAE,CAAC;QAElF,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,EAAE,YAAY,EAAE,CAAC;QAEjD,MAAM,wBAAwB,GAAG,MAAM,kBAAQ,CAAC,cAAc,CAC1D,MAAM,gBAAM,CAAC,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,EAC9C,eAAe,EACf;YACI,SAAS,EAAE,aAAa;YACxB,aAAa,EAAE;gBACX,KAAK;aACR;YACD,4BAA4B,EAAE,IAAI;YAClC,oBAAoB,EAAE,IAAI;SAC7B,CACW,CAAC;QACjB,IAAI,wBAAwB,KAAK,4BAA4B,EAAE,CAAC;YAC5D,OAAO,CAAC,GAAG,CAAC,eAAK,CAAC,IAAI,CAAC,YAAY,IAAI,CAAC,YAAY,gBAAgB,CAAC,CAAC,CAAC;YACvE,uCAAuC;YACvC,IAAI,KAAK,EAAE,CAAC;gBACR,IAAI,CAAC,aAAa,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;YAC5C,CAAC;QACL,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAC;QAC7D,CAAC;IACL,CAAC;CACJ;AA9FD,sCA8FC"}
|
package/dist/src/upgrader.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { Transaction } from "ethers";
|
|
2
|
-
import { Project } from "./types/upgrader";
|
|
3
1
|
import { Instance } from "@skalenetwork/skale-contracts-ethers-v6";
|
|
2
|
+
import { NonceProvider } from "./nonceProvider";
|
|
3
|
+
import { Project } from "./types/upgrader";
|
|
4
|
+
import { ProxyUpgrader } from "./proxyUpgrader";
|
|
4
5
|
import { Submitter } from "./submitters/submitter";
|
|
6
|
+
import { Transaction } from "ethers";
|
|
5
7
|
export declare abstract class Upgrader {
|
|
6
8
|
private targetVersion;
|
|
7
9
|
private contractNamesToUpgrade;
|
|
8
10
|
private projectName;
|
|
9
11
|
private submitter;
|
|
10
|
-
private nonceProvider?;
|
|
11
12
|
private deploySemaphore;
|
|
13
|
+
private proxyUpgraders;
|
|
14
|
+
protected nonceProvider?: NonceProvider;
|
|
12
15
|
protected instance: Instance;
|
|
13
16
|
protected transactions: Transaction[];
|
|
14
17
|
constructor(project: Project, submitter?: Submitter);
|
|
@@ -16,18 +19,20 @@ export declare abstract class Upgrader {
|
|
|
16
19
|
abstract setVersion: (newVersion: string) => Promise<void>;
|
|
17
20
|
deployNewContracts?: () => Promise<void>;
|
|
18
21
|
initialize?: () => Promise<void>;
|
|
22
|
+
protected createProxyUpgrader(contractName: string): Promise<ProxyUpgrader>;
|
|
19
23
|
upgrade(): Promise<void>;
|
|
20
24
|
getOwner(): Promise<string>;
|
|
25
|
+
private upgradeOldContracts;
|
|
26
|
+
private getChangedContracts;
|
|
27
|
+
private createProxyUpgraders;
|
|
21
28
|
private callInitialize;
|
|
22
29
|
private callDeployNewContracts;
|
|
23
30
|
private prepareVersion;
|
|
24
31
|
private writeTransactions;
|
|
25
|
-
private
|
|
32
|
+
private verify;
|
|
26
33
|
private switchToNewImplementations;
|
|
27
34
|
private deployNewImplementations;
|
|
28
35
|
private protectedDeployNewImplementation;
|
|
29
|
-
private deployNewImplementation;
|
|
30
|
-
private prepareUpgrade;
|
|
31
36
|
private getNormalizedDeployedVersion;
|
|
32
37
|
private checkVersion;
|
|
33
38
|
}
|
package/dist/src/upgrader.js
CHANGED
|
@@ -5,25 +5,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Upgrader = void 0;
|
|
7
7
|
const hardhat_1 = require("hardhat");
|
|
8
|
-
const
|
|
8
|
+
const abstractTransparentProxyUpgrader_1 = require("./upgraders/abstractTransparentProxyUpgrader");
|
|
9
9
|
const auto_submitter_1 = require("./submitters/auto-submitter");
|
|
10
10
|
const exitCodes_1 = require("./exitCodes");
|
|
11
11
|
const nonceProvider_1 = require("./nonceProvider");
|
|
12
12
|
const semaphore_async_await_1 = __importDefault(require("semaphore-async-await"));
|
|
13
|
+
const transparentProxyUpgrader_1 = require("./upgraders/transparentProxyUpgrader");
|
|
14
|
+
const v4TransparentProxyUpgrader_1 = require("./upgraders/v4TransparentProxyUpgrader");
|
|
13
15
|
const chalk_1 = __importDefault(require("chalk"));
|
|
14
16
|
const fs_1 = require("fs");
|
|
15
|
-
const contractFactory_1 = require("./contractFactory");
|
|
16
|
-
const upgrades_core_1 = require("@openzeppelin/upgrades-core");
|
|
17
17
|
const version_1 = require("./version");
|
|
18
18
|
const verification_1 = require("./verification");
|
|
19
19
|
const withoutNull = (array) => array.
|
|
20
20
|
filter((element) => element !== null);
|
|
21
21
|
// TODO: Set to 8 when upgrade plugins become thread safe
|
|
22
22
|
const maxSimultaneousDeployments = 1;
|
|
23
|
-
// 10 minutes
|
|
24
|
-
const deployTimeout = 60e4;
|
|
25
23
|
class Upgrader {
|
|
26
24
|
constructor(project, submitter) {
|
|
25
|
+
this.proxyUpgraders = [];
|
|
27
26
|
this.targetVersion = project.version;
|
|
28
27
|
if (!project.version.includes("-")) {
|
|
29
28
|
this.targetVersion = `${project.version}-stable.0`;
|
|
@@ -35,24 +34,46 @@ class Upgrader {
|
|
|
35
34
|
this.submitter = submitter ?? new auto_submitter_1.AutoSubmitter(this);
|
|
36
35
|
this.deploySemaphore = new semaphore_async_await_1.default(maxSimultaneousDeployments);
|
|
37
36
|
}
|
|
37
|
+
async createProxyUpgrader(contractName) {
|
|
38
|
+
const proxyAddress = await this.instance.getContractAddress(contractName);
|
|
39
|
+
const proxyAdmin = await abstractTransparentProxyUpgrader_1.AbstractTransparentProxyUpgrader.getProxyAdmin(proxyAddress);
|
|
40
|
+
const proxyAdminVersion = await abstractTransparentProxyUpgrader_1.AbstractTransparentProxyUpgrader.getProxyAdminVersion(proxyAdmin);
|
|
41
|
+
const defaultProxyAdminVersion = "5.0.0";
|
|
42
|
+
if (proxyAdminVersion === defaultProxyAdminVersion) {
|
|
43
|
+
console.log(chalk_1.default.gray(`${contractName} uses ProxyAdmin version ${proxyAdminVersion}`));
|
|
44
|
+
return new transparentProxyUpgrader_1.TransparentProxyUpgrader({
|
|
45
|
+
contractName,
|
|
46
|
+
nonceProvider: this.nonceProvider,
|
|
47
|
+
proxyAddress,
|
|
48
|
+
proxyAdmin
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
else if (proxyAdminVersion === null) {
|
|
52
|
+
console.log(chalk_1.default.gray(`${contractName} uses old ProxyAdmin (v4 or lower)`));
|
|
53
|
+
return new v4TransparentProxyUpgrader_1.V4TransparentProxyUpgrader({
|
|
54
|
+
contractName,
|
|
55
|
+
nonceProvider: this.nonceProvider,
|
|
56
|
+
proxyAddress,
|
|
57
|
+
proxyAdmin
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`Unsupported ProxyAdmin version: ${proxyAdminVersion}`);
|
|
61
|
+
}
|
|
38
62
|
// Public
|
|
39
63
|
async upgrade() {
|
|
40
64
|
const version = await this.prepareVersion();
|
|
41
65
|
await this.callDeployNewContracts();
|
|
42
|
-
|
|
43
|
-
await this.switchToNewImplementations(contractsToUpgrade);
|
|
66
|
+
await this.upgradeOldContracts();
|
|
44
67
|
await this.callInitialize();
|
|
45
68
|
// Write version
|
|
46
69
|
await this.setVersion(version);
|
|
47
70
|
await this.writeTransactions(version);
|
|
48
71
|
await this.submitter.submit(this.transactions);
|
|
49
|
-
await
|
|
72
|
+
await this.verify();
|
|
50
73
|
console.log("Done");
|
|
51
74
|
}
|
|
52
75
|
async getOwner() {
|
|
53
|
-
const
|
|
54
|
-
const admins = await Promise.all(proxyAddresses.map((proxy) => (0, proxyAdmin_1.getProxyAdmin)(proxy)));
|
|
55
|
-
const owners = await Promise.all(admins.map((admin) => admin.owner()));
|
|
76
|
+
const owners = await Promise.all(this.proxyUpgraders.map((upgrader) => upgrader.getOwner()));
|
|
56
77
|
return owners.reduce((owner1, owner2) => {
|
|
57
78
|
if (owner1 !== owner2) {
|
|
58
79
|
throw Error("Proxies have different owners");
|
|
@@ -60,9 +81,26 @@ class Upgrader {
|
|
|
60
81
|
return owner1;
|
|
61
82
|
});
|
|
62
83
|
}
|
|
84
|
+
async upgradeOldContracts() {
|
|
85
|
+
await this.createProxyUpgraders();
|
|
86
|
+
await this.deployNewImplementations();
|
|
87
|
+
await this.switchToNewImplementations();
|
|
88
|
+
}
|
|
63
89
|
// Private
|
|
90
|
+
getChangedContracts() {
|
|
91
|
+
return this.proxyUpgraders.filter((upgrader) => upgrader.needsUpgrade());
|
|
92
|
+
}
|
|
93
|
+
async createProxyUpgraders() {
|
|
94
|
+
const [deployer] = await hardhat_1.ethers.getSigners();
|
|
95
|
+
this.nonceProvider ?? (this.nonceProvider = await nonceProvider_1.NonceProvider.createForWallet(deployer));
|
|
96
|
+
this.proxyUpgraders = await Promise.all(this.contractNamesToUpgrade.map(this.createProxyUpgrader, this));
|
|
97
|
+
}
|
|
64
98
|
async callInitialize() {
|
|
65
|
-
if (typeof this.initialize
|
|
99
|
+
if (typeof this.initialize === "undefined") {
|
|
100
|
+
console.log(chalk_1.default.gray("No initialize function defined, skipping"));
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
console.log("Generating initialize transaction(s)");
|
|
66
104
|
await this.initialize();
|
|
67
105
|
}
|
|
68
106
|
}
|
|
@@ -82,72 +120,34 @@ class Upgrader {
|
|
|
82
120
|
const indentation = 4;
|
|
83
121
|
await fs_1.promises.writeFile(`data/transactions-${version}-${hardhat_1.network.name}.json`, JSON.stringify(this.transactions, null, indentation));
|
|
84
122
|
}
|
|
85
|
-
|
|
123
|
+
async verify() {
|
|
86
124
|
if (process.env.NO_VERIFY) {
|
|
87
125
|
console.log("Skip verification");
|
|
88
126
|
}
|
|
89
127
|
else {
|
|
90
128
|
console.log("Start verification");
|
|
91
|
-
await Promise.all(
|
|
129
|
+
await Promise.all(this.getChangedContracts().map((upgrader) => (0, verification_1.verify)(upgrader.getContractName(), upgrader.getNewImplementationAddress())));
|
|
92
130
|
}
|
|
93
131
|
}
|
|
94
|
-
async switchToNewImplementations(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
` to ${contract.implementationAddress}`;
|
|
100
|
-
console.log(chalk_1.default.yellowBright(infoMessage));
|
|
101
|
-
this.transactions.push(upgradeTransactions[index]);
|
|
102
|
-
});
|
|
132
|
+
async switchToNewImplementations() {
|
|
133
|
+
this.transactions = [
|
|
134
|
+
...this.transactions,
|
|
135
|
+
...await Promise.all(this.getChangedContracts().map((upgrader) => upgrader.getUpgradeTransaction()))
|
|
136
|
+
];
|
|
103
137
|
}
|
|
104
138
|
async deployNewImplementations() {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
const contracts = await Promise.all(this.contractNamesToUpgrade.
|
|
108
|
-
map(this.protectedDeployNewImplementation, this));
|
|
139
|
+
const contracts = await Promise.all(this.proxyUpgraders.
|
|
140
|
+
map((upgrader) => this.protectedDeployNewImplementation(upgrader), this));
|
|
109
141
|
return withoutNull(contracts);
|
|
110
142
|
}
|
|
111
|
-
async protectedDeployNewImplementation(
|
|
143
|
+
async protectedDeployNewImplementation(upgrader) {
|
|
112
144
|
await this.deploySemaphore.acquire();
|
|
113
|
-
let result = null;
|
|
114
145
|
try {
|
|
115
|
-
|
|
146
|
+
await upgrader.deployNewImplementation();
|
|
116
147
|
}
|
|
117
148
|
finally {
|
|
118
149
|
this.deploySemaphore.release();
|
|
119
150
|
}
|
|
120
|
-
return result;
|
|
121
|
-
}
|
|
122
|
-
async deployNewImplementation(contract) {
|
|
123
|
-
const contractFactory = await (0, contractFactory_1.getContractFactoryAndUpdateManifest)(contract, this.nonceProvider);
|
|
124
|
-
const proxyAddress = await (await this.instance.getContract(contract)).getAddress();
|
|
125
|
-
console.log(`Prepare upgrade of ${contract}`);
|
|
126
|
-
return this.prepareUpgrade(contract, proxyAddress, contractFactory);
|
|
127
|
-
}
|
|
128
|
-
async prepareUpgrade(contractName, proxyAddress, contractFactory) {
|
|
129
|
-
const currentImplementationAddress = await (0, upgrades_core_1.getImplementationAddress)(hardhat_1.network.provider, proxyAddress);
|
|
130
|
-
const nonce = this.nonceProvider?.reserveNonce();
|
|
131
|
-
const newImplementationAddress = await hardhat_1.upgrades.prepareUpgrade(proxyAddress, contractFactory, {
|
|
132
|
-
"timeout": deployTimeout,
|
|
133
|
-
"txOverrides": {
|
|
134
|
-
nonce
|
|
135
|
-
},
|
|
136
|
-
"unsafeAllowLinkedLibraries": true,
|
|
137
|
-
"unsafeAllowRenames": true
|
|
138
|
-
});
|
|
139
|
-
if (newImplementationAddress !== currentImplementationAddress) {
|
|
140
|
-
return {
|
|
141
|
-
"implementationAddress": newImplementationAddress,
|
|
142
|
-
"name": contractName,
|
|
143
|
-
proxyAddress
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
console.log(chalk_1.default.gray(`Contract ${contractName} is up to date`));
|
|
147
|
-
if (nonce) {
|
|
148
|
-
this.nonceProvider?.releaseNonce(nonce);
|
|
149
|
-
}
|
|
150
|
-
return null;
|
|
151
151
|
}
|
|
152
152
|
async getNormalizedDeployedVersion() {
|
|
153
153
|
const deployedVersion = await this.getDeployedVersion();
|