@xyo-network/chain-bridge 1.20.15 → 1.20.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -75
- package/dist/node/index.mjs +44 -0
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/queue/flows/createXl1ToEthBridgeJob/getJobIdForXl1ToEthBridgeJob.d.ts +1 -1
- package/dist/node/queue/flows/createXl1ToEthBridgeJob/getJobIdForXl1ToEthBridgeJob.d.ts.map +1 -1
- package/dist/node/server/routes/addProbeRoutes.d.ts +3 -0
- package/dist/node/server/routes/addProbeRoutes.d.ts.map +1 -0
- package/dist/node/server/routes/addRoutes.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeConfig.d.ts +7 -7
- package/dist/node/server/routes/{healthz → livez}/get.d.ts +1 -1
- package/dist/node/server/routes/livez/get.d.ts.map +1 -0
- package/dist/node/server/routes/livez/index.d.ts.map +1 -0
- package/dist/node/server/routes/readyz/get.d.ts +4 -0
- package/dist/node/server/routes/readyz/get.d.ts.map +1 -0
- package/dist/node/server/routes/readyz/index.d.ts +2 -0
- package/dist/node/server/routes/readyz/index.d.ts.map +1 -0
- package/dist/node/server/routes/startupz/get.d.ts +4 -0
- package/dist/node/server/routes/startupz/get.d.ts.map +1 -0
- package/dist/node/server/routes/startupz/index.d.ts +2 -0
- package/dist/node/server/routes/startupz/index.d.ts.map +1 -0
- package/package.json +143 -54
- package/dist/node/server/routes/healthz/get.d.ts.map +0 -1
- package/dist/node/server/routes/healthz/index.d.ts.map +0 -1
- package/src/BridgeActor.ts +0 -51
- package/src/config/asChainId.ts +0 -7
- package/src/config/asToken.ts +0 -7
- package/src/config/getBridgeEscrowAddress.ts +0 -13
- package/src/config/getBridgeFeesAddress.ts +0 -13
- package/src/config/getBridgeSettings.ts +0 -24
- package/src/config/getBridgeWalletAccount.ts +0 -37
- package/src/config/getFeeStructure.ts +0 -8
- package/src/config/getMaxBridgeAmount.ts +0 -7
- package/src/config/getMinBridgeAmount.ts +0 -7
- package/src/config/getRemoteChainId.ts +0 -10
- package/src/config/getRemoteTokenAddress.ts +0 -10
- package/src/config/getTestGateway.ts +0 -24
- package/src/config/getTransferAddresses.ts +0 -17
- package/src/config/getXl1ChainId.ts +0 -13
- package/src/config/getXl1TokenAddress.ts +0 -12
- package/src/config/index.ts +0 -15
- package/src/index.ts +0 -1
- package/src/interface/index.ts +0 -4
- package/src/interface/interface/ChainBridgeRelayInterface.ts +0 -9
- package/src/interface/interface/IntentIndexerInterface.ts +0 -8
- package/src/interface/interface/LockingProcessorInterface.ts +0 -10
- package/src/interface/interface/ObservationIndexerInterface.ts +0 -12
- package/src/interface/interface/Params.ts +0 -26
- package/src/interface/interface/RelayInterface.ts +0 -8
- package/src/interface/interface/index.ts +0 -6
- package/src/interface/repository/RepositoryInterface.ts +0 -28
- package/src/interface/repository/index.ts +0 -1
- package/src/interface/service/Observer/ERC20TransferObserver/ERC20TransferObserver.ts +0 -180
- package/src/interface/service/Observer/ERC20TransferObserver/index.ts +0 -1
- package/src/interface/service/Observer/LiquidityPoolBridgeObserver/LiquidityPoolBridgeObserver.ts +0 -210
- package/src/interface/service/Observer/LiquidityPoolBridgeObserver/index.ts +0 -1
- package/src/interface/service/Observer/Observer.ts +0 -48
- package/src/interface/service/Observer/index.ts +0 -1
- package/src/interface/service/Relay/ChainBridgeRelay/ChainBridgeRelayInterface.ts +0 -11
- package/src/interface/service/Relay/ChainBridgeRelay/ChainBridgeRelayService.ts +0 -116
- package/src/interface/service/Relay/ChainBridgeRelay/index.ts +0 -1
- package/src/interface/service/Relay/LiquidityPoolBridgeRelay/LiquidityPoolBridgeRelay.ts +0 -227
- package/src/interface/service/Relay/LiquidityPoolBridgeRelay/index.ts +0 -1
- package/src/interface/service/Relay/index.ts +0 -1
- package/src/interface/service/index.ts +0 -2
- package/src/interface/util/getBridgeIntentIdentifier.ts +0 -18
- package/src/interface/util/index.ts +0 -1
- package/src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.ts +0 -235
- package/src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/index.ts +0 -1
- package/src/modules/index.ts +0 -1
- package/src/queue/connection.ts +0 -16
- package/src/queue/flowProducer.ts +0 -16
- package/src/queue/flows/createEthToXl1BridgeJob.ts +0 -71
- package/src/queue/flows/createXl1ToEthBridgeJob/createXl1ToEthBridgeJob.ts +0 -127
- package/src/queue/flows/createXl1ToEthBridgeJob/getJobIdForXl1ToEthBridgeJob.ts +0 -18
- package/src/queue/flows/createXl1ToEthBridgeJob/getXl1ToEthBridgeJob.ts +0 -11
- package/src/queue/flows/createXl1ToEthBridgeJob/index.ts +0 -3
- package/src/queue/flows/index.ts +0 -2
- package/src/queue/getXl1ToEthQueueJobs.ts +0 -57
- package/src/queue/getXl1ToEthQueues.ts +0 -39
- package/src/queue/index.ts +0 -8
- package/src/queue/prefix.ts +0 -1
- package/src/queue/telemetry.ts +0 -12
- package/src/queue/workers/EthToXl1BridgeParent.ts +0 -40
- package/src/queue/workers/EthTransactionMonitor.ts +0 -59
- package/src/queue/workers/EthTransactionPreparation.ts +0 -83
- package/src/queue/workers/EthTransactionSubmission.ts +0 -63
- package/src/queue/workers/EthTransactionSubmissionStorage.ts +0 -76
- package/src/queue/workers/WorkerDescription.ts +0 -10
- package/src/queue/workers/Xl1ToEthBridgeParent.ts +0 -41
- package/src/queue/workers/Xl1TransactionJobData.ts +0 -12
- package/src/queue/workers/Xl1TransactionMonitor.ts +0 -82
- package/src/queue/workers/Xl1TransactionPreparation.ts +0 -52
- package/src/queue/workers/Xl1TransactionSubmission.ts +0 -70
- package/src/queue/workers/Xl1TransactionSubmissionStorage.ts +0 -77
- package/src/queue/workers/createWorkers.ts +0 -29
- package/src/queue/workers/index.ts +0 -11
- package/src/queue/workers/util/index.ts +0 -2
- package/src/queue/workers/util/submitEthTransaction.ts +0 -32
- package/src/queue/workers/util/submitXl1Transaction.ts +0 -26
- package/src/server/addFlowProducer.ts +0 -14
- package/src/server/addWorkers.ts +0 -13
- package/src/server/app.ts +0 -20
- package/src/server/index.ts +0 -19
- package/src/server/instrumentation.ts +0 -15
- package/src/server/routes/addRoutes.ts +0 -9
- package/src/server/routes/bridge/addBridgeRoutes.ts +0 -12
- package/src/server/routes/bridge/index.ts +0 -1
- package/src/server/routes/bridge/routeDefinitions/getRouteDefinitions.ts +0 -18
- package/src/server/routes/bridge/routeDefinitions/index.ts +0 -1
- package/src/server/routes/bridge/routeDefinitions/pathParams/ChainIdPathParam.ts +0 -21
- package/src/server/routes/bridge/routeDefinitions/pathParams/index.ts +0 -1
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeConfig.ts +0 -46
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.ts +0 -58
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.ts +0 -93
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts +0 -69
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.ts +0 -64
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts +0 -98
- package/src/server/routes/bridge/routeDefinitions/routes/index.ts +0 -6
- package/src/server/routes/healthz/get.ts +0 -20
- package/src/server/routes/healthz/index.ts +0 -1
- package/src/server/routes/index.ts +0 -1
- package/src/server/server.ts +0 -21
- package/src/services/EthTxState.ts +0 -5
- package/src/services/IBridgeServiceCollection.ts +0 -19
- package/src/services/TxState.ts +0 -14
- package/src/services/Xl1TxState.ts +0 -9
- package/src/services/getIterableMap.ts +0 -34
- package/src/services/getServices.ts +0 -41
- package/src/services/index.ts +0 -5
- package/src/util/BridgeFees.ts +0 -16
- package/src/util/bridgeFeesAsBigInt.ts +0 -15
- package/src/util/calculateBridgeFees.ts +0 -33
- package/src/util/calculateMaxBridgeAmount.ts +0 -22
- package/src/util/createBridgeTransfer.ts +0 -31
- package/src/util/generateBridgeEstimate.ts +0 -55
- package/src/util/getConfigFromEnv.ts +0 -15
- package/src/util/index.ts +0 -7
- package/src/validation/AsyncLogger.ts +0 -5
- package/src/validation/index.ts +0 -6
- package/src/validation/validateBridgeEstimate.ts +0 -60
- package/src/validation/validateBridgeEstimateExact.ts +0 -39
- package/src/validation/validateBridgeTransaction.ts +0 -53
- package/src/validation/validateSufficientLiquiditySourceAllowance.ts +0 -39
- package/src/validation/validateSufficientLiquiditySourceBalance.ts +0 -38
- package/src/validation/validateSufficientRunnerEthBalanceForGas.ts +0 -57
- package/src/validation/validateSufficientXL1SourceAddressBalance.ts +0 -39
- /package/dist/node/server/routes/{healthz → livez}/index.d.ts +0 -0
|
@@ -1,76 +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 type { EthTransactionSubmissionJobReturn } from './EthTransactionSubmission.ts'
|
|
11
|
-
import { EthTransactionSubmission } from './EthTransactionSubmission.ts'
|
|
12
|
-
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
13
|
-
import type { Xl1TransactionJobData } from './Xl1TransactionJobData.ts'
|
|
14
|
-
|
|
15
|
-
export type EthTransactionSubmissionStorageJobData = Xl1TransactionJobData
|
|
16
|
-
export interface EthTransactionSubmissionStorageJobReturn {
|
|
17
|
-
submissionHash: Required<EthTxState>['submissionHash']
|
|
18
|
-
}
|
|
19
|
-
export type EthTransactionSubmissionStorageJob = Job<EthTransactionSubmissionStorageJobData, EthTransactionSubmissionStorageJobReturn>
|
|
20
|
-
|
|
21
|
-
const name = 'Store ETH Transaction Submission'
|
|
22
|
-
const queueName = 'eth-tx-store-submission'
|
|
23
|
-
|
|
24
|
-
const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBridgeServiceCollection) => {
|
|
25
|
-
const stateMap = assertEx(services?.ethTxStateMap, () => 'ethTxStateMap service not provided')
|
|
26
|
-
|
|
27
|
-
const worker = new Worker(
|
|
28
|
-
queueName,
|
|
29
|
-
async (job: EthTransactionSubmissionStorageJob) => {
|
|
30
|
-
const { tx } = job.data
|
|
31
|
-
// Get the hash of the transaction
|
|
32
|
-
const hash = await PayloadBuilder.hash(tx[0])
|
|
33
|
-
|
|
34
|
-
// Get the state of the transaction
|
|
35
|
-
const state = assertEx(await stateMap.get(hash), () => `[${hash}] state not found`)
|
|
36
|
-
|
|
37
|
-
// Idempotency check against re-store
|
|
38
|
-
const { submissionHash: existingSubmissionHash } = state
|
|
39
|
-
if (isDefined(existingSubmissionHash)) {
|
|
40
|
-
await job.log(`[${hash}] submissionHash already stored as ${existingSubmissionHash}`)
|
|
41
|
-
return { submissionHash: existingSubmissionHash }
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// In a Flow, this job should be the PARENT and the submit job should be a CHILD.
|
|
45
|
-
// That lets us read the child job’s return value(s) here.
|
|
46
|
-
const childrenValues = await job.getChildrenValues()
|
|
47
|
-
const jobKey = `${prefix}:${EthTransactionSubmission.queueName}:${hash}`
|
|
48
|
-
const childValues = childrenValues?.[jobKey] as EthTransactionSubmissionJobReturn | undefined
|
|
49
|
-
const submissionHash = childValues?.submissionHash
|
|
50
|
-
|
|
51
|
-
const resolvedSubmissionHash = assertEx(submissionHash, () => `[${hash}] child submissionHash not found in children values`)
|
|
52
|
-
|
|
53
|
-
// Store the submission hash in the state
|
|
54
|
-
await job.log(`[${hash}] Storing ETH submissionHash`)
|
|
55
|
-
state.submissionHash = resolvedSubmissionHash
|
|
56
|
-
await stateMap.set(hash, state)
|
|
57
|
-
await job.log(`[${hash}] Stored ETH submissionHash`)
|
|
58
|
-
return { submissionHash: resolvedSubmissionHash }
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
connection, telemetry, prefix,
|
|
62
|
-
},
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
worker.on('failed', (job, err) => {
|
|
66
|
-
console.error(`[${name}] Job ${job?.id} failed:`, err.message)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
worker.on('error', (err) => {
|
|
70
|
-
console.error(`[${name}] Worker error:`, err)
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export const EthTransactionSubmissionStorage: WorkerDescription = {
|
|
75
|
-
createWorker, name, queueName,
|
|
76
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { BullMQOtel } from 'bullmq-otel'
|
|
2
|
-
import type { Redis } from 'ioredis'
|
|
3
|
-
|
|
4
|
-
import type { IBridgeServiceCollection } from '../../services/index.ts'
|
|
5
|
-
|
|
6
|
-
export interface WorkerDescription {
|
|
7
|
-
createWorker: (connection: Redis, telemetry?: BullMQOtel, services?: IBridgeServiceCollection) => void
|
|
8
|
-
name: string
|
|
9
|
-
queueName: string
|
|
10
|
-
}
|
|
@@ -1,41 +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
|
-
import type { Xl1DataLakeTransactionJobData } from './Xl1TransactionJobData.ts'
|
|
9
|
-
|
|
10
|
-
export type Xl1ToEthBridgeParentJobData = Xl1DataLakeTransactionJobData
|
|
11
|
-
export interface Xl1ToEthBridgeParentJobReturn { }
|
|
12
|
-
export type Xl1ToEthBridgeParentJob = Job<Xl1ToEthBridgeParentJobData, Xl1ToEthBridgeParentJobReturn>
|
|
13
|
-
|
|
14
|
-
const name = 'Bridge XL1 to Ethereum'
|
|
15
|
-
const queueName = 'xl1-to-eth-bridge'
|
|
16
|
-
const createWorker = (connection: Redis, telemetry?: BullMQOtel) => {
|
|
17
|
-
const worker = new Worker(
|
|
18
|
-
queueName,
|
|
19
|
-
async (job: Xl1ToEthBridgeParentJob) => {
|
|
20
|
-
await job.log(`[${job.name}] start`)
|
|
21
|
-
// Parent job has no work other than waiting on children
|
|
22
|
-
await job.log(`[${job.name}] done`)
|
|
23
|
-
return {}
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
connection, telemetry, prefix,
|
|
27
|
-
},
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
worker.on('failed', (job, err) => {
|
|
31
|
-
console.error(`[${name}] Job ${job?.id} failed:`, err.message)
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
worker.on('error', (err) => {
|
|
35
|
-
console.error(`[${name}] Worker error:`, err)
|
|
36
|
-
})
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export const Xl1ToEthBridgeParent: WorkerDescription = {
|
|
40
|
-
createWorker, name, queueName,
|
|
41
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Payload } from '@xyo-network/sdk-js'
|
|
2
|
-
import type { SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Represents the data required for a job that requires an XL1 transaction.
|
|
6
|
-
*/
|
|
7
|
-
export type Xl1TransactionJobData = { tx: SignedHydratedTransaction }
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Represents the data required for a job that requires an XL1 transaction and its associated off-chain payloads.
|
|
11
|
-
*/
|
|
12
|
-
export type Xl1DataLakeTransactionJobData = Xl1TransactionJobData & { offChainPayloads: Payload[] }
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import type { BrandedHash } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
assertEx, isDefined, isNull,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
6
|
-
import type { Job } from 'bullmq'
|
|
7
|
-
import { UnrecoverableError, Worker } from 'bullmq'
|
|
8
|
-
import type { BullMQOtel } from 'bullmq-otel'
|
|
9
|
-
import type { Redis } from 'ioredis'
|
|
10
|
-
|
|
11
|
-
import type { IBridgeServiceCollection } from '../../services/index.ts'
|
|
12
|
-
import { prefix } from '../prefix.ts'
|
|
13
|
-
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
14
|
-
import type { Xl1TransactionJobData } from './Xl1TransactionJobData.ts'
|
|
15
|
-
|
|
16
|
-
export type Xl1TransactionMonitorJobData = Xl1TransactionJobData
|
|
17
|
-
export interface Xl1TransactionMonitorJobReturn {
|
|
18
|
-
submissionHash: BrandedHash
|
|
19
|
-
}
|
|
20
|
-
export type Xl1TransactionMonitorJob = Job<Xl1TransactionMonitorJobData, Xl1TransactionMonitorJobReturn>
|
|
21
|
-
|
|
22
|
-
const name = 'Monitor Submitted XL1 Transaction'
|
|
23
|
-
const queueName = 'xl1-tx-monitor'
|
|
24
|
-
const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBridgeServiceCollection) => {
|
|
25
|
-
const gateway = assertEx(services?.gateway, () => 'gateway service not provided')
|
|
26
|
-
const stateMap = assertEx(services?.xl1TxStateMap, () => 'xl1TxStateMap service not provided')
|
|
27
|
-
const viewer = assertEx(gateway.connection.viewer, () => 'viewer not defined on gateway')
|
|
28
|
-
|
|
29
|
-
const worker = new Worker(
|
|
30
|
-
queueName,
|
|
31
|
-
async (job: Xl1TransactionMonitorJob) => {
|
|
32
|
-
const { tx } = job.data
|
|
33
|
-
// Get the hash of the transaction
|
|
34
|
-
const hash = await PayloadBuilder.hash(tx[0])
|
|
35
|
-
// Get the state of the transaction
|
|
36
|
-
const state = assertEx(await stateMap.get(hash), () => `[${hash}] state not found`)
|
|
37
|
-
const submissionHash = assertEx(state.submissionHash, () => `[${hash}] submissionHash not found`)
|
|
38
|
-
|
|
39
|
-
// Check for transaction inclusion on chain
|
|
40
|
-
await job.log(`[${hash}] Checking for XL1 transaction inclusion on chain`)
|
|
41
|
-
const foundTx = await viewer.transaction.byHash(submissionHash)
|
|
42
|
-
// const foundTx = await viewer.transaction.byHash(submissionHash)
|
|
43
|
-
|
|
44
|
-
// Transaction found on chain
|
|
45
|
-
if (isDefined(foundTx) && !isNull(foundTx)) {
|
|
46
|
-
await job.log(`[${hash}] Found transaction on chain`)
|
|
47
|
-
// Store the block hash
|
|
48
|
-
const submissionHash = await PayloadBuilder.hash(foundTx[0])
|
|
49
|
-
return { submissionHash }
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Check for transaction expiration
|
|
53
|
-
const currentBlockNumber = await viewer.currentBlockNumber()
|
|
54
|
-
if (tx[0].exp < currentBlockNumber) {
|
|
55
|
-
await job.log(
|
|
56
|
-
`[${hash}] Transaction expired at block ${tx[0].exp}, current block ${currentBlockNumber}`,
|
|
57
|
-
)
|
|
58
|
-
// Throw unrecoverable error to stop retries
|
|
59
|
-
throw new UnrecoverableError(`[${hash}] Transaction expired and will never be included`)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Transaction not yet found, but still valid — retry later
|
|
63
|
-
await job.log(`[${hash}] Transaction not yet included, retrying later`)
|
|
64
|
-
throw new Error(`[${hash}] Transaction not yet included`)
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
connection, telemetry, prefix,
|
|
68
|
-
},
|
|
69
|
-
)
|
|
70
|
-
|
|
71
|
-
worker.on('failed', (job, err) => {
|
|
72
|
-
console.error(`[${name}] Job ${job?.id} failed:`, err.message)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
worker.on('error', (err) => {
|
|
76
|
-
console.error(`[${name}] Worker error:`, err)
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export const Xl1TransactionMonitor: WorkerDescription = {
|
|
81
|
-
createWorker, name, queueName,
|
|
82
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
2
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
3
|
-
import type { SignedHydratedTransaction } 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 type { Redis } from 'ioredis'
|
|
8
|
-
|
|
9
|
-
import type { IBridgeServiceCollection } from '../../services/index.ts'
|
|
10
|
-
import { prefix } from '../prefix.ts'
|
|
11
|
-
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
12
|
-
import type { Xl1DataLakeTransactionJobData } from './Xl1TransactionJobData.ts'
|
|
13
|
-
|
|
14
|
-
export type Xl1TransactionPreparationJobData = Xl1DataLakeTransactionJobData
|
|
15
|
-
export interface Xl1TransactionPreparationJobReturn { preparedTx: SignedHydratedTransaction }
|
|
16
|
-
export type Xl1TransactionPreparationJob = Job<Xl1TransactionPreparationJobData, Xl1TransactionPreparationJobReturn>
|
|
17
|
-
|
|
18
|
-
const name = 'Prepare XL1 Transaction'
|
|
19
|
-
const queueName = 'xl1-tx-prepare'
|
|
20
|
-
const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBridgeServiceCollection) => {
|
|
21
|
-
const stateMap = assertEx(services?.xl1TxStateMap, () => 'xl1TxStateMap service not provided')
|
|
22
|
-
|
|
23
|
-
const worker = new Worker(
|
|
24
|
-
queueName,
|
|
25
|
-
async (job: Xl1TransactionPreparationJob) => {
|
|
26
|
-
const { tx, offChainPayloads = [] } = job.data
|
|
27
|
-
const hash = await PayloadBuilder.hash(tx[0])
|
|
28
|
-
await job.log(`[${hash}] preparing XL1 transaction`)
|
|
29
|
-
const preparedTx = tx
|
|
30
|
-
await job.log(`[${hash}] storing XL1 preparedTx`)
|
|
31
|
-
await stateMap.set(hash, { offChainPayloads, preparedTx })
|
|
32
|
-
await job.log(`[${hash}] stored XL1 preparedTx`)
|
|
33
|
-
await job.log(`[${hash}] prepared XL1 transaction`)
|
|
34
|
-
return { preparedTx }
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
connection, telemetry, prefix,
|
|
38
|
-
},
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
worker.on('failed', (job, err) => {
|
|
42
|
-
console.error(`[${name}] Job ${job?.id} failed:`, err.message)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
worker.on('error', (err) => {
|
|
46
|
-
console.error(`[${name}] Worker error:`, err)
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export const Xl1TransactionPreparation: WorkerDescription = {
|
|
51
|
-
createWorker, name, queueName,
|
|
52
|
-
}
|
|
@@ -1,70 +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 { IBridgeServiceCollection, Xl1TxState } from '../../services/index.ts'
|
|
9
|
-
import { prefix } from '../prefix.ts'
|
|
10
|
-
import { submitXl1Transaction } from './util/index.ts'
|
|
11
|
-
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
12
|
-
import type { Xl1TransactionJobData } from './Xl1TransactionJobData.ts'
|
|
13
|
-
|
|
14
|
-
export type Xl1TransactionSubmissionJobData = Xl1TransactionJobData
|
|
15
|
-
export interface Xl1TransactionSubmissionJobReturn {
|
|
16
|
-
submissionHash: Required<Xl1TxState>['submissionHash']
|
|
17
|
-
}
|
|
18
|
-
export type Xl1TransactionSubmissionJob = Job<Xl1TransactionSubmissionJobData, Xl1TransactionSubmissionJobReturn>
|
|
19
|
-
|
|
20
|
-
const name = 'Submit XL1 Transaction'
|
|
21
|
-
const queueName = 'xl1-tx-submit'
|
|
22
|
-
|
|
23
|
-
const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBridgeServiceCollection) => {
|
|
24
|
-
const gateway = assertEx(services?.gateway, () => 'gateway service not provided')
|
|
25
|
-
const stateMap = assertEx(services?.xl1TxStateMap, () => 'xl1TxStateMap service not provided')
|
|
26
|
-
|
|
27
|
-
const worker = new Worker(
|
|
28
|
-
queueName,
|
|
29
|
-
async (job: Xl1TransactionSubmissionJob) => {
|
|
30
|
-
const { tx } = job.data
|
|
31
|
-
// Get the hash of the transaction
|
|
32
|
-
const hash = await PayloadBuilder.hash(tx[0])
|
|
33
|
-
// Get the state of the transaction
|
|
34
|
-
const state = assertEx(await stateMap.get(hash), () => `[${hash}] state not found`)
|
|
35
|
-
const {
|
|
36
|
-
preparedTx, offChainPayloads = [], submissionHash: existingSubmissionHash,
|
|
37
|
-
} = state
|
|
38
|
-
|
|
39
|
-
// Idempotency check against resubmission
|
|
40
|
-
if (isDefined(existingSubmissionHash)) {
|
|
41
|
-
await job.log(`[${hash}] Tx already submitted with submission response hash ${existingSubmissionHash}`)
|
|
42
|
-
return { submissionHash: existingSubmissionHash }
|
|
43
|
-
}
|
|
44
|
-
const txToSubmit = assertEx(preparedTx, () => `[${hash}] preparedTx not found`)
|
|
45
|
-
|
|
46
|
-
// Submit the transaction to the XL1 network
|
|
47
|
-
await job.log(`[${hash}] Submitting XL1 tx`)
|
|
48
|
-
const [submissionHash] = await submitXl1Transaction(txToSubmit, offChainPayloads, gateway)
|
|
49
|
-
await job.log(`[${hash}] Submitted XL1 tx`)
|
|
50
|
-
|
|
51
|
-
// This worker intentionally does NOT store state as subsequent steps will do that.
|
|
52
|
-
return { submissionHash }
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
connection, telemetry, prefix,
|
|
56
|
-
},
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
worker.on('failed', (job, err) => {
|
|
60
|
-
console.error(`[${name}] Job ${job?.id} failed:`, err.message)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
worker.on('error', (err) => {
|
|
64
|
-
console.error(`[${name}] Worker error:`, err)
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export const Xl1TransactionSubmission: WorkerDescription = {
|
|
69
|
-
createWorker, name, queueName,
|
|
70
|
-
}
|
|
@@ -1,77 +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 { IBridgeServiceCollection, Xl1TxState } 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
|
-
import type { Xl1TransactionSubmissionJobReturn } from './Xl1TransactionSubmission.ts'
|
|
13
|
-
import { Xl1TransactionSubmission } from './Xl1TransactionSubmission.ts'
|
|
14
|
-
|
|
15
|
-
export type Xl1TransactionSubmissionStorageJobData = Xl1TransactionJobData
|
|
16
|
-
export interface Xl1TransactionSubmissionStorageJobReturn {
|
|
17
|
-
submissionHash: Required<Xl1TxState>['submissionHash']
|
|
18
|
-
}
|
|
19
|
-
export type Xl1TransactionSubmissionStorageJob = Job<Xl1TransactionSubmissionStorageJobData, Xl1TransactionSubmissionStorageJobReturn>
|
|
20
|
-
|
|
21
|
-
const name = 'Store XL1 Transaction Submission'
|
|
22
|
-
const queueName = 'xl1-tx-store-submission'
|
|
23
|
-
|
|
24
|
-
const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBridgeServiceCollection) => {
|
|
25
|
-
const stateMap = assertEx(services?.xl1TxStateMap, () => 'xl1TxStateMap service not provided')
|
|
26
|
-
|
|
27
|
-
const worker = new Worker(
|
|
28
|
-
queueName,
|
|
29
|
-
async (job: Xl1TransactionSubmissionStorageJob) => {
|
|
30
|
-
const { tx } = job.data
|
|
31
|
-
// Get the hash of the transaction
|
|
32
|
-
const hash = await PayloadBuilder.hash(tx[0])
|
|
33
|
-
|
|
34
|
-
// Get the state of the transaction
|
|
35
|
-
const state = assertEx(await stateMap.get(hash), () => `[${hash}] state not found`)
|
|
36
|
-
|
|
37
|
-
// Idempotency check against re-store
|
|
38
|
-
const { submissionHash: existingSubmissionHash } = state
|
|
39
|
-
if (isDefined(existingSubmissionHash)) {
|
|
40
|
-
await job.log(`[${hash}] submissionHash already stored as ${existingSubmissionHash}`)
|
|
41
|
-
return { submissionHash: existingSubmissionHash }
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// In a Flow, this job should be the PARENT and the submit job should be a CHILD.
|
|
45
|
-
// That lets us read the child job’s return value(s) here.
|
|
46
|
-
const childrenValues = await job.getChildrenValues()
|
|
47
|
-
const jobKey = `${prefix}:${Xl1TransactionSubmission.queueName}:${hash}`
|
|
48
|
-
const childValues = childrenValues?.[jobKey] as Xl1TransactionSubmissionJobReturn | undefined
|
|
49
|
-
const submissionHash = childValues?.submissionHash
|
|
50
|
-
|
|
51
|
-
const resolvedSubmissionHash = assertEx(submissionHash, () => `[${hash}] child submissionHash not found in children values`)
|
|
52
|
-
|
|
53
|
-
// Store the submission hash in the state
|
|
54
|
-
await job.log(`[${hash}] Storing XL1 submissionHash`)
|
|
55
|
-
state.submissionHash = resolvedSubmissionHash
|
|
56
|
-
await stateMap.set(hash, state)
|
|
57
|
-
await job.log(`[${hash}] Stored XL1 submissionHash`)
|
|
58
|
-
|
|
59
|
-
return { submissionHash: resolvedSubmissionHash }
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
connection, telemetry, prefix,
|
|
63
|
-
},
|
|
64
|
-
)
|
|
65
|
-
|
|
66
|
-
worker.on('failed', (job, err) => {
|
|
67
|
-
console.error(`[${name}] Job ${job?.id} failed:`, err.message)
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
worker.on('error', (err) => {
|
|
71
|
-
console.error(`[${name}] Worker error:`, err)
|
|
72
|
-
})
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const Xl1TransactionSubmissionStorage: WorkerDescription = {
|
|
76
|
-
createWorker, name, queueName,
|
|
77
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { BullMQOtel } from 'bullmq-otel'
|
|
2
|
-
import type { Redis } from 'ioredis'
|
|
3
|
-
|
|
4
|
-
import type { IBridgeServiceCollection } from '../../services/index.ts'
|
|
5
|
-
import {
|
|
6
|
-
EthTransactionMonitor,
|
|
7
|
-
EthTransactionPreparation,
|
|
8
|
-
EthTransactionSubmission,
|
|
9
|
-
EthTransactionSubmissionStorage,
|
|
10
|
-
Xl1ToEthBridgeParent,
|
|
11
|
-
Xl1TransactionMonitor,
|
|
12
|
-
Xl1TransactionPreparation,
|
|
13
|
-
Xl1TransactionSubmission,
|
|
14
|
-
Xl1TransactionSubmissionStorage,
|
|
15
|
-
} from './index.ts'
|
|
16
|
-
|
|
17
|
-
export const createWorkers = (connection: Redis, telemetry: BullMQOtel, services: IBridgeServiceCollection) => {
|
|
18
|
-
// TODO: Uncomment when EthToXl1 flow is ready
|
|
19
|
-
// EthToXl1BridgeParent.createWorker(connection, telemetry)
|
|
20
|
-
EthTransactionMonitor.createWorker(connection, telemetry, services)
|
|
21
|
-
EthTransactionPreparation.createWorker(connection, telemetry, services)
|
|
22
|
-
EthTransactionSubmission.createWorker(connection, telemetry, services)
|
|
23
|
-
EthTransactionSubmissionStorage.createWorker(connection, telemetry, services)
|
|
24
|
-
Xl1ToEthBridgeParent.createWorker(connection, telemetry)
|
|
25
|
-
Xl1TransactionMonitor.createWorker(connection, telemetry, services)
|
|
26
|
-
Xl1TransactionPreparation.createWorker(connection, telemetry, services)
|
|
27
|
-
Xl1TransactionSubmission.createWorker(connection, telemetry, services)
|
|
28
|
-
Xl1TransactionSubmissionStorage.createWorker(connection, telemetry, services)
|
|
29
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './createWorkers.ts'
|
|
2
|
-
export * from './EthToXl1BridgeParent.ts'
|
|
3
|
-
export * from './EthTransactionMonitor.ts'
|
|
4
|
-
export * from './EthTransactionPreparation.ts'
|
|
5
|
-
export * from './EthTransactionSubmission.ts'
|
|
6
|
-
export * from './EthTransactionSubmissionStorage.ts'
|
|
7
|
-
export * from './Xl1ToEthBridgeParent.ts'
|
|
8
|
-
export * from './Xl1TransactionMonitor.ts'
|
|
9
|
-
export * from './Xl1TransactionPreparation.ts'
|
|
10
|
-
export * from './Xl1TransactionSubmission.ts'
|
|
11
|
-
export * from './Xl1TransactionSubmissionStorage.ts'
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
assertEx, hexToBigInt, toEthAddress,
|
|
3
|
-
} from '@xylabs/sdk-js'
|
|
4
|
-
import type { Payload } from '@xyo-network/sdk-js'
|
|
5
|
-
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
6
|
-
import type { LiquidityPoolBridge } from '@xyo-network/typechain'
|
|
7
|
-
import { isBridgeIntent, type SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
|
|
8
|
-
import type { Wallet } from 'ethers'
|
|
9
|
-
|
|
10
|
-
export const submitEthTransaction = async (
|
|
11
|
-
tx: SignedHydratedTransaction,
|
|
12
|
-
offChainPayloads: Payload[],
|
|
13
|
-
bridge: LiquidityPoolBridge,
|
|
14
|
-
wallet: Wallet,
|
|
15
|
-
) => {
|
|
16
|
-
// Approve the bridge to spend tokens
|
|
17
|
-
const xl1Transaction = assertEx(tx[0], () => 'No corresponding XL1 transaction found')
|
|
18
|
-
const allPayloads = [...tx[1], ...offChainPayloads]
|
|
19
|
-
const bridgeIntent = assertEx(allPayloads.find(isBridgeIntent), () => 'No bridge intent found')
|
|
20
|
-
const srcAddress = toEthAddress(bridgeIntent.srcAddress)
|
|
21
|
-
const destAddress = toEthAddress(bridgeIntent.destAddress)
|
|
22
|
-
const amount = hexToBigInt(bridgeIntent.destAmount)
|
|
23
|
-
const nonce = hexToBigInt(await PayloadBuilder.hash(xl1Transaction))
|
|
24
|
-
// Assume approval has already been done out of band for simplicity
|
|
25
|
-
// const contractApprovalTx = await bridgeableToken.connect(wallet).approve(bridge.getAddress(), amount)
|
|
26
|
-
// await contractApprovalTx.wait(1)
|
|
27
|
-
|
|
28
|
-
// Send tokens to bridge
|
|
29
|
-
const bridgeTx = await bridge.connect(wallet).bridgeFromRemote(srcAddress, destAddress, amount, nonce)
|
|
30
|
-
const receipt = await bridgeTx.wait(1)
|
|
31
|
-
return receipt?.hash
|
|
32
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type BrandedHash } from '@xylabs/sdk-js'
|
|
2
|
-
import type { Payload } from '@xyo-network/sdk-js'
|
|
3
|
-
import { type SignedHydratedTransaction, type XyoGatewayRunner } from '@xyo-network/xl1-sdk'
|
|
4
|
-
|
|
5
|
-
export const submitXl1Transaction = async (
|
|
6
|
-
preparedTx: SignedHydratedTransaction,
|
|
7
|
-
offChain: Payload[] = [],
|
|
8
|
-
gateway: XyoGatewayRunner,
|
|
9
|
-
): Promise<[BrandedHash, SignedHydratedTransaction]> => {
|
|
10
|
-
// Option 1: Add payloads to chain with addPayloadsToChain
|
|
11
|
-
// Not optimal as it requires reconstructing the transaction from the on-chain payloads, which changes the tx hash
|
|
12
|
-
// const offChainPayloads = preparedTx[1].filter(p => !isAllowedBlockPayload(p))
|
|
13
|
-
// const onChainPayloads = preparedTx[1].filter(isAllowedBlockPayload)
|
|
14
|
-
// const result = await gateway.addPayloadsToChain(onChainPayloads, offChainPayloads)
|
|
15
|
-
// return result
|
|
16
|
-
|
|
17
|
-
// Option 2: Add transaction to chain with addTransactionToChain
|
|
18
|
-
// Fails due to resigning of transaction in addTransactionToChain, which causes `from` to be invalid
|
|
19
|
-
const result = await gateway.addTransactionToChain(preparedTx, offChain)
|
|
20
|
-
return result
|
|
21
|
-
|
|
22
|
-
// Option 3: Add transaction to chain with addTransactionToChain, but bypass resigning by passing the preparedTx as an unsigned transaction
|
|
23
|
-
// const runner = assertEx(gateway.connection.runner, () => 'No runner available on gateway connection')
|
|
24
|
-
// const result = await runner.broadcastTransaction(preparedTx)
|
|
25
|
-
// return [result, preparedTx]
|
|
26
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
2
|
-
import type { Express } from 'express'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
getConnection, getFlowProducer, getTelemetry,
|
|
6
|
-
} from '../queue/index.ts'
|
|
7
|
-
|
|
8
|
-
export const addFlowProducer = (app: Express, config: BridgeConfig): Express => {
|
|
9
|
-
const connection = getConnection(config)
|
|
10
|
-
const telemetry = getTelemetry()
|
|
11
|
-
const flowProducer = getFlowProducer(connection, telemetry)
|
|
12
|
-
app.flowProducer = flowProducer
|
|
13
|
-
return app
|
|
14
|
-
}
|
package/src/server/addWorkers.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createWorkers, getConnection,
|
|
5
|
-
getTelemetry,
|
|
6
|
-
} from '../queue/index.ts'
|
|
7
|
-
import type { IBridgeServiceCollection } from '../services/index.ts'
|
|
8
|
-
|
|
9
|
-
export const addWorkers = (config: BridgeConfig, services: IBridgeServiceCollection) => {
|
|
10
|
-
const connection = getConnection(config)
|
|
11
|
-
const telemetry = getTelemetry()
|
|
12
|
-
createWorkers(connection, telemetry, services)
|
|
13
|
-
}
|
package/src/server/app.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { standardErrors } from '@xylabs/express'
|
|
2
|
-
import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
3
|
-
import { sharedMiddleware } from '@xyo-network/chain-orchestration'
|
|
4
|
-
import type { XyoGatewayRunner } from '@xyo-network/xl1-sdk'
|
|
5
|
-
import type { Express } from 'express'
|
|
6
|
-
import express from 'express'
|
|
7
|
-
|
|
8
|
-
import { addFlowProducer } from './addFlowProducer.ts'
|
|
9
|
-
import { addInstrumentation } from './instrumentation.ts'
|
|
10
|
-
import { addRoutes } from './routes/index.ts'
|
|
11
|
-
|
|
12
|
-
export const getApp = (config: BridgeConfig, gateway: XyoGatewayRunner): Express => {
|
|
13
|
-
addInstrumentation()
|
|
14
|
-
const app = express()
|
|
15
|
-
sharedMiddleware(app)
|
|
16
|
-
addFlowProducer(app, config)
|
|
17
|
-
addRoutes(app, config, gateway)
|
|
18
|
-
app.use(standardErrors)
|
|
19
|
-
return app
|
|
20
|
-
}
|
package/src/server/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export * from './app.ts'
|
|
2
|
-
export * from './server.ts'
|
|
3
|
-
|
|
4
|
-
// import type { NodeInstance } from '@xyo-network/sdk-js'
|
|
5
|
-
import type { FlowProducer } from 'bullmq'
|
|
6
|
-
|
|
7
|
-
import type { IBridgeServiceCollection } from '../services/index.ts'
|
|
8
|
-
|
|
9
|
-
// import type { IBridgeServiceCollection } from '../services/index.ts'
|
|
10
|
-
|
|
11
|
-
declare global {
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
13
|
-
namespace Express {
|
|
14
|
-
interface Application {
|
|
15
|
-
flowProducer: FlowProducer
|
|
16
|
-
services: IBridgeServiceCollection
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { registerInstrumentations } from '@opentelemetry/instrumentation'
|
|
2
|
-
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'
|
|
3
|
-
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Registers OpenTelemetry instrumentations for HTTP and Express.
|
|
7
|
-
* This function is used to set up the necessary instrumentations for monitoring
|
|
8
|
-
* HTTP requests and Express applications. Since it monkey patches the Express
|
|
9
|
-
* router & middleware system, it should be called before any Express applications
|
|
10
|
-
* are defined.
|
|
11
|
-
*/
|
|
12
|
-
export const addInstrumentation = () => {
|
|
13
|
-
const instrumentations = [new HttpInstrumentation(), new ExpressInstrumentation()]
|
|
14
|
-
registerInstrumentations({ instrumentations })
|
|
15
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
2
|
-
import type { XyoGatewayRunner } from '@xyo-network/xl1-sdk'
|
|
3
|
-
import type { Express } from 'express'
|
|
4
|
-
|
|
5
|
-
import { addBridgeRoutes } from './bridge/index.ts'
|
|
6
|
-
|
|
7
|
-
export const addRoutes = (app: Express, config: BridgeConfig, gateway: XyoGatewayRunner) => {
|
|
8
|
-
addBridgeRoutes(app, config, gateway)
|
|
9
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
2
|
-
import type { XyoGatewayRunner } from '@xyo-network/xl1-sdk'
|
|
3
|
-
import type { Express } from 'express'
|
|
4
|
-
|
|
5
|
-
import { getRouteDefinitions } from './routeDefinitions/index.ts'
|
|
6
|
-
|
|
7
|
-
export const addBridgeRoutes = (app: Express, config: BridgeConfig, gateway: XyoGatewayRunner) => {
|
|
8
|
-
const routeDefinitions = getRouteDefinitions(config, gateway)
|
|
9
|
-
for (const definition of routeDefinitions) {
|
|
10
|
-
app[definition.method](definition.path, definition.handlers)
|
|
11
|
-
}
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './addBridgeRoutes.ts'
|