rocketh 0.10.7 → 0.10.9

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.
package/dist/cli.cjs CHANGED
@@ -1,1355 +1,99 @@
1
- #! /usr/bin/env node
2
- "use strict";
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ var ldenv = require('ldenv');
5
+ var index = require('./index-BJlVmvtt.cjs');
6
+ require('node:path');
7
+ require('node:fs');
8
+ require('ethers');
9
+ var commander = require('commander');
10
+ require('module');
11
+ require('viem');
12
+ require('eip-1193-jsonrpc-provider');
13
+ require('named-logs');
14
+ require('named-logs-console');
15
+ require('viem/chains');
16
+ require('prompts');
17
+
18
+ var name = "rocketh";
19
+ var version = "0.10.8";
20
+ var description = "deploy smart contract on ethereum-compatible networks";
21
+ var publishConfig = {
22
+ access: "public"
16
23
  };
17
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
18
- // If the importer is in node compatibility mode or this is not an ESM
19
- // file that has been converted to a CommonJS file using a Babel-
20
- // compatible transform (i.e. "__esModule" has not been set), then set
21
- // "default" to the CommonJS "module.exports" for node compatibility.
22
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
23
- mod
24
- ));
25
-
26
- // src/cli.ts
27
- var import_ldenv = require("ldenv");
28
-
29
- // src/utils/fs.ts
30
- var import_node_fs = __toESM(require("fs"), 1);
31
- var import_node_path = __toESM(require("path"), 1);
32
- function traverseMultipleDirectory(dirs) {
33
- const filepaths = [];
34
- for (const dir of dirs) {
35
- let filesStats = traverse(dir);
36
- filesStats = filesStats.filter((v) => !v.directory);
37
- for (const filestat of filesStats) {
38
- filepaths.push(import_node_path.default.join(dir, filestat.relativePath));
39
- }
40
- }
41
- return filepaths;
42
- }
43
- var traverse = function(dir, result = [], topDir, filter) {
44
- import_node_fs.default.readdirSync(dir).forEach((name) => {
45
- const fPath = import_node_path.default.resolve(dir, name);
46
- const stats = import_node_fs.default.statSync(fPath);
47
- if (!filter && !name.startsWith(".") || filter && filter(name, stats)) {
48
- const fileStats = {
49
- name,
50
- path: fPath,
51
- relativePath: import_node_path.default.relative(topDir || dir, fPath),
52
- mtimeMs: stats.mtimeMs,
53
- directory: stats.isDirectory()
54
- };
55
- if (fileStats.directory) {
56
- result.push(fileStats);
57
- return traverse(fPath, result, topDir || dir, filter);
58
- }
59
- result.push(fileStats);
60
- }
61
- });
62
- return result;
24
+ var type = "module";
25
+ var main = "dist/index.cjs";
26
+ var module$1 = "dist/index.mjs";
27
+ var types = "dist/index.d.ts";
28
+ var bin = {
29
+ rocketh: "dist/cli.cjs"
63
30
  };
64
-
65
- // src/executor/index.ts
66
- var import_node_path4 = __toESM(require("path"), 1);
67
- var import_node_fs4 = __toESM(require("fs"), 1);
68
-
69
- // src/environment/index.ts
70
- var import_node_fs3 = __toESM(require("fs"), 1);
71
- var import_viem = require("viem");
72
- var import_eip_1193_jsonrpc_provider = require("eip-1193-jsonrpc-provider");
73
- var import_node_path3 = __toESM(require("path"), 1);
74
-
75
- // src/utils/json.ts
76
- function bnReplacer(k, v) {
77
- if (typeof v === "bigint") {
78
- return v.toString() + "n";
79
- }
80
- return v;
81
- }
82
- function bnReviver(k, v) {
83
- if (typeof v === "string" && (v.startsWith("-") ? !isNaN(parseInt(v.charAt(1))) : !isNaN(parseInt(v.charAt(0)))) && v.charAt(v.length - 1) === "n") {
84
- return BigInt(v.slice(0, -1));
85
- }
86
- return v;
87
- }
88
- function JSONToString(json, space) {
89
- return JSON.stringify(json, bnReplacer, space);
90
- }
91
- function stringToJSON(str) {
92
- return JSON.parse(str, bnReviver);
93
- }
94
-
95
- // src/environment/deployments.ts
96
- var import_node_path2 = __toESM(require("path"), 1);
97
- var import_node_fs2 = __toESM(require("fs"), 1);
98
- function loadDeployments(deploymentsPath, networkName, onlyABIAndAddress, expectedChain) {
99
- const deploymentsFound = {};
100
- const deployPath = import_node_path2.default.join(deploymentsPath, networkName);
101
- let filesStats;
102
- try {
103
- filesStats = traverse(deployPath, void 0, void 0, (name) => !name.startsWith(".") && name !== "solcInputs");
104
- } catch (e) {
105
- return { deployments: {} };
106
- }
107
- let chainId;
108
- let genesisHash;
109
- if (filesStats.length > 0) {
110
- const chainIdFilepath = import_node_path2.default.join(deployPath, ".chainId");
111
- if (import_node_fs2.default.existsSync(chainIdFilepath)) {
112
- chainId = import_node_fs2.default.readFileSync(chainIdFilepath, "utf-8").trim();
113
- } else {
114
- const chainFilepath = import_node_path2.default.join(deployPath, ".chain");
115
- if (import_node_fs2.default.existsSync(chainFilepath)) {
116
- const chainSTR = import_node_fs2.default.readFileSync(chainFilepath, "utf-8");
117
- const chainData = JSON.parse(chainSTR);
118
- chainId = chainData.chainId;
119
- genesisHash = chainData.genesisHash;
120
- } else {
121
- throw new Error(
122
- `A '.chain' or '.chainId' file is expected to be present in the deployment folder for network ${networkName}`
123
- );
124
- }
125
- }
126
- if (expectedChain) {
127
- if (expectedChain.chainId !== chainId) {
128
- throw new Error(
129
- `Loading deployment in folder '${deployPath}' (with chainId: ${chainId}) for a different chainId (${expectedChain.chainId})`
130
- );
131
- }
132
- if (expectedChain.genesisHash && expectedChain.genesisHash !== genesisHash) {
133
- if (expectedChain.deleteDeploymentsIfDifferentGenesisHash) {
134
- import_node_fs2.default.rmSync(deployPath, { recursive: true, force: true });
135
- return { deployments: {} };
136
- } else {
137
- throw new Error(
138
- `Loading deployment in folder '${deployPath}' (with genesisHash: ${genesisHash}) for a different genesisHash (${expectedChain.genesisHash})`
139
- );
140
- }
141
- }
142
- }
143
- } else {
144
- return { deployments: {} };
145
- }
146
- let fileNames = filesStats.map((a) => a.relativePath);
147
- fileNames = fileNames.sort((a, b) => {
148
- if (a < b) {
149
- return -1;
150
- }
151
- if (a > b) {
152
- return 1;
153
- }
154
- return 0;
155
- });
156
- for (const fileName of fileNames) {
157
- if (fileName.substring(fileName.length - 5) === ".json") {
158
- const deploymentFileName = import_node_path2.default.join(deployPath, fileName);
159
- let deployment = JSON.parse(import_node_fs2.default.readFileSync(deploymentFileName).toString());
160
- if (onlyABIAndAddress) {
161
- deployment = {
162
- address: deployment.address,
163
- abi: deployment.abi,
164
- linkedData: deployment.linkedData
165
- };
166
- }
167
- const name = fileName.slice(0, fileName.length - 5);
168
- deploymentsFound[name] = deployment;
169
- }
170
- }
171
- return { deployments: deploymentsFound, chainId, genesisHash };
172
- }
173
-
174
- // src/internal/logging.ts
175
- var import_named_logs = require("named-logs");
176
- var import_named_logs_console = require("named-logs-console");
177
- (0, import_named_logs_console.hookup)();
178
- function setLogLevel(level) {
179
- import_named_logs_console.factory.level = level;
180
- if (import_named_logs_console.factory.level > 0) {
181
- import_named_logs_console.factory.enable();
182
- } else {
183
- import_named_logs_console.factory.disable();
184
- }
185
- }
186
- var logger = (0, import_named_logs.logs)("rocketh");
187
- var loggerProgressIndicator = {
188
- start(msg) {
189
- if (msg) {
190
- console.log(msg);
191
- }
192
- return this;
193
- },
194
- stop() {
195
- return this;
196
- },
197
- succeed(msg) {
198
- if (msg) {
199
- console.log(msg);
200
- }
201
- return this;
202
- },
203
- fail(msg) {
204
- if (msg) {
205
- console.error(msg);
206
- }
207
- return this;
208
- }
31
+ var devDependencies = {
32
+ "@types/node": "^20.12.7",
33
+ abitype: "^1.0.2",
34
+ "eip-1193": "^0.5.0",
35
+ "ipfs-gateway-emulator": "4.2.1-ipfs.2",
36
+ pkgroll: "^2.0.2",
37
+ rimraf: "^5.0.5",
38
+ typedoc: "^0.25.13",
39
+ typescript: "^5.4.5"
209
40
  };
210
- var voidProgressIndicator = {
211
- start() {
212
- return this;
213
- },
214
- stop() {
215
- return this;
216
- },
217
- succeed() {
218
- return this;
219
- },
220
- fail() {
221
- return this;
222
- }
41
+ var dependencies = {
42
+ "@types/figlet": "^1.5.8",
43
+ "@types/prompts": "^2.4.9",
44
+ commander: "^12.0.0",
45
+ "eip-1193-jsonrpc-provider": "^0.3.0",
46
+ esbuild: "^0.20.2",
47
+ "esbuild-register": "^3.5.0",
48
+ ethers: "^6.11.1",
49
+ figlet: "^1.7.0",
50
+ ldenv: "^0.3.10",
51
+ "named-logs": "^0.2.4",
52
+ "named-logs-console": "^0.3.1",
53
+ prompts: "^2.4.2",
54
+ viem: "^2.9.16"
223
55
  };
224
- var lastSpin = loggerProgressIndicator;
225
- function spin(message) {
226
- if (import_named_logs_console.factory.level > 0) {
227
- lastSpin = lastSpin.start(message);
228
- return lastSpin;
229
- } else {
230
- return voidProgressIndicator;
231
- }
232
- }
233
- function log(message) {
234
- if (import_named_logs_console.factory.level > 0) {
235
- console.log(message);
236
- }
237
- }
238
-
239
- // src/environment/utils/chains.ts
240
- var import_chains = __toESM(require("viem/chains"), 1);
241
- var chainById = {};
242
- var allChains = import_chains.default.default || import_chains.default;
243
- for (const key of Object.keys(allChains)) {
244
- const chain = allChains[key];
245
- chainById[chain.id.toString()] = chain;
246
- }
247
- function getChain(id) {
248
- const chain = chainById[id];
249
- if (!chain) {
250
- return {
251
- id: parseInt(id),
252
- name: "unkwown",
253
- // TODO
254
- nativeCurrency: {
255
- name: "Unknown Currency",
256
- symbol: "UNKNOWN",
257
- decimals: 18
258
- },
259
- rpcUrls: {
260
- default: {
261
- http: []
262
- }
263
- }
264
- };
265
- }
266
- return chain;
267
- }
268
-
269
- // src/environment/utils/artifacts.ts
270
- var import_ethers = require("ethers");
271
- function deepEqual(obj1, obj2) {
272
- function isObject(obj) {
273
- if (typeof obj === "object" && obj != null) {
274
- return true;
275
- } else {
276
- return false;
277
- }
278
- }
279
- if (obj1 === obj2) {
280
- return true;
281
- } else if (isObject(obj1) && isObject(obj2)) {
282
- if (Object.keys(obj1).length !== Object.keys(obj2).length) {
283
- return false;
284
- }
285
- for (var prop in obj1) {
286
- if (!deepEqual(obj1[prop], obj2[prop])) {
287
- return false;
288
- }
289
- }
290
- return true;
291
- }
292
- return false;
293
- }
294
- function mergeDoc(values, mergedDevDocs, field) {
295
- if (values[field]) {
296
- const mergedEventDocs = mergedDevDocs[field] = mergedDevDocs[field] || {};
297
- for (const signature of Object.keys(values[field])) {
298
- if (mergedEventDocs[signature] && !deepEqual(mergedEventDocs[signature], values[field][signature])) {
299
- throw new Error(`Doc ${field} conflict: "${signature}" `);
300
- }
301
- mergedEventDocs[signature] = values[field][signature];
302
- }
303
- }
304
- }
305
- function mergeArtifacts(list) {
306
- const mergedABI = [];
307
- const added = /* @__PURE__ */ new Map();
308
- const mergedDevDocs = { kind: "dev", version: 1, methods: {} };
309
- const mergedUserDocs = { kind: "user", version: 1, methods: {} };
310
- const sigJSMap = /* @__PURE__ */ new Map();
311
- for (let i = 0; i < list.length; i++) {
312
- const listElem = list[i];
313
- for (const element of listElem.artifact.abi) {
314
- if (element.type === "function") {
315
- const selector = import_ethers.FunctionFragment.from(element).selector;
316
- if (sigJSMap.has(selector)) {
317
- const existing = sigJSMap.get(selector);
318
- throw new Error(
319
- `ABI conflict: ${existing.routeName} has function "${existing.functionName}" which conflict with ${listElem.name}'s "${element.name}" (selector: "${selector}") `
320
- );
321
- }
322
- sigJSMap.set(selector, { index: i, routeName: listElem.name, functionName: element.name });
323
- const exists = added.has(element.name);
324
- if (exists) {
325
- } else {
326
- added.set(element.name, element);
327
- mergedABI.push(element);
328
- }
329
- } else if (element.type === "constructor") {
330
- } else if (element.type === "error") {
331
- const exists = added.has(element.name);
332
- if (exists) {
333
- } else {
334
- added.set(element.name, element);
335
- mergedABI.push(element);
336
- }
337
- } else if (element.type === "event") {
338
- const exists = added.has(element.name);
339
- if (exists) {
340
- } else {
341
- added.set(element.name, element);
342
- mergedABI.push(element);
343
- }
344
- } else if (element.type === "fallback") {
345
- } else if (element.type === "receive") {
346
- } else {
347
- }
348
- }
349
- const devdoc = listElem.artifact.devdoc;
350
- if (devdoc) {
351
- mergeDoc(devdoc, mergedDevDocs, "events");
352
- mergeDoc(devdoc, mergedDevDocs, "errors");
353
- mergeDoc(devdoc, mergedDevDocs, "methods");
354
- if (devdoc.author) {
355
- if (mergedDevDocs.author && mergedDevDocs.author != devdoc.author) {
356
- throw new Error(`DevDoc author conflict `);
357
- }
358
- mergedDevDocs.author = devdoc.author;
359
- if (mergedDevDocs.title && mergedDevDocs.title != devdoc.title) {
360
- throw new Error(`DevDoc title conflict `);
361
- }
362
- mergedDevDocs.title = devdoc.title;
363
- }
364
- }
365
- const userdoc = listElem.artifact.userdoc;
366
- if (userdoc) {
367
- mergeDoc(userdoc, mergedUserDocs, "events");
368
- mergeDoc(userdoc, mergedUserDocs, "errors");
369
- mergeDoc(userdoc, mergedUserDocs, "methods");
370
- if (userdoc.notice) {
371
- if (mergedUserDocs.notice && mergedUserDocs.notice != userdoc.notice) {
372
- throw new Error(`UserDoc notice conflict `);
373
- }
374
- mergedUserDocs.notice = userdoc.notice;
375
- }
376
- }
377
- }
378
- return {
379
- mergedABI,
380
- added,
381
- mergedDevDocs,
382
- mergedUserDocs,
383
- sigJSMap
384
- };
385
- }
386
-
387
- // src/environment/providers/BaseProvider.ts
388
- var BaseProvider = class {
389
- constructor(provider) {
390
- this.provider = provider;
391
- }
392
- request(args) {
393
- return this._request(args);
394
- }
395
- };
396
-
397
- // src/environment/providers/TransactionHashTracker.ts
398
- var TransactionHashTracker = class extends BaseProvider {
399
- constructor(provider) {
400
- super(provider);
401
- this.transactionHashes = [];
402
- }
403
- async _request(args) {
404
- let response;
405
- try {
406
- response = await this.provider.request(args);
407
- } catch (err) {
408
- console.error(`failed to execute ${args.method}`, args);
409
- throw err;
410
- }
411
- if (args.method === "eth_sendRawTransaction" || args.method === "eth_sendTransaction") {
412
- this.transactionHashes.push(response);
413
- }
414
- return response;
415
- }
56
+ var scripts = {
57
+ build: "rimraf dist && pkgroll --sourcemap",
58
+ dev: "pkgroll --watch",
59
+ "gen-docs": "typedoc --out docs src",
60
+ "serve-docs": "ipfs-emulator --only -d docs -p 8080"
416
61
  };
417
-
418
- // src/environment/index.ts
419
- globalThis.extensions = [];
420
- globalThis.signerProtocols = {};
421
- function wait(numSeconds) {
422
- return new Promise((resolve) => {
423
- setTimeout(resolve, numSeconds * 1e3);
424
- });
425
- }
426
- function displayTransaction(transaction) {
427
- if (transaction.type === "0x2") {
428
- return `(maxFeePerGas: ${BigInt(transaction.maxFeePerGas).toString()}, maxPriorityFeePerGas: ${BigInt(
429
- transaction.maxPriorityFeePerGas
430
- ).toString()})`;
431
- } else {
432
- return `(gasPrice: ${BigInt(transaction.gasPrice).toString()})`;
433
- }
434
- }
435
- async function createEnvironment(config, providedContext) {
436
- const rawProvider = "provider" in config.network ? config.network.provider : new import_eip_1193_jsonrpc_provider.JSONRPCHTTPProvider(config.network.nodeUrl);
437
- const provider = new TransactionHashTracker(rawProvider);
438
- const transport = (0, import_viem.custom)(provider);
439
- const viemClient = (0, import_viem.createPublicClient)({ transport });
440
- const chainId = (await viemClient.getChainId()).toString();
441
- let genesisHash;
442
- try {
443
- genesisHash = (await viemClient.getBlock({ blockTag: "earliest" })).hash;
444
- } catch (err) {
445
- console.error(`failed to get genesis hash`);
446
- }
447
- let networkName;
448
- let saveDeployments;
449
- let networkTags = {};
450
- for (const networkTag of config.network.tags) {
451
- networkTags[networkTag] = true;
452
- }
453
- if ("nodeUrl" in config) {
454
- networkName = config.network.name;
455
- saveDeployments = true;
456
- } else {
457
- if (config.network.name) {
458
- networkName = config.network.name;
459
- } else {
460
- networkName = "memory";
461
- }
462
- if (networkName === "memory" || networkName === "hardhat") {
463
- networkTags["memory"] = true;
464
- saveDeployments = false;
465
- } else {
466
- saveDeployments = true;
467
- }
468
- }
469
- if (config.saveDeployments !== void 0) {
470
- saveDeployments = config.saveDeployments;
471
- }
472
- const resolvedAccounts = {};
473
- const accountCache = {};
474
- async function getAccount(name, accounts, accountDef) {
475
- if (accountCache[name]) {
476
- return accountCache[name];
477
- }
478
- let account;
479
- if (typeof accountDef === "number") {
480
- const accounts2 = await provider.request({ method: "eth_accounts" });
481
- const accountPerIndex = accounts2[accountDef];
482
- if (accountPerIndex) {
483
- accountCache[name] = account = {
484
- type: "remote",
485
- address: accountPerIndex,
486
- signer: provider
487
- };
488
- }
489
- } else if (typeof accountDef === "string") {
490
- if (accountDef.startsWith("0x")) {
491
- if (accountDef.length === 66) {
492
- const privateKeyProtocol = globalThis.signerProtocols["privateKey"];
493
- if (privateKeyProtocol) {
494
- const namedSigner = await privateKeyProtocol.getSigner(`privateKey:${accountDef}`);
495
- const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
496
- accountCache[name] = account = {
497
- ...namedSigner,
498
- address
499
- };
500
- }
501
- } else {
502
- accountCache[name] = account = {
503
- type: "remote",
504
- address: accountDef,
505
- signer: provider
506
- };
507
- }
508
- } else {
509
- if (accountDef.indexOf(":") > 0) {
510
- const [protocolID, extra] = accountDef.split(":");
511
- const protocol = globalThis.signerProtocols[protocolID];
512
- if (!protocol) {
513
- throw new Error(`protocol: ${protocol} is not supported`);
514
- }
515
- const namedSigner = await protocol.getSigner(accountDef);
516
- const [address] = await namedSigner.signer.request({ method: "eth_accounts" });
517
- accountCache[name] = account = {
518
- ...namedSigner,
519
- address
520
- };
521
- } else {
522
- const accountFetched = await getAccount(name, accounts, accounts[accountDef]);
523
- if (accountFetched) {
524
- accountCache[name] = account = accountFetched;
525
- }
526
- }
527
- }
528
- } else {
529
- const accountForNetwork = accountDef[networkName] || accountDef[chainId] || accountDef["default"];
530
- if (typeof accountForNetwork !== void 0) {
531
- const accountFetched = await getAccount(name, accounts, accountForNetwork);
532
- if (accountFetched) {
533
- accountCache[name] = account = accountFetched;
534
- }
535
- }
536
- }
537
- return account;
538
- }
539
- if (providedContext.accounts) {
540
- const accountNames = Object.keys(providedContext.accounts);
541
- for (const accountName of accountNames) {
542
- let account = await getAccount(accountName, providedContext.accounts, providedContext.accounts[accountName]);
543
- resolvedAccounts[accountName] = account;
544
- }
545
- }
546
- const context = {
547
- accounts: resolvedAccounts,
548
- artifacts: providedContext.artifacts,
549
- network: {
550
- name: networkName,
551
- fork: config.network.fork,
552
- saveDeployments,
553
- tags: networkTags
554
- }
555
- };
556
- const { deployments } = loadDeployments(
557
- config.deployments,
558
- context.network.name,
559
- false,
560
- context.network.fork ? void 0 : {
561
- chainId,
562
- genesisHash,
563
- deleteDeploymentsIfDifferentGenesisHash: true
564
- }
565
- );
566
- const namedAccounts = {};
567
- const namedSigners = {};
568
- const addressSigners = {};
569
- for (const entry of Object.entries(resolvedAccounts)) {
570
- const name = entry[0];
571
- const { address, ...namedSigner } = entry[1];
572
- namedAccounts[name] = address;
573
- addressSigners[address] = namedSigner;
574
- namedSigners[name] = namedSigner;
575
- }
576
- const perliminaryEnvironment = {
577
- config,
578
- deployments,
579
- accounts: namedAccounts,
580
- signers: namedSigners,
581
- addressSigners,
582
- artifacts: context.artifacts,
583
- network: {
584
- chain: getChain(chainId),
585
- name: context.network.name,
586
- tags: context.network.tags,
587
- provider
588
- }
589
- };
590
- function ensureDeploymentFolder() {
591
- const folderPath = import_node_path3.default.join(config.deployments, context.network.name);
592
- import_node_fs3.default.mkdirSync(folderPath, { recursive: true });
593
- const chainFilepath = import_node_path3.default.join(folderPath, ".chain");
594
- if (!import_node_fs3.default.existsSync(chainFilepath)) {
595
- import_node_fs3.default.writeFileSync(chainFilepath, JSON.stringify({ chainId, genesisHash }));
596
- }
597
- return folderPath;
598
- }
599
- function get(name) {
600
- const deployment = deployments[name];
601
- if (!deployment) {
602
- throw new Error(`no deployment named "${name}" found.`);
603
- }
604
- return deployment;
605
- }
606
- function getOrNull(name) {
607
- return deployments[name] || null;
608
- }
609
- function fromAddressToNamedABIOrNull(address) {
610
- let list = [];
611
- for (const name of Object.keys(deployments)) {
612
- const deployment = deployments[name];
613
- if (deployment.address.toLowerCase() == address.toLowerCase()) {
614
- list.push({ name, artifact: deployment });
615
- }
616
- }
617
- if (list.length === 0) {
618
- return null;
619
- }
620
- const { mergedABI } = mergeArtifacts(list);
621
- return {
622
- mergedABI,
623
- names: list.map((v) => v.name)
624
- };
625
- }
626
- function fromAddressToNamedABI(address) {
627
- const n = fromAddressToNamedABIOrNull(address);
628
- if (!n) {
629
- throw new Error(`could not find artifact for address ${address}`);
630
- }
631
- return n;
632
- }
633
- async function save(name, deployment) {
634
- deployments[name] = deployment;
635
- if (context.network.saveDeployments) {
636
- const folderPath = ensureDeploymentFolder();
637
- import_node_fs3.default.writeFileSync(`${folderPath}/${name}.json`, JSONToString(deployment, 2));
638
- }
639
- return deployment;
640
- }
641
- async function recoverTransactionsIfAny() {
642
- if (!context.network.saveDeployments) {
643
- return;
644
- }
645
- const folderPath = ensureDeploymentFolder();
646
- const filepath = import_node_path3.default.join(folderPath, ".pending_transactions.json");
647
- let existingPendingTansactions;
648
- try {
649
- existingPendingTansactions = stringToJSON(import_node_fs3.default.readFileSync(filepath, "utf-8"));
650
- } catch {
651
- existingPendingTansactions = [];
652
- }
653
- if (existingPendingTansactions.length > 0) {
654
- while (existingPendingTansactions.length > 0) {
655
- const pendingTransaction = existingPendingTansactions.shift();
656
- if (pendingTransaction) {
657
- if (pendingTransaction.type === "deployment") {
658
- const spinner = spin(
659
- `recovering ${pendingTransaction.name} with transaction ${pendingTransaction.transaction.hash}`
660
- );
661
- try {
662
- await waitForDeploymentTransactionAndSave(pendingTransaction);
663
- import_node_fs3.default.writeFileSync(filepath, JSONToString(existingPendingTansactions, 2));
664
- spinner.succeed();
665
- } catch (e) {
666
- spinner.fail();
667
- throw e;
668
- }
669
- } else {
670
- const spinner = spin(`recovering execution's transaction ${pendingTransaction.transaction.hash}`);
671
- try {
672
- await waitForTransaction(pendingTransaction.transaction.hash);
673
- import_node_fs3.default.writeFileSync(filepath, JSONToString(existingPendingTansactions, 2));
674
- spinner.succeed();
675
- } catch (e) {
676
- spinner.fail();
677
- throw e;
678
- }
679
- }
680
- }
681
- }
682
- import_node_fs3.default.rmSync(filepath);
683
- }
684
- }
685
- async function savePendingTransaction(pendingTransaction) {
686
- if (context.network.saveDeployments) {
687
- const folderPath = ensureDeploymentFolder();
688
- const filepath = import_node_path3.default.join(folderPath, ".pending_transactions.json");
689
- let existingPendinTransactions;
690
- try {
691
- existingPendinTransactions = stringToJSON(import_node_fs3.default.readFileSync(filepath, "utf-8"));
692
- } catch {
693
- existingPendinTransactions = [];
694
- }
695
- existingPendinTransactions.push(pendingTransaction);
696
- import_node_fs3.default.writeFileSync(filepath, JSONToString(existingPendinTransactions, 2));
697
- }
698
- return deployments;
699
- }
700
- async function waitForTransactionReceipt(params) {
701
- const { hash, pollingInterval } = { pollingInterval: 1, ...params };
702
- let latestBlockNumber = await provider.request({
703
- method: "eth_blockNumber"
704
- });
705
- let receipt = await provider.request({
706
- method: "eth_getTransactionReceipt",
707
- params: [hash]
708
- });
709
- if (!receipt || !receipt.blockHash) {
710
- await wait(pollingInterval);
711
- return waitForTransactionReceipt(params);
712
- }
713
- return { receipt, latestBlockNumber };
714
- }
715
- async function deleteTransaction(hash) {
716
- if (context.network.saveDeployments) {
717
- const folderPath = ensureDeploymentFolder();
718
- const filepath = import_node_path3.default.join(folderPath, ".pending_transactions.json");
719
- let existingPendinTransactions;
720
- try {
721
- existingPendinTransactions = stringToJSON(import_node_fs3.default.readFileSync(filepath, "utf-8"));
722
- } catch {
723
- existingPendinTransactions = [];
724
- }
725
- existingPendinTransactions = existingPendinTransactions.filter((v) => v.transaction.hash !== hash);
726
- if (existingPendinTransactions.length === 0) {
727
- import_node_fs3.default.rmSync(filepath);
728
- } else {
729
- import_node_fs3.default.writeFileSync(filepath, JSONToString(existingPendinTransactions, 2));
730
- }
731
- }
732
- }
733
- async function exportDeploymentsAsTypes() {
734
- const folderPath = "./generated";
735
- import_node_fs3.default.mkdirSync(folderPath, { recursive: true });
736
- import_node_fs3.default.writeFileSync(`${folderPath}/deployments.ts`, `export default ${JSONToString(deployments, 2)} as const;`);
737
- }
738
- async function waitForTransaction(hash, info) {
739
- const spinner = spin(
740
- info?.message ? info.message : ` - Broadcasting tx:
741
- ${hash}${info?.transaction ? `
742
- ${displayTransaction(info?.transaction)}` : ""}`
743
- );
744
- let receiptResult;
745
- try {
746
- receiptResult = await waitForTransactionReceipt({
747
- hash
748
- });
749
- } catch (e) {
750
- spinner.fail();
751
- throw e;
752
- }
753
- if (!receiptResult) {
754
- throw new Error(`receipt for ${hash} not found`);
755
- } else {
756
- spinner.succeed();
757
- }
758
- return receiptResult;
759
- }
760
- async function waitForDeploymentTransactionAndSave(pendingDeployment, transaction) {
761
- const message = ` - Deploying ${pendingDeployment.name} with tx:
762
- ${pendingDeployment.transaction.hash}${transaction ? `
763
- ${displayTransaction(transaction)}` : ""}`;
764
- const { receipt, latestBlockNumber } = await waitForTransaction(pendingDeployment.transaction.hash, {
765
- message,
766
- transaction
767
- });
768
- const contractAddress = pendingDeployment.expectedAddress || receipt.contractAddress;
769
- if (!contractAddress) {
770
- console.error(receipt);
771
- throw new Error(`no contract address found for ${pendingDeployment.name}`);
772
- }
773
- showMessage(` => ${contractAddress}`);
774
- const { abi, ...artifactObjectWithoutABI } = pendingDeployment.partialDeployment;
775
- if (!pendingDeployment.transaction.hash) {
776
- const spinner = spin();
777
- let transaction2 = null;
778
- try {
779
- transaction2 = await provider.request({
780
- method: "eth_getTransactionByHash",
781
- params: [pendingDeployment.transaction.hash]
782
- });
783
- } catch (e) {
784
- spinner.fail();
785
- throw e;
786
- }
787
- if (!transaction2) {
788
- spinner.fail(`tx ${pendingDeployment.transaction.hash} not found`);
789
- } else {
790
- spinner.stop();
791
- }
792
- if (transaction2) {
793
- pendingDeployment.transaction = {
794
- nonce: transaction2.nonce,
795
- hash: transaction2.hash,
796
- origin: transaction2.from
797
- };
798
- }
799
- }
800
- for (const key of Object.keys(artifactObjectWithoutABI)) {
801
- if (key.startsWith("_")) {
802
- delete artifactObjectWithoutABI[key];
803
- }
804
- if (key === "evm") {
805
- if (artifactObjectWithoutABI.evm) {
806
- if ("gasEstimates" in artifactObjectWithoutABI["evm"]) {
807
- const { gasEstimates } = artifactObjectWithoutABI.evm;
808
- artifactObjectWithoutABI.evm = {
809
- gasEstimates
810
- };
811
- }
812
- }
813
- }
814
- }
815
- const latestBlockNumberAsNumber = parseInt(latestBlockNumber.slice(2), 16);
816
- const receiptBlockNumber = parseInt(receipt.blockNumber.slice(2), 16);
817
- const confirmations = Math.max(0, latestBlockNumberAsNumber - receiptBlockNumber);
818
- const deployment = {
819
- address: contractAddress,
820
- abi,
821
- ...artifactObjectWithoutABI,
822
- transaction: pendingDeployment.transaction,
823
- receipt: {
824
- confirmations,
825
- blockHash: receipt.blockHash,
826
- blockNumber: receipt.blockNumber,
827
- transactionIndex: receipt.transactionIndex
828
- }
829
- };
830
- return save(pendingDeployment.name, deployment);
831
- }
832
- async function savePendingExecution(pendingExecution) {
833
- await savePendingTransaction(pendingExecution);
834
- let transaction = null;
835
- const spinner = spin();
836
- try {
837
- transaction = await provider.request({
838
- method: "eth_getTransactionByHash",
839
- params: [pendingExecution.transaction.hash]
840
- });
841
- } catch (e) {
842
- spinner.fail();
843
- throw e;
844
- }
845
- if (!transaction) {
846
- spinner.fail(`tx ${pendingExecution.transaction.hash} not found`);
847
- } else {
848
- spinner.stop();
849
- }
850
- if (transaction) {
851
- pendingExecution.transaction.nonce = transaction.nonce;
852
- pendingExecution.transaction.origin = transaction.from;
853
- }
854
- const { receipt } = await waitForTransaction(pendingExecution.transaction.hash, { transaction });
855
- await deleteTransaction(pendingExecution.transaction.hash);
856
- return receipt;
857
- }
858
- async function savePendingDeployment(pendingDeployment) {
859
- await savePendingTransaction(pendingDeployment);
860
- let transaction = null;
861
- const spinner = spin();
862
- try {
863
- transaction = await provider.request({
864
- method: "eth_getTransactionByHash",
865
- params: [pendingDeployment.transaction.hash]
866
- });
867
- } catch (e) {
868
- console.error(`failed to fetch tx ${pendingDeployment.transaction.hash}. Can't know its status`);
869
- spinner.fail();
870
- throw e;
871
- }
872
- if (!transaction) {
873
- spinner.fail(`tx ${pendingDeployment.transaction.hash} not found`);
874
- } else {
875
- spinner.stop();
876
- }
877
- if (transaction) {
878
- pendingDeployment = {
879
- ...pendingDeployment,
880
- transaction: { hash: transaction.hash, nonce: transaction.nonce, origin: transaction.from }
881
- };
882
- }
883
- const deployment = await waitForDeploymentTransactionAndSave(pendingDeployment, transaction);
884
- await deleteTransaction(pendingDeployment.transaction.hash);
885
- return deployment;
886
- }
887
- function showMessage(message) {
888
- log(message);
889
- }
890
- function showProgress(message) {
891
- return spin(message);
892
- }
893
- let env = {
894
- ...perliminaryEnvironment,
895
- save,
896
- savePendingDeployment,
897
- savePendingExecution,
898
- get,
899
- getOrNull,
900
- fromAddressToNamedABI,
901
- fromAddressToNamedABIOrNull,
902
- showMessage,
903
- showProgress
904
- };
905
- for (const extension of globalThis.extensions) {
906
- env = extension(env);
907
- }
908
- return {
909
- external: env,
910
- internal: {
911
- exportDeploymentsAsTypes,
912
- recoverTransactionsIfAny
913
- }
914
- };
915
- }
916
-
917
- // src/utils/eth.ts
918
- function avg(arr) {
919
- const sum = arr.reduce((a, v) => a + v);
920
- return sum / BigInt(arr.length);
921
- }
922
- async function getGasPriceEstimate(provider, options2) {
923
- const defaultOptions = {
924
- blockCount: 20,
925
- newestBlock: "pending",
926
- rewardPercentiles: [10, 50, 80]
927
- };
928
- const optionsResolved = options2 ? { ...defaultOptions, ...options2 } : defaultOptions;
929
- const historicalBlocks = optionsResolved.blockCount;
930
- const rawFeeHistory = await provider.request({
931
- method: "eth_feeHistory",
932
- params: [`0x${historicalBlocks.toString(16)}`, optionsResolved.newestBlock, optionsResolved.rewardPercentiles]
933
- });
934
- let blockNum = Number(rawFeeHistory.oldestBlock);
935
- const lastBlock = blockNum + rawFeeHistory.reward.length;
936
- let index = 0;
937
- const blocksHistory = [];
938
- while (blockNum < lastBlock) {
939
- blocksHistory.push({
940
- number: blockNum,
941
- baseFeePerGas: BigInt(rawFeeHistory.baseFeePerGas[index]),
942
- gasUsedRatio: Number(rawFeeHistory.gasUsedRatio[index]),
943
- priorityFeePerGas: rawFeeHistory.reward[index].map((x) => BigInt(x))
944
- });
945
- blockNum += 1;
946
- index += 1;
947
- }
948
- const percentilePriorityFeeAverages = [];
949
- for (let i = 0; i < optionsResolved.rewardPercentiles.length; i++) {
950
- percentilePriorityFeeAverages.push(avg(blocksHistory.map((b) => b.priorityFeePerGas[i])));
951
- }
952
- const baseFeePerGas = BigInt(rawFeeHistory.baseFeePerGas[rawFeeHistory.baseFeePerGas.length - 1]);
953
- const result = [];
954
- for (let i = 0; i < optionsResolved.rewardPercentiles.length; i++) {
955
- result.push({
956
- maxFeePerGas: percentilePriorityFeeAverages[i] + baseFeePerGas,
957
- maxPriorityFeePerGas: percentilePriorityFeeAverages[i]
958
- });
959
- }
960
- return result;
961
- }
962
- async function getRoughGasPriceEstimate(provider, options2) {
963
- const defaultOptions = {
964
- blockCount: 20,
965
- newestBlock: "pending",
966
- rewardPercentiles: [10, 50, 80]
967
- };
968
- const optionsResolved = options2 ? { ...defaultOptions, ...options2 } : defaultOptions;
969
- if (optionsResolved.rewardPercentiles.length !== 3) {
970
- throw new Error(`rough gas estimate require 3 percentile, it defaults to [10,50,80]`);
971
- }
972
- const result = await getGasPriceEstimate(provider, optionsResolved);
973
- return {
974
- slow: result[0],
975
- average: result[1],
976
- fast: result[2]
977
- };
978
- }
979
-
980
- // src/executor/index.ts
981
- var import_prompts = __toESM(require("prompts"), 1);
982
- var import_viem2 = require("viem");
983
- if (!process.env["ROCKETH_SKIP_ESBUILD"]) {
984
- require("esbuild-register/dist/node").register();
985
- }
986
- function readConfig(options2) {
987
- let configFile;
988
- try {
989
- const configString = import_node_fs4.default.readFileSync("./rocketh.json", "utf-8");
990
- configFile = JSON.parse(configString);
991
- } catch {
992
- }
993
- if (configFile) {
994
- if (!options2.deployments && configFile.deployments) {
995
- options2.deployments = configFile.deployments;
996
- }
997
- if (!options2.scripts && configFile.scripts) {
998
- options2.scripts = configFile.scripts;
999
- }
1000
- }
1001
- const fromEnv = process.env["ETH_NODE_URI_" + options2.network];
1002
- const fork = typeof options2.network !== "string";
1003
- let networkName = "memory";
1004
- if (options2.network) {
1005
- if (typeof options2.network === "string") {
1006
- networkName = options2.network;
1007
- } else if ("fork" in options2.network) {
1008
- networkName = options2.network.fork;
1009
- }
1010
- }
1011
- let networkTags = configFile?.networks && configFile?.networks[networkName]?.tags || [];
1012
- if (!options2.provider) {
1013
- let nodeUrl;
1014
- if (typeof fromEnv === "string") {
1015
- nodeUrl = fromEnv;
1016
- } else {
1017
- if (configFile) {
1018
- const network = configFile.networks && configFile.networks[networkName];
1019
- if (network && network.rpcUrl) {
1020
- nodeUrl = network.rpcUrl;
1021
- } else {
1022
- if (options2?.ignoreMissingRPC) {
1023
- nodeUrl = "";
1024
- } else {
1025
- if (options2.network === "localhost") {
1026
- nodeUrl = "http://127.0.0.1:8545";
1027
- } else {
1028
- logger.error(`network "${options2.network}" is not configured. Please add it to the rocketh.json file`);
1029
- process.exit(1);
1030
- }
1031
- }
1032
- }
1033
- } else {
1034
- if (options2?.ignoreMissingRPC) {
1035
- nodeUrl = "";
1036
- } else {
1037
- if (options2.network === "localhost") {
1038
- nodeUrl = "http://127.0.0.1:8545";
1039
- } else {
1040
- logger.error(`network "${options2.network}" is not configured. Please add it to the rocketh.json file`);
1041
- process.exit(1);
1042
- }
1043
- }
1044
- }
1045
- }
1046
- return {
1047
- network: {
1048
- nodeUrl,
1049
- name: networkName,
1050
- tags: networkTags,
1051
- fork
1052
- },
1053
- deployments: options2.deployments,
1054
- saveDeployments: options2.saveDeployments,
1055
- scripts: options2.scripts,
1056
- tags: typeof options2.tags === "undefined" ? void 0 : options2.tags.split(","),
1057
- logLevel: options2.logLevel,
1058
- askBeforeProceeding: options2.askBeforeProceeding,
1059
- reportGasUse: options2.reportGasUse
1060
- };
1061
- } else {
1062
- return {
1063
- network: {
1064
- provider: options2.provider,
1065
- name: networkName,
1066
- tags: networkTags,
1067
- fork
1068
- },
1069
- deployments: options2.deployments,
1070
- saveDeployments: options2.saveDeployments,
1071
- scripts: options2.scripts,
1072
- tags: typeof options2.tags === "undefined" ? void 0 : options2.tags.split(","),
1073
- logLevel: options2.logLevel,
1074
- askBeforeProceeding: options2.askBeforeProceeding,
1075
- reportGasUse: options2.reportGasUse
1076
- };
1077
- }
1078
- }
1079
- function readAndResolveConfig(options2) {
1080
- return resolveConfig(readConfig(options2));
1081
- }
1082
- function resolveConfig(config) {
1083
- const resolvedConfig = {
1084
- ...config,
1085
- network: config.network,
1086
- // TODO default to || {name: 'memory'....}
1087
- deployments: config.deployments || "deployments",
1088
- scripts: config.scripts || "deploy",
1089
- tags: config.tags || [],
1090
- networkTags: config.networkTags || [],
1091
- saveDeployments: config.saveDeployments
1092
- };
1093
- return resolvedConfig;
1094
- }
1095
- async function loadAndExecuteDeployments(options2, args) {
1096
- const resolvedConfig = readAndResolveConfig(options2);
1097
- return executeDeployScripts(resolvedConfig, args);
1098
- }
1099
- async function executeDeployScripts(config, args) {
1100
- setLogLevel(typeof config.logLevel === "undefined" ? 0 : config.logLevel);
1101
- let filepaths;
1102
- filepaths = traverseMultipleDirectory([config.scripts]);
1103
- filepaths = filepaths.filter((v) => !import_node_path4.default.basename(v).startsWith("_")).sort((a, b) => {
1104
- if (a < b) {
1105
- return -1;
1106
- }
1107
- if (a > b) {
1108
- return 1;
1109
- }
1110
- return 0;
1111
- });
1112
- let providedContext;
1113
- const scriptModuleByFilePath = {};
1114
- const scriptPathBags = {};
1115
- const scriptFilePaths = [];
1116
- for (const filepath of filepaths) {
1117
- const scriptFilePath = import_node_path4.default.resolve(filepath);
1118
- let scriptModule;
1119
- try {
1120
- if (require.cache) {
1121
- delete require.cache[scriptFilePath];
1122
- }
1123
- scriptModule = require(scriptFilePath);
1124
- if (scriptModule.default) {
1125
- scriptModule = scriptModule.default;
1126
- if (scriptModule.default) {
1127
- logger.warn(`double default...`);
1128
- scriptModule = scriptModule.default;
1129
- }
1130
- }
1131
- scriptModuleByFilePath[scriptFilePath] = scriptModule;
1132
- if (providedContext && providedContext !== scriptModule.providedContext) {
1133
- throw new Error(`context between 2 scripts is different, please share the same across them`);
1134
- }
1135
- providedContext = scriptModule.providedContext;
1136
- } catch (e) {
1137
- logger.error(`could not import ${filepath}`);
1138
- throw e;
1139
- }
1140
- let scriptTags = scriptModule.tags;
1141
- if (scriptTags !== void 0) {
1142
- if (typeof scriptTags === "string") {
1143
- scriptTags = [scriptTags];
1144
- }
1145
- for (const tag of scriptTags) {
1146
- if (tag.indexOf(",") >= 0) {
1147
- throw new Error("Tag cannot contains commas");
1148
- }
1149
- const bag = scriptPathBags[tag] || [];
1150
- scriptPathBags[tag] = bag;
1151
- bag.push(scriptFilePath);
1152
- }
1153
- }
1154
- if (config.tags !== void 0 && config.tags.length > 0) {
1155
- let found = false;
1156
- if (scriptTags !== void 0) {
1157
- for (const tagToFind of config.tags) {
1158
- for (const tag of scriptTags) {
1159
- if (tag === tagToFind) {
1160
- scriptFilePaths.push(scriptFilePath);
1161
- found = true;
1162
- break;
1163
- }
1164
- }
1165
- if (found) {
1166
- break;
1167
- }
1168
- }
1169
- }
1170
- } else {
1171
- scriptFilePaths.push(scriptFilePath);
1172
- }
1173
- }
1174
- if (!providedContext) {
1175
- throw new Error(`no context loaded`);
1176
- }
1177
- const { internal, external } = await createEnvironment(config, providedContext);
1178
- await internal.recoverTransactionsIfAny();
1179
- const scriptsRegisteredToRun = {};
1180
- const scriptsToRun = [];
1181
- const scriptsToRunAtTheEnd = [];
1182
- function recurseDependencies(scriptFilePath) {
1183
- if (scriptsRegisteredToRun[scriptFilePath]) {
1184
- return;
1185
- }
1186
- const scriptModule = scriptModuleByFilePath[scriptFilePath];
1187
- if (scriptModule.dependencies) {
1188
- for (const dependency of scriptModule.dependencies) {
1189
- const scriptFilePathsToAdd = scriptPathBags[dependency];
1190
- if (scriptFilePathsToAdd) {
1191
- for (const scriptFilenameToAdd of scriptFilePathsToAdd) {
1192
- recurseDependencies(scriptFilenameToAdd);
1193
- }
1194
- }
1195
- }
1196
- }
1197
- if (!scriptsRegisteredToRun[scriptFilePath]) {
1198
- if (scriptModule.runAtTheEnd) {
1199
- scriptsToRunAtTheEnd.push({
1200
- filePath: scriptFilePath,
1201
- func: scriptModule
1202
- });
1203
- } else {
1204
- scriptsToRun.push({
1205
- filePath: scriptFilePath,
1206
- func: scriptModule
1207
- });
1208
- }
1209
- scriptsRegisteredToRun[scriptFilePath] = true;
1210
- }
1211
- }
1212
- for (const scriptFilePath of scriptFilePaths) {
1213
- recurseDependencies(scriptFilePath);
1214
- }
1215
- if (config.askBeforeProceeding) {
1216
- console.log(
1217
- `Network: ${external.network.name}
1218
- Chain: ${external.network.chain.name}
1219
- Tags: ${Object.keys(
1220
- external.network.tags
1221
- ).join("',")}`
1222
- );
1223
- const gasPriceEstimate = await getRoughGasPriceEstimate(external.network.provider);
1224
- const prompt = await (0, import_prompts.default)({
1225
- type: "confirm",
1226
- name: "proceed",
1227
- message: `gas price is currently in this range:
1228
- slow: ${(0, import_viem2.formatEther)(gasPriceEstimate.slow.maxFeePerGas)} (priority: ${(0, import_viem2.formatEther)(
1229
- gasPriceEstimate.slow.maxPriorityFeePerGas
1230
- )})
1231
- average: ${(0, import_viem2.formatEther)(gasPriceEstimate.average.maxFeePerGas)} (priority: ${(0, import_viem2.formatEther)(
1232
- gasPriceEstimate.average.maxPriorityFeePerGas
1233
- )})
1234
- fast: ${(0, import_viem2.formatEther)(gasPriceEstimate.fast.maxFeePerGas)} (priority: ${(0, import_viem2.formatEther)(
1235
- gasPriceEstimate.fast.maxPriorityFeePerGas
1236
- )})
1237
-
1238
- Do you want to proceed (note that gas price can change for each tx)`
1239
- });
1240
- if (!prompt.proceed) {
1241
- process.exit();
1242
- }
1243
- }
1244
- for (const deployScript of scriptsToRun.concat(scriptsToRunAtTheEnd)) {
1245
- const filename = import_node_path4.default.basename(deployScript.filePath);
1246
- const relativeFilepath = import_node_path4.default.relative(".", deployScript.filePath);
1247
- let skip = false;
1248
- const spinner = spin(`- Executing ${filename}`);
1249
- if (deployScript.func.skip) {
1250
- const spinner2 = spin(` - skip?()`);
1251
- try {
1252
- skip = await deployScript.func.skip(external, args);
1253
- spinner2.succeed(skip ? `skipping ${filename}` : void 0);
1254
- } catch (e) {
1255
- spinner2.fail();
1256
- throw e;
1257
- }
1258
- }
1259
- if (!skip) {
1260
- let result;
1261
- try {
1262
- result = await deployScript.func(external, args);
1263
- spinner.succeed(`
1264
- `);
1265
- } catch (e) {
1266
- spinner.fail();
1267
- throw e;
1268
- }
1269
- if (result && typeof result === "boolean") {
1270
- const deploymentFolderPath = config.deployments;
1271
- }
1272
- }
1273
- }
1274
- if (config.reportGasUse) {
1275
- const provider = external.network.provider;
1276
- const transactionHashes = provider.transactionHashes;
1277
- let totalGasUsed = 0;
1278
- for (const hash of transactionHashes) {
1279
- const transactionReceipt = await provider.request({ method: "eth_getTransactionReceipt", params: [hash] });
1280
- if (transactionReceipt) {
1281
- const gasUsed = Number(transactionReceipt.gasUsed);
1282
- totalGasUsed += gasUsed;
1283
- }
1284
- }
1285
- console.log({ totalGasUsed });
1286
- }
1287
- return external;
1288
- }
1289
-
1290
- // src/cli.ts
1291
- var import_commander = require("commander");
1292
-
1293
- // package.json
1294
- var package_default = {
1295
- name: "rocketh",
1296
- version: "0.10.6",
1297
- description: "deploy smart contract on ethereum-compatible networks",
1298
- publishConfig: {
1299
- access: "public"
1300
- },
1301
- type: "module",
1302
- main: "dist/index.cjs",
1303
- module: "dist/index.js",
1304
- types: "dist/index.d.ts",
1305
- bin: {
1306
- rocketh: "dist/cli.cjs"
1307
- },
1308
- devDependencies: {
1309
- "@types/figlet": "^1.5.8",
1310
- "@types/node": "^20.11.19",
1311
- "@types/prompts": "^2.4.9",
1312
- abitype: "^1.0.0",
1313
- "eip-1193": "^0.5.0",
1314
- "ipfs-gateway-emulator": "4.2.1-ipfs.2",
1315
- rimraf: "^5.0.5",
1316
- tsup: "^8.0.2",
1317
- typedoc: "^0.25.8",
1318
- typescript: "^5.3.3"
1319
- },
1320
- dependencies: {
1321
- commander: "^12.0.0",
1322
- "eip-1193-jsonrpc-provider": "^0.3.0",
1323
- esbuild: "^0.20.1",
1324
- "esbuild-register": "^3.5.0",
1325
- ethers: "^6.11.1",
1326
- figlet: "^1.7.0",
1327
- ldenv: "^0.3.9",
1328
- "named-logs": "^0.2.2",
1329
- "named-logs-console": "^0.3.0",
1330
- prompts: "^2.4.2",
1331
- viem: "^2.7.11"
1332
- },
1333
- scripts: {
1334
- build: "rimraf dist && tsup --entry src/index.ts --entry src/cli.ts --dts --format esm,cjs",
1335
- dev: "rimraf dist && tsup --entry src/index.ts --entry src/cli.ts --dts --format esm,cjs --watch",
1336
- "dev-no-reset": "tsup --entry src/index.ts --entry src/cli.ts --dts --format esm,cjs --watch",
1337
- "gen-docs": "typedoc --out docs src",
1338
- "serve-docs": "ipfs-emulator --only -d docs -p 8080"
1339
- }
62
+ var pkg = {
63
+ name: name,
64
+ version: version,
65
+ description: description,
66
+ publishConfig: publishConfig,
67
+ type: type,
68
+ main: main,
69
+ module: module$1,
70
+ types: types,
71
+ ".": {
72
+ require: {
73
+ types: "./dist/index.d.ts",
74
+ "default": "./dist/index.cjs"
75
+ },
76
+ "import": {
77
+ types: "./dist/index.d.ts",
78
+ "default": "./dist/index.mjs"
79
+ }
80
+ },
81
+ bin: bin,
82
+ devDependencies: devDependencies,
83
+ dependencies: dependencies,
84
+ scripts: scripts
1340
85
  };
1341
86
 
1342
- // src/cli.ts
1343
- (0, import_ldenv.loadEnv)();
1344
- var commandName = package_default.name;
1345
- var program = new import_commander.Command();
1346
- program.name(commandName).version(package_default.version).usage(`${commandName}`).description("execute deploy scripts and store the deployments").option("-s, --scripts <value>", "path the folder containing the deploy scripts to execute").option("-t, --tags <value>", "comma separated list of tags to execute").option("-d, --deployments <value>", "folder where deployments are saved").option("--skip-gas-report", "if set skip gas report").option("--skip-prompts", "if set skip any prompts").requiredOption("-n, --network <value>", "network context to use").parse(process.argv);
1347
- var options = program.opts();
87
+ ldenv.loadEnv();
88
+ const commandName = pkg.name;
89
+ const program = new commander.Command();
90
+ program.name(commandName).version(pkg.version).usage(`${commandName}`).description("execute deploy scripts and store the deployments").option("-s, --scripts <value>", "path the folder containing the deploy scripts to execute").option("-t, --tags <value>", "comma separated list of tags to execute").option("-d, --deployments <value>", "folder where deployments are saved").option("--skip-gas-report", "if set skip gas report").option("--skip-prompts", "if set skip any prompts").requiredOption("-n, --network <value>", "network context to use").parse(process.argv);
91
+ const options = program.opts();
1348
92
  console.log(options);
1349
- loadAndExecuteDeployments({
93
+ index.loadAndExecuteDeployments({
1350
94
  ...options,
1351
95
  logLevel: 1,
1352
96
  askBeforeProceeding: options.skipPrompts ? false : true,
1353
97
  reportGasUse: options.skipGasReport ? false : true
1354
98
  });
1355
- //# sourceMappingURL=cli.cjs.map
99
+ //# sourceMappingURL=cli.cjs.map