@xyo-network/chain-bridge 1.20.5 → 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.
Files changed (28) hide show
  1. package/dist/node/index.mjs +147 -90
  2. package/dist/node/index.mjs.map +1 -1
  3. package/dist/node/queue/workers/EthTransactionMonitor.d.ts.map +1 -1
  4. package/dist/node/queue/workers/Xl1TransactionSubmissionStorage.d.ts.map +1 -1
  5. package/dist/node/server/app.d.ts.map +1 -1
  6. package/dist/node/server/routes/bridge/routeDefinitions/getRouteDefinitions.d.ts.map +1 -1
  7. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.d.ts.map +1 -1
  8. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.d.ts +77 -0
  9. package/dist/node/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.d.ts.map +1 -0
  10. package/dist/node/server/routes/bridge/routeDefinitions/routes/index.d.ts +1 -0
  11. package/dist/node/server/routes/bridge/routeDefinitions/routes/index.d.ts.map +1 -1
  12. package/dist/node/util/calculateMaxBridgeAmount.d.ts +11 -0
  13. package/dist/node/util/calculateMaxBridgeAmount.d.ts.map +1 -0
  14. package/dist/node/util/index.d.ts +1 -0
  15. package/dist/node/util/index.d.ts.map +1 -1
  16. package/dist/node/validation/validateBridgeEstimateExact.d.ts.map +1 -1
  17. package/package.json +32 -49
  18. package/src/queue/workers/EthTransactionMonitor.ts +0 -1
  19. package/src/queue/workers/Xl1TransactionSubmissionStorage.ts +0 -1
  20. package/src/server/app.ts +3 -15
  21. package/src/server/routes/bridge/routeDefinitions/getRouteDefinitions.ts +2 -1
  22. package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts +11 -2
  23. package/src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.ts +64 -0
  24. package/src/server/routes/bridge/routeDefinitions/routes/index.ts +1 -0
  25. package/src/util/calculateBridgeFees.ts +4 -4
  26. package/src/util/calculateMaxBridgeAmount.ts +22 -0
  27. package/src/util/index.ts +1 -0
  28. package/src/validation/validateBridgeEstimateExact.ts +6 -1
@@ -7,9 +7,8 @@ import { asBridgeConfigContext } from "@xyo-network/chain-orchestration";
7
7
  import { ActorV3, XyoGatewayRunnerMoniker } from "@xyo-network/xl1-sdk";
8
8
 
9
9
  // src/server/app.ts
10
- import { customPoweredByHeader, disableCaseSensitiveRouting, disableExpressDefaultPoweredByHeader, getJsonBodyParser, getJsonBodyParserOptions, responseProfiler, standardErrors, standardResponses } from "@xylabs/express";
11
- import compression from "compression";
12
- import cors from "cors";
10
+ import { standardErrors } from "@xylabs/express";
11
+ import { sharedMiddleware } from "@xyo-network/chain-orchestration";
13
12
  import express from "express";
14
13
 
15
14
  // src/queue/connection.ts
@@ -103,57 +102,16 @@ var EthTransactionMonitor = {
103
102
  };
104
103
 
105
104
  // src/queue/workers/EthTransactionPreparation.ts
106
- import { assertEx as assertEx11, hexToBigInt as hexToBigInt6 } from "@xylabs/sdk-js";
105
+ import { assertEx as assertEx11, hexToBigInt as hexToBigInt8 } from "@xylabs/sdk-js";
107
106
  import { PayloadBuilder as PayloadBuilder5 } from "@xyo-network/sdk-js";
108
107
  import { isBridgeIntent as isBridgeIntent3 } from "@xyo-network/xl1-sdk";
109
108
  import { Worker as Worker2 } from "bullmq";
110
109
  import { getAddress } from "ethers";
111
110
 
112
111
  // src/validation/validateBridgeEstimateExact.ts
113
- import { isUndefined as isUndefined2 } from "@xylabs/sdk-js";
112
+ import { hexToBigInt as hexToBigInt4, isUndefined as isUndefined2 } from "@xylabs/sdk-js";
114
113
  import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk-js";
115
114
 
