@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.mjs CHANGED
@@ -9,6 +9,49 @@ function requiresRecipientInExecute(params) {
9
9
  return "sender" in params && "receiveUser" in params;
10
10
  }
11
11
 
12
+ // src/utils/errorMessages.ts
13
+ var TRANSACTION_EXECUTION_ERROR_MESSAGE = "Transaction execution error occurred. Please contact support";
14
+ var ErrorMessages = {
15
+ // Quote errors
16
+ QUOTE_FAILED: "Failed to get quote",
17
+ // Execution errors
18
+ EXECUTE_FAILED: "Transaction failed"
19
+ };
20
+ function getErrorMessage(error, fallback = ErrorMessages.EXECUTE_FAILED) {
21
+ if (!error) return fallback;
22
+ if (error && error.length > 0) {
23
+ return error;
24
+ }
25
+ return fallback;
26
+ }
27
+ function processErrorMessage(errorMessage) {
28
+ const errorString = errorMessage.toLowerCase();
29
+ const userActionKeywords = [
30
+ "user",
31
+ "rejected",
32
+ "cancelled",
33
+ "cancel",
34
+ "denied",
35
+ "undefined",
36
+ "null"
37
+ ];
38
+ const containsUserActionKeyword = userActionKeywords.some(
39
+ (keyword) => errorString.includes(keyword)
40
+ );
41
+ if (containsUserActionKeyword) {
42
+ return errorMessage;
43
+ }
44
+ return TRANSACTION_EXECUTION_ERROR_MESSAGE;
45
+ }
46
+ function normalizeError(error) {
47
+ if (!error) return ErrorMessages.EXECUTE_FAILED;
48
+ const errorLower = error.toLowerCase();
49
+ 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")) {
50
+ return ErrorMessages.QUOTE_FAILED;
51
+ }
52
+ return processErrorMessage(error);
53
+ }
54
+
12
55
  // src/utils/logger.ts
13
56
  var LOG_LEVELS = {
14
57
  silent: 0,
@@ -149,7 +192,7 @@ function findBestEvmBluechipToken(bluechipTokens, nativeTokenAddress) {
149
192
  };
150
193
  }
151
194
  if (preferredTokens.length === 0) {
152
- throw new Error("No EVM bluechip token configured");
195
+ throw new Error(ErrorMessages.QUOTE_FAILED);
153
196
  }
154
197
  return preferredTokens[0];
155
198
  }
@@ -330,7 +373,7 @@ var NearSmartRouter = class {
330
373
  amountOut: "0",
331
374
  minAmountOut: "0",
332
375
  routes: [],
333
- error: "Missing token address"
376
+ error: ErrorMessages.QUOTE_FAILED
334
377
  };
335
378
  }
336
379
  const normalizedTokenIn = normalizeTokenId(
@@ -350,7 +393,7 @@ var NearSmartRouter = class {
350
393
  amountOut: "0",
351
394
  minAmountOut: "0",
352
395
  routes: [],
353
- error: "Invalid token address"
396
+ error: ErrorMessages.QUOTE_FAILED
354
397
  };
355
398
  }
356
399
  const slippageBps = convertSlippageToBasisPoints(slippage);
@@ -371,7 +414,7 @@ var NearSmartRouter = class {
371
414
  amountOut: "0",
372
415
  minAmountOut: "0",
373
416
  routes: [],
374
- error: response?.result_msg || response?.result_message || "No route found"
417
+ error: normalizeError(response?.result_msg || response?.result_message) || ErrorMessages.QUOTE_FAILED
375
418
  };
376
419
  }
377
420
  const { routes: serverRoutes, amount_out } = response.result_data;
@@ -410,7 +453,7 @@ var NearSmartRouter = class {
410
453
  amountOut: "0",
411
454
  minAmountOut: "0",
412
455
  routes: [],
413
- error: error?.message || "Quote failed"
456
+ error: normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
414
457
  };
415
458
  }
416
459
  }
