@xyo-network/chain-bridge 1.19.18 → 1.20.1
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 +700 -506
- 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.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 +3 -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/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 +2 -0
- package/dist/node/queue/workers/EthTransactionMonitor.d.ts.map +1 -1
- package/dist/node/queue/workers/EthTransactionPreparation.d.ts +4 -2
- package/dist/node/queue/workers/EthTransactionPreparation.d.ts.map +1 -1
- package/dist/node/queue/workers/EthTransactionSubmission.d.ts +2 -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/Xl1ToEthBridgeParent.d.ts +6 -1
- package/dist/node/queue/workers/Xl1ToEthBridgeParent.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1TransactionMonitor.d.ts +4 -0
- package/dist/node/queue/workers/Xl1TransactionMonitor.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1TransactionPreparation.d.ts +2 -0
- package/dist/node/queue/workers/Xl1TransactionPreparation.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1TransactionSubmission.d.ts +2 -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.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 -3
- package/dist/node/queue/workers/util/index.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.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/validation/validateSufficientLiquiditySourceAllowance.d.ts.map +1 -0
- package/dist/node/validation/validateSufficientLiquiditySourceBalance.d.ts.map +1 -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 -31
- 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 +5 -1
- 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 +3 -0
- package/src/queue/prefix.ts +1 -0
- package/src/queue/workers/EthToXl1BridgeParent.ts +40 -0
- package/src/queue/workers/EthTransactionMonitor.ts +6 -2
- package/src/queue/workers/EthTransactionPreparation.ts +9 -5
- package/src/queue/workers/EthTransactionSubmission.ts +4 -12
- package/src/queue/workers/EthTransactionSubmissionStorage.ts +76 -0
- package/src/queue/workers/Xl1ToEthBridgeParent.ts +8 -3
- package/src/queue/workers/Xl1TransactionMonitor.ts +13 -9
- package/src/queue/workers/Xl1TransactionPreparation.ts +6 -2
- package/src/queue/workers/Xl1TransactionSubmission.ts +8 -9
- package/src/queue/workers/Xl1TransactionSubmissionStorage.ts +77 -0
- package/src/queue/workers/createWorkers.ts +10 -4
- package/src/queue/workers/index.ts +3 -0
- package/src/queue/workers/util/index.ts +0 -3
- 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/util/index.ts +0 -3
- 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/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/AsyncLogger.d.ts.map +0 -1
- package/dist/node/queue/workers/util/validateSufficientLiquiditySourceAllowance.d.ts.map +0 -1
- package/dist/node/queue/workers/util/validateSufficientLiquiditySourceBalance.d.ts.map +0 -1
- package/dist/node/queue/workers/util/validateSufficientRunnerEthBalanceForGas.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/{queue/workers/util → validation}/AsyncLogger.d.ts +0 -0
- /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
- /package/dist/node/{queue/workers/util → validation}/validateSufficientLiquiditySourceAllowance.d.ts +0 -0
- /package/dist/node/{queue/workers/util → validation}/validateSufficientLiquiditySourceBalance.d.ts +0 -0
- /package/dist/node/{queue/workers/util → validation}/validateSufficientRunnerEthBalanceForGas.d.ts +0 -0
- /package/src/{queue/workers/util → validation}/AsyncLogger.ts +0 -0
- /package/src/{queue/workers/util → validation}/validateSufficientLiquiditySourceAllowance.ts +0 -0
- /package/src/{queue/workers/util → validation}/validateSufficientLiquiditySourceBalance.ts +0 -0
- /package/src/{queue/workers/util → validation}/validateSufficientRunnerEthBalanceForGas.ts +0 -0
package/src/util/index.ts
CHANGED
|
@@ -4,6 +4,3 @@ export * from './calculateBridgeFees.ts'
|
|
|
4
4
|
export * from './createBridgeTransfer.ts'
|
|
5
5
|
export * from './generateBridgeEstimate.ts'
|
|
6
6
|
export * from './getConfigFromEnv.ts'
|
|
7
|
-
export * from './validateBridgeEstimate.ts'
|
|
8
|
-
export * from './validateBridgeEstimateExact.ts'
|
|
9
|
-
export * from './validateBridgeTransaction.ts'
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './validateBridgeEstimateExact.ts'
|
|
2
|
+
export * from './validateBridgeTransaction.ts'
|
|
3
|
+
export * from './validateSufficientLiquiditySourceAllowance.ts'
|
|
4
|
+
export * from './validateSufficientLiquiditySourceBalance.ts'
|
|
5
|
+
export * from './validateSufficientRunnerEthBalanceForGas.ts'
|
|
6
|
+
export * from './validateSufficientXL1SourceAddressBalance.ts'
|
|
@@ -3,7 +3,7 @@ import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
|
3
3
|
import type { BridgeIntent, Transfer } from '@xyo-network/xl1-sdk'
|
|
4
4
|
|
|
5
5
|
import { getBridgeSettings } from '../config/index.ts'
|
|
6
|
-
import { calculateBridgeFees } from '
|
|
6
|
+
import { calculateBridgeFees } from '../util/index.ts'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Validates a bridge estimate by checking the intent and transfer against the provided configuration. This method
|
|
@@ -3,7 +3,7 @@ import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
|
3
3
|
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
4
4
|
import type { BridgeIntent, Transfer } from '@xyo-network/xl1-sdk'
|
|
5
5
|
|
|
6
|
-
import { generateBridgeEstimate } from '
|
|
6
|
+
import { generateBridgeEstimate } from '../util/index.ts'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Validates a bridge estimate by checking the intent and transfer against the provided configuration. This method
|
|
@@ -5,8 +5,7 @@ import {
|
|
|
5
5
|
import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
6
6
|
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
7
7
|
import type {
|
|
8
|
-
BridgeIntent,
|
|
9
|
-
TransactionBoundWitness, Transfer,
|
|
8
|
+
BridgeIntent, TransactionBoundWitness, Transfer,
|
|
10
9
|
} from '@xyo-network/xl1-sdk'
|
|
11
10
|
|
|
12
11
|
import { getXl1ChainId } from '../config/index.ts'
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
asAddress, assertEx, hexToBigInt,
|
|
3
|
+
} from '@xylabs/sdk-js'
|
|
4
|
+
import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
5
|
+
import type { BridgeIntent, XyoGatewayRunner } from '@xyo-network/xl1-sdk'
|
|
6
|
+
|
|
7
|
+
import { generateBridgeEstimate } from '../util/index.ts'
|
|
8
|
+
import type { AsyncLogger } from './AsyncLogger.ts'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Checks if the liquidity source has sufficient balance for the bridge to execute the transaction. This doesn't
|
|
12
|
+
* ensure that (due to race conditions) the transaction will succeed, but is a quick check to avoid
|
|
13
|
+
* submitting transactions that are likely to fail.
|
|
14
|
+
* @param bridgeIntent The bridge intent containing the details of the bridge transaction, including the source address and amount being bridged
|
|
15
|
+
* @param gateway The XyoGatewayRunner to check the balance of the source address on XL1
|
|
16
|
+
* @param config The bridge configuration, used to generate a bridge estimate for the transaction
|
|
17
|
+
* @param logger Optional logger for asynchronous logging
|
|
18
|
+
* @returns True if the liquidity source balance is sufficient to execute the bridge
|
|
19
|
+
*/
|
|
20
|
+
export const validateSufficientXL1SourceAddressBalance = async (
|
|
21
|
+
bridgeIntent: BridgeIntent,
|
|
22
|
+
gateway: XyoGatewayRunner,
|
|
23
|
+
config: BridgeConfig,
|
|
24
|
+
logger?: AsyncLogger,
|
|
25
|
+
) => {
|
|
26
|
+
// Get the amount being bridged from the bridge intent
|
|
27
|
+
const viewer = assertEx(gateway.connection.viewer, () => 'Gateway connection does not have a viewer')
|
|
28
|
+
const {
|
|
29
|
+
srcAddress, srcAmount, destAddress,
|
|
30
|
+
} = bridgeIntent
|
|
31
|
+
const srcAddressBranded = asAddress(srcAddress, () => `Invalid source address in bridge intent: ${srcAddress}`)
|
|
32
|
+
const [_, calculatedTransfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config)
|
|
33
|
+
const totalAmount = Object.values(calculatedTransfer.transfers).reduce((acc, transfer) => acc + hexToBigInt(transfer), 0n)
|
|
34
|
+
|
|
35
|
+
// Check the srcAddress balance on XL1 for the bridge
|
|
36
|
+
const accountBalance = await viewer.account.balance.accountBalance(srcAddressBranded)
|
|
37
|
+
await logger?.log(`Account balance for ${srcAddressBranded}: ${accountBalance.toString()}`)
|
|
38
|
+
return accountBalance >= totalAmount
|
|
39
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getGateway.d.ts","sourceRoot":"","sources":["../../../src/config/getGateway.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAEpE,OAAO,KAAK,EACsB,gBAAgB,EACjD,MAAM,sBAAsB,CAAA;AAO7B,eAAO,MAAM,UAAU,GAAU,QAAQ,YAAY,KAAG,OAAO,CAAC,gBAAgB,CAU/E,CAAA"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type { Hash } from '@xylabs/sdk-js';
|
|
2
|
-
import type { AnyConfigSchema, Payload } from '@xyo-network/sdk-js';
|
|
3
|
-
import { AbstractSentinel } from '@xyo-network/sentinel-abstract';
|
|
4
|
-
import type { SentinelConfig, SentinelInstance, SentinelModuleEventData, SentinelParams } from '@xyo-network/sentinel-model';
|
|
5
|
-
import type { IterableMap, MapType, SignedHydratedTransaction, XyoViewer } from '@xyo-network/xl1-sdk';
|
|
6
|
-
export declare const XL1TransactionCompletionMonitorSentinelConfigSchema: "network.xyo.sentinel.chain.transaction.completion.monitor.config" & {
|
|
7
|
-
readonly __schema: true;
|
|
8
|
-
};
|
|
9
|
-
export type XL1TransactionCompletionMonitorSentinelConfigSchema = typeof XL1TransactionCompletionMonitorSentinelConfigSchema;
|
|
10
|
-
/**
|
|
11
|
-
* The configuration for the sentinel
|
|
12
|
-
*/
|
|
13
|
-
export type XL1TransactionCompletionMonitorSentinelConfig = SentinelConfig<{
|
|
14
|
-
/**
|
|
15
|
-
* The interval in milliseconds between checking for jobs to fulfill
|
|
16
|
-
*/
|
|
17
|
-
jobCheckInterval: number;
|
|
18
|
-
/**
|
|
19
|
-
* The schema for the sentinel config
|
|
20
|
-
*/
|
|
21
|
-
schema: XL1TransactionCompletionMonitorSentinelConfigSchema;
|
|
22
|
-
}>;
|
|
23
|
-
interface XL1TransactionCompletionMonitorSentinelParamFields {
|
|
24
|
-
/**
|
|
25
|
-
* The map of completed transactions to monitor for completion
|
|
26
|
-
*/
|
|
27
|
-
completedTransactions: MapType<Hash, SignedHydratedTransaction>;
|
|
28
|
-
/**
|
|
29
|
-
* The map of pending transactions to monitor for completion
|
|
30
|
-
*/
|
|
31
|
-
pendingTransactions: IterableMap<Hash, SignedHydratedTransaction>;
|
|
32
|
-
/**
|
|
33
|
-
* The viewer instance to use for viewing transactions
|
|
34
|
-
*/
|
|
35
|
-
viewer: XyoViewer;
|
|
36
|
-
}
|
|
37
|
-
export type XL1TransactionCompletionMonitorSentinelParams<TConfig extends AnyConfigSchema<XL1TransactionCompletionMonitorSentinelConfig> = AnyConfigSchema<XL1TransactionCompletionMonitorSentinelConfig>> = SentinelParams<TConfig> & XL1TransactionCompletionMonitorSentinelParamFields;
|
|
38
|
-
export declare class XL1TransactionCompletionMonitorSentinel<TParams extends XL1TransactionCompletionMonitorSentinelParams = XL1TransactionCompletionMonitorSentinelParams, TEventData extends SentinelModuleEventData<SentinelInstance<TParams>> = SentinelModuleEventData<SentinelInstance<TParams>>> extends AbstractSentinel<TParams, TEventData> {
|
|
39
|
-
static readonly configSchemas: ("network.xyo.sentinel.chain.transaction.completion.monitor.config" & {
|
|
40
|
-
readonly __schema: true;
|
|
41
|
-
})[];
|
|
42
|
-
static readonly defaultConfigSchema: "network.xyo.sentinel.chain.transaction.completion.monitor.config" & {
|
|
43
|
-
readonly __schema: true;
|
|
44
|
-
};
|
|
45
|
-
private _attemptsCounter;
|
|
46
|
-
private _checkCounter;
|
|
47
|
-
private _errorCounter;
|
|
48
|
-
private _reportMutex;
|
|
49
|
-
private _successCounter;
|
|
50
|
-
protected get completedTransactions(): MapType<Hash, SignedHydratedTransaction>;
|
|
51
|
-
protected get jobCheckInterval(): number;
|
|
52
|
-
protected get pendingTransactions(): IterableMap<Hash, SignedHydratedTransaction>;
|
|
53
|
-
protected get viewer(): XyoViewer;
|
|
54
|
-
createHandler(): Promise<void>;
|
|
55
|
-
reportHandler(payloads?: Payload[]): Promise<Payload[]>;
|
|
56
|
-
private processAllTransactions;
|
|
57
|
-
private processTransaction;
|
|
58
|
-
}
|
|
59
|
-
export {};
|
|
60
|
-
//# sourceMappingURL=XL1TransactionCompletionMonitorSentinel.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"XL1TransactionCompletionMonitorSentinel.d.ts","sourceRoot":"","sources":["../../../../src/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAI1C,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,KAAK,EACV,cAAc,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,cAAc,EAC1E,MAAM,6BAA6B,CAAA;AACpC,OAAO,KAAK,EACV,WAAW,EAAE,OAAO,EAAE,yBAAyB,EAC/C,SAAS,EACV,MAAM,sBAAsB,CAAA;AAM7B,eAAO,MAAM,mDAAmD;;CAAqF,CAAA;AACrJ,MAAM,MAAM,mDAAmD,GAAG,OAAO,mDAAmD,CAAA;AAE5H;;GAEG;AACH,MAAM,MAAM,6CAA6C,GAAG,cAAc,CAAC;IACzE;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,MAAM,EAAE,mDAAmD,CAAA;CAC5D,CAAC,CAAA;AAEF,UAAU,kDAAkD;IAC1D;;OAEG;IACH,qBAAqB,EAAE,OAAO,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAA;IAE/D;;OAEG;IACH,mBAAmB,EAAE,WAAW,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAA;IAEjE;;OAEG;IACH,MAAM,EAAE,SAAS,CAAA;CAClB;AAED,MAAM,MAAM,6CAA6C,CACvD,OAAO,SAAS,eAAe,CAAC,6CAA6C,CAAC,GAAG,eAAe,CAAC,6CAA6C,CAAC,IAC7I,cAAc,CAAC,OAAO,CAAC,GAAG,kDAAkD,CAAA;AAIhF,qBAAa,uCAAuC,CAClD,OAAO,SAAS,6CAA6C,GAAG,6CAA6C,EAC7G,UAAU,SAAS,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,uBAAuB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAC1H,SAAQ,gBAAgB,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7C,gBAAyB,aAAa;;SAAwD;IAC9F,gBAAyB,mBAAmB;;MAAsD;IAClG,OAAO,CAAC,gBAAgB,CAAiC;IACzD,OAAO,CAAC,aAAa,CAAiC;IACtD,OAAO,CAAC,aAAa,CAAiC;IACtD,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,eAAe,CAAiC;IAExD,SAAS,KAAK,qBAAqB,IAAI,OAAO,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAE9E;IAED,SAAS,KAAK,gBAAgB,IAAI,MAAM,CAEvC;IAED,SAAS,KAAK,mBAAmB,IAAI,WAAW,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAEhF;IAED,SAAS,KAAK,MAAM,IAAI,SAAS,CAEhC;IAEc,aAAa;IASb,aAAa,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;YA0BxD,sBAAsB;YAUtB,kBAAkB;CA8BjC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/XL1TransactionCompletionMonitorSentinel/index.ts"],"names":[],"mappings":"AAAA,cAAc,8CAA8C,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AsyncLogger.d.ts","sourceRoot":"","sources":["../../../../../src/queue/workers/util/AsyncLogger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEhD,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,UAAU,CAAC,OAAO,CAAC,CAAA;CAC9C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateSufficientLiquiditySourceAllowance.d.ts","sourceRoot":"","sources":["../../../../../src/queue/workers/util/validateSufficientLiquiditySourceAllowance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAClF,OAAO,EAAkB,KAAK,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AAErF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD;;;;;;;;;GASG;AACH,eAAO,MAAM,0CAA0C,GACrD,IAAI,yBAAyB,EAC7B,iBAAiB,eAAe,EAChC,QAAQ,mBAAmB,EAC3B,SAAS,WAAW,qBAcrB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateSufficientLiquiditySourceBalance.d.ts","sourceRoot":"","sources":["../../../../../src/queue/workers/util/validateSufficientLiquiditySourceBalance.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAClF,OAAO,EAAkB,KAAK,yBAAyB,EAAE,MAAM,sBAAsB,CAAA;AAErF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAEnD;;;;;;;;;GASG;AACH,eAAO,MAAM,wCAAwC,GACnD,IAAI,yBAAyB,EAC7B,iBAAiB,eAAe,EAChC,QAAQ,mBAAmB,EAC3B,SAAS,WAAW,qBAarB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateSufficientRunnerEthBalanceForGas.d.ts","sourceRoot":"","sources":["../../../../../src/queue/workers/util/validateSufficientRunnerEthBalanceForGas.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAEzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAInD;;;;;;;;;GASG;AACH,eAAO,MAAM,wCAAwC,GACnD,YAAY,mBAAmB,EAC/B,QAAQ,MAAM,EACd,SAAS,WAAW,EACpB,YAAW,MAA+B,qBAmC3C,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateBridgeEstimate.d.ts","sourceRoot":"","sources":["../../../src/util/validateBridgeEstimate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAKlE;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,GACjC,QAAQ,YAAY,EACpB,UAAU,QAAQ,EAClB,QAAQ,YAAY,KACnB,OAAO,CAAC,OAAO,CAuCjB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateBridgeEstimateExact.d.ts","sourceRoot":"","sources":["../../../src/util/validateBridgeEstimateExact.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAEpE,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAIlE;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,GACtC,QAAQ,YAAY,EACpB,UAAU,QAAQ,EAClB,QAAQ,YAAY,KACnB,OAAO,CAAC,OAAO,CAcjB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validateBridgeTransaction.d.ts","sourceRoot":"","sources":["../../../src/util/validateBridgeTransaction.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAEpE,OAAO,KAAK,EACV,YAAY,EACZ,uBAAuB,EAAE,QAAQ,EAClC,MAAM,sBAAsB,CAAA;AAI7B;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,GACpC,YAAY,uBAAuB,EACnC,QAAQ,YAAY,EACpB,UAAU,QAAQ,EAClB,QAAQ,YAAY,KACnB,OAAO,CAAC,OAAO,CAgBjB,CAAA"}
|
package/src/config/getGateway.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
|
-
import type { BridgeConfig } from '@xyo-network/chain-orchestration'
|
|
3
|
-
import { HDWallet } from '@xyo-network/sdk-js'
|
|
4
|
-
import type {
|
|
5
|
-
RpcSchemaMap, TransportFactory, XyoGatewayRunner,
|
|
6
|
-
} from '@xyo-network/xl1-sdk'
|
|
7
|
-
import {
|
|
8
|
-
ADDRESS_INDEX, buildJsonRpcProviderLocator, generateXyoBaseWalletFromPhrase, HttpRpcTransport, XyoGatewayRunnerMoniker,
|
|
9
|
-
} from '@xyo-network/xl1-sdk'
|
|
10
|
-
|
|
11
|
-
let gatewayInstance: XyoGatewayRunner | undefined
|
|
12
|
-
|
|
13
|
-
export const getGateway = async (config: BridgeConfig): Promise<XyoGatewayRunner> => {
|
|
14
|
-
if (isDefined(gatewayInstance)) return gatewayInstance
|
|
15
|
-
const { mnemonic } = config
|
|
16
|
-
const endpoint = assertEx(config.remote?.rpc?.url ?? config.remote?.rpc?.url, () => 'RPC URL is required for gateway')
|
|
17
|
-
const walletPhrase = isDefined(mnemonic) ? mnemonic : HDWallet.generateMnemonic()
|
|
18
|
-
const wallet = await generateXyoBaseWalletFromPhrase(walletPhrase)
|
|
19
|
-
const signerAccount = await wallet.derivePath(ADDRESS_INDEX.XYO)
|
|
20
|
-
const transportFactory: TransportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(endpoint, schemas)
|
|
21
|
-
const locator = await buildJsonRpcProviderLocator({ transportFactory, signerAccount })
|
|
22
|
-
return await locator.getInstance<XyoGatewayRunner>(XyoGatewayRunnerMoniker)
|
|
23
|
-
}
|
|
@@ -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
|
|
File without changes
|
/package/dist/node/{queue/workers/util → validation}/validateSufficientLiquiditySourceAllowance.d.ts
RENAMED
|
File without changes
|
/package/dist/node/{queue/workers/util → validation}/validateSufficientLiquiditySourceBalance.d.ts
RENAMED
|
File without changes
|
/package/dist/node/{queue/workers/util → validation}/validateSufficientRunnerEthBalanceForGas.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
/package/src/{queue/workers/util → validation}/validateSufficientLiquiditySourceAllowance.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|