@rhea-finance/cross-chain-aggregation-dex 0.1.9 → 0.2.1

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/index.js CHANGED
@@ -15,6 +15,49 @@ function requiresRecipientInExecute(params) {
15
15
  return "sender" in params && "receiveUser" in params;
16
16
  }
17
17
 
18
+ // src/utils/errorMessages.ts
19
+ var TRANSACTION_EXECUTION_ERROR_MESSAGE = "Transaction execution error occurred. Please contact support";
20
+ var ErrorMessages = {
21
+ // Quote errors
22
+ QUOTE_FAILED: "Failed to get quote",
23
+ // Execution errors
24
+ EXECUTE_FAILED: "Transaction failed"
25
+ };
26
+ function getErrorMessage(error, fallback = ErrorMessages.EXECUTE_FAILED) {
27
+ if (!error) return fallback;
28
+ if (error && error.length > 0) {
29
+ return error;
30
+ }
31
+ return fallback;
32
+ }
33
+ function processErrorMessage(errorMessage) {
34
+ const errorString = errorMessage.toLowerCase();
35
+ const userActionKeywords = [
36
+ "user",
37
+ "rejected",
38
+ "cancelled",
39
+ "cancel",
40
+ "denied",
41
+ "undefined",
42
+ "null"
43
+ ];
44
+ const containsUserActionKeyword = userActionKeywords.some(
45
+ (keyword) => errorString.includes(keyword)
46
+ );
47
+ if (containsUserActionKeyword) {
48
+ return errorMessage;
49
+ }
50
+ return TRANSACTION_EXECUTION_ERROR_MESSAGE;
51
+ }
52
+ function normalizeError(error) {
53
+ if (!error) return ErrorMessages.EXECUTE_FAILED;
54
+ const errorLower = error.toLowerCase();
55
+ if (errorLower.includes("quote") || errorLower.includes("route") || errorLower.includes("missing") || errorLower.includes("required") || errorLower.includes("invalid") || errorLower.includes("balance") || errorLower.includes("liquidity") || errorLower.includes("slippage") || errorLower.includes("gas") || errorLower.includes("network")) {
56
+ return ErrorMessages.QUOTE_FAILED;
57
+ }
58
+ return processErrorMessage(error);
59
+ }
60
+
18
61
  // src/utils/logger.ts
19
62
  var LOG_LEVELS = {
20
63
  silent: 0,
@@ -155,7 +198,7 @@ function findBestEvmBluechipToken(bluechipTokens, nativeTokenAddress) {
155
198
  };
156
199
  }
157
200
  if (preferredTokens.length === 0) {
158
- throw new Error("No EVM bluechip token configured");
201
+ throw new Error(ErrorMessages.QUOTE_FAILED);
159
202
  }
160
203
  return preferredTokens[0];
161
204
  }
@@ -336,7 +379,7 @@ var NearSmartRouter = class {
336
379
  amountOut: "0",
337
380
  minAmountOut: "0",
338
381
  routes: [],
339
- error: "Missing token address"
382
+ error: ErrorMessages.QUOTE_FAILED
340
383
  };
341
384
  }
342
385
  const normalizedTokenIn = normalizeTokenId(
@@ -356,7 +399,7 @@ var NearSmartRouter = class {
356
399
  amountOut: "0",
357
400
  minAmountOut: "0",
358
401
  routes: [],
359
- error: "Invalid token address"
402
+ error: ErrorMessages.QUOTE_FAILED
360
403
  };
361
404
  }
362
405
  const slippageBps = convertSlippageToBasisPoints(slippage);
@@ -377,7 +420,7 @@ var NearSmartRouter = class {
377
420
  amountOut: "0",
378
421
  minAmountOut: "0",
379
422
  routes: [],
380
- error: response?.result_msg || response?.result_message || "No route found"
423
+ error: normalizeError(response?.result_msg || response?.result_message) || ErrorMessages.QUOTE_FAILED
381
424
  };
382
425
  }
383
426
  const { routes: serverRoutes, amount_out } = response.result_data;