@@ -423,7 +466,7 @@ var NearSmartRouter = class {
423
466
  if (!quote.success || !quote.routes.length) {
424
467
  return {
425
468
  success: false,
426
- error: "Invalid quote"
469
+ error: ErrorMessages.QUOTE_FAILED
427
470
  };
428
471
  }
429
472
  const swapActions = [];
@@ -442,7 +485,7 @@ var NearSmartRouter = class {
442
485
  if (!swapActions.length) {
443
486
  return {
444
487
  success: false,
445
- error: "No swap actions"
488
+ error: ErrorMessages.QUOTE_FAILED
446
489
  };
447
490
  }
448
491
  const finalRecipient = depositAddress || recipient;
@@ -543,13 +586,13 @@ var NearSmartRouter = class {
543
586
  } else {
544
587
  return {
545
588
  success: false,
546
- error: result.message || "Execute swap failed"
589
+ error: normalizeError(result.message) || ErrorMessages.EXECUTE_FAILED
547
590
  };
548
591
  }
549
592
  } catch (error) {
550
593
  return {
551
594
  success: false,
552
- error: error?.message || "Execute swap failed"
595
+ error: normalizeError(error?.message) || ErrorMessages.EXECUTE_FAILED
553
596
  };
554
597
  }
555
598
  }
@@ -611,7 +654,7 @@ var AggregateDexRouter = class {
611
654
  amountOut: "0",
612
655
  minAmountOut: "0",
613
656
  routes: [],
614
- error: "Missing sender or recipient"
657
+ error: ErrorMessages.QUOTE_FAILED
615
658
  };
616
659
  }
617
660
  const { tokenIn, tokenOut, amountIn, slippage, sender, recipient } = params;
@@ -624,7 +667,7 @@ var AggregateDexRouter = class {
624
667
  amountOut: "0",
625
668
  minAmountOut: "0",
626
669
  routes: [],
627
- error: "Missing sender or recipient"
670
+ error: ErrorMessages.QUOTE_FAILED
628
671
  };
629
672
  }
630
673
  if (!tokenIn?.address || !tokenOut?.address) {
@@ -636,7 +679,7 @@ var AggregateDexRouter = class {
636
679
  amountOut: "0",
637
680
  minAmountOut: "0",
638
681
  routes: [],
639
- error: "Missing token address"
682
+ error: ErrorMessages.QUOTE_FAILED
640
683
  };
641
684
  }
642
685
  const normalizedTokenIn = normalizeTokenId(
@@ -656,7 +699,7 @@ var AggregateDexRouter = class {
656
699
  amountOut: "0",
657
700
  minAmountOut: "0",
658
701
  routes: [],
659
- error: "Invalid token address"
702
+ error: ErrorMessages.QUOTE_FAILED
660
703
  };
661
704
  }
662
705
  const slippageBps = convertSlippageToBasisPoints(slippage);
@@ -679,7 +722,7 @@ var AggregateDexRouter = class {
679
722
  amountOut: "0",
680
723
  minAmountOut: "0",
681
724
  routes: [],
682
- error: "Failed to get quote"
725
+ error: ErrorMessages.QUOTE_FAILED
683
726
  };
684
727
  }
685
728
  const {
@@ -715,7 +758,7 @@ var AggregateDexRouter = class {
715
758
  amountOut: "0",
716
759
  minAmountOut: "0",
717
760
  routes: [],
718
- error: "Failed to get quote"
761
+ error: normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
719
762
  };
720
763
  }
721
764
  }
