@xyo-network/chain-bridge 1.17.2 → 1.17.3

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 (160) hide show
  1. package/dist/node/config/asChainId.d.ts +3 -0
  2. package/dist/node/config/asChainId.d.ts.map +1 -0
  3. package/dist/node/config/asToken.d.ts +3 -0
  4. package/dist/node/config/asToken.d.ts.map +1 -0
  5. package/dist/node/config/getBridgeEscrowAddress.d.ts +5 -0
  6. package/dist/node/config/getBridgeEscrowAddress.d.ts.map +1 -0
  7. package/dist/node/config/getBridgeFeesAddress.d.ts +5 -0
  8. package/dist/node/config/getBridgeFeesAddress.d.ts.map +1 -0
  9. package/dist/node/config/getBridgeSettings.d.ts +3 -0
  10. package/dist/node/config/getBridgeSettings.d.ts.map +1 -0
  11. package/dist/node/config/getBridgeWalletAccount.d.ts +6 -0
  12. package/dist/node/config/getBridgeWalletAccount.d.ts.map +1 -0
  13. package/dist/node/config/getFeeStructure.d.ts +4 -0
  14. package/dist/node/config/getFeeStructure.d.ts.map +1 -0
  15. package/dist/node/config/getGateway.d.ts +3 -0
  16. package/dist/node/config/getGateway.d.ts.map +1 -0
  17. package/dist/node/config/getMaxBridgeAmount.d.ts +4 -0
  18. package/dist/node/config/getMaxBridgeAmount.d.ts.map +1 -0
  19. package/dist/node/config/getMinBridgeAmount.d.ts +4 -0
  20. package/dist/node/config/getMinBridgeAmount.d.ts.map +1 -0
  21. package/dist/node/config/getRemoteChainId.d.ts +4 -0
  22. package/dist/node/config/getRemoteChainId.d.ts.map +1 -0
  23. package/dist/node/config/getRemoteTokenAddress.d.ts +4 -0
  24. package/dist/node/config/getRemoteTokenAddress.d.ts.map +1 -0
  25. package/dist/node/config/getTransferAddresses.d.ts +8 -0
  26. package/dist/node/config/getTransferAddresses.d.ts.map +1 -0
  27. package/dist/node/config/getXl1ChainId.d.ts +4 -0
  28. package/dist/node/config/getXl1ChainId.d.ts.map +1 -0
  29. package/dist/node/config/getXl1TokenAddress.d.ts +4 -0
  30. package/dist/node/config/getXl1TokenAddress.d.ts.map +1 -0
  31. package/dist/node/config/index.d.ts +16 -0
  32. package/dist/node/config/index.d.ts.map +1 -0
  33. package/dist/node/index.mjs +1133 -206
  34. package/dist/node/index.mjs.map +1 -1
  35. package/dist/node/interface/service/Observer/LiquidityPoolBridgeObserver/LiquidityPoolBridgeObserver.d.ts.map +1 -1
  36. package/dist/node/manifest/getLocator.d.ts.map +1 -1
  37. package/dist/node/manifest/public/index.d.ts +0 -4
  38. package/dist/node/manifest/public/index.d.ts.map +1 -1
  39. package/dist/node/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.d.ts +77 -0
  40. package/dist/node/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.d.ts.map +1 -0
  41. package/dist/node/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/index.d.ts +2 -0
  42. package/dist/node/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/index.d.ts.map +1 -0
  43. package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.d.ts +56 -0
  44. package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.d.ts.map +1 -0
  45. package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/index.d.ts +2 -0
  46. package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/index.d.ts.map +1 -0
  47. package/dist/node/modules/index.d.ts +2 -1
  48. package/dist/node/modules/index.d.ts.map +1 -1
  49. package/dist/node/server/app.d.ts +3 -1
  50. package/dist/node/server/app.d.ts.map +1 -1
  51. package/dist/node/server/routes/addRoutes.d.ts +2 -1
  52. package/dist/node/server/routes/addRoutes.d.ts.map +1 -1
  53. package/dist/node/server/routes/bridge/addBridgeRoutes.d.ts +2 -1
  54. package/dist/node/server/routes/bridge/addBridgeRoutes.d.ts.map +1 -1
  55. package/dist/node/server/routes/bridge/routeDefinitions/getRouteDefinitions.d.ts +2 -1
  56. package/dist/node/server/routes/bridge/routeDefinitions/getRouteDefinitions.d.ts.map +1 -1
  57. package/dist/node/server/routes/bridge/routeDefinitions/pathParams/ChainIdPathParam.d.ts +2 -1
  58. package/dist/node/server/routes/bridge/routeDefinitions/pathParams/ChainIdPathParam.d.ts.map +1 -1
  59. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeConfig.d.ts +4 -0
  60. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeConfig.d.ts.map +1 -0
  61. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.d.ts +2 -1
  62. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.d.ts.map +1 -1
  63. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.d.ts +2 -1
  64. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.d.ts.map +1 -1
  65. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.d.ts +2 -1
  66. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.d.ts.map +1 -1
  67. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.d.ts +2 -1
  68. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.d.ts.map +1 -1
  69. package/dist/node/server/routes/bridge/routeDefinitions/routes/index.d.ts +1 -0
  70. package/dist/node/server/routes/bridge/routeDefinitions/routes/index.d.ts.map +1 -1
  71. package/dist/node/server/routes/index.d.ts +0 -2
  72. package/dist/node/server/routes/index.d.ts.map +1 -1
  73. package/dist/node/server/server.d.ts +1 -1
  74. package/dist/node/server/server.d.ts.map +1 -1
  75. package/dist/node/util/calculateBridgeFees.d.ts +10 -0
  76. package/dist/node/util/calculateBridgeFees.d.ts.map +1 -0
  77. package/dist/node/util/generateBridgeEstimate.d.ts +5 -0
  78. package/dist/node/util/generateBridgeEstimate.d.ts.map +1 -0
  79. package/dist/node/util/index.d.ts +5 -0
  80. package/dist/node/util/index.d.ts.map +1 -0
  81. package/dist/node/util/validateBridgeEstimate.d.ts +13 -0
  82. package/dist/node/util/validateBridgeEstimate.d.ts.map +1 -0
  83. package/dist/node/util/validateBridgeEstimateExact.d.ts +12 -0
  84. package/dist/node/util/validateBridgeEstimateExact.d.ts.map +1 -0
  85. package/package.json +29 -14
  86. package/src/config/asChainId.ts +7 -0
  87. package/src/config/asToken.ts +7 -0
  88. package/src/config/getBridgeEscrowAddress.ts +13 -0
  89. package/src/config/getBridgeFeesAddress.ts +13 -0
  90. package/src/config/getBridgeSettings.ts +24 -0
  91. package/src/config/getBridgeWalletAccount.ts +34 -0
  92. package/src/config/getFeeStructure.ts +8 -0
  93. package/src/config/getGateway.ts +19 -0
  94. package/src/config/getMaxBridgeAmount.ts +7 -0
  95. package/src/config/getMinBridgeAmount.ts +7 -0
  96. package/src/config/getRemoteChainId.ts +10 -0
  97. package/src/config/getRemoteTokenAddress.ts +10 -0
  98. package/src/config/getTransferAddresses.ts +17 -0
  99. package/src/config/getXl1ChainId.ts +13 -0
  100. package/src/config/getXl1TokenAddress.ts +12 -0
  101. package/src/config/index.ts +15 -0
  102. package/src/interface/service/Observer/LiquidityPoolBridgeObserver/LiquidityPoolBridgeObserver.ts +1 -2
  103. package/src/manifest/getLocator.ts +97 -34
  104. package/src/manifest/public/Ethereum.json +24 -64
  105. package/src/manifest/public/XL1.json +24 -64
  106. package/src/manifest/public/index.ts +0 -6
  107. package/src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.ts +234 -0
  108. package/src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/index.ts +1 -0
  109. package/src/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.ts +166 -0
  110. package/src/modules/XL1TransactionCompletionMonitorSentinel/index.ts +1 -0
  111. package/src/modules/index.ts +2 -1
  112. package/src/server/app.ts +5 -4
  113. package/src/server/routes/addRoutes.ts +3 -2
  114. package/src/server/routes/bridge/addBridgeRoutes.ts +3 -2
  115. package/src/server/routes/bridge/routeDefinitions/getRouteDefinitions.ts +8 -6
  116. package/src/server/routes/bridge/routeDefinitions/pathParams/ChainIdPathParam.ts +16 -13
  117. package/src/server/routes/bridge/routeDefinitions/routes/bridgeConfig.ts +43 -0
  118. package/src/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.ts +40 -37
  119. package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.ts +74 -45
  120. package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts +48 -75
  121. package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts +95 -47
  122. package/src/server/routes/bridge/routeDefinitions/routes/index.ts +1 -0
  123. package/src/server/routes/index.ts +0 -2
  124. package/src/server/server.ts +37 -31
  125. package/src/util/calculateBridgeFees.ts +39 -0
  126. package/src/util/generateBridgeEstimate.ts +64 -0
  127. package/src/util/index.ts +4 -0
  128. package/src/util/validateBridgeEstimate.ts +60 -0
  129. package/src/util/validateBridgeEstimateExact.ts +34 -0
  130. package/dist/node/modules/XL1toEvmBridgeSentinel/XL1toEvmBridgeSentinel.d.ts +0 -47
  131. package/dist/node/modules/XL1toEvmBridgeSentinel/XL1toEvmBridgeSentinel.d.ts.map +0 -1
  132. package/dist/node/modules/XL1toEvmBridgeSentinel/index.d.ts +0 -2
  133. package/dist/node/modules/XL1toEvmBridgeSentinel/index.d.ts.map +0 -1
  134. package/dist/node/server/routes/address/AddressPathParams.d.ts +0 -4
  135. package/dist/node/server/routes/address/AddressPathParams.d.ts.map +0 -1
  136. package/dist/node/server/routes/address/addNodeRoutes.d.ts +0 -3
  137. package/dist/node/server/routes/address/addNodeRoutes.d.ts.map +0 -1
  138. package/dist/node/server/routes/address/get/get.d.ts +0 -4
  139. package/dist/node/server/routes/address/get/get.d.ts.map +0 -1
  140. package/dist/node/server/routes/address/get/index.d.ts +0 -2
  141. package/dist/node/server/routes/address/get/index.d.ts.map +0 -1
  142. package/dist/node/server/routes/address/index.d.ts +0 -2
  143. package/dist/node/server/routes/address/index.d.ts.map +0 -1
  144. package/dist/node/server/routes/address/post/getQueryConfig.d.ts +0 -6
  145. package/dist/node/server/routes/address/post/getQueryConfig.d.ts.map +0 -1
  146. package/dist/node/server/routes/address/post/index.d.ts +0 -2
  147. package/dist/node/server/routes/address/post/index.d.ts.map +0 -1
  148. package/dist/node/server/routes/address/post/post.d.ts +0 -8
  149. package/dist/node/server/routes/address/post/post.d.ts.map +0 -1
  150. package/src/manifest/public/Chain.json +0 -32
  151. package/src/modules/XL1toEvmBridgeSentinel/XL1toEvmBridgeSentinel.ts +0 -156
  152. package/src/modules/XL1toEvmBridgeSentinel/index.ts +0 -1
  153. package/src/server/routes/address/AddressPathParams.ts +0 -3
  154. package/src/server/routes/address/addNodeRoutes.ts +0 -21
  155. package/src/server/routes/address/get/get.ts +0 -30
  156. package/src/server/routes/address/get/index.ts +0 -1
  157. package/src/server/routes/address/index.ts +0 -1
  158. package/src/server/routes/address/post/getQueryConfig.ts +0 -23
  159. package/src/server/routes/address/post/index.ts +0 -1
  160. package/src/server/routes/address/post/post.ts +0 -77
