@skalenetwork/upgrade-tools 2.0.0-refactor.13 → 2.0.0-refactor.15

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.
@@ -92,8 +92,6 @@ function createMultiSendTransaction(ethers, safeAddress, privateKey, transaction
92
92
  const multiSendAddress = getMultiSendAddress(chainId);
93
93
  const multiSendAbi = [{ "constant": false, "inputs": [{ "internalType": "bytes", "name": "transactions", "type": "bytes" }], "name": "multiSend", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }];
94
94
  const multiSend = new ethers.Contract(multiSendAddress, new ethers.utils.Interface(multiSendAbi), ethers.provider);
95
- const safeAbi = [{ "constant": true, "inputs": [{ "internalType": "address", "name": "to", "type": "address" }, { "internalType": "uint256", "name": "value", "type": "uint256" }, { "internalType": "bytes", "name": "data", "type": "bytes" }, { "internalType": "enum Enum.Operation", "name": "operation", "type": "uint8" }, { "internalType": "uint256", "name": "safeTxGas", "type": "uint256" }, { "internalType": "uint256", "name": "baseGas", "type": "uint256" }, { "internalType": "uint256", "name": "gasPrice", "type": "uint256" }, { "internalType": "address", "name": "gasToken", "type": "address" }, { "internalType": "address", "name": "refundReceiver", "type": "address" }, { "internalType": "uint256", "name": "_nonce", "type": "uint256" }], "name": "getTransactionHash", "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], "payable": false, "stateMutability": "view", "type": "function" }];
96
- const safe = new ethers.Contract(safeAddress, new ethers.utils.Interface(safeAbi), ethers.provider);
97
95
  let nonceValue = 0;
98
96
  if (nonce === undefined) {
99
97
  try {
@@ -141,7 +139,7 @@ function createMultiSendTransaction(ethers, safeAddress, privateKey, transaction
141
139
  "refundReceiver": ethers.constants.AddressZero,
142
140
  "nonce": nonceValue, // Nonce of the Safe, transaction cannot be executed until Safe's nonce is not equal to this nonce
143
141
  };
144
- const digestHex = yield safe.getTransactionHash(tx.to, tx.value, tx.data, tx.operation, tx.safeTxGas, tx.baseGas, tx.gasPrice, tx.gasToken, tx.refundReceiver, tx.nonce);
142
+ const digestHex = getTransactionHash(tx.to, tx.value, tx.data, tx.operation, tx.safeTxGas, tx.baseGas, tx.gasPrice, tx.gasToken, tx.refundReceiver, tx.nonce, safeAddress, chainId);
145
143
  const privateKeyBuffer = ethUtil.toBuffer(privateKey);
146
144
  const { r, s, v } = ethUtil.ecsign(ethUtil.toBuffer(digestHex), privateKeyBuffer);
147
145
  const signature = ethUtil.toRpcSig(v, r, s).toString();
@@ -223,3 +221,45 @@ function getSafeNonceWithPending(chainId, safeAddress) {
223
221
  }
224
222
  });
225
223
  }
224
+ function getDomainSeparator(safeAddress, chainId) {
225
+ const DOMAIN_SEPARATOR_TYPEHASH = "0x47e79534a245952e8b16893a336b85a3d9ea9fa8c573f3d803afb92a79469218";
226
+ return ethers_1.ethers.utils.solidityKeccak256(["bytes"], [
227
+ ethers_1.ethers.utils.defaultAbiCoder.encode(["bytes32", "uint256", "address"], [DOMAIN_SEPARATOR_TYPEHASH, chainId, safeAddress])
228
+ ]);
229
+ }
230
+ function encodeTransactionData(to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce, safeAddress, chainId) {
231
+ const dataHash = ethers_1.ethers.utils.solidityKeccak256(["bytes"], [data]);
232
+ const SAFE_TX_TYPEHASH = "0xbb8310d486368db6bd6f849402fdd73ad53d316b5a4b2644ad6efe0f941286d8";
233
+ const encoded = ethers_1.ethers.utils.defaultAbiCoder.encode([
234
+ "bytes32",
235
+ "address",
236
+ "uint256",
237
+ "bytes32",
238
+ "uint256",
239
+ "uint256",
240
+ "uint256",
241
+ "uint256",
242
+ "address",
243
+ "address",
244
+ "uint256"
245
+ ], [
246
+ SAFE_TX_TYPEHASH,
247
+ to,
248
+ value,
249
+ dataHash,
250
+ operation,
251
+ safeTxGas,
252
+ baseGas,
253
+ gasPrice,
254
+ gasToken,
255
+ refundReceiver,
256
+ _nonce
257
+ ]);
258
+ const encodedHash = ethers_1.ethers.utils.solidityKeccak256(["bytes"], [encoded]);
259
+ return ethers_1.ethers.utils.solidityPack(["bytes1", "bytes1", "bytes32", "bytes32"], ["0x19", "0x01", getDomainSeparator(safeAddress, chainId), encodedHash]);
260
+ }
261
+ function getTransactionHash(to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce, safeAddress, chainId) {
262
+ return ethers_1.ethers.utils.solidityKeccak256(["bytes"], [
263
+ encodeTransactionData(to, value, data, operation, safeTxGas, baseGas, gasPrice, gasToken, refundReceiver, _nonce, safeAddress, chainId)
264
+ ]);
265
+ }
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skalenetwork/upgrade-tools",
3
- "version": "2.0.0-refactor.13",
3
+ "version": "2.0.0-refactor.15",
4
4
  "description": "Scripts to support upgrades of smart contracts",
5
5
  "files": [
6
6
  "dist/**/*"