@skalenetwork/upgrade-tools 3.0.0-skale-contracts.7 → 3.0.0-skale-contracts.9

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.
@@ -5,8 +5,7 @@ const upgrades_core_1 = require("@openzeppelin/upgrades-core");
5
5
  const hardhat_1 = require("hardhat");
6
6
  const fs_1 = require("fs");
7
7
  async function _deployLibrary(libraryName) {
8
- const Library = await hardhat_1.ethers.getContractFactory(libraryName);
9
- const library = await Library.deploy();
8
+ const Library = await hardhat_1.ethers.getContractFactory(libraryName), library = await Library.deploy();
10
9
  await library.deployed();
11
10
  return library.address;
12
11
  }
@@ -37,9 +36,7 @@ function _linkBytecode(artifact, libraries) {
37
36
  return bytecode;
38
37
  }
39
38
  async function getLinkedContractFactory(contractName, libraries) {
40
- const cArtifact = await hardhat_1.artifacts.readArtifact(contractName);
41
- const linkedBytecode = _linkBytecode(cArtifact, libraries);
42
- const ContractFactory = await hardhat_1.ethers.getContractFactory(cArtifact.abi, linkedBytecode);
39
+ const cArtifact = await hardhat_1.artifacts.readArtifact(contractName), linkedBytecode = _linkBytecode(cArtifact, libraries), ContractFactory = await hardhat_1.ethers.getContractFactory(cArtifact.abi, linkedBytecode);
43
40
  return ContractFactory;
44
41
  }
45
42
  exports.getLinkedContractFactory = getLinkedContractFactory;
@@ -56,11 +53,13 @@ async function getContractFactory(contract) {
56
53
  const libraryName = Object.keys(linkReferences[key])[0];
57
54
  libraryNames.push(libraryName);
58
55
  }
59
- const libraries = await deployLibraries(libraryNames);
60
- const libraryArtifacts = {};
56
+ const libraries = await deployLibraries(libraryNames), libraryArtifacts = {};
61
57
  for (const [libraryName, libraryAddress] of libraries.entries()) {
62
58
  const { bytecode } = await hardhat_1.artifacts.readArtifact(libraryName);
63
- libraryArtifacts[libraryName] = { "address": libraryAddress, "bytecodeHash": (0, upgrades_core_1.hashBytecode)(bytecode) };
59
+ libraryArtifacts[libraryName] = {
60
+ "address": libraryAddress,
61
+ "bytecodeHash": (0, upgrades_core_1.hashBytecode)(bytecode)
62
+ };
64
63
  }
65
64
  let manifest;
66
65
  try {
@@ -56,8 +56,7 @@ async function createMultiSendTransaction(safeAddress, transactions) {
56
56
  operation: 0,
57
57
  });
58
58
  }
59
- const safeService = await getSafeService();
60
- const nonce = await safeService.getNextNonce(safeAddress);
59
+ const safeService = await getSafeService(), nonce = await safeService.getNextNonce(safeAddress);
61
60
  console.log("Will send tx to Gnosis with nonce", nonce);
62
61
  const options = {
63
62
  safeTxGas: "0",
@@ -66,10 +65,7 @@ async function createMultiSendTransaction(safeAddress, transactions) {
66
65
  gasToken: hardhat_1.ethers.constants.AddressZero,
67
66
  refundReceiver: hardhat_1.ethers.constants.AddressZero,
68
67
  nonce: nonce // Nonce of the Safe, transaction cannot be executed until Safe's nonce is not equal to this nonce
69
- };
70
- const ethAdapter = await getEthAdapter();
71
- const safeSdk = await protocol_kit_1.default.create({ ethAdapter, safeAddress });
72
- const safeTransaction = await safeSdk.createTransaction({ safeTransactionData, options });
68
+ }, ethAdapter = await getEthAdapter(), safeSdk = await protocol_kit_1.default.create({ ethAdapter, safeAddress }), safeTransaction = await safeSdk.createTransaction({ safeTransactionData, options });
73
69
  await estimateSafeTransaction(safeAddress, safeTransactionData);
74
70
  await proposeTransaction(safeAddress, safeTransaction);
75
71
  }
@@ -90,12 +86,7 @@ async function estimateSafeTransaction(safeAddress, safeTransactionData) {
90
86
  console.log(chalk_1.default.green("Send transaction to gnosis safe"));
91
87
  }
