@xyo-network/chain-bridge 1.20.8 → 1.20.9
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 +144 -72
- package/dist/node/index.mjs.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/getRouteDefinitions.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.d.ts.map +1 -1
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.d.ts +77 -0
- package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.d.ts.map +1 -0
- package/dist/node/server/routes/bridge/routeDefinitions/routes/index.d.ts +1 -0
- package/dist/node/server/routes/bridge/routeDefinitions/routes/index.d.ts.map +1 -1
- package/dist/node/util/calculateMaxBridgeAmount.d.ts +11 -0
- package/dist/node/util/calculateMaxBridgeAmount.d.ts.map +1 -0
- package/dist/node/util/index.d.ts +1 -0
- package/dist/node/util/index.d.ts.map +1 -1
- package/dist/node/validation/validateBridgeEstimateExact.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/server/routes/bridge/routeDefinitions/getRouteDefinitions.ts +2 -1
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts +11 -2
- package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.ts +64 -0
- package/src/server/routes/bridge/routeDefinitions/routes/index.ts +1 -0
- package/src/util/calculateMaxBridgeAmount.ts +22 -0
- package/src/util/index.ts +1 -0
- package/src/validation/validateBridgeEstimateExact.ts +6 -1
package/dist/node/index.mjs
CHANGED
|
@@ -102,53 +102,16 @@ var EthTransactionMonitor = {
|
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
// src/queue/workers/EthTransactionPreparation.ts
|
|
105
|
-
import { assertEx as assertEx11, hexToBigInt as
|
|
105
|
+
import { assertEx as assertEx11, hexToBigInt as hexToBigInt8 } from "@xylabs/sdk-js";
|
|
106
106
|
import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/sdk-js";
|
|
107
107
|
import { isBridgeIntent as isBridgeIntent3 } from "@xyo-network/xl1-sdk";
|
|
108
108
|
import { Worker as Worker2 } from "bullmq";
|
|
109
109
|
import { getAddress } from "ethers";
|
|
110
110
|
|
|
111
111
|
// src/validation/validateBridgeEstimateExact.ts
|
|
112
|
-
import { isUndefined as isUndefined2 } from "@xylabs/sdk-js";
|
|
112
|
+
import { hexToBigInt as hexToBigInt4, isUndefined as isUndefined2 } from "@xylabs/sdk-js";
|
|
113
113
|
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk-js";
|
|
114
114
|
|
|
115
|
-
// src/util/calculateBridgeFees.ts
|
|
116
|
-
import { hexToBigInt, toHex } from "@xylabs/sdk-js";
|
|
117
|
-
var calculateBridgeFees = /* @__PURE__ */ __name((srcAmount, feeStructure) => {
|
|
118
|
-
const { feeFixed, feeRateBasisPoints } = feeStructure;
|
|
119
|
-
const srcAmountBigInt = hexToBigInt(srcAmount);
|
|
120
|
-
const feeVariableBigInt = srcAmountBigInt * BigInt(feeRateBasisPoints) / 10000n;
|
|
121
|
-
const feeVariable = toHex(feeVariableBigInt);
|
|
122
|
-
return {
|
|
123
|
-
feeFixed,
|
|
124
|
-
feeVariable,
|
|
125
|
-
srcAmount
|
|
126
|
-
};
|
|
127
|
-
}, "calculateBridgeFees");
|
|
128
|
-
|
|
129
|
-
// src/util/createBridgeTransfer.ts
|
|
130
|
-
import { hexToBigInt as hexToBigInt2 } from "@xylabs/sdk-js";
|
|
131
|
-
import { createTransferPayload } from "@xyo-network/xl1-sdk";
|
|
132
|
-
var createBridgeTransfer = /* @__PURE__ */ __name((sender, srcAmount, escrowAddress, feesAddress, context) => {
|
|
133
|
-
const { feeFixed, feeVariable } = context;
|
|
134
|
-
const escrowAmount = hexToBigInt2(srcAmount);
|
|
135
|
-
const feesAmount = hexToBigInt2(feeFixed) + hexToBigInt2(feeVariable);
|
|
136
|
-
const transfers = escrowAddress === feesAddress ? {
|
|
137
|
-
[feesAddress]: escrowAmount + feesAmount
|
|
138
|
-
} : {
|
|
139
|
-
[escrowAddress]: escrowAmount,
|
|
140
|
-
[feesAddress]: feesAmount
|
|
141
|
-
};
|
|
142
|
-
const transfer = createTransferPayload(sender, transfers, context);
|
|
143
|
-
return transfer;
|
|
144
|
-
}, "createBridgeTransfer");
|
|
145
|
-
|
|
146
|
-
// src/util/generateBridgeEstimate.ts
|
|
147
|
-
import { toAddress } from "@xylabs/sdk-js";
|
|
148
|
-
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
|
|
149
|
-
import { BridgeIntentSchema } from "@xyo-network/xl1-sdk";
|
|
150
|
-
import { v4 } from "uuid";
|
|
151
|
-
|
|
152
115
|
// src/config/asChainId.ts
|
|
153
116
|
import { asHex } from "@xylabs/sdk-js";
|
|
154
117
|
var asChainId = /* @__PURE__ */ __name((value) => {
|
|
@@ -288,7 +251,53 @@ var getBridgeSettings = /* @__PURE__ */ __name(async (config) => {
|
|
|
288
251
|
};
|
|
289
252
|
}, "getBridgeSettings");
|
|
290
253
|
|
|
254
|
+
// src/util/calculateBridgeFees.ts
|
|
255
|
+
import { hexToBigInt, toHex } from "@xylabs/sdk-js";
|
|
256
|
+
var calculateBridgeFees = /* @__PURE__ */ __name((srcAmount, feeStructure) => {
|
|
257
|
+
const { feeFixed, feeRateBasisPoints } = feeStructure;
|
|
258
|
+
const srcAmountBigInt = hexToBigInt(srcAmount);
|
|
259
|
+
const feeVariableBigInt = srcAmountBigInt * BigInt(feeRateBasisPoints) / 10000n;
|
|
260
|
+
const feeVariable = toHex(feeVariableBigInt);
|
|
261
|
+
return {
|
|
262
|
+
feeFixed,
|
|
263
|
+
feeVariable,
|
|
264
|
+
srcAmount
|
|
265
|
+
};
|
|
266
|
+
}, "calculateBridgeFees");
|
|
267
|
+
|
|
268
|
+
// src/util/calculateMaxBridgeAmount.ts
|
|
269
|
+
import { hexToBigInt as hexToBigInt2, toHex as toHex2 } from "@xylabs/sdk-js";
|
|
270
|
+
var calculateMaxBridgeAmount = /* @__PURE__ */ __name((balance, feeStructure) => {
|
|
271
|
+
const { feeFixed, feeRateBasisPoints } = feeStructure;
|
|
272
|
+
const balanceBigInt = hexToBigInt2(balance);
|
|
273
|
+
const feeFixedBigInt = hexToBigInt2(feeFixed);
|
|
274
|
+
if (balanceBigInt <= feeFixedBigInt) return toHex2(0n);
|
|
275
|
+
const maxAmount = (balanceBigInt - feeFixedBigInt) * 10000n / (10000n + BigInt(feeRateBasisPoints));
|
|
276
|
+
return toHex2(maxAmount);
|
|
277
|
+
}, "calculateMaxBridgeAmount");
|
|
278
|
+
|
|
279
|
+
// src/util/createBridgeTransfer.ts
|
|
280
|
+
import { hexToBigInt as hexToBigInt3 } from "@xylabs/sdk-js";
|
|
281
|
+
import { createTransferPayload } from "@xyo-network/xl1-sdk";
|
|
282
|
+
var createBridgeTransfer = /* @__PURE__ */ __name((sender, srcAmount, escrowAddress, feesAddress, context) => {
|
|
283
|
+
const { feeFixed, feeVariable } = context;
|
|
284
|
+
const escrowAmount = hexToBigInt3(srcAmount);
|
|
285
|
+
const feesAmount = hexToBigInt3(feeFixed) + hexToBigInt3(feeVariable);
|
|
286
|
+
const transfers = escrowAddress === feesAddress ? {
|
|
287
|
+
[feesAddress]: escrowAmount + feesAmount
|
|
288
|
+
} : {
|
|
289
|
+
[escrowAddress]: escrowAmount,
|
|
290
|
+
[feesAddress]: feesAmount
|
|
291
|
+
};
|
|
292
|
+
const transfer = createTransferPayload(sender, transfers, context);
|
|
293
|
+
return transfer;
|
|
294
|
+
}, "createBridgeTransfer");
|
|
295
|
+
|
|
291
296
|
// src/util/generateBridgeEstimate.ts
|
|
297
|
+
import { toAddress } from "@xylabs/sdk-js";
|
|
298
|
+
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
|
|
299
|
+
import { BridgeIntentSchema } from "@xyo-network/xl1-sdk";
|
|
300
|
+
import { v4 } from "uuid";
|
|
292
301
|
var generateBridgeEstimate = /* @__PURE__ */ __name(async (srcAddress, srcAmount, destAddress, config, nonceOverride) => {
|
|
293
302
|
const { escrowAddress, feeFixed, feeRateBasisPoints, feesAddress, remoteChainId, remoteTokenAddress, xl1ChainId, xl1TokenAddress } = await getBridgeSettings(config);
|
|
294
303
|
const sender = toAddress(srcAddress);
|
|
@@ -323,6 +332,7 @@ var generateBridgeEstimate = /* @__PURE__ */ __name(async (srcAddress, srcAmount
|
|
|
323
332
|
// src/validation/validateBridgeEstimateExact.ts
|
|
324
333
|
var validateBridgeEstimateExact = /* @__PURE__ */ __name(async (intent, transfer, config) => {
|
|
325
334
|
const { srcAddress, srcAmount, destAddress } = intent;
|
|
335
|
+
if (hexToBigInt4(srcAmount) > hexToBigInt4(getMaxBridgeAmount(config))) return false;
|
|
326
336
|
const [calculatedIntent, calculatedTransfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
|
|
327
337
|
if (isUndefined2(calculatedIntent) || isUndefined2(calculatedTransfer)) return false;
|
|
328
338
|
const { nonce: expectedIntentNonce, ...expectedIntentStatic } = calculatedIntent;
|
|
@@ -361,7 +371,7 @@ var validateBridgeTransaction = /* @__PURE__ */ __name(async (signedTxBw, intent
|
|
|
361
371
|
}, "validateBridgeTransaction");
|
|
362
372
|
|
|
363
373
|
// src/validation/validateSufficientLiquiditySourceAllowance.ts
|
|
364
|
-
import { assertEx as assertEx7, hexToBigInt as
|
|
374
|
+
import { assertEx as assertEx7, hexToBigInt as hexToBigInt5 } from "@xylabs/sdk-js";
|
|
365
375
|
import { isBridgeIntent } from "@xyo-network/xl1-sdk";
|
|
366
376
|
var validateSufficientLiquiditySourceAllowance = /* @__PURE__ */ __name(async (tx, offChainPayloads, bridgeableToken, bridge, logger) => {
|
|
367
377
|
const allPayloads = [
|
|
@@ -369,7 +379,7 @@ var validateSufficientLiquiditySourceAllowance = /* @__PURE__ */ __name(async (t
|
|
|
369
379
|
...offChainPayloads
|
|
370
380
|
];
|
|
371
381
|
const bridgeIntent = assertEx7(allPayloads.find(isBridgeIntent), () => "No bridge intent found");
|
|
372
|
-
const amount =
|
|
382
|
+
const amount = hexToBigInt5(bridgeIntent.destAmount);
|
|
373
383
|
const liquiditySourceAddress = await bridge.liquiditySource();
|
|
374
384
|
const bridgeAddress = await bridge.getAddress();
|
|
375
385
|
const remainingAllowance = await bridgeableToken.allowance(liquiditySourceAddress, bridgeAddress);
|
|
@@ -378,7 +388,7 @@ var validateSufficientLiquiditySourceAllowance = /* @__PURE__ */ __name(async (t
|
|
|
378
388
|
}, "validateSufficientLiquiditySourceAllowance");
|
|
379
389
|
|
|
380
390
|
// src/validation/validateSufficientLiquiditySourceBalance.ts
|
|
381
|
-
import { assertEx as assertEx8, hexToBigInt as
|
|
391
|
+
import { assertEx as assertEx8, hexToBigInt as hexToBigInt6 } from "@xylabs/sdk-js";
|
|
382
392
|
import { isBridgeIntent as isBridgeIntent2 } from "@xyo-network/xl1-sdk";
|
|
383
393
|
var validateSufficientLiquiditySourceBalance = /* @__PURE__ */ __name(async (tx, offChainPayloads, bridgeableToken, bridge, logger) => {
|
|
384
394
|
const allPayloads = [
|
|
@@ -386,7 +396,7 @@ var validateSufficientLiquiditySourceBalance = /* @__PURE__ */ __name(async (tx,
|
|
|
386
396
|
...offChainPayloads
|
|
387
397
|
];
|
|
388
398
|
const bridgeIntent = assertEx8(allPayloads.find(isBridgeIntent2), () => "No bridge intent found");
|
|
389
|
-
const amount =
|
|
399
|
+
const amount = hexToBigInt6(bridgeIntent.destAmount);
|
|
390
400
|
const liquiditySourceAddress = await bridge.liquiditySource();
|
|
391
401
|
const balance = await bridgeableToken.balanceOf(liquiditySourceAddress);
|
|
392
402
|
await logger?.log(`Remaining balance: ${balance.toString()}`);
|
|
@@ -418,13 +428,13 @@ var validateSufficientRunnerEthBalanceForGas = /* @__PURE__ */ __name(async (pre
|
|
|
418
428
|
}, "validateSufficientRunnerEthBalanceForGas");
|
|
419
429
|
|
|
420
430
|
// src/validation/validateSufficientXL1SourceAddressBalance.ts
|
|
421
|
-
import { asAddress as asAddress5, assertEx as assertEx10, hexToBigInt as
|
|
431
|
+
import { asAddress as asAddress5, assertEx as assertEx10, hexToBigInt as hexToBigInt7 } from "@xylabs/sdk-js";
|
|
422
432
|
var validateSufficientXL1SourceAddressBalance = /* @__PURE__ */ __name(async (bridgeIntent, gateway, config, logger) => {
|
|
423
433
|
const viewer = assertEx10(gateway.connection.viewer, () => "Gateway connection does not have a viewer");
|
|
424
434
|
const { srcAddress, srcAmount, destAddress } = bridgeIntent;
|
|
425
435
|
const srcAddressBranded = asAddress5(srcAddress, () => `Invalid source address in bridge intent: ${srcAddress}`);
|
|
426
436
|
const [_, calculatedTransfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
|
|
427
|
-
const totalAmount = Object.values(calculatedTransfer.transfers).reduce((acc, transfer) => acc +
|
|
437
|
+
const totalAmount = Object.values(calculatedTransfer.transfers).reduce((acc, transfer) => acc + hexToBigInt7(transfer), 0n);
|
|
428
438
|
const accountBalance = await viewer.account.balance.accountBalance(srcAddressBranded);
|
|
429
439
|
await logger?.log(`Account balance for ${srcAddressBranded}: ${accountBalance.toString()}`);
|
|
430
440
|
return accountBalance >= totalAmount;
|
|
@@ -458,10 +468,10 @@ var createWorker2 = /* @__PURE__ */ __name((connection2, telemetry2, services) =
|
|
|
458
468
|
...offChainPayloads
|
|
459
469
|
];
|
|
460
470
|
const bridgeIntent = assertEx11(allPayloads.find(isBridgeIntent3), () => "No bridge intent found");
|
|
461
|
-
const amount =
|
|
471
|
+
const amount = hexToBigInt8(bridgeIntent.destAmount);
|
|
462
472
|
const srcAddress = getAddress(bridgeIntent.srcAddress);
|
|
463
473
|
const destAddress = getAddress(bridgeIntent.destAddress);
|
|
464
|
-
const nonce =
|
|
474
|
+
const nonce = hexToBigInt8(await PayloadBuilder5.hash(tx[0]));
|
|
465
475
|
const preparedTx = await bridge.getFunction("bridgeFromRemote").populateTransaction(srcAddress, destAddress, amount, nonce);
|
|
466
476
|
await job.log(`[${hash}] built ETH transaction`);
|
|
467
477
|
await job.log(`[${hash}] validating tx runner has sufficient ETH for gas`);
|
|
@@ -500,7 +510,7 @@ import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/sdk-js";
|
|
|
500
510
|
import { Worker as Worker3 } from "bullmq";
|
|
501
511
|
|
|
502
512
|
// src/queue/workers/util/submitEthTransaction.ts
|
|
503
|
-
import { assertEx as assertEx12, hexToBigInt as
|
|
513
|
+
import { assertEx as assertEx12, hexToBigInt as hexToBigInt9, toEthAddress } from "@xylabs/sdk-js";
|
|
504
514
|
import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/sdk-js";
|
|
505
515
|
import { isBridgeIntent as isBridgeIntent4 } from "@xyo-network/xl1-sdk";
|
|
506
516
|
var submitEthTransaction = /* @__PURE__ */ __name(async (tx, offChainPayloads, bridge, wallet) => {
|
|
@@ -512,8 +522,8 @@ var submitEthTransaction = /* @__PURE__ */ __name(async (tx, offChainPayloads, b
|
|
|
512
522
|
const bridgeIntent = assertEx12(allPayloads.find(isBridgeIntent4), () => "No bridge intent found");
|
|
513
523
|
const srcAddress = toEthAddress(bridgeIntent.srcAddress);
|
|
514
524
|
const destAddress = toEthAddress(bridgeIntent.destAddress);
|
|
515
|
-
const amount =
|
|
516
|
-
const nonce =
|
|
525
|
+
const amount = hexToBigInt9(bridgeIntent.destAmount);
|
|
526
|
+
const nonce = hexToBigInt9(await PayloadBuilder6.hash(xl1Transaction));
|
|
517
527
|
const bridgeTx = await bridge.connect(wallet).bridgeFromRemote(srcAddress, destAddress, amount, nonce);
|
|
518
528
|
const receipt = await bridgeTx.wait(1);
|
|
519
529
|
return receipt?.hash;
|
|
@@ -1135,7 +1145,7 @@ var makeBridgeConfigRoute = /* @__PURE__ */ __name((config) => {
|
|
|
1135
1145
|
|
|
1136
1146
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.ts
|
|
1137
1147
|
import { requestHandlerValidator as requestHandlerValidator2 } from "@xylabs/express";
|
|
1138
|
-
import { toAddress as toAddress2, toHex as
|
|
1148
|
+
import { toAddress as toAddress2, toHex as toHex3 } from "@xylabs/sdk-js";
|
|
1139
1149
|
import { PayloadZodStrictOfSchema } from "@xyo-network/sdk-js";
|
|
1140
1150
|
import { BridgeDestinationObservationFieldsZod, BridgeDestinationObservationSchema } from "@xyo-network/xl1-sdk";
|
|
1141
1151
|
import { z } from "zod";
|
|
@@ -1181,13 +1191,13 @@ var makeBridgeFromRemoteStatusRoute = /* @__PURE__ */ __name((config) => {
|
|
|
1181
1191
|
schema: BridgeDestinationObservationSchema,
|
|
1182
1192
|
dest: xl1ChainId,
|
|
1183
1193
|
destAddress: toAddress2("0xabc"),
|
|
1184
|
-
destAmount:
|
|
1194
|
+
destAmount: toHex3("0x100"),
|
|
1185
1195
|
destToken: xl1TokenAddress,
|
|
1186
1196
|
src: remoteChainId,
|
|
1187
1197
|
srcAddress: toAddress2("0x123"),
|
|
1188
|
-
srcAmount:
|
|
1198
|
+
srcAmount: toHex3("0x200"),
|
|
1189
1199
|
srcToken: remoteTokenAddress,
|
|
1190
|
-
destConfirmation:
|
|
1200
|
+
destConfirmation: toHex3("0x9999")
|
|
1191
1201
|
};
|
|
1192
1202
|
res.json(observation);
|
|
1193
1203
|
})
|
|
@@ -1268,7 +1278,7 @@ var makeBridgeToRemoteRoute = /* @__PURE__ */ __name((config) => {
|
|
|
1268
1278
|
|
|
1269
1279
|
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts
|
|
1270
1280
|
import { requestHandlerValidator as requestHandlerValidator4 } from "@xylabs/express";
|
|
1271
|
-
import { assertEx as assertEx19, toAddress as toAddress3 } from "@xylabs/sdk-js";
|
|
1281
|
+
import { assertEx as assertEx19, hexToBigInt as hexToBigInt10, toAddress as toAddress3 } from "@xylabs/sdk-js";
|
|
1272
1282
|
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema3 } from "@xyo-network/sdk-js";
|
|
1273
1283
|
import { BridgeIntentFieldsZod as BridgeIntentFieldsZod2, BridgeIntentSchema as BridgeIntentSchema4, buildUnsignedTransaction, toXL1BlockNumber, TransactionBoundWitnessZod, TransferZod as TransferZod2 } from "@xyo-network/xl1-sdk";
|
|
1274
1284
|
import { z as z3 } from "zod";
|
|
@@ -1297,6 +1307,11 @@ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config, gateway) =
|
|
|
1297
1307
|
handlers: validateRequest2(async (req, res) => {
|
|
1298
1308
|
const xl1ChainId = getXl1ChainId(config);
|
|
1299
1309
|
const { srcAddress, srcAmount, destAddress } = req.body;
|
|
1310
|
+
const { maxBridgeAmount } = await getBridgeSettings(config);
|
|
1311
|
+
if (hexToBigInt10(srcAmount) > hexToBigInt10(maxBridgeAmount)) {
|
|
1312
|
+
res.status(400).send();
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1300
1315
|
const [bridgeIntent, transfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
|
|
1301
1316
|
const sender = toAddress3(srcAddress);
|
|
1302
1317
|
const viewer = assertEx19(gateway.connection.viewer, () => new Error("Viewer not available on gateway connection"));
|
|
@@ -1317,36 +1332,92 @@ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config, gateway) =
|
|
|
1317
1332
|
};
|
|
1318
1333
|
}, "makeBridgeToRemoteEstimateRoute");
|
|
1319
1334
|
|
|
1320
|
-
// src/server/routes/bridge/routeDefinitions/routes/
|
|
1335
|
+
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.ts
|
|
1321
1336
|
import { requestHandlerValidator as requestHandlerValidator5 } from "@xylabs/express";
|
|
1322
|
-
import {
|
|
1323
|
-
import {
|
|
1324
|
-
import {
|
|
1337
|
+
import { assertEx as assertEx20, hexToBigInt as hexToBigInt11, toAddress as toAddress4, toHex as toHex4 } from "@xylabs/sdk-js";
|
|
1338
|
+
import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema4 } from "@xyo-network/sdk-js";
|
|
1339
|
+
import { BridgeIntentFieldsZod as BridgeIntentFieldsZod3, BridgeIntentSchema as BridgeIntentSchema5, buildUnsignedTransaction as buildUnsignedTransaction2, toXL1BlockNumber as toXL1BlockNumber2, TransactionBoundWitnessZod as TransactionBoundWitnessZod2, TransferZod as TransferZod3 } from "@xyo-network/xl1-sdk";
|
|
1325
1340
|
import { z as z4 } from "zod";
|
|
1326
|
-
var
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1341
|
+
var BridgeToRemoteMaxEstimateBodyZod = BridgeIntentFieldsZod3.pick({
|
|
1342
|
+
destAddress: true,
|
|
1343
|
+
srcAddress: true,
|
|
1344
|
+
srcAmount: true
|
|
1345
|
+
});
|
|
1346
|
+
var BridgeToRemoteMaxEstimateResponseZod = z4.tuple([
|
|
1347
|
+
TransactionBoundWitnessZod2,
|
|
1348
|
+
PayloadZodStrictOfSchema4(BridgeIntentSchema5).extend(BridgeIntentFieldsZod3.shape),
|
|
1349
|
+
TransferZod3
|
|
1350
|
+
]);
|
|
1351
|
+
var makeBridgeToRemoteMaxEstimateRoute = /* @__PURE__ */ __name((config, gateway) => {
|
|
1352
|
+
const params = z4.object({
|
|
1353
|
+
chainId: getRemoteChainIdZod(config)
|
|
1354
|
+
});
|
|
1355
|
+
const validateRequest2 = requestHandlerValidator5({
|
|
1356
|
+
params,
|
|
1357
|
+
body: BridgeToRemoteMaxEstimateBodyZod,
|
|
1358
|
+
response: BridgeToRemoteMaxEstimateResponseZod
|
|
1359
|
+
});
|
|
1360
|
+
return {
|
|
1361
|
+
method: "post",
|
|
1362
|
+
path: "/bridge/chains/:chainId/bridgeToRemote/maxEstimate",
|
|
1363
|
+
handlers: validateRequest2(async (req, res) => {
|
|
1364
|
+
const { feeFixed, feeRateBasisPoints, maxBridgeAmount: configMax, xl1ChainId } = await getBridgeSettings(config);
|
|
1365
|
+
const { srcAddress, srcAmount: balance, destAddress } = req.body;
|
|
1366
|
+
const balanceMax = calculateMaxBridgeAmount(balance, {
|
|
1367
|
+
feeFixed,
|
|
1368
|
+
feeRateBasisPoints
|
|
1369
|
+
});
|
|
1370
|
+
const maxBridgeAmount = toHex4(hexToBigInt11(balanceMax) < hexToBigInt11(configMax) ? balanceMax : configMax);
|
|
1371
|
+
const [bridgeIntent, transfer] = await generateBridgeEstimate(srcAddress, maxBridgeAmount, destAddress, config);
|
|
1372
|
+
const sender = toAddress4(srcAddress);
|
|
1373
|
+
const viewer = assertEx20(gateway.connection.viewer, () => new Error("Viewer not available on gateway connection"));
|
|
1374
|
+
const currentBlockNumber = await viewer.currentBlockNumber();
|
|
1375
|
+
const nbf = toXL1BlockNumber2(currentBlockNumber, true);
|
|
1376
|
+
const exp = toXL1BlockNumber2(currentBlockNumber + 1e3, true);
|
|
1377
|
+
const [txBw] = await buildUnsignedTransaction2(xl1ChainId, [
|
|
1378
|
+
transfer
|
|
1379
|
+
], [
|
|
1380
|
+
bridgeIntent
|
|
1381
|
+
], nbf, exp, sender);
|
|
1382
|
+
res.json([
|
|
1383
|
+
txBw,
|
|
1384
|
+
bridgeIntent,
|
|
1385
|
+
transfer
|
|
1386
|
+
]);
|
|
1387
|
+
})
|
|
1388
|
+
};
|
|
1389
|
+
}, "makeBridgeToRemoteMaxEstimateRoute");
|
|
1390
|
+
|
|
1391
|
+
// src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts
|
|
1392
|
+
import { requestHandlerValidator as requestHandlerValidator6 } from "@xylabs/express";
|
|
1393
|
+
import { asHex as asHex3, isDefined as isDefined13 } from "@xylabs/sdk-js";
|
|
1394
|
+
import { PayloadBuilder as PayloadBuilder15, PayloadZodStrictOfSchema as PayloadZodStrictOfSchema5 } from "@xyo-network/sdk-js";
|
|
1395
|
+
import { asBridgeIntent, BridgeDestinationObservationFieldsZod as BridgeDestinationObservationFieldsZod2, BridgeDestinationObservationSchema as BridgeDestinationObservationSchema2, BridgeIntentFieldsZod as BridgeIntentFieldsZod4, BridgeIntentSchema as BridgeIntentSchema6, BridgeSourceObservationFieldsZod as BridgeSourceObservationFieldsZod2, BridgeSourceObservationSchema as BridgeSourceObservationSchema2, isBridgeIntent as isBridgeIntent5 } from "@xyo-network/xl1-sdk";
|
|
1396
|
+
import { z as z5 } from "zod";
|
|
1397
|
+
var BridgeIntentResponseZod = PayloadZodStrictOfSchema5(BridgeIntentSchema6).extend(BridgeIntentFieldsZod4.shape);
|
|
1398
|
+
var BridgeSourceResponseZod = PayloadZodStrictOfSchema5(BridgeSourceObservationSchema2).extend(BridgeSourceObservationFieldsZod2.shape);
|
|
1399
|
+
var BridgeDestinationResponseZod = PayloadZodStrictOfSchema5(BridgeDestinationObservationSchema2).extend(BridgeDestinationObservationFieldsZod2.shape);
|
|
1400
|
+
var BridgeToRemoteStatusResponseZod = z5.union([
|
|
1401
|
+
z5.tuple([]),
|
|
1402
|
+
z5.tuple([
|
|
1332
1403
|
BridgeIntentResponseZod
|
|
1333
1404
|
]),
|
|
1334
|
-
|
|
1405
|
+
z5.tuple([
|
|
1335
1406
|
BridgeIntentResponseZod,
|
|
1336
1407
|
BridgeSourceResponseZod
|
|
1337
1408
|
]),
|
|
1338
|
-
|
|
1409
|
+
z5.tuple([
|
|
1339
1410
|
BridgeIntentResponseZod,
|
|
1340
1411
|
BridgeSourceResponseZod,
|
|
1341
1412
|
BridgeDestinationResponseZod
|
|
1342
1413
|
])
|
|
1343
1414
|
]);
|
|
1344
1415
|
var makeBridgeToRemoteStatusRoute = /* @__PURE__ */ __name((config) => {
|
|
1345
|
-
const params =
|
|
1416
|
+
const params = z5.object({
|
|
1346
1417
|
chainId: getRemoteChainIdZod(config),
|
|
1347
|
-
nonce:
|
|
1418
|
+
nonce: z5.string().nonempty()
|
|
1348
1419
|
});
|
|
1349
|
-
const validateRequest2 =
|
|
1420
|
+
const validateRequest2 = requestHandlerValidator6({
|
|
1350
1421
|
params,
|
|
1351
1422
|
response: BridgeToRemoteStatusResponseZod
|
|
1352
1423
|
});
|
|
@@ -1407,6 +1478,7 @@ var getRouteDefinitions = /* @__PURE__ */ __name((config, gateway) => {
|
|
|
1407
1478
|
return [
|
|
1408
1479
|
makeBridgeConfigRoute(config),
|
|
1409
1480
|
makeBridgeToRemoteEstimateRoute(config, gateway),
|
|
1481
|
+
makeBridgeToRemoteMaxEstimateRoute(config, gateway),
|
|
1410
1482
|
makeBridgeToRemoteRoute(config),
|
|
1411
1483
|
makeBridgeToRemoteStatusRoute(config),
|
|
1412
1484
|
makeBridgeFromRemoteStatusRoute(config)
|
|
@@ -1438,7 +1510,7 @@ var getApp = /* @__PURE__ */ __name((config, gateway) => {
|
|
|
1438
1510
|
}, "getApp");
|
|
1439
1511
|
|
|
1440
1512
|
// src/services/getServices.ts
|
|
1441
|
-
import { assertEx as
|
|
1513
|
+
import { assertEx as assertEx21, isDefined as isDefined14 } from "@xylabs/sdk-js";
|
|
1442
1514
|
import { initEvmProvider } from "@xyo-network/chain-orchestration";
|
|
1443
1515
|
import { HDWallet as HDWallet2 } from "@xyo-network/sdk-js";
|
|
1444
1516
|
import { BridgeableToken__factory, LiquidityPoolBridge__factory } from "@xyo-network/typechain";
|
|
@@ -1488,7 +1560,7 @@ var getServices = /* @__PURE__ */ __name(async (context, gateway) => {
|
|
|
1488
1560
|
const bridgeableToken = BridgeableToken__factory.connect(getAddress2(remoteTokenAddress), wallet);
|
|
1489
1561
|
const bridge = LiquidityPoolBridge__factory.connect(getAddress2(remoteBridgeContractAddress), wallet);
|
|
1490
1562
|
const bridgeOwner = await bridge.owner();
|
|
1491
|
-
|
|
1563
|
+
assertEx21(bridgeOwner.toLowerCase() === wallet.address.toLowerCase(), () => "Wallet is not the owner of the bridge contract");
|
|
1492
1564
|
return {
|
|
1493
1565
|
account,
|
|
1494
1566
|
bridge,
|