@xyo-network/xl1-cli-lib 1.19.8 → 1.19.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/node/xl1.mjs CHANGED
@@ -5,8 +5,9 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
5
5
  import { config } from "dotenv";
6
6
 
7
7
  // src/runCLI.ts
8
- import { deepMerge, isDefined as isDefined3, toAddress } from "@xylabs/sdk-js";
8
+ import { deepMerge, isDefined as isDefined4, toAddress } from "@xylabs/sdk-js";
9
9
  import { runApi } from "@xyo-network/chain-api";
10
+ import { runMempool } from "@xyo-network/chain-mempool";
10
11
  import { Orchestrator } from "@xyo-network/chain-orchestration";
11
12
  import { runProducer } from "@xyo-network/chain-producer";
12
13
  import { ConfigZod as ConfigZod2, isZodError } from "@xyo-network/xl1-sdk";
@@ -14,23 +15,49 @@ import yargs from "yargs";
14
15
  import { hideBin } from "yargs/helpers";
15
16
 
16
17
  // src/commands/bridge/runBridge.ts
17
- import { getServer } from "@xyo-network/chain-bridge";
18
- function runBridge(context) {
19
- void getServer(context);
20
- }
21
- __name(runBridge, "runBridge");
22
-
23
- // src/commands/mempool/runMempool.ts
24
- import { getServer as getServer2 } from "@xyo-network/chain-mempool";
25
- function runMempool(context) {
26
- void getServer2(context);
27
- }
28
- __name(runMempool, "runMempool");
18
+ import { exists } from "@xylabs/sdk-js";
19
+ import { BridgeActor } from "@xyo-network/chain-bridge";
20
+ import { initBridgeWallet } from "@xyo-network/chain-orchestration";
21
+ var runBridge = /* @__PURE__ */ __name(async (config2, orchestrator, locator) => {
22
+ const account = await initBridgeWallet({
23
+ config: config2,
24
+ logger: locator.context.logger
25
+ });
26
+ const api = await BridgeActor.create({
27
+ account,
28
+ config: config2,
29
+ locator
30
+ });
31
+ const actors = [
32
+ api
33
+ ].filter(exists);
34
+ for (const actor of actors) {
35
+ await orchestrator.registerActor(actor);
36
+ }
37
+ await orchestrator.start();
38
+ }, "runBridge");
29
39
 
30
40
  // src/commands/rewardRedemption/runRewardRedemptionApi.ts