92
88
  async function proposeTransaction(safeAddress, safeTransaction) {
93
- const [safeOwner] = await hardhat_1.ethers.getSigners();
94
- const ethAdapter = await getEthAdapter();
95
- const safeSdk = await protocol_kit_1.default.create({ ethAdapter, safeAddress });
96
- const safeTxHash = await safeSdk.getTransactionHash(safeTransaction);
97
- const senderSignature = await safeSdk.signTransactionHash(safeTxHash);
98
- const safeService = await getSafeService();
89
+ const [safeOwner] = await hardhat_1.ethers.getSigners(), ethAdapter = await getEthAdapter(), safeSdk = await protocol_kit_1.default.create({ ethAdapter, safeAddress }), safeTxHash = await safeSdk.getTransactionHash(safeTransaction), senderSignature = await safeSdk.signTransactionHash(safeTxHash), safeService = await getSafeService();
99
90
  await safeService.proposeTransaction({
100
91
  safeAddress,
101
92
  safeTransactionData: safeTransaction.data,
@@ -105,17 +96,14 @@ async function proposeTransaction(safeAddress, safeTransaction) {
105
96
  });
106
97
  }
107
98
  async function getEthAdapter() {
108
- const [safeOwner] = await hardhat_1.ethers.getSigners();
109
- const ethAdapter = new protocol_kit_1.EthersAdapter({
99
+ const [safeOwner] = await hardhat_1.ethers.getSigners(), ethAdapter = new protocol_kit_1.EthersAdapter({
110
100
  ethers: hardhat_1.ethers,
111
101
  signerOrProvider: safeOwner
112
102
  });
113
103
  return ethAdapter;
114
104
  }
115
105
  async function getSafeService() {
116
- const chainId = (await hardhat_1.ethers.provider.getNetwork()).chainId;
117
- const ethAdapter = await getEthAdapter();
118
- const safeService = new api_kit_1.default({
106
+ const chainId = (await hardhat_1.ethers.provider.getNetwork()).chainId, ethAdapter = await getEthAdapter(), safeService = new api_kit_1.default({
119
107
  txServiceUrl: getSafeTransactionUrl(chainId),
120
108
  ethAdapter
121
109
  });
@@ -2,7 +2,7 @@ import { Transaction } from "ethers";
2
2
  import { Submitter } from "./submitter";
3
3
  export declare class AutoSubmitter extends Submitter {
4
4
  submit(transactions: Transaction[]): Promise<void>;
5
- _getImaInstance(): Promise<import("@skalenetwork/skale-contracts").Instance>;
5
+ _getImaInstance(): Promise<import("@skalenetwork/skale-contracts/lib/instance").Instance<import("ethers").BaseContract>>;
6
6
  _getSafeAddress(): string;
7
7
  _getSchainHash(): string;
8
8
  _getMainnetChainId(): number;
@@ -35,13 +35,12 @@ const safe_submitter_1 = require("./safe-submitter");
35
35
  const chalk_1 = __importDefault(require("chalk"));
36
36
  const safe_ima_legacy_marionette_submitter_1 = require("./safe-ima-legacy-marionette-submitter");
37
37
  const marionette_1 = require("./types/marionette");
38
- const skale_contracts_1 = require("@skalenetwork/skale-contracts");
38
+ const skale_contracts_ethers_v5_1 = require("@skalenetwork/skale-contracts-ethers-v5");
39
39
  class AutoSubmitter extends submitter_1.Submitter {
40
40
  async submit(transactions) {
41
41
  let submitter;
42
42
  // TODO: remove unknown when move everything to ethers 6
43
- const proxyAdmin = await (0, admin_1.getManifestAdmin)(hardhat_1.default);
44
- const owner = await proxyAdmin.owner();
43
+ const proxyAdmin = await (0, admin_1.getManifestAdmin)(hardhat_1.default), owner = await proxyAdmin.owner();
45
44
  if (await hardhat_1.default.ethers.provider.getCode(owner) === "0x") {
46
45
  console.log("Owner is not a contract");
47
46
  submitter = new eoa_submitter_1.EoaSubmitter();
@@ -50,10 +49,7 @@ class AutoSubmitter extends submitter_1.Submitter {
50
49
  console.log("Owner is a contract");
51
50
  if (hardhat_1.ethers.utils.getAddress(owner) == hardhat_1.ethers.utils.getAddress(marionette_1.MARIONETTE_ADDRESS)) {
52
51
  console.log("Marionette owner is detected");
53
- const imaInstance = await this._getImaInstance();
54
- const safeAddress = this._getSafeAddress();
55
- const schainHash = this._getSchainHash();
56
- const mainnetChainId = this._getMainnetChainId();
52
+ const imaInstance = await this._getImaInstance(), mainnetChainId = this._getMainnetChainId(), safeAddress = this._getSafeAddress(), schainHash = this._getSchainHash();
57
53
  // TODO: after marionette has multiSend functionality
58
54
  // query version and properly select a submitter
59
55
  // based on it
@@ -91,8 +87,7 @@ class AutoSubmitter extends submitter_1.Submitter {
91
87
  console.log(chalk_1.default.red("Set target IMA alias to IMA environment variable"));
92
88
  process.exit(1);
93
89
  }
94
- const network = await skale_contracts_1.skaleContracts.getNetworkByChainId((await hardhat_1.ethers.provider.getNetwork()).chainId);
95
- const ima = await network.getProject("ima");
90
+ const network = await skale_contracts_ethers_v5_1.skaleContracts.getNetworkByProvider(hardhat_1.ethers.provider), ima = await network.getProject("ima");
96
91
  return await ima.getInstance(process.env.IMA);
97
92
  }
98
93
  _getSafeAddress() {
@@ -1,6 +1,6 @@
1
1
  import { BytesLike, UnsignedTransaction } from "ethers";
2
2
  import { SafeSubmitter } from "./safe-submitter";
3
- import { Instance } from "@skalenetwork/skale-contracts";
3
+ import { Instance } from "@skalenetwork/skale-contracts-ethers-v5";
4
4
  export declare class SafeToImaSubmitter extends SafeSubmitter {
5
5
  imaInstance: Instance;
6
6
  targetSchainHash: BytesLike;
@@ -12,8 +12,7 @@ class SafeToImaSubmitter extends safe_submitter_1.SafeSubmitter {
12
12
  if (transactions.length > 1) {
13
13
  this._atomicityWarning();
14
14
  }
15
- const messageProxyForMainnet = await this._getMessageProxyForMainnet();
16
- const transactionsToIma = transactions.map((transaction) => {
15
+ const messageProxyForMainnet = await this._getMessageProxyForMainnet(), transactionsToIma = transactions.map((transaction) => {
17
16
  return {
18
17
  to: messageProxyForMainnet.address,
19
18
  data: messageProxyForMainnet.interface.encodeFunctionData("postOutgoingMessage", [this.targetSchainHash, transaction.to, transaction.data])
@@ -1,6 +1,6 @@
1
1
  import { UnsignedTransaction } from "ethers";
2
2
  import { Submitter } from "./submitters/submitter";
3
- import { Instance } from "@skalenetwork/skale-contracts/lib/instance";
3
+ import { Instance } from "@skalenetwork/skale-contracts-ethers-v5";
4
4
  export declare abstract class Upgrader {
5
5
  instance: Instance;
6
6
  targetVersion: string;
@@ -52,14 +52,12 @@ class Upgrader {
52
52
  // Deploy new implementations
53
53
  const contractsToUpgrade = [];
54
54
  for (const contract of this.contractNamesToUpgrade) {
55
- const contractFactory = await this._getContractFactoryAndUpdateManifest(contract);
56
- const proxyAddress = (await this.instance.getContract(contract)).address;
55
+ const contractFactory = await this._getContractFactoryAndUpdateManifest(contract), proxyAddress = (await this.instance.getContract(contract)).address;
57
56
  console.log(`Prepare upgrade of ${contract}`);
58
- const newImplementationAddress = await hardhat_2.upgrades.prepareUpgrade(proxyAddress, contractFactory, {
57
+ const currentImplementationAddress = await (0, upgrades_core_1.getImplementationAddress)(hardhat_2.network.provider, proxyAddress), newImplementationAddress = await hardhat_2.upgrades.prepareUpgrade(proxyAddress, contractFactory, {
59
58
  unsafeAllowLinkedLibraries: true,
60
59
  unsafeAllowRenames: true
61
60
  });
62
- const currentImplementationAddress = await (0, upgrades_core_1.getImplementationAddress)(hardhat_2.network.provider, proxyAddress);
63
61
  if (newImplementationAddress !== currentImplementationAddress) {
64
62
  contractsToUpgrade.push({
65
63
  proxyAddress,
@@ -89,18 +87,15 @@ class Upgrader {
89
87
  }
90
88
  // private
91
89
  async _getContractFactoryAndUpdateManifest(contract) {
92
- const manifest = JSON.parse(await fs_1.promises.readFile(await (0, deploy_1.getManifestFile)(), "utf-8"));
93
- const { linkReferences } = await hardhat_2.artifacts.readArtifact(contract);
90
+ const { linkReferences } = await hardhat_2.artifacts.readArtifact(contract), manifest = JSON.parse(await fs_1.promises.readFile(await (0, deploy_1.getManifestFile)(), "utf-8"));
94
91
  if (!Object.keys(linkReferences).length)
95
92
  return await hardhat_2.ethers.getContractFactory(contract);
96
- const librariesToUpgrade = [];
97
- const oldLibraries = {};
93
+ const librariesToUpgrade = [], oldLibraries = {};
98
94
  if (manifest.libraries === undefined) {
99
95
  Object.assign(manifest, { libraries: {} });
100
96
  }
101
97
  for (const key of Object.keys(linkReferences)) {
102
- const libraryName = Object.keys(linkReferences[key])[0];
103
- const { bytecode } = await hardhat_2.artifacts.readArtifact(libraryName);
98
+ const libraryName = Object.keys(linkReferences[key])[0], { bytecode } = await hardhat_2.artifacts.readArtifact(libraryName);
104
99
  if (manifest.libraries[libraryName] === undefined) {
105
100
  librariesToUpgrade.push(libraryName);
106
101
  continue;
@@ -1 +1 @@
1
- export declare function getVersion(): Promise<string>;
1
+ export declare const getVersion: () => Promise<string>;
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getVersion = void 0;
7
- const fs_1 = require("fs");
8
7
  const child_process_1 = require("child_process");
8
+ const fs_1 = require("fs");
9
9
  const util_1 = __importDefault(require("util"));
10
10
  const exec = util_1.default.promisify(child_process_1.exec);
11
- async function getVersion() {
11
+ const getVersion = async () => {
12
12
  if (process.env.VERSION) {
13
13
  return process.env.VERSION;
14
14
  }
@@ -19,5 +19,5 @@ async function getVersion() {
19
19
  catch {
20
20
  return (await fs_1.promises.readFile("VERSION", "utf-8")).trim();
21
21
  }
22
- }
22
+ };
23
23
  exports.getVersion = getVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skalenetwork/upgrade-tools",
3
- "version": "3.0.0-skale-contracts.7",
3
+ "version": "3.0.0-skale-contracts.9",
4
4
  "description": "Scripts to support upgrades of smart contracts",
5
5
  "files": [
6
6
  "dist/**/*"
@@ -21,15 +21,15 @@
21
21
  "fullCheck": "yarn compile && yarn lint && yarn eslint && yarn cspell && yarn slither",
22
22
  "lint": "npx solhint \"contracts/**/*.sol\"",
23
23
  "slither": "slither .",
24
- "eslint": "npx eslint --cache --ext .js,.jsx,.ts,.tsx .",
24
+ "eslint": "npx eslint .",
25
25
  "cspell": "npx cspell \"**/*\""
26
26
  },
27
27
  "devDependencies": {
28
28
  "@tsconfig/recommended": "^1.0.2",
29
29
  "@typechain/ethers-v5": "^9.0.0",
30
30
  "@typechain/hardhat": "^8.0.0",
31
- "@typescript-eslint/eslint-plugin": "^5.23.0",
32
- "@typescript-eslint/parser": "^5.23.0",
31
+ "@typescript-eslint/eslint-plugin": "^6.6.0",
32
+ "@typescript-eslint/parser": "^6.6.0",
33
33
  "cspell": "^7.0.0",
34
34
  "eslint": "^8.15.0",
35
35
  "install-peers-cli": "^2.2.0",
@@ -43,7 +43,7 @@
43
43
  "@safe-global/api-kit": "^1.3.0",
44
44
  "@safe-global/protocol-kit": "^1.2.0",
45
45
  "@safe-global/safe-core-sdk-types": "^2.2.0",
46
- "@skalenetwork/skale-contracts": "^0.0.1-main.20",
46
+ "@skalenetwork/skale-contracts-ethers-v5": "0.1.0-develop.0",
47
47
  "axios": "^1.4.0",
48
48
  "ethereumjs-util": "^7.1.4"
49
49
  },