@skalenetwork/upgrade-tools 2.0.0-refactor.14 → 2.0.0-refactor.16

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.
@@ -1,5 +1,10 @@
1
1
  import { UnsignedTransaction } from "ethers";
2
2
  import { Submitter } from "./submitter";
3
+ import { SkaleABIFile } from "../types/SkaleABIFile";
3
4
  export declare class AutoSubmitter extends Submitter {
4
5
  submit(transactions: UnsignedTransaction[]): Promise<void>;
6
+ _getImaAbi(): Promise<SkaleABIFile>;
7
+ _getSafeAddress(): string;
8
+ _getSchainHash(): string;
9
+ _getMainnetChainId(): number;
5
10
  }
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -15,9 +38,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
38
  exports.AutoSubmitter = void 0;
16
39
  const admin_1 = require("@openzeppelin/hardhat-upgrades/dist/admin");
17
40
  const submitter_1 = require("./submitter");
18
- const hardhat_1 = __importDefault(require("hardhat"));
41
+ const hardhat_1 = __importStar(require("hardhat"));
19
42
  const eoa_submitter_1 = require("./eoa-submitter");
20
43
  const safe_submitter_1 = require("./safe-submitter");
44
+ const chalk_1 = __importDefault(require("chalk"));
45
+ const safe_ima_legacy_marionette_submitter_1 = require("./safe-ima-legacy-marionette-submitter");
46
+ const fs_1 = require("fs");
21
47
  class AutoSubmitter extends submitter_1.Submitter {
22
48
  submit(transactions) {
23
49
  return __awaiter(this, void 0, void 0, function* () {
@@ -30,11 +56,65 @@ class AutoSubmitter extends submitter_1.Submitter {
30
56
  }
31
57
  else {
32
58
  console.log("Owner is a contract");
33
- // TODO: add support of Marionette
34
- submitter = new safe_submitter_1.SafeSubmitter(owner);
59
+ if (hardhat_1.ethers.utils.getAddress(owner) == hardhat_1.ethers.utils.getAddress("0xD2c0DeFACe000000000000000000000000000000")) {
60
+ console.log("Marionette owner is detected");
61
+ const imaAbi = yield this._getImaAbi();
62
+ const safeAddress = this._getSafeAddress();
63
+ const schainHash = this._getSchainHash();
64
+ const mainnetChainId = this._getMainnetChainId();
65
+ submitter = new safe_ima_legacy_marionette_submitter_1.SafeImaLegacyMarionetteSubmitter(safeAddress, imaAbi, schainHash, mainnetChainId);
66
+ }
67
+ else {
68
+ // assuming owner is a Gnosis Safe
69
+ console.log("Using Gnosis Safe");
70
+ submitter = new safe_submitter_1.SafeSubmitter(owner);
71
+ }
35
72
  }
36
73
  yield submitter.submit(transactions);
37
74
  });
38
75
  }
76
+ // private
77
+ _getImaAbi() {
78
+ return __awaiter(this, void 0, void 0, function* () {
79
+ if (!process.env.IMA_ABI) {
80
+ console.log(chalk_1.default.red("Set path to ima abi to IMA_ABI environment variable"));
81
+ process.exit(1);
82
+ }
83
+ return JSON.parse(yield fs_1.promises.readFile(process.env.IMA_ABI, "utf-8"));
84
+ });
85
+ }
86
+ _getSafeAddress() {
87
+ if (!process.env.SAFE_ADDRESS) {
88
+ console.log(chalk_1.default.red("Set Gnosis Safe owner address to SAFE_ADDRESS environment variable"));
89
+ process.exit(1);
90
+ }
91
+ return process.env.SAFE_ADDRESS;
92
+ }
93
+ _getSchainHash() {
94
+ // query Context to get schain hash
95
+ if (!process.env.SCHAIN_HASH) {
96
+ if (!process.env.SCHAIN_NAME) {
97
+ console.log(chalk_1.default.red("Set schain name to SCHAIN_NAME environment variable"));
98
+ console.log(chalk_1.default.red("or schain hash to SCHAIN_HASH environment variable"));
99
+ process.exit(1);
100
+ }
101
+ else {
102
+ return hardhat_1.ethers.utils.solidityKeccak256(["string"], [process.env.SCHAIN_NAME]);
103
+ }
104
+ }
105
+ else {
106
+ return process.env.SCHAIN_HASH;
107
+ }
108
+ }
109
+ _getMainnetChainId() {
110
+ if (!process.env.MAINNET_CHAIN_ID) {
111
+ console.log(chalk_1.default.red("Set chainId of mainnet to MAINNET_CHAIN_ID environment variable"));
112
+ console.log(chalk_1.default.red("Use 1 for Ethereum mainnet or 5 for Goerli"));
113
+ process.exit(1);
114
+ }
115
+ else {
116
+ return Number.parseInt(process.env.MAINNET_CHAIN_ID);
117
+ }
118
+ }
39
119
  }
