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