@xyo-network/chain-bridge 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.
Files changed (33) hide show
  1. package/dist/node/BridgeActor.d.ts +15 -0
  2. package/dist/node/BridgeActor.d.ts.map +1 -0
  3. package/dist/node/index.d.ts +1 -1
  4. package/dist/node/index.d.ts.map +1 -1
  5. package/dist/node/index.mjs +140 -115
  6. package/dist/node/index.mjs.map +1 -1
  7. package/dist/node/manifest/getServices.d.ts +2 -2
  8. package/dist/node/manifest/getServices.d.ts.map +1 -1
  9. package/dist/node/queue/workers/util/submitXl1Transaction.d.ts +3 -42
  10. package/dist/node/queue/workers/util/submitXl1Transaction.d.ts.map +1 -1
  11. package/dist/node/server/app.d.ts +2 -2
  12. package/dist/node/server/app.d.ts.map +1 -1
  13. package/dist/node/server/routes/addRoutes.d.ts +2 -2
  14. package/dist/node/server/routes/addRoutes.d.ts.map +1 -1
  15. package/dist/node/server/routes/bridge/addBridgeRoutes.d.ts +2 -2
  16. package/dist/node/server/routes/bridge/addBridgeRoutes.d.ts.map +1 -1
  17. package/dist/node/server/routes/bridge/routeDefinitions/getRouteDefinitions.d.ts +2 -2
  18. package/dist/node/server/routes/bridge/routeDefinitions/getRouteDefinitions.d.ts.map +1 -1
  19. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.d.ts +2 -2
  20. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.d.ts.map +1 -1
  21. package/dist/node/server/server.d.ts +2 -2
  22. package/dist/node/server/server.d.ts.map +1 -1
  23. package/package.json +17 -17
  24. package/src/BridgeActor.ts +51 -0
  25. package/src/index.ts +1 -1
  26. package/src/manifest/getServices.ts +2 -4
  27. package/src/queue/workers/util/submitXl1Transaction.ts +23 -7
  28. package/src/server/app.ts +3 -3
  29. package/src/server/routes/addRoutes.ts +3 -3
  30. package/src/server/routes/bridge/addBridgeRoutes.ts +3 -3
  31. package/src/server/routes/bridge/routeDefinitions/getRouteDefinitions.ts +3 -3
  32. package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts +4 -7
  33. package/src/server/server.ts +4 -4
@@ -1,6 +1,10 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
+ // src/BridgeActor.ts
5
+ import { creatable } from "@xylabs/sdk-js";
6
+ import { ActorV3, XyoGatewayRunnerMoniker as XyoGatewayRunnerMoniker2 } from "@xyo-network/xl1-sdk";
7
+
4
8
  // src/server/app.ts
5
9
  import { customPoweredByHeader, disableCaseSensitiveRouting, disableExpressDefaultPoweredByHeader, getJsonBodyParser, getJsonBodyParserOptions, responseProfiler, standardErrors, standardResponses } from "@xylabs/express";
6
10
  import compression from "compression";
@@ -132,7 +136,7 @@ var EthTransactionPreparation = {
132
136
  };
133
137
 
134
138
  // src/queue/workers/EthTransactionSubmission.ts
135
- import { assertEx as assertEx4, isDefined as isDefined3 } from "@xylabs/sdk-js";
139
+ import { assertEx as assertEx5, isDefined as isDefined3 } from "@xylabs/sdk-js";
136
140
  import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/payload-builder";
137
141
  import { Worker as Worker3 } from "bullmq";
138
142
 
@@ -153,27 +157,29 @@ var submitEthTransaction = /* @__PURE__ */ __name(async (tx, bridgeableToken, br
153
157
  }, "submitEthTransaction");
154
158
 
155
159
  // src/queue/workers/util/submitXl1Transaction.ts
156
- import { isAllowedBlockPayload } from "@xyo-network/xl1-sdk";
160
+ import { assertEx as assertEx4 } from "@xylabs/sdk-js";
157
161
  var submitXl1Transaction = /* @__PURE__ */ __name(async (preparedTx, gateway) => {
158
- const onChain = preparedTx[1].filter(isAllowedBlockPayload);
159
- const offChainPayloads = preparedTx[1].filter((p) => !isAllowedBlockPayload(p));
160
- const result = await gateway.addPayloadsToChain(onChain, offChainPayloads);
161
- return result;
162
+ const runner = assertEx4(gateway.connection.runner, () => "No runner available on gateway connection");
163
+ const result = await runner.broadcastTransaction(preparedTx);
164
+ return [
165
+ result,
166
+ preparedTx
167
+ ];
162
168
  }, "submitXl1Transaction");
163
169
 
164
170
  // src/queue/workers/EthTransactionSubmission.ts
165
171
  var name3 = "Submit ETH Transaction";
166
172
  var queueName3 = "eth-tx-submit";