40
120
  exports.AutoSubmitter = AutoSubmitter;
@@ -0,0 +1,16 @@
1
+ import { BigNumberish, BytesLike, UnsignedTransaction } from "ethers";
2
+ import { ethers as RawEthers } from "ethers";
3
+ import { SafeToImaSubmitter } from "./safe-to-ima-submitter";
4
+ declare type FunctionCallStruct = {
5
+ receiver: string;
6
+ value: BigNumberish;
7
+ data: BytesLike;
8
+ };
9
+ interface Marionette extends RawEthers.Contract {
10
+ encodeFunctionCalls(functionCalls: FunctionCallStruct[]): Promise<BytesLike>;
11
+ }
12
+ export declare class SafeImaMarionetteSubmitter extends SafeToImaSubmitter {
13
+ marionette: Marionette;
14
+ submit(transactions: UnsignedTransaction[]): Promise<void>;
15
+ }
16
+ export {};
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.SafeImaMarionetteSubmitter = void 0;
13
+ const hardhat_1 = require("hardhat");
14
+ const safe_to_ima_submitter_1 = require("./safe-to-ima-submitter");
15
+ class SafeImaMarionetteSubmitter extends safe_to_ima_submitter_1.SafeToImaSubmitter {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.marionette = new hardhat_1.ethers.Contract("0xD2c0DeFACe000000000000000000000000000000", new hardhat_1.ethers.utils.Interface([
19
+ {
20
+ "inputs": [
21
+ {
22
+ "components": [
23
+ {
24
+ "internalType": "address",
25
+ "name": "receiver",
26
+ "type": "address"
27
+ },
28
+ {
29
+ "internalType": "uint256",
30
+ "name": "value",
31
+ "type": "uint256"
32
+ },
33
+ {
34
+ "internalType": "bytes",
35
+ "name": "data",
36
+ "type": "bytes"
37
+ }
38
+ ],
39
+ "internalType": "struct IMarionette.FunctionCall[]",
40
+ "name": "functionCalls",
41
+ "type": "tuple[]"
42
+ }
43
+ ],
44
+ "name": "encodeFunctionCalls",
45
+ "outputs": [
46
+ {
47
+ "internalType": "bytes",
48
+ "name": "",
49
+ "type": "bytes"
50
+ }
51
+ ],
52
+ "stateMutability": "pure",
53
+ "type": "function"
54
+ }
55
+ ]), hardhat_1.ethers.provider);
56
+ }
57
+ submit(transactions) {
58
+ const _super = Object.create(null, {
59
+ submit: { get: () => super.submit }
60
+ });
61
+ return __awaiter(this, void 0, void 0, function* () {
62
+ const functionCalls = [];
63
+ for (const transaction of transactions) {
64
+ functionCalls.push({
65
+ receiver: transaction.to ? transaction.to : hardhat_1.ethers.constants.AddressZero,
66
+ value: transaction.value ? transaction.value : 0,
67
+ data: (transaction.data ? transaction.data : "0x")
68
+ });
69
+ }
70
+ yield _super.submit.call(this, [
71
+ {
72
+ to: this.marionette.address,
73
+ data: yield this.marionette.encodeFunctionCalls(functionCalls)
74
+ }
75
+ ]);
76
+ });
77
+ }
78
+ }
79
+ exports.SafeImaMarionetteSubmitter = SafeImaMarionetteSubmitter;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skalenetwork/upgrade-tools",
3
- "version": "2.0.0-refactor.14",
3
+ "version": "2.0.0-refactor.16",
4
4
  "description": "Scripts to support upgrades of smart contracts",
5
5
  "files": [
6
6
  "dist/**/*"