@skalenetwork/upgrade-tools 3.0.0-linter.11 → 3.0.0-linter.3

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.
@@ -3,11 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  require("@typechain/hardhat");
4
4
  require("@nomiclabs/hardhat-ethers");
5
5
  require("@openzeppelin/hardhat-upgrades");
6
- const coreArtifacts = "node_modules/@openzeppelin/upgrades-core/artifacts/[!b]*.json";
7
6
  const config = {
8
7
  "typechain": {
9
8
  "target": "ethers-v5",
10
- "externalArtifacts": [coreArtifacts]
9
+ "externalArtifacts": ["node_modules/@openzeppelin/upgrades-core/artifacts/[!b]*.json"]
11
10
  }
12
11
  };
13
12
  exports.default = config;
package/dist/src/abi.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  import { Interface } from "ethers/lib/utils";
2
- export declare const getAbi: (contractInterface: Interface) => [];
2
+ export declare function getAbi(contractInterface: Interface): [];
package/dist/src/abi.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAbi = void 0;
4
- const getAbi = (contractInterface) => {
4
+ function getAbi(contractInterface) {
5
5
  const abi = JSON.parse(contractInterface.format("json"));
6
6
  abi.forEach((obj) => {
7
7
  if (obj.type === "function") {
@@ -15,5 +15,5 @@ const getAbi = (contractInterface) => {
15
15
  }
16
16
  });
17
17
  return abi;
18
- };
18
+ }
19
19
  exports.getAbi = getAbi;
@@ -1,4 +1,4 @@
1
- export declare const deployLibraries: (libraryNames: string[]) => Promise<Map<string, string>>;
2
- export declare const getLinkedContractFactory: (contractName: string, libraries: Map<string, string>) => Promise<import("ethers").ContractFactory>;
3
- export declare const getManifestFile: () => Promise<string>;
4
- export declare const getContractFactory: (contract: string) => Promise<import("ethers").ContractFactory>;
1
+ export declare function deployLibraries(libraryNames: string[]): Promise<Map<string, string>>;
2
+ export declare function getLinkedContractFactory(contractName: string, libraries: Map<string, string>): Promise<import("ethers").ContractFactory>;
3
+ export declare function getManifestFile(): Promise<string>;
4
+ export declare function getContractFactory(contract: string): Promise<import("ethers").ContractFactory>;
@@ -4,21 +4,21 @@ exports.getContractFactory = exports.getManifestFile = exports.getLinkedContract
4
4
  const upgrades_core_1 = require("@openzeppelin/upgrades-core");
5
5
  const hardhat_1 = require("hardhat");
6
6
  const fs_1 = require("fs");
7
- const _deployLibrary = async (libraryName) => {
7
+ async function _deployLibrary(libraryName) {
8
8
  const Library = await hardhat_1.ethers.getContractFactory(libraryName);
9
9
  const library = await Library.deploy();
10
10
  await library.deployed();
11
11
  return library.address;
12
- };
13
- const deployLibraries = async (libraryNames) => {
12
+ }
13
+ async function deployLibraries(libraryNames) {
14
14
  const libraries = new Map();
15
15
  for (const libraryName of libraryNames) {
16
16
  libraries.set(libraryName, await _deployLibrary(libraryName));
17
17
  }
18
18
  return libraries;
19
- };
19
+ }
20
20
  exports.deployLibraries = deployLibraries;
21
- const _linkBytecode = (artifact, libraries) => {
21
+ function _linkBytecode(artifact, libraries) {
22
22
  let { bytecode } = artifact;
23
23
  for (const [, fileReferences] of Object.entries(artifact.linkReferences)) {
24
24
  for (const [libName, fixups] of Object.entries(fileReferences)) {
@@ -35,19 +35,19 @@ const _linkBytecode = (artifact, libraries) => {
35
35
  }
36
36
  }
37
37
  return bytecode;
38
- };
39
- const getLinkedContractFactory = async (contractName, libraries) => {
38
+ }
39
+ async function getLinkedContractFactory(contractName, libraries) {
40
40
  const cArtifact = await hardhat_1.artifacts.readArtifact(contractName);
41
41
  const linkedBytecode = _linkBytecode(cArtifact, libraries);
42
42
  const ContractFactory = await hardhat_1.ethers.getContractFactory(cArtifact.abi, linkedBytecode);
43
43
  return ContractFactory;
44
- };
44
+ }
45
45
  exports.getLinkedContractFactory = getLinkedContractFactory;
46
- const getManifestFile = async function getManifestFile() {
46
+ async function getManifestFile() {
47
47
  return (await upgrades_core_1.Manifest.forNetwork(hardhat_1.ethers.provider)).file;
48
- };
48
+ }
49
49
  exports.getManifestFile = getManifestFile;
50
- const getContractFactory = async (contract) => {
50
+ async function getContractFactory(contract) {
51
51
  const { linkReferences } = await hardhat_1.artifacts.readArtifact(contract);
52
52
  if (!Object.keys(linkReferences).length) {
53
53
  return await hardhat_1.ethers.getContractFactory(contract);
@@ -57,7 +57,7 @@ const getContractFactory = async (contract) => {
57
57
  const libraryName = Object.keys(linkReferences[key])[0];
58
58
  libraryNames.push(libraryName);
59
59
  }
60
- const libraries = await (0, exports.deployLibraries)(libraryNames);
60
+ const libraries = await deployLibraries(libraryNames);
61
61
  const libraryArtifacts = {};
62
62
  for (const [libraryName, libraryAddress] of libraries.entries()) {
63
63
  const { bytecode } = await hardhat_1.artifacts.readArtifact(libraryName);
@@ -66,14 +66,17 @@ const getContractFactory = async (contract) => {
66
66
  "bytecodeHash": (0, upgrades_core_1.hashBytecode)(bytecode)
67
67
  };
68
68
  }
69
- const manifest = JSON.parse(await fs_1.promises.readFile(await (0, exports.getManifestFile)(), "utf-8"));
70
- if (manifest.libraries === undefined) {
71
- Object.assign(manifest, { "libraries": libraryArtifacts });
72
- }
73
- else {
69
+ let manifest;
70
+ try {
71
+ manifest = JSON.parse(await fs_1.promises.readFile(await getManifestFile(), "utf-8"));
74
72
  Object.assign(libraryArtifacts, manifest.libraries);
75
73
  }
76
- await fs_1.promises.writeFile(await (0, exports.getManifestFile)(), JSON.stringify(manifest, null, 4));
77
- return await (0, exports.getLinkedContractFactory)(contract, libraries);
78
- };
74
+ finally {
75
+ if (manifest !== undefined) {
76
+ Object.assign(manifest, { "libraries": libraryArtifacts });
77
+ }
78
+ await fs_1.promises.writeFile(await getManifestFile(), JSON.stringify(manifest, null, 4));
79
+ }
80
+ return await getLinkedContractFactory(contract, libraries);
81
+ }
79
82
  exports.getContractFactory = getContractFactory;
@@ -1,2 +1,2 @@
1
1
  import { UnsignedTransaction } from "ethers";
2
- export declare const createMultiSendTransaction: (safeAddress: string, transactions: UnsignedTransaction[]) => Promise<void>;
2
+ export declare function createMultiSendTransaction(safeAddress: string, transactions: UnsignedTransaction[]): Promise<void>;
@@ -46,7 +46,7 @@ const URLS = {
46
46
  }
47
47
  };
48
48
  // Public functions
49
- const createMultiSendTransaction = async (safeAddress, transactions) => {
49
+ async function createMultiSendTransaction(safeAddress, transactions) {
50
50
  const safeTransactionData = [];
51
51
  for (const transaction of transactions) {
52
52
  safeTransactionData.push({
@@ -66,38 +66,24 @@ const createMultiSendTransaction = async (safeAddress, transactions) => {
66
66
  const nonce = await safeService.getNextNonce(safeAddress);
67
67
  console.log("Will send tx to Gnosis with nonce", nonce);
68
68
  const options = {
69
- // Max gas to use in the transaction
70
69
  "safeTxGas": "0",
71
- // Gas costs not related to the transaction execution
72
- // (signature check, refund payment...)
73
70
  "baseGas": "0",
74
- // Gas price used for the refund calculation
75
71
  "gasPrice": "0",
76
- /* Token address (hold by the Safe)
77
- * to be used as a refund to the sender,
78
- * if `null` is Ether
79
- */
80
72
  "gasToken": hardhat_1.ethers.constants.AddressZero,
81
- // Address of receiver of gas payment (or `null` if tx.origin)
82
73
  "refundReceiver": hardhat_1.ethers.constants.AddressZero,
83
- // Nonce of the Safe,
84
- // Transaction cannot be executed until
85
- // Safe's nonce is not equal to this nonce
86
- nonce
74
+ nonce // Nonce of the Safe, transaction cannot be executed until Safe's nonce is not equal to this nonce
87
75
  };
88
76
  const ethAdapter = await getEthAdapter();
89
77
  const safeSdk = await protocol_kit_1.default.create({ ethAdapter,
90
78
  safeAddress });
91
- const safeTransaction = await safeSdk.createTransaction({
92
- safeTransactionData,
93
- options
94
- });
79
+ const safeTransaction = await safeSdk.createTransaction({ safeTransactionData,
80
+ options });
95
81
  await estimateSafeTransaction(safeAddress, safeTransactionData);
96
82
  await proposeTransaction(safeAddress, safeTransaction);
97
- };
83
+ }
98
84
  exports.createMultiSendTransaction = createMultiSendTransaction;
99
85
  // Private functions
100
- const estimateSafeTransaction = async (safeAddress, safeTransactionData) => {
86
+ async function estimateSafeTransaction(safeAddress, safeTransactionData) {
101
87
  console.log("Estimate gas");
102
88
  const safeService = await getSafeService();
103
89
  for (const transaction of safeTransactionData) {
@@ -110,8 +96,8 @@ const estimateSafeTransaction = async (safeAddress, safeTransactionData) => {
110
96
  console.log(chalk_1.default.cyan(`Recommend to set gas limit to ${parseInt(estimateResponse.safeTxGas, 10)}`));
111
97
  }
112
98
  console.log(chalk_1.default.green("Send transaction to gnosis safe"));
113
- };
114
- const proposeTransaction = async (safeAddress, safeTransaction) => {
99
+ }
100
+ async function proposeTransaction(safeAddress, safeTransaction) {
115
101
  const [safeOwner] = await hardhat_1.ethers.getSigners();
116
102
  const ethAdapter = await getEthAdapter();
117
103
  const safeSdk = await protocol_kit_1.default.create({ ethAdapter,
@@ -126,16 +112,16 @@ const proposeTransaction = async (safeAddress, safeTransaction) => {
126
112
  "senderAddress": safeOwner.address,
127
113
  "senderSignature": senderSignature.data
128
114
  });
129
- };
130
- const getEthAdapter = async () => {
115
+ }
116
+ async function getEthAdapter() {
131
117
  const [safeOwner] = await hardhat_1.ethers.getSigners();
132
118
  const ethAdapter = new protocol_kit_1.EthersAdapter({
133
119
  ethers: hardhat_1.ethers,
134
120
  "signerOrProvider": safeOwner
135
121
  });
136
122
  return ethAdapter;
137
- };
138
- const getSafeService = async () => {
123
+ }
124
+ async function getSafeService() {
139
125
  const { chainId } = await hardhat_1.ethers.provider.getNetwork();
140
126
  const ethAdapter = await getEthAdapter();
141
127
  const safeService = new api_kit_1.default({
@@ -143,11 +129,10 @@ const getSafeService = async () => {
143
129
  ethAdapter
144
130
  });
145
131
  return safeService;
146
- };
147
- const getSafeTransactionUrl = (chainId) => {
132
+ }
133
+ function getSafeTransactionUrl(chainId) {
148
134
  if (Object.keys(URLS.safe_transaction).includes(chainId.toString())) {
149
135
  return URLS.safe_transaction[chainId];
150
136
  }
151
- throw Error("Can't get safe-transaction url" +
152
- ` at network with chainId = ${chainId}`);
153
- };
137
+ throw Error(`Can't get safe-transaction url at network with chainId = ${chainId}`);
138
+ }
@@ -1,2 +1,2 @@
1
1
  import { BigNumber } from "ethers";
2
- export declare const encodeTransaction: (operation: 0 | 1, to: string, value: BigNumber | number, data: string) => string;
2
+ export declare function encodeTransaction(operation: 0 | 1, to: string, value: BigNumber | number, data: string): string;
@@ -2,19 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.encodeTransaction = void 0;
4
4
  const ethers_1 = require("ethers");
5
- const padWithZeros = (value, targetLength) => ("0".repeat(targetLength) + value).slice(-targetLength);
6
- const encodeTransaction = (
7
- /* Operation as a uint8 with 0 for a call
8
- * or 1 for a delegatecall (=> 1 byte)
9
- */
10
- operation,
11
- // To as a address (=> 20 bytes)
12
- to,
13
- // Value as a uint256 (=> 32 bytes)
14
- value,
15
- // Data as bytes.
16
- data) => {
17
- let _operation = "";
5
+ function padWithZeros(value, targetLength) {
6
+ return ("0".repeat(targetLength) + value).slice(-targetLength);
7
+ }
8
+ function encodeTransaction(operation, to, value, data) {
9
+ // / operation as a uint8 with 0 for a call or 1 for a delegatecall (=> 1 byte),
10
+ // / to as a address (=> 20 bytes),
11
+ // / value as a uint256 (=> 32 bytes),
12
+ // / data length as a uint256 (=> 32 bytes),
13
+ // / data as bytes.
14
+ let _operation;
18
15
  if (operation === 0) {
19
16
  _operation = "00";
20
17
  }
@@ -46,5 +43,5 @@ data) => {
46
43
  _dataLength,
47
44
  _data
48
45
  ].join("")}`;
49
- };
46
+ }
50
47
  exports.encodeTransaction = encodeTransaction;
@@ -3,7 +3,6 @@ import { Submitter } from "./submitter";
3
3
  export declare class AutoSubmitter extends Submitter {
4
4
  name: string;
5
5
  submit(transactions: Transaction[]): Promise<void>;
6
- private static getSubmitter;
7
6
  private static _getImaInstance;
8
7
  private static _getSafeAddress;
9
8
  private static _getSchainHash;
@@ -43,61 +43,59 @@ class AutoSubmitter extends submitter_1.Submitter {
43
43
  }
44
44
  async submit(transactions) {
45
45
  console.log(`Submit via ${this.name}`);
46
- const submitter = await AutoSubmitter.getSubmitter();
47
- await submitter.submit(transactions);
48
- }
49
- // Private
50
- static async getSubmitter() {
46
+ let submitter;
51
47
  // TODO: remove unknown when move everything to ethers 6
52
48
  const proxyAdmin = await (0, admin_1.getManifestAdmin)(hardhat_1.default);
53
49
  const owner = await proxyAdmin.owner();
54
50
  if (await hardhat_1.default.ethers.provider.getCode(owner) === "0x") {
55
51
  console.log("Owner is not a contract");
56
- return new eoa_submitter_1.EoaSubmitter();
52
+ submitter = new eoa_submitter_1.EoaSubmitter();
57
53
  }
58
- console.log("Owner is a contract");
59
- if (hardhat_1.ethers.utils.getAddress(owner) ===
60
- hardhat_1.ethers.utils.getAddress(marionette_1.MARIONETTE_ADDRESS)) {
61
- console.log("Marionette owner is detected");
62
- const imaInstance = await AutoSubmitter._getImaInstance();
63
- const mainnetChainId = AutoSubmitter._getMainnetChainId();
64
- const safeAddress = AutoSubmitter._getSafeAddress();
65
- const schainHash = AutoSubmitter._getSchainHash();
66
- /*
67
- * TODO: after marionette has multiSend functionality
68
- * query version and properly select a submitter
69
- * based on it
70
- *
71
- * if (await this._versionFunctionExists()) {
72
- * console.log("version() function was found." +
73
- * " Use normal Marionette")
74
- * submitter = new SafeImaMarionetteSubmitter(
75
- * safeAddress,
76
- * imaAbi,
77
- * schainHash,
78
- * mainnetChainId
79
- * )
80
- * } else {
81
- * console.log("No version() function was found." +
82
- * " Use legacy Marionette")
83
- * submitter = new SafeImaLegacyMarionetteSubmitter(
84
- * safeAddress,
85
- * imaAbi,
86
- * schainHash,
87
- * mainnetChainId
88
- * )
89
- * }
90
- */
91
- return new safe_ima_legacy_marionette_submitter_1.SafeImaLegacyMarionetteSubmitter(safeAddress, imaInstance, schainHash, mainnetChainId);
54
+ else {
55
+ console.log("Owner is a contract");
56
+ if (hardhat_1.ethers.utils.getAddress(owner) == hardhat_1.ethers.utils.getAddress(marionette_1.MARIONETTE_ADDRESS)) {
57
+ console.log("Marionette owner is detected");
58
+ const imaInstance = await AutoSubmitter._getImaInstance();
59
+ const mainnetChainId = AutoSubmitter._getMainnetChainId();
60
+ const safeAddress = AutoSubmitter._getSafeAddress();
61
+ const schainHash = AutoSubmitter._getSchainHash();
62
+ /*
63
+ * TODO: after marionette has multiSend functionality
64
+ * query version and properly select a submitter
65
+ * based on it
66
+ *
67
+ * if (await this._versionFunctionExists()) {
68
+ * console.log("version() function was found. Use normal Marionette")
69
+ * submitter = new SafeImaMarionetteSubmitter(
70
+ * safeAddress,
71
+ * imaAbi,
72
+ * schainHash,
73
+ * mainnetChainId
74
+ * )
75
+ * } else {
76
+ * console.log("No version() function was found. Use legacy Marionette")
77
+ * submitter = new SafeImaLegacyMarionetteSubmitter(
78
+ * safeAddress,
79
+ * imaAbi,
80
+ * schainHash,
81
+ * mainnetChainId
82
+ * )
83
+ * }
84
+ */
85
+ submitter = new safe_ima_legacy_marionette_submitter_1.SafeImaLegacyMarionetteSubmitter(safeAddress, imaInstance, schainHash, mainnetChainId);
86
+ }
87
+ else {
88
+ // Assuming owner is a Gnosis Safe
89
+ console.log("Using Gnosis Safe");
90
+ submitter = new safe_submitter_1.SafeSubmitter(owner);
91
+ }
92
92
  }
93
- // Assuming owner is a Gnosis Safe
94
- console.log("Using Gnosis Safe");
95
- return new safe_submitter_1.SafeSubmitter(owner);
93
+ await submitter.submit(transactions);
96
94
  }
95
+ // Private
97
96
  static async _getImaInstance() {
98
97
  if (!process.env.IMA) {
99
- console.log(chalk_1.default.red("Set target IMA alias" +
100
- " to IMA environment variable"));
98
+ console.log(chalk_1.default.red("Set target IMA alias to IMA environment variable"));
101
99
  process.exit(1);
102
100
  }
103
101
  const network = await skale_contracts_ethers_v5_1.skaleContracts.getNetworkByProvider(hardhat_1.ethers.provider);
@@ -106,8 +104,7 @@ class AutoSubmitter extends submitter_1.Submitter {
106
104
  }
107
105
  static _getSafeAddress() {
108
106
  if (!process.env.SAFE_ADDRESS) {
109
- console.log(chalk_1.default.red("Set Gnosis Safe owner address" +
110
- " to SAFE_ADDRESS environment variable"));
107
+ console.log(chalk_1.default.red("Set Gnosis Safe owner address to SAFE_ADDRESS environment variable"));
111
108
  process.exit(1);
112
109
  }
113
110
  return process.env.SAFE_ADDRESS;
@@ -116,10 +113,8 @@ class AutoSubmitter extends submitter_1.Submitter {
116
113
  // Query Context to get schain hash
117
114
  if (!process.env.SCHAIN_HASH) {
118
115
  if (!process.env.SCHAIN_NAME) {
119
- console.log(chalk_1.default.red("Set schain name" +
120
- " to SCHAIN_NAME environment variable"));
121
- console.log(chalk_1.default.red("or schain hash" +
122
- " to SCHAIN_HASH environment variable"));
116
+ console.log(chalk_1.default.red("Set schain name to SCHAIN_NAME environment variable"));
117
+ console.log(chalk_1.default.red("or schain hash to SCHAIN_HASH environment variable"));
123
118
  throw Error("Schain is not set");
124
119
  }
125
120
  else {
@@ -132,10 +127,8 @@ class AutoSubmitter extends submitter_1.Submitter {
132
127
  }
133
128
  static _getMainnetChainId() {
134
129
  if (!process.env.MAINNET_CHAIN_ID) {
135
- console.log(chalk_1.default.red("Set chainId of mainnet" +
136
- " to MAINNET_CHAIN_ID environment variable"));
137
- console.log(chalk_1.default.red("Use 1 for Ethereum mainnet" +
138
- " or 5 for Goerli"));
130
+ console.log(chalk_1.default.red("Set chainId of mainnet to MAINNET_CHAIN_ID environment variable"));
131
+ console.log(chalk_1.default.red("Use 1 for Ethereum mainnet or 5 for Goerli"));
139
132
  throw Error("Mainnet chainId is not set");
140
133
  }
141
134
  else {
@@ -176,8 +169,7 @@ class AutoSubmitter extends submitter_1.Submitter {
176
169
  }
177
170
  catch {
178
171
  /*
179
- * Otherwise (revert) we assume
180
- * that there is no entry in the jump table
172
+ * Otherwise (revert) we assume that there is no entry in the jump table
181
173
  * meaning that the contract doesn't include version()
182
174
  */
183
175
  return false;
@@ -18,8 +18,7 @@ class EoaSubmitter extends submitter_1.Submitter {
18
18
  "value": transaction.value,
19
19
  "data": transaction.data
20
20
  });
21
- console.log("Waiting for a transaction" +
22
- ` with nonce ${response.nonce}`);
21
+ console.log(`Waiting for a transaction with nonce ${response.nonce}`);
23
22
  await response.wait();
24
23
  console.log("The transaction was sent");
25
24
  }
@@ -25,8 +25,7 @@ class SafeToImaSubmitter extends safe_submitter_1.SafeSubmitter {
25
25
  }
26
26
  async _getMessageProxyForMainnet() {
27
27
  if (this._messageProxyForMainnet === undefined) {
28
- this._messageProxyForMainnet =
29
- await this.imaInstance.getContract("MessageProxyForMainnet");
28
+ this._messageProxyForMainnet = await this.imaInstance.getContract("MessageProxyForMainnet");
30
29
  }
31
30
  return this._messageProxyForMainnet;
32
31
  }
@@ -9,10 +9,8 @@ class Submitter {
9
9
  // Protected
10
10
  static _atomicityWarning() {
11
11
  if (!process.env.ALLOW_NOT_ATOMIC_UPGRADE) {
12
- console.log(chalk_1.default.red("The upgrade will consist" +
13
- " of multiple transactions and will not be atomic"));
14
- console.log(chalk_1.default.red("If not atomic upgrade is OK" +
15
- " set ALLOW_NOT_ATOMIC_UPGRADE environment variable"));
12
+ console.log(chalk_1.default.red("The upgrade will consist of multiple transactions and will not be atomic"));
13
+ console.log(chalk_1.default.red("If not atomic upgrade is OK set ALLOW_NOT_ATOMIC_UPGRADE environment variable"));
16
14
  process.exit(1);
17
15
  }
18
16
  else {
@@ -1,6 +1,6 @@
1
1
  import { ManifestData } from "@openzeppelin/upgrades-core";
2
2
  export interface SkaleManifestData extends ManifestData {
3
- libraries?: {
3
+ libraries: {
4
4
  [libraryName: string]: {
5
5
  address: string;
6
6
  bytecodeHash: string;
@@ -14,5 +14,5 @@ export declare abstract class Upgrader {
14
14
  deployNewContracts?: () => Promise<void>;
15
15
  initialize?: () => Promise<void>;
16
16
  upgrade(): Promise<void>;
17
- private static getContractFactoryAndUpdateManifest;
17
+ private static _getContractFactoryAndUpdateManifest;
18
18
  }
@@ -36,15 +36,12 @@ class Upgrader {
36
36
  deployedVersion += "-stable.0";
37
37
  }
38
38
  if (deployedVersion !== this.targetVersion) {
39
- const cannotUpgradeMessage = `This script can't upgrade version ${deployedVersion}` +
40
- ` to ${version}`;
41
- console.log(chalk_1.default.red(cannotUpgradeMessage));
39
+ console.log(chalk_1.default.red(`This script can't upgrade version ${deployedVersion} to ${version}`));
42
40
  process.exit(1);
43
41
  }
44
42
  }
45
43
  else {
46
- const cannotCheckMessage = `Can't check currently deployed version of ${this.projectName}`;
47
- console.log(chalk_1.default.yellow(cannotCheckMessage));
44
+ console.log(chalk_1.default.yellow(`Can't check currently deployed version of ${this.projectName}`));
48
45
  }
49
46
  console.log(`Will mark updated version as ${version}`);
50
47
  if (this.deployNewContracts !== undefined) {
@@ -54,7 +51,7 @@ class Upgrader {
54
51
  // Deploy new implementations
55
52
  const contractsToUpgrade = [];
56
53
  for (const contract of this.contractNamesToUpgrade) {
57
- const contractFactory = await Upgrader.getContractFactoryAndUpdateManifest(contract);
54
+ const contractFactory = await Upgrader._getContractFactoryAndUpdateManifest(contract);
58
55
  const proxyAddress = (await this.instance.getContract(contract)).address;
59
56
  console.log(`Prepare upgrade of ${contract}`);
60
57
  const currentImplementationAddress = await (0, upgrades_core_1.getImplementationAddress)(hardhat_2.network.provider, proxyAddress);
@@ -75,10 +72,7 @@ class Upgrader {
75
72
  }
76
73
  // Switch proxies to new implementations
77
74
  for (const contract of contractsToUpgrade) {
78
- const infoMessage = `Prepare transaction to upgrade ${contract.name}` +
79
- ` at ${contract.proxyAddress}` +
80
- ` to ${contract.implementationAddress}`;
81
- console.log(chalk_1.default.yellowBright(infoMessage));
75
+ console.log(chalk_1.default.yellowBright(`Prepare transaction to upgrade ${contract.name} at ${contract.proxyAddress} to ${contract.implementationAddress}`));
82
76
  this.transactions.push({
83
77
  "to": proxyAdmin.address,
84
78
  "data": proxyAdmin.interface.encodeFunctionData("upgrade", [
@@ -106,7 +100,7 @@ class Upgrader {
106
100
  console.log("Done");
107
101
  }
108
102
  // Private
109
- static async getContractFactoryAndUpdateManifest(contract) {
103
+ static async _getContractFactoryAndUpdateManifest(contract) {
110
104
  const { linkReferences } = await hardhat_2.artifacts.readArtifact(contract);
111
105
  const manifest = JSON.parse(await fs_1.promises.readFile(await (0, deploy_1.getManifestFile)(), "utf-8"));
112
106
  if (!Object.keys(linkReferences).length) {
@@ -115,7 +109,7 @@ class Upgrader {
115
109
  const librariesToUpgrade = [];
116
110
  const oldLibraries = {};
117
111
  if (manifest.libraries === undefined) {
118
- manifest.libraries = {};
112
+ Object.assign(manifest, { "libraries": {} });
119
113
  }
120
114
  for (const key of Object.keys(linkReferences)) {
121
115
  const libraryName = Object.keys(linkReferences[key])[0];
@@ -129,8 +123,7 @@ class Upgrader {
129
123
  librariesToUpgrade.push(libraryName);
130
124
  }
131
125
  else {
132
- oldLibraries[libraryName] =
133
- manifest.libraries[libraryName].address;
126
+ oldLibraries[libraryName] = manifest.libraries[libraryName].address;
134
127
  }
135
128
  }
136
129
  const libraries = await (0, deploy_1.deployLibraries)(librariesToUpgrade);
@@ -1,2 +1,2 @@
1
- export declare const verify: (contractName: string, contractAddress: string, constructorArguments: object) => Promise<void>;
2
- export declare const verifyProxy: (contractName: string, proxyAddress: string, constructorArguments: object) => Promise<void>;
1
+ export declare function verify(contractName: string, contractAddress: string, constructorArguments: object): Promise<void>;
2
+ export declare function verifyProxy(contractName: string, proxyAddress: string, constructorArguments: object): Promise<void>;
@@ -8,41 +8,35 @@ const hardhat_1 = require("hardhat");
8
8
  const chain_config_1 = require("@nomicfoundation/hardhat-verify/internal/chain-config");
9
9
  const chalk_1 = __importDefault(require("chalk"));
10
10
  const upgrades_core_1 = require("@openzeppelin/upgrades-core");
11
- const verify = async (contractName, contractAddress, constructorArguments) => {
11
+ async function verify(contractName, contractAddress, constructorArguments) {
12
12
  const { chainId } = await hardhat_1.ethers.provider.getNetwork();
13
- if (!chain_config_1.builtinChains.map((chain) => chain.chainId).includes(chainId)) {
14
- const errorMessage = "Verification on this network is not supported";
15
- console.log(chalk_1.default.grey(errorMessage));
16
- return;
17
- }
18
- for (let retry = 0; retry <= 5; retry += 1) {
19
- try {
20
- await (0, hardhat_1.run)("verify:verify", {
21
- "address": contractAddress,
22
- constructorArguments
23
- });
24
- break;
25
- }
26
- catch (error) {
27
- if (error instanceof Error) {
28
- const alreadyVerifiedErrorLine = "Contract source code already verified";
29
- if (error.toString().includes(alreadyVerifiedErrorLine)) {
30
- const infoMessage = `${contractName} is already verified`;
31
- console.log(chalk_1.default.grey(infoMessage));
32
- return;
33
- }
34
- const errorMessage = `Contract ${contractName} was not verified on etherscan`;
35
- console.log(chalk_1.default.red(errorMessage));
36
- console.log(error.toString());
13
+ if (chain_config_1.builtinChains.find((chain) => chain.chainId === chainId) !== undefined) {
14
+ for (let retry = 0; retry <= 5; retry += 1) {
15
+ try {
16
+ await (0, hardhat_1.run)("verify:verify", {
17
+ "address": contractAddress,
18
+ constructorArguments
19
+ });
20
+ break;
37
21
  }
38
- else {
39
- console.log("Unknown exception type:", error);
22
+ catch (e) {
23
+ if (e instanceof Error) {
24
+ if (e.toString().includes("Contract source code already verified")) {
25
+ console.log(chalk_1.default.grey(`${contractName} is already verified`));
26
+ return;
27
+ }
28
+ console.log(chalk_1.default.red(`Contract ${contractName} was not verified on etherscan`));
29
+ console.log(e.toString());
30
+ }
31
+ else {
32
+ console.log("Unknown exception type:", e);
33
+ }
40
34
  }
41
35
  }
42
36
  }
43
- };
37
+ }
44
38
  exports.verify = verify;
45
- const verifyProxy = async (contractName, proxyAddress, constructorArguments) => {
46
- await (0, exports.verify)(contractName, await (0, upgrades_core_1.getImplementationAddress)(hardhat_1.network.provider, proxyAddress), constructorArguments);
47
- };
39
+ async function verifyProxy(contractName, proxyAddress, constructorArguments) {
40
+ await verify(contractName, await (0, upgrades_core_1.getImplementationAddress)(hardhat_1.network.provider, proxyAddress), constructorArguments);
41
+ }
48
42
  exports.verifyProxy = verifyProxy;
@@ -10,7 +10,7 @@ const util_1 = __importDefault(require("util"));
10
10
  const exec = util_1.default.promisify(child_process_1.exec);
11
11
  class VersionNotFound extends Error {
12
12
  }
13
- const getVersionFilename = async (folder) => {
13
+ async function getVersionFilename(folder) {
14
14
  if (folder === undefined) {
15
15
  return getVersionFilename((await exec("git rev-parse --show-toplevel")).stdout.trim());
16
16
  }
@@ -19,16 +19,14 @@ const getVersionFilename = async (folder) => {
19
19
  if ((0, fs_1.existsSync)(path)) {
20
20
  return path;
21
21
  }
22
- for (const entry of await fs_1.promises.readdir(folder, {
23
- "withFileTypes": true,
24
- "recursive": true
25
- })) {
22
+ for (const entry of await fs_1.promises.readdir(folder, { "withFileTypes": true,
23
+ "recursive": true })) {
26
24
  if (entry.isFile() && entry.name === VERSION_FILENAME) {
27
25
  return `${entry.path}/${entry.name}`;
28
26
  }
29
27
  }
30
28
  throw new VersionNotFound("Can't find version file");
31
- };
29
+ }
32
30
  const getVersion = async () => {
33
31
  if (process.env.VERSION) {
34
32
  return process.env.VERSION;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skalenetwork/upgrade-tools",
3
- "version": "3.0.0-linter.11",
3
+ "version": "3.0.0-linter.3",
4
4
  "description": "Scripts to support upgrades of smart contracts",
5
5
  "files": [
6
6
  "dist/**/*"