116
- // src/util/calculateBridgeFees.ts
117
- import { hexToBigInt, toHex } from "@xylabs/sdk-js";
118
- var calculateBridgeFees = /* @__PURE__ */ __name((srcAmount, feeStructure) => {
119
- const { feeFixed, feeRateBasisPoints } = feeStructure;
120
- const srcAmountBigInt = hexToBigInt(srcAmount);
121
- const feeFixedBigInt = hexToBigInt(feeFixed);
122
- const feeVariableBigInt = srcAmountBigInt * BigInt(feeRateBasisPoints) / 10000n;
123
- const feeVariable = toHex(feeVariableBigInt);
124
- const feeTotalBigInt = feeFixedBigInt + feeVariableBigInt;
125
- const destAmountBigInt = srcAmountBigInt > feeTotalBigInt ? srcAmountBigInt - feeTotalBigInt : 0n;
126
- const destAmount = toHex(destAmountBigInt);
127
- return {
128
- feeFixed,
129
- feeVariable,
130
- srcAmount
131
- };
132
- }, "calculateBridgeFees");
133
-
134
- // src/util/createBridgeTransfer.ts
135
- import { hexToBigInt as hexToBigInt2 } from "@xylabs/sdk-js";
136
- import { createTransferPayload } from "@xyo-network/xl1-sdk";
137
- var createBridgeTransfer = /* @__PURE__ */ __name((sender, srcAmount, escrowAddress, feesAddress, context) => {
138
- const { feeFixed, feeVariable } = context;
139
- const escrowAmount = hexToBigInt2(srcAmount);
140
- const feesAmount = hexToBigInt2(feeFixed) + hexToBigInt2(feeVariable);
141
- const transfers = escrowAddress === feesAddress ? {
142
- [feesAddress]: escrowAmount + feesAmount
143
- } : {
144
- [escrowAddress]: escrowAmount,
145
- [feesAddress]: feesAmount
146
- };
147
- const transfer = createTransferPayload(sender, transfers, context);
148
- return transfer;
149
- }, "createBridgeTransfer");
150
-
151
- // src/util/generateBridgeEstimate.ts
152
- import { toAddress } from "@xylabs/sdk-js";
153
- import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
154
- import { BridgeIntentSchema } from "@xyo-network/xl1-sdk";
155
- import { v4 } from "uuid";
156
-
157
115
  // src/config/asChainId.ts
158
116
  import { asHex } from "@xylabs/sdk-js";