@@ -1,4 +0,0 @@
1
- export type AddressPathParams = {
2
- address: string;
3
- };
4
- //# sourceMappingURL=AddressPathParams.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AddressPathParams.d.ts","sourceRoot":"","sources":["../../../../../src/server/routes/address/AddressPathParams.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA"}
@@ -1,3 +0,0 @@
1
- import type { Express } from 'express';
2
- export declare const addNodeRoutes: (app: Express) => void;
3
- //# sourceMappingURL=addNodeRoutes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"addNodeRoutes.d.ts","sourceRoot":"","sources":["../../../../../src/server/routes/address/addNodeRoutes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAMtC,eAAO,MAAM,aAAa,GAAI,KAAK,OAAO,SAczC,CAAA"}
@@ -1,4 +0,0 @@
1
- import type { Payload } from '@xyo-network/payload-model';
2
- import type { AddressPathParams } from '../AddressPathParams.ts';
3
- export declare const getAddress: (req: import("express").Request<AddressPathParams, Payload[], any, import("qs").ParsedQs, Record<string, any>>, res: import("express").Response<Payload[], Record<string, any>>, next: import("express").NextFunction) => Promise<unknown>;
4
- //# sourceMappingURL=get.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get.d.ts","sourceRoot":"","sources":["../../../../../../src/server/routes/address/get/get.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAIzD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAsBhE,eAAO,MAAM,UAAU,4OAAwB,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './get.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/server/routes/address/get/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './addNodeRoutes.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/server/routes/address/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA"}
@@ -1,6 +0,0 @@
1
- import type { QueryBoundWitness } from '@xyo-network/boundwitness-model';
2
- import type { ModuleConfig, ModuleInstance } from '@xyo-network/module-model';
3
- import type { Payload } from '@xyo-network/payload-model';
4
- import type { Request } from 'express';
5
- export declare const getQueryConfig: (mod: ModuleInstance, req: Request, bw: QueryBoundWitness, payloads?: Payload[]) => ModuleConfig | undefined;
6
- //# sourceMappingURL=getQueryConfig.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getQueryConfig.d.ts","sourceRoot":"","sources":["../../../../../../src/server/routes/address/post/getQueryConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAEtF,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAE7E,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAItC,eAAO,MAAM,cAAc,GAAI,KAAK,cAAc,EAAE,KAAK,OAAO,EAAE,IAAI,iBAAiB,EAAE,WAAW,OAAO,EAAE,KAAG,YAAY,GAAG,SAa9H,CAAA"}
@@ -1,2 +0,0 @@
1
- export * from './post.ts';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/server/routes/address/post/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
@@ -1,8 +0,0 @@
1
- import { type QueryBoundWitness } from '@xyo-network/boundwitness-model';
2
- import type { ModuleQueryResult } from '@xyo-network/module-model';
3
- import type { ModuleError, Payload } from '@xyo-network/payload-model';
4
- import type { AddressPathParams } from '../AddressPathParams.ts';
5
- type PostAddressRequestBody = [QueryBoundWitness, undefined | Payload[]];
6
- export declare const postAddress: (req: import("express").Request<AddressPathParams, ModuleError | ModuleQueryResult, PostAddressRequestBody, import("qs").ParsedQs, Record<string, any>>, res: import("express").Response<ModuleError | ModuleQueryResult, Record<string, any>>, next: import("express").NextFunction) => Promise<unknown>;
7
- export {};
8
- //# sourceMappingURL=post.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../../../../../src/server/routes/address/post/post.ts"],"names":[],"mappings":"AAOA,OAAO,EAAuB,KAAK,iBAAiB,EAAE,MAAM,iCAAiC,CAAA;AAE7F,OAAO,KAAK,EAAkB,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAA;AAItE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAGhE,KAAK,sBAAsB,GAAG,CAAC,iBAAiB,EAAE,SAAS,GAAG,OAAO,EAAE,CAAC,CAAA;AA2DxE,eAAO,MAAM,WAAW,2SAAwB,CAAA"}
@@ -1,32 +0,0 @@
1
- {
2
- "$schema": "https://raw.githubusercontent.com/XYOracleNetwork/sdk-xyo-client-js/main/packages/manifest/src/schema.json",
3
- "nodes": [
4
- {
5
- "config": {
6
- "accountPath": "1",
7
- "name": "Chain",
8
- "schema": "network.xyo.node.config"
9
- },
10
- "modules": {
11
- "private": [],
12
- "public": [
13
- {
14
- "config": {
15
- "accountPath": "1/1/1",
16
- "name": "Finalized",
17
- "getCache": {
18
- "enabled": true,
19
- "maxEntries": 5000
20
- },
21
- "payloadSdkConfig": {
22
- "collection": "chain_validated"
23
- },
24
- "schema": "network.xyo.archivist.config"
25
- }
26
- }
27
- ]
28
- }
29
- }
30
- ],
31
- "schema": "network.xyo.manifest"
32
- }
@@ -1,156 +0,0 @@
1
- import type { Attributes, Counter } from '@opentelemetry/api'
2
- import {
3
- assertEx, delay, isDefined, isUndefined,
4
- } from '@xylabs/sdk-js'
5
- import type { AnyConfigSchema } from '@xyo-network/module-model'
6
- import type { Payload } from '@xyo-network/payload-model'
7
- import { AbstractSentinel } from '@xyo-network/sentinel-abstract'
8
- import type {
9
- SentinelConfig, SentinelInstance, SentinelModuleEventData, SentinelParams,
10
- } from '@xyo-network/sentinel-model'
11
- import type { BridgeIntent, SignedHydratedTransaction } from '@xyo-network/xl1-protocol'
12
- import { asXL1BlockNumber, isBridgeIntent } from '@xyo-network/xl1-protocol'
13
- import type {
14
- XyoConnection, XyoGatewayRunner, XyoViewer,
15
- } from '@xyo-network/xl1-protocol-sdk'
16
- import { flattenHydratedTransaction, flattenHydratedTransactions } from '@xyo-network/xl1-protocol-sdk'
17
- import { Mutex } from 'async-mutex'
18
-
19
- export const XL1toEvmBridgeSentinelConfigSchema = 'network.xyo.sentinel.chain.evm.bridge.config'
20
- export type XL1toEvmBridgeSentinelConfigSchema = typeof XL1toEvmBridgeSentinelConfigSchema
21
-
22
- /**
23
- * The configuration for the XL1 to EVM bridge sentinel
24
- */
25
- export type XL1toEvmBridgeSentinelConfig = SentinelConfig<{
26
- /**
27
- * The interval in milliseconds between checking for bridging intents to fulfill
28
- */
29
- bridgeIntentFulfillmentInterval: number
30
- /**
31
- * The schema for the XL1 to EVM bridge sentinel config
32
- */
33
- schema: XL1toEvmBridgeSentinelConfigSchema
34
-
35
- }>
36
-
37
- interface XL1toEvmBridgeSentinelParamFields {
38
- gateway: XyoGatewayRunner
39
- }
40
-
41
- export type XL1toEvmBridgeSentinelParams<
42
- TConfig extends AnyConfigSchema<XL1toEvmBridgeSentinelConfig> = AnyConfigSchema<XL1toEvmBridgeSentinelConfig>,
43
- > = SentinelParams<TConfig> & XL1toEvmBridgeSentinelParamFields
44
-
45
- const defaultStepClaimIntervalMs = 15_000
46
-
47
- export class XL1toEvmBridgeSentinel<
48
- TParams extends XL1toEvmBridgeSentinelParams = XL1toEvmBridgeSentinelParams,
49
- TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,
50
- > extends AbstractSentinel<TParams, TEventData> {
51
- static override readonly configSchemas = [XL1toEvmBridgeSentinelConfigSchema]
52
- static override readonly defaultConfigSchema = XL1toEvmBridgeSentinelConfigSchema
53
- private _bridgeAttemptsCounter: Counter<Attributes> | undefined
54
- private _bridgeCheckCounter: Counter<Attributes> | undefined
55
- private _bridgeErrorCounter: Counter<Attributes> | undefined
56
- private _bridgeSuccessCounter: Counter<Attributes> | undefined
57
- private _connection: XyoConnection | undefined
58
- private _gateway: XyoGatewayRunner | undefined
59
- private _reportMutex = new Mutex()
60
- private _viewer: XyoViewer | undefined
61
-
62
- protected get bridgeIntentFulfillmentInterval(): number {
63
- return isDefined(this.config.bridgeIntentFulfillmentInterval) ? this.config.bridgeIntentFulfillmentInterval : defaultStepClaimIntervalMs
64
- }
65
-
66
- protected get connection(): XyoConnection {
67
- return assertEx(this._connection, () => 'Connection is not defined')
68
- }
69
-
70
- protected get gateway(): XyoGatewayRunner {
71
- return assertEx(this._gateway, () => 'Gateway is not defined')
72
- }
73
-
74
- protected get viewer(): XyoViewer {
75
- return assertEx(this._viewer, () => 'Viewer is not defined')
76
- }
77
-
78
- override async createHandler(): Promise<void> {
79
- await super.createHandler()
80
- // Create meters for tracking bridge attempts, successes, and errors.
81
- this._bridgeAttemptsCounter = this.meter?.createCounter('xl1_to_evm_bridge_sentinel_attempts_total', { description: 'Number of bridge attempts' })
82
- this._bridgeCheckCounter = this.meter?.createCounter('xl1_to_evm_bridge_sentinel_check_total', { description: 'Number of bridge checks' })
83
- this._bridgeSuccessCounter = this.meter?.createCounter('xl1_to_evm_bridge_sentinel_success_total', { description: 'Number of bridge successes' })
84
- this._bridgeErrorCounter = this.meter?.createCounter('xl1_to_evm_bridge_sentinel_errors_total', { description: 'Number of bridge errors' })
85
-
86
- const gateway = assertEx(this.params.gateway, () => 'Gateway parameter is required')
87
- const connection = assertEx(gateway.connectionInstance, () => 'Gateway connection is required')
88
- const viewer = assertEx(connection.viewer, () => 'Viewer is not defined in gateway connection')
89
- this._gateway = gateway
90
- this._connection = connection
91
- this._viewer = viewer
92
- }
93
-
94
- override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {
95
- if (this._reportMutex.isLocked()) {
96
- this.logger?.debug(`XL1toEvmBridgeSentinel [${this.id}] is already running, skipping report [${Date.now()}]`)
97
- return []
98
- }
99
- return await this._reportMutex.runExclusive(async () => {
100
- const response: Payload[] = []
101
- if (isUndefined(payloads) || payloads.length === 0) {
102
- await this.processAllBridgeIntents()
103
- } else {
104
- // Process provided payloads
105
- const bridgeIntentsToProcess = payloads.filter(isBridgeIntent)
106
- for (const bridgeIntent of bridgeIntentsToProcess) {
107
- const result = await this.processBridgeIntent(bridgeIntent)
108
- if (isDefined(result)) response.push(...flattenHydratedTransaction(result))
109
- }
110
- }
111
- return response
112
- })
113
- }
114
-
115
- private async processAllBridgeIntents(): Promise<Payload[]> {
116
- // No payloads to process, just do unprocessed bridge intents since last run
117
- const results: SignedHydratedTransaction[] = []
118
- // TODO: Grab from iterable map of pending bridge intents
119
- const bridgeIntents: BridgeIntent[] = []
120
-
121
- for (const bridgeIntent of bridgeIntents) {
122
- const result = await this.processBridgeIntent(bridgeIntent)
123
- if (isDefined(result)) {
124
- results.push(result)
125
- }
126
- await delay(this.bridgeIntentFulfillmentInterval)
127
- }
128
- return flattenHydratedTransactions(results)
129
- }
130
-
131
- private async processBridgeIntent(bridgeIntent: BridgeIntent): Promise<SignedHydratedTransaction | undefined> {
132
- this.logger?.info(`Processing bridge request for ${bridgeIntent.srcAddress} with nonce ${bridgeIntent.nonce}`)
133
- try {
134
- this._bridgeCheckCounter?.add(1)
135
- this._bridgeAttemptsCounter?.add(1)
136
- // Create single transaction for all claims
137
- const tx = await this.submitBridgeInitiationTransaction(bridgeIntent, this.gateway)
138
- this.logger?.info(`Claimed rewards for ${bridgeIntent.srcAddress} with nonce ${bridgeIntent.nonce}`)
139
- this._bridgeSuccessCounter?.add(1)
140
- // Return submitted transaction
141
- return tx
142
- } catch (error) {
143
- this._bridgeErrorCounter?.add(1)
144
- this.logger?.error(`Error claiming rewards for ${bridgeIntent.srcAddress} with nonce ${bridgeIntent.nonce}:`, error)
145
- }
146
- }
147
-
148
- private async submitBridgeInitiationTransaction(
149
- bridgeIntent: BridgeIntent,
150
- gateway: XyoGatewayRunner,
151
- ): Promise<SignedHydratedTransaction | undefined> {
152
- const currentBlockNumber = await this.viewer.currentBlockNumber()
153
- const result = await gateway.addPayloadsToChain?.([], [], { nbf: currentBlockNumber, exp: asXL1BlockNumber(currentBlockNumber + 10) })
154
- if (isDefined(result)) return result[1]
155
- }
156
- }
@@ -1 +0,0 @@
1
- export * from './XL1toEvmBridgeSentinel.ts'
@@ -1,3 +0,0 @@
1
- export type AddressPathParams = {
2
- address: string
3
- }
@@ -1,21 +0,0 @@
1
- import type { Express } from 'express'
2
- import { StatusCodes } from 'http-status-codes'
3
-
4
- import { getAddress } from './get/index.ts'
5
- import { postAddress } from './post/index.ts'
6
-
7
- export const addNodeRoutes = (app: Express) => {
8
- const defaultModule = app.node
9
- const address = defaultModule.address
10
- const defaultModuleEndpoint = `/${address}`
11
- app.get('/', (_req, res) => res.redirect(StatusCodes.MOVED_TEMPORARILY, defaultModuleEndpoint))
12
- app.post('/', (_req, res) => res.redirect(StatusCodes.TEMPORARY_REDIRECT, defaultModuleEndpoint))
13
- app.get('/:address', getAddress)
14
- app.post('/:address', postAddress)
15
- app.get('/:hash', (_req, res) => {
16
- res.sendStatus(StatusCodes.NOT_FOUND)
17
- })
18
- app.post('/:hash', (_req, res) => {
19
- res.sendStatus(StatusCodes.NOT_FOUND)
20
- })
21
- }
@@ -1,30 +0,0 @@
1
- import { asyncHandler } from '@xylabs/express'
2
- import { asAddress, isDefined } from '@xylabs/sdk-js'
3
- import { isModuleName } from '@xyo-network/module-model'
4
- import type { Payload } from '@xyo-network/payload-model'
5
- import type { RequestHandler } from 'express'
6
- import { StatusCodes } from 'http-status-codes'
7
-
8
- import type { AddressPathParams } from '../AddressPathParams.ts'
9
-
10
- const handler: RequestHandler<AddressPathParams, Payload[]> = async (req, res, next) => {
11
- const { address: moduleIdentifier } = req.params
12
- const { node } = req.app
13
- const address = asAddress(moduleIdentifier)
14
- if (isDefined(address)) {
15
- let mod = node.address === address ? node : (await node.resolve(address, { direction: 'down' }))
16
- if (mod) {
17
- res.json(await mod.state())
18
- return
19
- }
20
- }
21
- if (isModuleName(moduleIdentifier)) {
22
- const mod = await node.resolve(moduleIdentifier, { direction: 'down' })
23
- if (mod) {
24
- res.redirect(StatusCodes.MOVED_TEMPORARILY, `/${mod.address}`)
25
- return
26
- }
27
- }
28
- next('route')
29
- }
30
- export const getAddress = asyncHandler(handler)
@@ -1 +0,0 @@
1
- export * from './get.ts'
@@ -1 +0,0 @@
1
- export * from './addNodeRoutes.ts'
@@ -1,23 +0,0 @@
1
- import type { BoundWitness, QueryBoundWitness } from '@xyo-network/boundwitness-model'
2
- import { BoundWitnessSchema } from '@xyo-network/boundwitness-model'
3
- import type { ModuleConfig, ModuleInstance } from '@xyo-network/module-model'
4
- import { ModuleConfigSchema } from '@xyo-network/module-model'
5
- import type { Payload } from '@xyo-network/payload-model'
6
- import type { Request } from 'express'
7
-
8
- const DEFAULT_DEPTH = 5 as const
9
-
10
- export const getQueryConfig = (mod: ModuleInstance, req: Request, bw: QueryBoundWitness, payloads?: Payload[]): ModuleConfig | undefined => {
11
- // TODO: Filter based on query addresses?
12
- // Recurse through payloads for nested BWs
13
- const nestedBwAddresses
14
- = payloads
15
- ?.flat(DEFAULT_DEPTH)
16
- .filter<BoundWitness>((payload): payload is BoundWitness => payload?.schema === BoundWitnessSchema)
17
- .map(bw => bw.addresses) ?? []
18
- // TODO: Do we want to end up with a list of addresses or a list of address lists?
19
- const addresses = [bw.addresses, ...nestedBwAddresses].filter(address => address.length > 0)
20
- const allowed = addresses.length > 0 ? Object.fromEntries(mod.queries.map(schema => [schema, addresses])) : {}
21
- const security = { allowed }
22
- return { schema: ModuleConfigSchema, security }
23
- }
@@ -1 +0,0 @@
1
- export * from './post.ts'
@@ -1,77 +0,0 @@
1
- import { asyncHandler } from '@xylabs/express'
2
- import type { JsonObject } from '@xylabs/sdk-js'
3
- import {
4
- asAddress, assertEx,
5
- isAddress,
6
- toAddress,
7
- } from '@xylabs/sdk-js'
8
- import { isQueryBoundWitness, type QueryBoundWitness } from '@xyo-network/boundwitness-model'
9
- import { ModuleErrorBuilder } from '@xyo-network/module-abstract'
10
- import type { ModuleInstance, ModuleQueryResult } from '@xyo-network/module-model'
11
- import type { ModuleError, Payload } from '@xyo-network/payload-model'
12
- import type { RequestHandler } from 'express'
13
- import { StatusCodes } from 'http-status-codes'
14
-
15
- import type { AddressPathParams } from '../AddressPathParams.ts'
16
- import { getQueryConfig } from './getQueryConfig.ts'
17
-
18
- type PostAddressRequestBody = [QueryBoundWitness, undefined | Payload[]]
19
-
20
- const handler: RequestHandler<AddressPathParams, ModuleQueryResult | ModuleError, PostAddressRequestBody> = async (req, res, next) => {
21
- const returnError = (code: number, message = 'An error occurred', details?: JsonObject) => {
22
- const error = new ModuleErrorBuilder().message(message).details(details).build()
23
- res.locals.rawResponse = false
24
- res.status(code).json(error)
25
- next()
26
- }
27
-
28
- const { address } = req.params
29
- const { node } = req.app
30
- const [bw, payloads] = Array.isArray(req.body) ? req.body : []
31
- if (!isAddress(address)) {
32
- return returnError(StatusCodes.BAD_REQUEST, 'Missing address')
33
- }
34
-
35
- if (!bw) {
36
- return returnError(StatusCodes.BAD_REQUEST, 'Missing boundwitness')
37
- }
38
-
39
- if (!isQueryBoundWitness(bw)) {
40
- return returnError(StatusCodes.BAD_REQUEST, 'Invalid query boundwitness')
41
- }
42
-
43
- let modules: ModuleInstance[] = []
44
- const normalizedAddress = toAddress(address)
45
- if (node.address === normalizedAddress) modules = [node]
46
- else {
47
- const typedAddress = asAddress(address)
48
- const byAddress = (typedAddress === undefined) ? undefined : await node.resolve(typedAddress, { maxDepth: 10 })
49
-
50
- if (byAddress) modules = [byAddress]
51
- else {
52
- const byName = await node.resolve(address, { direction: 'down' })
53
- if (byName) {
54
- const moduleAddress = assertEx(byName?.address, () => 'Error redirecting to module by address')
55
- res.redirect(StatusCodes.TEMPORARY_REDIRECT, `/${moduleAddress}`)
56
- return
57
- } else {
58
- return returnError(StatusCodes.NOT_FOUND, 'Module not found', { address })
59
- }
60
- }
61
- }
62
-
63
- if (modules.length > 0) {
64
- const mod = modules[0]
65
- const queryConfig = getQueryConfig(mod, req, bw, payloads)
66
- try {
67
- const queryResult = await mod.query(bw, payloads, queryConfig)
68
- res.json(queryResult)
69
- } catch (ex) {
70
- return returnError(StatusCodes.INTERNAL_SERVER_ERROR, 'Query Failed', { message: (ex as Error)?.message ?? 'Unknown Error' })
71
- }
72
- } else {
73
- return returnError(StatusCodes.NOT_FOUND, 'Module not found', { address })
74
- }
75
- }
76
-
77
- export const postAddress = asyncHandler(handler)