@xyo-network/chain-bridge 1.19.17 → 1.20.0
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/dist/node/config/getTestGateway.d.ts +4 -0
- package/dist/node/config/getTestGateway.d.ts.map +1 -0
- package/dist/node/config/index.d.ts +1 -1
- package/dist/node/config/index.d.ts.map +1 -1
- package/dist/node/index.mjs +767 -520
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/modules/index.d.ts +0 -1
- package/dist/node/modules/index.d.ts.map +1 -1
- package/dist/node/queue/flowProducer.d.ts +2 -1
- package/dist/node/queue/flowProducer.d.ts.map +1 -1
- package/dist/node/queue/flows/createEthToXl1BridgeJob.d.ts +10 -0
- package/dist/node/queue/flows/createEthToXl1BridgeJob.d.ts.map +1 -0
- package/dist/node/queue/flows/createXl1ToEthBridgeJob.d.ts.map +1 -1
- package/dist/node/queue/flows/index.d.ts +1 -0
- package/dist/node/queue/flows/index.d.ts.map +1 -1
- package/dist/node/queue/getXl1ToEthQueueJobs.d.ts +20 -0
- package/dist/node/queue/getXl1ToEthQueueJobs.d.ts.map +1 -0
- package/dist/node/queue/getXl1ToEthQueues.d.ts +14 -0
- package/dist/node/queue/getXl1ToEthQueues.d.ts.map +1 -0
- package/dist/node/queue/index.d.ts +4 -0
- package/dist/node/queue/index.d.ts.map +1 -1
- package/dist/node/queue/prefix.d.ts +2 -0
- package/dist/node/queue/prefix.d.ts.map +1 -0
- package/dist/node/queue/telemetry.d.ts +3 -0
- package/dist/node/queue/telemetry.d.ts.map +1 -0
- package/dist/node/queue/workers/EthToXl1BridgeParent.d.ts +8 -0
- package/dist/node/queue/workers/EthToXl1BridgeParent.d.ts.map +1 -0
- package/dist/node/queue/workers/EthTransactionMonitor.d.ts +11 -0
- package/dist/node/queue/workers/EthTransactionMonitor.d.ts.map +1 -1
- package/dist/node/queue/workers/EthTransactionPreparation.d.ts +9 -1
- package/dist/node/queue/workers/EthTransactionPreparation.d.ts.map +1 -1
- package/dist/node/queue/workers/EthTransactionSubmission.d.ts +10 -0
- package/dist/node/queue/workers/EthTransactionSubmission.d.ts.map +1 -1
- package/dist/node/queue/workers/EthTransactionSubmissionStorage.d.ts +13 -0
- package/dist/node/queue/workers/EthTransactionSubmissionStorage.d.ts.map +1 -0
- package/dist/node/queue/workers/WorkerDescription.d.ts +2 -1
- package/dist/node/queue/workers/WorkerDescription.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1ToEthBridgeParent.d.ts +8 -0
- package/dist/node/queue/workers/Xl1ToEthBridgeParent.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1TransactionMonitor.d.ts +10 -0
- package/dist/node/queue/workers/Xl1TransactionMonitor.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1TransactionPreparation.d.ts +9 -0
- package/dist/node/queue/workers/Xl1TransactionPreparation.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1TransactionSubmission.d.ts +10 -0
- package/dist/node/queue/workers/Xl1TransactionSubmission.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1TransactionSubmissionStorage.d.ts +13 -0
- package/dist/node/queue/workers/Xl1TransactionSubmissionStorage.d.ts.map +1 -0
- package/dist/node/queue/workers/createWorkers.d.ts +2 -1
- package/dist/node/queue/workers/createWorkers.d.ts.map +1 -1
- package/dist/node/queue/workers/index.d.ts +3 -0
- package/dist/node/queue/workers/index.d.ts.map +1 -1
- package/dist/node/queue/workers/util/index.d.ts +0 -2
- package/dist/node/queue/workers/util/index.d.ts.map +1 -1
- package/dist/node/server/addFlowProducer.d.ts.map +1 -1
- package/dist/node/server/addWorkers.d.ts.map +1 -1
- package/dist/node/server/index.d.ts +2 -0
- package/dist/node/server/index.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.d.ts +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.d.ts.map +1 -1
- package/dist/node/server/server.d.ts.map +1 -1
- package/dist/node/services/IBridgeServiceCollection.d.ts +1 -1
- package/dist/node/services/IBridgeServiceCollection.d.ts.map +1 -1
- package/dist/node/services/TxState.d.ts +0 -7
- package/dist/node/services/TxState.d.ts.map +1 -1
- package/dist/node/util/index.d.ts +0 -3
- package/dist/node/util/index.d.ts.map +1 -1
- package/dist/node/validation/AsyncLogger.d.ts +5 -0
- package/dist/node/validation/AsyncLogger.d.ts.map +1 -0
- package/dist/node/validation/index.d.ts +7 -0
- package/dist/node/validation/index.d.ts.map +1 -0
- package/dist/node/validation/validateBridgeEstimate.d.ts.map +1 -0
- package/dist/node/validation/validateBridgeEstimateExact.d.ts.map +1 -0
- package/dist/node/validation/validateBridgeTransaction.d.ts.map +1 -0
- package/dist/node/{queue/workers/util/validateSufficientAllowance.d.ts → validation/validateSufficientLiquiditySourceAllowance.d.ts} +3 -7
- package/dist/node/validation/validateSufficientLiquiditySourceAllowance.d.ts.map +1 -0
- package/dist/node/{queue/workers/util/validateSufficientBalance.d.ts → validation/validateSufficientLiquiditySourceBalance.d.ts} +3 -7
- package/dist/node/validation/validateSufficientLiquiditySourceBalance.d.ts.map +1 -0
- package/dist/node/validation/validateSufficientRunnerEthBalanceForGas.d.ts +14 -0
- package/dist/node/validation/validateSufficientRunnerEthBalanceForGas.d.ts.map +1 -0
- package/dist/node/validation/validateSufficientXL1SourceAddressBalance.d.ts +15 -0
- package/dist/node/validation/validateSufficientXL1SourceAddressBalance.d.ts.map +1 -0
- package/package.json +31 -35
- package/src/config/getBridgeWalletAccount.ts +1 -1
- package/src/config/getTestGateway.ts +24 -0
- package/src/config/index.ts +1 -1
- package/src/modules/index.ts +0 -1
- package/src/queue/flowProducer.ts +7 -2
- package/src/queue/flows/createEthToXl1BridgeJob.ts +71 -0
- package/src/queue/flows/createXl1ToEthBridgeJob.ts +48 -20
- package/src/queue/flows/index.ts +1 -0
- package/src/queue/getXl1ToEthQueueJobs.ts +57 -0
- package/src/queue/getXl1ToEthQueues.ts +39 -0
- package/src/queue/index.ts +4 -0
- package/src/queue/prefix.ts +1 -0
- package/src/queue/telemetry.ts +12 -0
- package/src/queue/workers/EthToXl1BridgeParent.ts +40 -0
- package/src/queue/workers/EthTransactionMonitor.ts +14 -6
- package/src/queue/workers/EthTransactionPreparation.ts +21 -9
- package/src/queue/workers/EthTransactionSubmission.ts +10 -38
- package/src/queue/workers/EthTransactionSubmissionStorage.ts +76 -0
- package/src/queue/workers/WorkerDescription.ts +2 -1
- package/src/queue/workers/Xl1ToEthBridgeParent.ts +13 -5
- package/src/queue/workers/Xl1TransactionMonitor.ts +18 -12
- package/src/queue/workers/Xl1TransactionPreparation.ts +11 -7
- package/src/queue/workers/Xl1TransactionSubmission.ts +12 -12
- package/src/queue/workers/Xl1TransactionSubmissionStorage.ts +77 -0
- package/src/queue/workers/createWorkers.ts +15 -8
- package/src/queue/workers/index.ts +3 -0
- package/src/queue/workers/util/index.ts +0 -2
- package/src/server/addFlowProducer.ts +5 -2
- package/src/server/addWorkers.ts +6 -2
- package/src/server/index.ts +3 -2
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.ts +11 -1
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts +27 -101
- package/src/server/server.ts +1 -0
- package/src/services/IBridgeServiceCollection.ts +1 -1
- package/src/services/TxState.ts +0 -18
- package/src/services/getServices.ts +1 -1
- package/src/util/index.ts +0 -3
- package/src/validation/AsyncLogger.ts +5 -0
- package/src/validation/index.ts +6 -0
- package/src/{util → validation}/validateBridgeEstimate.ts +1 -1
- package/src/{util → validation}/validateBridgeEstimateExact.ts +1 -1
- package/src/{util → validation}/validateBridgeTransaction.ts +1 -2
- package/src/{queue/workers/util/validateSufficientAllowance.ts → validation/validateSufficientLiquiditySourceAllowance.ts} +3 -6
- package/src/{queue/workers/util/validateSufficientBalance.ts → validation/validateSufficientLiquiditySourceBalance.ts} +3 -6
- package/src/validation/validateSufficientRunnerEthBalanceForGas.ts +57 -0
- package/src/validation/validateSufficientXL1SourceAddressBalance.ts +39 -0
- package/dist/node/config/getGateway.d.ts +0 -4
- package/dist/node/config/getGateway.d.ts.map +0 -1
- package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.d.ts +0 -60
- package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.d.ts.map +0 -1
- package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/index.d.ts +0 -2
- package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/index.d.ts.map +0 -1
- package/dist/node/queue/workers/util/validateSufficientAllowance.d.ts.map +0 -1
- package/dist/node/queue/workers/util/validateSufficientBalance.d.ts.map +0 -1
- package/dist/node/util/validateBridgeEstimate.d.ts.map +0 -1
- package/dist/node/util/validateBridgeEstimateExact.d.ts.map +0 -1
- package/dist/node/util/validateBridgeTransaction.d.ts.map +0 -1
- package/src/config/getGateway.ts +0 -23
- package/src/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.ts +0 -165
- package/src/modules/XL1TransactionCompletionMonitorSentinel/index.ts +0 -1
- /package/dist/node/{util → validation}/validateBridgeEstimate.d.ts +0 -0
- /package/dist/node/{util → validation}/validateBridgeEstimateExact.d.ts +0 -0
- /package/dist/node/{util → validation}/validateBridgeTransaction.d.ts +0 -0
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import type { Attributes, Counter } from '@opentelemetry/api'
|
|
2
|
-
import type { Hash } from '@xylabs/sdk-js'
|
|
3
|
-
import {
|
|
4
|
-
assertEx, delay, isDefined, isNull, isUndefined,
|
|
5
|
-
} from '@xylabs/sdk-js'
|
|
6
|
-
import type { AnyConfigSchema, Payload } from '@xyo-network/sdk-js'
|
|
7
|
-
import { asSchema, PayloadBuilder } from '@xyo-network/sdk-js'
|
|
8
|
-
import { AbstractSentinel } from '@xyo-network/sentinel-abstract'
|
|
9
|
-
import type {
|
|
10
|
-
SentinelConfig, SentinelInstance, SentinelModuleEventData, SentinelParams,
|
|
11
|
-
} from '@xyo-network/sentinel-model'
|
|
12
|
-
import type {
|
|
13
|
-
IterableMap, MapType, SignedHydratedTransaction,
|
|
14
|
-
XyoViewer,
|
|
15
|
-
} from '@xyo-network/xl1-sdk'
|
|
16
|
-
import {
|
|
17
|
-
flattenHydratedTransaction, flattenHydratedTransactions, tryUnflattenHydratedTransaction,
|
|
18
|
-
} from '@xyo-network/xl1-sdk'
|
|
19
|
-
import { Mutex } from 'async-mutex'
|
|
20
|
-
|
|
21
|
-
export const XL1TransactionCompletionMonitorSentinelConfigSchema = asSchema('network.xyo.sentinel.chain.transaction.completion.monitor.config', true)
|
|
22
|
-
export type XL1TransactionCompletionMonitorSentinelConfigSchema = typeof XL1TransactionCompletionMonitorSentinelConfigSchema
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The configuration for the sentinel
|
|
26
|
-
*/
|
|
27
|
-
export type XL1TransactionCompletionMonitorSentinelConfig = SentinelConfig<{
|
|
28
|
-
/**
|
|
29
|
-
* The interval in milliseconds between checking for jobs to fulfill
|
|
30
|
-
*/
|
|
31
|
-
jobCheckInterval: number
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* The schema for the sentinel config
|
|
35
|
-
*/
|
|
36
|
-
schema: XL1TransactionCompletionMonitorSentinelConfigSchema
|
|
37
|
-
}>
|
|
38
|
-
|
|
39
|
-
interface XL1TransactionCompletionMonitorSentinelParamFields {
|
|
40
|
-
/**
|
|
41
|
-
* The map of completed transactions to monitor for completion
|
|
42
|
-
*/
|
|
43
|
-
completedTransactions: MapType<Hash, SignedHydratedTransaction>
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* The map of pending transactions to monitor for completion
|
|
47
|
-
*/
|
|
48
|
-
pendingTransactions: IterableMap<Hash, SignedHydratedTransaction>
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* The viewer instance to use for viewing transactions
|
|
52
|
-
*/
|
|
53
|
-
viewer: XyoViewer
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export type XL1TransactionCompletionMonitorSentinelParams<
|
|
57
|
-
TConfig extends AnyConfigSchema<XL1TransactionCompletionMonitorSentinelConfig> = AnyConfigSchema<XL1TransactionCompletionMonitorSentinelConfig>,
|
|
58
|
-
> = SentinelParams<TConfig> & XL1TransactionCompletionMonitorSentinelParamFields
|
|
59
|
-
|
|
60
|
-
const defaultJobCheckIntervalMs = 15_000
|
|
61
|
-
|
|
62
|
-
export class XL1TransactionCompletionMonitorSentinel<
|
|
63
|
-
TParams extends XL1TransactionCompletionMonitorSentinelParams = XL1TransactionCompletionMonitorSentinelParams,
|
|
64
|
-
TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>,
|
|
65
|
-
> extends AbstractSentinel<TParams, TEventData> {
|
|
66
|
-
static override readonly configSchemas = [XL1TransactionCompletionMonitorSentinelConfigSchema]
|
|
67
|
-
static override readonly defaultConfigSchema = XL1TransactionCompletionMonitorSentinelConfigSchema
|
|
68
|
-
private _attemptsCounter: Counter<Attributes> | undefined
|
|
69
|
-
private _checkCounter: Counter<Attributes> | undefined
|
|
70
|
-
private _errorCounter: Counter<Attributes> | undefined
|
|
71
|
-
private _reportMutex = new Mutex()
|
|
72
|
-
private _successCounter: Counter<Attributes> | undefined
|
|
73
|
-
|
|
74
|
-
protected get completedTransactions(): MapType<Hash, SignedHydratedTransaction> {
|
|
75
|
-
return assertEx(this.params.completedTransactions, () => 'Completed transactions map is not defined')
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
protected get jobCheckInterval(): number {
|
|
79
|
-
return isDefined(this.config.jobCheckInterval) ? this.config.jobCheckInterval : defaultJobCheckIntervalMs
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
protected get pendingTransactions(): IterableMap<Hash, SignedHydratedTransaction> {
|
|
83
|
-
return assertEx(this.params.pendingTransactions, () => 'Pending transactions map is not defined')
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
protected get viewer(): XyoViewer {
|
|
87
|
-
return assertEx(this.params.viewer, () => 'Viewer is not defined in params')
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
override async createHandler() {
|
|
91
|
-
await super.createHandler()
|
|
92
|
-
// Create meters for tracking bridge attempts, successes, and errors.
|
|
93
|
-
this._attemptsCounter = this.meter?.createCounter('xl1_transaction_completion_monitor_sentinel_attempts_total', { description: 'Number of attempts' })
|
|
94
|
-
this._checkCounter = this.meter?.createCounter('xl1_transaction_completion_monitor_sentinel_check_total', { description: 'Number of checks' })
|
|
95
|
-
this._successCounter = this.meter?.createCounter('xl1_transaction_completion_monitor_sentinel_success_total', { description: 'Number of successes' })
|
|
96
|
-
this._errorCounter = this.meter?.createCounter('xl1_transaction_completion_monitor_sentinel_errors_total', { description: 'Number of errors' })
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
override async reportHandler(payloads?: Payload[]): Promise<Payload[]> {
|
|
100
|
-
if (isDefined(payloads) && payloads.length > 0) {
|
|
101
|
-
const signedHydratedTransaction = tryUnflattenHydratedTransaction(payloads)
|
|
102
|
-
if (isDefined(signedHydratedTransaction)) {
|
|
103
|
-
// Insert into pending transactions for monitoring
|
|
104
|
-
const txHash = await PayloadBuilder.hash(signedHydratedTransaction[0])
|
|
105
|
-
this.logger?.info(`Adding transaction ${signedHydratedTransaction[0]} with hash ${txHash} to pending transactions for monitoring`)
|
|
106
|
-
await this.pendingTransactions.set(txHash, signedHydratedTransaction)
|
|
107
|
-
return flattenHydratedTransaction(signedHydratedTransaction)
|
|
108
|
-
}
|
|
109
|
-
return []
|
|
110
|
-
} else {
|
|
111
|
-
if (this._reportMutex.isLocked()) {
|
|
112
|
-
this.logger?.debug(`XL1TransactionCompletionMonitorSentinel [${this.id}] is already running, skipping report [${Date.now()}]`)
|
|
113
|
-
return []
|
|
114
|
-
}
|
|
115
|
-
return await this._reportMutex.runExclusive(async () => {
|
|
116
|
-
const response: Payload[] = []
|
|
117
|
-
if (isUndefined(payloads) || payloads.length === 0) {
|
|
118
|
-
await this.processAllTransactions()
|
|
119
|
-
}
|
|
120
|
-
return response
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
private async processAllTransactions(): Promise<Payload[]> {
|
|
126
|
-
const results: SignedHydratedTransaction[] = []
|
|
127
|
-
for await (const [hash, signedHydratedTransaction] of this.pendingTransactions) {
|
|
128
|
-
const result = await this.processTransaction([hash, signedHydratedTransaction])
|
|
129
|
-
if (isDefined(result)) results.push(result[1])
|
|
130
|
-
await delay(this.jobCheckInterval)
|
|
131
|
-
}
|
|
132
|
-
return flattenHydratedTransactions(results)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
private async processTransaction(
|
|
136
|
-
[hash, signedHydratedTransaction]: [Hash, SignedHydratedTransaction],
|
|
137
|
-
): Promise<[Hash, SignedHydratedTransaction] | undefined> {
|
|
138
|
-
this.logger?.info(`Checking for transaction ${signedHydratedTransaction[0]} with hash ${hash}`)
|
|
139
|
-
try {
|
|
140
|
-
let ret: [Hash, SignedHydratedTransaction] | undefined = undefined
|
|
141
|
-
this._checkCounter?.add(1)
|
|
142
|
-
this._attemptsCounter?.add(1)
|
|
143
|
-
// Check if the transaction is already included in the chain
|
|
144
|
-
const tx = await this.viewer.transactionByHash(hash)
|
|
145
|
-
if (isDefined(tx) && !isNull(tx)) {
|
|
146
|
-
await this.completedTransactions.set(hash, signedHydratedTransaction)
|
|
147
|
-
this.logger?.info(`Found transaction ${signedHydratedTransaction[0]} with hash ${hash}`)
|
|
148
|
-
this.logger?.info(`Removing completed transaction ${signedHydratedTransaction[0]} with hash ${hash}`)
|
|
149
|
-
await this.pendingTransactions.delete(hash)
|
|
150
|
-
ret = [hash, signedHydratedTransaction]
|
|
151
|
-
} else {
|
|
152
|
-
const currentBlockNumber = await this.viewer.currentBlockNumber()
|
|
153
|
-
if (signedHydratedTransaction[0].exp < currentBlockNumber) {
|
|
154
|
-
this.logger?.info(`Removing expired transaction ${signedHydratedTransaction[0]} with hash ${hash}`)
|
|
155
|
-
await this.pendingTransactions.delete(hash)
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
this._successCounter?.add(1)
|
|
159
|
-
return ret
|
|
160
|
-
} catch (error) {
|
|
161
|
-
this._errorCounter?.add(1)
|
|
162
|
-
this.logger?.error(`Error checking for transaction ${signedHydratedTransaction[0]} with hash ${hash}:`, error)
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './XL1TransactionCompletionMonitorSentinel.ts'
|
|
File without changes
|
|
File without changes
|
|
File without changes
|