@stableflow/bridges 3.1.1 → 3.1.3-rc-45fcf7f0b6-20260730
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 +65 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
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: {
|
|
@@ -5570,55 +5578,24 @@ var CCTPOneClickService = class {
|
|
|
5570
5578
|
refundTo: evmAddress,
|
|
5571
5579
|
wallet: evmWallet
|
|
5572
5580
|
};
|
|
5573
|
-
|
|
5574
|
-
let
|
|
5575
|
-
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
...oneClickParams,
|
|
5579
|
-
amountWei: Big(0.01).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0)
|
|
5580
|
-
});
|
|
5581
|
-
execTime.log("CCTPOneClickService.quote", "oneClickService.quote: %o", oneClickResult);
|
|
5582
|
-
if (oneClickResult.errMsg) {
|
|
5583
|
-
return oneClickResult;
|
|
5584
|
-
}
|
|
5585
|
-
cctpParams.recipient = oneClickResult.quote.depositAddress;
|
|
5586
|
-
execTime.breakpoint();
|
|
5587
|
-
cctpResult = await cctp_default.quote(cctpParams);
|
|
5588
|
-
execTime.log("CCTPOneClickService.quote", "cctpService.quote: %o", cctpResult);
|
|
5589
|
-
execTime.breakpoint();
|
|
5590
|
-
try {
|
|
5591
|
-
const oneClickResult2 = await oneclick_default.quote({
|
|
5592
|
-
...oneClickParams,
|
|
5593
|
-
dry: true,
|
|
5594
|
-
amountWei: Big(cctpResult.outputAmount || 0).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0)
|
|
5595
|
-
});
|
|
5596
|
-
oneClickResult.fees = oneClickResult2.fees;
|
|
5597
|
-
oneClickResult.outputAmount = oneClickResult2.outputAmount;
|
|
5598
|
-
oneClickResult.estimateTime = oneClickResult2.estimateTime;
|
|
5599
|
-
oneClickResult.priceImpact = oneClickResult2.priceImpact;
|
|
5600
|
-
oneClickResult.exchangeRate = oneClickResult2.exchangeRate;
|
|
5601
|
-
execTime.log("CCTPOneClickService.quote", "confirm get actual output amount result: %o", oneClickResult2);
|
|
5602
|
-
} catch (err) {
|
|
5603
|
-
execTime.log("CCTPOneClickService.quote", "confirm get actual output amount error: %o", err);
|
|
5604
|
-
}
|
|
5605
|
-
} else {
|
|
5606
|
-
execTime.breakpoint();
|
|
5607
|
-
cctpResult = await cctp_default.quote(cctpParams);
|
|
5608
|
-
execTime.log("CCTPOneClickService.quote", "cctpService.quote dry: %o", cctpResult);
|
|
5609
|
-
if (cctpResult.errMsg) {
|
|
5610
|
-
return cctpResult;
|
|
5611
|
-
}
|
|
5612
|
-
oneClickParams.amountWei = Big(cctpResult.outputAmount || 0).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0);
|
|
5613
|
-
execTime.breakpoint();
|
|
5614
|
-
oneClickResult = await oneclick_default.quote(oneClickParams);
|
|
5615
|
-
execTime.log("CCTPOneClickService.quote", "oneClickService.quote: %o", oneClickResult);
|
|
5581
|
+
execTime.breakpoint();
|
|
5582
|
+
let cctpResult = await cctp_default.quote(cctpParams);
|
|
5583
|
+
execTime.log("cctpService.quote: %o", cctpResult);
|
|
5584
|
+
if (cctpResult.errMsg) {
|
|
5585
|
+
return cctpResult;
|
|
5616
5586
|
}
|
|
5587
|
+
oneClickParams.amountWei = Big(cctpResult.outputAmount || 0).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0);
|
|
5588
|
+
execTime.breakpoint();
|
|
5589
|
+
const oneClickResult = await oneclick_default.quote(oneClickParams);
|
|
5590
|
+
execTime.log("oneClickService.quote: %o", oneClickResult);
|
|
5617
5591
|
if (oneClickResult.errMsg) {
|
|
5618
5592
|
return oneClickResult;
|
|
5619
5593
|
}
|
|
5620
|
-
if (
|
|
5621
|
-
|
|
5594
|
+
if (!dry) {
|
|
5595
|
+
cctpParams.recipient = oneClickResult.quote.depositAddress;
|
|
5596
|
+
execTime.breakpoint();
|
|
5597
|
+
cctpResult = await cctp_default.quote(cctpParams);
|
|
5598
|
+
execTime.log("cctpService.quote again: %o", cctpResult);
|
|
5622
5599
|
}
|
|
5623
5600
|
csl("CCTPOneClickService quote", "rose-600", "oneClickResult: %o", oneClickResult);
|
|
5624
5601
|
csl("CCTPOneClickService quote", "rose-600", "cctpResult: %o", cctpResult);
|
|
@@ -6241,6 +6218,7 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6241
6218
|
_params.appFees = params.oneclickParams?.appFees || params.appFees;
|
|
6242
6219
|
_params.swapType = params.oneclickParams?.swapType;
|
|
6243
6220
|
_params.isProxy = params.oneclickParams?.isProxy;
|
|
6221
|
+
_params.forceCalculateFee = params.oneclickParams?.forceCalculateFee;
|
|
6244
6222
|
}
|
|
6245
6223
|
if ([
|
|
6246
6224
|
Service.Usdt0,
|