@skalenetwork/upgrade-tools 4.0.0-update-verify.6 → 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.
Files changed (42) hide show
  1. package/dist/src/contractVerifier.d.ts +23 -12
  2. package/dist/src/contractVerifier.js +47 -43
  3. package/dist/src/contractVerifier.js.map +1 -1
  4. package/dist/src/gnosis-safe.js +6 -37
  5. package/dist/src/gnosis-safe.js.map +1 -1
  6. package/dist/src/index.d.ts +3 -0
  7. package/dist/src/index.js +3 -0
  8. package/dist/src/index.js.map +1 -1
  9. package/dist/src/proxyUpgrader.d.ts +18 -0
  10. package/dist/src/proxyUpgrader.js +72 -0
  11. package/dist/src/proxyUpgrader.js.map +1 -0
  12. package/dist/src/upgrader.d.ts +11 -6
  13. package/dist/src/upgrader.js +61 -61
  14. package/dist/src/upgrader.js.map +1 -1
  15. package/dist/src/upgraders/abstractTransparentProxyUpgrader.d.ts +19 -0
  16. package/dist/src/upgraders/abstractTransparentProxyUpgrader.js +57 -0
  17. package/dist/src/upgraders/abstractTransparentProxyUpgrader.js.map +1 -0
  18. package/dist/src/upgraders/beaconUpgrader.d.ts +8 -0
  19. package/dist/src/upgraders/beaconUpgrader.js +37 -0
  20. package/dist/src/upgraders/beaconUpgrader.js.map +1 -0
  21. package/dist/src/upgraders/transparentProxyUpgrader.d.ts +5 -0
  22. package/dist/src/upgraders/transparentProxyUpgrader.js +20 -0
  23. package/dist/src/upgraders/transparentProxyUpgrader.js.map +1 -0
  24. package/dist/src/upgraders/v4TransparentProxyUpgrader.d.ts +5 -0
  25. package/dist/src/upgraders/v4TransparentProxyUpgrader.js +19 -0
  26. package/dist/src/upgraders/v4TransparentProxyUpgrader.js.map +1 -0
  27. package/dist/src/verification.d.ts +2 -17
  28. package/dist/src/verification.js +55 -206
  29. package/dist/src/verification.js.map +1 -1
  30. package/dist/src/verifiers/blockscoutVerifier.d.ts +11 -0
  31. package/dist/src/verifiers/blockscoutVerifier.js +65 -0
  32. package/dist/src/verifiers/blockscoutVerifier.js.map +1 -0
  33. package/dist/src/verifiers/etherscanVerifier.d.ts +19 -0
  34. package/dist/src/verifiers/etherscanVerifier.js +105 -0
  35. package/dist/src/verifiers/etherscanVerifier.js.map +1 -0
  36. package/dist/src/verifiers/skaleBlockscoutVerifier.d.ts +7 -0
  37. package/dist/src/verifiers/skaleBlockscoutVerifier.js +60 -0
  38. package/dist/src/verifiers/skaleBlockscoutVerifier.js.map +1 -0
  39. package/package.json +4 -4
  40. package/dist/src/proxyAdmin.d.ts +0 -4
  41. package/dist/src/proxyAdmin.js +0 -56
  42. package/dist/src/proxyAdmin.js.map +0 -1
