@xyo-network/chain-bridge 1.20.14 → 1.20.16

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 (147) hide show
  1. package/README.md +9 -75
  2. package/dist/node/index.mjs +44 -0
  3. package/dist/node/index.mjs.map +1 -1
  4. package/dist/node/queue/flows/createXl1ToEthBridgeJob/getJobIdForXl1ToEthBridgeJob.d.ts +1 -1
  5. package/dist/node/queue/flows/createXl1ToEthBridgeJob/getJobIdForXl1ToEthBridgeJob.d.ts.map +1 -1
  6. package/dist/node/server/routes/addProbeRoutes.d.ts +3 -0
  7. package/dist/node/server/routes/addProbeRoutes.d.ts.map +1 -0
  8. package/dist/node/server/routes/addRoutes.d.ts.map +1 -1
  9. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeConfig.d.ts +7 -7
  10. package/dist/node/server/routes/{healthz → livez}/get.d.ts +1 -1
  11. package/dist/node/server/routes/livez/get.d.ts.map +1 -0
  12. package/dist/node/server/routes/livez/index.d.ts.map +1 -0
  13. package/dist/node/server/routes/readyz/get.d.ts +4 -0
  14. package/dist/node/server/routes/readyz/get.d.ts.map +1 -0
  15. package/dist/node/server/routes/readyz/index.d.ts +2 -0
  16. package/dist/node/server/routes/readyz/index.d.ts.map +1 -0
  17. package/dist/node/server/routes/startupz/get.d.ts +4 -0
  18. package/dist/node/server/routes/startupz/get.d.ts.map +1 -0
  19. package/dist/node/server/routes/startupz/index.d.ts +2 -0
  20. package/dist/node/server/routes/startupz/index.d.ts.map +1 -0
  21. package/package.json +141 -52
  22. package/dist/node/server/routes/healthz/get.d.ts.map +0 -1
  23. package/dist/node/server/routes/healthz/index.d.ts.map +0 -1
  24. package/src/BridgeActor.ts +0 -51
  25. package/src/config/asChainId.ts +0 -7
  26. package/src/config/asToken.ts +0 -7
  27. package/src/config/getBridgeEscrowAddress.ts +0 -13
  28. package/src/config/getBridgeFeesAddress.ts +0 -13
  29. package/src/config/getBridgeSettings.ts +0 -24
  30. package/src/config/getBridgeWalletAccount.ts +0 -37
  31. package/src/config/getFeeStructure.ts +0 -8
  32. package/src/config/getMaxBridgeAmount.ts +0 -7
  33. package/src/config/getMinBridgeAmount.ts +0 -7
  34. package/src/config/getRemoteChainId.ts +0 -10
  35. package/src/config/getRemoteTokenAddress.ts +0 -10
  36. package/src/config/getTestGateway.ts +0 -24
  37. package/src/config/getTransferAddresses.ts +0 -17
  38. package/src/config/getXl1ChainId.ts +0 -13
  39. package/src/config/getXl1TokenAddress.ts +0 -12
  40. package/src/config/index.ts +0 -15
  41. package/src/index.ts +0 -1
  42. package/src/interface/index.ts +0 -4
  43. package/src/interface/interface/ChainBridgeRelayInterface.ts +0 -9
  44. package/src/interface/interface/IntentIndexerInterface.ts +0 -8
  45. package/src/interface/interface/LockingProcessorInterface.ts +0 -10
  46. package/src/interface/interface/ObservationIndexerInterface.ts +0 -12
  47. package/src/interface/interface/Params.ts +0 -26
  48. package/src/interface/interface/RelayInterface.ts +0 -8
  49. package/src/interface/interface/index.ts +0 -6
  50. package/src/interface/repository/RepositoryInterface.ts +0 -28
  51. package/src/interface/repository/index.ts +0 -1
  52. package/src/interface/service/Observer/ERC20TransferObserver/ERC20TransferObserver.ts +0 -180
  53. package/src/interface/service/Observer/ERC20TransferObserver/index.ts +0 -1
  54. package/src/interface/service/Observer/LiquidityPoolBridgeObserver/LiquidityPoolBridgeObserver.ts +0 -210
  55. package/src/interface/service/Observer/LiquidityPoolBridgeObserver/index.ts +0 -1
  56. package/src/interface/service/Observer/Observer.ts +0 -48
  57. package/src/interface/service/Observer/index.ts +0 -1
  58. package/src/interface/service/Relay/ChainBridgeRelay/ChainBridgeRelayInterface.ts +0 -11
  59. package/src/interface/service/Relay/ChainBridgeRelay/ChainBridgeRelayService.ts +0 -116
  60. package/src/interface/service/Relay/ChainBridgeRelay/index.ts +0 -1
  61. package/src/interface/service/Relay/LiquidityPoolBridgeRelay/LiquidityPoolBridgeRelay.ts +0 -227
  62. package/src/interface/service/Relay/LiquidityPoolBridgeRelay/index.ts +0 -1
  63. package/src/interface/service/Relay/index.ts +0 -1
  64. package/src/interface/service/index.ts +0 -2
  65. package/src/interface/util/getBridgeIntentIdentifier.ts +0 -18
  66. package/src/interface/util/index.ts +0 -1
  67. package/src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.ts +0 -235
  68. package/src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/index.ts +0 -1
  69. package/src/modules/index.ts +0 -1
  70. package/src/queue/connection.ts +0 -16
  71. package/src/queue/flowProducer.ts +0 -16
  72. package/src/queue/flows/createEthToXl1BridgeJob.ts +0 -71
  73. package/src/queue/flows/createXl1ToEthBridgeJob/createXl1ToEthBridgeJob.ts +0 -127
  74. package/src/queue/flows/createXl1ToEthBridgeJob/getJobIdForXl1ToEthBridgeJob.ts +0 -18
  75. package/src/queue/flows/createXl1ToEthBridgeJob/getXl1ToEthBridgeJob.ts +0 -11
  76. package/src/queue/flows/createXl1ToEthBridgeJob/index.ts +0 -3
  77. package/src/queue/flows/index.ts +0 -2
  78. package/src/queue/getXl1ToEthQueueJobs.ts +0 -57
  79. package/src/queue/getXl1ToEthQueues.ts +0 -39
  80. package/src/queue/index.ts +0 -8
  81. package/src/queue/prefix.ts +0 -1
  82. package/src/queue/telemetry.ts +0 -12
  83. package/src/queue/workers/EthToXl1BridgeParent.ts +0 -40
  84. package/src/queue/workers/EthTransactionMonitor.ts +0 -59
  85. package/src/queue/workers/EthTransactionPreparation.ts +0 -83
  86. package/src/queue/workers/EthTransactionSubmission.ts +0 -63
  87. package/src/queue/workers/EthTransactionSubmissionStorage.ts +0 -76
  88. package/src/queue/workers/WorkerDescription.ts +0 -10
  89. package/src/queue/workers/Xl1ToEthBridgeParent.ts +0 -41
  90. package/src/queue/workers/Xl1TransactionJobData.ts +0 -12
  91. package/src/queue/workers/Xl1TransactionMonitor.ts +0 -82
  92. package/src/queue/workers/Xl1TransactionPreparation.ts +0 -52
  93. package/src/queue/workers/Xl1TransactionSubmission.ts +0 -70
  94. package/src/queue/workers/Xl1TransactionSubmissionStorage.ts +0 -77
  95. package/src/queue/workers/createWorkers.ts +0 -29
  96. package/src/queue/workers/index.ts +0 -11
  97. package/src/queue/workers/util/index.ts +0 -2
  98. package/src/queue/workers/util/submitEthTransaction.ts +0 -32
  99. package/src/queue/workers/util/submitXl1Transaction.ts +0 -26
  100. package/src/server/addFlowProducer.ts +0 -14
  101. package/src/server/addWorkers.ts +0 -13
  102. package/src/server/app.ts +0 -20
  103. package/src/server/index.ts +0 -19
  104. package/src/server/instrumentation.ts +0 -15
  105. package/src/server/routes/addRoutes.ts +0 -9
  106. package/src/server/routes/bridge/addBridgeRoutes.ts +0 -12
  107. package/src/server/routes/bridge/index.ts +0 -1
  108. package/src/server/routes/bridge/routeDefinitions/getRouteDefinitions.ts +0 -18
  109. package/src/server/routes/bridge/routeDefinitions/index.ts +0 -1
  110. package/src/server/routes/bridge/routeDefinitions/pathParams/ChainIdPathParam.ts +0 -21
  111. package/src/server/routes/bridge/routeDefinitions/pathParams/index.ts +0 -1
  112. package/src/server/routes/bridge/routeDefinitions/routes/bridgeConfig.ts +0 -46
  113. package/src/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.ts +0 -58
  114. package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.ts +0 -93
  115. package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts +0 -69
  116. package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.ts +0 -64
  117. package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts +0 -98
  118. package/src/server/routes/bridge/routeDefinitions/routes/index.ts +0 -6
  119. package/src/server/routes/healthz/get.ts +0 -20
  120. package/src/server/routes/healthz/index.ts +0 -1
  121. package/src/server/routes/index.ts +0 -1
  122. package/src/server/server.ts +0 -21
  123. package/src/services/EthTxState.ts +0 -5
  124. package/src/services/IBridgeServiceCollection.ts +0 -19
  125. package/src/services/TxState.ts +0 -14
  126. package/src/services/Xl1TxState.ts +0 -9
  127. package/src/services/getIterableMap.ts +0 -34
  128. package/src/services/getServices.ts +0 -41
  129. package/src/services/index.ts +0 -5
  130. package/src/util/BridgeFees.ts +0 -16
  131. package/src/util/bridgeFeesAsBigInt.ts +0 -15
  132. package/src/util/calculateBridgeFees.ts +0 -33
  133. package/src/util/calculateMaxBridgeAmount.ts +0 -22
  134. package/src/util/createBridgeTransfer.ts +0 -31
  135. package/src/util/generateBridgeEstimate.ts +0 -55
  136. package/src/util/getConfigFromEnv.ts +0 -15
  137. package/src/util/index.ts +0 -7
  138. package/src/validation/AsyncLogger.ts +0 -5
  139. package/src/validation/index.ts +0 -6
  140. package/src/validation/validateBridgeEstimate.ts +0 -60
  141. package/src/validation/validateBridgeEstimateExact.ts +0 -39
  142. package/src/validation/validateBridgeTransaction.ts +0 -53
  143. package/src/validation/validateSufficientLiquiditySourceAllowance.ts +0 -39
  144. package/src/validation/validateSufficientLiquiditySourceBalance.ts +0 -38
  145. package/src/validation/validateSufficientRunnerEthBalanceForGas.ts +0 -57
  146. package/src/validation/validateSufficientXL1SourceAddressBalance.ts +0 -39
  147. /package/dist/node/server/routes/{healthz → livez}/index.d.ts +0 -0