@@ -416,7 +459,7 @@ var NearSmartRouter = class {
416
459
  amountOut: "0",
417
460
  minAmountOut: "0",
418
461
  routes: [],
419
- error: error?.message || "Quote failed"
462
+ error: normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
420
463
  };
421
464
  }
422
465
  }
@@ -429,7 +472,7 @@ var NearSmartRouter = class {
429
472
  if (!quote.success || !quote.routes.length) {
430
473
  return {
431
474
  success: false,
432
- error: "Invalid quote"
475
+ error: ErrorMessages.QUOTE_FAILED
433
476
  };
434
477
  }
435
478
  const swapActions = [];
@@ -448,7 +491,7 @@ var NearSmartRouter = class {
448
491
  if (!swapActions.length) {
449
492
  return {
450
493
  success: false,
451
- error: "No swap actions"
494
+ error: ErrorMessages.QUOTE_FAILED
452
495
  };
453
496
  }
454
497
  const finalRecipient = depositAddress || recipient;
@@ -549,13 +592,13 @@ var NearSmartRouter = class {
549
592
  } else {
550
593
  return {
551
594
  success: false,
552
- error: result.message || "Execute swap failed"
595
+ error: normalizeError(result.message) || ErrorMessages.EXECUTE_FAILED
553
596
  };
554
597
  }
555
598
  } catch (error) {
556
599
  return {
557
600
  success: false,
558
- error: error?.message || "Execute swap failed"
601
+ error: normalizeError(error?.message) || ErrorMessages.EXECUTE_FAILED
559
602
  };
560
603
  }
561
604
  }
@@ -617,7 +660,7 @@ var AggregateDexRouter = class {
617
660
  amountOut: "0",
618
661
  minAmountOut: "0",
619
662
  routes: [],
620
- error: "Missing sender or recipient"
663
+ error: ErrorMessages.QUOTE_FAILED
621
664
  };
622
665
  }
623
666
  const { tokenIn, tokenOut, amountIn, slippage, sender, recipient } = params;
@@ -630,7 +673,7 @@ var AggregateDexRouter = class {
630
673
  amountOut: "0",
631
674
  minAmountOut: "0",
632
675
  routes: [],
633
- error: "Missing sender or recipient"
676
+ error: ErrorMessages.QUOTE_FAILED
634
677
  };
635
678
  }
636
679
  if (!tokenIn?.address || !tokenOut?.address) {
@@ -642,7 +685,7 @@ var AggregateDexRouter = class {
642
685
  amountOut: "0",
643
686
  minAmountOut: "0",
644
687
  routes: [],
645
- error: "Missing token address"
688
+ error: ErrorMessages.QUOTE_FAILED
646
689
  };
647
690
  }
648
691
  const normalizedTokenIn = normalizeTokenId(
@@ -662,7 +705,7 @@ var AggregateDexRouter = class {
662
705
  amountOut: "0",
663
706
  minAmountOut: "0",
664
707
  routes: [],
665
- error: "Invalid token address"
708
+ error: ErrorMessages.QUOTE_FAILED
666
709
  };
667
710
  }
668
711
  const slippageBps = convertSlippageToBasisPoints(slippage);
@@ -685,7 +728,7 @@ var AggregateDexRouter = class {
685
728
  amountOut: "0",
686
729
  minAmountOut: "0",
687
730
  routes: [],
688
- error: "Failed to get quote"
731
+ error: ErrorMessages.QUOTE_FAILED
689
732
  };
690
733
  }
691
734
  const {
@@ -721,7 +764,7 @@ var AggregateDexRouter = class {
721
764
  amountOut: "0",
722
765
  minAmountOut: "0",
723
766
  routes: [],
724
- error: "Failed to get quote"
767
+ error: normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
725
768
  };
726
769
  }
727
770
  }