@@ -1,14 +1,25 @@
1
- import { VerificationTarget } from "./verification";
2
- export declare class ContractVerifier {
3
- private readonly contractName;
4
- private readonly contractAddress;
5
- private readonly apiURL;
6
- private readonly browserURL;
7
- private readonly isEtherscan;
8
- private readonly etherscan;
9
- constructor(target: VerificationTarget);
10
- private isAlreadyVerified;
11
- private submitVerification;
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 verification_1 = require("./verification");
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(target) {
12
- this.contractName = target.contractName;
13
- this.contractAddress = target.contractAddress;
14
- this.apiURL = target.explorerUrls.apiURL;
15
- this.browserURL = target.explorerUrls.browserURL;
16
- this.isEtherscan = Boolean(target.isEtherscan);
17
- this.etherscan = new etherscan_1.Etherscan(process.env.ETHERSCAN ?? "", this.apiURL, this.browserURL, target.chainId);
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 isAlreadyVerified() {
20
- let verified = false;
21
- if (this.isEtherscan) {
22
- verified = await this.etherscan.isVerified(this.contractAddress);
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
- return verified;
31
- }
32
- async submitVerification(params) {
30
+ const params = await this.getVerifyParameters(verificationTarget.contractName);
33
31
  try {
34
- const res = await this.etherscan.verify(this.contractAddress, params.solcInputJson, params.fullContractName, params.compilerVersion, "");
35
- return res.message;
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 ${this.contractName} failed with error: ${error}`));
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 attempt() {
52
- if (await this.isAlreadyVerified()) {
53
- return true;
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 params = await (0, verification_1.getVerifyParameters)(this.contractName);
56
- if (this.isEtherscan) {
57
- params.compilerVersion = `v${params.compilerVersion}`;
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
- const guid = await this.submitVerification(params);
60
- if (!guid) {
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
- return this.checkVerificationStatus(guid);
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":";;;;;;AAAA,iDAIwB;AACxB,yEAAoE;AACpE,kDAA0B;AAE1B,MAAa,gBAAgB;IAQzB,YAAY,MAA0B;QAClC,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC;QAC9C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC;QACzC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC;QACjD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,GAAG,IAAI,qBAAS,CAC1B,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,EAAE,EAC3B,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,UAAU,EACf,MAAM,CAAC,OAAO,CACjB,CAAC;IACN,CAAC;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e;gBAC/C,gBAAgB,EAAE,GAAG,0CAAa,CAAC,UAAU,IAAI,YAAY,EAAE;gBAC/D,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC,4BAAc,CAAC,KAAK,CAAC;aACtD,CAAC;QACN,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,mBAAS,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QAC5D,MAAM,gBAAgB,GAAG,GAAG,QAAQ,CAAC,UAAU,IAAI,YAAY,EAAE,CAAC;QAClE,MAAM,SAAS,GAAG,MAAM,mBAAS,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC;QACjE,IAAI,CAAC,SAAS,EAAE,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"}
@@ -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
- "txServiceUrl": getSafeTransactionUrl(chainId)
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,mCAA4C;AAC5C,qCAAwC;AACxC,6EAA6C;AAC7C,mEAA8C;AAE9C,kDAAkD;AAElD,YAAY;AAEZ,MAAM,IAAI,GAAG;IACT,kBAAkB,EAAE;QAChB,CAAC,gBAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EACxC,kDAAkD;QACtD,CAAC,gBAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC,EACzC,mDAAmD;QACvD,CAAC,gBAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,QAAQ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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"}
@@ -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
@@ -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":";;;;;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IAAI,CAAC,wBAAwB,KAAK,IAAI,EAAE,CAAC;YACzC,MAAM,IAAI,KAAK,CACX,8CAA8C,IAAI,CAAC,YAAY,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"}
@@ -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 static verify;
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
  }
@@ -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 proxyAdmin_1 = require("./proxyAdmin");
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
- const contractsToUpgrade = await this.deployNewImplementations();
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 Upgrader.verify(contractsToUpgrade);
72
+ await this.verify();
50
73
  console.log("Done");
51
74
  }
52
75
  async getOwner() {
53
- const proxyAddresses = await Promise.all(this.contractNamesToUpgrade.map((contract) => this.instance.getContractAddress(contract), this));
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 !== "undefined") {
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
- static async verify(contractsToUpgrade) {
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(contractsToUpgrade.map((contract) => (0, verification_1.verify)(contract.name, contract.implementationAddress)));
129
+ await Promise.all(this.getChangedContracts().map((upgrader) => (0, verification_1.verify)(upgrader.getContractName(), upgrader.getNewImplementationAddress())));
92
130
  }
93
131
  }
94
- async switchToNewImplementations(contractsToUpgrade) {
95
- const upgradeTransactions = await Promise.all(contractsToUpgrade.map((contract) => (0, proxyAdmin_1.getUpgradeTransaction)(contract.proxyAddress, contract.implementationAddress)));
96
- contractsToUpgrade.forEach((contract, index) => {
97
- const infoMessage = `Prepare transaction to upgrade ${contract.name}` +
98
- ` at ${contract.proxyAddress}` +
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 [deployer] = await hardhat_1.ethers.getSigners();
106
- this.nonceProvider ?? (this.nonceProvider = await nonceProvider_1.NonceProvider.createForWallet(deployer));
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(contract) {
143
+ async protectedDeployNewImplementation(upgrader) {
112
144
  await this.deploySemaphore.acquire();
113
- let result = null;
114
145
  try {
115
- result = await this.deployNewImplementation(contract);
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();