@xyo-network/chain-bridge 1.19.15 → 1.19.16
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 +115 -80
- 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/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/package.json +40 -43
- package/src/modules/EVMLiquidityBridgeTransactionCompletionMonitorSentinel/EVMLiquidityBridgeTransactionCompletionMonitorSentinel.ts +2 -3
- package/src/modules/XL1TransactionCompletionMonitorSentinel/XL1TransactionCompletionMonitorSentinel.ts +2 -3
- 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 +1 -1
package/dist/node/index.mjs
CHANGED
|
@@ -91,26 +91,88 @@ var EthTransactionMonitor = {
|
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
// src/queue/workers/EthTransactionPreparation.ts
|
|
94
|
-
import { assertEx as
|
|
95
|
-
import { PayloadBuilder as
|
|
96
|
-
import { isBridgeIntent } from "@xyo-network/xl1-sdk";
|
|
94
|
+
import { assertEx as assertEx5, hexToBigInt as hexToBigInt4 } from "@xylabs/sdk-js";
|
|
95
|
+
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk-js";
|
|
96
|
+
import { isBridgeIntent as isBridgeIntent4 } from "@xyo-network/xl1-sdk";
|
|
97
97
|
import { Worker as Worker2 } from "bullmq";
|
|
98
98
|
import { getAddress } from "ethers";
|
|
99
|
+
|
|
100
|
+
// src/queue/workers/util/submitEthTransaction.ts
|
|
101
|
+
import { assertEx as assertEx2, hexToBigInt, toEthAddress } from "@xylabs/sdk-js";
|
|
102
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
|
|
103
|
+
import { isBridgeIntent } from "@xyo-network/xl1-sdk";
|
|
104
|
+
var submitEthTransaction = /* @__PURE__ */ __name(async (tx, bridgeableToken, bridge, wallet) => {
|
|
105
|
+
const xl1Transaction = assertEx2(tx[0], () => "No corresponding XL1 transaction found");
|
|
106
|
+
const bridgeIntent = assertEx2(tx[1].find(isBridgeIntent), () => "No bridge intent found");
|
|
107
|
+
const srcAddress = toEthAddress(bridgeIntent.srcAddress);
|
|
108
|
+
const destAddress = toEthAddress(bridgeIntent.destAddress);
|
|
109
|
+
const amount = hexToBigInt(bridgeIntent.destAmount);
|
|
110
|
+
const nonce = hexToBigInt(await PayloadBuilder2.hash(xl1Transaction));
|
|
111
|
+
const bridgeTx = await bridge.connect(wallet).bridgeFromRemote(srcAddress, destAddress, amount, nonce);
|
|
112
|
+
const receipt = await bridgeTx.wait(1);
|
|
113
|
+
return receipt?.hash;
|
|
114
|
+
}, "submitEthTransaction");
|
|
115
|
+
|
|
116
|
+
// src/queue/workers/util/submitXl1Transaction.ts
|
|
117
|
+
import { isAllowedBlockPayload } from "@xyo-network/xl1-sdk";
|
|
118
|
+
var submitXl1Transaction = /* @__PURE__ */ __name(async (preparedTx, gateway) => {
|
|
119
|
+
const offChainPayloads = preparedTx[1].filter((p) => !isAllowedBlockPayload(p));
|
|
120
|
+
const result = await gateway.addTransactionToChain(preparedTx, offChainPayloads);
|
|
121
|
+
return result;
|
|
122
|
+
}, "submitXl1Transaction");
|
|
123
|
+
|
|
124
|
+
// src/queue/workers/util/validateSufficientAllowance.ts
|
|
125
|
+
import { assertEx as assertEx3, hexToBigInt as hexToBigInt2 } from "@xylabs/sdk-js";
|
|
126
|
+
import { isBridgeIntent as isBridgeIntent2 } from "@xyo-network/xl1-sdk";
|
|
127
|
+
var validateSufficientAllowance = /* @__PURE__ */ __name(async (tx, bridgeableToken, bridge, logger) => {
|
|
128
|
+
const bridgeIntent = assertEx3(tx[1].find(isBridgeIntent2), () => "No bridge intent found");
|
|
129
|
+
const amount = hexToBigInt2(bridgeIntent.destAmount);
|
|
130
|
+
const liquiditySourceAddress = await bridge.liquiditySource();
|
|
131
|
+
const bridgeAddress = await bridge.getAddress();
|
|
132
|
+
const remainingAllowance = await bridgeableToken.allowance(liquiditySourceAddress, bridgeAddress);
|
|
133
|
+
await logger?.log(`Remaining allowance: ${remainingAllowance.toString()}`);
|
|
134
|
+
return remainingAllowance >= amount;
|
|
135
|
+
}, "validateSufficientAllowance");
|
|
136
|
+
|
|
137
|
+
// src/queue/workers/util/validateSufficientBalance.ts
|
|
138
|
+
import { assertEx as assertEx4, hexToBigInt as hexToBigInt3 } from "@xylabs/sdk-js";
|
|
139
|
+
import { isBridgeIntent as isBridgeIntent3 } from "@xyo-network/xl1-sdk";
|
|
140
|
+
var validateSufficientBalance = /* @__PURE__ */ __name(async (tx, bridgeableToken, bridge, logger) => {
|
|
141
|
+
const bridgeIntent = assertEx4(tx[1].find(isBridgeIntent3), () => "No bridge intent found");
|
|
142
|
+
const amount = hexToBigInt3(bridgeIntent.destAmount);
|
|
143
|
+
const liquiditySourceAddress = await bridge.liquiditySource();
|
|
144
|
+
const balance = await bridgeableToken.balanceOf(liquiditySourceAddress);
|
|
145
|
+
await logger?.log(`Remaining balance: ${balance.toString()}`);
|
|
146
|
+
return balance >= amount;
|
|
147
|
+
}, "validateSufficientBalance");
|
|
148
|
+
|
|
149
|
+
// src/queue/workers/EthTransactionPreparation.ts
|
|
99
150
|
var name2 = "Prepare ETH Transaction";
|
|
100
151
|
var queueName2 = "eth-tx-prepare";
|
|
101
152
|
var createWorker2 = /* @__PURE__ */ __name((connection2, services) => {
|
|
102
|
-
const bridge =
|
|
103
|
-
const
|
|
153
|
+
const bridge = assertEx5(services?.bridge, () => "bridge service not provided");
|
|
154
|
+
const bridgeableToken = assertEx5(services?.bridgeableToken, () => "bridgeableToken service not provided");
|
|
155
|
+
const stateMap = assertEx5(services?.ethTxStateMap, () => "ethTxStateMap service not provided");
|
|
104
156
|
const worker = new Worker2(queueName2, async (job) => {
|
|
105
157
|
const { tx } = job.data;
|
|
106
|
-
const hash = await
|
|
158
|
+
const hash = await PayloadBuilder3.hash(tx[0]);
|
|
107
159
|
await job.log(`[${hash}] preparing ETH transaction`);
|
|
160
|
+
await job.log(`[${hash}] validating liquiditySource has sufficient allowance`);
|
|
161
|
+
if (!await validateSufficientAllowance(tx, bridgeableToken, bridge, job)) {
|
|
162
|
+
throw new Error("Liquidity source does not have sufficient allowance for the bridge to execute the transaction");
|
|
163
|
+
}
|
|
164
|
+
await job.log(`[${hash}] validated liquiditySource has sufficient allowance`);
|
|
165
|
+
await job.log(`[${hash}] validating liquiditySource has sufficient balance`);
|
|
166
|
+
if (!await validateSufficientBalance(tx, bridgeableToken, bridge, job)) {
|
|
167
|
+
throw new Error("Liquidity source does not have sufficient balance for the bridge to execute the transaction");
|
|
168
|
+
}
|
|
169
|
+
await job.log(`[${hash}] validated liquiditySource has sufficient balance`);
|
|
108
170
|
await job.log(`[${hash}] building ETH transaction`);
|
|
109
|
-
const bridgeIntent =
|
|
110
|
-
const amount =
|
|
171
|
+
const bridgeIntent = assertEx5(tx[1].find(isBridgeIntent4), () => "No bridge intent found");
|
|
172
|
+
const amount = hexToBigInt4(bridgeIntent.destAmount);
|
|
111
173
|
const srcAddress = getAddress(bridgeIntent.srcAddress);
|
|
112
174
|
const destAddress = getAddress(bridgeIntent.destAddress);
|
|
113
|
-
const nonce =
|
|
175
|
+
const nonce = hexToBigInt4(await PayloadBuilder3.hash(tx[0]));
|
|
114
176
|
const preparedTx = await bridge.getFunction("bridgeFromRemote").populateTransaction(srcAddress, destAddress, amount, nonce);
|
|
115
177
|
await job.log(`[${hash}] built ETH transaction`);
|
|
116
178
|
await job.log(`[${hash}] storing ETH preparedTx`);
|
|
@@ -137,47 +199,21 @@ var EthTransactionPreparation = {
|
|
|
137
199
|
};
|
|
138
200
|
|
|
139
201
|
// src/queue/workers/EthTransactionSubmission.ts
|
|
140
|
-
import { assertEx as
|
|
202
|
+
import { assertEx as assertEx6, isDefined as isDefined3 } from "@xylabs/sdk-js";
|
|
141
203
|
import { PayloadBuilder as PayloadBuilder4 } from "@xyo-network/sdk-js";
|
|
142
204
|
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
205
|
var name3 = "Submit ETH Transaction";
|
|
170
206
|
var queueName3 = "eth-tx-submit";
|
|
171
207
|
var createWorker3 = /* @__PURE__ */ __name((connection2, services) => {
|
|
172
|
-
const bridge =
|
|
173
|
-
const bridgeableToken =
|
|
174
|
-
const wallet =
|
|
175
|
-
const stateMap =
|
|
208
|
+
const bridge = assertEx6(services?.bridge, () => "bridge service not provided");
|
|
209
|
+
const bridgeableToken = assertEx6(services?.bridgeableToken, () => "bridgeableToken service not provided");
|
|
210
|
+
const wallet = assertEx6(services?.wallet, () => "wallet service not provided");
|
|
211
|
+
const stateMap = assertEx6(services?.ethTxStateMap, () => "ethTxStateMap service not provided");
|
|
176
212
|
const worker = new Worker3(queueName3, async (job) => {
|
|
177
213
|
const { tx } = job.data;
|
|
178
214
|
const hash = await PayloadBuilder4.hash(tx[0]);
|
|
179
|
-
const state =
|
|
180
|
-
const preparedTx =
|
|
215
|
+
const state = assertEx6(await stateMap.get(hash), () => `[${hash}] state not found`);
|
|
216
|
+
const preparedTx = assertEx6(state?.preparedTx, () => `[${hash}] preparedTx not found`);
|
|
181
217
|
const { submissionHash: existingSubmissionHash } = state;
|
|
182
218
|
if (isDefined3(existingSubmissionHash)) {
|
|
183
219
|
await job.log(`[${hash}] Tx already submitted with submission response hash ${existingSubmissionHash}`);
|
|
@@ -186,7 +222,7 @@ var createWorker3 = /* @__PURE__ */ __name((connection2, services) => {
|
|
|
186
222
|
};
|
|
187
223
|
}
|
|
188
224
|
await job.log(`[${hash}] Submitting ETH tx`);
|
|
189
|
-
const submissionHash =
|
|
225
|
+
const submissionHash = assertEx6(await submitEthTransaction(tx, bridgeableToken, bridge, wallet), () => `[${hash}] submissionHash not found in receipt`);
|
|
190
226
|
await job.log(`[${hash}] Submitted ETH tx and received submission response hash ${submissionHash}`);
|
|
191
227
|
await job.log(`[${hash}] Storing ETH submissionHash`);
|
|
192
228
|
state.submissionHash = submissionHash;
|
|
@@ -240,20 +276,20 @@ var Xl1ToEthBridgeParent = {
|
|
|
240
276
|
};
|
|
241
277
|
|
|
242
278
|
// src/queue/workers/Xl1TransactionMonitor.ts
|
|
243
|
-
import { assertEx as
|
|
279
|
+
import { assertEx as assertEx7, isDefined as isDefined4, isNull } from "@xylabs/sdk-js";
|
|
244
280
|
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/sdk-js";
|
|
245
281
|
import { UnrecoverableError, Worker as Worker5 } from "bullmq";
|
|
246
282
|
var name5 = "Monitor Submitted XL1 Transaction";
|
|
247
283
|
var queueName5 = "xl1-tx-monitor";
|
|
248
284
|
var createWorker5 = /* @__PURE__ */ __name((connection2, services) => {
|
|
249
|
-
const gateway =
|
|
250
|
-
const stateMap =
|
|
285
|
+
const gateway = assertEx7(services?.gateway, () => "gateway service not provided");
|
|
286
|
+
const stateMap = assertEx7(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
|
|
251
287
|
const worker = new Worker5(queueName5, async (job) => {
|
|
252
288
|
const { tx } = job.data;
|
|
253
289
|
const hash = await PayloadBuilder5.hash(tx[0]);
|
|
254
|
-
const viewer =
|
|
255
|
-
const state =
|
|
256
|
-
const submissionHash =
|
|
290
|
+
const viewer = assertEx7(gateway.connection.viewer, () => `[${hash}] viewer not defined on gateway`);
|
|
291
|
+
const state = assertEx7(await stateMap.get(hash), () => `[${hash}] state not found`);
|
|
292
|
+
const submissionHash = assertEx7(state?.submissionHash, () => `[${hash}] submissionHash not found`);
|
|
257
293
|
await job.log(`[${hash}] Checking for XL1 transaction inclusion on chain`);
|
|
258
294
|
const foundTx = await viewer.transactionByHash(submissionHash);
|
|
259
295
|
if (isDefined4(foundTx) && !isNull(foundTx)) {
|
|
@@ -286,13 +322,13 @@ var Xl1TransactionMonitor = {
|
|
|
286
322
|
};
|
|
287
323
|
|
|
288
324
|
// src/queue/workers/Xl1TransactionPreparation.ts
|
|
289
|
-
import { assertEx as
|
|
325
|
+
import { assertEx as assertEx8 } from "@xylabs/sdk-js";
|
|
290
326
|
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/sdk-js";
|
|
291
327
|
import { Worker as Worker6 } from "bullmq";
|
|
292
328
|
var name6 = "Prepare XL1 Transaction";
|
|
293
329
|
var queueName6 = "xl1-tx-prepare";
|
|
294
330
|
var createWorker6 = /* @__PURE__ */ __name((connection2, services) => {
|
|
295
|
-
const stateMap =
|
|
331
|
+
const stateMap = assertEx8(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
|
|
296
332
|
const worker = new Worker6(queueName6, async (job) => {
|
|
297
333
|
const { tx } = job.data;
|
|
298
334
|
const hash = await PayloadBuilder6.hash(tx[0]);
|
|
@@ -322,19 +358,19 @@ var Xl1TransactionPreparation = {
|
|
|
322
358
|
};
|
|
323
359
|
|
|
324
360
|
// src/queue/workers/Xl1TransactionSubmission.ts
|
|
325
|
-
import { assertEx as
|
|
361
|
+
import { assertEx as assertEx9, isDefined as isDefined5 } from "@xylabs/sdk-js";
|
|
326
362
|
import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/sdk-js";
|
|
327
363
|
import { Worker as Worker7 } from "bullmq";
|
|
328
364
|
var name7 = "Submit XL1 Transaction";
|
|
329
365
|
var queueName7 = "xl1-tx-submit";
|
|
330
366
|
var createWorker7 = /* @__PURE__ */ __name((connection2, services) => {
|
|
331
|
-
const gateway =
|
|
332
|
-
const stateMap =
|
|
367
|
+
const gateway = assertEx9(services?.gateway, () => "gateway service not provided");
|
|
368
|
+
const stateMap = assertEx9(services?.xl1TxStateMap, () => "xl1TxStateMap service not provided");
|
|
333
369
|
const worker = new Worker7(queueName7, async (job) => {
|
|
334
370
|
const { tx } = job.data;
|
|
335
371
|
const hash = await PayloadBuilder7.hash(tx[0]);
|
|
336
|
-
const state =
|
|
337
|
-
const preparedTx =
|
|
372
|
+
const state = assertEx9(await stateMap.get(hash), () => `[${hash}] state not found`);
|
|
373
|
+
const preparedTx = assertEx9(state?.preparedTx, () => `[${hash}] preparedTx not found`);
|
|
338
374
|
const { submissionHash: existingSubmissionHash } = state;
|
|
339
375
|
if (isDefined5(existingSubmissionHash)) {
|
|
340
376
|
await job.log(`[${hash}] Tx already submitted with submission response hash ${existingSubmissionHash}`);
|
|
@@ -495,14 +531,14 @@ var asToken = /* @__PURE__ */ __name((value) => {
|
|
|
495
531
|
}, "asToken");
|
|
496
532
|
|
|
497
533
|
// src/config/getBridgeEscrowAddress.ts
|
|
498
|
-
import { asAddress as asAddress2, assertEx as
|
|
534
|
+
import { asAddress as asAddress2, assertEx as assertEx10 } from "@xylabs/sdk-js";
|
|
499
535
|
var tryGetBridgeEscrowAddress = /* @__PURE__ */ __name((config) => {
|
|
500
536
|
const address = asAddress2(config.escrowAddress);
|
|
501
537
|
return address;
|
|
502
538
|
}, "tryGetBridgeEscrowAddress");
|
|
503
539
|
|
|
504
540
|
// src/config/getBridgeFeesAddress.ts
|
|
505
|
-
import { asAddress as asAddress3, assertEx as
|
|
541
|
+
import { asAddress as asAddress3, assertEx as assertEx11 } from "@xylabs/sdk-js";
|
|
506
542
|
var tryGetBridgeFeesAddress = /* @__PURE__ */ __name((config) => {
|
|
507
543
|
const address = asAddress3(config.feesAddress);
|
|
508
544
|
return address;
|
|
@@ -530,17 +566,17 @@ var getMinBridgeAmount = /* @__PURE__ */ __name((config) => {
|
|
|
530
566
|
}, "getMinBridgeAmount");
|
|
531
567
|
|
|
532
568
|
// src/config/getRemoteChainId.ts
|
|
533
|
-
import { assertEx as
|
|
569
|
+
import { assertEx as assertEx12 } from "@xylabs/sdk-js";
|
|
534
570
|
var getRemoteChainId = /* @__PURE__ */ __name((config) => {
|
|
535
|
-
const remoteChainId =
|
|
571
|
+
const remoteChainId = assertEx12(asChainId(config.remoteChainId), () => "Invalid remote chain ID in config");
|
|
536
572
|
return remoteChainId;
|
|
537
573
|
}, "getRemoteChainId");
|
|
538
574
|
|
|
539
575
|
// src/config/getRemoteTokenAddress.ts
|
|
540
|
-
import { assertEx as
|
|
576
|
+
import { assertEx as assertEx13 } from "@xylabs/sdk-js";
|
|
541
577
|
var getRemoteTokenAddress = /* @__PURE__ */ __name((config) => {
|
|
542
578
|
const token = asToken(config.remoteTokenAddress);
|
|
543
|
-
return
|
|
579
|
+
return assertEx13(token, () => "Remote token address is not defined in bridge configuration");
|
|
544
580
|
}, "getRemoteTokenAddress");
|
|
545
581
|
|
|
546
582
|
// src/config/getBridgeWalletAccount.ts
|
|
@@ -578,13 +614,13 @@ var getTransferAddresses = /* @__PURE__ */ __name(async (config) => {
|
|
|
578
614
|
}, "getTransferAddresses");
|
|
579
615
|
|
|
580
616
|
// src/config/getXl1ChainId.ts
|
|
581
|
-
import { assertEx as
|
|
617
|
+
import { assertEx as assertEx14, isDefined as isDefined7 } from "@xylabs/sdk-js";
|
|
582
618
|
var getXl1ChainId = /* @__PURE__ */ __name((config) => {
|
|
583
619
|
const xl1ChainId = config.xl1ChainId;
|
|
584
620
|
if (isDefined7(xl1ChainId)) {
|
|
585
|
-
return
|
|
621
|
+
return assertEx14(asChainId(xl1ChainId), () => "Invalid xl1ChainId in bridge config");
|
|
586
622
|
}
|
|
587
|
-
return
|
|
623
|
+
return assertEx14(asChainId(config.chain.id), () => "Invalid chain.id in config");
|
|
588
624
|
}, "getXl1ChainId");
|
|
589
625
|
|
|
590
626
|
// src/config/getXl1TokenAddress.ts
|
|
@@ -650,7 +686,7 @@ var makeBridgeConfigRoute = /* @__PURE__ */ __name((config) => {
|
|
|
650
686
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.ts
|
|
651
687
|
import { requestHandlerValidator as requestHandlerValidator2 } from "@xylabs/express";
|
|
652
688
|
import { toAddress, toHex } from "@xylabs/sdk-js";
|
|
653
|
-
import { PayloadZodStrictOfSchema } from "@xyo-network/
|
|
689
|
+
import { PayloadZodStrictOfSchema } from "@xyo-network/sdk-js";
|
|
654
690
|
import { BridgeDestinationObservationFieldsZod, BridgeDestinationObservationSchema } from "@xyo-network/xl1-sdk";
|
|
655
691
|
import { z } from "zod";
|
|
656
692
|
|
|
@@ -710,17 +746,16 @@ var makeBridgeFromRemoteStatusRoute = /* @__PURE__ */ __name((config) => {
|
|
|
710
746
|
|
|
711
747
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemote.ts
|
|
712
748
|
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";
|
|
749
|
+
import { PayloadBuilder as PayloadBuilder11, PayloadZodLooseOfSchema, PayloadZodStrictOfSchema as PayloadZodStrictOfSchema2 } from "@xyo-network/sdk-js";
|
|
715
750
|
import { BridgeIntentFieldsZod, BridgeIntentSchema as BridgeIntentSchema2, BridgeSourceObservationFieldsZod, BridgeSourceObservationSchema, SignedTransactionBoundWitnessZod, TransferZod } from "@xyo-network/xl1-sdk";
|
|
716
751
|
import { z as z2 } from "zod";
|
|
717
752
|
|
|
718
753
|
// src/util/calculateBridgeFees.ts
|
|
719
|
-
import { hexToBigInt as
|
|
754
|
+
import { hexToBigInt as hexToBigInt5, toHex as toHex2 } from "@xylabs/sdk-js";
|
|
720
755
|
var calculateBridgeFees = /* @__PURE__ */ __name((srcAmount, feeStructure) => {
|
|
721
756
|
const { feeFixed, feeRateBasisPoints } = feeStructure;
|
|
722
|
-
const srcAmountBigInt =
|
|
723
|
-
const feeFixedBigInt =
|
|
757
|
+
const srcAmountBigInt = hexToBigInt5(srcAmount);
|
|
758
|
+
const feeFixedBigInt = hexToBigInt5(feeFixed);
|
|
724
759
|
const feeVariableBigInt = srcAmountBigInt * BigInt(feeRateBasisPoints) / 10000n;
|
|
725
760
|
const feeVariable = toHex2(feeVariableBigInt);
|
|
726
761
|
const feeTotalBigInt = feeFixedBigInt + feeVariableBigInt;
|
|
@@ -734,12 +769,12 @@ var calculateBridgeFees = /* @__PURE__ */ __name((srcAmount, feeStructure) => {
|
|
|
734
769
|
}, "calculateBridgeFees");
|
|
735
770
|
|
|
736
771
|
// src/util/createBridgeTransfer.ts
|
|
737
|
-
import { hexToBigInt as
|
|
772
|
+
import { hexToBigInt as hexToBigInt6 } from "@xylabs/sdk-js";
|
|
738
773
|
import { createTransferPayload } from "@xyo-network/xl1-sdk";
|
|
739
774
|
var createBridgeTransfer = /* @__PURE__ */ __name((sender, srcAmount, escrowAddress, feesAddress, context) => {
|
|
740
775
|
const { feeFixed, feeVariable } = context;
|
|
741
|
-
const escrowAmount =
|
|
742
|
-
const feesAmount =
|
|
776
|
+
const escrowAmount = hexToBigInt6(srcAmount);
|
|
777
|
+
const feesAmount = hexToBigInt6(feeFixed) + hexToBigInt6(feeVariable);
|
|
743
778
|
const transfers = escrowAddress === feesAddress ? {
|
|
744
779
|
[feesAddress]: escrowAmount + feesAmount
|
|
745
780
|
} : {
|
|
@@ -879,8 +914,8 @@ var makeBridgeToRemoteRoute = /* @__PURE__ */ __name((config) => {
|
|
|
879
914
|
|
|
880
915
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts
|
|
881
916
|
import { requestHandlerValidator as requestHandlerValidator4 } from "@xylabs/express";
|
|
882
|
-
import { assertEx as
|
|
883
|
-
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema3 } from "@xyo-network/
|
|
917
|
+
import { assertEx as assertEx15, toAddress as toAddress3 } from "@xylabs/sdk-js";
|
|
918
|
+
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema3 } from "@xyo-network/sdk-js";
|
|
884
919
|
import { BridgeIntentFieldsZod as BridgeIntentFieldsZod2, BridgeIntentSchema as BridgeIntentSchema3, buildUnsignedTransaction, toXL1BlockNumber, TransactionBoundWitnessZod, TransferZod as TransferZod2 } from "@xyo-network/xl1-sdk";
|
|
885
920
|
import { z as z3 } from "zod";
|
|
886
921
|
var BridgeToRemoteEstimateBodyZod = BridgeIntentFieldsZod2.pick({
|
|
@@ -910,7 +945,7 @@ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config, gateway) =
|
|
|
910
945
|
const { srcAddress, srcAmount, destAddress } = req.body;
|
|
911
946
|
const [bridgeIntent, transfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
|
|
912
947
|
const sender = toAddress3(srcAddress);
|
|
913
|
-
const viewer =
|
|
948
|
+
const viewer = assertEx15(gateway.connection.viewer, () => new Error("Viewer not available on gateway connection"));
|
|
914
949
|
const currentBlockNumber = await viewer.currentBlockNumber();
|
|
915
950
|
const nbf = toXL1BlockNumber(currentBlockNumber, true);
|
|
916
951
|
const exp = toXL1BlockNumber(currentBlockNumber + 1e3, true);
|
|
@@ -931,7 +966,7 @@ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config, gateway) =
|
|
|
931
966
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts
|
|
932
967
|
import { requestHandlerValidator as requestHandlerValidator5 } from "@xylabs/express";
|
|
933
968
|
import { asAddress as asAddress5, asHex as asHex3, toHex as toHex3 } from "@xylabs/sdk-js";
|
|
934
|
-
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema4 } from "@xyo-network/
|
|
969
|
+
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema4 } from "@xyo-network/sdk-js";
|
|
935
970
|
import { BridgeDestinationObservationFieldsZod as BridgeDestinationObservationFieldsZod2, BridgeDestinationObservationSchema as BridgeDestinationObservationSchema2, BridgeIntentFieldsZod as BridgeIntentFieldsZod3, BridgeIntentSchema as BridgeIntentSchema4, BridgeSourceObservationFieldsZod as BridgeSourceObservationFieldsZod2, BridgeSourceObservationSchema as BridgeSourceObservationSchema2 } from "@xyo-network/xl1-sdk";
|
|
936
971
|
import { z as z4 } from "zod";
|
|
937
972
|
var BridgeToRemoteStatusResponseZod = z4.union([
|
|
@@ -1064,7 +1099,7 @@ var getApp = /* @__PURE__ */ __name((config, gateway) => {
|
|
|
1064
1099
|
}, "getApp");
|
|
1065
1100
|
|
|
1066
1101
|
// src/services/getServices.ts
|
|
1067
|
-
import { assertEx as
|
|
1102
|
+
import { assertEx as assertEx16, isDefined as isDefined10 } from "@xylabs/sdk-js";
|
|
1068
1103
|
import { initEvmProvider } from "@xyo-network/chain-orchestration";
|
|
1069
1104
|
import { BridgeableToken__factory, LiquidityPoolBridge__factory } from "@xyo-network/typechain";
|
|
1070
1105
|
import { HDWallet as HDWallet2 } from "@xyo-network/wallet";
|
|
@@ -1114,7 +1149,7 @@ var getServices = /* @__PURE__ */ __name(async (context, gateway) => {
|
|
|
1114
1149
|
const bridgeableToken = BridgeableToken__factory.connect(getAddress2(remoteTokenAddress), wallet);
|
|
1115
1150
|
const bridge = LiquidityPoolBridge__factory.connect(getAddress2(remoteBridgeContractAddress), wallet);
|
|
1116
1151
|
const bridgeOwner = await bridge.owner();
|
|
1117
|
-
|
|
1152
|
+
assertEx16(bridgeOwner.toLowerCase() === wallet.address.toLowerCase(), () => "Wallet is not the owner of the bridge contract");
|
|
1118
1153
|
return {
|
|
1119
1154
|
account,
|
|
1120
1155
|
bridge,
|