@@ -1,18 +0,0 @@
1
- import type { RouteDefinition } from '@xylabs/express'
2
- import type { BridgeConfig } from '@xyo-network/chain-orchestration'
3
- import type { XyoGatewayRunner } from '@xyo-network/xl1-sdk'
4
-
5
- import {
6
- makeBridgeConfigRoute, makeBridgeFromRemoteStatusRoute, makeBridgeToRemoteEstimateRoute, makeBridgeToRemoteMaxEstimateRoute, makeBridgeToRemoteRoute, makeBridgeToRemoteStatusRoute,
7
- } from './routes/index.ts'
8
-
9
- export const getRouteDefinitions = (config: BridgeConfig, gateway: XyoGatewayRunner): RouteDefinition[] => {
10
- return [
11
- makeBridgeConfigRoute(config),
12
- makeBridgeToRemoteEstimateRoute(config, gateway),
13
- makeBridgeToRemoteMaxEstimateRoute(config, gateway),
14
- makeBridgeToRemoteRoute(config),
15
- makeBridgeToRemoteStatusRoute(config),
16
- makeBridgeFromRemoteStatusRoute(config),
17
- ]
18
- }
@@ -1 +0,0 @@
1
- export * from './getRouteDefinitions.ts'
@@ -1,21 +0,0 @@
1
- import {
2
- asHex, HexZod, isUndefined,
3
- } from '@xylabs/sdk-js'
4
- import type { BridgeConfig } from '@xyo-network/chain-orchestration'
5
- import type { ChainId } from '@xyo-network/xl1-sdk'
6
-
7
- import { getRemoteChainId } from '../../../../../config/index.ts'
8
-
9
- export const getRemoteChainIdZod = (config: BridgeConfig) => {
10
- const remoteChainId: ChainId = getRemoteChainId(config)
11
- return HexZod.superRefine((val, ctx) => {
12
- const chainId = asHex(val)
13
- if (isUndefined(chainId)) {
14
- ctx.addIssue('Not a valid chain id')
15
- return
16
- }
17
- if (chainId !== remoteChainId) {
18
- ctx.addIssue(`Only ${remoteChainId} is supported`)
19
- }
20
- })
21
- }
@@ -1 +0,0 @@
1
- export * from './ChainIdPathParam.ts'
@@ -1,46 +0,0 @@
1
- import type { RouteDefinition } from '@xylabs/express'
2
- import { requestHandlerValidator } from '@xylabs/express'
3
- import type { BridgeConfig } from '@xyo-network/chain-orchestration'
4
- import { BridgeSettingsZod } from '@xyo-network/chain-orchestration'
5
- import type { z } from 'zod'
6
-
7
- import { getBridgeSettings } from '../../../../../config/index.ts'
8
-
9
- export const BridgeConfigResponseZod = BridgeSettingsZod
10
- export type BridgeConfigResponse = z.infer<typeof BridgeConfigResponseZod>
11
-
12
- const validateRequest = requestHandlerValidator({ response: BridgeConfigResponseZod })
13
-
14
- export const makeBridgeConfigRoute = (config: BridgeConfig): RouteDefinition => {
15
- return {
16
- method: 'get',
17
- path: '/bridge/chains/:chainId/config',
18
- handlers: validateRequest(async (_, res) => {
19
- const {
20
- escrowAddress,
21
- feeFixed,
22
- feeRateBasisPoints,
23
- feesAddress,
24
- maxBridgeAmount,
25
- minBridgeAmount,
26
- remoteChainId,
27
- remoteTokenAddress,
28
- xl1ChainId,
29
- xl1TokenAddress,
30
- } = await getBridgeSettings(config)
31
- const sanitizedConfig = {
32
- escrowAddress,
33
- feeFixed,
34
- feeRateBasisPoints,
35
- feesAddress,
36
- maxBridgeAmount,
37
- minBridgeAmount,
38
- remoteChainId,
39
- remoteTokenAddress,
40
- xl1ChainId,
41
- xl1TokenAddress,
42
- }
43
- res.json(sanitizedConfig)
44
- }),
45
- }
46
- }
@@ -1,58 +0,0 @@
1
- import type { RouteDefinition } from '@xylabs/express'
2
- import { requestHandlerValidator } from '@xylabs/express'
3
- import { toAddress, toHex } from '@xylabs/sdk-js'
4
- import type { BridgeConfig } from '@xyo-network/chain-orchestration'
5
- import { PayloadZodStrictOfSchema } from '@xyo-network/sdk-js'
6
- import type { BridgeDestinationObservation } from '@xyo-network/xl1-sdk'
7
- import {
8
- BridgeDestinationObservationFieldsZod,
9
- BridgeDestinationObservationSchema,
10
- } from '@xyo-network/xl1-sdk'
11
- import { z } from 'zod'
12
-
13
- import { getBridgeSettings } from '../../../../../config/index.ts'
14
- import { getRemoteChainIdZod } from '../pathParams/index.ts'
15
-
16
- export const makeBridgeFromRemoteStatusRoute = (config: BridgeConfig): RouteDefinition => {
17
- const params = z.object({
18
- chainId: getRemoteChainIdZod(config),
19
- nonce: z.string().nonempty(),
20
- })
21
- const response = PayloadZodStrictOfSchema(BridgeDestinationObservationSchema).extend(
22
- BridgeDestinationObservationFieldsZod.shape,
23
- )
24
- const validateRequest = requestHandlerValidator({ params, response })
25
-
26
- return {
27
- method: 'get',
28
- path: '/bridge/chains/:chainId/bridgeFromRemote/status/:nonce',
29
- handlers: validateRequest(async (req, res) => {
30
- const {
31
- remoteChainId, remoteTokenAddress, xl1ChainId, xl1TokenAddress,
32
- } = await getBridgeSettings(config)
33
-
34
- const rand = await Promise.resolve(Math.random())
35
-
36
- // TODO: Replace with actual lookup logic (e.g. database or chain query)
37
- const found = rand > 0.5 // simulate lookup
38
- if (!found) return res.sendStatus(404)
39
-
40
- const confirmed = rand > 0.8 // simulate pending/confirmed
41
- if (!confirmed) return res.sendStatus(204)
42
-
43
- const observation: BridgeDestinationObservation = {
44
- schema: BridgeDestinationObservationSchema,
45
- dest: xl1ChainId,
46
- destAddress: toAddress('0xabc'),
47
- destAmount: toHex('0x100'),
48
- destToken: xl1TokenAddress,
49
- src: remoteChainId,
50
- srcAddress: toAddress('0x123'),
51
- srcAmount: toHex('0x200'),
52
- srcToken: remoteTokenAddress,
53
- destConfirmation: toHex('0x9999'),
54
- }
55
- res.json(observation)
56
- }),
57
- }
58
- }
@@ -1,93 +0,0 @@
1
- import type { RouteDefinition } from '@xylabs/express'
2
- import { requestHandlerValidator } from '@xylabs/express'
3
- import { isDefined } from '@xylabs/sdk-js'
4
- import type { BridgeConfig } from '@xyo-network/chain-orchestration'
5
- import {
6
- PayloadBuilder, PayloadZodLooseOfSchema, PayloadZodStrictOfSchema,
7
- } from '@xyo-network/sdk-js'
8
- import type {
9
- BridgeSourceObservation, BridgeSourceObservationFields, SignedHydratedTransaction,
10
- } from '@xyo-network/xl1-sdk'
11
- import {
12
- BridgeIntentFieldsZod, BridgeIntentSchema, BridgeSourceObservationFieldsZod, BridgeSourceObservationSchema, SignedTransactionBoundWitnessZod, TransferZod,
13
- } from '@xyo-network/xl1-sdk'
14
- import { z } from 'zod'
15
-
16
- import { createXl1ToEthBridgeJob, getXl1ToEthBridgeJob } from '../../../../../queue/index.ts'
17
- import {
18
- validateBridgeEstimateExact, validateBridgeTransaction, validateSufficientXL1SourceAddressBalance,
19
- } from '../../../../../validation/index.ts'
20
- import { getRemoteChainIdZod } from '../pathParams/index.ts'
21
-
22
- export const BridgeToRemoteBodyZod = z.tuple([
23
- SignedTransactionBoundWitnessZod,
24
- PayloadZodLooseOfSchema(BridgeIntentSchema).extend(BridgeIntentFieldsZod.shape),
25
- TransferZod,
26
- ])
27
- export type BridgeToRemoteBody = z.infer<typeof BridgeToRemoteBodyZod>
28
-
29
- export const BridgeToRemoteResponseZod = PayloadZodStrictOfSchema(BridgeSourceObservationSchema).extend(BridgeSourceObservationFieldsZod.shape)
30
- export type BridgeToRemoteResponse = z.infer<typeof BridgeToRemoteResponseZod>
31
-
32
- export const makeBridgeToRemoteRoute = (config: BridgeConfig): RouteDefinition => {
33
- const params = z.object({ chainId: getRemoteChainIdZod(config) })
34
-
35
- const validateRequest = requestHandlerValidator({
36
- params, body: BridgeToRemoteBodyZod, response: BridgeToRemoteResponseZod,
37
- })
38
- return {
39
- method: 'post',
40
- path: '/bridge/chains/:chainId/bridgeToRemote',
41
- handlers: validateRequest(async (req, res) => {
42
- const [signedTxBw, bridgeIntent, transfer] = req.body
43
- const { flowProducer } = req.app
44
- const { gateway } = req.app.services
45
-
46
- // Validate request
47
- const transactionValid = await validateBridgeTransaction(signedTxBw, bridgeIntent, transfer, config)
48
- if (!transactionValid) {
49
- res.status(400).send()
50
- return
51
- }
52
-
53
- // Validate estimate
54
- const estimateValid = await validateBridgeEstimateExact(bridgeIntent, transfer, config)
55
- if (!estimateValid) {
56
- res.status(400).send()
57
- return
58
- }
59
-
60
- // Validate sufficient balance
61
- const sufficientBalance = await validateSufficientXL1SourceAddressBalance(bridgeIntent, gateway, config)
62
- if (!sufficientBalance) {
63
- res.status(400).send()
64
- return
65
- }
66
-
67
- // Create the signed hydrated transaction for the job
68
- const singedHydratedTransaction: SignedHydratedTransaction = [signedTxBw, [transfer]]
69
-
70
- // Check if a job already exists for this transaction
71
- const existingFlow = await getXl1ToEthBridgeJob(flowProducer, singedHydratedTransaction)
72
- if (isDefined(existingFlow)) {
73
- res.status(200).send()
74
- return
75
- }
76
-
77
- // Submit to job queue
78
- await createXl1ToEthBridgeJob(flowProducer, singedHydratedTransaction, [bridgeIntent])
79
-
80
- // Create BridgeObservation
81
- const srcConfirmation = await PayloadBuilder.hash(signedTxBw)
82
- const bridgeCommonFieldsZod = z.object({}).extend(BridgeSourceObservationFieldsZod.shape)
83
- const bridgeCommonFields = bridgeCommonFieldsZod.parse(bridgeIntent)
84
- const bridgeObservationFields: BridgeSourceObservationFields = { ...bridgeCommonFields, srcConfirmation }
85
- const bridgeObservation: BridgeSourceObservation = new PayloadBuilder<BridgeSourceObservation>(
86
- { schema: BridgeSourceObservationSchema },
87
- ).fields(bridgeObservationFields).build()
88
-
89
- // Return bridge observation to caller
90
- res.status(202).json(bridgeObservation)
91
- }),
92
- }
93
- }
@@ -1,69 +0,0 @@
1
- import type { RouteDefinition } from '@xylabs/express'
2
- import { requestHandlerValidator } from '@xylabs/express'
3
- import {
4
- assertEx, hexToBigInt, toAddress,
5
- } from '@xylabs/sdk-js'
6
- import type { BridgeConfig } from '@xyo-network/chain-orchestration'
7
- import { PayloadZodStrictOfSchema } from '@xyo-network/sdk-js'
8
- import type { XyoGatewayRunner } from '@xyo-network/xl1-sdk'
9
- import {
10
- BridgeIntentFieldsZod, BridgeIntentSchema, buildUnsignedTransaction, toXL1BlockNumber, TransactionBoundWitnessZod, TransferZod,
11
- } from '@xyo-network/xl1-sdk'
12
- import { z } from 'zod'
13
-
14
- import { getBridgeSettings, getXl1ChainId } from '../../../../../config/index.ts'
15
- import { generateBridgeEstimate } from '../../../../../util/index.ts'
16
- import { getRemoteChainIdZod } from '../pathParams/index.ts'
17
-
18
- export const BridgeToRemoteEstimateBodyZod = BridgeIntentFieldsZod.pick({
19
- destAddress: true,
20
- srcAddress: true,
21
- srcAmount: true,
22
- })
23
- export type BridgeToRemoteEstimateBody = z.infer<typeof BridgeToRemoteEstimateBodyZod>
24
-
25
- export const BridgeToRemoteEstimateResponseZod = z.tuple([
26
- TransactionBoundWitnessZod,
27
- PayloadZodStrictOfSchema(BridgeIntentSchema).extend(BridgeIntentFieldsZod.shape),
28
- TransferZod,
29
- ])
30
-
31
- export type BridgeToRemoteEstimateResponse = z.infer<typeof BridgeToRemoteEstimateResponseZod>
32
-
33
- export const makeBridgeToRemoteEstimateRoute = (config: BridgeConfig, gateway: XyoGatewayRunner): RouteDefinition => {
34
- const params = z.object({ chainId: getRemoteChainIdZod(config) })
35
- const validateRequest = requestHandlerValidator({
36
- params, body: BridgeToRemoteEstimateBodyZod, response: BridgeToRemoteEstimateResponseZod,
37
- })
38
- return {
39
- method: 'post',
40
- path: '/bridge/chains/:chainId/bridgeToRemote/estimate',
41
- handlers: validateRequest(async (req, res) => {
42
- const xl1ChainId = getXl1ChainId(config)
43
- const {
44
- srcAddress, srcAmount, destAddress,
45
- } = req.body
46
-
47
- const { maxBridgeAmount } = await getBridgeSettings(config)
48
- if (hexToBigInt(srcAmount) > hexToBigInt(maxBridgeAmount)) {
49
- res.status(400).send()
50
- return
51
- }
52
-
53
- const [bridgeIntent, transfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config)
54
- const sender = toAddress(srcAddress)
55
-
56
- // Use viewer to get current block
57
- const viewer = assertEx(gateway.connection.viewer, () => new Error('Viewer not available on gateway connection'))
58
- const currentBlockNumber = await viewer.currentBlockNumber()
59
- // Calculate nbf/exp
60
- const nbf = toXL1BlockNumber(currentBlockNumber, true)
61
- const exp = toXL1BlockNumber(currentBlockNumber + 1000, true)
62
- // Build unsigned transaction representing the transfer that will be signed by srcAddress
63
- const [txBw] = await buildUnsignedTransaction(xl1ChainId, [transfer], [bridgeIntent], nbf, exp, sender)
64
-
65
- // Return the TX to the caller for signing
66
- res.json([txBw, bridgeIntent, transfer])
67
- }),
68
- }
69
- }
@@ -1,64 +0,0 @@
1
- import type { RouteDefinition } from '@xylabs/express'
2
- import { requestHandlerValidator } from '@xylabs/express'
3
- import {
4
- assertEx, hexToBigInt, toAddress, toHex,
5
- } from '@xylabs/sdk-js'
6
- import type { BridgeConfig } from '@xyo-network/chain-orchestration'
7
- import { PayloadZodStrictOfSchema } from '@xyo-network/sdk-js'
8
- import type { XyoGatewayRunner } from '@xyo-network/xl1-sdk'
9
- import {
10
- BridgeIntentFieldsZod, BridgeIntentSchema, buildUnsignedTransaction, toXL1BlockNumber, TransactionBoundWitnessZod, TransferZod,
11
- } from '@xyo-network/xl1-sdk'
12
- import { z } from 'zod'
13
-
14
- import { getBridgeSettings } from '../../../../../config/index.ts'
15
- import { calculateMaxBridgeAmount, generateBridgeEstimate } from '../../../../../util/index.ts'
16
- import { getRemoteChainIdZod } from '../pathParams/index.ts'
17
-
18
- export const BridgeToRemoteMaxEstimateBodyZod = BridgeIntentFieldsZod.pick({
19
- destAddress: true,
20
- srcAddress: true,
21
- srcAmount: true,
22
- })
23
- export type BridgeToRemoteMaxEstimateBody = z.infer<typeof BridgeToRemoteMaxEstimateBodyZod>
24
-
25
- export const BridgeToRemoteMaxEstimateResponseZod = z.tuple([
26
- TransactionBoundWitnessZod,
27
- PayloadZodStrictOfSchema(BridgeIntentSchema).extend(BridgeIntentFieldsZod.shape),
28
- TransferZod,
29
- ])
30
-
31
- export type BridgeToRemoteMaxEstimateResponse = z.infer<typeof BridgeToRemoteMaxEstimateResponseZod>
32
-
33
- export const makeBridgeToRemoteMaxEstimateRoute = (config: BridgeConfig, gateway: XyoGatewayRunner): RouteDefinition => {
34
- const params = z.object({ chainId: getRemoteChainIdZod(config) })
35
- const validateRequest = requestHandlerValidator({
36
- params, body: BridgeToRemoteMaxEstimateBodyZod, response: BridgeToRemoteMaxEstimateResponseZod,
37
- })
38
- return {
39
- method: 'post',
40
- path: '/bridge/chains/:chainId/bridgeToRemote/maxEstimate',
41
- handlers: validateRequest(async (req, res) => {
42
- const {
43
- feeFixed, feeRateBasisPoints, maxBridgeAmount: configMax, xl1ChainId,
44
- } = await getBridgeSettings(config)
45
- const {
46
- srcAddress, srcAmount: balance, destAddress,
47
- } = req.body
48
-
49
- const balanceMax = calculateMaxBridgeAmount(balance, { feeFixed, feeRateBasisPoints })
50
- const maxBridgeAmount = toHex(hexToBigInt(balanceMax) < hexToBigInt(configMax) ? balanceMax : configMax)
51
-
52
- const [bridgeIntent, transfer] = await generateBridgeEstimate(srcAddress, maxBridgeAmount, destAddress, config)
53
- const sender = toAddress(srcAddress)
54
-
55
- const viewer = assertEx(gateway.connection.viewer, () => new Error('Viewer not available on gateway connection'))
56
- const currentBlockNumber = await viewer.currentBlockNumber()
57
- const nbf = toXL1BlockNumber(currentBlockNumber, true)
58
- const exp = toXL1BlockNumber(currentBlockNumber + 1000, true)
59
- const [txBw] = await buildUnsignedTransaction(xl1ChainId, [transfer], [bridgeIntent], nbf, exp, sender)
60
-
61
- res.json([txBw, bridgeIntent, transfer])
62
- }),
63
- }
64
- }
@@ -1,98 +0,0 @@
1
- import type { RouteDefinition } from '@xylabs/express'
2
- import { requestHandlerValidator } from '@xylabs/express'
3
- import { asHex, isDefined } from '@xylabs/sdk-js'
4
- import type { BridgeConfig } from '@xyo-network/chain-orchestration'
5
- import { PayloadBuilder, PayloadZodStrictOfSchema } from '@xyo-network/sdk-js'
6
- import type { BridgeDestinationObservation, BridgeSourceObservation } from '@xyo-network/xl1-sdk'
7
- import {
8
- asBridgeIntent, BridgeDestinationObservationFieldsZod, BridgeDestinationObservationSchema, BridgeIntentFieldsZod, BridgeIntentSchema,
9
- BridgeSourceObservationFieldsZod, BridgeSourceObservationSchema, isBridgeIntent,
10
- } from '@xyo-network/xl1-sdk'
11
- import { z } from 'zod'
12
-
13
- import { getStatusQueueJobs, getXl1ToEthQueues } from '../../../../../queue/index.ts'
14
- import { getRemoteChainIdZod } from '../pathParams/index.ts'
15
-
16
- const BridgeIntentResponseZod = PayloadZodStrictOfSchema(BridgeIntentSchema)
17
- .extend(BridgeIntentFieldsZod.shape)
18
-
19
- const BridgeSourceResponseZod = PayloadZodStrictOfSchema(BridgeSourceObservationSchema)
20
- .extend(BridgeSourceObservationFieldsZod.shape)
21
-
22
- const BridgeDestinationResponseZod = PayloadZodStrictOfSchema(BridgeDestinationObservationSchema)
23
- .extend(BridgeDestinationObservationFieldsZod.shape)
24
-
25
- export const BridgeToRemoteStatusResponseZod = z.union([
26
- z.tuple([]),
27
- z.tuple([BridgeIntentResponseZod]),
28
- z.tuple([BridgeIntentResponseZod, BridgeSourceResponseZod]),
29
- z.tuple([BridgeIntentResponseZod, BridgeSourceResponseZod, BridgeDestinationResponseZod]),
30
- ])
31
- export type BridgeToRemoteStatusResponse = z.infer<typeof BridgeToRemoteStatusResponseZod>
32
-
33
- export const makeBridgeToRemoteStatusRoute = (config: BridgeConfig): RouteDefinition => {
34
- const params = z.object({
35
- chainId: getRemoteChainIdZod(config),
36
- nonce: z.string().nonempty(),
37
- })
38
-
39
- const validateRequest = requestHandlerValidator({ params, response: BridgeToRemoteStatusResponseZod })
40
-
41
- return {
42
- method: 'get',
43
- path: '/bridge/chains/:chainId/bridgeToRemote/status/:nonce',
44
- handlers: validateRequest(async (req, res) => {
45
- const jobId = req.params.nonce
46
- const result: z.infer<typeof BridgeToRemoteStatusResponseZod> = [] as z.infer<typeof BridgeToRemoteStatusResponseZod>
47
- const queues = getXl1ToEthQueues(config)
48
-
49
- const statusQueueJobs = await getStatusQueueJobs(queues, jobId)
50
-
51
- // Check for the transaction hash in the parent job
52
- const { tx, offChainPayloads = [] } = statusQueueJobs.xl1ToEthBridgeParentJob?.data ?? {}
53
-
54
- // If the job does not exist return Not Found
55
- if (!tx) return res.sendStatus(404)
56
-
57
- // If the tx is not the right shape for bridging return Not Found
58
- const allPayloads = [...tx[1], ...offChainPayloads]
59
- const bridgeIntent = allPayloads.find(isBridgeIntent)
60
- if (!bridgeIntent) return res.sendStatus(404)
61
-
62
- // At this point we know we have a valid bridge intent, so we can start building the response
63
- result[0] = asBridgeIntent(PayloadBuilder.omitMeta(bridgeIntent))
64
-
65
- // Check the state of the XL1 monitor job to determine if we can include the source observation
66
- const { xl1TransactionMonitorJob } = statusQueueJobs
67
- const xl1MonitorState = xl1TransactionMonitorJob ? await xl1TransactionMonitorJob.getState() : undefined
68
- if (xl1MonitorState === 'completed') {
69
- const srcConfirmation = xl1TransactionMonitorJob?.returnvalue?.submissionHash
70
- if (isDefined(srcConfirmation)) {
71
- const schema = BridgeSourceObservationSchema
72
- const bridgeSourceObservationFields = BridgeSourceObservationFieldsZod.parse(bridgeIntent)
73
- const observation: BridgeSourceObservation = {
74
- schema, ...bridgeSourceObservationFields, srcConfirmation,
75
- }
76
- result[1] = observation
77
- }
78
- }
79
-
80
- // Check the state of the ETH monitor job to determine if we can include the destination observation
81
- const { ethTransactionMonitorJob } = statusQueueJobs
82
- const ethMonitorState = ethTransactionMonitorJob ? await ethTransactionMonitorJob.getState() : undefined
83
- if (ethMonitorState === 'completed') {
84
- const destConfirmation = asHex(ethTransactionMonitorJob?.returnvalue?.submissionHash)
85
- if (isDefined(destConfirmation)) {
86
- const schema = BridgeDestinationObservationSchema
87
- const bridgeDestinationObservationFields = BridgeDestinationObservationFieldsZod.parse(bridgeIntent)
88
- const observation: BridgeDestinationObservation = {
89
- schema, ...bridgeDestinationObservationFields, destConfirmation,
90
- }
91
- result[2] = observation
92
- }
93
- }
94
-
95
- res.json(result)
96
- }),
97
- }
98
- }
@@ -1,6 +0,0 @@
1
- export * from './bridgeConfig.ts'
2
- export * from './bridgeFromRemoteStatus.ts'
3
- export * from './bridgeToRemote.ts'
4
- export * from './bridgeToRemoteEstimate.ts'
5
- export * from './bridgeToRemoteMaxEstimate.ts'
6
- export * from './bridgeToRemoteStatus.ts'
@@ -1,20 +0,0 @@
1
- import type { NoReqParams } from '@xylabs/express'
2
- import { setRawResponseFormat } from '@xylabs/express'
3
- import type { RequestHandler } from 'express'
4
- import { ReasonPhrases } from 'http-status-codes'
5
-
6
- const message = ReasonPhrases.OK
7
-
8
- const handler: RequestHandler<NoReqParams> = (_req, res) => {
9
- setRawResponseFormat(res)
10
- const date = new Date()
11
- const {
12
- cpuUsage, memoryUsage, uptime,
13
- } = process
14
- const data = {
15
- cpuUsage: cpuUsage(), date, memoryUsage: memoryUsage(), message, uptime: uptime(),
16
- }
17
- res.status(200).send(data)
18
- }
19
-
20
- export const getHealthz: RequestHandler<NoReqParams> = handler
@@ -1 +0,0 @@
1
- export * from './get.ts'
@@ -1 +0,0 @@
1
- export * from './addRoutes.ts'
@@ -1,21 +0,0 @@
1
- import type { BridgeConfigContext } from '@xyo-network/chain-orchestration'
2
- import type { XyoGatewayRunner } from '@xyo-network/xl1-sdk'
3
-
4
- import { getServices } from '../services/index.ts'
5
- import { addWorkers } from './addWorkers.ts'
6
- import { getApp } from './app.ts'
7
-
8
- const hostname = '::'
9
- // const hostname = '0.0.0.0'
10
-
11
- export const getServer = async (context: BridgeConfigContext, gateway: XyoGatewayRunner) => {
12
- const { logger, config } = context
13
- const { port } = config
14
- const app = getApp(config, gateway)
15
- const services = await getServices(context, gateway)
16
- app.services = services
17
- addWorkers(config, services)
18
- const server = app.listen(port, hostname, () => logger?.log(`[Bridge] Server listening at http://${hostname}:${port}`))
19
- server.setTimeout(20_000)
20
- return server
21
- }
@@ -1,5 +0,0 @@
1
- import type { TransactionRequest } from 'ethers'
2
-
3
- import type { TxState } from './TxState.ts'
4
-
5
- export interface EthTxState extends TxState<TransactionRequest> {}
@@ -1,19 +0,0 @@
1
- import type { Hash } from '@xylabs/sdk-js'
2
- import type { AccountInstance } from '@xyo-network/sdk-js'
3
- import type { BridgeableToken, LiquidityPoolBridge } from '@xyo-network/typechain'
4
- import type { IterableMap, XyoGatewayRunner } from '@xyo-network/xl1-sdk'
5
- import type { Provider, Wallet } from 'ethers'
6
-
7
- import type { EthTxState } from './EthTxState.ts'
8
- import type { Xl1TxState } from './Xl1TxState.ts'
9
-
10
- export interface IBridgeServiceCollection {
11
- account: AccountInstance
12
- bridge: LiquidityPoolBridge
13
- bridgeableToken: BridgeableToken
14
- ethTxStateMap: IterableMap<Hash, EthTxState>
15
- gateway: XyoGatewayRunner
16
- provider: Provider
17
- wallet: Wallet
18
- xl1TxStateMap: IterableMap<Hash, Xl1TxState>
19
- }
@@ -1,14 +0,0 @@
1
- export interface TxState<TTx, TTxHash extends string = string, TConfHash extends string = string> {
2
- /**
3
- * The confirmation hash of the transaction
4
- */
5
- confirmationHash?: TConfHash
6
- /**
7
- * The transaction that has been prepared for submission
8
- */
9
- preparedTx?: TTx
10
- /**
11
- * The hash of the submitted transaction
12
- */
13
- submissionHash?: TTxHash
14
- }
@@ -1,9 +0,0 @@
1
- import type { Hash } from '@xylabs/sdk-js'
2
- import type { Payload } from '@xyo-network/sdk-js'
3
- import type { SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
4
-
5
- import type { TxState } from './TxState.ts'
6
-
7
- export interface Xl1TxState extends TxState<SignedHydratedTransaction, Hash, Hash> {
8
- offChainPayloads?: Payload[]
9
- }
@@ -1,34 +0,0 @@
1
- import { BaseMongoSdk, type BaseMongoSdkPrivateConfig } from '@xylabs/mongo'
2
- import { MongoMap } from '@xyo-network/chain-protocol'
3
- import type { BaseConfig, IterableMap } from '@xyo-network/xl1-sdk'
4
- import { hasMongoConfig, mapToMapType } from '@xyo-network/xl1-sdk'
5
- import type { Document } from 'mongodb'
6
-
7
- /**
8
- * Gets an iterable map based on the storage instructions in the config
9
- * @param config The config containing storage instructions
10
- * @param collection The collection to use if using MongoDB for persistence
11
- * @returns The iterable map
12
- */
13
- export const getIterableMap = async <K extends {} = string, V extends Document = Document>(
14
- config: BaseConfig,
15
- collection: string,
16
- ): Promise<IterableMap<K, V>> => {
17
- const mongoConfig = config.storage?.mongo
18
- if (hasMongoConfig(mongoConfig)) {
19
- const {
20
- connectionString: dbConnectionString, database: dbName, domain: dbDomain, password: dbPassword, username: dbUserName,
21
- } = mongoConfig
22
- const payloadSdkConfig: BaseMongoSdkPrivateConfig = {
23
- dbConnectionString, dbDomain, dbName, dbPassword, dbUserName,
24
- }
25
- const sdkBalanceSummaryMap = new BaseMongoSdk<V>({ ...payloadSdkConfig, collection })
26
- const result = await MongoMap.create<MongoMap<K, V>>({
27
- sdk: sdkBalanceSummaryMap,
28
- getCache: { enabled: true, maxEntries: 5000 },
29
- })
30
- return result
31
- } else {
32
- return mapToMapType(new Map<K, V>())
33
- }
34
- }