31
- import { getServer as getServer3 } from "@xyo-network/chain-reward-redemption";
32
- function runRewardRedemptionApi(context) {
33
- void getServer3(context);
41
+ import { exists as exists2 } from "@xylabs/sdk-js";
42
+ import { initRewardsRedemptionApiWallet } from "@xyo-network/chain-orchestration";
43
+ import { RewardRedemptionActor } from "@xyo-network/chain-reward-redemption";
44
+ async function runRewardRedemptionApi(config2, orchestrator, locator) {
45
+ const account = await initRewardsRedemptionApiWallet({
46
+ config: config2,
47
+ logger: locator.context.logger
48
+ });
49
+ const rewardRedemption = await RewardRedemptionActor.create({
50
+ account,
51
+ config: config2,
52
+ locator
53
+ });
54
+ const actors = [
55
+ rewardRedemption
56
+ ].filter(exists2);
57
+ for (const actor of actors) {
58
+ await orchestrator.registerActor(actor);
59
+ }
60
+ await orchestrator.start();
34
61
  }
35
62
  __name(runRewardRedemptionApi, "runRewardRedemptionApi");
36
63
 
@@ -73,12 +100,13 @@ var initLogger = /* @__PURE__ */ __name((config2) => {
73
100
  }, "initLogger");
74
101
 
75
102
  // src/locatorFromConfig.ts
76
- import { asAddress, assertEx, isString } from "@xylabs/sdk-js";
103
+ import { asAddress, assertEx, isDefined as isDefined2, isString } from "@xylabs/sdk-js";
77
104
  import { initApiWallet, initBalanceSummaryMap, initEvmProvidersIfAvailable, initFinalizationArchivistIfNeeded, initProducerAccount, initServerNode, initStatusReporter, initTransferSummaryMap } from "@xyo-network/chain-orchestration";
78
105
  import { SimpleBlockRunner } from "@xyo-network/chain-services";
79
106
  import { initTelemetry } from "@xyo-network/chain-telemetry";
80
107
  import { validateHydratedBlock, validateHydratedBlockState } from "@xyo-network/chain-validation";
81
- import { ProviderFactoryLocator, SimpleAccountBalanceViewer, SimpleBlockRewardViewer, SimpleBlockValidationViewer, SimpleBlockViewer, SimpleFinalizationViewer, SimpleMempoolRunner, SimpleMempoolViewer, SimpleNetworkStakeViewer, SimpleStepRewardsByPositionViewer, SimpleStepRewardsByStakerViewer, SimpleStepRewardsByStepViewer, SimpleStepRewardsTotalViewer, SimpleStepRewardsViewer, SimpleStepViewer, SimpleTimeSyncViewer, SimpleWindowedBlockViewer, SimpleXyoViewer } from "@xyo-network/xl1-sdk";
108
+ import { HDWallet } from "@xyo-network/wallet";
109
+ import { AccountBalanceViewerRpcSchemas, ADDRESS_INDEX, BlockViewerRpcSchemas, FinalizationViewerRpcSchemas, generateXyoBaseWalletFromPhrase, HttpRpcTransport, JsonRpcAccountBalanceViewer, JsonRpcBlockViewer, JsonRpcFinalizationViewer, JsonRpcMempoolRunner, JsonRpcMempoolViewer, MempoolRunnerRpcSchemas, MempoolViewerRpcSchemas, ProviderFactoryLocator, SimpleAccountBalanceViewer, SimpleBlockRewardViewer, SimpleBlockValidationViewer, SimpleBlockViewer, SimpleFinalizationViewer, SimpleMempoolRunner, SimpleMempoolViewer, SimpleNetworkStakeViewer, SimpleStepRewardsByPositionViewer, SimpleStepRewardsByStakerViewer, SimpleStepRewardsByStepViewer, SimpleStepRewardsTotalViewer, SimpleStepRewardsViewer, SimpleStepViewer, SimpleTimeSyncViewer, SimpleWindowedBlockViewer, SimpleXyoConnectionRunner, SimpleXyoConnectionViewer, SimpleXyoGatewayRunner, SimpleXyoRunner, SimpleXyoSigner, SimpleXyoViewer } from "@xyo-network/xl1-sdk";
82
110
  async function telemetryContextFromConfig(config2, serviceName, serviceVersion) {
83
111
  const { otlpEndpoint } = config2.telemetry?.otel ?? {};
84
112
  const { path: endpoint = "/metrics", port = 9466 } = config2.telemetry?.metrics?.scrape ?? {};
@@ -175,7 +203,10 @@ async function localLocatorFromConfig(config2, context) {
175
203
  maxWindowSize: 1e4,
176
204
  syncInterval: 1e4
177
205
  }),
178
- SimpleXyoViewer.factory(SimpleXyoViewer.dependencies, {})
206
+ SimpleXyoConnectionViewer.factory(SimpleXyoConnectionViewer.dependencies, {}),
207
+ SimpleXyoViewer.factory(SimpleXyoViewer.dependencies, {
208
+ finalizedArchivist: readonlyChainArchivist
209
+ })
179
210
  ]);
180
211
  locator.freeze();
181
212
  return locator;
@@ -215,7 +246,9 @@ async function remoteLocatorFromConfig(config2, context) {
215
246
  maxWindowSize: 1e4,
216
247
  syncInterval: 1e4
217
248
  }),
218
- SimpleXyoViewer.factory(SimpleXyoViewer.dependencies, {})
249
+ SimpleXyoViewer.factory(SimpleXyoViewer.dependencies, {
250
+ finalizedArchivist: readonlyChainArchivist
251
+ })
219
252
  ]);
220
253
  locator.freeze();
221
254
  return locator;