@@ -724,7 +767,7 @@ var AggregateDexRouter = class {
724
767
  */
725
768
  async finalizeQuote(params, depositAddress) {
726
769
  if (!requiresRecipient(params)) {
727
- throw new Error("V2 Router requires recipient parameters");
770
+ throw new Error(ErrorMessages.QUOTE_FAILED);
728
771
  }
729
772
  return await this.quote({
730
773
  ...params,
@@ -741,7 +784,7 @@ var AggregateDexRouter = class {
741
784
  if (adjustedQuote.success && adjustedQuote.routerMsg && adjustedQuote.signature) {
742
785
  return adjustedQuote;
743
786
  } else {
744
- throw new Error("Failed to get quote");
787
+ throw new Error(ErrorMessages.QUOTE_FAILED);
745
788
  }
746
789
  }
747
790
  async ensureQuoteAmountWithinBalance(quoteParams, actualBalance, context) {
@@ -773,7 +816,7 @@ var AggregateDexRouter = class {
773
816
  }
774
817
  const quote = await this.quote(quoteParams);
775
818
  if (!quote.success) {
776
- throw new Error("Failed to get quote");
819
+ throw new Error(ErrorMessages.QUOTE_FAILED);
777
820
  }
778
821
  if (quote.amountIn !== quoteParams.amountIn) {
779
822
  const apiAmountBig = new Big3(quote.amountIn);
@@ -796,26 +839,26 @@ var AggregateDexRouter = class {
796
839
  if (!requiresRecipientInExecute(params)) {
797
840
  return {
798
841
  success: false,
799
- error: "Missing sender or receiveUser"
842
+ error: ErrorMessages.QUOTE_FAILED
800
843
  };
801
844
  }
802
845
  const { quote, sender, receiveUser } = params;
803
846
  if (!quote.success) {
804
847
  return {
805
848
  success: false,
806
- error: "Invalid quote"
849
+ error: ErrorMessages.QUOTE_FAILED
807
850
  };
808
851
  }
809
852
  if (!receiveUser || receiveUser.trim() === "") {
810
853
  return {
811
854
  success: false,
812
- error: "Missing receiveUser"
855
+ error: ErrorMessages.QUOTE_FAILED
813
856
  };
814
857
  }
815
858
  if (receiveUser.startsWith("0x") && receiveUser.length === 42) {
816
859
  return {
817
860
  success: false,
818
- error: "Invalid receiveUser address"
861
+ error: ErrorMessages.QUOTE_FAILED
819
862
  };
820
863
  }
821
864
  const slippage = quote.slippage || 5e-3;
@@ -847,7 +890,7 @@ var AggregateDexRouter = class {
847
890
  } catch (error) {
848
891
  return {
849
892
  success: false,
850
- error: "Failed to get quote"
893
+ error: normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
851
894
  };
852
895
  }
853
896
  const routerMsg = finalQuote.routerMsg;
@@ -855,7 +898,7 @@ var AggregateDexRouter = class {
855
898
  if (!routerMsg || !signature) {
856
899
  return {
857
900
  success: false,
858
- error: "Failed to get quote"
901
+ error: ErrorMessages.QUOTE_FAILED
859
902
  };
860
903
  }
861
904
  const tokens = finalQuote.tokens || [];
@@ -1050,7 +1093,7 @@ var AggregateDexRouter = class {
1050
1093
  } catch (error) {
1051
1094
  return {
1052
1095
  success: false,
1053
- error: "Failed to get quote"
1096
+ error: normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
1054
1097
  };
1055
1098
  }
1056
1099
  const finalAmountToTransfer = finalQuoteForExecution.amountIn;
@@ -1081,13 +1124,13 @@ var AggregateDexRouter = class {
1081
1124
  } else {
1082
1125
  return {
1083
1126
  success: false,
1084
- error: "Execute swap failed"
1127
+ error: normalizeError(result.message) || ErrorMessages.EXECUTE_FAILED
1085
1128
  };
1086
1129
  }
1087
1130
  } catch (error) {
1088
1131
  return {
1089
1132
  success: false,
1090
- error: "Execute swap failed"
1133
+ error: normalizeError(error?.message) || ErrorMessages.EXECUTE_FAILED
1091
1134
  };
1092
1135
  }
1093
1136
  }
@@ -1314,7 +1357,7 @@ var BitgetRouter = class {
1314
1357
  amountOut: "0",
1315
1358
  minAmountOut: "0",
1316
1359
  routes: [],
1317
- error: "Missing sender or recipient"
1360
+ error: ErrorMessages.QUOTE_FAILED
1318
1361
  };
1319
1362
  }
1320
1363
  const { tokenIn, tokenOut, amountIn, slippage, sender, recipient } = params;
@@ -1327,7 +1370,7 @@ var BitgetRouter = class {
1327
1370
  amountOut: "0",
1328
1371
  minAmountOut: "0",
1329
1372
  routes: [],
1330
- error: "Missing sender or recipient"
1373
+ error: ErrorMessages.QUOTE_FAILED
1331
1374
  };
1332
1375
  }
1333
1376
  if (tokenIn?.address === void 0 || tokenOut?.address === void 0) {
@@ -1339,7 +1382,7 @@ var BitgetRouter = class {
1339
1382
  amountOut: "0",
1340
1383
  minAmountOut: "0",
1341
1384
  routes: [],
1342
- error: "Missing token address"
1385
+ error: ErrorMessages.QUOTE_FAILED
1343
1386
  };
1344
1387
  }
1345
1388
  const normalizedTokenIn = tokenIn.address === "" ? "" : this.normalizeEvmAddress(tokenIn.address);
@@ -1361,7 +1404,7 @@ var BitgetRouter = class {
1361
1404
  if (!isBitgetResponseSuccess(response) || !response.data) {
1362
1405
  return createQuoteError(
1363
1406
  params,
1364
- response.msg || "Failed to get quote"
1407
+ normalizeError(response.msg) || ErrorMessages.QUOTE_FAILED
1365
1408
  );
1366
1409
  }
1367
1410
  const {
@@ -1427,21 +1470,21 @@ var BitgetRouter = class {
1427
1470
  } catch (error) {
1428
1471
  return createQuoteError(
1429
1472
  params,
1430
- error?.message || "Failed to get quote"
1473
+ normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
1431
1474
  );
1432
1475
  }
1433
1476
  }
1434
1477
  async executeSwap(params) {
1435
1478
  try {
1436
1479
  if (!requiresRecipientInExecute(params)) {
1437
- return createExecuteError("Missing sender or receiveUser");
1480
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1438
1481
  }
1439
1482
  const { quote, sender, receiveUser } = params;
1440
1483
  if (!quote.success) {
1441
- return createExecuteError("Invalid quote");
1484
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1442
1485
  }
1443
1486
  if (!receiveUser || receiveUser.trim() === "") {
1444
- return createExecuteError("Missing receiveUser");
1487
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1445
1488
  }
1446
1489
  let market;
1447
1490
  try {
@@ -1449,13 +1492,13 @@ var BitgetRouter = class {
1449
1492
  const routerMsg = JSON.parse(quote.routerMsg);
1450
1493
  market = routerMsg.market || "";
1451
1494
  } else {
1452
- return createExecuteError("Missing market from quote, please re-fetch quote");
1495
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1453
1496
  }
1454
1497
  } catch (error) {
1455
- return createExecuteError("Invalid quote format: missing market");
1498
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1456
1499
  }
1457
1500
  if (!market) {
1458
- return createExecuteError("Missing market from quote response");
1501
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1459
1502
  }
1460
1503
  const normalizedTokenIn = this.normalizeEvmAddress(
1461
1504
  quote.tokenIn.address
@@ -1479,7 +1522,7 @@ var BitgetRouter = class {
1479
1522
  });
1480
1523
  if (!isBitgetResponseSuccess(reQuoteResponse) || !reQuoteResponse.data) {
1481
1524
  return createExecuteError(
1482
- `Re-quote failed: ${reQuoteResponse.msg || "Please refresh quote and try again"}`
1525
+ normalizeError(reQuoteResponse.msg) || ErrorMessages.QUOTE_FAILED
1483
1526
  );
1484
1527
  }
1485
1528
  market = reQuoteResponse.data?.market || market;
@@ -1499,13 +1542,11 @@ var BitgetRouter = class {
1499
1542
  });
1500
1543
  if (!isBitgetResponseSuccess(swapResponse) || !swapResponse.data) {
1501
1544
  return createExecuteError(
1502
- swapResponse.msg || "Failed to get swap calldata"
1545
+ normalizeError(swapResponse.msg) || ErrorMessages.QUOTE_FAILED
1503
1546
  );
1504
1547
  }
1505
1548
  if (swapResponse.data?.estimateRevert === true) {
1506
- return createExecuteError(
1507
- "Transaction will fail on-chain (slippage too high or price changed). Please refresh quote."
1508
- );
1549
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1509
1550
  }
1510
1551
  let transactionData = swapResponse.data?.calldata || swapResponse.data?.data;
1511
1552
  const to = swapResponse.data?.contract || swapResponse.data?.to;
@@ -1519,14 +1560,14 @@ var BitgetRouter = class {
1519
1560
  }
1520
1561
  const gas = swapResponse.data?.gas || (swapResponse.data?.computeUnits !== void 0 ? String(swapResponse.data.computeUnits) : void 0);
1521
1562
  if (!to || !transactionData) {
1522
- return createExecuteError("Invalid swap response: missing to or data");
1563
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1523
1564
  }
1524
1565
  if (transactionData.length < 10 || !/^0x[0-9a-fA-F]+$/.test(transactionData)) {
1525
- return createExecuteError("Invalid calldata format: must be hex string starting with 0x");
1566
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1526
1567
  }
1527
1568
  if (normalizedTokenIn && normalizedTokenIn !== "") {
1528
1569
  if (!this.evmChainAdapter.getBalance) {
1529
- return createExecuteError("getBalance method not available on evmChainAdapter");
1570
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1530
1571
  }
1531
1572
  const tokenBalanceFormatted = await this.evmChainAdapter.getBalance({
1532
1573
  address: sender,
@@ -1536,9 +1577,7 @@ var BitgetRouter = class {
1536
1577
  const balanceBN = ethers.utils.parseUnits(tokenBalanceFormatted || "0", tokenDecimals);
1537
1578
  const amountInBN = ethers.BigNumber.from(quote.amountIn);
1538
1579
  if (balanceBN.lt(amountInBN)) {
1539
- return createExecuteError(
1540
- `Insufficient token balance: have ${tokenBalanceFormatted}, need ${ethers.utils.formatUnits(amountInBN, tokenDecimals)}`
1541
- );
1580
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1542
1581
  }
1543
1582
  const currentAllowance = await this.evmChainAdapter.getAllowance({
1544
1583
  tokenAddress: normalizedTokenIn,
@@ -1548,7 +1587,7 @@ var BitgetRouter = class {
1548
1587
  const allowanceBN = ethers.BigNumber.from(currentAllowance);
1549
1588
  if (allowanceBN.lt(amountInBN)) {
1550
1589
  try {
1551
- const approveResult = await this.evmChainAdapter.approve({
1590
+ await this.evmChainAdapter.approve({
1552
1591
  tokenAddress: normalizedTokenIn,
1553
1592
  spender: to,
1554
1593
  amount: ethers.constants.MaxUint256.toString()
@@ -1571,19 +1610,17 @@ var BitgetRouter = class {
1571
1610
  retryCount++;
1572
1611
  }
1573
1612
  if (newAllowanceBN.lt(amountInBN)) {
1574
- return createExecuteError(
1575
- `Token approval insufficient after ${MAX_APPROVAL_RETRIES} retries. Approval tx: ${approveResult.txHash}`
1576
- );
1613
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1577
1614
  }
1578
1615
  } catch (error) {
1579
1616
  return createExecuteError(
1580
- `Token approval failed: ${error?.message || "Unknown error"}`
1617
+ normalizeError(error?.message) || ErrorMessages.QUOTE_FAILED
1581
1618
  );
1582
1619
  }
1583
1620
  }
1584
1621
  } else {
1585
1622
  if (!this.evmChainAdapter.getBalance) {
1586
- return createExecuteError("getBalance method not available on evmChainAdapter");
1623
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1587
1624
  }
1588
1625
  const nativeBalanceFormatted = await this.evmChainAdapter.getBalance({
1589
1626
  address: sender,
@@ -1607,9 +1644,7 @@ var BitgetRouter = class {
1607
1644
  const gasCostEstimate = estimatedGasLimitForBalance.mul(gasPriceEstimate2);
1608
1645
  const totalRequired = amountInBN.add(gasCostEstimate);
1609
1646
  if (balanceBN.lt(totalRequired)) {
1610
- return createExecuteError(
1611
- `Insufficient native token balance: have ${nativeBalanceFormatted} ETH, need ${ethers.utils.formatEther(totalRequired)} ETH`
1612
- );
1647
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1613
1648
  }
1614
1649
  }
1615
1650
  if (normalizedTokenIn && normalizedTokenIn !== "") {
@@ -1621,9 +1656,7 @@ var BitgetRouter = class {
1621
1656
  const finalAllowanceBN = ethers.BigNumber.from(finalAllowanceCheck);
1622
1657
  const amountInBN = ethers.BigNumber.from(quote.amountIn);
1623
1658
  if (finalAllowanceBN.lt(amountInBN)) {
1624
- return createExecuteError(
1625
- `Insufficient allowance: current ${finalAllowanceBN.toString()}, required ${amountInBN.toString()}`
1626
- );
1659
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1627
1660
  }
1628
1661
  }
1629
1662
  const [estimatedGasLimit, hasReliableEstimate, rpcEstimateError] = await estimateGasLimit(
@@ -1644,14 +1677,10 @@ var BitgetRouter = class {
1644
1677
  tokenOut: quote.tokenOut.symbol,
1645
1678
  rpcError: rpcEstimateError
1646
1679
  });
1647
- return createExecuteError(
1648
- "Insufficient liquidity, transaction may fail. Please refresh quote and try again."
1649
- );
1680
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1650
1681
  }
1651
1682
  if (!gas || gas === "0") {
1652
- return createExecuteError(
1653
- "Unable to estimate gas fee, possibly due to insufficient liquidity. Please refresh quote and try again."
1654
- );
1683
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1655
1684
  }
1656
1685
  logger.warn("RPC gas estimation failed, using Bitget estimate", {
1657
1686
  chainId: this.chainId,
@@ -1684,7 +1713,7 @@ var BitgetRouter = class {
1684
1713
  if (!feeData.maxFeePerGas || !feeData.maxPriorityFeePerGas || feeData.maxFeePerGas.lte(0) || feeData.maxPriorityFeePerGas.lte(0)) {
1685
1714
  const cachedGasPrice = await getCachedGasPrice();
1686
1715
  if (!cachedGasPrice || cachedGasPrice.lte(0)) {
1687
- return createExecuteError("Failed to get valid gas price. Please try again.");
1716
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1688
1717
  }
1689
1718
  feeData.maxFeePerGas = cachedGasPrice;
1690
1719
  feeData.maxPriorityFeePerGas = cachedGasPrice.div(10);
@@ -1717,27 +1746,27 @@ var BitgetRouter = class {
1717
1746
  } catch (error) {
1718
1747
  const cachedGasPrice = await getCachedGasPrice();
1719
1748
  if (!cachedGasPrice || cachedGasPrice.lte(0)) {
1720
- return createExecuteError("Failed to get valid gas price. Please try again.");
1749
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1721
1750
  }
1722
1751
  feeData.gasPrice = cachedGasPrice;
1723
1752
  }
1724
1753
  }
1725
1754
  if (!to || !ethers.utils.isAddress(to)) {
1726
- return createExecuteError(`Invalid contract address: ${to}`);
1755
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1727
1756
  }
1728
1757
  if (!transactionData || transactionData.length < 10) {
1729
- return createExecuteError(`Invalid calldata: length ${transactionData?.length || 0}`);
1758
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1730
1759
  }
1731
1760
  if (!estimatedGasLimit || estimatedGasLimit.lte(0)) {
1732
- return createExecuteError("Invalid gas limit estimate. Please refresh quote and try again.");
1761
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1733
1762
  }
1734
1763
  if (supportsEip1559) {
1735
1764
  if (!feeData.maxFeePerGas || !feeData.maxPriorityFeePerGas || feeData.maxFeePerGas.lte(0) || feeData.maxPriorityFeePerGas.lte(0)) {
1736
- return createExecuteError("Invalid gas fee data. Please try again.");
1765
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1737
1766
  }
1738
1767
  } else {
1739
1768
  if (!feeData.gasPrice || feeData.gasPrice.lte(0)) {
1740
- return createExecuteError("Invalid gas price. Please try again.");
1769
+ return createExecuteError(ErrorMessages.QUOTE_FAILED);
1741
1770
  }
1742
1771
  }
1743
1772
  const txParams = {
@@ -1761,10 +1790,10 @@ var BitgetRouter = class {
1761
1790
  txHashArray: result.txHash ? [result.txHash] : []
1762
1791
  };
1763
1792
  } else {
1764
- return createExecuteError(result.message || "Execute swap failed");
1793
+ return createExecuteError(normalizeError(result.message) || ErrorMessages.EXECUTE_FAILED);
1765
1794
  }
1766
1795
  } catch (error) {
1767
- return createExecuteError(error?.message || "Execute swap failed");
1796
+ return createExecuteError(normalizeError(error?.message) || ErrorMessages.EXECUTE_FAILED);
1768
1797
  }
1769
1798
  }
1770
1799
  normalizeEvmAddress(address) {
@@ -1805,13 +1834,13 @@ async function completeQuote(params, config) {
1805
1834
  const routers = dexRouters || (dexRouter ? [dexRouter] : []);
1806
1835
  const userAddress = currentUserAddress || recipient;
1807
1836
  if (!userAddress) {
1808
- throw new Error("currentUserAddress or recipient is required for routers that require recipient");
1837
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1809
1838
  }
1810
1839
  if (sourceToken?.address === void 0) {
1811
- throw new Error("Source token address is required");
1840
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1812
1841
  }
1813
1842
  if (targetToken?.address === void 0) {
1814
- throw new Error("Target token address is required");
1843
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1815
1844
  }
1816
1845
  const isEvmChain = evmChainId !== void 0 || sourceChain === "evm" || sourceChain === "ethereum" || sourceChain === "bsc" || sourceChain === "polygon" || sourceChain === "base" || sourceChain === "monad" || sourceToken.chain === "evm";
1817
1846
  const isTokenIntentsSupported = customIsIntentsSupportedToken ? customIsIntentsSupportedToken(sourceToken) : isEvmChain ? isEvmIntentsSupportedToken(sourceToken, bluechipTokens) : isNearIntentsSupportedToken(sourceToken, bluechipTokens);
@@ -1820,7 +1849,7 @@ async function completeQuote(params, config) {
1820
1849
  configAdapter.getEvmNativeWrappedTokenAddress?.()
1821
1850
  ) : findBestBluechipToken(bluechipTokens, wrapNearContractId);
1822
1851
  if (!bluechipToken?.address) {
1823
- throw new Error("Failed to find bluechip token address");
1852
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1824
1853
  }
1825
1854
  const quotePaths = [];
1826
1855
  routers.forEach((router, index) => {
@@ -1854,7 +1883,7 @@ async function completeQuote(params, config) {
1854
1883
  promise: (async () => {
1855
1884
  const preSwapQuote = await router.quote(quoteParams);
1856
1885
  if (!preSwapQuote.success) {
1857
- throw new Error(`Pre-swap quote failed: ${preSwapQuote.error || "Unknown error"}`);
1886
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1858
1887
  }
1859
1888
  let normalizedSourceAsset;
1860
1889
  if (isEvmChain) {
@@ -1882,11 +1911,11 @@ async function completeQuote(params, config) {
1882
1911
  try {
1883
1912
  const amountBN = new Big3(preSwapQuote.amountOut);
1884
1913
  if (amountBN.lte(0)) {
1885
- throw new Error(`Invalid amountOut: ${preSwapQuote.amountOut}`);
1914
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1886
1915
  }
1887
1916
  formattedAmountOut = amountBN.toFixed(0, Big3.roundDown);
1888
1917
  } catch (error) {
1889
- throw new Error(`Failed to process amountOut: ${error?.message || String(error)}`);
1918
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1890
1919
  }
1891
1920
  }
1892
1921
  try {
@@ -1902,7 +1931,7 @@ async function completeQuote(params, config) {
1902
1931
  ...appFees ? { appFees } : {}
1903
1932
  });
1904
1933
  if (intentsQuote.quoteStatus !== "success") {
1905
- throw new Error(`Intents quote failed: ${intentsQuote.message || "Unknown error"}`);
1934
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1906
1935
  }
1907
1936
  return {
1908
1937
  intentsQuote,
@@ -1965,7 +1994,7 @@ async function completeQuote(params, config) {
1965
1994
  ...customRecipientMsg ? { customRecipientMsg } : {}
1966
1995
  });
1967
1996
  if (intentsQuote.quoteStatus !== "success") {
1968
- throw new Error("Failed to get quote");
1997
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1969
1998
  }
1970
1999
  return {
1971
2000
  intentsQuote,
@@ -1988,7 +2017,7 @@ async function completeQuote(params, config) {
1988
2017
  }
1989
2018
  });
1990
2019
  if (validPaths.length === 0) {
1991
- throw new Error("Failed to get quote");
2020
+ throw new Error(ErrorMessages.QUOTE_FAILED);
1992
2021
  }
1993
2022
  const bestPath = validPaths.reduce((best, current) => {
1994
2023
  const bestAmount = new Big3(best.finalAmountOut);
@@ -1997,7 +2026,7 @@ async function completeQuote(params, config) {
1997
2026
  });
1998
2027
  const depositAddress = bestPath.intentsQuote.quoteSuccessResult?.quote?.depositAddress || "";
1999
2028
  if (!depositAddress) {
2000
- throw new Error("Deposit address not found in intents quote");
2029
+ throw new Error(ErrorMessages.QUOTE_FAILED);
2001
2030
  }
2002
2031
  return {
2003
2032
  intents: {
@@ -2064,11 +2093,12 @@ async function quoteSameChainSwap(params, dexRouters) {
2064
2093
  }
2065
2094
  return null;
2066
2095
  }).filter(Boolean);
2067
- throw new Error(`All router quotes failed: ${errors.join("; ")}`);
2096
+ const errorMessage = errors.length > 0 ? `${ErrorMessages.QUOTE_FAILED}: ${errors.join("; ")}` : ErrorMessages.QUOTE_FAILED;
2097
+ throw new Error(errorMessage);
2068
2098
  }
2069
2099
  return selectBestQuote(validQuotes);
2070
2100
  }
2071
2101
 
2072
- export { AggregateDexRouter, BitgetRouter, NearSmartRouter, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, findBestEvmBluechipToken, formatGasString, formatGasToTgas, getBluechipTokensConfig, isEvmIntentsSupportedToken, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeEvmAddress, normalizeTokenId, quoteSameChainSwap, requiresRecipient, requiresRecipientInExecute, selectBestQuote, setBluechipTokensConfig };
2102
+ export { AggregateDexRouter, BitgetRouter, ErrorMessages, NearSmartRouter, TRANSACTION_EXECUTION_ERROR_MESSAGE, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, findBestEvmBluechipToken, formatGasString, formatGasToTgas, getBluechipTokensConfig, getErrorMessage, isEvmIntentsSupportedToken, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeError, normalizeEvmAddress, normalizeTokenId, processErrorMessage, quoteSameChainSwap, requiresRecipient, requiresRecipientInExecute, selectBestQuote, setBluechipTokensConfig };
2073
2103
  //# sourceMappingURL=index.mjs.map
2074
2104
  //# sourceMappingURL=index.mjs.map