rocketh 0.5.11 → 0.5.13

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