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

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
+ }
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.14",
4
4
  "description": "Scripts to support upgrades of smart contracts",
5
5
  "files": [
6
6
  "dist/**/*"