@stableflow/bridges 3.1.1 → 3.1.2

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
@@ -84,7 +84,7 @@ var OneClickService = class {
84
84
  }
85
85
  async formatQuoteData(res) {
86
86
  const { params } = res;
87
- const { isProxy = true, prices } = params;
87
+ const { isProxy = true, prices, forceCalculateFee = true } = params;
88
88
  const isExactOutput = params.swapType === OneClickSwapType.Output;
89
89
  getPrice(prices, params.fromToken.nativeToken.symbol);
90
90
  params.fromToken.nativeToken.decimals;
@@ -129,7 +129,7 @@ var OneClickService = class {
129
129
  }
130
130
  let destinationGasFee = Big(netFee).minus(bridgeFeeValue);
131
131
  destinationGasFee = Big(destinationGasFee).lt(0) ? Big(0) : destinationGasFee;
132
- if (fromTokenSymbol !== toTokenSymbol) {
132
+ if (!forceCalculateFee && fromTokenSymbol !== toTokenSymbol) {
133
133
  destinationGasFee = Big(0);
134
134
  }
135
135
  res.data.fees = {
@@ -728,46 +728,6 @@ function parseUserFriendlyTonAddress(address) {
728
728
  isTestOnly
729
729
  };
730
730
  }
731
- var formatQuoteError = (error, options) => {
732
- const { service, fromToken } = options;
733
- const defaultErrorMessage = "Failed to get quote, please try again later";
734
- if (service === Service.OneClick) {
735
- const getQuoteErrorMessage = () => {
736
- const _messageResult = {
737
- message: error?.message || defaultErrorMessage,
738
- sourceMessage: error?.response?.data?.message || defaultErrorMessage
739
- };
740
- if (error?.response?.data?.message && error?.response?.data?.message !== "Internal server error") {
741
- if (error?.response?.data?.message === "Failed to get quote") {
742
- _messageResult.message = "Amount exceeds max";
743
- return _messageResult;
744
- }
745
- if (error?.response?.data?.message?.includes("Amount is too low for bridge, try at least")) {
746
- const match = error.response.data.message.match(/try at least\s+(\d+(?:\.\d+)?)/i);
747
- let minimumAmount = match ? match[1] : Big(1).times(10 ** fromToken.decimals).toFixed(0);
748
- minimumAmount = Big(minimumAmount).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
749
- _messageResult.message = `Amount is too low, at least ${minimumAmount}`;
750
- return _messageResult;
751
- }
752
- return _messageResult;
753
- }
754
- return _messageResult;
755
- };
756
- const onclickErrMsg = getQuoteErrorMessage();
757
- return {
758
- serviceType: service,
759
- error: onclickErrMsg.message
760
- };
761
- }
762
- return {
763
- serviceType: service,
764
- error: error?.message || defaultErrorMessage
765
- };
766
- };
767
- async function quoteSignature(params) {
768
- const response = await postRequest("/v0/cctp/sign", params);
769
- return response.data ?? {};
770
- }
771
731
  var addThousandSeparator = (numberString) => {
772
732
  if (!numberString) return "0";
773
733
  const parts = String(numberString).split(".");
@@ -871,6 +831,54 @@ var formatNumber = (value, precision, isSimple, options) => {
871
831
  };
872
832
  };
873
833
 
834
+ // src/utils/error.ts
835
+ var formatQuoteError = (error, options) => {
836
+ const { service, fromToken } = options;
837
+ const defaultErrorMessage = "Failed to get quote, please try again later";
838
+ if ([Service.OneClick, Service.OneClickUsdt0, Service.Usdt0OneClick, Service.CCTPOneClick, Service.OneClickCCTP, Service.FraxZeroOneClick, Service.OneClickFraxZero].includes(service)) {
839
+ const getQuoteErrorMessage = () => {
840
+ const apiMessage = error?.body?.message || error?.response?.data?.message;
841
+ const _messageResult = {
842
+ message: error?.message || defaultErrorMessage,
843
+ sourceMessage: apiMessage || defaultErrorMessage
844
+ };
845
+ if (apiMessage && apiMessage !== "Internal server error") {
846
+ if (apiMessage === "Failed to get quote") {
847
+ _messageResult.message = "Amount exceeds max";
848
+ return _messageResult;
849
+ }
850
+ if (apiMessage.includes("Amount is too low for bridge, try at least")) {
851
+ const match = apiMessage.match(/try at least\s+(\d+(?:\.\d+)?)/i);
852
+ const minWei = match ? match[1] : Big(1).times(10 ** fromToken.decimals).toFixed(0);
853
+ const minAmount = Big(minWei).div(10 ** fromToken.decimals);
854
+ const readableAmount = formatNumber(minAmount, fromToken.decimals, true);
855
+ _messageResult.message = `Amount is too low, at least ${readableAmount} ${fromToken.symbol}`;
856
+ return _messageResult;
857
+ }
858
+ if (apiMessage.includes("Cannot convert undefined or null to object")) {
859
+ _messageResult.message = "app fees exceeds 5% of amount";
860
+ return _messageResult;
861
+ }
862
+ return _messageResult;
863
+ }
864
+ return _messageResult;
865
+ };
866
+ const onclickErrMsg = getQuoteErrorMessage();
867
+ return {
868
+ serviceType: service,
869
+ error: onclickErrMsg.message
870
+ };
871
+ }
872
+ return {
873
+ serviceType: service,
874
+ error: error?.message || defaultErrorMessage
875
+ };
876
+ };
877
+ async function quoteSignature(params) {
878
+ const response = await postRequest("/v0/cctp/sign", params);
879
+ return response.data ?? {};
880
+ }
881
+
874
882
  // src/usdt0/config.ts
875
883
  var USDT0_CONFIG = {
876
884
  Ethereum: {
@@ -6241,6 +6249,7 @@ var BridgeSFA = class _BridgeSFA {
6241
6249
  _params.appFees = params.oneclickParams?.appFees || params.appFees;
6242
6250
  _params.swapType = params.oneclickParams?.swapType;
6243
6251
  _params.isProxy = params.oneclickParams?.isProxy;
6252
+ _params.forceCalculateFee = params.oneclickParams?.forceCalculateFee;
6244
6253
  }
6245
6254
  if ([
6246
6255
  Service.Usdt0,