@@ -232,6 +265,27 @@ async function producerLocatorFromConfig(config2, context) {
232
265
  if (rewardAddress === account.address) {
233
266
  logger?.warn(`Using producer account address as reward address: ${account.address}`);
234
267
  }
268
+ const remoteUrl = config2.remote.rpc?.url;
269
+ if (isString(remoteUrl)) {
270
+ const transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport(remoteUrl, schemas), "transportFactory");
271
+ locator.registerMany([
272
+ JsonRpcMempoolViewer.factory(JsonRpcMempoolViewer.dependencies, {
273
+ transport: await transportFactory(MempoolViewerRpcSchemas)
274
+ }),
275
+ JsonRpcMempoolRunner.factory(JsonRpcMempoolRunner.dependencies, {
276
+ transport: await transportFactory(MempoolRunnerRpcSchemas)
277
+ }),
278
+ JsonRpcAccountBalanceViewer.factory(JsonRpcAccountBalanceViewer.dependencies, {
279
+ transport: await transportFactory(AccountBalanceViewerRpcSchemas)
280
+ }),
281
+ JsonRpcFinalizationViewer.factory(JsonRpcFinalizationViewer.dependencies, {
282
+ transport: await transportFactory(FinalizationViewerRpcSchemas)
283
+ }),
284
+ JsonRpcBlockViewer.factory(JsonRpcBlockViewer.dependencies, {
285
+ transport: await transportFactory(BlockViewerRpcSchemas)
286
+ })
287
+ ]);
288
+ }
235
289
  locator.registerMany([
236
290
  SimpleBlockRewardViewer.factory(SimpleBlockRewardViewer.dependencies, {}),
237
291
  SimpleBlockRunner.factory(SimpleBlockRunner.dependencies, {
@@ -243,6 +297,68 @@ async function producerLocatorFromConfig(config2, context) {
243
297
  return locator;
244
298
  }
245
299
  __name(producerLocatorFromConfig, "producerLocatorFromConfig");
300
+ function apiLocatorFromConfig(config2, context) {
301
+ const locator = new ProviderFactoryLocator(context);
302
+ locator.registerMany([]);
303
+ locator.freeze();
304
+ return locator;
305
+ }
306
+ __name(apiLocatorFromConfig, "apiLocatorFromConfig");
307
+ function mempoolLocatorFromConfig(config2, context) {
308
+ const locator = new ProviderFactoryLocator(context);
309
+ locator.registerMany([]);
310
+ locator.freeze();
311
+ return locator;
312
+ }
313
+ __name(mempoolLocatorFromConfig, "mempoolLocatorFromConfig");
314
+ async function bridgeLocatorFromConfig(config2, context) {
315
+ const locator = new ProviderFactoryLocator(context);
316
+ const { mnemonic } = config2.actors.bridge;
317
+ const walletPhrase = isDefined2(mnemonic) ? mnemonic : HDWallet.generateMnemonic();
318
+ const wallet = await generateXyoBaseWalletFromPhrase(walletPhrase);
319
+ const signerAccount = await wallet.derivePath(ADDRESS_INDEX.XYO);
320
+ const remoteUrl = config2.actors.bridge.remote.rpc?.url;
321
+ if (isString(remoteUrl)) {
322
+ const transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport(remoteUrl, schemas), "transportFactory");
323
+ locator.registerMany([
324
+ JsonRpcMempoolViewer.factory(JsonRpcMempoolViewer.dependencies, {
325
+ transport: await transportFactory(MempoolViewerRpcSchemas)
326
+ }),
327
+ JsonRpcMempoolRunner.factory(JsonRpcMempoolRunner.dependencies, {
328
+ transport: await transportFactory(MempoolRunnerRpcSchemas)
329
+ }),
330
+ JsonRpcAccountBalanceViewer.factory(JsonRpcAccountBalanceViewer.dependencies, {
331
+ transport: await transportFactory(AccountBalanceViewerRpcSchemas)
332
+ }),
333
+ JsonRpcFinalizationViewer.factory(JsonRpcFinalizationViewer.dependencies, {
334
+ transport: await transportFactory(FinalizationViewerRpcSchemas)
335
+ }),
336
+ JsonRpcBlockViewer.factory(JsonRpcBlockViewer.dependencies, {
337
+ transport: await transportFactory(BlockViewerRpcSchemas)
338
+ })
339
+ ]);
340
+ }
341
+ locator.registerMany([
342
+ SimpleXyoSigner.factory(SimpleXyoSigner.dependencies, {
343
+ account: signerAccount
344
+ }),
345
+ SimpleXyoRunner.factory(SimpleXyoRunner.dependencies, {}),
346
+ SimpleXyoConnectionRunner.factory(SimpleXyoConnectionRunner.dependencies, {}),
347
+ SimpleXyoGatewayRunner.factory(SimpleXyoGatewayRunner.dependencies, {})
348
+ ]);
349
+ locator.freeze();
350
+ return locator;
351
+ }
352
+ __name(bridgeLocatorFromConfig, "bridgeLocatorFromConfig");
353
+ function rewardRedemptionLocatorFromConfig(config2, context) {
354
+ const locator = new ProviderFactoryLocator(context);
355
+ locator.registerMany([
356
+ SimpleXyoGatewayRunner.factory(SimpleXyoGatewayRunner.dependencies, {})
357
+ ]);
358
+ locator.freeze();
359
+ return locator;
360
+ }
361
+ __name(rewardRedemptionLocatorFromConfig, "rewardRedemptionLocatorFromConfig");
246
362
  async function locatorsFromConfig(actors, config2, context) {
247
363
  const result = {
248
364
  _root: await rootLocatorFromConfig(config2, context)
@@ -251,6 +367,22 @@ async function locatorsFromConfig(actors, config2, context) {
251
367
  if (producer) {
252
368
  result.producer = producer;
253
369
  }
370
+ const api = actors.includes("api") ? await apiLocatorFromConfig(config2, result._root.context) : void 0;
371
+ if (api) {
372
+ result.api = api;
373
+ }
374
+ const mempool = actors.includes("mempool") ? await mempoolLocatorFromConfig(config2, result._root.context) : void 0;
375
+ if (mempool) {
376
+ result.mempool = mempool;
377
+ }
378
+ const bridge = actors.includes("bridge") ? await bridgeLocatorFromConfig(config2, result._root.context) : void 0;
379
+ if (bridge) {
380
+ result.bridge = bridge;
381
+ }
382
+ const rewardRedemption = actors.includes("rewardRedemption") ? await rewardRedemptionLocatorFromConfig(config2, result._root.context) : void 0;
383
+ if (rewardRedemption) {
384
+ result.rewardRedemption = rewardRedemption;
385
+ }
254
386
  return result;
255
387
  }
256
388
  __name(locatorsFromConfig, "locatorsFromConfig");
@@ -273,7 +405,7 @@ var optionsFromGlobalZodRegistry = /* @__PURE__ */ __name(() => {
273
405
  }, "optionsFromGlobalZodRegistry");
274
406
 
275
407
  // src/tryParseConfig.ts
276
- import { isDefined as isDefined2, isNull } from "@xylabs/sdk-js";
408
+ import { isDefined as isDefined3, isNull } from "@xylabs/sdk-js";
277
409
  import { ConfigZod } from "@xyo-network/xl1-sdk";
278
410
  import { cosmiconfigSync } from "cosmiconfig";
279
411
  var configName = "xyo";
@@ -283,7 +415,7 @@ var tryParseConfig = /* @__PURE__ */ __name(() => {
283
415
  const result = explorer.search();
284
416
  if (!isNull(result)) {
285
417
  const section = result?.config?.[configSection];
286
- if (isDefined2(section) && typeof section === "object") {
418
+ if (isDefined3(section) && typeof section === "object") {
287
419
  return ConfigZod.parse(section);
288
420
  }
289
421
  }
@@ -313,7 +445,7 @@ var waitForHostPort = /* @__PURE__ */ __name((host, port) => {
313
445
 
314
446
  // src/runCLI.ts
315
447
  var configuration;
316
- var version = isDefined3("1.19.7") ? "1.19.7" : "unknown";
448
+ var version = isDefined4("1.19.8") ? "1.19.8" : "unknown";
317
449
  function resolveConfig(config2) {
318
450
  const logger = console;
319
451
  const defaultChainId = toAddress("1");
@@ -325,29 +457,6 @@ function resolveConfig(config2) {
325
457
  return resolved;
326
458
  }
327
459
  __name(resolveConfig, "resolveConfig");
328
- var getContextFromConfig = /* @__PURE__ */ __name(async (configuration2) => {
329
- const logger = initLogger(configuration2);
330
- const orchestrator = await Orchestrator.create({
331
- logger
332
- });
333
- process.on("SIGINT", () => {
334
- void (async () => {
335
- try {
336
- logger.log("\nSIGINT received. Attempting graceful shutdown...");
337
- await orchestrator?.stop();
338
- logger.log("Orchestrator stopped, exiting now.");
339
- process.exit(0);
340
- } catch (err) {
341
- logger.error("Error stopping orchestrator:", err);
342
- process.exit(1);
343
- }
344
- })();
345
- });
346
- return {
347
- logger,
348
- orchestrator
349
- };
350
- }, "getContextFromConfig");
351
460
  var getLocatorsFromConfig = /* @__PURE__ */ __name(async (actors, configuration2) => {
352
461
  const logger = initLogger(configuration2);
353
462
  const orchestrator = await Orchestrator.create({
@@ -425,30 +534,26 @@ $0 <command> [options]`).parserConfiguration({
425
534
  }).options(optionsFromGlobalZodRegistry()).wrap(y.terminalWidth()).command("api", "Run a XL1 API Node", (yargs2) => {
426
535
  return yargs2.command("$0", "Run a XL1 API Node", () => {
427
536
  }, async () => {
428
- const context = await getContextFromConfig(configuration);
429
- await runApi({
430
- ...context,
431
- config: configuration,
432
- singletons: {}
433
- });
537
+ const { locators, orchestrator } = await getLocatorsFromConfig([
538
+ "api"
539
+ ], configuration);
540
+ await runApi(configuration, orchestrator, locators["api"]);
434
541
  });
435
542
  }).command("bridge", "Run a XL1 Bridge Node", (yargs2) => {
436
543
  return yargs2.command("$0", "Run a XL1 Bridge Node", () => {
437
544
  }, async () => {
438
- const context = await getContextFromConfig(configuration);
439
- runBridge({
440
- ...context,
441
- config: configuration
442
- });
545
+ const { locators, orchestrator } = await getLocatorsFromConfig([
546
+ "bridge"
547
+ ], configuration);
548
+ await runBridge(configuration, orchestrator, locators["bridge"]);
443
549
  });
444
550
  }).command("mempool", "Run a XL1 Mempool Node", (yargs2) => {
445
551
  return yargs2.command("$0", "Run a XL1 Mempool Node", () => {
446
552
  }, async () => {
447
- const context = await getContextFromConfig(configuration);
448
- runMempool({
449
- ...context,
450
- config: configuration
451
- });
553
+ const { locators, orchestrator } = await getLocatorsFromConfig([
554
+ "mempool"
555
+ ], configuration);
556
+ await runMempool(configuration, orchestrator, locators["mempool"]);
452
557
  });
453
558
  }).command("producer", "Run a XL1 Producer Node", (yargs2) => {
454
559
  return yargs2.command("$0", "Run a XL1 Producer Node", () => {
@@ -461,11 +566,10 @@ $0 <command> [options]`).parserConfiguration({
461
566
  }).command("reward-redemption-api", "Run a XL1 Rewards Redemption API Node", (yargs2) => {
462
567
  return yargs2.command("$0", "Run a XL1 Rewards Redemption API Node", () => {
463
568
  }, async () => {
464
- const context = await getContextFromConfig(configuration);
465
- runRewardRedemptionApi({
466
- ...context,
467
- config: configuration
468
- });
569
+ const { locators, orchestrator } = await getLocatorsFromConfig([
570
+ "rewardRedemption"
571
+ ], configuration);
572
+ await runRewardRedemptionApi(configuration, orchestrator, locators["rewardRedemption"]);
469
573
  });
470
574
  }).command("$0", "Run a full XL1 Node", () => {
471
575
  }, async () => {
@@ -476,22 +580,15 @@ $0 <command> [options]`).parserConfiguration({
476
580
  if (configuration.actors.mempool.enabled) {
477
581
  actors.push("mempool");
478
582
  }
479
- const context = await getContextFromConfig(configuration);
480
583
  const { locators, orchestrator } = await getLocatorsFromConfig([
584
+ "api",
481
585
  "producer"
482
586
  ], configuration);
483
587
  if (configuration.actors.mempool.enabled) {
484
- runMempool({
485
- ...context,
486
- config: configuration
487
- });
588
+ await runMempool(configuration, orchestrator, locators["mempool"]);
488
589
  await waitForHostPort(configuration.actors.mempool.host, configuration.actors.mempool.port);
489
590
  }
490
- await runApi({
491
- ...context,
492
- config: configuration,
493
- singletons: {}
494
- });
591
+ await runApi(configuration, orchestrator, locators["api"]);
495
592
  await waitForHostPort(configuration.actors.api.host, configuration.actors.api.port);
496
593
  await runProducer(configuration, orchestrator, locators["producer"]);
497
594
  }).options({