@xyo-network/chain-bridge 1.20.3 → 1.20.5
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/index.mjs +54 -31
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.d.ts +2 -3
- package/dist/node/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.d.ts.map +1 -1
- package/dist/node/queue/flows/createXl1ToEthBridgeJob/createXl1ToEthBridgeJob.d.ts +3 -1
- package/dist/node/queue/flows/createXl1ToEthBridgeJob/createXl1ToEthBridgeJob.d.ts.map +1 -1
- package/dist/node/queue/workers/EthTransactionMonitor.d.ts +2 -4
- package/dist/node/queue/workers/EthTransactionMonitor.d.ts.map +1 -1
- package/dist/node/queue/workers/EthTransactionPreparation.d.ts +2 -4
- package/dist/node/queue/workers/EthTransactionPreparation.d.ts.map +1 -1
- package/dist/node/queue/workers/EthTransactionSubmission.d.ts +2 -4
- package/dist/node/queue/workers/EthTransactionSubmission.d.ts.map +1 -1
- package/dist/node/queue/workers/EthTransactionSubmissionStorage.d.ts +2 -4
- package/dist/node/queue/workers/EthTransactionSubmissionStorage.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1ToEthBridgeParent.d.ts +2 -4
- package/dist/node/queue/workers/Xl1ToEthBridgeParent.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1TransactionJobData.d.ts +15 -0
- package/dist/node/queue/workers/Xl1TransactionJobData.d.ts.map +1 -0
- package/dist/node/queue/workers/Xl1TransactionMonitor.d.ts +2 -4
- package/dist/node/queue/workers/Xl1TransactionMonitor.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1TransactionPreparation.d.ts +2 -3
- package/dist/node/queue/workers/Xl1TransactionPreparation.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1TransactionSubmission.d.ts +2 -4
- package/dist/node/queue/workers/Xl1TransactionSubmission.d.ts.map +1 -1
- package/dist/node/queue/workers/Xl1TransactionSubmissionStorage.d.ts +2 -4
- package/dist/node/queue/workers/Xl1TransactionSubmissionStorage.d.ts.map +1 -1
- package/dist/node/queue/workers/util/submitEthTransaction.d.ts +3 -2
- package/dist/node/queue/workers/util/submitEthTransaction.d.ts.map +1 -1
- package/dist/node/queue/workers/util/submitXl1Transaction.d.ts +2 -1
- package/dist/node/queue/workers/util/submitXl1Transaction.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.d.ts.map +1 -1
- package/dist/node/services/Xl1TxState.d.ts +2 -0
- package/dist/node/services/Xl1TxState.d.ts.map +1 -1
- package/dist/node/validation/validateSufficientLiquiditySourceAllowance.d.ts +3 -1
- package/dist/node/validation/validateSufficientLiquiditySourceAllowance.d.ts.map +1 -1
- package/dist/node/validation/validateSufficientLiquiditySourceBalance.d.ts +3 -1
- package/dist/node/validation/validateSufficientLiquiditySourceBalance.d.ts.map +1 -1
- package/package.json +18 -19
- package/src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.ts +5 -4
- package/src/queue/flows/createXl1ToEthBridgeJob/createXl1ToEthBridgeJob.ts +23 -9
- package/src/queue/workers/EthTransactionMonitor.ts +2 -1
- package/src/queue/workers/EthTransactionPreparation.ts +8 -6
- package/src/queue/workers/EthTransactionSubmission.ts +4 -5
- package/src/queue/workers/EthTransactionSubmissionStorage.ts +2 -2
- package/src/queue/workers/Xl1ToEthBridgeParent.ts +2 -2
- package/src/queue/workers/Xl1TransactionJobData.ts +12 -0
- package/src/queue/workers/Xl1TransactionMonitor.ts +2 -2
- package/src/queue/workers/Xl1TransactionPreparation.ts +4 -3
- package/src/queue/workers/Xl1TransactionSubmission.ts +7 -8
- package/src/queue/workers/Xl1TransactionSubmissionStorage.ts +2 -1
- package/src/queue/workers/util/submitEthTransaction.ts +10 -3
- package/src/queue/workers/util/submitXl1Transaction.ts +4 -5
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.ts +2 -2
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts +3 -2
- package/src/services/Xl1TxState.ts +4 -1
- package/src/validation/validateSufficientLiquiditySourceAllowance.ts +5 -1
- package/src/validation/validateSufficientLiquiditySourceBalance.ts +5 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { assertEx, hexToBigInt } from '@xylabs/sdk-js'
|
|
2
2
|
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
3
|
-
import { isBridgeIntent
|
|
3
|
+
import { isBridgeIntent } from '@xyo-network/xl1-sdk'
|
|
4
4
|
import type { Job } from 'bullmq'
|
|
5
5
|
import { Worker } from 'bullmq'
|
|
6
6
|
import type { BullMQOtel } from 'bullmq-otel'
|
|
@@ -13,8 +13,9 @@ import {
|
|
|
13
13
|
} from '../../validation/index.ts'
|
|
14
14
|
import { prefix } from '../prefix.ts'
|
|
15
15
|
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
16
|
+
import type { Xl1DataLakeTransactionJobData } from './Xl1TransactionJobData.ts'
|
|
16
17
|
|
|
17
|
-
export type EthTransactionPreparationJobData =
|
|
18
|
+
export type EthTransactionPreparationJobData = Xl1DataLakeTransactionJobData
|
|
18
19
|
export type EthTransactionPreparationJobReturn = Record<string, never>
|
|
19
20
|
export type EthTransactionPreparationJob = Job<EthTransactionPreparationJobData, EthTransactionPreparationJobReturn>
|
|
20
21
|
|
|
@@ -30,21 +31,22 @@ export const createWorker = (connection: Redis, telemetry?: BullMQOtel, services
|
|
|
30
31
|
const worker = new Worker(
|
|
31
32
|
queueName,
|
|
32
33
|
async (job: EthTransactionPreparationJob) => {
|
|
33
|
-
const { tx } = job.data
|
|
34
|
+
const { tx, offChainPayloads } = job.data
|
|
34
35
|
const hash = await PayloadBuilder.hash(tx[0])
|
|
35
36
|
await job.log(`[${hash}] preparing ETH transaction`)
|
|
36
37
|
await job.log(`[${hash}] validating liquiditySource has sufficient allowance`)
|
|
37
|
-
if (!await validateSufficientLiquiditySourceAllowance(tx, bridgeableToken, bridge, job)) {
|
|
38
|
+
if (!await validateSufficientLiquiditySourceAllowance(tx, offChainPayloads, bridgeableToken, bridge, job)) {
|
|
38
39
|
throw new Error('Liquidity source does not have sufficient allowance for the bridge to execute the transaction')
|
|
39
40
|
}
|
|
40
41
|
await job.log(`[${hash}] validated liquiditySource has sufficient allowance`)
|
|
41
42
|
await job.log(`[${hash}] validating liquiditySource has sufficient balance`)
|
|
42
|
-
if (!await validateSufficientLiquiditySourceBalance(tx, bridgeableToken, bridge, job)) {
|
|
43
|
+
if (!await validateSufficientLiquiditySourceBalance(tx, offChainPayloads, bridgeableToken, bridge, job)) {
|
|
43
44
|
throw new Error('Liquidity source does not have sufficient balance for the bridge to execute the transaction')
|
|
44
45
|
}
|
|
45
46
|
await job.log(`[${hash}] validated liquiditySource has sufficient balance`)
|
|
46
47
|
await job.log(`[${hash}] building ETH transaction`)
|
|
47
|
-
const
|
|
48
|
+
const allPayloads = [...tx[1], ...offChainPayloads]
|
|
49
|
+
const bridgeIntent = assertEx(allPayloads.find(isBridgeIntent), () => 'No bridge intent found')
|
|
48
50
|
const amount = hexToBigInt(bridgeIntent.destAmount)
|
|
49
51
|
const srcAddress = getAddress(bridgeIntent.srcAddress)
|
|
50
52
|
const destAddress = getAddress(bridgeIntent.destAddress)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
2
|
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
3
|
-
import { type SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
|
|
4
3
|
import type { Job } from 'bullmq'
|
|
5
4
|
import { Worker } from 'bullmq'
|
|
6
5
|
import type { BullMQOtel } from 'bullmq-otel'
|
|
@@ -10,8 +9,9 @@ import type { EthTxState, IBridgeServiceCollection } from '../../services/index.
|
|
|
10
9
|
import { prefix } from '../prefix.ts'
|
|
11
10
|
import { submitEthTransaction } from './util/index.ts'
|
|
12
11
|
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
12
|
+
import type { Xl1DataLakeTransactionJobData } from './Xl1TransactionJobData.ts'
|
|
13
13
|
|
|
14
|
-
export type EthTransactionSubmissionJobData =
|
|
14
|
+
export type EthTransactionSubmissionJobData = Xl1DataLakeTransactionJobData
|
|
15
15
|
export interface EthTransactionSubmissionJobReturn {
|
|
16
16
|
submissionHash: Required<EthTxState>['submissionHash']
|
|
17
17
|
}
|
|
@@ -21,14 +21,13 @@ const name = 'Submit ETH Transaction'
|
|
|
21
21
|
const queueName = 'eth-tx-submit'
|
|
22
22
|
const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBridgeServiceCollection) => {
|
|
23
23
|
const bridge = assertEx(services?.bridge, () => 'bridge service not provided')
|
|
24
|
-
const bridgeableToken = assertEx(services?.bridgeableToken, () => 'bridgeableToken service not provided')
|
|
25
24
|
const wallet = assertEx(services?.wallet, () => 'wallet service not provided')
|
|
26
25
|
const stateMap = assertEx(services?.ethTxStateMap, () => 'ethTxStateMap service not provided')
|
|
27
26
|
|
|
28
27
|
const worker = new Worker(
|
|
29
28
|
queueName,
|
|
30
29
|
async (job: EthTransactionSubmissionJob) => {
|
|
31
|
-
const { tx } = job.data
|
|
30
|
+
const { tx, offChainPayloads } = job.data
|
|
32
31
|
const hash = await PayloadBuilder.hash(tx[0])
|
|
33
32
|
const state = assertEx(await stateMap.get(hash), () => `[${hash}] state not found`)
|
|
34
33
|
|
|
@@ -41,7 +40,7 @@ const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBri
|
|
|
41
40
|
|
|
42
41
|
// Submit the transaction to the Ethereum network
|
|
43
42
|
await job.log(`[${hash}] Submitting ETH tx`)
|
|
44
|
-
const submissionHash = assertEx(await submitEthTransaction(tx,
|
|
43
|
+
const submissionHash = assertEx(await submitEthTransaction(tx, offChainPayloads, bridge, wallet), () => `[${hash}] submissionHash not found in receipt`)
|
|
45
44
|
await job.log(`[${hash}] Submitted ETH tx and received submission response hash ${submissionHash}`)
|
|
46
45
|
return { submissionHash }
|
|
47
46
|
},
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
2
|
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
3
|
-
import type { SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
|
|
4
3
|
import type { Job } from 'bullmq'
|
|
5
4
|
import { Worker } from 'bullmq'
|
|
6
5
|
import type { BullMQOtel } from 'bullmq-otel'
|
|
@@ -11,8 +10,9 @@ import { prefix } from '../prefix.ts'
|
|
|
11
10
|
import type { EthTransactionSubmissionJobReturn } from './EthTransactionSubmission.ts'
|
|
12
11
|
import { EthTransactionSubmission } from './EthTransactionSubmission.ts'
|
|
13
12
|
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
13
|
+
import type { Xl1TransactionJobData } from './Xl1TransactionJobData.ts'
|
|
14
14
|
|
|
15
|
-
export type EthTransactionSubmissionStorageJobData =
|
|
15
|
+
export type EthTransactionSubmissionStorageJobData = Xl1TransactionJobData
|
|
16
16
|
export interface EthTransactionSubmissionStorageJobReturn {
|
|
17
17
|
submissionHash: Required<EthTxState>['submissionHash']
|
|
18
18
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
|
|
2
1
|
import type { Job } from 'bullmq'
|
|
3
2
|
import { Worker } from 'bullmq'
|
|
4
3
|
import type { BullMQOtel } from 'bullmq-otel'
|
|
@@ -6,8 +5,9 @@ import type { Redis } from 'ioredis'
|
|
|
6
5
|
|
|
7
6
|
import { prefix } from '../prefix.ts'
|
|
8
7
|
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
8
|
+
import type { Xl1DataLakeTransactionJobData } from './Xl1TransactionJobData.ts'
|
|
9
9
|
|
|
10
|
-
export type Xl1ToEthBridgeParentJobData =
|
|
10
|
+
export type Xl1ToEthBridgeParentJobData = Xl1DataLakeTransactionJobData
|
|
11
11
|
export interface Xl1ToEthBridgeParentJobReturn { }
|
|
12
12
|
export type Xl1ToEthBridgeParentJob = Job<Xl1ToEthBridgeParentJobData, Xl1ToEthBridgeParentJobReturn>
|
|
13
13
|
|
|
@@ -0,0 +1,12 @@
|
|
|
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[] }
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
assertEx, isDefined, isNull,
|
|
4
4
|
} from '@xylabs/sdk-js'
|
|
5
5
|
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
6
|
-
import type { SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
|
|
7
6
|
import type { Job } from 'bullmq'
|
|
8
7
|
import { UnrecoverableError, Worker } from 'bullmq'
|
|
9
8
|
import type { BullMQOtel } from 'bullmq-otel'
|
|
@@ -12,8 +11,9 @@ import type { Redis } from 'ioredis'
|
|
|
12
11
|
import type { IBridgeServiceCollection } from '../../services/index.ts'
|
|
13
12
|
import { prefix } from '../prefix.ts'
|
|
14
13
|
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
14
|
+
import type { Xl1TransactionJobData } from './Xl1TransactionJobData.ts'
|
|
15
15
|
|
|
16
|
-
export type Xl1TransactionMonitorJobData =
|
|
16
|
+
export type Xl1TransactionMonitorJobData = Xl1TransactionJobData
|
|
17
17
|
export interface Xl1TransactionMonitorJobReturn {
|
|
18
18
|
submissionHash: BrandedHash
|
|
19
19
|
}
|
|
@@ -9,8 +9,9 @@ import type { Redis } from 'ioredis'
|
|
|
9
9
|
import type { IBridgeServiceCollection } from '../../services/index.ts'
|
|
10
10
|
import { prefix } from '../prefix.ts'
|
|
11
11
|
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
12
|
+
import type { Xl1DataLakeTransactionJobData } from './Xl1TransactionJobData.ts'
|
|
12
13
|
|
|
13
|
-
export type Xl1TransactionPreparationJobData =
|
|
14
|
+
export type Xl1TransactionPreparationJobData = Xl1DataLakeTransactionJobData
|
|
14
15
|
export interface Xl1TransactionPreparationJobReturn { preparedTx: SignedHydratedTransaction }
|
|
15
16
|
export type Xl1TransactionPreparationJob = Job<Xl1TransactionPreparationJobData, Xl1TransactionPreparationJobReturn>
|
|
16
17
|
|
|
@@ -22,12 +23,12 @@ const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBri
|
|
|
22
23
|
const worker = new Worker(
|
|
23
24
|
queueName,
|
|
24
25
|
async (job: Xl1TransactionPreparationJob) => {
|
|
25
|
-
const { tx } = job.data
|
|
26
|
+
const { tx, offChainPayloads = [] } = job.data
|
|
26
27
|
const hash = await PayloadBuilder.hash(tx[0])
|
|
27
28
|
await job.log(`[${hash}] preparing XL1 transaction`)
|
|
28
29
|
const preparedTx = tx
|
|
29
30
|
await job.log(`[${hash}] storing XL1 preparedTx`)
|
|
30
|
-
await stateMap.set(hash, { preparedTx })
|
|
31
|
+
await stateMap.set(hash, { offChainPayloads, preparedTx })
|
|
31
32
|
await job.log(`[${hash}] stored XL1 preparedTx`)
|
|
32
33
|
await job.log(`[${hash}] prepared XL1 transaction`)
|
|
33
34
|
return { preparedTx }
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
2
|
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
3
|
-
import { type SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
|
|
4
3
|
import type { Job } from 'bullmq'
|
|
5
4
|
import { Worker } from 'bullmq'
|
|
6
5
|
import type { BullMQOtel } from 'bullmq-otel'
|
|
@@ -10,8 +9,9 @@ import type { IBridgeServiceCollection, Xl1TxState } from '../../services/index.
|
|
|
10
9
|
import { prefix } from '../prefix.ts'
|
|
11
10
|
import { submitXl1Transaction } from './util/index.ts'
|
|
12
11
|
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
12
|
+
import type { Xl1TransactionJobData } from './Xl1TransactionJobData.ts'
|
|
13
13
|
|
|
14
|
-
export type Xl1TransactionSubmissionJobData =
|
|
14
|
+
export type Xl1TransactionSubmissionJobData = Xl1TransactionJobData
|
|
15
15
|
export interface Xl1TransactionSubmissionJobReturn {
|
|
16
16
|
submissionHash: Required<Xl1TxState>['submissionHash']
|
|
17
17
|
}
|
|
@@ -32,21 +32,20 @@ const createWorker = (connection: Redis, telemetry?: BullMQOtel, services?: IBri
|
|
|
32
32
|
const hash = await PayloadBuilder.hash(tx[0])
|
|
33
33
|
// Get the state of the transaction
|
|
34
34
|
const state = assertEx(await stateMap.get(hash), () => `[${hash}] state not found`)
|
|
35
|
-
const
|
|
35
|
+
const {
|
|
36
|
+
preparedTx, offChainPayloads = [], submissionHash: existingSubmissionHash,
|
|
37
|
+
} = state
|
|
36
38
|
|
|
37
39
|
// Idempotency check against resubmission
|
|
38
|
-
const { submissionHash: existingSubmissionHash } = state
|
|
39
40
|
if (isDefined(existingSubmissionHash)) {
|
|
40
41
|
await job.log(`[${hash}] Tx already submitted with submission response hash ${existingSubmissionHash}`)
|
|
41
42
|
return { submissionHash: existingSubmissionHash }
|
|
42
43
|
}
|
|
44
|
+
const txToSubmit = assertEx(preparedTx, () => `[${hash}] preparedTx not found`)
|
|
43
45
|
|
|
44
46
|
// Submit the transaction to the XL1 network
|
|
45
47
|
await job.log(`[${hash}] Submitting XL1 tx`)
|
|
46
|
-
const [submissionHash] = await submitXl1Transaction(
|
|
47
|
-
|
|
48
|
-
// Ensure the submission hash matches the expected hash
|
|
49
|
-
// assertEx(submissionHash === hash, () => `[${hash}] Submitted transaction hash ${submissionHash} does not match expected hash`)
|
|
48
|
+
const [submissionHash] = await submitXl1Transaction(txToSubmit, offChainPayloads, gateway)
|
|
50
49
|
await job.log(`[${hash}] Submitted XL1 tx`)
|
|
51
50
|
|
|
52
51
|
// This worker intentionally does NOT store state as subsequent steps will do that.
|
|
@@ -9,10 +9,11 @@ import type { Redis } from 'ioredis'
|
|
|
9
9
|
import type { IBridgeServiceCollection, Xl1TxState } from '../../services/index.ts'
|
|
10
10
|
import { prefix } from '../prefix.ts'
|
|
11
11
|
import type { WorkerDescription } from './WorkerDescription.ts'
|
|
12
|
+
import type { Xl1TransactionJobData } from './Xl1TransactionJobData.ts'
|
|
12
13
|
import type { Xl1TransactionSubmissionJobReturn } from './Xl1TransactionSubmission.ts'
|
|
13
14
|
import { Xl1TransactionSubmission } from './Xl1TransactionSubmission.ts'
|
|
14
15
|
|
|
15
|
-
export type Xl1TransactionSubmissionStorageJobData =
|
|
16
|
+
export type Xl1TransactionSubmissionStorageJobData = Xl1TransactionJobData
|
|
16
17
|
export interface Xl1TransactionSubmissionStorageJobReturn {
|
|
17
18
|
submissionHash: Required<Xl1TxState>['submissionHash']
|
|
18
19
|
}
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
assertEx, hexToBigInt, toEthAddress,
|
|
3
3
|
} from '@xylabs/sdk-js'
|
|
4
|
+
import type { Payload } from '@xyo-network/sdk-js'
|
|
4
5
|
import { PayloadBuilder } from '@xyo-network/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
+
import type { LiquidityPoolBridge } from '@xyo-network/typechain'
|
|
6
7
|
import { isBridgeIntent, type SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
|
|
7
8
|
import type { Wallet } from 'ethers'
|
|
8
9
|
|
|
9
|
-
export const submitEthTransaction = async (
|
|
10
|
+
export const submitEthTransaction = async (
|
|
11
|
+
tx: SignedHydratedTransaction,
|
|
12
|
+
offChainPayloads: Payload[],
|
|
13
|
+
bridge: LiquidityPoolBridge,
|
|
14
|
+
wallet: Wallet,
|
|
15
|
+
) => {
|
|
10
16
|
// Approve the bridge to spend tokens
|
|
11
17
|
const xl1Transaction = assertEx(tx[0], () => 'No corresponding XL1 transaction found')
|
|
12
|
-
const
|
|
18
|
+
const allPayloads = [...tx[1], ...offChainPayloads]
|
|
19
|
+
const bridgeIntent = assertEx(allPayloads.find(isBridgeIntent), () => 'No bridge intent found')
|
|
13
20
|
const srcAddress = toEthAddress(bridgeIntent.srcAddress)
|
|
14
21
|
const destAddress = toEthAddress(bridgeIntent.destAddress)
|
|
15
22
|
const amount = hexToBigInt(bridgeIntent.destAmount)
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type BrandedHash } from '@xylabs/sdk-js'
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
} from '@xyo-network/xl1-sdk'
|
|
2
|
+
import type { Payload } from '@xyo-network/sdk-js'
|
|
3
|
+
import { type SignedHydratedTransaction, type XyoGatewayRunner } from '@xyo-network/xl1-sdk'
|
|
5
4
|
|
|
6
5
|
export const submitXl1Transaction = async (
|
|
7
6
|
preparedTx: SignedHydratedTransaction,
|
|
7
|
+
offChain: Payload[] = [],
|
|
8
8
|
gateway: XyoGatewayRunner,
|
|
9
9
|
): Promise<[BrandedHash, SignedHydratedTransaction]> => {
|
|
10
10
|
// Option 1: Add payloads to chain with addPayloadsToChain
|
|
@@ -16,8 +16,7 @@ export const submitXl1Transaction = async (
|
|
|
16
16
|
|
|
17
17
|
// Option 2: Add transaction to chain with addTransactionToChain
|
|
18
18
|
// Fails due to resigning of transaction in addTransactionToChain, which causes `from` to be invalid
|
|
19
|
-
const
|
|
20
|
-
const result = await gateway.addTransactionToChain(preparedTx, offChainPayloads)
|
|
19
|
+
const result = await gateway.addTransactionToChain(preparedTx, offChain)
|
|
21
20
|
return result
|
|
22
21
|
|
|
23
22
|
// Option 3: Add transaction to chain with addTransactionToChain, but bypass resigning by passing the preparedTx as an unsigned transaction
|
|
@@ -65,7 +65,7 @@ export const makeBridgeToRemoteRoute = (config: BridgeConfig): RouteDefinition =
|
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
// Create the signed hydrated transaction for the job
|
|
68
|
-
const singedHydratedTransaction: SignedHydratedTransaction = [signedTxBw, [transfer
|
|
68
|
+
const singedHydratedTransaction: SignedHydratedTransaction = [signedTxBw, [transfer]]
|
|
69
69
|
|
|
70
70
|
// Check if a job already exists for this transaction
|
|
71
71
|
const existingFlow = await getXl1ToEthBridgeJob(flowProducer, singedHydratedTransaction)
|
|
@@ -75,7 +75,7 @@ export const makeBridgeToRemoteRoute = (config: BridgeConfig): RouteDefinition =
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
// Submit to job queue
|
|
78
|
-
await createXl1ToEthBridgeJob(flowProducer, singedHydratedTransaction)
|
|
78
|
+
await createXl1ToEthBridgeJob(flowProducer, singedHydratedTransaction, [bridgeIntent])
|
|
79
79
|
|
|
80
80
|
// Create BridgeObservation
|
|
81
81
|
const srcConfirmation = await PayloadBuilder.hash(signedTxBw)
|
|
@@ -49,13 +49,14 @@ export const makeBridgeToRemoteStatusRoute = (config: BridgeConfig): RouteDefini
|
|
|
49
49
|
const statusQueueJobs = await getStatusQueueJobs(queues, jobId)
|
|
50
50
|
|
|
51
51
|
// Check for the transaction hash in the parent job
|
|
52
|
-
const tx = statusQueueJobs.xl1ToEthBridgeParentJob?.data
|
|
52
|
+
const { tx, offChainPayloads = [] } = statusQueueJobs.xl1ToEthBridgeParentJob?.data ?? {}
|
|
53
53
|
|
|
54
54
|
// If the job does not exist return Not Found
|
|
55
55
|
if (!tx) return res.sendStatus(404)
|
|
56
56
|
|
|
57
57
|
// If the tx is not the right shape for bridging return Not Found
|
|
58
|
-
const
|
|
58
|
+
const allPayloads = [...tx[1], ...offChainPayloads]
|
|
59
|
+
const bridgeIntent = allPayloads.find(isBridgeIntent)
|
|
59
60
|
if (!bridgeIntent) return res.sendStatus(404)
|
|
60
61
|
|
|
61
62
|
// At this point we know we have a valid bridge intent, so we can start building the response
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Hash } from '@xylabs/sdk-js'
|
|
2
|
+
import type { Payload } from '@xyo-network/sdk-js'
|
|
2
3
|
import type { SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
|
|
3
4
|
|
|
4
5
|
import type { TxState } from './TxState.ts'
|
|
5
6
|
|
|
6
|
-
export interface Xl1TxState extends TxState<SignedHydratedTransaction, Hash, Hash> {
|
|
7
|
+
export interface Xl1TxState extends TxState<SignedHydratedTransaction, Hash, Hash> {
|
|
8
|
+
offChainPayloads?: Payload[]
|
|
9
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assertEx, hexToBigInt } from '@xylabs/sdk-js'
|
|
2
|
+
import type { Payload } from '@xyo-network/sdk-js'
|
|
2
3
|
import type { BridgeableToken, LiquidityPoolBridge } from '@xyo-network/typechain'
|
|
3
4
|
import { isBridgeIntent, type SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
|
|
4
5
|
|
|
@@ -9,6 +10,7 @@ import type { AsyncLogger } from './AsyncLogger.ts'
|
|
|
9
10
|
* ensure that (due to race conditions) the transaction will succeed, but is a quick check to avoid
|
|
10
11
|
* submitting transactions that are likely to fail.
|
|
11
12
|
* @param tx The transaction containing a bridge intent
|
|
13
|
+
* @param offChainPayloads The payloads to put off chain
|
|
12
14
|
* @param bridgeableToken The contract for the token being bridged
|
|
13
15
|
* @param bridge The contract for the liquidity bridge
|
|
14
16
|
* @param logger Optional logger for asynchronous logging
|
|
@@ -16,12 +18,14 @@ import type { AsyncLogger } from './AsyncLogger.ts'
|
|
|
16
18
|
*/
|
|
17
19
|
export const validateSufficientLiquiditySourceAllowance = async (
|
|
18
20
|
tx: SignedHydratedTransaction,
|
|
21
|
+
offChainPayloads: Payload[],
|
|
19
22
|
bridgeableToken: BridgeableToken,
|
|
20
23
|
bridge: LiquidityPoolBridge,
|
|
21
24
|
logger?: AsyncLogger,
|
|
22
25
|
) => {
|
|
23
26
|
// Get the amount being bridged from the bridge intent
|
|
24
|
-
const
|
|
27
|
+
const allPayloads = [...tx[1], ...offChainPayloads]
|
|
28
|
+
const bridgeIntent = assertEx(allPayloads.find(isBridgeIntent), () => 'No bridge intent found')
|
|
25
29
|
const amount = hexToBigInt(bridgeIntent.destAmount)
|
|
26
30
|
|
|
27
31
|
// Get the addresses
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assertEx, hexToBigInt } from '@xylabs/sdk-js'
|
|
2
|
+
import type { Payload } from '@xyo-network/sdk-js'
|
|
2
3
|
import type { BridgeableToken, LiquidityPoolBridge } from '@xyo-network/typechain'
|
|
3
4
|
import { isBridgeIntent, type SignedHydratedTransaction } from '@xyo-network/xl1-sdk'
|
|
4
5
|
|
|
@@ -9,6 +10,7 @@ import type { AsyncLogger } from './AsyncLogger.ts'
|
|
|
9
10
|
* ensure that (due to race conditions) the transaction will succeed, but is a quick check to avoid
|
|
10
11
|
* submitting transactions that are likely to fail.
|
|
11
12
|
* @param tx The transaction containing a bridge intent
|
|
13
|
+
* @param offChainPayloads The payloads to put off chain
|
|
12
14
|
* @param bridgeableToken The contract for the token being bridged
|
|
13
15
|
* @param bridge The contract for the liquidity bridge
|
|
14
16
|
* @param logger Optional logger for asynchronous logging
|
|
@@ -16,12 +18,14 @@ import type { AsyncLogger } from './AsyncLogger.ts'
|
|
|
16
18
|
*/
|
|
17
19
|
export const validateSufficientLiquiditySourceBalance = async (
|
|
18
20
|
tx: SignedHydratedTransaction,
|
|
21
|
+
offChainPayloads: Payload[],
|
|
19
22
|
bridgeableToken: BridgeableToken,
|
|
20
23
|
bridge: LiquidityPoolBridge,
|
|
21
24
|
logger?: AsyncLogger,
|
|
22
25
|
) => {
|
|
23
26
|
// Get the amount being bridged from the bridge intent
|
|
24
|
-
const
|
|
27
|
+
const allPayloads = [...tx[1], ...offChainPayloads]
|
|
28
|
+
const bridgeIntent = assertEx(allPayloads.find(isBridgeIntent), () => 'No bridge intent found')
|
|
25
29
|
const amount = hexToBigInt(bridgeIntent.destAmount)
|
|
26
30
|
|
|
27
31
|
// Get the addresses
|