@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.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +51 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -42
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -147,6 +147,8 @@ interface GetAllQuoteParams {
|
|
|
147
147
|
}[];
|
|
148
148
|
swapType?: OneClickSwapType;
|
|
149
149
|
isProxy?: boolean;
|
|
150
|
+
/** When true (default), always calculate destination gas fee. When false, fee is 0 if fromTokenSymbol !== toTokenSymbol. */
|
|
151
|
+
forceCalculateFee?: boolean;
|
|
150
152
|
};
|
|
151
153
|
}
|
|
152
154
|
/**
|
|
@@ -230,10 +232,7 @@ declare const formatQuoteError: (error: any, options: {
|
|
|
230
232
|
service: Service;
|
|
231
233
|
fromToken: TokenConfig;
|
|
232
234
|
}) => {
|
|
233
|
-
serviceType:
|
|
234
|
-
error: string;
|
|
235
|
-
} | {
|
|
236
|
-
serviceType: "usdt0" | "cctp" | "fraxzero" | "fraxzero-oneclick" | "oneclick-fraxzero" | "usdt0-oneclick" | "oneclick-usdt0" | "cctp-oneclick" | "oneclick-cctp" | "native";
|
|
235
|
+
serviceType: Service;
|
|
237
236
|
error: any;
|
|
238
237
|
};
|
|
239
238
|
|
package/dist/index.d.ts
CHANGED
|
@@ -147,6 +147,8 @@ interface GetAllQuoteParams {
|
|
|
147
147
|
}[];
|
|
148
148
|
swapType?: OneClickSwapType;
|
|
149
149
|
isProxy?: boolean;
|
|
150
|
+
/** When true (default), always calculate destination gas fee. When false, fee is 0 if fromTokenSymbol !== toTokenSymbol. */
|
|
151
|
+
forceCalculateFee?: boolean;
|
|
150
152
|
};
|
|
151
153
|
}
|
|
152
154
|
/**
|
|
@@ -230,10 +232,7 @@ declare const formatQuoteError: (error: any, options: {
|
|
|
230
232
|
service: Service;
|
|
231
233
|
fromToken: TokenConfig;
|
|
232
234
|
}) => {
|
|
233
|
-
serviceType:
|
|
234
|
-
error: string;
|
|
235
|
-
} | {
|
|
236
|
-
serviceType: "usdt0" | "cctp" | "fraxzero" | "fraxzero-oneclick" | "oneclick-fraxzero" | "usdt0-oneclick" | "oneclick-usdt0" | "cctp-oneclick" | "oneclick-cctp" | "native";
|
|
235
|
+
serviceType: Service;
|
|
237
236
|
error: any;
|
|
238
237
|
};
|
|
239
238
|
|
package/dist/index.js
CHANGED
|
@@ -91,7 +91,7 @@ var OneClickService = class {
|
|
|
91
91
|
}
|
|
92
92
|
async formatQuoteData(res) {
|
|
93
93
|
const { params } = res;
|
|
94
|
-
const { isProxy = true, prices } = params;
|
|
94
|
+
const { isProxy = true, prices, forceCalculateFee = true } = params;
|
|
95
95
|
const isExactOutput = params.swapType === core.OneClickSwapType.Output;
|
|
96
96
|
core.getPrice(prices, params.fromToken.nativeToken.symbol);
|
|
97
97
|
params.fromToken.nativeToken.decimals;
|
|
@@ -136,7 +136,7 @@ var OneClickService = class {
|
|
|
136
136
|
}
|
|
137
137
|
let destinationGasFee = Big__default.default(netFee).minus(bridgeFeeValue);
|
|
138
138
|
destinationGasFee = Big__default.default(destinationGasFee).lt(0) ? Big__default.default(0) : destinationGasFee;
|
|
139
|
-
if (fromTokenSymbol !== toTokenSymbol) {
|
|
139
|
+
if (!forceCalculateFee && fromTokenSymbol !== toTokenSymbol) {
|
|
140
140
|
destinationGasFee = Big__default.default(0);
|
|
141
141
|
}
|
|
142
142
|
res.data.fees = {
|
|
@@ -735,46 +735,6 @@ function parseUserFriendlyTonAddress(address) {
|
|
|
735
735
|
isTestOnly
|
|
736
736
|
};
|
|
737
737
|
}
|
|
738
|
-
var formatQuoteError = (error, options) => {
|
|
739
|
-
const { service, fromToken } = options;
|
|
740
|
-
const defaultErrorMessage = "Failed to get quote, please try again later";
|
|
741
|
-
if (service === core.Service.OneClick) {
|
|
742
|
-
const getQuoteErrorMessage = () => {
|
|
743
|
-
const _messageResult = {
|
|
744
|
-
message: error?.message || defaultErrorMessage,
|
|
745
|
-
sourceMessage: error?.response?.data?.message || defaultErrorMessage
|
|
746
|
-
};
|
|
747
|
-
if (error?.response?.data?.message && error?.response?.data?.message !== "Internal server error") {
|
|
748
|
-
if (error?.response?.data?.message === "Failed to get quote") {
|
|
749
|
-
_messageResult.message = "Amount exceeds max";
|
|
750
|
-
return _messageResult;
|
|
751
|
-
}
|
|
752
|
-
if (error?.response?.data?.message?.includes("Amount is too low for bridge, try at least")) {
|
|
753
|
-
const match = error.response.data.message.match(/try at least\s+(\d+(?:\.\d+)?)/i);
|
|
754
|
-
let minimumAmount = match ? match[1] : Big__default.default(1).times(10 ** fromToken.decimals).toFixed(0);
|
|
755
|
-
minimumAmount = Big__default.default(minimumAmount).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
|
|
756
|
-
_messageResult.message = `Amount is too low, at least ${minimumAmount}`;
|
|
757
|
-
return _messageResult;
|
|
758
|
-
}
|
|
759
|
-
return _messageResult;
|
|
760
|
-
}
|
|
761
|
-
return _messageResult;
|
|
762
|
-
};
|
|
763
|
-
const onclickErrMsg = getQuoteErrorMessage();
|
|
764
|
-
return {
|
|
765
|
-
serviceType: service,
|
|
766
|
-
error: onclickErrMsg.message
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
|
-
return {
|
|
770
|
-
serviceType: service,
|
|
771
|
-
error: error?.message || defaultErrorMessage
|
|
772
|
-
};
|
|
773
|
-
};
|
|
774
|
-
async function quoteSignature(params) {
|
|
775
|
-
const response = await core.postRequest("/v0/cctp/sign", params);
|
|
776
|
-
return response.data ?? {};
|
|
777
|
-
}
|
|
778
738
|
var addThousandSeparator = (numberString) => {
|
|
779
739
|
if (!numberString) return "0";
|
|
780
740
|
const parts = String(numberString).split(".");
|
|
@@ -878,6 +838,54 @@ var formatNumber = (value, precision, isSimple, options) => {
|
|
|
878
838
|
};
|
|
879
839
|
};
|
|
880
840
|
|
|
841
|
+
// src/utils/error.ts
|
|
842
|
+
var formatQuoteError = (error, options) => {
|
|
843
|
+
const { service, fromToken } = options;
|
|
844
|
+
const defaultErrorMessage = "Failed to get quote, please try again later";
|
|
845
|
+
if ([core.Service.OneClick, core.Service.OneClickUsdt0, core.Service.Usdt0OneClick, core.Service.CCTPOneClick, core.Service.OneClickCCTP, core.Service.FraxZeroOneClick, core.Service.OneClickFraxZero].includes(service)) {
|
|
846
|
+
const getQuoteErrorMessage = () => {
|
|
847
|
+
const apiMessage = error?.body?.message || error?.response?.data?.message;
|
|
848
|
+
const _messageResult = {
|
|
849
|
+
message: error?.message || defaultErrorMessage,
|
|
850
|
+
sourceMessage: apiMessage || defaultErrorMessage
|
|
851
|
+
};
|
|
852
|
+
if (apiMessage && apiMessage !== "Internal server error") {
|
|
853
|
+
if (apiMessage === "Failed to get quote") {
|
|
854
|
+
_messageResult.message = "Amount exceeds max";
|
|
855
|
+
return _messageResult;
|
|
856
|
+
}
|
|
857
|
+
if (apiMessage.includes("Amount is too low for bridge, try at least")) {
|
|
858
|
+
const match = apiMessage.match(/try at least\s+(\d+(?:\.\d+)?)/i);
|
|
859
|
+
const minWei = match ? match[1] : Big__default.default(1).times(10 ** fromToken.decimals).toFixed(0);
|
|
860
|
+
const minAmount = Big__default.default(minWei).div(10 ** fromToken.decimals);
|
|
861
|
+
const readableAmount = formatNumber(minAmount, fromToken.decimals, true);
|
|
862
|
+
_messageResult.message = `Amount is too low, at least ${readableAmount} ${fromToken.symbol}`;
|
|
863
|
+
return _messageResult;
|
|
864
|
+
}
|
|
865
|
+
if (apiMessage.includes("Cannot convert undefined or null to object")) {
|
|
866
|
+
_messageResult.message = "app fees exceeds 5% of amount";
|
|
867
|
+
return _messageResult;
|
|
868
|
+
}
|
|
869
|
+
return _messageResult;
|
|
870
|
+
}
|
|
871
|
+
return _messageResult;
|
|
872
|
+
};
|
|
873
|
+
const onclickErrMsg = getQuoteErrorMessage();
|
|
874
|
+
return {
|
|
875
|
+
serviceType: service,
|
|
876
|
+
error: onclickErrMsg.message
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
return {
|
|
880
|
+
serviceType: service,
|
|
881
|
+
error: error?.message || defaultErrorMessage
|
|
882
|
+
};
|
|
883
|
+
};
|
|
884
|
+
async function quoteSignature(params) {
|
|
885
|
+
const response = await core.postRequest("/v0/cctp/sign", params);
|
|
886
|
+
return response.data ?? {};
|
|
887
|
+
}
|
|
888
|
+
|
|
881
889
|
// src/usdt0/config.ts
|
|
882
890
|
var USDT0_CONFIG = {
|
|
883
891
|
Ethereum: {
|
|
@@ -6248,6 +6256,7 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6248
6256
|
_params.appFees = params.oneclickParams?.appFees || params.appFees;
|
|
6249
6257
|
_params.swapType = params.oneclickParams?.swapType;
|
|
6250
6258
|
_params.isProxy = params.oneclickParams?.isProxy;
|
|
6259
|
+
_params.forceCalculateFee = params.oneclickParams?.forceCalculateFee;
|
|
6251
6260
|
}
|
|
6252
6261
|
if ([
|
|
6253
6262
|
core.Service.Usdt0,
|