rocketh 0.5.10 → 0.5.12

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/chunk-472IGS3D.js +775 -0
  3. package/dist/chunk-472IGS3D.js.map +1 -0
  4. package/dist/chunk-4QVFNMWY.js +814 -0
  5. package/dist/chunk-4QVFNMWY.js.map +1 -0
  6. package/dist/chunk-4YSEV6V7.js +819 -0
  7. package/dist/chunk-4YSEV6V7.js.map +1 -0
  8. package/dist/chunk-6MXUXCI5.js +814 -0
  9. package/dist/chunk-6MXUXCI5.js.map +1 -0
  10. package/dist/chunk-6OHBWJ6R.js +802 -0
  11. package/dist/chunk-6OHBWJ6R.js.map +1 -0
  12. package/dist/chunk-6SYA5IBX.js +775 -0
  13. package/dist/chunk-6SYA5IBX.js.map +1 -0
  14. package/dist/chunk-A2DF6IYU.js +775 -0
  15. package/dist/chunk-A2DF6IYU.js.map +1 -0
  16. package/dist/chunk-BDP52TGA.js +775 -0
  17. package/dist/chunk-BDP52TGA.js.map +1 -0
  18. package/dist/chunk-CWIC3RNX.js +779 -0
  19. package/dist/chunk-CWIC3RNX.js.map +1 -0
  20. package/dist/chunk-CY65LIMI.js +812 -0
  21. package/dist/chunk-CY65LIMI.js.map +1 -0
  22. package/dist/chunk-DVS3FHRT.js +775 -0
  23. package/dist/chunk-DVS3FHRT.js.map +1 -0
  24. package/dist/chunk-E3HMPYAE.js +802 -0
  25. package/dist/chunk-E3HMPYAE.js.map +1 -0
  26. package/dist/chunk-EEKPYOVG.js +814 -0
  27. package/dist/chunk-EEKPYOVG.js.map +1 -0
  28. package/dist/chunk-EZAHXMFN.js +779 -0
  29. package/dist/chunk-EZAHXMFN.js.map +1 -0
  30. package/dist/chunk-FIYG7LWT.js +802 -0
  31. package/dist/chunk-FIYG7LWT.js.map +1 -0
  32. package/dist/chunk-FNGUBXU4.js +819 -0
  33. package/dist/chunk-FNGUBXU4.js.map +1 -0
  34. package/dist/chunk-HYG6AZHD.js +775 -0
  35. package/dist/chunk-HYG6AZHD.js.map +1 -0
  36. package/dist/chunk-K53RF3NI.js +775 -0
  37. package/dist/chunk-K53RF3NI.js.map +1 -0
  38. package/dist/chunk-LQNPDN2C.js +802 -0
  39. package/dist/chunk-LQNPDN2C.js.map +1 -0
  40. package/dist/chunk-N3LXBIZU.js +813 -0
  41. package/dist/chunk-N3LXBIZU.js.map +1 -0
  42. package/dist/{chunk-KPCNGETT.js → chunk-NYXECIHF.js} +53 -38
  43. package/dist/chunk-NYXECIHF.js.map +1 -0
  44. package/dist/chunk-PJUHRI2O.js +819 -0
  45. package/dist/chunk-PJUHRI2O.js.map +1 -0
  46. package/dist/chunk-QBPUQWOC.js +802 -0
  47. package/dist/chunk-QBPUQWOC.js.map +1 -0
  48. package/dist/chunk-SBMZCD52.js +813 -0
  49. package/dist/chunk-SBMZCD52.js.map +1 -0
  50. package/dist/chunk-T632AEY2.js +775 -0
  51. package/dist/chunk-T632AEY2.js.map +1 -0
  52. package/dist/chunk-TDQGC7ST.js +775 -0
  53. package/dist/chunk-TDQGC7ST.js.map +1 -0
  54. package/dist/chunk-TNMQT3PW.js +802 -0
  55. package/dist/chunk-TNMQT3PW.js.map +1 -0
  56. package/dist/chunk-TRN42LR4.js +779 -0
  57. package/dist/chunk-TRN42LR4.js.map +1 -0
  58. package/dist/chunk-TSZHO6IV.js +819 -0
  59. package/dist/chunk-TSZHO6IV.js.map +1 -0
  60. package/dist/chunk-YZAKY2DK.js +813 -0
  61. package/dist/chunk-YZAKY2DK.js.map +1 -0
  62. package/dist/cli.cjs +119 -64
  63. package/dist/cli.cjs.map +1 -1
  64. package/dist/cli.js +2 -2
  65. package/dist/cli.js.map +1 -1
  66. package/dist/index.cjs +118 -63
  67. package/dist/index.cjs.map +1 -1
  68. package/dist/index.d.ts +17 -4
  69. package/dist/index.js +1 -1
  70. package/package.json +1 -1
  71. package/src/environment/index.ts +136 -63
  72. package/src/environment/types.ts +18 -5
  73. package/src/executor/index.ts +4 -3
  74. package/src/internal/types.ts +0 -2
  75. package/dist/chunk-KPCNGETT.js.map +0 -1
