@xyo-network/chain-bridge 1.19.15 → 1.19.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/dist/node/index.mjs +231 -138
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/interface/service/Relay/LiquidityPoolBridgeRelay/LiquidityPoolBridgeRelay.d.ts +1 -1
- package/dist/node/interface/service/Relay/LiquidityPoolBridgeRelay/LiquidityPoolBridgeRelay.d.ts.map +1 -1
- package/dist/node/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.d.ts +1 -2
- package/dist/node/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.d.ts.map +1 -1
- package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.d.ts +1 -2
- package/dist/node/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.d.ts.map +1 -1
- package/dist/node/queue/flows/createXl1ToEthBridgeJob.d.ts.map +1 -1
- package/dist/node/queue/workers/EthTransactionPreparation.d.ts.map +1 -1
- package/dist/node/queue/workers/util/index.d.ts +2 -0
- package/dist/node/queue/workers/util/index.d.ts.map +1 -1
- package/dist/node/queue/workers/util/validateSufficientAllowance.d.ts +19 -0
- package/dist/node/queue/workers/util/validateSufficientAllowance.d.ts.map +1 -0
- package/dist/node/queue/workers/util/validateSufficientBalance.d.ts +19 -0
- package/dist/node/queue/workers/util/validateSufficientBalance.d.ts.map +1 -0
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.d.ts +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/util/BridgeFees.d.ts +7 -1
- package/dist/node/util/BridgeFees.d.ts.map +1 -1
- package/package.json +42 -46
- package/src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.ts +2 -3
- package/src/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.ts +2 -3
- package/src/queue/flows/createXl1ToEthBridgeJob.ts +12 -2
- package/src/queue/workers/EthTransactionPreparation.ts +12 -0
- package/src/queue/workers/util/index.ts +2 -0
- package/src/queue/workers/util/validateSufficientAllowance.ts +38 -0
- package/src/queue/workers/util/validateSufficientBalance.ts +37 -0
- package/src/server/index.ts +1 -1
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.ts +1 -1
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.ts +3 -2
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts +1 -1
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts +130 -65
- package/src/util/BridgeFees.ts +10 -1
package/dist/node/index.mjs
CHANGED
|
@@ -40,6 +40,9 @@ var getFlowProducer = /* @__PURE__ */ __name((connection2) => {
|
|
|
40
40
|
return flowProducer;
|
|
41
41
|
}, "getFlowProducer");
|
|
42
42
|
|
|
43
|
+
// src/queue/flows/createXl1ToEthBridgeJob.ts
|
|
44
|
+
import { PayloadBuilder as PayloadBuilder8 } from "@xyo-network/sdk-js";
|
|
45
|
+
|
|
43
46
|
// src/queue/workers/createWorkers.ts
|
|
44
47
|
var createWorkers = /* @__PURE__ */ __name((connection2, services) => {
|
|
45
48
|
Xl1ToEthBridgeParent.createWorker(connection2);
|
|
@@ -91,26 +94,88 @@ var EthTransactionMonitor = {
|
|
|
91
94
|
};
|
|
92
95
|
|
|
93
96
|
// src/queue/workers/EthTransactionPreparation.ts
|
|
94
|
-
import { assertEx as
|
|
95
|
-
import { PayloadBuilder as
|
|
96
|
-
import { isBridgeIntent } from "@xyo-network/xl1-sdk";
|
|
97
|
+
import { assertEx as assertEx5, hexToBigInt as hexToBigInt4 } from "@xylabs/sdk-js";
|
|
98
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk-js";
|
|
99
|
+
import { isBridgeIntent as isBridgeIntent4 } from "@xyo-network/xl1-sdk";
|
|
97
100
|
import { Worker as Worker2 } from "bullmq";
|
|
98
101
|
import { getAddress } from "ethers";
|
|
102
|
+
|
|
103
|
+
// src/queue/workers/util/submitEthTransaction.ts
|
|
104
|
+
import { assertEx as assertEx2, hexToBigInt, toEthAddress } from "@xylabs/sdk-js";
|
|
105
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
|
|
106
|
+
import { isBridgeIntent } from "@xyo-network/xl1-sdk";
|
|
107
|
+
var submitEthTransaction = /* @__PURE__ */ __name(async (tx, bridgeableToken, bridge, wallet) => {
|
|
108
|
+
const xl1Transaction = assertEx2(tx[0], () => "No corresponding XL1 transaction found");
|
|
109
|
+
const bridgeIntent = assertEx2(tx[1].find(isBridgeIntent), () => "No bridge intent found");
|
|
110
|
+
const srcAddress = toEthAddress(bridgeIntent.srcAddress);
|
|
111
|
+
const destAddress = toEthAddress(bridgeIntent.destAddress);
|
|
112
|
+
const amount = hexToBigInt(bridgeIntent.destAmount);
|
|
113
|
+
const nonce = hexToBigInt(await PayloadBuilder2.hash(xl1Transaction));
|
|
114
|
+
const bridgeTx = await bridge.connect(wallet).bridgeFromRemote(srcAddress, destAddress, amount, nonce);
|
|
115
|
+
const receipt = await bridgeTx.wait(1);
|
|
116
|
+
return receipt?.hash;
|
|
117
|
+
}, "submitEthTransaction");
|
|
118
|
+
|
|
119
|
+
// src/queue/workers/util/submitXl1Transaction.ts
|
|
120
|
+
import { isAllowedBlockPayload } from "@xyo-network/xl1-sdk";
|
|
121
|
+
var submitXl1Transaction = /* @__PURE__ */ __name(async (preparedTx, gateway) => {
|
|
122
|
+
const offChainPayloads = preparedTx[1].filter((p) => !isAllowedBlockPayload(p));
|
|
123
|
+
const result = await gateway.addTransactionToChain(preparedTx, offChainPayloads);
|
|
124
|
+
return result;
|
|
125
|
+
}, "submitXl1Transaction");
|
|
126
|
+
|
|
127
|
+
// src/queue/workers/util/validateSufficientAllowance.ts
|
|
128
|
+
import { assertEx as assertEx3, hexToBigInt as hexToBigInt2 } from "@xylabs/sdk-js";
|
|
129
|
+
import { isBridgeIntent as isBridgeIntent2 } from "@xyo-network/xl1-sdk";
|
|
130
|
+
var validateSufficientAllowance = /* @__PURE__ */ __name(async (tx, bridgeableToken, bridge, logger) => {
|
|
131
|
+
const bridgeIntent = assertEx3(tx[1].find(isBridgeIntent2), () => "No bridge intent found");
|
|
132
|
+
const amount = hexToBigInt2(bridgeIntent.destAmount);
|
|
133
|
+
const liquiditySourceAddress = await bridge.liquiditySource();
|
|
134
|
+
const bridgeAddress = await bridge.getAddress();
|
|
135
|
+
const remainingAllowance = await bridgeableToken.allowance(liquiditySourceAddress, bridgeAddress);
|
|
136
|
+
await logger?.log(`Remaining allowance: ${remainingAllowance.toString()}`);
|
|
137
|
+
return remainingAllowance >= amount;
|
|
138
|
+
}, "validateSufficientAllowance");
|
|
139
|
+
|
|
140
|
+
// src/queue/workers/util/validateSufficientBalance.ts
|
|
141
|
+
import { assertEx as assertEx4, hexToBigInt as hexToBigInt3 } from "@xylabs/sdk-js";
|
|
142
|
+
import { isBridgeIntent as isBridgeIntent3 } from "@xyo-network/xl1-sdk";
|
|
143
|
+
var validateSufficientBalance = /* @__PURE__ */ __name(async (tx, bridgeableToken, bridge, logger) => {
|
|
144
|
+
const bridgeIntent = assertEx4(tx[1].find(isBridgeIntent3), () => "No bridge intent found");
|
|
145
|
+
const amount = hexToBigInt3(bridgeIntent.destAmount);
|
|
146
|
+
const liquiditySourceAddress = await bridge.liquiditySource();
|
|
147
|
+
const balance = await bridgeableToken.balanceOf(liquiditySourceAddress);
|
|
148
|
+
await logger?.log(`Remaining balance: ${balance.toString()}`);
|
|
149
|
+
return balance >= amount;
|
|
150
|
+
}, "validateSufficientBalance");
|
|
151
|
+
|
|
152
|
+
// src/queue/workers/EthTransactionPreparation.ts
|
|
99
153
|
var name2 = "Prepare ETH Transaction";
|
|
100
154
|
var queueName2 = "eth-tx-prepare";
|
|
101
155
|
var createWorker2 = /* @__PURE__ */ __name((connection2, services) => {
|
|
102
|
-
const bridge =
|
|
103
|
-
const
|
|
156
|
+
const bridge = assertEx5(services?.bridge, () => "bridge service not provided");
|
|
157
|
+
const bridgeableToken = assertEx5(services?.bridgeableToken, () => "bridgeableToken service not provided");
|
|
158
|
+
const stateMap = assertEx5(services?.ethTxStateMap, () => "ethTxStateMap service not provided");
|
|
104
159
|
const worker = new Worker2(queueName2, async (job) => {
|
|
105
160
|
const { tx } = job.data;
|
|
106
|
-
const hash = await
|
|
161
|
+
const hash = await PayloadBuilder3.hash(tx[0]);
|
|
107
162
|
await job.log(`[${hash}] preparing ETH transaction`);
|
|
163
|
+
await job.log(`[${hash}] validating liquiditySource has sufficient allowance`);
|
|
164
|
+
if (!await validateSufficientAllowance(tx, bridgeableToken, bridge, job)) {
|
|
165
|
+
throw new Error("Liquidity source does not have sufficient allowance for the bridge to execute the transaction");
|
|
166
|
+
}
|
|
167
|
+
await job.log(`[${hash}] validated liquiditySource has sufficient allowance`);
|
|
168
|
+
await job.log(`[${hash}] validating liquiditySource has sufficient balance`);
|
|
169
|
+
if (!await validateSufficientBalance(tx, bridgeableToken, bridge, job)) {
|
|
170
|
+
throw new Error("Liquidity source does not have sufficient balance for the bridge to execute the transaction");
|
|
171
|
+
}
|
|
172
|
+
await job.log(`[${hash}] validated liquiditySource has sufficient balance`);
|
|
108
173
|
await job.log(`[${hash}] building ETH transaction`);
|
|
109
|
-
const bridgeIntent =
|
|
110
|
-
const amount =
|
|
174
|
+
const bridgeIntent = assertEx5(tx[1].find(isBridgeIntent4), () => "No bridge intent found");
|
|
175
|
+
const amount = hexToBigInt4(bridgeIntent.destAmount);
|
|
111
176
|
const srcAddress = getAddress(bridgeIntent.srcAddress);
|
|
112
177
|
const destAddress = getAddress(bridgeIntent.destAddress);
|
|
113
|
-
const nonce =
|
|
178
|
+
const nonce = hexToBigInt4(await PayloadBuilder3.hash(tx[0]));
|
|
114
179
|
const preparedTx = await bridge.getFunction("bridgeFromRemote").populateTransaction(srcAddress, destAddress, amount, nonce);
|
|
115
180
|
await job.log(`[${hash}] built ETH transaction`);
|
|
116
181
|
await job.log(`[${hash}] storing ETH preparedTx`);
|
|
@@ -137,47 +202,21 @@ var EthTransactionPreparation = {
|
|
|
137
202
|
};
|
|
138
203
|
|
|
139
204
|
// src/queue/workers/EthTransactionSubmission.ts
|
|
140
|
-
import { assertEx as
|
|
205
|
+
import { assertEx as assertEx6, isDefined as isDefined3 } from "@xylabs/sdk-js";
|
|
141
206
|
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/sdk-js";
|
|
142
207
|
import { Worker as Worker3 } from "bullmq";
|
|
143
|
-
|
|
144
|
-
// src/queue/workers/util/submitEthTransaction.ts
|
|
145
|
-
import { assertEx as assertEx3, hexToBigInt as hexToBigInt2, toEthAddress } from "@xylabs/sdk-js";
|
|
146
|
-
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk-js";
|
|
147
|
-
import { isBridgeIntent as isBridgeIntent2 } from "@xyo-network/xl1-sdk";
|
|
148
|
-
var submitEthTransaction = /* @__PURE__ */ __name(async (tx, bridgeableToken, bridge, wallet) => {
|
|
149
|
-
const xl1Transaction = assertEx3(tx[0], () => "No corresponding XL1 transaction found");
|
|
150
|
-
const bridgeIntent = assertEx3(tx[1].find(isBridgeIntent2), () => "No bridge intent found");
|
|
151
|
-
const srcAddress = toEthAddress(bridgeIntent.srcAddress);
|
|
152
|
-
const destAddress = toEthAddress(bridgeIntent.destAddress);
|
|
153
|
-
const amount = hexToBigInt2(bridgeIntent.destAmount);
|
|
154
|
-
const nonce = hexToBigInt2(await PayloadBuilder3.hash(xl1Transaction));
|
|
155
|
-
const bridgeTx = await bridge.connect(wallet).bridgeFromRemote(srcAddress, destAddress, amount, nonce);
|
|
156
|
-
const receipt = await bridgeTx.wait(1);
|
|
157
|
-
return receipt?.hash;
|
|
158
|
-
}, "submitEthTransaction");
|
|
159
|
-
|
|
160
|
-
// src/queue/workers/util/submitXl1Transaction.ts
|
|
161
|
-
import { isAllowedBlockPayload } from "@xyo-network/xl1-sdk";
|
|
162
|
-
var submitXl1Transaction = /* @__PURE__ */ __name(async (preparedTx, gateway) => {
|
|
163
|
-
const offChainPayloads = preparedTx[1].filter((p) => !isAllowedBlockPayload(p));
|
|
164
|
-
const result = await gateway.addTransactionToChain(preparedTx, offChainPayloads);
|
|
165
|
-
return result;
|
|
166
|
-
}, "submitXl1Transaction");
|
|
167
|
-
|
|
168
|
-
// src/queue/workers/EthTransactionSubmission.ts
|
|
169
208
|
var name3 = "Submit ETH Transaction";
|
|
170
209
|
var queueName3 = "eth-tx-submit";
|
|
171
210
|
var createWorker3 = /* @__PURE__ */ __name((connection2, services) => {
|
|
172
|
-
const bridge =
|
|
173
|
-
const bridgeableToken =
|
|
174
|
-
const wallet =
|
|
175
|
-
const stateMap =
|
|
211
|
+
const bridge = assertEx6(services?.bridge, () => "bridge service not provided");
|
|
212
|
+
const bridgeableToken = assertEx6(services?.bridgeableToken, () => "bridgeableToken service not provided");
|
|
213
|
+
const wallet = assertEx6(services?.wallet, () => "wallet service not provided");
|
|
214
|
+
const stateMap = assertEx6(services?.ethTxStateMap, () => "ethTxStateMap service not provided");
|
|
176
215
|
const worker = new Worker3(queueName3, async (job) => {
|
|
177
216
|
const { tx } = job.data;
|
|
178
217
|
const hash = await PayloadBuilder4.hash(tx[0]);
|
|
179
|
-
const state =
|
|
180
|
-
const preparedTx =
|
|
218
|
+
const state = assertEx6(await stateMap.get(hash), () => `[${hash}] state not found`);
|
|
219
|
+
const preparedTx = assertEx6(state?.preparedTx, () => `[${hash}] preparedTx not found`);
|
|
181
220
|
const { submissionHash: existingSubmissionHash } = state;
|
|
182
221
|
if (isDefined3(existingSubmissionHash)) {
|
|
183
222
|
await job.log(`[${hash}] Tx already submitted with submission response hash ${existingSubmissionHash}`);
|
|
@@ -186,7 +225,7 @@ var createWorker3 = /* @__PURE__ */ __name((connection2, services) => {
|
|
|
186
225
|
};
|
|
187
226
|
}
|
|
188
227
|
await job.log(`[${hash}] Submitting ETH tx`);
|
|
189
|
-
const submissionHash =
|
|
228
|
+
const submissionHash = assertEx6(await submitEthTransaction(tx, bridgeableToken, bridge, wallet), () => `[${hash}] submissionHash not found in receipt`);
|
|
190
229
|
await job.log(`[${hash}] Submitted ETH tx and received submission response hash ${submissionHash}`);
|
|
191
230
|
await job.log(`[${hash}] Storing ETH submissionHash`);
|
|
192
231
|
state.submissionHash = submissionHash;
|
|
@@ -240,20 +279,20 @@ var Xl1ToEthBridgeParent = {
|
|
|
240
279
|
};
|
|
241
280
|
|
|
242
281
|
// src/queue/workers/Xl1TransactionMonitor.ts
|
|
243
|
-
import { assertEx as
|
|
282
|
+
import { assertEx as assertEx7, isDefined as isDefined4, isNull } from "@xylabs/sdk-js";
|
|
244
283
|
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/sdk-js";
|
|
245
284
|
import { UnrecoverableError, Worker as Worker5 } from "bullmq";
|
|
246
285
|
var name5 = "Monitor Submitted XL1 Transaction";
|
|
247
286
|
var queueName5 = "xl1-tx-monitor";
|
|
248
287
|
var createWorker5 = /* @__PURE__ */ __name((connection2, services) => {
|
|
249
|
-
const gateway =
|
|
250
|
-
const stateMap =
|
|
288
|
+
const gateway = assertEx7(services?.gateway, () => "gateway service not provided");
|
|
289
|
+
const stateMap = assertEx7(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
|
|
251
290
|
const worker = new Worker5(queueName5, async (job) => {
|
|
252
291
|
const { tx } = job.data;
|
|
253
292
|
const hash = await PayloadBuilder5.hash(tx[0]);
|
|
254
|
-
const viewer =
|
|
255
|
-
const state =
|
|
256
|
-
const submissionHash =
|
|
293
|
+
const viewer = assertEx7(gateway.connection.viewer, () => `[${hash}] viewer not defined on gateway`);
|
|
294
|
+
const state = assertEx7(await stateMap.get(hash), () => `[${hash}] state not found`);
|
|
295
|
+
const submissionHash = assertEx7(state?.submissionHash, () => `[${hash}] submissionHash not found`);
|
|
257
296
|
await job.log(`[${hash}] Checking for XL1 transaction inclusion on chain`);
|
|
258
297
|
const foundTx = await viewer.transactionByHash(submissionHash);
|
|
259
298
|
if (isDefined4(foundTx) && !isNull(foundTx)) {
|
|
@@ -286,13 +325,13 @@ var Xl1TransactionMonitor = {
|
|
|
286
325
|
};
|
|
287
326
|
|
|
288
327
|
// src/queue/workers/Xl1TransactionPreparation.ts
|
|
289
|
-
import { assertEx as
|
|
328
|
+
import { assertEx as assertEx8 } from "@xylabs/sdk-js";
|
|
290
329
|
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/sdk-js";
|
|
291
330
|
import { Worker as Worker6 } from "bullmq";
|
|
292
331
|
var name6 = "Prepare XL1 Transaction";
|
|
293
332
|
var queueName6 = "xl1-tx-prepare";
|
|
294
333
|
var createWorker6 = /* @__PURE__ */ __name((connection2, services) => {
|
|
295
|
-
const stateMap =
|
|
334
|
+
const stateMap = assertEx8(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
|
|
296
335
|
const worker = new Worker6(queueName6, async (job) => {
|
|
297
336
|
const { tx } = job.data;
|
|
298
337
|
const hash = await PayloadBuilder6.hash(tx[0]);
|
|
@@ -322,19 +361,19 @@ var Xl1TransactionPreparation = {
|
|
|
322
361
|
};
|
|
323
362
|
|
|
324
363
|
// src/queue/workers/Xl1TransactionSubmission.ts
|
|
325
|
-
import { assertEx as
|
|
364
|
+
import { assertEx as assertEx9, isDefined as isDefined5 } from "@xylabs/sdk-js";
|
|
326
365
|
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/sdk-js";
|
|
327
366
|
import { Worker as Worker7 } from "bullmq";
|
|
328
367
|
var name7 = "Submit XL1 Transaction";
|
|
329
368
|
var queueName7 = "xl1-tx-submit";
|
|
330
369
|
var createWorker7 = /* @__PURE__ */ __name((connection2, services) => {
|
|
331
|
-
const gateway =
|
|
332
|
-
const stateMap =
|
|
370
|
+
const gateway = assertEx9(services?.gateway, () => "gateway service not provided");
|
|
371
|
+
const stateMap = assertEx9(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
|
|
333
372
|
const worker = new Worker7(queueName7, async (job) => {
|
|
334
373
|
const { tx } = job.data;
|
|
335
374
|
const hash = await PayloadBuilder7.hash(tx[0]);
|
|
336
|
-
const state =
|
|
337
|
-
const preparedTx =
|
|
375
|
+
const state = assertEx9(await stateMap.get(hash), () => `[${hash}] state not found`);
|
|
376
|
+
const preparedTx = assertEx9(state?.preparedTx, () => `[${hash}] preparedTx not found`);
|
|
338
377
|
const { submissionHash: existingSubmissionHash } = state;
|
|
339
378
|
if (isDefined5(existingSubmissionHash)) {
|
|
340
379
|
await job.log(`[${hash}] Tx already submitted with submission response hash ${existingSubmissionHash}`);
|
|
@@ -370,12 +409,16 @@ var Xl1TransactionSubmission = {
|
|
|
370
409
|
|
|
371
410
|
// src/queue/flows/createXl1ToEthBridgeJob.ts
|
|
372
411
|
var createXl1ToEthBridgeJob = /* @__PURE__ */ __name(async (flowProducer2, tx) => {
|
|
412
|
+
const jobId = await PayloadBuilder8.hash(tx[0]);
|
|
373
413
|
const flow = await flowProducer2.add({
|
|
374
414
|
name: Xl1ToEthBridgeParent.name,
|
|
375
415
|
queueName: Xl1ToEthBridgeParent.queueName,
|
|
376
416
|
data: {
|
|
377
417
|
tx
|
|
378
418
|
},
|
|
419
|
+
opts: {
|
|
420
|
+
jobId
|
|
421
|
+
},
|
|
379
422
|
children: [
|
|
380
423
|
{
|
|
381
424
|
// Step 6 (runs after child completes)
|
|
@@ -385,6 +428,7 @@ var createXl1ToEthBridgeJob = /* @__PURE__ */ __name(async (flowProducer2, tx) =
|
|
|
385
428
|
tx
|
|
386
429
|
},
|
|
387
430
|
opts: {
|
|
431
|
+
jobId,
|
|
388
432
|
attempts: 60,
|
|
389
433
|
backoff: {
|
|
390
434
|
type: "fixed",
|
|
@@ -407,6 +451,9 @@ var createXl1ToEthBridgeJob = /* @__PURE__ */ __name(async (flowProducer2, tx) =
|
|
|
407
451
|
data: {
|
|
408
452
|
tx
|
|
409
453
|
},
|
|
454
|
+
opts: {
|
|
455
|
+
jobId
|
|
456
|
+
},
|
|
410
457
|
children: [
|
|
411
458
|
{
|
|
412
459
|
// Step 3
|
|
@@ -416,6 +463,7 @@ var createXl1ToEthBridgeJob = /* @__PURE__ */ __name(async (flowProducer2, tx) =
|
|
|
416
463
|
tx
|
|
417
464
|
},
|
|
418
465
|
opts: {
|
|
466
|
+
jobId,
|
|
419
467
|
attempts: 60,
|
|
420
468
|
backoff: {
|
|
421
469
|
type: "fixed",
|
|
@@ -430,6 +478,9 @@ var createXl1ToEthBridgeJob = /* @__PURE__ */ __name(async (flowProducer2, tx) =
|
|
|
430
478
|
data: {
|
|
431
479
|
tx
|
|
432
480
|
},
|
|
481
|
+
opts: {
|
|
482
|
+
jobId
|
|
483
|
+
},
|
|
433
484
|
children: [
|
|
434
485
|
{
|
|
435
486
|
// Step 1 (runs first as deepest child)
|
|
@@ -437,6 +488,9 @@ var createXl1ToEthBridgeJob = /* @__PURE__ */ __name(async (flowProducer2, tx) =
|
|
|
437
488
|
queueName: Xl1TransactionPreparation.queueName,
|
|
438
489
|
data: {
|
|
439
490
|
tx
|
|
491
|
+
},
|
|
492
|
+
opts: {
|
|
493
|
+
jobId
|
|
440
494
|
}
|
|
441
495
|
}
|
|
442
496
|
]
|
|
@@ -495,14 +549,14 @@ var asToken = /* @__PURE__ */ __name((value) => {
|
|
|
495
549
|
}, "asToken");
|
|
496
550
|
|
|
497
551
|
// src/config/getBridgeEscrowAddress.ts
|
|
498
|
-
import { asAddress as asAddress2, assertEx as
|
|
552
|
+
import { asAddress as asAddress2, assertEx as assertEx10 } from "@xylabs/sdk-js";
|
|
499
553
|
var tryGetBridgeEscrowAddress = /* @__PURE__ */ __name((config) => {
|
|
500
554
|
const address = asAddress2(config.escrowAddress);
|
|
501
555
|
return address;
|
|
502
556
|
}, "tryGetBridgeEscrowAddress");
|
|
503
557
|
|
|
504
558
|
// src/config/getBridgeFeesAddress.ts
|
|
505
|
-
import { asAddress as asAddress3, assertEx as
|
|
559
|
+
import { asAddress as asAddress3, assertEx as assertEx11 } from "@xylabs/sdk-js";
|
|
506
560
|
var tryGetBridgeFeesAddress = /* @__PURE__ */ __name((config) => {
|
|
507
561
|
const address = asAddress3(config.feesAddress);
|
|
508
562
|
return address;
|
|
@@ -530,17 +584,17 @@ var getMinBridgeAmount = /* @__PURE__ */ __name((config) => {
|
|
|
530
584
|
}, "getMinBridgeAmount");
|
|
531
585
|
|
|
532
586
|
// src/config/getRemoteChainId.ts
|
|
533
|
-
import { assertEx as
|
|
587
|
+
import { assertEx as assertEx12 } from "@xylabs/sdk-js";
|
|
534
588
|
var getRemoteChainId = /* @__PURE__ */ __name((config) => {
|
|
535
|
-
const remoteChainId =
|
|
589
|
+
const remoteChainId = assertEx12(asChainId(config.remoteChainId), () => "Invalid remote chain ID in config");
|
|
536
590
|
return remoteChainId;
|
|
537
591
|
}, "getRemoteChainId");
|
|
538
592
|
|
|
539
593
|
// src/config/getRemoteTokenAddress.ts
|
|
540
|
-
import { assertEx as
|
|
594
|
+
import { assertEx as assertEx13 } from "@xylabs/sdk-js";
|
|
541
595
|
var getRemoteTokenAddress = /* @__PURE__ */ __name((config) => {
|
|
542
596
|
const token = asToken(config.remoteTokenAddress);
|
|
543
|
-
return
|
|
597
|
+
return assertEx13(token, () => "Remote token address is not defined in bridge configuration");
|
|
544
598
|
}, "getRemoteTokenAddress");
|
|
545
599
|
|
|
546
600
|
// src/config/getBridgeWalletAccount.ts
|
|
@@ -578,13 +632,13 @@ var getTransferAddresses = /* @__PURE__ */ __name(async (config) => {
|
|
|
578
632
|
}, "getTransferAddresses");
|
|
579
633
|
|
|
580
634
|
// src/config/getXl1ChainId.ts
|
|
581
|
-
import { assertEx as
|
|
635
|
+
import { assertEx as assertEx14, isDefined as isDefined7 } from "@xylabs/sdk-js";
|
|
582
636
|
var getXl1ChainId = /* @__PURE__ */ __name((config) => {
|
|
583
637
|
const xl1ChainId = config.xl1ChainId;
|
|
584
638
|
if (isDefined7(xl1ChainId)) {
|
|
585
|
-
return
|
|
639
|
+
return assertEx14(asChainId(xl1ChainId), () => "Invalid xl1ChainId in bridge config");
|
|
586
640
|
}
|
|
587
|
-
return
|
|
641
|
+
return assertEx14(asChainId(config.chain.id), () => "Invalid chain.id in config");
|
|
588
642
|
}, "getXl1ChainId");
|
|
589
643
|
|
|
590
644
|
// src/config/getXl1TokenAddress.ts
|
|
@@ -650,7 +704,7 @@ var makeBridgeConfigRoute = /* @__PURE__ */ __name((config) => {
|
|
|
650
704
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.ts
|
|
651
705
|
import { requestHandlerValidator as requestHandlerValidator2 } from "@xylabs/express";
|
|
652
706
|
import { toAddress, toHex } from "@xylabs/sdk-js";
|
|
653
|
-
import { PayloadZodStrictOfSchema } from "@xyo-network/
|
|
707
|
+
import { PayloadZodStrictOfSchema } from "@xyo-network/sdk-js";
|
|
654
708
|
import { BridgeDestinationObservationFieldsZod, BridgeDestinationObservationSchema } from "@xyo-network/xl1-sdk";
|
|
655
709
|
import { z } from "zod";
|
|
656
710
|
|
|
@@ -710,17 +764,16 @@ var makeBridgeFromRemoteStatusRoute = /* @__PURE__ */ __name((config) => {
|
|
|
710
764
|
|
|
711
765
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.ts
|
|
712
766
|
import { requestHandlerValidator as requestHandlerValidator3 } from "@xylabs/express";
|
|
713
|
-
import { PayloadZodLooseOfSchema, PayloadZodStrictOfSchema as PayloadZodStrictOfSchema2 } from "@xyo-network/
|
|
714
|
-
import { PayloadBuilder as PayloadBuilder11 } from "@xyo-network/sdk-js";
|
|
767
|
+
import { PayloadBuilder as PayloadBuilder12, PayloadZodLooseOfSchema, PayloadZodStrictOfSchema as PayloadZodStrictOfSchema2 } from "@xyo-network/sdk-js";
|
|
715
768
|
import { BridgeIntentFieldsZod, BridgeIntentSchema as BridgeIntentSchema2, BridgeSourceObservationFieldsZod, BridgeSourceObservationSchema, SignedTransactionBoundWitnessZod, TransferZod } from "@xyo-network/xl1-sdk";
|
|
716
769
|
import { z as z2 } from "zod";
|
|
717
770
|
|
|
718
771
|
// src/util/calculateBridgeFees.ts
|
|
719
|
-
import { hexToBigInt as
|
|
772
|
+
import { hexToBigInt as hexToBigInt5, toHex as toHex2 } from "@xylabs/sdk-js";
|
|
720
773
|
var calculateBridgeFees = /* @__PURE__ */ __name((srcAmount, feeStructure) => {
|
|
721
774
|
const { feeFixed, feeRateBasisPoints } = feeStructure;
|
|
722
|
-
const srcAmountBigInt =
|
|
723
|
-
const feeFixedBigInt =
|
|
775
|
+
const srcAmountBigInt = hexToBigInt5(srcAmount);
|
|
776
|
+
const feeFixedBigInt = hexToBigInt5(feeFixed);
|
|
724
777
|
const feeVariableBigInt = srcAmountBigInt * BigInt(feeRateBasisPoints) / 10000n;
|
|
725
778
|
const feeVariable = toHex2(feeVariableBigInt);
|
|
726
779
|
const feeTotalBigInt = feeFixedBigInt + feeVariableBigInt;
|
|
@@ -734,12 +787,12 @@ var calculateBridgeFees = /* @__PURE__ */ __name((srcAmount, feeStructure) => {
|
|
|
734
787
|
}, "calculateBridgeFees");
|
|
735
788
|
|
|
736
789
|
// src/util/createBridgeTransfer.ts
|
|
737
|
-
import { hexToBigInt as
|
|
790
|
+
import { hexToBigInt as hexToBigInt6 } from "@xylabs/sdk-js";
|
|
738
791
|
import { createTransferPayload } from "@xyo-network/xl1-sdk";
|
|
739
792
|
var createBridgeTransfer = /* @__PURE__ */ __name((sender, srcAmount, escrowAddress, feesAddress, context) => {
|
|
740
793
|
const { feeFixed, feeVariable } = context;
|
|
741
|
-
const escrowAmount =
|
|
742
|
-
const feesAmount =
|
|
794
|
+
const escrowAmount = hexToBigInt6(srcAmount);
|
|
795
|
+
const feesAmount = hexToBigInt6(feeFixed) + hexToBigInt6(feeVariable);
|
|
743
796
|
const transfers = escrowAddress === feesAddress ? {
|
|
744
797
|
[feesAddress]: escrowAmount + feesAmount
|
|
745
798
|
} : {
|
|
@@ -752,7 +805,7 @@ var createBridgeTransfer = /* @__PURE__ */ __name((sender, srcAmount, escrowAddr
|
|
|
752
805
|
|
|
753
806
|
// src/util/generateBridgeEstimate.ts
|
|
754
807
|
import { toAddress as toAddress2 } from "@xylabs/sdk-js";
|
|
755
|
-
import { PayloadBuilder as
|
|
808
|
+
import { PayloadBuilder as PayloadBuilder9 } from "@xyo-network/sdk-js";
|
|
756
809
|
import { BridgeIntentSchema } from "@xyo-network/xl1-sdk";
|
|
757
810
|
import { v4 } from "uuid";
|
|
758
811
|
var generateBridgeEstimate = /* @__PURE__ */ __name(async (srcAddress, srcAmount, destAddress, config, nonceOverride) => {
|
|
@@ -776,7 +829,7 @@ var generateBridgeEstimate = /* @__PURE__ */ __name(async (srcAddress, srcAmount
|
|
|
776
829
|
destToken: remoteTokenAddress,
|
|
777
830
|
nonce
|
|
778
831
|
};
|
|
779
|
-
const bridgeIntent = new
|
|
832
|
+
const bridgeIntent = new PayloadBuilder9({
|
|
780
833
|
schema: BridgeIntentSchema
|
|
781
834
|
}).fields(bridgeIntentFields).build();
|
|
782
835
|
const transfer = createBridgeTransfer(sender, srcAmount, escrowAddress, feesAddress, fees);
|
|
@@ -788,24 +841,24 @@ var generateBridgeEstimate = /* @__PURE__ */ __name(async (srcAddress, srcAmount
|
|
|
788
841
|
|
|
789
842
|
// src/util/validateBridgeEstimateExact.ts
|
|
790
843
|
import { isUndefined as isUndefined3 } from "@xylabs/sdk-js";
|
|
791
|
-
import { PayloadBuilder as
|
|
844
|
+
import { PayloadBuilder as PayloadBuilder10 } from "@xyo-network/sdk-js";
|
|
792
845
|
var validateBridgeEstimateExact = /* @__PURE__ */ __name(async (intent, transfer, config) => {
|
|
793
846
|
const { srcAddress, srcAmount, destAddress } = intent;
|
|
794
847
|
const [calculatedIntent, calculatedTransfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
|
|
795
848
|
if (isUndefined3(calculatedIntent) || isUndefined3(calculatedTransfer)) return false;
|
|
796
849
|
const { nonce: expectedIntentNonce, ...expectedIntentStatic } = calculatedIntent;
|
|
797
850
|
const { nonce: actualIntentNonce, ...actualIntentStatic } = intent;
|
|
798
|
-
if (await
|
|
851
|
+
if (await PayloadBuilder10.dataHash(expectedIntentStatic) !== await PayloadBuilder10.dataHash(actualIntentStatic)) return false;
|
|
799
852
|
const { epoch: expectedTransferEpoch, ...expectedTransferStatic } = calculatedTransfer;
|
|
800
853
|
const { epoch: actualTransferEpoch, ...actualTransferStatic } = transfer;
|
|
801
|
-
if (await
|
|
854
|
+
if (await PayloadBuilder10.dataHash(expectedTransferStatic) !== await PayloadBuilder10.dataHash(actualTransferStatic)) return false;
|
|
802
855
|
return true;
|
|
803
856
|
}, "validateBridgeEstimateExact");
|
|
804
857
|
|
|
805
858
|
// src/util/validateBridgeTransaction.ts
|
|
806
859
|
import { asAddress as asAddress4, isDefined as isDefined9 } from "@xylabs/sdk-js";
|
|
807
860
|
import { addressesContains, BoundWitnessValidator, payloadHashesContainsAll } from "@xyo-network/boundwitness-validator";
|
|
808
|
-
import { PayloadBuilder as
|
|
861
|
+
import { PayloadBuilder as PayloadBuilder11 } from "@xyo-network/sdk-js";
|
|
809
862
|
var validateBridgeTransaction = /* @__PURE__ */ __name(async (signedTxBw, intent, transfer, config) => {
|
|
810
863
|
const { srcAddress } = intent;
|
|
811
864
|
const chainId = getXl1ChainId(config);
|
|
@@ -814,7 +867,7 @@ var validateBridgeTransaction = /* @__PURE__ */ __name(async (signedTxBw, intent
|
|
|
814
867
|
if (isDefined9(errors) && errors.length > 0) return false;
|
|
815
868
|
const sender = asAddress4(srcAddress, true);
|
|
816
869
|
if (!addressesContains(signedTxBw, sender)) return false;
|
|
817
|
-
const hashes = await
|
|
870
|
+
const hashes = await PayloadBuilder11.hashes([
|
|
818
871
|
intent,
|
|
819
872
|
transfer
|
|
820
873
|
]);
|
|
@@ -862,14 +915,14 @@ var makeBridgeToRemoteRoute = /* @__PURE__ */ __name((config) => {
|
|
|
862
915
|
]
|
|
863
916
|
];
|
|
864
917
|
await createXl1ToEthBridgeJob(flowProducer2, singedHydratedTransaction);
|
|
865
|
-
const srcConfirmation = await
|
|
918
|
+
const srcConfirmation = await PayloadBuilder12.hash(signedTxBw);
|
|
866
919
|
const bridgeCommonFieldsZod = z2.object({}).extend(BridgeSourceObservationFieldsZod.shape);
|
|
867
920
|
const bridgeCommonFields = bridgeCommonFieldsZod.parse(bridgeIntent);
|
|
868
921
|
const bridgeObservationFields = {
|
|
869
922
|
...bridgeCommonFields,
|
|
870
923
|
srcConfirmation
|
|
871
924
|
};
|
|
872
|
-
const bridgeObservation = new
|
|
925
|
+
const bridgeObservation = new PayloadBuilder12({
|
|
873
926
|
schema: BridgeSourceObservationSchema
|
|
874
927
|
}).fields(bridgeObservationFields).build();
|
|
875
928
|
res.json(bridgeObservation);
|
|
@@ -879,8 +932,8 @@ var makeBridgeToRemoteRoute = /* @__PURE__ */ __name((config) => {
|
|
|
879
932
|
|
|
880
933
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts
|
|
881
934
|
import { requestHandlerValidator as requestHandlerValidator4 } from "@xylabs/express";
|
|
882
|
-
import { assertEx as
|
|
883
|
-
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema3 } from "@xyo-network/
|
|
935
|
+
import { assertEx as assertEx15, toAddress as toAddress3 } from "@xylabs/sdk-js";
|
|
936
|
+
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema3 } from "@xyo-network/sdk-js";
|
|
884
937
|
import { BridgeIntentFieldsZod as BridgeIntentFieldsZod2, BridgeIntentSchema as BridgeIntentSchema3, buildUnsignedTransaction, toXL1BlockNumber, TransactionBoundWitnessZod, TransferZod as TransferZod2 } from "@xyo-network/xl1-sdk";
|
|
885
938
|
import { z as z3 } from "zod";
|
|
886
939
|
var BridgeToRemoteEstimateBodyZod = BridgeIntentFieldsZod2.pick({
|
|
@@ -910,7 +963,7 @@ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config, gateway) =
|
|
|
910
963
|
const { srcAddress, srcAmount, destAddress } = req.body;
|
|
911
964
|
const [bridgeIntent, transfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
|
|
912
965
|
const sender = toAddress3(srcAddress);
|
|
913
|
-
const viewer =
|
|
966
|
+
const viewer = assertEx15(gateway.connection.viewer, () => new Error("Viewer not available on gateway connection"));
|
|
914
967
|
const currentBlockNumber = await viewer.currentBlockNumber();
|
|
915
968
|
const nbf = toXL1BlockNumber(currentBlockNumber, true);
|
|
916
969
|
const exp = toXL1BlockNumber(currentBlockNumber + 1e3, true);
|
|
@@ -930,86 +983,126 @@ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config, gateway) =
|
|
|
930
983
|
|
|
931
984
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts
|
|
932
985
|
import { requestHandlerValidator as requestHandlerValidator5 } from "@xylabs/express";
|
|
933
|
-
import {
|
|
934
|
-
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema4 } from "@xyo-network/
|
|
935
|
-
import { BridgeDestinationObservationFieldsZod as BridgeDestinationObservationFieldsZod2, BridgeDestinationObservationSchema as BridgeDestinationObservationSchema2, BridgeIntentFieldsZod as BridgeIntentFieldsZod3, BridgeIntentSchema as BridgeIntentSchema4, BridgeSourceObservationFieldsZod as BridgeSourceObservationFieldsZod2, BridgeSourceObservationSchema as BridgeSourceObservationSchema2 } from "@xyo-network/xl1-sdk";
|
|
986
|
+
import { asHex as asHex3, isDefined as isDefined10 } from "@xylabs/sdk-js";
|
|
987
|
+
import { PayloadBuilder as PayloadBuilder13, PayloadZodStrictOfSchema as PayloadZodStrictOfSchema4 } from "@xyo-network/sdk-js";
|
|
988
|
+
import { asBridgeIntent, BridgeDestinationObservationFieldsZod as BridgeDestinationObservationFieldsZod2, BridgeDestinationObservationSchema as BridgeDestinationObservationSchema2, BridgeIntentFieldsZod as BridgeIntentFieldsZod3, BridgeIntentSchema as BridgeIntentSchema4, BridgeSourceObservationFieldsZod as BridgeSourceObservationFieldsZod2, BridgeSourceObservationSchema as BridgeSourceObservationSchema2, isBridgeIntent as isBridgeIntent5 } from "@xyo-network/xl1-sdk";
|
|
989
|
+
import { Queue } from "bullmq";
|
|
936
990
|
import { z as z4 } from "zod";
|
|
991
|
+
var BridgeIntentResponseZod = PayloadZodStrictOfSchema4(BridgeIntentSchema4).extend(BridgeIntentFieldsZod3.shape);
|
|
992
|
+
var BridgeSourceResponseZod = PayloadZodStrictOfSchema4(BridgeSourceObservationSchema2).extend(BridgeSourceObservationFieldsZod2.shape);
|
|
993
|
+
var BridgeDestinationResponseZod = PayloadZodStrictOfSchema4(BridgeDestinationObservationSchema2).extend(BridgeDestinationObservationFieldsZod2.shape);
|
|
937
994
|
var BridgeToRemoteStatusResponseZod = z4.union([
|
|
938
995
|
z4.tuple([]),
|
|
939
996
|
z4.tuple([
|
|
940
|
-
|
|
997
|
+
BridgeIntentResponseZod
|
|
941
998
|
]),
|
|
942
999
|
z4.tuple([
|
|
943
|
-
|
|
944
|
-
|
|
1000
|
+
BridgeIntentResponseZod,
|
|
1001
|
+
BridgeSourceResponseZod
|
|
945
1002
|
]),
|
|
946
1003
|
z4.tuple([
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
1004
|
+
BridgeIntentResponseZod,
|
|
1005
|
+
BridgeSourceResponseZod,
|
|
1006
|
+
BridgeDestinationResponseZod
|
|
950
1007
|
])
|
|
951
1008
|
]);
|
|
1009
|
+
var statusQueues;
|
|
1010
|
+
var getStatusQueues = /* @__PURE__ */ __name((config) => {
|
|
1011
|
+
if (statusQueues) return statusQueues;
|
|
1012
|
+
const connection2 = getConnection(config);
|
|
1013
|
+
statusQueues = {
|
|
1014
|
+
ethTransactionMonitor: new Queue(EthTransactionMonitor.queueName, {
|
|
1015
|
+
connection: connection2
|
|
1016
|
+
}),
|
|
1017
|
+
ethTransactionPreparation: new Queue(EthTransactionPreparation.queueName, {
|
|
1018
|
+
connection: connection2
|
|
1019
|
+
}),
|
|
1020
|
+
ethTransactionSubmission: new Queue(EthTransactionSubmission.queueName, {
|
|
1021
|
+
connection: connection2
|
|
1022
|
+
}),
|
|
1023
|
+
xl1ToEthBridgeParent: new Queue(Xl1ToEthBridgeParent.queueName, {
|
|
1024
|
+
connection: connection2
|
|
1025
|
+
}),
|
|
1026
|
+
xl1TransactionMonitor: new Queue(Xl1TransactionMonitor.queueName, {
|
|
1027
|
+
connection: connection2
|
|
1028
|
+
}),
|
|
1029
|
+
xl1TransactionPreparation: new Queue(Xl1TransactionPreparation.queueName, {
|
|
1030
|
+
connection: connection2
|
|
1031
|
+
}),
|
|
1032
|
+
xl1TransactionSubmission: new Queue(Xl1TransactionSubmission.queueName, {
|
|
1033
|
+
connection: connection2
|
|
1034
|
+
})
|
|
1035
|
+
};
|
|
1036
|
+
return statusQueues;
|
|
1037
|
+
}, "getStatusQueues");
|
|
1038
|
+
var getStatusQueueJobs = /* @__PURE__ */ __name(async (queues, jobId) => {
|
|
1039
|
+
const [ethTransactionMonitorJob, ethTransactionPreparationJob, ethTransactionSubmissionJob, xl1ToEthBridgeParentJob, xl1TransactionMonitorJob, xl1TransactionPreparationJob, xl1TransactionSubmissionJob] = await Promise.all([
|
|
1040
|
+
queues.ethTransactionMonitor.getJob(jobId),
|
|
1041
|
+
queues.ethTransactionPreparation.getJob(jobId),
|
|
1042
|
+
queues.ethTransactionSubmission.getJob(jobId),
|
|
1043
|
+
queues.xl1ToEthBridgeParent.getJob(jobId),
|
|
1044
|
+
queues.xl1TransactionMonitor.getJob(jobId),
|
|
1045
|
+
queues.xl1TransactionPreparation.getJob(jobId),
|
|
1046
|
+
queues.xl1TransactionSubmission.getJob(jobId)
|
|
1047
|
+
]);
|
|
1048
|
+
return {
|
|
1049
|
+
ethTransactionMonitorJob,
|
|
1050
|
+
ethTransactionPreparationJob,
|
|
1051
|
+
ethTransactionSubmissionJob,
|
|
1052
|
+
xl1ToEthBridgeParentJob,
|
|
1053
|
+
xl1TransactionMonitorJob,
|
|
1054
|
+
xl1TransactionPreparationJob,
|
|
1055
|
+
xl1TransactionSubmissionJob
|
|
1056
|
+
};
|
|
1057
|
+
}, "getStatusQueueJobs");
|
|
952
1058
|
var makeBridgeToRemoteStatusRoute = /* @__PURE__ */ __name((config) => {
|
|
953
1059
|
const params = z4.object({
|
|
954
1060
|
chainId: getRemoteChainIdZod(config),
|
|
955
1061
|
nonce: z4.string().nonempty()
|
|
956
1062
|
});
|
|
957
|
-
const query = z4.object({
|
|
958
|
-
mockStatus: z4.coerce.number().default(0)
|
|
959
|
-
});
|
|
960
1063
|
const validateRequest2 = requestHandlerValidator5({
|
|
961
1064
|
params,
|
|
962
|
-
query,
|
|
963
1065
|
response: BridgeToRemoteStatusResponseZod
|
|
964
1066
|
});
|
|
965
1067
|
return {
|
|
966
1068
|
method: "get",
|
|
967
1069
|
path: "/bridge/chains/:chainId/bridgeToRemote/status/:nonce",
|
|
968
1070
|
handlers: validateRequest2(async (req, res) => {
|
|
969
|
-
const
|
|
970
|
-
const { mockStatus = 0 } = req.query;
|
|
1071
|
+
const jobId = req.params.nonce;
|
|
971
1072
|
const result = [];
|
|
972
|
-
const
|
|
973
|
-
const
|
|
974
|
-
const
|
|
975
|
-
|
|
976
|
-
const
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
const
|
|
980
|
-
const
|
|
981
|
-
|
|
982
|
-
if (
|
|
983
|
-
const
|
|
984
|
-
|
|
985
|
-
}
|
|
986
|
-
if (mockStatus > 1) {
|
|
1073
|
+
const queues = getStatusQueues(config);
|
|
1074
|
+
const statusQueueJobs = await getStatusQueueJobs(queues, jobId);
|
|
1075
|
+
const tx = Object.values(statusQueueJobs).map((job) => job?.data?.tx).find((tx2) => isDefined10(tx2));
|
|
1076
|
+
if (!tx) return res.sendStatus(404);
|
|
1077
|
+
const bridgeIntent = tx[1].find(isBridgeIntent5);
|
|
1078
|
+
if (!bridgeIntent) return res.sendStatus(404);
|
|
1079
|
+
result[0] = asBridgeIntent(PayloadBuilder13.omitMeta(bridgeIntent));
|
|
1080
|
+
const { xl1TransactionMonitorJob } = statusQueueJobs;
|
|
1081
|
+
const xl1MonitorState = xl1TransactionMonitorJob ? await xl1TransactionMonitorJob.getState() : void 0;
|
|
1082
|
+
const srcConfirmation = asHex3(jobId);
|
|
1083
|
+
if (xl1MonitorState === "completed" && isDefined10(srcConfirmation)) {
|
|
1084
|
+
const bridgeCommonFieldsZod = z4.object({}).extend(BridgeSourceObservationFieldsZod2.shape);
|
|
1085
|
+
const bridgeCommonFields = bridgeCommonFieldsZod.parse(bridgeIntent);
|
|
987
1086
|
const observation = {
|
|
988
1087
|
schema: BridgeSourceObservationSchema2,
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
destAmount,
|
|
992
|
-
destToken,
|
|
993
|
-
src,
|
|
994
|
-
srcAddress,
|
|
995
|
-
srcAmount,
|
|
996
|
-
srcToken,
|
|
997
|
-
srcConfirmation: toHex3("0x8888")
|
|
1088
|
+
...bridgeCommonFields,
|
|
1089
|
+
srcConfirmation
|
|
998
1090
|
};
|
|
999
1091
|
result[1] = observation;
|
|
1000
1092
|
}
|
|
1001
|
-
|
|
1093
|
+
const { ethTransactionMonitorJob } = statusQueueJobs;
|
|
1094
|
+
const ethMonitorState = ethTransactionMonitorJob ? await ethTransactionMonitorJob.getState() : void 0;
|
|
1095
|
+
const blockHash = ethTransactionMonitorJob?.returnvalue?.blockHash;
|
|
1096
|
+
const destConfirmation = asHex3(blockHash);
|
|
1097
|
+
if (ethMonitorState === "completed" && isDefined10(blockHash)) {
|
|
1098
|
+
const bridgeDestinationFieldsZod = z4.object({}).extend(BridgeDestinationObservationFieldsZod2.shape);
|
|
1099
|
+
const bridgeDestinationFields = bridgeDestinationFieldsZod.parse({
|
|
1100
|
+
...bridgeIntent,
|
|
1101
|
+
destConfirmation
|
|
1102
|
+
});
|
|
1002
1103
|
const observation = {
|
|
1003
1104
|
schema: BridgeDestinationObservationSchema2,
|
|
1004
|
-
|
|
1005
|
-
destAddress,
|
|
1006
|
-
destAmount,
|
|
1007
|
-
destToken,
|
|
1008
|
-
src,
|
|
1009
|
-
srcAddress,
|
|
1010
|
-
srcAmount,
|
|
1011
|
-
srcToken,
|
|
1012
|
-
destConfirmation: toHex3("0x9999")
|
|
1105
|
+
...bridgeDestinationFields
|
|
1013
1106
|
};
|
|
1014
1107
|
result[2] = observation;
|
|
1015
1108
|
}
|
|
@@ -1064,7 +1157,7 @@ var getApp = /* @__PURE__ */ __name((config, gateway) => {
|
|
|
1064
1157
|
}, "getApp");
|
|
1065
1158
|
|
|
1066
1159
|
// src/services/getServices.ts
|
|
1067
|
-
import { assertEx as
|
|
1160
|
+
import { assertEx as assertEx16, isDefined as isDefined11 } from "@xylabs/sdk-js";
|
|
1068
1161
|
import { initEvmProvider } from "@xyo-network/chain-orchestration";
|
|
1069
1162
|
import { BridgeableToken__factory, LiquidityPoolBridge__factory } from "@xyo-network/typechain";
|
|
1070
1163
|
import { HDWallet as HDWallet2 } from "@xyo-network/wallet";
|
|
@@ -1109,12 +1202,12 @@ var getServices = /* @__PURE__ */ __name(async (context, gateway) => {
|
|
|
1109
1202
|
const xl1TxStateMap = await getIterableMap(config, "liquidity_bridge_xl1_to_eth_xl1_tx_state");
|
|
1110
1203
|
const provider = await initEvmProvider(context);
|
|
1111
1204
|
const { remoteBridgeContractAddress, remoteChainWalletPrivateKey, remoteTokenAddress, mnemonic } = config;
|
|
1112
|
-
const account =
|
|
1205
|
+
const account = isDefined11(mnemonic) ? await HDWallet2.fromPhrase(mnemonic) : await HDWallet2.random();
|
|
1113
1206
|
const wallet = new Wallet(remoteChainWalletPrivateKey, provider);
|
|
1114
1207
|
const bridgeableToken = BridgeableToken__factory.connect(getAddress2(remoteTokenAddress), wallet);
|
|
1115
1208
|
const bridge = LiquidityPoolBridge__factory.connect(getAddress2(remoteBridgeContractAddress), wallet);
|
|
1116
1209
|
const bridgeOwner = await bridge.owner();
|
|
1117
|
-
|
|
1210
|
+
assertEx16(bridgeOwner.toLowerCase() === wallet.address.toLowerCase(), () => "Wallet is not the owner of the bridge contract");
|
|
1118
1211
|
return {
|
|
1119
1212
|
account,
|
|
1120
1213
|
bridge,
|