@@ -730,7 +773,7 @@ var AggregateDexRouter = class {
730
773
  */
731
774
  async finalizeQuote(params, depositAddress) {
732
775
  if (!requiresRecipient(params)) {
733
- throw new Error("V2 Router requires recipient parameters");
776
+ throw new Error(ErrorMessages.QUOTE_FAILED);
734
777
  }
735
778
  return await this.quote({
736
779
  ...params,
@@ -747,7 +790,7 @@ var AggregateDexRouter = class {
747
790
  if (adjustedQuote.success && adjustedQuote.routerMsg && adjustedQuote.signature) {
748
791
  return adjustedQuote;
749
792
  } else {
750
- throw new Error("Failed to get quote");
793
+ throw new Error(ErrorMessages.QUOTE_FAILED);
751
794
  }
752
795
  }
753
796
  async ensureQuoteAmountWithinBalance(quoteParams, actualBalance, context) {
@@ -779,7 +822,7 @@ var AggregateDexRouter = class {
779
822
  }
780
823
  const quote = await this.quote(quoteParams);
781
824
  if (!quote.success) {
782
- throw new Error("Failed to get quote");
825
+ throw new Error(ErrorMessages.QUOTE_FAILED);
783
826
  }
784
827
  if (quote.amountIn !== quoteParams.amountIn) {
785
828
  const apiAmountBig = new Big3__default.default(quote.amountIn);
@@ -802,26 +845,26 @@ var AggregateDexRouter = class {
802
845
  if (!requiresRecipientInExecute(params)) {
803
846
  return {
804
847
  success: false,
805
- error: "Missing sender or receiveUser"
848
+ error: ErrorMessages.QUOTE_FAILED
806
849
  };
807
850
  }
808
851
  const { quote, sender, receiveUser } = params;
809
852
  if (!quote.success) {
810
853
  return {
811
854
  success: false,
812
- error: "Invalid quote"
855
+ error: ErrorMessages.QUOTE_FAILED
813
856
  };
814
857
  }
815
858
  if (!receiveUser || receiveUser.trim() === "") {
816
859
  return {
817
860
  success: false,
818
- error: "Missing receiveUser"
861
+ error: ErrorMessages.QUOTE_FAILED
819
862
  };
820
863
  }
821
864
  if (receiveUser.startsWith("0x") && receiveUser.length === 42) {
822
865
  return {
823
866
  success: false,
824
- error: "Invalid receiveUser address"
867
+ error: ErrorMessages.QUOTE_FAILED
825
868
  };
826
869
  }
827
870
  const slippage = quote.slippage || 5e-3;
@@ -853,7 +896,7 @@ var AggregateDexRouter = class {
853
896
  } catch (error) {
854
897
  return {
855
898
  success: false,
856
- error: "Failed to get quote"
899
+ error: normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
857
900
  };
858
901
  }
859
902
  const routerMsg = finalQuote.routerMsg;
@@ -861,7 +904,7 @@ var AggregateDexRouter = class {
861
904
  if (!routerMsg || !signature) {
862
905
  return {
863
906
  success: false,
864
- error: "Failed to get quote"
907
+ error: ErrorMessages.QUOTE_FAILED
865
908
  };
866
909
  }
867
910
  const tokens = finalQuote.tokens || [];
@@ -1056,7 +1099,7 @@ var AggregateDexRouter = class {
1056
1099
  } catch (error) {
1057
1100
  return {
1058
1101
  success: false,
1059
- error: "Failed to get quote"
1102
+ error: normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
1060
1103
  };
1061
1104
  }
1062
1105
  const finalAmountToTransfer = finalQuoteForExecution.amountIn;
@@ -1087,13 +1130,13 @@ var AggregateDexRouter = class {
1087
1130
  } else {
1088
1131
  return {
1089
1132
  success: false,
1090
- error: "Execute swap failed"
1133
+ error: normalizeError(result.message) || ErrorMessages.EXECUTE_FAILED
1091
1134
  };
1092
1135
  }
1093
1136
  } catch (error) {
1094
1137
  return {
1095
1138
  success: false,
1096
- error: "Execute swap failed"
1139
+ error: normalizeError(error?.message) || ErrorMessages.EXECUTE_FAILED
1097
1140
  };
1098
1141
  }
1099
1142
  }
@@ -1320,7 +1363,7 @@ var BitgetRouter = class {
1320
1363
  amountOut: "0",
1321
1364
  minAmountOut: "0",
1322
1365
  routes: [],
1323
- error: "Missing sender or recipient"
1366
+ error: ErrorMessages.QUOTE_FAILED
1324
1367
  };
1325
1368
  }
1326
1369
  const { tokenIn, tokenOut, amountIn, slippage, sender, recipient } = params;
@@ -1333,7 +1376,7 @@ var BitgetRouter = class {
1333
1376
  amountOut: "0",
1334
1377
  minAmountOut: "0",
1335
1378
  routes: [],
1336
- error: "Missing sender or recipient"
1379
+ error: ErrorMessages.QUOTE_FAILED
1337
1380
  };
1338
1381
  }
1339
1382
  if (tokenIn?.address === void 0 || tokenOut?.address === void 0) {
@@ -1345,7 +1388,7 @@ var BitgetRouter = class {
1345
1388
  amountOut: "0",
1346
1389
  minAmountOut: "0",
1347
1390
  routes: [],
1348
- error: "Missing token address"
1391
+ error: ErrorMessages.QUOTE_FAILED
1349
1392
  };
1350
1393
  }
1351
1394
  const normalizedTokenIn = tokenIn.address === "" ? "" : this.normalizeEvmAddress(tokenIn.address);
@@ -1367,7 +1410,7 @@ var BitgetRouter = class {
1367
1410
  if (!isBitgetResponseSuccess(response) || !response.data) {
1368
1411
  return createQuoteError(
1369
1412
  params,
1370
- response.msg || "Failed to get quote"
1413
+ normalizeError(response.msg) || ErrorMessages.QUOTE_FAILED
1371
1414
  );
1372
1415
  }
1373
1416
  const {
@@ -1433,21 +1476,21 @@ var BitgetRouter = class {
1433
1476
  } catch (error) {
1434
1477
  return createQuoteError(
1435
1478
  params,
1436
- error?.message || "Failed to get quote"
1479
+ normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
1437
1480
  );
1438
1481
  }
1439
1482
  }
1440
1483
  async executeSwap(params) {
1441
1484
  try {
1442
1485
  if (!requiresRecipientInExecute(params)) {
1443
- return createExecuteError("Missing sender or receiveUser");
1486
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1444
1487
  }
1445
1488
  const { quote, sender, receiveUser } = params;
1446
1489
  if (!quote.success) {
1447
- return createExecuteError("Invalid quote");
1490
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1448
1491
  }
1449
1492
  if (!receiveUser || receiveUser.trim() === "") {
1450
- return createExecuteError("Missing receiveUser");
1493
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1451
1494
  }
1452
1495
  let market;
1453
1496
  try {
@@ -1455,13 +1498,13 @@ var BitgetRouter = class {
1455
1498
  const routerMsg = JSON.parse(quote.routerMsg);
1456
1499
  market = routerMsg.market || "";
1457
1500
  } else {
1458
- return createExecuteError("Missing market from quote, please re-fetch quote");
1501
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1459
1502
  }
1460
1503
  } catch (error) {
1461
- return createExecuteError("Invalid quote format: missing market");
1504
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1462
1505
  }
1463
1506
  if (!market) {
1464
- return createExecuteError("Missing market from quote response");
1507
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1465
1508
  }
1466
1509
  const normalizedTokenIn = this.normalizeEvmAddress(
1467
1510
  quote.tokenIn.address
@@ -1485,7 +1528,7 @@ var BitgetRouter = class {
1485
1528
  });
1486
1529
  if (!isBitgetResponseSuccess(reQuoteResponse) || !reQuoteResponse.data) {
1487
1530
  return createExecuteError(
1488
- `Re-quote failed: ${reQuoteResponse.msg || "Please refresh quote and try again"}`
1531
+ normalizeError(reQuoteResponse.msg) || ErrorMessages.QUOTE_FAILED
1489
1532
  );
1490
1533
  }
1491
1534
  market = reQuoteResponse.data?.market || market;
@@ -1505,13 +1548,11 @@ var BitgetRouter = class {
1505
1548
  });
1506
1549
  if (!isBitgetResponseSuccess(swapResponse) || !swapResponse.data) {
1507
1550
  return createExecuteError(
1508
- swapResponse.msg || "Failed to get swap calldata"
1551
+ normalizeError(swapResponse.msg) || ErrorMessages.QUOTE_FAILED
1509
1552
  );
1510
1553
  }
1511
1554
  if (swapResponse.data?.estimateRevert === true) {
1512
- return createExecuteError(
1513
- "Transaction will fail on-chain (slippage too high or price changed). Please refresh quote."
1514
- );
1555
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1515
1556
  }
1516
1557
  let transactionData = swapResponse.data?.calldata || swapResponse.data?.data;
1517
1558
  const to = swapResponse.data?.contract || swapResponse.data?.to;
@@ -1525,14 +1566,14 @@ var BitgetRouter = class {
1525
1566
  }
1526
1567
  const gas = swapResponse.data?.gas || (swapResponse.data?.computeUnits !== void 0 ? String(swapResponse.data.computeUnits) : void 0);
1527
1568
  if (!to || !transactionData) {
1528
- return createExecuteError("Invalid swap response: missing to or data");
1569
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1529
1570
  }
1530
1571
  if (transactionData.length < 10 || !/^0x[0-9a-fA-F]+$/.test(transactionData)) {
1531
- return createExecuteError("Invalid calldata format: must be hex string starting with 0x");
1572
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1532
1573
  }
1533
1574
  if (normalizedTokenIn && normalizedTokenIn !== "") {
1534
1575
  if (!this.evmChainAdapter.getBalance) {
1535
- return createExecuteError("getBalance method not available on evmChainAdapter");
1576
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1536
1577
  }
1537
1578
  const tokenBalanceFormatted = await this.evmChainAdapter.getBalance({
1538
1579
  address: sender,
@@ -1542,9 +1583,7 @@ var BitgetRouter = class {
1542
1583
  const balanceBN = ethers.ethers.utils.parseUnits(tokenBalanceFormatted || "0", tokenDecimals);
1543
1584
  const amountInBN = ethers.ethers.BigNumber.from(quote.amountIn);
1544
1585
  if (balanceBN.lt(amountInBN)) {
1545
- return createExecuteError(
1546
- `Insufficient token balance: have ${tokenBalanceFormatted}, need ${ethers.ethers.utils.formatUnits(amountInBN, tokenDecimals)}`
1547
- );
1586
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1548
1587
  }
1549
1588
  const currentAllowance = await this.evmChainAdapter.getAllowance({
1550
1589
  tokenAddress: normalizedTokenIn,
@@ -1554,7 +1593,7 @@ var BitgetRouter = class {
1554
1593
  const allowanceBN = ethers.ethers.BigNumber.from(currentAllowance);
1555
1594
  if (allowanceBN.lt(amountInBN)) {
1556
1595
  try {
1557
- const approveResult = await this.evmChainAdapter.approve({
1596
+ await this.evmChainAdapter.approve({
1558
1597
  tokenAddress: normalizedTokenIn,
1559
1598
  spender: to,
1560
1599
  amount: ethers.ethers.constants.MaxUint256.toString()
@@ -1577,19 +1616,17 @@ var BitgetRouter = class {
1577
1616
  retryCount++;
1578
1617
  }
1579
1618
  if (newAllowanceBN.lt(amountInBN)) {
1580
- return createExecuteError(
1581
- `Token approval insufficient after ${MAX_APPROVAL_RETRIES} retries. Approval tx: ${approveResult.txHash}`
1582
- );
1619
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1583
1620
  }
1584
1621
  } catch (error) {
1585
1622
  return createExecuteError(
1586
- `Token approval failed: ${error?.message || "Unknown error"}`
1623
+ normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
1587
1624
  );
1588
1625
  }
1589
1626
  }
1590
1627
  } else {
1591
1628
  if (!this.evmChainAdapter.getBalance) {
1592
- return createExecuteError("getBalance method not available on evmChainAdapter");
1629
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1593
1630
  }
1594
1631
  const nativeBalanceFormatted = await this.evmChainAdapter.getBalance({
1595
1632
  address: sender,
@@ -1613,9 +1650,7 @@ var BitgetRouter = class {
1613
1650
  const gasCostEstimate = estimatedGasLimitForBalance.mul(gasPriceEstimate2);
1614
1651
  const totalRequired = amountInBN.add(gasCostEstimate);
1615
1652
  if (balanceBN.lt(totalRequired)) {
1616
- return createExecuteError(
1617
- `Insufficient native token balance: have ${nativeBalanceFormatted} ETH, need ${ethers.ethers.utils.formatEther(totalRequired)} ETH`
1618
- );
1653
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1619
1654
  }
1620
1655
  }
1621
1656
  if (normalizedTokenIn && normalizedTokenIn !== "") {
@@ -1627,9 +1662,7 @@ var BitgetRouter = class {
1627
1662
  const finalAllowanceBN = ethers.ethers.BigNumber.from(finalAllowanceCheck);
1628
1663
  const amountInBN = ethers.ethers.BigNumber.from(quote.amountIn);
1629
1664
  if (finalAllowanceBN.lt(amountInBN)) {
1630
- return createExecuteError(
1631
- `Insufficient allowance: current ${finalAllowanceBN.toString()}, required ${amountInBN.toString()}`
1632
- );
1665
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1633
1666
  }
1634
1667
  }
1635
1668
  const [estimatedGasLimit, hasReliableEstimate, rpcEstimateError] = await estimateGasLimit(
@@ -1650,14 +1683,10 @@ var BitgetRouter = class {
1650
1683
  tokenOut: quote.tokenOut.symbol,
1651
1684
  rpcError: rpcEstimateError
1652
1685
  });
1653
- return createExecuteError(
1654
- "Insufficient liquidity, transaction may fail. Please refresh quote and try again."
1655
- );
1686
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1656
1687
  }
1657
1688
  if (!gas || gas === "0") {
1658
- return createExecuteError(
1659
- "Unable to estimate gas fee, possibly due to insufficient liquidity. Please refresh quote and try again."
1660
- );
1689
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1661
1690
  }
1662
1691
  logger.warn("RPC gas estimation failed, using Bitget estimate", {
1663
1692
  chainId: this.chainId,
@@ -1690,7 +1719,7 @@ var BitgetRouter = class {
1690
1719
  if (!feeData.maxFeePerGas || !feeData.maxPriorityFeePerGas || feeData.maxFeePerGas.lte(0) || feeData.maxPriorityFeePerGas.lte(0)) {
1691
1720
  const cachedGasPrice = await getCachedGasPrice();
1692
1721
  if (!cachedGasPrice || cachedGasPrice.lte(0)) {
1693
- return createExecuteError("Failed to get valid gas price. Please try again.");
1722
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1694
1723
  }
1695
1724
  feeData.maxFeePerGas = cachedGasPrice;
1696
1725
  feeData.maxPriorityFeePerGas = cachedGasPrice.div(10);
@@ -1723,27 +1752,27 @@ var BitgetRouter = class {
1723
1752
  } catch (error) {
1724
1753
  const cachedGasPrice = await getCachedGasPrice();
1725
1754
  if (!cachedGasPrice || cachedGasPrice.lte(0)) {
1726
- return createExecuteError("Failed to get valid gas price. Please try again.");
1755
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1727
1756
  }
1728
1757
  feeData.gasPrice = cachedGasPrice;
1729
1758
  }
1730
1759
  }
1731
1760
  if (!to || !ethers.ethers.utils.isAddress(to)) {
1732
- return createExecuteError(`Invalid contract address: ${to}`);
1761
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1733
1762
  }
1734
1763
  if (!transactionData || transactionData.length < 10) {
1735
- return createExecuteError(`Invalid calldata: length ${transactionData?.length || 0}`);
1764
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1736
1765
  }
1737
1766
  if (!estimatedGasLimit || estimatedGasLimit.lte(0)) {
1738
- return createExecuteError("Invalid gas limit estimate. Please refresh quote and try again.");
1767
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1739
1768
  }
1740
1769
  if (supportsEip1559) {
1741
1770
  if (!feeData.maxFeePerGas || !feeData.maxPriorityFeePerGas || feeData.maxFeePerGas.lte(0) || feeData.maxPriorityFeePerGas.lte(0)) {
1742
- return createExecuteError("Invalid gas fee data. Please try again.");
1771
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1743
1772
  }
1744
1773
  } else {
1745
1774
  if (!feeData.gasPrice || feeData.gasPrice.lte(0)) {
1746
- return createExecuteError("Invalid gas price. Please try again.");
1775
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1747
1776
  }
1748
1777
  }
1749
1778
  const txParams = {
@@ -1767,10 +1796,10 @@ var BitgetRouter = class {
1767
1796
  txHashArray: result.txHash ? [result.txHash] : []
1768
1797
  };
1769
1798
  } else {
1770
- return createExecuteError(result.message || "Execute swap failed");
1799
+ return createExecuteError(normalizeError(result.message) || ErrorMessages.EXECUTE_FAILED);
1771
1800
  }
1772
1801
  } catch (error) {
1773
- return createExecuteError(error?.message || "Execute swap failed");
1802
+ return createExecuteError(normalizeError(error?.message) || ErrorMessages.EXECUTE_FAILED);
1774
1803
  }
1775
1804
  }
1776
1805
  normalizeEvmAddress(address) {
@@ -1811,13 +1840,13 @@ async function completeQuote(params, config) {
1811
1840
  const routers = dexRouters || (dexRouter ? [dexRouter] : []);
1812
1841
  const userAddress = currentUserAddress || recipient;
1813
1842
  if (!userAddress) {
1814
- throw new Error("currentUserAddress or recipient is required for routers that require recipient");
1843
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1815
1844
  }
1816
1845
  if (sourceToken?.address === void 0) {
1817
- throw new Error("Source token address is required");
1846
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1818
1847
  }
1819
1848
  if (targetToken?.address === void 0) {
1820
- throw new Error("Target token address is required");
1849
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1821
1850
  }
1822
1851
  const isEvmChain = evmChainId !== void 0 || sourceChain === "evm" || sourceChain === "ethereum" || sourceChain === "bsc" || sourceChain === "polygon" || sourceChain === "base" || sourceChain === "monad" || sourceToken.chain === "evm";
1823
1852
  const isTokenIntentsSupported = customIsIntentsSupportedToken ? customIsIntentsSupportedToken(sourceToken) : isEvmChain ? isEvmIntentsSupportedToken(sourceToken, bluechipTokens) : isNearIntentsSupportedToken(sourceToken, bluechipTokens);
@@ -1826,7 +1855,7 @@ async function completeQuote(params, config) {
1826
1855
  configAdapter.getEvmNativeWrappedTokenAddress?.()
1827
1856
  ) : findBestBluechipToken(bluechipTokens, wrapNearContractId);
1828
1857
  if (!bluechipToken?.address) {
1829
- throw new Error("Failed to find bluechip token address");
1858
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1830
1859
  }
1831
1860
  const quotePaths = [];
1832
1861
  routers.forEach((router, index) => {
@@ -1860,7 +1889,7 @@ async function completeQuote(params, config) {
1860
1889
  promise: (async () => {
1861
1890
  const preSwapQuote = await router.quote(quoteParams);
1862
1891
  if (!preSwapQuote.success) {
1863
- throw new Error(`Pre-swap quote failed: ${preSwapQuote.error || "Unknown error"}`);
1892
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1864
1893
  }
1865
1894
  let normalizedSourceAsset;
1866
1895
  if (isEvmChain) {
@@ -1888,11 +1917,11 @@ async function completeQuote(params, config) {
1888
1917
  try {
1889
1918
  const amountBN = new Big3__default.default(preSwapQuote.amountOut);
1890
1919
  if (amountBN.lte(0)) {
1891
- throw new Error(`Invalid amountOut: ${preSwapQuote.amountOut}`);
1920
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1892
1921
  }
1893
1922
  formattedAmountOut = amountBN.toFixed(0, Big3__default.default.roundDown);
1894
1923
  } catch (error) {
1895
- throw new Error(`Failed to process amountOut: ${error?.message || String(error)}`);
1924
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1896
1925
  }
1897
1926
  }
1898
1927
  try {
@@ -1908,7 +1937,7 @@ async function completeQuote(params, config) {
1908
1937
  ...appFees ? { appFees } : {}
1909
1938
  });
1910
1939
  if (intentsQuote.quoteStatus !== "success") {
1911
- throw new Error(`Intents quote failed: ${intentsQuote.message || "Unknown error"}`);
1940
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1912
1941
  }
1913
1942
  return {
1914
1943
  intentsQuote,
@@ -1971,7 +2000,7 @@ async function completeQuote(params, config) {
1971
2000
  ...customRecipientMsg ? { customRecipientMsg } : {}
1972
2001
  });
1973
2002
  if (intentsQuote.quoteStatus !== "success") {
1974
- throw new Error("Failed to get quote");
2003
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1975
2004
  }
1976
2005
  return {
1977
2006
  intentsQuote,
@@ -1994,7 +2023,7 @@ async function completeQuote(params, config) {
1994
2023
  }
1995
2024
  });
1996
2025
  if (validPaths.length === 0) {
1997
- throw new Error("Failed to get quote");
2026
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1998
2027
  }
1999
2028
  const bestPath = validPaths.reduce((best, current) => {
2000
2029
  const bestAmount = new Big3__default.default(best.finalAmountOut);
@@ -2003,7 +2032,7 @@ async function completeQuote(params, config) {
2003
2032
  });
2004
2033
  const depositAddress = bestPath.intentsQuote.quoteSuccessResult?.quote?.depositAddress || "";
2005
2034
  if (!depositAddress) {
2006
- throw new Error("Deposit address not found in intents quote");
2035
+ throw new Error(ErrorMessages.QUOTE_FAILED);
2007
2036
  }
2008
2037
  return {
2009
2038
  intents: {
@@ -2070,14 +2099,17 @@ async function quoteSameChainSwap(params, dexRouters) {
2070
2099
  }
2071
2100
  return null;
2072
2101
  }).filter(Boolean);
2073
- throw new Error(`All router quotes failed: ${errors.join("; ")}`);
2102
+ const errorMessage = errors.length > 0 ? `${ErrorMessages.QUOTE_FAILED}: ${errors.join("; ")}` : ErrorMessages.QUOTE_FAILED;
2103
+ throw new Error(errorMessage);
2074
2104
  }
2075
2105
  return selectBestQuote(validQuotes);
2076
2106
  }
2077
2107
 
2078
2108
  exports.AggregateDexRouter = AggregateDexRouter;
2079
2109
  exports.BitgetRouter = BitgetRouter;
2110
+ exports.ErrorMessages = ErrorMessages;
2080
2111
  exports.NearSmartRouter = NearSmartRouter;
2112
+ exports.TRANSACTION_EXECUTION_ERROR_MESSAGE = TRANSACTION_EXECUTION_ERROR_MESSAGE;
2081
2113
  exports.completeQuote = completeQuote;
2082
2114
  exports.convertSlippageToBasisPoints = convertSlippageToBasisPoints;
2083
2115
  exports.findBestBluechipToken = findBestBluechipToken;
@@ -2085,12 +2117,15 @@ exports.findBestEvmBluechipToken = findBestEvmBluechipToken;
2085
2117
  exports.formatGasString = formatGasString;
2086
2118
  exports.formatGasToTgas = formatGasToTgas;
2087
2119
  exports.getBluechipTokensConfig = getBluechipTokensConfig;
2120
+ exports.getErrorMessage = getErrorMessage;
2088
2121
  exports.isEvmIntentsSupportedToken = isEvmIntentsSupportedToken;
2089
2122
  exports.isNearIntentsSupportedToken = isNearIntentsSupportedToken;
2090
2123
  exports.logger = logger;
2091
2124
  exports.normalizeDestinationAsset = normalizeDestinationAsset;
2125
+ exports.normalizeError = normalizeError;
2092
2126
  exports.normalizeEvmAddress = normalizeEvmAddress;
2093
2127
  exports.normalizeTokenId = normalizeTokenId;
2128
+ exports.processErrorMessage = processErrorMessage;
2094
2129
  exports.quoteSameChainSwap = quoteSameChainSwap;
2095
2130
  exports.requiresRecipient = requiresRecipient;
2096
2131
  exports.requiresRecipientInExecute = requiresRecipientInExecute;