167
173
  var createWorker3 = /* @__PURE__ */ __name((connection2, services) => {
168
- const bridge = assertEx4(services?.bridge, () => "bridge service not provided");
169
- const bridgeableToken = assertEx4(services?.bridgeableToken, () => "bridgeableToken service not provided");
170
- const wallet = assertEx4(services?.wallet, () => "wallet service not provided");
171
- const stateMap = assertEx4(services?.ethTxStateMap, () => "ethTxStateMap service not provided");
174
+ const bridge = assertEx5(services?.bridge, () => "bridge service not provided");
175
+ const bridgeableToken = assertEx5(services?.bridgeableToken, () => "bridgeableToken service not provided");
176
+ const wallet = assertEx5(services?.wallet, () => "wallet service not provided");
177
+ const stateMap = assertEx5(services?.ethTxStateMap, () => "ethTxStateMap service not provided");
172
178
  const worker = new Worker3(queueName3, async (job) => {
173
179
  const { tx } = job.data;
174
180
  const hash = await PayloadBuilder4.hash(tx[0]);
175
- const state = assertEx4(await stateMap.get(hash), () => `[${hash}] state not found`);
176
- const preparedTx = assertEx4(state?.preparedTx, () => `[${hash}] preparedTx not found`);
181
+ const state = assertEx5(await stateMap.get(hash), () => `[${hash}] state not found`);
182
+ const preparedTx = assertEx5(state?.preparedTx, () => `[${hash}] preparedTx not found`);
177
183
  const { submissionHash: existingSubmissionHash } = state;
178
184
  if (isDefined3(existingSubmissionHash)) {
179
185
  await job.log(`[${hash}] Tx already submitted with submission response hash ${existingSubmissionHash}`);
@@ -182,7 +188,7 @@ var createWorker3 = /* @__PURE__ */ __name((connection2, services) => {
182
188
  };
183
189
  }
184
190
  await job.log(`[${hash}] Submitting ETH tx`);
185
- const submissionHash = assertEx4(await submitEthTransaction(tx, bridgeableToken, bridge, wallet), () => `[${hash}] submissionHash not found in receipt`);
191
+ const submissionHash = assertEx5(await submitEthTransaction(tx, bridgeableToken, bridge, wallet), () => `[${hash}] submissionHash not found in receipt`);
186
192
  await job.log(`[${hash}] Submitted ETH tx and received submission response hash ${submissionHash}`);
187
193
  await job.log(`[${hash}] Storing ETH submissionHash`);
188
194
  state.submissionHash = submissionHash;
@@ -236,20 +242,20 @@ var Xl1ToEthBridgeParent = {
236
242
  };
237
243
 
238
244
  // src/queue/workers/Xl1TransactionMonitor.ts
239
- import { assertEx as assertEx5, isDefined as isDefined4, isNull } from "@xylabs/sdk-js";
245
+ import { assertEx as assertEx6, isDefined as isDefined4, isNull } from "@xylabs/sdk-js";
240
246
  import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/payload-builder";
241
247
  import { UnrecoverableError, Worker as Worker5 } from "bullmq";
242
248
  var name5 = "Monitor Submitted XL1 Transaction";
243
249
  var queueName5 = "xl1-tx-monitor";
244
250
  var createWorker5 = /* @__PURE__ */ __name((connection2, services) => {
245
- const gateway = assertEx5(services?.gateway, () => "gateway service not provided");
246
- const stateMap = assertEx5(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
251
+ const gateway = assertEx6(services?.gateway, () => "gateway service not provided");
252
+ const stateMap = assertEx6(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
247
253
  const worker = new Worker5(queueName5, async (job) => {
248
254
  const { tx } = job.data;
249
255
  const hash = await PayloadBuilder5.hash(tx[0]);
250
- const viewer = assertEx5(gateway.connection.viewer, () => `[${hash}] viewer not defined on gateway`);
251
- const state = assertEx5(await stateMap.get(hash), () => `[${hash}] state not found`);
252
- const submissionHash = assertEx5(state?.submissionHash, () => `[${hash}] submissionHash not found`);
256
+ const viewer = assertEx6(gateway.connection.viewer, () => `[${hash}] viewer not defined on gateway`);
257
+ const state = assertEx6(await stateMap.get(hash), () => `[${hash}] state not found`);
258
+ const submissionHash = assertEx6(state?.submissionHash, () => `[${hash}] submissionHash not found`);
253
259
  await job.log(`[${hash}] Checking for XL1 transaction inclusion on chain`);
254
260
  const foundTx = await viewer.transactionByHash(submissionHash);
255
261
  if (isDefined4(foundTx) && !isNull(foundTx)) {
@@ -282,13 +288,13 @@ var Xl1TransactionMonitor = {
282
288
  };
283
289
 
284
290
  // src/queue/workers/Xl1TransactionPreparation.ts
285
- import { assertEx as assertEx6 } from "@xylabs/sdk-js";
291
+ import { assertEx as assertEx7 } from "@xylabs/sdk-js";
286
292
  import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/payload-builder";
287
293
  import { Worker as Worker6 } from "bullmq";
288
294
  var name6 = "Prepare XL1 Transaction";
289
295
  var queueName6 = "xl1-tx-prepare";
290
296
  var createWorker6 = /* @__PURE__ */ __name((connection2, services) => {
291
- const stateMap = assertEx6(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
297
+ const stateMap = assertEx7(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
292
298
  const worker = new Worker6(queueName6, async (job) => {
293
299
  const { tx } = job.data;
294
300
  const hash = await PayloadBuilder6.hash(tx[0]);
@@ -318,19 +324,19 @@ var Xl1TransactionPreparation = {
318
324
  };
319
325
 
320
326
  // src/queue/workers/Xl1TransactionSubmission.ts
321
- import { assertEx as assertEx7, isDefined as isDefined5 } from "@xylabs/sdk-js";
327
+ import { assertEx as assertEx8, isDefined as isDefined5 } from "@xylabs/sdk-js";
322
328
  import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/payload-builder";
323
329
  import { Worker as Worker7 } from "bullmq";
324
330
  var name7 = "Submit XL1 Transaction";
325
331
  var queueName7 = "xl1-tx-submit";
326
332
  var createWorker7 = /* @__PURE__ */ __name((connection2, services) => {
327
- const gateway = assertEx7(services?.gateway, () => "gateway service not provided");
328
- const stateMap = assertEx7(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
333
+ const gateway = assertEx8(services?.gateway, () => "gateway service not provided");
334
+ const stateMap = assertEx8(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
329
335
  const worker = new Worker7(queueName7, async (job) => {
330
336
  const { tx } = job.data;
331
337
  const hash = await PayloadBuilder7.hash(tx[0]);
332
- const state = assertEx7(await stateMap.get(hash), () => `[${hash}] state not found`);
333
- const preparedTx = assertEx7(state?.preparedTx, () => `[${hash}] preparedTx not found`);
338
+ const state = assertEx8(await stateMap.get(hash), () => `[${hash}] state not found`);
339
+ const preparedTx = assertEx8(state?.preparedTx, () => `[${hash}] preparedTx not found`);
334
340
  const { submissionHash: existingSubmissionHash } = state;
335
341
  if (isDefined5(existingSubmissionHash)) {
336
342
  await job.log(`[${hash}] Tx already submitted with submission response hash ${existingSubmissionHash}`);
@@ -491,14 +497,14 @@ var asToken = /* @__PURE__ */ __name((value) => {
491
497
  }, "asToken");
492
498
 
493
499
  // src/config/getBridgeEscrowAddress.ts
494
- import { asAddress as asAddress2, assertEx as assertEx8 } from "@xylabs/sdk-js";
500
+ import { asAddress as asAddress2, assertEx as assertEx9 } from "@xylabs/sdk-js";
495
501
  var tryGetBridgeEscrowAddress = /* @__PURE__ */ __name((config) => {
496
502
  const address = asAddress2(config.actors.bridge.escrowAddress);
497
503
  return address;
498
504
  }, "tryGetBridgeEscrowAddress");
499
505
 
500
506
  // src/config/getBridgeFeesAddress.ts
501
- import { asAddress as asAddress3, assertEx as assertEx9 } from "@xylabs/sdk-js";
507
+ import { asAddress as asAddress3, assertEx as assertEx10 } from "@xylabs/sdk-js";
502
508
  var tryGetBridgeFeesAddress = /* @__PURE__ */ __name((config) => {
503
509
  const address = asAddress3(config.actors.bridge.feesAddress);
504
510
  return address;
@@ -526,17 +532,17 @@ var getMinBridgeAmount = /* @__PURE__ */ __name((config) => {
526
532
  }, "getMinBridgeAmount");
527
533
 
528
534
  // src/config/getRemoteChainId.ts
529
- import { assertEx as assertEx10 } from "@xylabs/sdk-js";
535
+ import { assertEx as assertEx11 } from "@xylabs/sdk-js";
530
536
  var getRemoteChainId = /* @__PURE__ */ __name((config) => {
531
- const remoteChainId = assertEx10(asChainId(config.actors.bridge.remoteChainId), () => "Invalid remote chain ID in config");
537
+ const remoteChainId = assertEx11(asChainId(config.actors.bridge.remoteChainId), () => "Invalid remote chain ID in config");
532
538
  return remoteChainId;
533
539
  }, "getRemoteChainId");
534
540
 
535
541
  // src/config/getRemoteTokenAddress.ts
536
- import { assertEx as assertEx11 } from "@xylabs/sdk-js";
542
+ import { assertEx as assertEx12 } from "@xylabs/sdk-js";
537
543
  var getRemoteTokenAddress = /* @__PURE__ */ __name((config) => {
538
544
  const token = asToken(config.actors.bridge.remoteTokenAddress);
539
- return assertEx11(token, () => "Remote token address is not defined in bridge configuration");
545
+ return assertEx12(token, () => "Remote token address is not defined in bridge configuration");
540
546
  }, "getRemoteTokenAddress");
541
547
 
542
548
  // src/config/getBridgeWalletAccount.ts
@@ -574,13 +580,13 @@ var getTransferAddresses = /* @__PURE__ */ __name(async (config) => {
574
580
  }, "getTransferAddresses");
575
581
 
576
582
  // src/config/getXl1ChainId.ts
577
- import { assertEx as assertEx12, isDefined as isDefined7 } from "@xylabs/sdk-js";
583
+ import { assertEx as assertEx13, isDefined as isDefined7 } from "@xylabs/sdk-js";
578
584
  var getXl1ChainId = /* @__PURE__ */ __name((config) => {
579
585
  const xl1ChainId = config.actors.bridge.xl1ChainId;
580
586
  if (isDefined7(xl1ChainId)) {
581
- return assertEx12(asChainId(xl1ChainId), () => "Invalid xl1ChainId in bridge config");
587
+ return assertEx13(asChainId(xl1ChainId), () => "Invalid xl1ChainId in bridge config");
582
588
  }
583
- return assertEx12(asChainId(config.chain.id), () => "Invalid chain.id in config");
589
+ return assertEx13(asChainId(config.chain.id), () => "Invalid chain.id in config");
584
590
  }, "getXl1ChainId");
585
591
 
586
592
  // src/config/getXl1TokenAddress.ts
@@ -615,25 +621,6 @@ var getBridgeSettings = /* @__PURE__ */ __name(async (config) => {
615
621
  };
616
622
  }, "getBridgeSettings");
617
623
 
618
- // src/config/getGateway.ts
619
- import { isDefined as isDefined9 } from "@xylabs/sdk-js";
620
- import { HDWallet as HDWallet2 } from "@xyo-network/wallet";
621
- import { ADDRESS_INDEX as ADDRESS_INDEX2, buildJsonRpcProviderLocator, generateXyoBaseWalletFromPhrase as generateXyoBaseWalletFromPhrase2, HttpRpcTransport, XyoGatewayRunnerMoniker } from "@xyo-network/xl1-sdk";
622
- var gatewayInstance;
623
- var getGateway = /* @__PURE__ */ __name(async (config) => {
624
- if (isDefined9(gatewayInstance)) return gatewayInstance;
625
- const { mnemonic, chainRpcApiUrl: endpoint } = config.actors.bridge;
626
- const walletPhrase = isDefined9(mnemonic) ? mnemonic : HDWallet2.generateMnemonic();
627
- const wallet = await generateXyoBaseWalletFromPhrase2(walletPhrase);
628
- const signerAccount = await wallet.derivePath(ADDRESS_INDEX2.XYO);
629
- const transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport(endpoint, schemas), "transportFactory");
630
- const locator = await buildJsonRpcProviderLocator({
631
- transportFactory,
632
- signerAccount
633
- });
634
- return await locator.getInstance(XyoGatewayRunnerMoniker);
635
- }, "getGateway");
636
-
637
624
  // src/server/routes/bridge/routeDefinitions/routes/bridgeConfig.ts
638
625
  var BridgeConfigResponseZod = BridgeSettingsZod;
639
626
  var validateRequest = requestHandlerValidator({
@@ -810,7 +797,7 @@ var validateBridgeEstimateExact = /* @__PURE__ */ __name(async (intent, transfer
810
797
  }, "validateBridgeEstimateExact");
811
798
 
812
799
  // src/util/validateBridgeTransaction.ts
813
- import { asAddress as asAddress4, isDefined as isDefined10 } from "@xylabs/sdk-js";
800
+ import { asAddress as asAddress4, isDefined as isDefined9 } from "@xylabs/sdk-js";
814
801
  import { addressesContains, BoundWitnessValidator, payloadHashesContainsAll } from "@xyo-network/boundwitness-validator";
815
802
  import { PayloadBuilder as PayloadBuilder10 } from "@xyo-network/payload-builder";
816
803
  var validateBridgeTransaction = /* @__PURE__ */ __name(async (signedTxBw, intent, transfer, config) => {
@@ -818,7 +805,7 @@ var validateBridgeTransaction = /* @__PURE__ */ __name(async (signedTxBw, intent
818
805
  const chainId = getXl1ChainId(config);
819
806
  if (signedTxBw.chain !== chainId) return false;
820
807
  const errors = await new BoundWitnessValidator(signedTxBw).validate();
821
- if (isDefined10(errors) && errors.length > 0) return false;
808
+ if (isDefined9(errors) && errors.length > 0) return false;
822
809
  const sender = asAddress4(srcAddress, true);
823
810
  if (!addressesContains(signedTxBw, sender)) return false;
824
811
  const hashes = await PayloadBuilder10.hashes([
@@ -886,10 +873,9 @@ var makeBridgeToRemoteRoute = /* @__PURE__ */ __name((config) => {
886
873
 
887
874
  // src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts
888
875
  import { requestHandlerValidator as requestHandlerValidator4 } from "@xylabs/express";
889
- import { assertEx as assertEx13, toAddress as toAddress3 } from "@xylabs/sdk-js";
876
+ import { assertEx as assertEx14, toAddress as toAddress3 } from "@xylabs/sdk-js";
890
877
  import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema3 } from "@xyo-network/payload-model";
891
- import { buildUnsignedTransaction, TransferZod as TransferZod2 } from "@xyo-network/xl1-sdk";
892
- import { BridgeIntentFieldsZod as BridgeIntentFieldsZod2, BridgeIntentSchema as BridgeIntentSchema3, toXL1BlockNumber, TransactionBoundWitnessZod } from "@xyo-network/xl1-sdk";
878
+ import { BridgeIntentFieldsZod as BridgeIntentFieldsZod2, BridgeIntentSchema as BridgeIntentSchema3, buildUnsignedTransaction, toXL1BlockNumber, TransactionBoundWitnessZod, TransferZod as TransferZod2 } from "@xyo-network/xl1-sdk";
893
879
  import { z as z3 } from "zod";
894
880
  var BridgeToRemoteEstimateBodyZod = BridgeIntentFieldsZod2.pick({
895
881
  destAddress: true,
@@ -901,7 +887,7 @@ var BridgeToRemoteEstimateResponseZod = z3.tuple([
901
887
  PayloadZodStrictOfSchema3(BridgeIntentSchema3).extend(BridgeIntentFieldsZod2.shape),
902
888
  TransferZod2
903
889
  ]);
904
- var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config) => {
890
+ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config, gateway) => {
905
891
  const params = z3.object({
906
892
  chainId: getRemoteChainIdZod(config)
907
893
  });
@@ -918,8 +904,7 @@ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config) => {
918
904
  const { srcAddress, srcAmount, destAddress } = req.body;
919
905
  const [bridgeIntent, transfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
920
906
  const sender = toAddress3(srcAddress);
921
- const gateway = await getGateway(config);
922
- const viewer = assertEx13(gateway.connection.viewer, () => new Error("Viewer not available on gateway connection"));
907
+ const viewer = assertEx14(gateway.connection.viewer, () => new Error("Viewer not available on gateway connection"));
923
908
  const currentBlockNumber = await viewer.currentBlockNumber();
924
909
  const nbf = toXL1BlockNumber(currentBlockNumber, true);
925
910
  const exp = toXL1BlockNumber(currentBlockNumber + 1e3, true);
@@ -1028,10 +1013,10 @@ var makeBridgeToRemoteStatusRoute = /* @__PURE__ */ __name((config) => {
1028
1013
  }, "makeBridgeToRemoteStatusRoute");
1029
1014
 
1030
1015
  // src/server/routes/bridge/routeDefinitions/getRouteDefinitions.ts
1031
- var getRouteDefinitions = /* @__PURE__ */ __name((config) => {
1016
+ var getRouteDefinitions = /* @__PURE__ */ __name((config, gateway) => {
1032
1017
  return [
1033
1018
  makeBridgeConfigRoute(config),
1034
- makeBridgeToRemoteEstimateRoute(config),
1019
+ makeBridgeToRemoteEstimateRoute(config, gateway),
1035
1020
  makeBridgeToRemoteRoute(config),
1036
1021
  makeBridgeToRemoteStatusRoute(config),
1037
1022
  makeBridgeFromRemoteStatusRoute(config)
@@ -1039,20 +1024,20 @@ var getRouteDefinitions = /* @__PURE__ */ __name((config) => {
1039
1024
  }, "getRouteDefinitions");
1040
1025
 
1041
1026
  // src/server/routes/bridge/addBridgeRoutes.ts
1042
- var addBridgeRoutes = /* @__PURE__ */ __name((app, config) => {
1043
- const routeDefinitions = getRouteDefinitions(config);
1027
+ var addBridgeRoutes = /* @__PURE__ */ __name((app, config, gateway) => {
1028
+ const routeDefinitions = getRouteDefinitions(config, gateway);
1044
1029
  for (const definition of routeDefinitions) {
1045
1030
  app[definition.method](definition.path, definition.handlers);
1046
1031
  }
1047
1032
  }, "addBridgeRoutes");
1048
1033
 
1049
1034
  // src/server/routes/addRoutes.ts
1050
- var addRoutes = /* @__PURE__ */ __name((app, config) => {
1051
- addBridgeRoutes(app, config);
1035
+ var addRoutes = /* @__PURE__ */ __name((app, config, gateway) => {
1036
+ addBridgeRoutes(app, config, gateway);
1052
1037
  }, "addRoutes");
1053
1038
 
1054
1039
  // src/server/app.ts
1055
- var getApp = /* @__PURE__ */ __name((node, config) => {
1040
+ var getApp = /* @__PURE__ */ __name((node, config, gateway) => {
1056
1041
  addInstrumentation();
1057
1042
  const app = express();
1058
1043
  app.set("etag", false);
@@ -1068,19 +1053,19 @@ var getApp = /* @__PURE__ */ __name((node, config) => {
1068
1053
  disableCaseSensitiveRouting(app);
1069
1054
  app.node = node;
1070
1055
  addFlowProducer(app, config);
1071
- addRoutes(app, config);
1056
+ addRoutes(app, config, gateway);
1072
1057
  app.use(standardErrors);
1073
1058
  return app;
1074
1059
  }, "getApp");
1075
1060
 
1076
1061
  // src/server/server.ts
1077
- import { assertEx as assertEx18, isDefined as isDefined15, isString } from "@xylabs/sdk-js";
1062
+ import { assertEx as assertEx19, isDefined as isDefined14, isString } from "@xylabs/sdk-js";
1078
1063
  import { boot } from "@xyo-network/bios";
1079
- import { HDWallet as HDWallet4 } from "@xyo-network/wallet";
1064
+ import { HDWallet as HDWallet3 } from "@xyo-network/wallet";
1080
1065
 
1081
1066
  // src/manifest/getModuleLocator.ts
1082
1067
  import { BaseMongoSdk } from "@xylabs/mongo";
1083
- import { assertEx as assertEx16, isDefined as isDefined13 } from "@xylabs/sdk-js";
1068
+ import { assertEx as assertEx17, isDefined as isDefined12 } from "@xylabs/sdk-js";
1084
1069
  import { MemoryArchivist } from "@xyo-network/archivist-memory";
1085
1070
  import { MongoDBArchivistV2 } from "@xyo-network/archivist-mongodb";
1086
1071
  import { ViewArchivist } from "@xyo-network/archivist-view";
@@ -1090,10 +1075,10 @@ import { initTelemetry } from "@xyo-network/chain-telemetry";
1090
1075
  import { AbstractModule, LoggerModuleStatusReporter } from "@xyo-network/module-abstract";
1091
1076
  import { ModuleFactoryLocator } from "@xyo-network/module-factory-locator";
1092
1077
  import { MemorySentinel } from "@xyo-network/sentinel-memory";
1093
- import { hasMongoConfig, mapToMapType, XyoGatewayRunnerMoniker as XyoGatewayRunnerMoniker2 } from "@xyo-network/xl1-sdk";
1078
+ import { hasMongoConfig, mapToMapType, XyoGatewayRunnerMoniker } from "@xyo-network/xl1-sdk";
1094
1079
 
1095
1080
  // src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.ts
1096
- import { asAddress as asAddress6, asHex as asHex4, assertEx as assertEx14, delay, hexFromBigInt, hexToBigInt as hexToBigInt5, isDefined as isDefined11, isUndefined as isUndefined4 } from "@xylabs/sdk-js";
1081
+ import { asAddress as asAddress6, asHex as asHex4, assertEx as assertEx15, delay, hexFromBigInt, hexToBigInt as hexToBigInt5, isDefined as isDefined10, isUndefined as isUndefined4 } from "@xylabs/sdk-js";
1097
1082
  import { PayloadBuilder as PayloadBuilder12 } from "@xyo-network/payload-builder";
1098
1083
  import { asSchema } from "@xyo-network/payload-model";
1099
1084
  import { AbstractSentinel } from "@xyo-network/sentinel-abstract";
@@ -1123,19 +1108,19 @@ var EVMLiquidityBridgeTransactionCompletionMonitorSentinel = class extends Abstr
1123
1108
  _successCounter;
1124
1109
  _wallet;
1125
1110
  get bridge() {
1126
- return assertEx14(this._bridge, () => new Error("Bridge contract not initialized"));
1111
+ return assertEx15(this._bridge, () => new Error("Bridge contract not initialized"));
1127
1112
  }
1128
1113
  get completedTransactions() {
1129
- return assertEx14(this.params.completedTransactions, () => "Completed transactions map is not defined");
1114
+ return assertEx15(this.params.completedTransactions, () => "Completed transactions map is not defined");
1130
1115
  }
1131
1116
  get jobCheckInterval() {
1132
- return isDefined11(this.config.jobCheckInterval) ? this.config.jobCheckInterval : defaultJobCheckIntervalMs;
1117
+ return isDefined10(this.config.jobCheckInterval) ? this.config.jobCheckInterval : defaultJobCheckIntervalMs;
1133
1118
  }
1134
1119
  get pendingTransactions() {
1135
- return assertEx14(this.params.pendingTransactions, () => "Pending transactions map is not defined");
1120
+ return assertEx15(this.params.pendingTransactions, () => "Pending transactions map is not defined");
1136
1121
  }
1137
1122
  get wallet() {
1138
- return assertEx14(this._wallet, () => "wallet is required");
1123
+ return assertEx15(this._wallet, () => "wallet is required");
1139
1124
  }
1140
1125
  async createHandler() {
1141
1126
  await super.createHandler();
@@ -1152,20 +1137,20 @@ var EVMLiquidityBridgeTransactionCompletionMonitorSentinel = class extends Abstr
1152
1137
  description: "Number of errors"
1153
1138
  });
1154
1139
  const { provider, bridgeAddress } = this.params;
1155
- const key = assertEx14(this.account?.private?.hex, () => new Error("Account private key is required"));
1140
+ const key = assertEx15(this.account?.private?.hex, () => new Error("Account private key is required"));
1156
1141
  this._wallet = new Wallet(key, provider);
1157
1142
  this._bridge = LiquidityPoolBridge__factory.connect(getAddress2(bridgeAddress), this._wallet);
1158
1143
  const network = await provider.getNetwork();
1159
- this._bridgeChainId = assertEx14(hexFromBigInt(network.chainId), () => new Error("Failed to parse bridgeChainId"));
1144
+ this._bridgeChainId = assertEx15(hexFromBigInt(network.chainId), () => new Error("Failed to parse bridgeChainId"));
1160
1145
  const tokenAddress = await this.bridge.token();
1161
1146
  this._bridgeTokenAddress = asAddress6(tokenAddress, true);
1162
1147
  const bridgeRemoteChain = await this.bridge.remoteChain();
1163
1148
  this._bridgeRemoteChainId = asHex4(bridgeRemoteChain);
1164
1149
  }
1165
1150
  async reportHandler(payloads) {
1166
- if (isDefined11(payloads) && payloads.length > 0) {
1151
+ if (isDefined10(payloads) && payloads.length > 0) {
1167
1152
  const signedHydratedTransaction = tryUnflattenHydratedTransaction(payloads);
1168
- if (isDefined11(signedHydratedTransaction)) {
1153
+ if (isDefined10(signedHydratedTransaction)) {
1169
1154
  const txHash = await PayloadBuilder12.hash(signedHydratedTransaction[0]);
1170
1155
  this.logger?.info(`Adding transaction ${signedHydratedTransaction[0]} with hash ${txHash} to pending transactions for monitoring`);
1171
1156
  await this.pendingTransactions.set(txHash, signedHydratedTransaction);
@@ -1193,7 +1178,7 @@ var EVMLiquidityBridgeTransactionCompletionMonitorSentinel = class extends Abstr
1193
1178
  hash,
1194
1179
  signedHydratedTransaction
1195
1180
  ]);
1196
- if (isDefined11(result)) results.push(result[1]);
1181
+ if (isDefined10(result)) results.push(result[1]);
1197
1182
  await delay(this.jobCheckInterval);
1198
1183
  }
1199
1184
  return flattenHydratedTransactions(results);
@@ -1246,7 +1231,7 @@ var EVMLiquidityBridgeTransactionCompletionMonitorSentinel = class extends Abstr
1246
1231
  };
1247
1232
 
1248
1233
  // src/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.ts
1249
- import { assertEx as assertEx15, delay as delay2, isDefined as isDefined12, isNull as isNull2, isUndefined as isUndefined5 } from "@xylabs/sdk-js";
1234
+ import { assertEx as assertEx16, delay as delay2, isDefined as isDefined11, isNull as isNull2, isUndefined as isUndefined5 } from "@xylabs/sdk-js";
1250
1235
  import { PayloadBuilder as PayloadBuilder13 } from "@xyo-network/payload-builder";
1251
1236
  import { asSchema as asSchema2 } from "@xyo-network/payload-model";
1252
1237
  import { AbstractSentinel as AbstractSentinel2 } from "@xyo-network/sentinel-abstract";
@@ -1268,16 +1253,16 @@ var XL1TransactionCompletionMonitorSentinel = class extends AbstractSentinel2 {
1268
1253
  _reportMutex = new Mutex2();
1269
1254
  _successCounter;
1270
1255
  get completedTransactions() {
1271
- return assertEx15(this.params.completedTransactions, () => "Completed transactions map is not defined");
1256
+ return assertEx16(this.params.completedTransactions, () => "Completed transactions map is not defined");
1272
1257
  }
1273
1258
  get jobCheckInterval() {
1274
- return isDefined12(this.config.jobCheckInterval) ? this.config.jobCheckInterval : defaultJobCheckIntervalMs2;
1259
+ return isDefined11(this.config.jobCheckInterval) ? this.config.jobCheckInterval : defaultJobCheckIntervalMs2;
1275
1260
  }
1276
1261
  get pendingTransactions() {
1277
- return assertEx15(this.params.pendingTransactions, () => "Pending transactions map is not defined");
1262
+ return assertEx16(this.params.pendingTransactions, () => "Pending transactions map is not defined");
1278
1263
  }
1279
1264
  get viewer() {
1280
- return assertEx15(this.params.viewer, () => "Viewer is not defined in params");
1265
+ return assertEx16(this.params.viewer, () => "Viewer is not defined in params");
1281
1266
  }
1282
1267
  async createHandler() {
1283
1268
  await super.createHandler();
@@ -1295,9 +1280,9 @@ var XL1TransactionCompletionMonitorSentinel = class extends AbstractSentinel2 {
1295
1280
  });
1296
1281
  }
1297
1282
  async reportHandler(payloads) {
1298
- if (isDefined12(payloads) && payloads.length > 0) {
1283
+ if (isDefined11(payloads) && payloads.length > 0) {
1299
1284
  const signedHydratedTransaction = tryUnflattenHydratedTransaction2(payloads);
1300
- if (isDefined12(signedHydratedTransaction)) {
1285
+ if (isDefined11(signedHydratedTransaction)) {
1301
1286
  const txHash = await PayloadBuilder13.hash(signedHydratedTransaction[0]);
1302
1287
  this.logger?.info(`Adding transaction ${signedHydratedTransaction[0]} with hash ${txHash} to pending transactions for monitoring`);
1303
1288
  await this.pendingTransactions.set(txHash, signedHydratedTransaction);
@@ -1325,7 +1310,7 @@ var XL1TransactionCompletionMonitorSentinel = class extends AbstractSentinel2 {
1325
1310
  hash,
1326
1311
  signedHydratedTransaction
1327
1312
  ]);
1328
- if (isDefined12(result)) results.push(result[1]);
1313
+ if (isDefined11(result)) results.push(result[1]);
1329
1314
  await delay2(this.jobCheckInterval);
1330
1315
  }
1331
1316
  return flattenHydratedTransactions2(results);
@@ -1337,7 +1322,7 @@ var XL1TransactionCompletionMonitorSentinel = class extends AbstractSentinel2 {
1337
1322
  this._checkCounter?.add(1);
1338
1323
  this._attemptsCounter?.add(1);
1339
1324
  const tx = await this.viewer.transactionByHash(hash);
1340
- if (isDefined12(tx) && !isNull2(tx)) {
1325
+ if (isDefined11(tx) && !isNull2(tx)) {
1341
1326
  await this.completedTransactions.set(hash, signedHydratedTransaction);
1342
1327
  this.logger?.info(`Found transaction ${signedHydratedTransaction[0]} with hash ${hash}`);
1343
1328
  this.logger?.info(`Removing completed transaction ${signedHydratedTransaction[0]} with hash ${hash}`);
@@ -1378,7 +1363,7 @@ var getModuleLocator = /* @__PURE__ */ __name(async (context) => {
1378
1363
  port
1379
1364
  }
1380
1365
  });
1381
- if (isDefined13(logger)) AbstractModule.defaultLogger = logger;
1366
+ if (isDefined12(logger)) AbstractModule.defaultLogger = logger;
1382
1367
  const statusReporter = logger ? new LoggerModuleStatusReporter(logger) : void 0;
1383
1368
  const moduleLocator = new ModuleFactoryLocator();
1384
1369
  const mongoConfig = config.storage?.mongo;
@@ -1414,8 +1399,8 @@ var getModuleLocator = /* @__PURE__ */ __name(async (context) => {
1414
1399
  meterProvider,
1415
1400
  statusReporter
1416
1401
  }));
1417
- const gateway = await locator.getInstance(XyoGatewayRunnerMoniker2);
1418
- const viewer = assertEx16(gateway.connection.viewer, () => "Gateway viewer is not defined");
1402
+ const gateway = await locator.getInstance(XyoGatewayRunnerMoniker);
1403
+ const viewer = assertEx17(gateway.connection.viewer, () => "Gateway viewer is not defined");
1419
1404
  const pendingXl1ToEthXl1BridgeIntentTransactions = await getIterableMap(config, "liquidity_bridge_xl1_to_eth_xl1_pending");
1420
1405
  const completedXl1ToEthXl1BridgeIntentTransactions = await getIterableMap(config, "liquidity_bridge_xl1_to_eth_xl1_completed");
1421
1406
  const xl1TransactionCompletionMonitorSentinelParams = {
@@ -1480,7 +1465,7 @@ var getIterableMap = /* @__PURE__ */ __name(async (config, collection) => {
1480
1465
 
1481
1466
  // src/manifest/getNode.ts
1482
1467
  import { ManifestWrapper } from "@xyo-network/manifest-wrapper";
1483
- import { buildJsonRpcProviderLocator as buildJsonRpcProviderLocator2, HttpRpcTransport as HttpRpcTransport2 } from "@xyo-network/xl1-sdk";
1468
+ import { buildJsonRpcProviderLocator, HttpRpcTransport } from "@xyo-network/xl1-sdk";
1484
1469
 
1485
1470
  // src/manifest/node.json
1486
1471
  var node_default = {
@@ -1508,9 +1493,9 @@ var NodeManifest = node_default;
1508
1493
  var getNode = /* @__PURE__ */ __name(async (context) => {
1509
1494
  const { config, wallet } = context;
1510
1495
  const { chainRpcApiUrl: endpoint } = config.actors.bridge;
1511
- const transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport2(endpoint, schemas), "transportFactory");
1496
+ const transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport(endpoint, schemas), "transportFactory");
1512
1497
  const signerAccount = await getBridgeWalletAccount(config);
1513
- const locator = await buildJsonRpcProviderLocator2({
1498
+ const locator = await buildJsonRpcProviderLocator({
1514
1499
  signerAccount,
1515
1500
  transportFactory
1516
1501
  });
@@ -1528,10 +1513,10 @@ var getNode = /* @__PURE__ */ __name(async (context) => {
1528
1513
  }, "getNode");
1529
1514
 
1530
1515
  // src/manifest/getServices.ts
1531
- import { assertEx as assertEx17, isDefined as isDefined14 } from "@xylabs/sdk-js";
1516
+ import { assertEx as assertEx18, isDefined as isDefined13 } from "@xylabs/sdk-js";
1532
1517
  import { initEvmProvider as initEvmProvider2 } from "@xyo-network/chain-orchestration";
1533
1518
  import { BridgeableToken__factory, LiquidityPoolBridge__factory as LiquidityPoolBridge__factory2 } from "@xyo-network/typechain";
1534
- import { HDWallet as HDWallet3 } from "@xyo-network/wallet";
1519
+ import { HDWallet as HDWallet2 } from "@xyo-network/wallet";
1535
1520
  import { getAddress as getAddress3, Wallet as Wallet2 } from "ethers";
1536
1521
 
1537
1522
  // src/manifest/getIterableMap.ts
@@ -1567,21 +1552,20 @@ var getIterableMap2 = /* @__PURE__ */ __name(async (config, collection) => {
1567
1552
  }, "getIterableMap");
1568
1553
 
1569
1554
  // src/manifest/getServices.ts
1570
- var getServices = /* @__PURE__ */ __name(async (context) => {
1555
+ var getServices = /* @__PURE__ */ __name(async (context, gateway) => {
1571
1556
  const { config } = context;
1572
- const gateway = await getGateway(config);
1573
1557
  const ethTxStateMap = await getIterableMap2(config, "liquidity_bridge_xl1_to_eth_eth_tx_state");
1574
1558
  const xl1TxStateMap = await getIterableMap2(config, "liquidity_bridge_xl1_to_eth_xl1_tx_state");
1575
1559
  const provider = await initEvmProvider2({
1576
1560
  config
1577
1561
  });
1578
1562
  const { remoteBridgeContractAddress, remoteChainWalletPrivateKey, remoteTokenAddress, mnemonic } = config.actors.bridge;
1579
- const account = isDefined14(mnemonic) ? await HDWallet3.fromPhrase(mnemonic) : await HDWallet3.random();
1563
+ const account = isDefined13(mnemonic) ? await HDWallet2.fromPhrase(mnemonic) : await HDWallet2.random();
1580
1564
  const wallet = new Wallet2(remoteChainWalletPrivateKey, provider);
1581
1565
  const bridgeableToken = BridgeableToken__factory.connect(getAddress3(remoteTokenAddress), wallet);
1582
1566
  const bridge = LiquidityPoolBridge__factory2.connect(getAddress3(remoteBridgeContractAddress), wallet);
1583
1567
  const bridgeOwner = await bridge.owner();
1584
- assertEx17(bridgeOwner.toLowerCase() === wallet.address.toLowerCase(), () => "Wallet is not the owner of the bridge contract");
1568
+ assertEx18(bridgeOwner.toLowerCase() === wallet.address.toLowerCase(), () => "Wallet is not the owner of the bridge contract");
1585
1569
  return {
1586
1570
  account,
1587
1571
  bridge,
@@ -1614,38 +1598,79 @@ var getSeedPhrase = /* @__PURE__ */ __name(async (bios, config, logger) => {
1614
1598
  if (isString(mnemonic)) {
1615
1599
  seedPhrase = mnemonic;
1616
1600
  } else {
1617
- seedPhrase = HDWallet4.generateMnemonic();
1601
+ seedPhrase = HDWallet3.generateMnemonic();
1618
1602
  logger?.log("[Bridge] No mnemonic provided, using random mnemonic. This is not recommended for production use.");
1619
1603
  logger?.log(`[Bridge] Mnemonic: ${seedPhrase}`);
1620
1604
  }
1621
1605
  await bios.seedPhraseStore.set("os", seedPhrase);
1622
1606
  }
1623
- return assertEx18(await bios.seedPhraseStore.get("os"), () => "Unable to acquire mnemonic from bios");
1607
+ return assertEx19(await bios.seedPhraseStore.get("os"), () => "Unable to acquire mnemonic from bios");
1624
1608
  }, "getSeedPhrase");
1625
- var getServer = /* @__PURE__ */ __name(async (context) => {
1609
+ var getServer = /* @__PURE__ */ __name(async (context, gateway) => {
1626
1610
  const { logger, config } = context;
1627
1611
  const { port, mnemonic } = config.actors.bridge;
1628
1612
  const bios = await boot();
1629
- const seedPhrase = isDefined15(mnemonic) ? mnemonic : await getSeedPhrase(bios, config, logger);
1630
- const wallet = await HDWallet4.fromPhrase(seedPhrase);
1613
+ const seedPhrase = isDefined14(mnemonic) ? mnemonic : await getSeedPhrase(bios, config, logger);
1614
+ const wallet = await HDWallet3.fromPhrase(seedPhrase);
1631
1615
  const nodeContext = {
1632
1616
  wallet,
1633
1617
  logger,
1634
1618
  config
1635
1619
  };
1636
1620
  const node = context.node ?? await getNode(nodeContext);
1637
- const app = getApp(node, config);
1621
+ const app = getApp(node, config, gateway);
1638
1622
  const services = await getServices({
1639
1623
  config,
1640
1624
  logger
1641
- });
1625
+ }, gateway);
1642
1626
  addWorkers(config, services);
1643
1627
  const server = app.listen(port, hostname, () => logger?.log(`[Bridge] Server listening at http://${hostname}:${port}`));
1644
1628
  server.setTimeout(2e4);
1645
1629
  return server;
1646
1630
  }, "getServer");
1631
+
1632
+ // src/BridgeActor.ts
1633
+ function _ts_decorate(decorators, target, key, desc) {
1634
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1635
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
1636
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1637
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
1638
+ }
1639
+ __name(_ts_decorate, "_ts_decorate");
1640
+ var BridgeActor = class extends ActorV3 {
1641
+ static {
1642
+ __name(this, "BridgeActor");
1643
+ }
1644
+ _gatewayRunner;
1645
+ server;
1646
+ get gatewayRunner() {
1647
+ return this._gatewayRunner;
1648
+ }
1649
+ async createHandler() {
1650
+ await super.createHandler();
1651
+ this._gatewayRunner = await this.locator.getInstance(XyoGatewayRunnerMoniker2);
1652
+ }
1653
+ async startHandler() {
1654
+ await super.startHandler();
1655
+ this.stopServer();
1656
+ await this.startServer();
1657
+ }
1658
+ async stopHandler() {
1659
+ await super.stopHandler();
1660
+ this.stopServer();
1661
+ }
1662
+ async startServer() {
1663
+ this.server = await getServer(this.context, this._gatewayRunner);
1664
+ }
1665
+ stopServer() {
1666
+ this.server?.close();
1667
+ this.server = void 0;
1668
+ }
1669
+ };
1670
+ BridgeActor = _ts_decorate([
1671
+ creatable()
1672
+ ], BridgeActor);
1647
1673
  export {
1648
- getApp,
1649
- getServer
1674
+ BridgeActor
1650
1675
  };
1651
1676
  //# sourceMappingURL=index.mjs.map