@xyo-network/chain-bridge 1.20.15 → 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,71 +0,0 @@
1
- import { PayloadBuilder } from '@xyo-network/sdk-js'
2
- import type { SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
3
- import type { FlowProducer } from 'bullmq'
4
-
5
- import {
6
- EthToXl1BridgeParent, Xl1TransactionMonitor, Xl1TransactionPreparation, Xl1TransactionSubmission,
7
- Xl1TransactionSubmissionStorage,
8
- } from '../workers/index.ts'
9
-
10
- /**
11
- * Creates a job flow for bridging a transaction from Ethereum to XL1.
12
- * @param flowProducer The flow producer to run the job
13
- * @param tx The bridge transaction
14
- * @returns The JobNode representing the ETH to XL1 bridge job
15
- */
16
- export const createEthToXl1BridgeJob = async (
17
- flowProducer: FlowProducer,
18
- tx: SignedHydratedTransaction,
19
- ) => {
20
- const jobId = await PayloadBuilder.hash(tx[0])
21
- const flow = await flowProducer.add({
22
- // Step 0 (runs first as parent job)
23
- name: EthToXl1BridgeParent.name,
24
- queueName: EthToXl1BridgeParent.queueName,
25
- data: { tx },
26
- opts: { jobId },
27
- children: [
28
- {
29
- // Step 4
30
- name: Xl1TransactionMonitor.name,
31
- queueName: Xl1TransactionMonitor.queueName,
32
- data: { tx },
33
- opts: {
34
- jobId, attempts: 60, backoff: { type: 'fixed', delay: 5000 },
35
- },
36
- children: [
37
- {
38
- // Step 3
39
- name: Xl1TransactionSubmissionStorage.name,
40
- queueName: Xl1TransactionSubmissionStorage.queueName,
41
- data: { tx },
42
- opts: {
43
- jobId, attempts: 60, backoff: { type: 'fixed', delay: 5000 },
44
- },
45
- children: [
46
- {
47
- // Step 2
48
- name: Xl1TransactionSubmission.name,
49
- queueName: Xl1TransactionSubmission.queueName,
50
- data: { tx },
51
- opts: { jobId },
52
- children: [
53
- {
54
- // Step 1 (runs first as deepest child)
55
- name: Xl1TransactionPreparation.name,
56
- queueName: Xl1TransactionPreparation.queueName,
57
- data: { tx },
58
- opts: {
59
- jobId, attempts: 60, backoff: { type: 'fixed', delay: 5000 },
60
- },
61
- },
62
- ],
63
- },
64
- ],
65
- },
66
- ],
67
- },
68
- ],
69
- })
70
- return flow
71
- }
@@ -1,127 +0,0 @@
1
- import type { Payload } from '@xyo-network/sdk-js'
2
- import type { SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
3
- import type { FlowProducer } from 'bullmq'
4
-
5
- import type {
6
- EthTransactionMonitorJobData,
7
- EthTransactionPreparationJobData,
8
- EthTransactionSubmissionJobData,
9
- EthTransactionSubmissionStorageJobData,
10
- Xl1ToEthBridgeParentJobData,
11
- Xl1TransactionMonitorJobData,
12
- Xl1TransactionPreparationJobData,
13
- Xl1TransactionSubmissionJobData,
14
- Xl1TransactionSubmissionStorageJobData,
15
- } from '../../workers/index.ts'
16
- import {
17
- EthTransactionMonitor, EthTransactionPreparation, EthTransactionSubmission, EthTransactionSubmissionStorage, Xl1ToEthBridgeParent, Xl1TransactionMonitor,
18
- Xl1TransactionPreparation, Xl1TransactionSubmission, Xl1TransactionSubmissionStorage,
19
- } from '../../workers/index.ts'
20
- import { getJobIdForXl1ToEthBridgeJob } from './getJobIdForXl1ToEthBridgeJob.ts'
21
-
22
- /**
23
- * Creates a job flow for bridging a transaction from XL1 to Ethereum.
24
- * @param flowProducer The flow producer to run the job
25
- * @param tx The bridge transaction
26
- * @param offChainPayloads The payloads to put off chain
27
- * @returns The JobNode representing the XL1 to ETH bridge job
28
- */
29
- export const createXl1ToEthBridgeJob = async (
30
- flowProducer: FlowProducer,
31
- tx: SignedHydratedTransaction,
32
- offChainPayloads: Payload[] = [],
33
- ) => {
34
- const jobId = await getJobIdForXl1ToEthBridgeJob(tx)
35
- const flow = await flowProducer.add({
36
- // Step 0 (runs first as parent job)
37
- name: Xl1ToEthBridgeParent.name,
38
- queueName: Xl1ToEthBridgeParent.queueName,
39
- data: { tx, offChainPayloads } as Xl1ToEthBridgeParentJobData,
40
- opts: { jobId },
41
- children: [
42
- {
43
- // Step 8
44
- name: EthTransactionMonitor.name,
45
- queueName: EthTransactionMonitor.queueName,
46
- data: { tx } as EthTransactionMonitorJobData,
47
- opts: {
48
- jobId, attempts: 60, backoff: { type: 'fixed', delay: 5000 },
49
- },
50
- children: [
51
- {
52
- // Step 7
53
- name: EthTransactionSubmissionStorage.name,
54
- queueName: EthTransactionSubmissionStorage.queueName,
55
- data: { tx } as EthTransactionSubmissionStorageJobData,
56
- opts: {
57
- jobId, attempts: 60, backoff: { type: 'fixed', delay: 5000 },
58
- },
59
- children: [
60
- {
61
- // Step 6
62
- name: EthTransactionSubmission.name,
63
- queueName: EthTransactionSubmission.queueName,
64
- data: { tx, offChainPayloads } as EthTransactionSubmissionJobData,
65
- opts: { jobId },
66
- children: [
67
- {
68
- // Step 5
69
- name: EthTransactionPreparation.name,
70
- queueName: EthTransactionPreparation.queueName,
71
- data: { tx, offChainPayloads } as EthTransactionPreparationJobData,
72
- opts: {
73
- jobId, attempts: 60, backoff: { type: 'fixed', delay: 5000 },
74
- },
75
- children: [
76
- {
77
- // Step 4
78
- name: Xl1TransactionMonitor.name,
79
- queueName: Xl1TransactionMonitor.queueName,
80
- data: { tx } as Xl1TransactionMonitorJobData,
81
- opts: {
82
- jobId, attempts: 60, backoff: { type: 'fixed', delay: 5000 },
83
- },
84
- children: [
85
- {
86
- // Step 3
87
- name: Xl1TransactionSubmissionStorage.name,
88
- queueName: Xl1TransactionSubmissionStorage.queueName,
89
- data: { tx } as Xl1TransactionSubmissionStorageJobData,
90
- opts: {
91
- jobId, attempts: 60, backoff: { type: 'fixed', delay: 5000 },
92
- },
93
- children: [
94
- {
95
- // Step 2
96
- name: Xl1TransactionSubmission.name,
97
- queueName: Xl1TransactionSubmission.queueName,
98
- data: { tx } as Xl1TransactionSubmissionJobData,
99
- opts: { jobId },
100
- children: [
101
- {
102
- // Step 1 (runs first as deepest child)
103
- name: Xl1TransactionPreparation.name,
104
- queueName: Xl1TransactionPreparation.queueName,
105
- data: { tx, offChainPayloads } as Xl1TransactionPreparationJobData,
106
- opts: {
107
- jobId, attempts: 60, backoff: { type: 'fixed', delay: 5000 },
108
- },
109
- },
110
- ],
111
- },
112
- ],
113
- },
114
- ],
115
- },
116
- ],
117
- },
118
- ],
119
- },
120
- ],
121
- },
122
- ],
123
- },
124
- ],
125
- })
126
- return flow
127
- }
@@ -1,18 +0,0 @@
1
- import { PayloadBuilder } from '@xyo-network/sdk-js'
2
- import type { SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
3
-
4
- /**
5
- * Returns a deterministic & repeatable job ID based off the Transaction hash. This is to ensure
6
- * that if the same transaction is attempted to be bridged multiple times, it will have the same
7
- * job ID and not create duplicate jobs.
8
- * https://docs.bullmq.io/guide/jobs/job-ids
9
- * "The main reason to be able to specify a custom id is in cases when you want to avoid duplicated
10
- * jobs. Since ids must be unique, if you add a job with an existing id then that job will just be
11
- * ignored and not added to the queue at all."
12
- * @param tx The transaction to bridge from XL1 to ETH
13
- * @returns A deterministic job ID for the bridge job
14
- */
15
- export const getJobIdForXl1ToEthBridgeJob = async (tx: SignedHydratedTransaction) => {
16
- const jobId = await PayloadBuilder.hash(tx[0])
17
- return jobId
18
- }
@@ -1,11 +0,0 @@
1
- import type { SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
2
- import type { FlowProducer } from 'bullmq'
3
-
4
- import { Xl1ToEthBridgeParent } from '../../workers/index.ts'
5
- import { getJobIdForXl1ToEthBridgeJob } from './getJobIdForXl1ToEthBridgeJob.ts'
6
-
7
- export const getXl1ToEthBridgeJob = async (flowProducer: FlowProducer, tx: SignedHydratedTransaction) => {
8
- const id = await getJobIdForXl1ToEthBridgeJob(tx)
9
- const flow = await flowProducer.getFlow({ queueName: Xl1ToEthBridgeParent.queueName, id })
10
- return flow
11
- }
@@ -1,3 +0,0 @@
1
- export * from './createXl1ToEthBridgeJob.ts'
2
- export * from './getJobIdForXl1ToEthBridgeJob.ts'
3
- export * from './getXl1ToEthBridgeJob.ts'
@@ -1,2 +0,0 @@
1
- export * from './createEthToXl1BridgeJob.ts'
2
- export * from './createXl1ToEthBridgeJob/index.ts'
@@ -1,57 +0,0 @@
1
- import type { Xl1ToEthQueues } from './getXl1ToEthQueues.ts'
2
- import type {
3
- EthTransactionMonitorJob, EthTransactionPreparationJob,
4
- EthTransactionSubmissionJob,
5
- Xl1ToEthBridgeParentJob,
6
- Xl1TransactionMonitorJob, Xl1TransactionPreparationJob, Xl1TransactionSubmissionJob,
7
- Xl1TransactionSubmissionStorageJob,
8
- } from './workers/index.ts'
9
-
10
- export interface StatusQueueJobs {
11
- ethTransactionMonitorJob?: EthTransactionMonitorJob
12
- ethTransactionPreparationJob?: EthTransactionPreparationJob
13
- ethTransactionSubmissionJob?: EthTransactionSubmissionJob
14
- xl1ToEthBridgeParentJob?: Xl1ToEthBridgeParentJob
15
- xl1TransactionMonitorJob?: Xl1TransactionMonitorJob
16
- xl1TransactionPreparationJob?: Xl1TransactionPreparationJob
17
- xl1TransactionSubmissionJob?: Xl1TransactionSubmissionJob
18
- xl1TransactionSubmissionStorageJob?: Xl1TransactionSubmissionStorageJob
19
- }
20
-
21
- /**
22
- * Checks all the relevant status queues for a job with the given id and returns the jobs found in an object
23
- * @param queues The status queues to check for jobs
24
- * @param jobId The job id to look for in the queues, which is the same as the tx hash of the bridge transaction
25
- * @returns An object containing the jobs found in the status queues corresponding to the given job id
26
- */
27
- export const getStatusQueueJobs = async (queues: Xl1ToEthQueues, jobId: string): Promise<StatusQueueJobs> => {
28
- const [
29
- ethTransactionMonitorJob,
30
- ethTransactionPreparationJob,
31
- ethTransactionSubmissionJob,
32
- xl1ToEthBridgeParentJob,
33
- xl1TransactionMonitorJob,
34
- xl1TransactionPreparationJob,
35
- xl1TransactionSubmissionJob,
36
- xl1TransactionSubmissionStorageJob,
37
- ] = await Promise.all([
38
- queues.ethTransactionMonitor.getJob(jobId),
39
- queues.ethTransactionPreparation.getJob(jobId),
40
- queues.ethTransactionSubmission.getJob(jobId),
41
- queues.xl1ToEthBridgeParent.getJob(jobId),
42
- queues.xl1TransactionMonitor.getJob(jobId),
43
- queues.xl1TransactionPreparation.getJob(jobId),
44
- queues.xl1TransactionSubmission.getJob(jobId),
45
- queues.xl1TransactionSubmissionStorage.getJob(jobId),
46
- ])
47
- return {
48
- ethTransactionMonitorJob,
49
- ethTransactionPreparationJob,
50
- ethTransactionSubmissionJob,
51
- xl1ToEthBridgeParentJob,
52
- xl1TransactionMonitorJob,
53
- xl1TransactionPreparationJob,
54
- xl1TransactionSubmissionStorageJob,
55
- xl1TransactionSubmissionJob,
56
- }
57
- }
@@ -1,39 +0,0 @@
1
- import type { BridgeConfig } from '@xyo-network/chain-orchestration'
2
- import { Queue } from 'bullmq'
3
-
4
- import { getConnection } from './connection.ts'
5
- import { prefix } from './prefix.ts'
6
- import {
7
- EthTransactionMonitor, EthTransactionPreparation, EthTransactionSubmission, Xl1ToEthBridgeParent, Xl1TransactionMonitor, Xl1TransactionPreparation,
8
- Xl1TransactionSubmission,
9
- Xl1TransactionSubmissionStorage,
10
- } from './workers/index.ts'
11
-
12
- export interface Xl1ToEthQueues {
13
- ethTransactionMonitor: Queue
14
- ethTransactionPreparation: Queue
15
- ethTransactionSubmission: Queue
16
- xl1ToEthBridgeParent: Queue
17
- xl1TransactionMonitor: Queue
18
- xl1TransactionPreparation: Queue
19
- xl1TransactionSubmission: Queue
20
- xl1TransactionSubmissionStorage: Queue
21
- }
22
-
23
- let xl1ToEthQueues: Xl1ToEthQueues | undefined
24
-
25
- export const getXl1ToEthQueues = (config: BridgeConfig): Xl1ToEthQueues => {
26
- if (xl1ToEthQueues) return xl1ToEthQueues
27
- const connection = getConnection(config)
28
- xl1ToEthQueues = {
29
- ethTransactionMonitor: new Queue(EthTransactionMonitor.queueName, { connection, prefix }),
30
- ethTransactionPreparation: new Queue(EthTransactionPreparation.queueName, { connection, prefix }),
31
- ethTransactionSubmission: new Queue(EthTransactionSubmission.queueName, { connection, prefix }),
32
- xl1ToEthBridgeParent: new Queue(Xl1ToEthBridgeParent.queueName, { connection, prefix }),
33
- xl1TransactionMonitor: new Queue(Xl1TransactionMonitor.queueName, { connection, prefix }),
34
- xl1TransactionPreparation: new Queue(Xl1TransactionPreparation.queueName, { connection, prefix }),
35
- xl1TransactionSubmission: new Queue(Xl1TransactionSubmission.queueName, { connection, prefix }),
36
- xl1TransactionSubmissionStorage: new Queue(Xl1TransactionSubmissionStorage.queueName, { connection, prefix }),
37
- }
38
- return xl1ToEthQueues
39
- }
@@ -1,8 +0,0 @@
1
- export * from './connection.ts'
2
- export * from './flowProducer.ts'
3
- export * from './flows/index.ts'
4
- export * from './getXl1ToEthQueueJobs.ts'
5
- export * from './getXl1ToEthQueues.ts'
6
- export * from './prefix.ts'
7
- export * from './telemetry.ts'
8
- export * from './workers/index.ts'
@@ -1 +0,0 @@
1
- export const prefix = 'xl1-bridge'
@@ -1,12 +0,0 @@
1
- import { isDefined } from '@xylabs/sdk-js'
2
- import type { BullMQOtelOptions } from 'bullmq-otel'
3
- import { BullMQOtel } from 'bullmq-otel'
4
-
5
- let telemetry: BullMQOtel | undefined
6
- const options: BullMQOtelOptions = { enableMetrics: true }
7
-
8
- export const getTelemetry = () => {
9
- if (isDefined(telemetry)) return telemetry
10
- telemetry = new BullMQOtel(options)
11
- return telemetry
12
- }
@@ -1,40 +0,0 @@
1
- import type { Job } from 'bullmq'
2
- import { Worker } from 'bullmq'
3
- import type { BullMQOtel } from 'bullmq-otel'
4
- import type { Redis } from 'ioredis'
5
-
6
- import { prefix } from '../prefix.ts'
7
- import type { WorkerDescription } from './WorkerDescription.ts'
8
-
9
- export type EthToXl1BridgeParentJobData = {}
10
- export interface EthToXl1BridgeParentJobReturn { }
11
- export type EthToXl1BridgeParentJob = Job<EthToXl1BridgeParentJobData, EthToXl1BridgeParentJobReturn>
12
-
13
- const name = 'Bridge Ethereum to XL1'
14
- const queueName = 'eth-to-xl1-bridge'
15
- const createWorker = (connection: Redis, telemetry?: BullMQOtel) => {
16
- const worker = new Worker(
17
- queueName,
18
- async (job: EthToXl1BridgeParentJob) => {
19
- await job.log(`[${job.name}] start`)
20
- // Parent job has no work other than waiting on children
21
- await job.log(`[${job.name}] done`)
22
- return {}
23
- },
24
- {
25
- connection, telemetry, prefix,
26
- },
27
- )
28
-
29
- worker.on('failed', (job, err) => {
30
- console.error(`[${name}] Job ${job?.id} failed:`, err.message)
31
- })
32
-
33
- worker.on('error', (err) => {
34
- console.error(`[${name}] Worker error:`, err)
35
- })
36
- }
37
-
38
- export const EthToXl1BridgeParent: WorkerDescription = {
39
- createWorker, name, queueName,
40
- }
@@ -1,59 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
- import { PayloadBuilder } from '@xyo-network/sdk-js'
3
- import type { Job } from 'bullmq'
4
- import { Worker } from 'bullmq'
5
- import type { BullMQOtel } from 'bullmq-otel'
6
- import type { Redis } from 'ioredis'
7
-
8
- import type { IBridgeServiceCollection } from '../../services/index.ts'
9
- import { prefix } from '../prefix.ts'
10
- import type { WorkerDescription } from './WorkerDescription.ts'
11
- import type { Xl1TransactionJobData } from './Xl1TransactionJobData.ts'
12
-
13
- export type EthTransactionMonitorJobData = Xl1TransactionJobData
14
- export interface EthTransactionMonitorJobReturn {
15
- blockHash: string
16
- blockNumber: number
17
- submissionHash: string
18
- }
19
- export type EthTransactionMonitorJob = Job<EthTransactionMonitorJobData, EthTransactionMonitorJobReturn>
20
-
21
- const name = 'Monitor Submitted ETH Transaction'
22
- const queueName = 'eth-tx-monitor'
23
- const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBridgeServiceCollection) => {
24
- const provider = assertEx(services?.provider, () => 'provider service not provided')
25
- const stateMap = assertEx(services?.ethTxStateMap, () => 'ethTxStateMap service not provided')
26
-
27
- const worker = new Worker(
28
- queueName,
29
- async (job: EthTransactionMonitorJob) => {
30
- const { tx } = job.data
31
- const hash = await PayloadBuilder.hash(tx[0])
32
- const state = assertEx(await stateMap.get(hash), () => 'State not found')
33
- const submissionHash = assertEx(state?.submissionHash, () => 'submissionHash not found')
34
- const receipt = assertEx(await provider.getTransactionReceipt(submissionHash), () => 'Transaction receipt not found')
35
- await job.log(`[${hash}] confirmed ETH tx ${submissionHash} in block ${receipt.blockNumber}`)
36
- const { blockHash, blockNumber } = receipt
37
- state.confirmationHash = blockHash
38
- await stateMap.set(hash, state)
39
- return {
40
- blockHash, blockNumber, submissionHash,
41
- }
42
- },
43
- {
44
- connection, telemetry, prefix,
45
- },
46
- )
47
-
48
- worker.on('failed', (job, err) => {
49
- console.error(`[${name}] Job ${job?.id} failed:`, err.message)
50
- })
51
-
52
- worker.on('error', (err) => {
53
- console.error(`[${name}] Worker error:`, err)
54
- })
55
- }
56
-
57
- export const EthTransactionMonitor: WorkerDescription = {
58
- createWorker, name, queueName,
59
- }
@@ -1,83 +0,0 @@
1
- import { assertEx, hexToBigInt } from '@xylabs/sdk-js'
2
- import { PayloadBuilder } from '@xyo-network/sdk-js'
3
- import { isBridgeIntent } from '@xyo-network/xl1-sdk'
4
- import type { Job } from 'bullmq'
5
- import { Worker } from 'bullmq'
6
- import type { BullMQOtel } from 'bullmq-otel'
7
- import { getAddress } from 'ethers'
8
- import type { Redis } from 'ioredis'
9
-
10
- import type { IBridgeServiceCollection } from '../../services/index.ts'
11
- import {
12
- validateSufficientLiquiditySourceAllowance, validateSufficientLiquiditySourceBalance, validateSufficientRunnerEthBalanceForGas,
13
- } from '../../validation/index.ts'
14
- import { prefix } from '../prefix.ts'
15
- import type { WorkerDescription } from './WorkerDescription.ts'
16
- import type { Xl1DataLakeTransactionJobData } from './Xl1TransactionJobData.ts'
17
-
18
- export type EthTransactionPreparationJobData = Xl1DataLakeTransactionJobData
19
- export type EthTransactionPreparationJobReturn = Record<string, never>
20
- export type EthTransactionPreparationJob = Job<EthTransactionPreparationJobData, EthTransactionPreparationJobReturn>
21
-
22
- const name = 'Prepare ETH Transaction'
23
- const queueName = 'eth-tx-prepare'
24
-
25
- export const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBridgeServiceCollection) => {
26
- const bridge = assertEx(services?.bridge, () => 'bridge service not provided')
27
- const bridgeableToken = assertEx(services?.bridgeableToken, () => 'bridgeableToken service not provided')
28
- const stateMap = assertEx(services?.ethTxStateMap, () => 'ethTxStateMap service not provided')
29
- const wallet = assertEx(services?.wallet, () => 'wallet service not provided')
30
-
31
- const worker = new Worker(
32
- queueName,
33
- async (job: EthTransactionPreparationJob) => {
34
- const { tx, offChainPayloads } = job.data
35
- const hash = await PayloadBuilder.hash(tx[0])
36
- await job.log(`[${hash}] preparing ETH transaction`)
37
- await job.log(`[${hash}] validating liquiditySource has sufficient allowance`)
38
- if (!await validateSufficientLiquiditySourceAllowance(tx, offChainPayloads, bridgeableToken, bridge, job)) {
39
- throw new Error('Liquidity source does not have sufficient allowance for the bridge to execute the transaction')
40
- }
41
- await job.log(`[${hash}] validated liquiditySource has sufficient allowance`)
42
- await job.log(`[${hash}] validating liquiditySource has sufficient balance`)
43
- if (!await validateSufficientLiquiditySourceBalance(tx, offChainPayloads, bridgeableToken, bridge, job)) {
44
- throw new Error('Liquidity source does not have sufficient balance for the bridge to execute the transaction')
45
- }
46
- await job.log(`[${hash}] validated liquiditySource has sufficient balance`)
47
- await job.log(`[${hash}] building ETH transaction`)
48
- const allPayloads = [...tx[1], ...offChainPayloads]
49
- const bridgeIntent = assertEx(allPayloads.find(isBridgeIntent), () => 'No bridge intent found')
50
- const amount = hexToBigInt(bridgeIntent.destAmount)
51
- const srcAddress = getAddress(bridgeIntent.srcAddress)
52
- const destAddress = getAddress(bridgeIntent.destAddress)
53
- const nonce = hexToBigInt(await PayloadBuilder.hash(tx[0]))
54
- const preparedTx = await bridge.getFunction('bridgeFromRemote').populateTransaction(srcAddress, destAddress, amount, nonce)
55
- await job.log(`[${hash}] built ETH transaction`)
56
- await job.log(`[${hash}] validating tx runner has sufficient ETH for gas`)
57
- if (!await validateSufficientRunnerEthBalanceForGas(preparedTx, wallet, job)) {
58
- throw new Error('Transaction runner does not have sufficient ETH to cover estimated gas (with buffer)')
59
- }
60
- await job.log(`[${hash}] validated tx runner has sufficient ETH for gas`)
61
- await job.log(`[${hash}] storing ETH preparedTx`)
62
- await stateMap.set(hash, { preparedTx })
63
- await job.log(`[${hash}] stored ETH preparedTx`)
64
- await job.log(`[${hash}] prepared ETH transaction`)
65
- return {}
66
- },
67
- {
68
- connection, telemetry, prefix,
69
- },
70
- )
71
-
72
- worker.on('failed', (job, err) => {
73
- console.error(`[${name}] Job ${job?.id} failed:`, err.message)
74
- })
75
-
76
- worker.on('error', (err) => {
77
- console.error(`[${name}] Worker error:`, err)
78
- })
79
- }
80
-
81
- export const EthTransactionPreparation: WorkerDescription = {
82
- createWorker, name, queueName,
83
- }
@@ -1,63 +0,0 @@
1
- import { assertEx, isDefined } from '@xylabs/sdk-js'
2
- import { PayloadBuilder } from '@xyo-network/sdk-js'
3
- import type { Job } from 'bullmq'
4
- import { Worker } from 'bullmq'
5
- import type { BullMQOtel } from 'bullmq-otel'
6
- import type { Redis } from 'ioredis'
7
-
8
- import type { EthTxState, IBridgeServiceCollection } from '../../services/index.ts'
9
- import { prefix } from '../prefix.ts'
10
- import { submitEthTransaction } from './util/index.ts'
11
- import type { WorkerDescription } from './WorkerDescription.ts'
12
- import type { Xl1DataLakeTransactionJobData } from './Xl1TransactionJobData.ts'
13
-
14
- export type EthTransactionSubmissionJobData = Xl1DataLakeTransactionJobData
15
- export interface EthTransactionSubmissionJobReturn {
16
- submissionHash: Required<EthTxState>['submissionHash']
17
- }
18
- export type EthTransactionSubmissionJob = Job<EthTransactionSubmissionJobData, EthTransactionSubmissionJobReturn>
19
-
20
- const name = 'Submit ETH Transaction'
21
- const queueName = 'eth-tx-submit'
22
- const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBridgeServiceCollection) => {
23
- const bridge = assertEx(services?.bridge, () => 'bridge service not provided')
24
- const wallet = assertEx(services?.wallet, () => 'wallet service not provided')
25
- const stateMap = assertEx(services?.ethTxStateMap, () => 'ethTxStateMap service not provided')
26
-
27
- const worker = new Worker(
28
- queueName,
29
- async (job: EthTransactionSubmissionJob) => {
30
- const { tx, offChainPayloads } = job.data
31
- const hash = await PayloadBuilder.hash(tx[0])
32
- const state = assertEx(await stateMap.get(hash), () => `[${hash}] state not found`)
33
-
34
- // Idempotency check against resubmission
35
- const { submissionHash: existingSubmissionHash } = state
36
- if (isDefined(existingSubmissionHash)) {
37
- await job.log(`[${hash}] Tx already submitted with submission response hash ${existingSubmissionHash}`)
38
- return { submissionHash: existingSubmissionHash }
39
- }
40
-
41
- // Submit the transaction to the Ethereum network
42
- await job.log(`[${hash}] Submitting ETH tx`)
43
- const submissionHash = assertEx(await submitEthTransaction(tx, offChainPayloads, bridge, wallet), () => `[${hash}] submissionHash not found in receipt`)
44
- await job.log(`[${hash}] Submitted ETH tx and received submission response hash ${submissionHash}`)
45
- return { submissionHash }
46
- },
47
- {
48
- connection, telemetry, concurrency: 1, prefix,
49
- },
50
- )
51
-
52
- worker.on('failed', (job, err) => {
53
- console.error(`[${name}] Job ${job?.id} failed:`, err.message)
54
- })
55
-
56
- worker.on('error', (err) => {
57
- console.error(`[${name}] Worker error:`, err)
58
- })
59
- }
60
-
61
- export const EthTransactionSubmission: WorkerDescription = {
62
- createWorker, name, queueName,
63
- }