159
117
  var asChainId = /* @__PURE__ */ __name((value) => {
@@ -293,7 +251,53 @@ var getBridgeSettings = /* @__PURE__ */ __name(async (config) => {
293
251
  };
294
252
  }, "getBridgeSettings");
295
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
+
296
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";
297
301
  var generateBridgeEstimate = /* @__PURE__ */ __name(async (srcAddress, srcAmount, destAddress, config, nonceOverride) => {
298
302
  const { escrowAddress, feeFixed, feeRateBasisPoints, feesAddress, remoteChainId, remoteTokenAddress, xl1ChainId, xl1TokenAddress } = await getBridgeSettings(config);
299
303
  const sender = toAddress(srcAddress);
@@ -328,6 +332,7 @@ var generateBridgeEstimate = /* @__PURE__ */ __name(async (srcAddress, srcAmount
328
332
  // src/validation/validateBridgeEstimateExact.ts
329
333
  var validateBridgeEstimateExact = /* @__PURE__ */ __name(async (intent, transfer, config) => {
330
334
  const { srcAddress, srcAmount, destAddress } = intent;
335
+ if (hexToBigInt4(srcAmount) > hexToBigInt4(getMaxBridgeAmount(config))) return false;
331
336
  const [calculatedIntent, calculatedTransfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
332
337
  if (isUndefined2(calculatedIntent) || isUndefined2(calculatedTransfer)) return false;
333
338
  const { nonce: expectedIntentNonce, ...expectedIntentStatic } = calculatedIntent;
@@ -366,7 +371,7 @@ var validateBridgeTransaction = /* @__PURE__ */ __name(async (signedTxBw, intent
366
371
  }, "validateBridgeTransaction");
367
372
 
368
373
  // src/validation/validateSufficientLiquiditySourceAllowance.ts
369
- import { assertEx as assertEx7, hexToBigInt as hexToBigInt3 } from "@xylabs/sdk-js";
374
+ import { assertEx as assertEx7, hexToBigInt as hexToBigInt5 } from "@xylabs/sdk-js";
370
375
  import { isBridgeIntent } from "@xyo-network/xl1-sdk";
371
376
  var validateSufficientLiquiditySourceAllowance = /* @__PURE__ */ __name(async (tx, offChainPayloads, bridgeableToken, bridge, logger) => {
372
377
  const allPayloads = [
@@ -374,7 +379,7 @@ var validateSufficientLiquiditySourceAllowance = /* @__PURE__ */ __name(async (t
374
379
  ...offChainPayloads
375
380
  ];
376
381
  const bridgeIntent = assertEx7(allPayloads.find(isBridgeIntent), () => "No bridge intent found");
377
- const amount = hexToBigInt3(bridgeIntent.destAmount);
382
+ const amount = hexToBigInt5(bridgeIntent.destAmount);
378
383
  const liquiditySourceAddress = await bridge.liquiditySource();
379
384
  const bridgeAddress = await bridge.getAddress();
380
385
  const remainingAllowance = await bridgeableToken.allowance(liquiditySourceAddress, bridgeAddress);
@@ -383,7 +388,7 @@ var validateSufficientLiquiditySourceAllowance = /* @__PURE__ */ __name(async (t
383
388
  }, "validateSufficientLiquiditySourceAllowance");
384
389
 
385
390
  // src/validation/validateSufficientLiquiditySourceBalance.ts
386
- import { assertEx as assertEx8, hexToBigInt as hexToBigInt4 } from "@xylabs/sdk-js";
391
+ import { assertEx as assertEx8, hexToBigInt as hexToBigInt6 } from "@xylabs/sdk-js";
387
392
  import { isBridgeIntent as isBridgeIntent2 } from "@xyo-network/xl1-sdk";
388
393
  var validateSufficientLiquiditySourceBalance = /* @__PURE__ */ __name(async (tx, offChainPayloads, bridgeableToken, bridge, logger) => {
389
394
  const allPayloads = [
@@ -391,7 +396,7 @@ var validateSufficientLiquiditySourceBalance = /* @__PURE__ */ __name(async (tx,
391
396
  ...offChainPayloads
392
397
  ];
393
398
  const bridgeIntent = assertEx8(allPayloads.find(isBridgeIntent2), () => "No bridge intent found");
394
- const amount = hexToBigInt4(bridgeIntent.destAmount);
399
+ const amount = hexToBigInt6(bridgeIntent.destAmount);
395
400
  const liquiditySourceAddress = await bridge.liquiditySource();
396
401
  const balance = await bridgeableToken.balanceOf(liquiditySourceAddress);
397
402
  await logger?.log(`Remaining balance: ${balance.toString()}`);
@@ -423,13 +428,13 @@ var validateSufficientRunnerEthBalanceForGas = /* @__PURE__ */ __name(async (pre
423
428
  }, "validateSufficientRunnerEthBalanceForGas");
424
429
 
425
430
  // src/validation/validateSufficientXL1SourceAddressBalance.ts
426
- import { asAddress as asAddress5, assertEx as assertEx10, hexToBigInt as hexToBigInt5 } from "@xylabs/sdk-js";
431
+ import { asAddress as asAddress5, assertEx as assertEx10, hexToBigInt as hexToBigInt7 } from "@xylabs/sdk-js";
427
432
  var validateSufficientXL1SourceAddressBalance = /* @__PURE__ */ __name(async (bridgeIntent, gateway, config, logger) => {
428
433
  const viewer = assertEx10(gateway.connection.viewer, () => "Gateway connection does not have a viewer");
429
434
  const { srcAddress, srcAmount, destAddress } = bridgeIntent;
430
435
  const srcAddressBranded = asAddress5(srcAddress, () => `Invalid source address in bridge intent: ${srcAddress}`);
431
436
  const [_, calculatedTransfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
432
- const totalAmount = Object.values(calculatedTransfer.transfers).reduce((acc, transfer) => acc + hexToBigInt5(transfer), 0n);
437
+ const totalAmount = Object.values(calculatedTransfer.transfers).reduce((acc, transfer) => acc + hexToBigInt7(transfer), 0n);
433
438
  const accountBalance = await viewer.account.balance.accountBalance(srcAddressBranded);
434
439
  await logger?.log(`Account balance for ${srcAddressBranded}: ${accountBalance.toString()}`);
435
440
  return accountBalance >= totalAmount;
@@ -463,10 +468,10 @@ var createWorker2 = /* @__PURE__ */ __name((connection2, telemetry2, services) =
463
468
  ...offChainPayloads
464
469
  ];
465
470
  const bridgeIntent = assertEx11(allPayloads.find(isBridgeIntent3), () => "No bridge intent found");
466
- const amount = hexToBigInt6(bridgeIntent.destAmount);
471
+ const amount = hexToBigInt8(bridgeIntent.destAmount);
467
472
  const srcAddress = getAddress(bridgeIntent.srcAddress);
468
473
  const destAddress = getAddress(bridgeIntent.destAddress);
469
- const nonce = hexToBigInt6(await PayloadBuilder5.hash(tx[0]));
474
+ const nonce = hexToBigInt8(await PayloadBuilder5.hash(tx[0]));
470
475
  const preparedTx = await bridge.getFunction("bridgeFromRemote").populateTransaction(srcAddress, destAddress, amount, nonce);
471
476
  await job.log(`[${hash}] built ETH transaction`);
472
477
  await job.log(`[${hash}] validating tx runner has sufficient ETH for gas`);
@@ -505,7 +510,7 @@ import { PayloadBuilder as PayloadBuilder7 } from "@xyo-network/sdk-js";
505
510
  import { Worker as Worker3 } from "bullmq";
506
511
 
507
512
  // src/queue/workers/util/submitEthTransaction.ts
508
- import { assertEx as assertEx12, hexToBigInt as hexToBigInt7, toEthAddress } from "@xylabs/sdk-js";
513
+ import { assertEx as assertEx12, hexToBigInt as hexToBigInt9, toEthAddress } from "@xylabs/sdk-js";
509
514
  import { PayloadBuilder as PayloadBuilder6 } from "@xyo-network/sdk-js";
510
515
  import { isBridgeIntent as isBridgeIntent4 } from "@xyo-network/xl1-sdk";
511
516
  var submitEthTransaction = /* @__PURE__ */ __name(async (tx, offChainPayloads, bridge, wallet) => {
@@ -517,8 +522,8 @@ var submitEthTransaction = /* @__PURE__ */ __name(async (tx, offChainPayloads, b
517
522
  const bridgeIntent = assertEx12(allPayloads.find(isBridgeIntent4), () => "No bridge intent found");
518
523
  const srcAddress = toEthAddress(bridgeIntent.srcAddress);
519
524
  const destAddress = toEthAddress(bridgeIntent.destAddress);
520
- const amount = hexToBigInt7(bridgeIntent.destAmount);
521
- const nonce = hexToBigInt7(await PayloadBuilder6.hash(xl1Transaction));
525
+ const amount = hexToBigInt9(bridgeIntent.destAmount);
526
+ const nonce = hexToBigInt9(await PayloadBuilder6.hash(xl1Transaction));
522
527
  const bridgeTx = await bridge.connect(wallet).bridgeFromRemote(srcAddress, destAddress, amount, nonce);
523
528
  const receipt = await bridgeTx.wait(1);
524
529
  return receipt?.hash;
@@ -1140,7 +1145,7 @@ var makeBridgeConfigRoute = /* @__PURE__ */ __name((config) => {
1140
1145
 
1141
1146
  // src/server/routes/bridge/routeDefinitions/routes/bridgeFromRemoteStatus.ts
1142
1147
  import { requestHandlerValidator as requestHandlerValidator2 } from "@xylabs/express";
1143
- import { toAddress as toAddress2, toHex as toHex2 } from "@xylabs/sdk-js";
1148
+ import { toAddress as toAddress2, toHex as toHex3 } from "@xylabs/sdk-js";
1144
1149
  import { PayloadZodStrictOfSchema } from "@xyo-network/sdk-js";
1145
1150
  import { BridgeDestinationObservationFieldsZod, BridgeDestinationObservationSchema } from "@xyo-network/xl1-sdk";
1146
1151
  import { z } from "zod";
@@ -1186,13 +1191,13 @@ var makeBridgeFromRemoteStatusRoute = /* @__PURE__ */ __name((config) => {
1186
1191
  schema: BridgeDestinationObservationSchema,
1187
1192
  dest: xl1ChainId,
1188
1193
  destAddress: toAddress2("0xabc"),
1189
- destAmount: toHex2("0x100"),
1194
+ destAmount: toHex3("0x100"),
1190
1195
  destToken: xl1TokenAddress,
1191
1196
  src: remoteChainId,
1192
1197
  srcAddress: toAddress2("0x123"),
1193
- srcAmount: toHex2("0x200"),
1198
+ srcAmount: toHex3("0x200"),
1194
1199
  srcToken: remoteTokenAddress,
1195
- destConfirmation: toHex2("0x9999")
1200
+ destConfirmation: toHex3("0x9999")
1196
1201
  };
1197
1202
  res.json(observation);
1198
1203
  })
@@ -1273,7 +1278,7 @@ var makeBridgeToRemoteRoute = /* @__PURE__ */ __name((config) => {
1273
1278
 
1274
1279
  // src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteEstimate.ts
1275
1280
  import { requestHandlerValidator as requestHandlerValidator4 } from "@xylabs/express";
1276
- 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";
1277
1282
  import { PayloadZodStrictOfSchema as PayloadZodStrictOfSchema3 } from "@xyo-network/sdk-js";
1278
1283
  import { BridgeIntentFieldsZod as BridgeIntentFieldsZod2, BridgeIntentSchema as BridgeIntentSchema4, buildUnsignedTransaction, toXL1BlockNumber, TransactionBoundWitnessZod, TransferZod as TransferZod2 } from "@xyo-network/xl1-sdk";
1279
1284
  import { z as z3 } from "zod";
@@ -1302,6 +1307,11 @@ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config, gateway) =
1302
1307
  handlers: validateRequest2(async (req, res) => {
1303
1308
  const xl1ChainId = getXl1ChainId(config);
1304
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
+ }
1305
1315
  const [bridgeIntent, transfer] = await generateBridgeEstimate(srcAddress, srcAmount, destAddress, config);
1306
1316
  const sender = toAddress3(srcAddress);
1307
1317
  const viewer = assertEx19(gateway.connection.viewer, () => new Error("Viewer not available on gateway connection"));
@@ -1322,36 +1332,92 @@ var makeBridgeToRemoteEstimateRoute = /* @__PURE__ */ __name((config, gateway) =
1322
1332
  };
1323
1333
  }, "makeBridgeToRemoteEstimateRoute");
1324
1334
 
1325
- // src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteStatus.ts
1335
+ // src/server/routes/bridge/routeDefinitions/routes/bridgeToRemoteMaxEstimate.ts
1326
1336
  import { requestHandlerValidator as requestHandlerValidator5 } from "@xylabs/express";
1327
- import { asHex as asHex3, isDefined as isDefined13 } from "@xylabs/sdk-js";
1328
- import { PayloadBuilder as PayloadBuilder15, PayloadZodStrictOfSchema as PayloadZodStrictOfSchema4 } from "@xyo-network/sdk-js";
1329
- import { asBridgeIntent, BridgeDestinationObservationFieldsZod as BridgeDestinationObservationFieldsZod2, BridgeDestinationObservationSchema as BridgeDestinationObservationSchema2, BridgeIntentFieldsZod as BridgeIntentFieldsZod3, BridgeIntentSchema as BridgeIntentSchema5, BridgeSourceObservationFieldsZod as BridgeSourceObservationFieldsZod2, BridgeSourceObservationSchema as BridgeSourceObservationSchema2, isBridgeIntent as isBridgeIntent5 } from "@xyo-network/xl1-sdk";
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";
1330
1340
  import { z as z4 } from "zod";
1331
- var BridgeIntentResponseZod = PayloadZodStrictOfSchema4(BridgeIntentSchema5).extend(BridgeIntentFieldsZod3.shape);
1332
- var BridgeSourceResponseZod = PayloadZodStrictOfSchema4(BridgeSourceObservationSchema2).extend(BridgeSourceObservationFieldsZod2.shape);
1333
- var BridgeDestinationResponseZod = PayloadZodStrictOfSchema4(BridgeDestinationObservationSchema2).extend(BridgeDestinationObservationFieldsZod2.shape);
1334
- var BridgeToRemoteStatusResponseZod = z4.union([
1335
- z4.tuple([]),
1336
- z4.tuple([
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([
1337
1403
  BridgeIntentResponseZod
1338
1404
  ]),
1339
- z4.tuple([
1405
+ z5.tuple([
1340
1406
  BridgeIntentResponseZod,
1341
1407
  BridgeSourceResponseZod
1342
1408
  ]),
1343
- z4.tuple([
1409
+ z5.tuple([
1344
1410
  BridgeIntentResponseZod,
1345
1411
  BridgeSourceResponseZod,
1346
1412
  BridgeDestinationResponseZod
1347
1413
  ])
1348
1414
  ]);
1349
1415
  var makeBridgeToRemoteStatusRoute = /* @__PURE__ */ __name((config) => {
1350
- const params = z4.object({
1416
+ const params = z5.object({
1351
1417
  chainId: getRemoteChainIdZod(config),
1352
- nonce: z4.string().nonempty()
1418
+ nonce: z5.string().nonempty()
1353
1419
  });
1354
- const validateRequest2 = requestHandlerValidator5({
1420
+ const validateRequest2 = requestHandlerValidator6({
1355
1421
  params,
1356
1422
  response: BridgeToRemoteStatusResponseZod
1357
1423
  });
@@ -1412,6 +1478,7 @@ var getRouteDefinitions = /* @__PURE__ */ __name((config, gateway) => {
1412
1478
  return [
1413
1479
  makeBridgeConfigRoute(config),
1414
1480
  makeBridgeToRemoteEstimateRoute(config, gateway),
1481
+ makeBridgeToRemoteMaxEstimateRoute(config, gateway),
1415
1482
  makeBridgeToRemoteRoute(config),
1416
1483
  makeBridgeToRemoteStatusRoute(config),
1417
1484
  makeBridgeFromRemoteStatusRoute(config)
@@ -1435,17 +1502,7 @@ var addRoutes = /* @__PURE__ */ __name((app, config, gateway) => {
1435
1502
  var getApp = /* @__PURE__ */ __name((config, gateway) => {
1436
1503
  addInstrumentation();
1437
1504
  const app = express();
1438
- app.set("etag", false);
1439
- app.use(cors());
1440
- app.use(compression());
1441
- app.use(responseProfiler);
1442
- app.use(getJsonBodyParser(getJsonBodyParserOptions({
1443
- limit: "1mb"
1444
- })));
1445
- app.use(standardResponses);
1446
- disableExpressDefaultPoweredByHeader(app);
1447
- app.use(customPoweredByHeader);
1448
- disableCaseSensitiveRouting(app);
1505
+ sharedMiddleware(app);
1449
1506
  addFlowProducer(app, config);
1450
1507
  addRoutes(app, config, gateway);
1451
1508
  app.use(standardErrors);
@@ -1453,7 +1510,7 @@ var getApp = /* @__PURE__ */ __name((config, gateway) => {
1453
1510
  }, "getApp");
1454
1511
 
1455
1512
  // src/services/getServices.ts
1456
- import { assertEx as assertEx20, isDefined as isDefined14 } from "@xylabs/sdk-js";
1513
+ import { assertEx as assertEx21, isDefined as isDefined14 } from "@xylabs/sdk-js";
1457
1514
  import { initEvmProvider } from "@xyo-network/chain-orchestration";
1458
1515
  import { HDWallet as HDWallet2 } from "@xyo-network/sdk-js";
1459
1516
  import { BridgeableToken__factory, LiquidityPoolBridge__factory } from "@xyo-network/typechain";
@@ -1503,7 +1560,7 @@ var getServices = /* @__PURE__ */ __name(async (context, gateway) => {
1503
1560
  const bridgeableToken = BridgeableToken__factory.connect(getAddress2(remoteTokenAddress), wallet);
1504
1561
  const bridge = LiquidityPoolBridge__factory.connect(getAddress2(remoteBridgeContractAddress), wallet);
1505
1562
  const bridgeOwner = await bridge.owner();
1506
- assertEx20(bridgeOwner.toLowerCase() === wallet.address.toLowerCase(), () => "Wallet is not the owner of the bridge contract");
1563
+ assertEx21(bridgeOwner.toLowerCase() === wallet.address.toLowerCase(), () => "Wallet is not the owner of the bridge contract");
1507
1564
  return {
1508
1565
  account,
1509
1566
  bridge,