@@ -0,0 +1,819 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw new Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // src/utils/fs.ts
10
+ import fs from "fs";
11
+ import path from "path";
12
+ function traverseMultipleDirectory(dirs) {
13
+ const filepaths = [];
14
+ for (const dir of dirs) {
15
+ let filesStats = traverse(dir);
16
+ filesStats = filesStats.filter((v) => !v.directory);
17
+ for (const filestat of filesStats) {
18
+ filepaths.push(path.join(dir, filestat.relativePath));
19
+ }
20
+ }
21
+ return filepaths;
22
+ }
23
+ var traverse = function(dir, result = [], topDir, filter) {
24
+ fs.readdirSync(dir).forEach((name) => {
25
+ const fPath = path.resolve(dir, name);
26
+ const stats = fs.statSync(fPath);
27
+ if (!filter && !name.startsWith(".") || filter && filter(name, stats)) {
28
+ const fileStats = {
29
+ name,
30
+ path: fPath,
31
+ relativePath: path.relative(topDir || dir, fPath),
32
+ mtimeMs: stats.mtimeMs,
33
+ directory: stats.isDirectory()
34
+ };
35
+ if (fileStats.directory) {
36
+ result.push(fileStats);
37
+ return traverse(fPath, result, topDir || dir, filter);
38
+ }
39
+ result.push(fileStats);
40
+ }
41
+ });
42
+ return result;
43
+ };
44
+
45
+ // src/executor/index.ts
46
+ import path4 from "path";
47
+ import fs4 from "fs";
48
+
49
+ // src/environment/index.ts
50
+ import fs3 from "fs";
51
+ import { createPublicClient, custom } from "viem";
52
+ import { JSONRPCHTTPProvider } from "eip-1193-json-provider";
53
+ import path3 from "path";
54
+
55
+ // src/utils/json.ts
56
+ function bnReplacer(k, v) {
57
+ if (typeof v === "bigint") {
58
+ return v.toString() + "n";
59
+ }
60
+ return v;
61
+ }
62
+ function bnReviver(k, v) {
63
+ if (typeof v === "string" && (v.startsWith("-") ? !isNaN(parseInt(v.charAt(1))) : !isNaN(parseInt(v.charAt(0)))) && v.charAt(v.length - 1) === "n") {
64
+ return BigInt(v.slice(0, -1));
65
+ }
66
+ return v;
67
+ }
68
+ function JSONToString(json, space) {
69
+ return JSON.stringify(json, bnReplacer, space);
70
+ }
71
+ function stringToJSON(str) {
72
+ return JSON.parse(str, bnReviver);
73
+ }
74
+
75
+ // src/environment/deployments.ts
76
+ import path2 from "path";
77
+ import fs2 from "fs";
78
+ function loadDeployments(deploymentsPath, subPath, onlyABIAndAddress, expectedChainId) {
79
+ const deploymentsFound = {};
80
+ const deployPath = path2.join(deploymentsPath, subPath);
81
+ let filesStats;
82
+ try {
83
+ filesStats = traverse(deployPath, void 0, void 0, (name) => !name.startsWith(".") && name !== "solcInputs");
84
+ } catch (e) {
85
+ return { deployments: {} };
86
+ }
87
+ let chainId;
88
+ if (filesStats.length > 0) {
89
+ const chainIdFilepath = path2.join(deployPath, ".chainId");
90
+ if (fs2.existsSync(chainIdFilepath)) {
91
+ chainId = fs2.readFileSync(chainIdFilepath).toString().trim();
92
+ } else {
93
+ throw new Error(`A .chainId' file is expected to be present in the deployment folder for network ${subPath}`);
94
+ }
95
+ if (expectedChainId) {
96
+ if (expectedChainId !== chainId) {
97
+ throw new Error(
98
+ `Loading deployment in folder '${deployPath}' (with chainId: ${chainId}) for a different chainId (${expectedChainId})`
99
+ );
100
+ }
101
+ }
102
+ } else {
103
+ return { deployments: {} };
104
+ }
105
+ let fileNames = filesStats.map((a) => a.relativePath);
106
+ fileNames = fileNames.sort((a, b) => {
107
+ if (a < b) {
108
+ return -1;
109
+ }
110
+ if (a > b) {
111
+ return 1;
112
+ }
113
+ return 0;
114
+ });
115
+ for (const fileName of fileNames) {
116
+ if (fileName.substring(fileName.length - 5) === ".json") {
117
+ const deploymentFileName = path2.join(deployPath, fileName);
118
+ let deployment = JSON.parse(fs2.readFileSync(deploymentFileName).toString());
119
+ if (onlyABIAndAddress) {
120
+ deployment = {
121
+ address: deployment.address,
122
+ abi: deployment.abi,
123
+ linkedData: deployment.linkedData
124
+ };
125
+ }
126
+ const name = fileName.slice(0, fileName.length - 5);
127
+ deploymentsFound[name] = deployment;
128
+ }
129
+ }
130
+ return { deployments: deploymentsFound, chainId };
131
+ }
132
+
133
+ // src/internal/logging.ts
134
+ import { logs } from "named-logs";
135
+ import { hookup, logs as Logging } from "named-logs-console";
136
+ hookup();
137
+ function setLogLevel(level) {
138
+ Logging.level = level;
139
+ if (Logging.level > 0) {
140
+ Logging.enable();
141
+ } else {
142
+ Logging.disable();
143
+ }
144
+ }
145
+ var logger = logs("rocketh");
146
+ var voidSpinner = {
147
+ start(msg) {
148
+ if (msg) {
149
+ console.log(msg);
150
+ }
151
+ return this;
152
+ },
153
+ stop() {
154
+ return this;
155
+ },
156
+ succeed(msg) {
157
+ if (msg) {
158
+ console.log(msg);
159
+ }
160
+ return this;
161
+ },
162
+ fail(msg) {
163
+ if (msg) {
164
+ console.error(msg);
165
+ }
166
+ return this;
167
+ }
168
+ };
169
+ var lastSpin = voidSpinner;
170
+ function spin(message) {
171
+ if (Logging.level > 0) {
172
+ lastSpin = lastSpin.start(message);
173
+ return lastSpin;
174
+ } else {
175
+ return voidSpinner;
176
+ }
177
+ }
178
+
179
+ // src/environment/index.ts
180
+ globalThis.extensions = [];
181
+ function extendEnvironment(extension) {
182
+ globalThis.extensions.push(extension);
183
+ }
184
+ globalThis.signerProtocols = {};
185
+ function handleSignerProtocol(protocol, getSigner) {
186
+ globalThis.signerProtocols[protocol] = {
187
+ getSigner
188
+ };
189
+ }
190
+ function wait(numSeconds) {
191
+ return new Promise((resolve) => {
192
+ setTimeout(resolve, numSeconds * 1e3);
193
+ });
194
+ }
195
+ function displayTransaction(transaction) {
196
+ if (transaction.type === "0x2") {
197
+ return `(maxFeePerGas: ${BigInt(transaction.maxFeePerGas).toString()}, maxPriorityFeePerGas: ${BigInt(
198
+ transaction.maxPriorityFeePerGas
199
+ ).toString()})`;
200
+ } else {
201
+ return `(gasPrice: ${BigInt(transaction.gasPrice).toString()})`;
202
+ }
203
+ }
204
+ async function createEnvironment(config, providedContext) {
205
+ const provider = "provider" in config ? config.provider : new JSONRPCHTTPProvider(config.nodeUrl);
206
+ const transport = custom(provider);
207
+ const viemClient = createPublicClient({ transport });
208
+ const chainId = (await viemClient.getChainId()).toString();
209
+ let networkName;
210
+ let saveDeployments;
211
+ let tags = {};
212
+ if ("nodeUrl" in config) {
213
+ networkName = config.networkName;
214
+ saveDeployments = true;
215
+ } else {
216
+ if (config.networkName) {
217
+ networkName = config.networkName;
218
+ } else {
219
+ networkName = "memory";
220
+ }
221
+ if (networkName === "memory" || networkName === "hardhat") {
222
+ tags["memory"] = true;
223
+ saveDeployments = false;
224
+ } else {
225
+ saveDeployments = true;
226
+ }
227
+ }
228
+ const resolvedAccounts = {};
229
+ const accountCache = {};
230
+ async function getAccount(name, accounts, accountDef) {
231
+ if (accountCache[name]) {
232
+ return accountCache[name];
233
+ }
234
+ let account;
235
+ if (typeof accountDef === "number") {
236
+ const accounts2 = await provider.request({ method: "eth_accounts" });
237
+ const accountPerIndex = accounts2[accountDef];
238
+ if (accountPerIndex) {
239
+ accountCache[name] = account = {
240
+ type: "remote",
241
+ address: accountPerIndex,
242
+ signer: provider
243
+ };
244
+ }
245
+ } else if (typeof accountDef === "string") {
246
+ if (accountDef.startsWith("0x")) {
247
+ if (accountDef.length === 66) {
248
+ const privateKeyProtocol = globalThis.signerProtocols["privateKey"];
249
+ if (privateKeyProtocol) {
250
+ const namedSigner = await privateKeyProtocol.getSigner(`privateKey:${accountDef}`);
251
+ const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
252
+ accountCache[name] = account = {
253
+ ...namedSigner,
254
+ address
255
+ };
256
+ }
257
+ } else {
258
+ accountCache[name] = account = {
259
+ type: "remote",
260
+ address: accountDef,
261
+ signer: provider
262
+ };
263
+ }
264
+ } else {
265
+ if (accountDef.indexOf(":") > 0) {
266
+ const [protocolID, extra] = accountDef.split(":");
267
+ const protocol = globalThis.signerProtocols[protocolID];
268
+ if (!protocol) {
269
+ throw new Error(`protocol: ${protocol} is not supported`);
270
+ }
271
+ const namedSigner = await protocol.getSigner(accountDef);
272
+ const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
273
+ accountCache[name] = account = {
274
+ ...namedSigner,
275
+ address
276
+ };
277
+ } else {
278
+ const accountFetched = await getAccount(name, accounts, accounts[accountDef]);
279
+ if (accountFetched) {
280
+ accountCache[name] = account = accountFetched;
281
+ }
282
+ }
283
+ }
284
+ } else {
285
+ const accountForNetwork = accountDef[networkName] || accountDef[chainId] || accountDef["default"];
286
+ if (typeof accountForNetwork !== void 0) {
287
+ const accountFetched = await getAccount(name, accounts, accountForNetwork);
288
+ if (accountFetched) {
289
+ accountCache[name] = account = accountFetched;
290
+ }
291
+ }
292
+ }
293
+ return account;
294
+ }
295
+ if (providedContext.accounts) {
296
+ const accountNames = Object.keys(providedContext.accounts);
297
+ for (const accountName of accountNames) {
298
+ let account = await getAccount(accountName, providedContext.accounts, providedContext.accounts[accountName]);
299
+ resolvedAccounts[accountName] = account;
300
+ }
301
+ }
302
+ const context = {
303
+ accounts: resolvedAccounts,
304
+ artifacts: providedContext.artifacts,
305
+ network: {
306
+ name: networkName,
307
+ saveDeployments,
308
+ tags
309
+ }
310
+ };
311
+ const { deployments } = loadDeployments(config.deployments, context.network.name, false, chainId);
312
+ const namedAccounts = {};
313
+ const namedSigners = {};
314
+ const addressSigners = {};
315
+ for (const entry of Object.entries(resolvedAccounts)) {
316
+ const name = entry[0];
317
+ const { address, ...namedSigner } = entry[1];
318
+ namedAccounts[name] = address;
319
+ addressSigners[address] = namedSigner;
320
+ namedSigners[name] = namedSigner;
321
+ }
322
+ const perliminaryEnvironment = {
323
+ config,
324
+ deployments,
325
+ accounts: namedAccounts,
326
+ signers: namedSigners,
327
+ addressSigners,
328
+ artifacts: context.artifacts,
329
+ network: {
330
+ chainId,
331
+ name: context.network.name,
332
+ tags: context.network.tags,
333
+ provider
334
+ }
335
+ };
336
+ function ensureDeploymentFolder() {
337
+ const folderPath = path3.join(config.deployments, context.network.name);
338
+ fs3.mkdirSync(folderPath, { recursive: true });
339
+ const chainIdFilepath = path3.join(folderPath, ".chainId");
340
+ if (!fs3.existsSync(chainIdFilepath)) {
341
+ fs3.writeFileSync(chainIdFilepath, chainId);
342
+ }
343
+ return folderPath;
344
+ }
345
+ function get(name) {
346
+ return deployments[name];
347
+ }
348
+ async function save(name, deployment) {
349
+ deployments[name] = deployment;
350
+ if (context.network.saveDeployments) {
351
+ const folderPath = ensureDeploymentFolder();
352
+ fs3.writeFileSync(`${folderPath}/${name}.json`, JSONToString(deployment, 2));
353
+ }
354
+ return deployment;
355
+ }
356
+ async function recoverTransactionsIfAny() {
357
+ const folderPath = ensureDeploymentFolder();
358
+ const filepath = path3.join(folderPath, ".pending_transactions.json");
359
+ let existingPendingTansactions;
360
+ try {
361
+ existingPendingTansactions = stringToJSON(fs3.readFileSync(filepath, "utf-8"));
362
+ } catch {
363
+ existingPendingTansactions = [];
364
+ }
365
+ if (existingPendingTansactions.length > 0) {
366
+ while (existingPendingTansactions.length > 0) {
367
+ const pendingTransaction = existingPendingTansactions.shift();
368
+ if (pendingTransaction) {
369
+ if (pendingTransaction.type === "deployment") {
370
+ const spinner = spin(`recovering ${pendingTransaction.name} with transaction ${pendingTransaction.txHash}`);
371
+ try {
372
+ await waitForDeploymentTransactionAndSave(pendingTransaction);
373
+ fs3.writeFileSync(filepath, JSONToString(existingPendingTansactions, 2));
374
+ spinner.succeed();
375
+ } catch (e) {
376
+ spinner.fail();
377
+ throw e;
378
+ }
379
+ } else {
380
+ const spinner = spin(`recovering execution's transaction ${pendingTransaction.txHash}`);
381
+ try {
382
+ await waitForTransaction(pendingTransaction.txHash);
383
+ fs3.writeFileSync(filepath, JSONToString(existingPendingTansactions, 2));
384
+ spinner.succeed();
385
+ } catch (e) {
386
+ spinner.fail();
387
+ throw e;
388
+ }
389
+ }
390
+ }
391
+ }
392
+ fs3.rmSync(filepath);
393
+ }
394
+ }
395
+ async function savePendingTransaction(pendingTransaction) {
396
+ if (context.network.saveDeployments) {
397
+ const folderPath = ensureDeploymentFolder();
398
+ const filepath = path3.join(folderPath, ".pending_transactions.json");
399
+ let existingPendinTransactions;
400
+ try {
401
+ existingPendinTransactions = stringToJSON(fs3.readFileSync(filepath, "utf-8"));
402
+ } catch {
403
+ existingPendinTransactions = [];
404
+ }
405
+ existingPendinTransactions.push(pendingTransaction);
406
+ fs3.writeFileSync(filepath, JSONToString(existingPendinTransactions, 2));
407
+ }
408
+ return deployments;
409
+ }
410
+ async function waitForTransactionReceipt(params) {
411
+ const { hash, pollingInterval } = { pollingInterval: 1, ...params };
412
+ let receipt = await provider.request({
413
+ method: "eth_getTransactionReceipt",
414
+ params: [hash]
415
+ });
416
+ if (!receipt || !receipt.blockHash) {
417
+ await wait(pollingInterval);
418
+ return waitForTransactionReceipt(params);
419
+ }
420
+ return receipt;
421
+ }
422
+ async function deleteTransaction(hash) {
423
+ if (context.network.saveDeployments) {
424
+ const folderPath = ensureDeploymentFolder();
425
+ const filepath = path3.join(folderPath, ".pending_transactions.json");
426
+ let existingPendinTransactions;
427
+ try {
428
+ existingPendinTransactions = stringToJSON(fs3.readFileSync(filepath, "utf-8"));
429
+ } catch {
430
+ existingPendinTransactions = [];
431
+ }
432
+ existingPendinTransactions = existingPendinTransactions.filter((v) => v.txHash !== hash);
433
+ if (existingPendinTransactions.length === 0) {
434
+ fs3.rmSync(filepath);
435
+ } else {
436
+ fs3.writeFileSync(filepath, JSONToString(existingPendinTransactions, 2));
437
+ }
438
+ }
439
+ }
440
+ async function exportDeploymentsAsTypes() {
441
+ const folderPath = "./generated";
442
+ fs3.mkdirSync(folderPath, { recursive: true });
443
+ fs3.writeFileSync(`${folderPath}/deployments.ts`, `export default ${JSONToString(deployments, 2)} as const;`);
444
+ }
445
+ async function waitForTransaction(hash, message) {
446
+ const spinner = spin(message || "");
447
+ let receipt;
448
+ try {
449
+ receipt = await waitForTransactionReceipt({
450
+ hash
451
+ });
452
+ } catch (e) {
453
+ spinner.fail();
454
+ throw e;
455
+ }
456
+ if (!receipt) {
457
+ throw new Error(`receipt for ${hash} not found`);
458
+ } else {
459
+ spinner.succeed();
460
+ }
461
+ return receipt;
462
+ }
463
+ async function waitForDeploymentTransactionAndSave(pendingDeployment, transaction) {
464
+ const message = ` - Deploying ${pendingDeployment.name} with tx:
465
+ ${pendingDeployment.txHash}${transaction ? `
466
+ ${displayTransaction(transaction)}` : ""}`;
467
+ const receipt = await waitForTransaction(pendingDeployment.txHash, message);
468
+ if (!receipt.contractAddress) {
469
+ throw new Error(`failed to deploy contract ${pendingDeployment.name}`);
470
+ }
471
+ const { abi, ...artifactObjectWithoutABI } = pendingDeployment.partialDeployment;
472
+ if (!artifactObjectWithoutABI.nonce) {
473
+ const spinner = spin();
474
+ let transaction2 = null;
475
+ try {
476
+ transaction2 = await provider.request({
477
+ method: "eth_getTransactionByHash",
478
+ params: [pendingDeployment.txHash]
479
+ });
480
+ } catch (e) {
481
+ spinner.fail();
482
+ throw e;
483
+ }
484
+ if (!transaction2) {
485
+ spinner.fail(`tx ${pendingDeployment.txHash} not found`);
486
+ } else {
487
+ spinner.stop();
488
+ }
489
+ if (transaction2) {
490
+ artifactObjectWithoutABI.nonce = transaction2.nonce;
491
+ artifactObjectWithoutABI.txOrigin = transaction2.from;
492
+ }
493
+ }
494
+ for (const key of Object.keys(artifactObjectWithoutABI)) {
495
+ if (key.startsWith("_")) {
496
+ delete artifactObjectWithoutABI[key];
497
+ }
498
+ if (key === "evm") {
499
+ const { gasEstimates } = artifactObjectWithoutABI.evm;
500
+ artifactObjectWithoutABI.evm = {
501
+ gasEstimates
502
+ };
503
+ }
504
+ }
505
+ const deployment = {
506
+ address: receipt.contractAddress,
507
+ txHash: pendingDeployment.txHash,
508
+ abi,
509
+ ...artifactObjectWithoutABI
510
+ };
511
+ return save(pendingDeployment.name, deployment);
512
+ }
513
+ async function savePendingExecution(pendingExecution) {
514
+ await savePendingTransaction(pendingExecution);
515
+ let transaction = null;
516
+ const spinner = spin();
517
+ try {
518
+ transaction = await provider.request({
519
+ method: "eth_getTransactionByHash",
520
+ params: [pendingExecution.txHash]
521
+ });
522
+ } catch (e) {
523
+ spinner.fail();
524
+ throw e;
525
+ }
526
+ if (!transaction) {
527
+ spinner.fail(`tx ${pendingExecution.txHash} not found`);
528
+ } else {
529
+ spinner.stop();
530
+ }
531
+ if (transaction) {
532
+ pendingExecution.nonce = transaction.nonce;
533
+ pendingExecution.txOrigin = transaction.from;
534
+ }
535
+ const receipt = await waitForTransaction(pendingExecution.txHash);
536
+ await deleteTransaction(pendingExecution.txHash);
537
+ return receipt;
538
+ }
539
+ async function savePendingDeployment(pendingDeployment) {
540
+ await savePendingTransaction(pendingDeployment);
541
+ let transaction = null;
542
+ const spinner = spin();
543
+ try {
544
+ transaction = await provider.request({
545
+ method: "eth_getTransactionByHash",
546
+ params: [pendingDeployment.txHash]
547
+ });
548
+ } catch (e) {
549
+ spinner.fail();
550
+ throw e;
551
+ }
552
+ if (!transaction) {
553
+ spinner.fail(`tx ${pendingDeployment.txHash} not found`);
554
+ } else {
555
+ spinner.stop();
556
+ }
557
+ if (transaction) {
558
+ pendingDeployment.nonce = transaction.nonce;
559
+ pendingDeployment.txOrigin = transaction.from;
560
+ }
561
+ const deployment = await waitForDeploymentTransactionAndSave(pendingDeployment);
562
+ await deleteTransaction(pendingDeployment.txHash);
563
+ return deployment;
564
+ }
565
+ let env = {
566
+ ...perliminaryEnvironment,
567
+ save,
568
+ savePendingDeployment,
569
+ savePendingExecution,
570
+ get
571
+ };
572
+ for (const extension of globalThis.extensions) {
573
+ env = extension(env);
574
+ }
575
+ return {
576
+ external: env,
577
+ internal: {
578
+ exportDeploymentsAsTypes,
579
+ recoverTransactionsIfAny
580
+ }
581
+ };
582
+ }
583
+
584
+ // src/executor/index.ts
585
+ __require("esbuild-register/dist/node").register();
586
+ function execute(context, callback, options) {
587
+ const scriptModule = (env) => callback(env);
588
+ scriptModule.providedContext = context;
589
+ scriptModule.tags = options.tags;
590
+ scriptModule.dependencies = options.dependencies;
591
+ return scriptModule;
592
+ }
593
+ function readConfig(options, extra) {
594
+ let configFile;
595
+ try {
596
+ const configString = fs4.readFileSync("./rocketh.json", "utf-8");
597
+ configFile = JSON.parse(configString);
598
+ } catch {
599
+ }
600
+ let nodeUrl;
601
+ const fromEnv = process.env["ETH_NODE_URI_" + options.network];
602
+ if (typeof fromEnv === "string") {
603
+ nodeUrl = fromEnv;
604
+ } else {
605
+ if (configFile) {
606
+ const network = configFile.networks && configFile.networks[options.network];
607
+ if (network) {
608
+ nodeUrl = network.rpcUrl;
609
+ } else {
610
+ if (extra?.ignoreMissingRPC) {
611
+ nodeUrl = "";
612
+ } else {
613
+ if (options.network === "localhost") {
614
+ nodeUrl = "http://127.0.0.1:8545";
615
+ } else {
616
+ logger.error(`network "${options.network}" is not configured. Please add it to the rocketh.json file`);
617
+ process.exit(1);
618
+ }
619
+ }
620
+ }
621
+ } else {
622
+ if (extra?.ignoreMissingRPC) {
623
+ nodeUrl = "";
624
+ } else {
625
+ if (options.network === "localhost") {
626
+ nodeUrl = "http://127.0.0.1:8545";
627
+ } else {
628
+ logger.error(`network "${options.network}" is not configured. Please add it to the rocketh.json file`);
629
+ process.exit(1);
630
+ }
631
+ }
632
+ }
633
+ }
634
+ return {
635
+ nodeUrl,
636
+ networkName: options.network,
637
+ deployments: options.deployments,
638
+ scripts: options.scripts,
639
+ tags: typeof options.tags === "undefined" ? void 0 : options.tags.split(",")
640
+ };
641
+ }
642
+ function readAndResolveConfig(options, extra) {
643
+ return resolveConfig(readConfig(options, extra));
644
+ }
645
+ function resolveConfig(config) {
646
+ const resolvedConfig = {
647
+ ...config,
648
+ networkName: config.networkName || "memory",
649
+ deployments: config.deployments || "deployments",
650
+ scripts: config.scripts || "deploy",
651
+ tags: config.tags || []
652
+ };
653
+ return resolvedConfig;
654
+ }
655
+ async function loadAndExecuteDeployments(config) {
656
+ const resolvedConfig = resolveConfig(config);
657
+ return executeDeployScripts(resolvedConfig);
658
+ }
659
+ async function executeDeployScripts(config) {
660
+ setLogLevel(typeof config.logLevel === "undefined" ? 0 : config.logLevel);
661
+ let filepaths;
662
+ filepaths = traverseMultipleDirectory([config.scripts]);
663
+ filepaths = filepaths.filter((v) => !path4.basename(v).startsWith("_")).sort((a, b) => {
664
+ if (a < b) {
665
+ return -1;
666
+ }
667
+ if (a > b) {
668
+ return 1;
669
+ }
670
+ return 0;
671
+ });
672
+ let providedContext;
673
+ const scriptModuleByFilePath = {};
674
+ const scriptPathBags = {};
675
+ const scriptFilePaths = [];
676
+ for (const filepath of filepaths) {
677
+ const scriptFilePath = path4.resolve(filepath);
678
+ let scriptModule;
679
+ try {
680
+ if (__require.cache) {
681
+ delete __require.cache[scriptFilePath];
682
+ }
683
+ scriptModule = __require(scriptFilePath);
684
+ if (scriptModule.default) {
685
+ scriptModule = scriptModule.default;
686
+ if (scriptModule.default) {
687
+ logger.warn(`double default...`);
688
+ scriptModule = scriptModule.default;
689
+ }
690
+ }
691
+ scriptModuleByFilePath[scriptFilePath] = scriptModule;
692
+ if (providedContext && providedContext !== scriptModule.providedContext) {
693
+ throw new Error(`context between 2 scripts is different, please share the same across them`);
694
+ }
695
+ providedContext = scriptModule.providedContext;
696
+ } catch (e) {
697
+ logger.error(`could not import ${filepath}`);
698
+ throw e;
699
+ }
700
+ let scriptTags = scriptModule.tags;
701
+ if (scriptTags !== void 0) {
702
+ if (typeof scriptTags === "string") {
703
+ scriptTags = [scriptTags];
704
+ }
705
+ for (const tag of scriptTags) {
706
+ if (tag.indexOf(",") >= 0) {
707
+ throw new Error("Tag cannot contains commas");
708
+ }
709
+ const bag = scriptPathBags[tag] || [];
710
+ scriptPathBags[tag] = bag;
711
+ bag.push(scriptFilePath);
712
+ }
713
+ }
714
+ if (config.tags !== void 0 && config.tags.length > 0) {
715
+ let found = false;
716
+ if (scriptTags !== void 0) {
717
+ for (const tagToFind of config.tags) {
718
+ for (const tag of scriptTags) {
719
+ if (tag === tagToFind) {
720
+ scriptFilePaths.push(scriptFilePath);
721
+ found = true;
722
+ break;
723
+ }
724
+ }
725
+ if (found) {
726
+ break;
727
+ }
728
+ }
729
+ }
730
+ } else {
731
+ scriptFilePaths.push(scriptFilePath);
732
+ }
733
+ }
734
+ if (!providedContext) {
735
+ throw new Error(`no context loaded`);
736
+ }
737
+ const { internal, external } = await createEnvironment(config, providedContext);
738
+ await internal.recoverTransactionsIfAny();
739
+ const scriptsRegisteredToRun = {};
740
+ const scriptsToRun = [];
741
+ const scriptsToRunAtTheEnd = [];
742
+ function recurseDependencies(scriptFilePath) {
743
+ if (scriptsRegisteredToRun[scriptFilePath]) {
744
+ return;
745
+ }
746
+ const scriptModule = scriptModuleByFilePath[scriptFilePath];
747
+ if (scriptModule.dependencies) {
748
+ for (const dependency of scriptModule.dependencies) {
749
+ const scriptFilePathsToAdd = scriptPathBags[dependency];
750
+ if (scriptFilePathsToAdd) {
751
+ for (const scriptFilenameToAdd of scriptFilePathsToAdd) {
752
+ recurseDependencies(scriptFilenameToAdd);
753
+ }
754
+ }
755
+ }
756
+ }
757
+ if (!scriptsRegisteredToRun[scriptFilePath]) {
758
+ if (scriptModule.runAtTheEnd) {
759
+ scriptsToRunAtTheEnd.push({
760
+ filePath: scriptFilePath,
761
+ func: scriptModule
762
+ });
763
+ } else {
764
+ scriptsToRun.push({
765
+ filePath: scriptFilePath,
766
+ func: scriptModule
767
+ });
768
+ }
769
+ scriptsRegisteredToRun[scriptFilePath] = true;
770
+ }
771
+ }
772
+ for (const scriptFilePath of scriptFilePaths) {
773
+ recurseDependencies(scriptFilePath);
774
+ }
775
+ for (const deployScript of scriptsToRun.concat(scriptsToRunAtTheEnd)) {
776
+ const filename = path4.basename(deployScript.filePath);
777
+ const relativeFilepath = path4.relative(".", deployScript.filePath);
778
+ let skip = false;
779
+ const spinner = spin(`- Executing ${filename}`);
780
+ if (deployScript.func.skip) {
781
+ const spinner2 = spin(` - skip?()`);
782
+ try {
783
+ skip = await deployScript.func.skip(external);
784
+ spinner2.succeed(skip ? `skipping ${filename}` : void 0);
785
+ } catch (e) {
786
+ spinner2.fail();
787
+ throw e;
788
+ }
789
+ }
790
+ if (!skip) {
791
+ let result;
792
+ try {
793
+ result = await deployScript.func(external);
794
+ spinner.succeed(`
795
+ `);
796
+ } catch (e) {
797
+ spinner.fail();
798
+ throw e;
799
+ }
800
+ if (result && typeof result === "boolean") {
801
+ const deploymentFolderPath = config.deployments;
802
+ }
803
+ }
804
+ }
805
+ return external.deployments;
806
+ }
807
+
808
+ export {
809
+ loadDeployments,
810
+ extendEnvironment,
811
+ handleSignerProtocol,
812
+ execute,
813
+ readConfig,
814
+ readAndResolveConfig,
815
+ resolveConfig,
816
+ loadAndExecuteDeployments,
817
+ executeDeployScripts
818
+ };
819
+ //# sourceMappingURL=chunk-TSZHO6IV.js.map