@skalenetwork/upgrade-tools 1.0.0-develop.15 → 1.0.0-develop.18

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.
@@ -47,6 +47,7 @@ var Network;
47
47
  Network[Network["GANACHE"] = 1337] = "GANACHE";
48
48
  Network[Network["HARDHAT"] = 31337] = "HARDHAT";
49
49
  })(Network || (Network = {}));
50
+ // constants
50
51
  const ADDRESSES = {
51
52
  multiSend: {
52
53
  [Network.MAINNET]: "0x8D29bE29923b68abfDD21e541b9374737B49cdAD",
@@ -63,20 +64,7 @@ const URLS = {
63
64
  [Network.RINKEBY]: "https://safe-relay.rinkeby.gnosis.io",
64
65
  }
65
66
  };
66
- function getMultiSendAddress(chainId) {
67
- if (chainId === Network.MAINNET) {
68
- return ADDRESSES.multiSend[chainId];
69
- }
70
- else if (chainId === Network.RINKEBY) {
71
- return ADDRESSES.multiSend[chainId];
72
- }
73
- else if ([Network.GANACHE, Network.HARDHAT].includes(chainId)) {
74
- return ethers_1.ethers.constants.AddressZero;
75
- }
76
- else {
77
- throw Error(`Can't get multiSend contract at network with chainId = ${chainId}`);
78
- }
79
- }
67
+ // public functions
80
68
  function getSafeTransactionUrl(chainId) {
81
69
  if (chainId === Network.MAINNET) {
82
70
  return URLS.safe_transaction[chainId];
@@ -101,16 +89,6 @@ function getSafeRelayUrl(chainId) {
101
89
  }
102
90
  }
103
91
  exports.getSafeRelayUrl = getSafeRelayUrl;
104
- function concatTransactions(transactions) {
105
- return "0x" + transactions.map((transaction) => {
106
- if (transaction.startsWith("0x")) {
107
- return transaction.slice(2);
108
- }
109
- else {
110
- return transaction;
111
- }
112
- }).join("");
113
- }
114
92
  function createMultiSendTransaction(ethers, safeAddress, privateKey, transactions, nonce) {
115
93
  return __awaiter(this, void 0, void 0, function* () {
116
94
  const chainId = (yield ethers.provider.getNetwork()).chainId;
@@ -122,8 +100,26 @@ function createMultiSendTransaction(ethers, safeAddress, privateKey, transaction
122
100
  let nonceValue = 0;
123
101
  if (nonce === undefined) {
124
102
  try {
125
- const nonceResponse = yield axios_1.default.get(`${getSafeTransactionUrl(chainId)}/api/v1/safes/${safeAddress}/`);
126
- nonceValue = nonceResponse.data.nonce;
103
+ if (process.env.NONCE) {
104
+ // NONCE variable is set
105
+ if (isNaN(Number.parseInt(process.env.NONCE))) {
106
+ // NONCE variable is not a number
107
+ if (process.env.NONCE.toLowerCase() === "pending") {
108
+ nonceValue = yield getSafeNonceWithPending(chainId, safeAddress);
109
+ }
110
+ else {
111
+ nonceValue = yield getSafeNonce(chainId, safeAddress);
112
+ }
113
+ }
114
+ else {
115
+ // NONCE variable is a number
116
+ nonceValue = Number.parseInt(process.env.NONCE);
117
+ }
118
+ }
119
+ else {
120
+ // NONCE variable is not set
121
+ nonceValue = yield getSafeNonce(chainId, safeAddress);
122
+ }
127
123
  }
128
124
  catch (e) {
129
125
  if (!(e instanceof Error) || !e.toString().startsWith("Error: Can't get safe-transaction url")) {
@@ -134,6 +130,7 @@ function createMultiSendTransaction(ethers, safeAddress, privateKey, transaction
134
130
  else {
135
131
  nonceValue = nonce;
136
132
  }
133
+ console.log("Will send tx to Gnosis with nonce", nonceValue);
137
134
  const tx = {
138
135
  "safe": safeAddress,
139
136
  "to": multiSend.address,
@@ -190,3 +187,45 @@ function sendSafeTransaction(safe, chainId, safeTx) {
190
187
  });
191
188
  }
192
189
  exports.sendSafeTransaction = sendSafeTransaction;
190
+ // private functions
191
+ function getMultiSendAddress(chainId) {
192
+ if (chainId === Network.MAINNET) {
193
+ return ADDRESSES.multiSend[chainId];
194
+ }
195
+ else if (chainId === Network.RINKEBY) {
196
+ return ADDRESSES.multiSend[chainId];
197
+ }
198
+ else if ([Network.GANACHE, Network.HARDHAT].includes(chainId)) {
199
+ return ethers_1.ethers.constants.AddressZero;
200
+ }
201
+ else {
202
+ throw Error(`Can't get multiSend contract at network with chainId = ${chainId}`);
203
+ }
204
+ }
205
+ function concatTransactions(transactions) {
206
+ return "0x" + transactions.map((transaction) => {
207
+ if (transaction.startsWith("0x")) {
208
+ return transaction.slice(2);
209
+ }
210
+ else {
211
+ return transaction;
212
+ }
213
+ }).join("");
214
+ }
215
+ function getSafeNonce(chainId, safeAddress) {
216
+ return __awaiter(this, void 0, void 0, function* () {
217
+ const safeInfo = yield axios_1.default.get(`${getSafeTransactionUrl(chainId)}/api/v1/safes/${safeAddress}/`);
218
+ return safeInfo.data.nonce;
219
+ });
220
+ }
221
+ function getSafeNonceWithPending(chainId, safeAddress) {
222
+ return __awaiter(this, void 0, void 0, function* () {
223
+ const allTransactions = yield axios_1.default.get(`${getSafeTransactionUrl(chainId)}/api/v1/safes/${safeAddress}/all-transactions/?executed=false&queued=true&trusted=true`);
224
+ if (allTransactions.data.results.length > 0) {
225
+ return allTransactions.data.results[0].nonce + 1;
226
+ }
227
+ else {
228
+ return 0;
229
+ }
230
+ });
231
+ }
@@ -209,6 +209,11 @@ function upgrade(projectName, targetVersion, getDeployedVersion, setVersion, saf
209
209
  }
210
210
  console.log(chalk_1.default.blue("Transactions have been sent"));
211
211
  }
212
+ catch (exception) {
213
+ console.log(chalk_1.default.red("Error during upgrade"));
214
+ console.log(exception);
215
+ process.exitCode = 13;
216
+ }
212
217
  finally {
213
218
  console.log(chalk_1.default.blue("Return ownership to wallet"));
214
219
  yield (yield safeMock.transferProxyAdminOwnership(contractManager.address, deployer.address)).wait();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skalenetwork/upgrade-tools",
3
- "version": "1.0.0-develop.15",
3
+ "version": "1.0.0-develop.18",
4
4
  "description": "Scripts to support upgrades of smart contracts",
5
5
  "files": [
6
6
  "dist/**/*"