@stableflow/bridges 3.1.1-rc-34b8bcf337-20260722 → 3.1.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/README.md +2 -2
- package/dist/index.d.mts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +352 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +350 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -29,9 +29,9 @@ For HTTP-only quote/status without wallet orchestration, [`@stableflow/core`](..
|
|
|
29
29
|
| `ServiceMap` | Per-service `quote` / `send` / `getStatus` implementations |
|
|
30
30
|
| `getQuoteModes` | Helpers to interpret quote shape (OneClick, exact output, etc.) |
|
|
31
31
|
| Utilities | `formatQuoteError`, `addressToBytes32`, `quoteSignature`, `formatNumber` |
|
|
32
|
-
| USDT0 / FraxZero | `USDT0_CONFIG`, `OFT_ABI`, `getHopMsgFee`, `FRAXZERO_MIDDLE_TOKEN_*`, … |
|
|
32
|
+
| USDT0 / FraxZero / CCTP hybrid | `USDT0_CONFIG`, `OFT_ABI`, `getHopMsgFee`, `FRAXZERO_MIDDLE_TOKEN_*`, `CCTP_MIDDLE_TOKEN_CHAIN`, `CCTP_PROXY_RELAY_CONTRACT`, … |
|
|
33
33
|
|
|
34
|
-
Supported `Service` values (from `@stableflow/core`): `oneclick`, `usdt0`, `cctp`, `fraxzero`, composite routes (`usdt0-oneclick`, `oneclick-usdt0`, `fraxzero-oneclick`, `oneclick-fraxzero`), and `native`.
|
|
34
|
+
Supported `Service` values (from `@stableflow/core`): `oneclick`, `usdt0`, `cctp`, `fraxzero`, composite routes (`usdt0-oneclick`, `oneclick-usdt0`, `cctp-oneclick`, `oneclick-cctp`, `fraxzero-oneclick`, `oneclick-fraxzero`), and `native`.
|
|
35
35
|
|
|
36
36
|
See `dist/index.d.ts` after `pnpm build`.
|
|
37
37
|
|
package/dist/index.d.mts
CHANGED
|
@@ -233,7 +233,7 @@ declare const formatQuoteError: (error: any, options: {
|
|
|
233
233
|
serviceType: "oneclick";
|
|
234
234
|
error: string;
|
|
235
235
|
} | {
|
|
236
|
-
serviceType: "usdt0" | "cctp" | "fraxzero" | "fraxzero-oneclick" | "oneclick-fraxzero" | "usdt0-oneclick" | "oneclick-usdt0" | "native";
|
|
236
|
+
serviceType: "usdt0" | "cctp" | "fraxzero" | "fraxzero-oneclick" | "oneclick-fraxzero" | "usdt0-oneclick" | "oneclick-usdt0" | "cctp-oneclick" | "oneclick-cctp" | "native";
|
|
237
237
|
error: any;
|
|
238
238
|
};
|
|
239
239
|
|
|
@@ -324,4 +324,8 @@ declare const OFT_ABI: ({
|
|
|
324
324
|
declare const FRAXZERO_MIDDLE_TOKEN_USDC: _stableflow_core.TokenConfig;
|
|
325
325
|
declare const FRAXZERO_MIDDLE_TOKEN_FRXUSD: _stableflow_core.TokenConfig;
|
|
326
326
|
|
|
327
|
-
|
|
327
|
+
declare const MIDDLE_TOKEN_CHAIN: _stableflow_core.TokenConfig;
|
|
328
|
+
declare const CCTP_PROXY_RELAY_CONTRACT = "0x0da5336C5CEb9d15e7659Ae376CC41d86Edd8802";
|
|
329
|
+
declare const MIDDLE_CHAIN_REFOUND_ADDRESS = "0x654E7B96E1DE0b54E53D9ae8082fC2219E66dAC3";
|
|
330
|
+
|
|
331
|
+
export { BridgeSFA, type BuildTransactionResult, MIDDLE_CHAIN_REFOUND_ADDRESS as CCTP_MIDDLE_CHAIN_REFOUND_ADDRESS, MIDDLE_TOKEN_CHAIN as CCTP_MIDDLE_TOKEN_CHAIN, CCTP_PROXY_RELAY_CONTRACT, DATA_HEX_PROTOBUF_EXTRA, type EvmTxData, FRAXZERO_MIDDLE_TOKEN_FRXUSD, FRAXZERO_MIDDLE_TOKEN_USDC, type GetAllQuoteParams, LZ_RECEIVE_VALUE, OFT_ABI, type PermitSignature, type PermitTypedData, SIGNATURE_SIZE, ServiceMap, USDT0_CONFIG, USDT0_LEGACY_MESH_TRANSFTER_FEE, addressToBytes32, buildApproveTx, buildPermitTypedData, buildSendTx, formatNumber, formatQuoteError, getHopMsgFee, getQuoteModes, quoteSignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -233,7 +233,7 @@ declare const formatQuoteError: (error: any, options: {
|
|
|
233
233
|
serviceType: "oneclick";
|
|
234
234
|
error: string;
|
|
235
235
|
} | {
|
|
236
|
-
serviceType: "usdt0" | "cctp" | "fraxzero" | "fraxzero-oneclick" | "oneclick-fraxzero" | "usdt0-oneclick" | "oneclick-usdt0" | "native";
|
|
236
|
+
serviceType: "usdt0" | "cctp" | "fraxzero" | "fraxzero-oneclick" | "oneclick-fraxzero" | "usdt0-oneclick" | "oneclick-usdt0" | "cctp-oneclick" | "oneclick-cctp" | "native";
|
|
237
237
|
error: any;
|
|
238
238
|
};
|
|
239
239
|
|
|
@@ -324,4 +324,8 @@ declare const OFT_ABI: ({
|
|
|
324
324
|
declare const FRAXZERO_MIDDLE_TOKEN_USDC: _stableflow_core.TokenConfig;
|
|
325
325
|
declare const FRAXZERO_MIDDLE_TOKEN_FRXUSD: _stableflow_core.TokenConfig;
|
|
326
326
|
|
|
327
|
-
|
|
327
|
+
declare const MIDDLE_TOKEN_CHAIN: _stableflow_core.TokenConfig;
|
|
328
|
+
declare const CCTP_PROXY_RELAY_CONTRACT = "0x0da5336C5CEb9d15e7659Ae376CC41d86Edd8802";
|
|
329
|
+
declare const MIDDLE_CHAIN_REFOUND_ADDRESS = "0x654E7B96E1DE0b54E53D9ae8082fC2219E66dAC3";
|
|
330
|
+
|
|
331
|
+
export { BridgeSFA, type BuildTransactionResult, MIDDLE_CHAIN_REFOUND_ADDRESS as CCTP_MIDDLE_CHAIN_REFOUND_ADDRESS, MIDDLE_TOKEN_CHAIN as CCTP_MIDDLE_TOKEN_CHAIN, CCTP_PROXY_RELAY_CONTRACT, DATA_HEX_PROTOBUF_EXTRA, type EvmTxData, FRAXZERO_MIDDLE_TOKEN_FRXUSD, FRAXZERO_MIDDLE_TOKEN_USDC, type GetAllQuoteParams, LZ_RECEIVE_VALUE, OFT_ABI, type PermitSignature, type PermitTypedData, SIGNATURE_SIZE, ServiceMap, USDT0_CONFIG, USDT0_LEGACY_MESH_TRANSFTER_FEE, addressToBytes32, buildApproveTx, buildPermitTypedData, buildSendTx, formatNumber, formatQuoteError, getHopMsgFee, getQuoteModes, quoteSignature };
|
package/dist/index.js
CHANGED
|
@@ -61,12 +61,29 @@ var ONECLICK_PROXY_ABI = [
|
|
|
61
61
|
];
|
|
62
62
|
var BridgeFee = [
|
|
63
63
|
{
|
|
64
|
+
includeChains: ["BNB Chain", "Tron"],
|
|
64
65
|
recipient: "reffer.near",
|
|
65
66
|
// No bridge fee will be charged temporarily
|
|
66
|
-
fee:
|
|
67
|
+
fee: 1
|
|
67
68
|
// 100=1% 1=0.01%
|
|
68
69
|
}
|
|
69
70
|
];
|
|
71
|
+
var checkIsBridgeFee = (params) => {
|
|
72
|
+
const currentBridgeFee = BridgeFee[0];
|
|
73
|
+
const { fromToken, toToken } = params ?? {};
|
|
74
|
+
if (!fromToken || !toToken) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
const fromTokenSymbol = fromToken?.symbol === "USD\u20AE0" ? "USDT" : fromToken?.symbol;
|
|
78
|
+
const toTokenSymbol = toToken?.symbol === "USD\u20AE0" ? "USDT" : toToken?.symbol;
|
|
79
|
+
if (
|
|
80
|
+
// 1. bridge chains is bsc / tron
|
|
81
|
+
currentBridgeFee.includeChains.includes(fromToken?.chainName) || currentBridgeFee.includeChains.includes(toToken?.chainName) || fromTokenSymbol !== toTokenSymbol
|
|
82
|
+
) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
};
|
|
70
87
|
var excludeFees = ["estimateGasUsd"];
|
|
71
88
|
var OneClickService = class {
|
|
72
89
|
constructor() {
|
|
@@ -108,7 +125,15 @@ var OneClickService = class {
|
|
|
108
125
|
}
|
|
109
126
|
try {
|
|
110
127
|
const netFee = Big__default.default(_amountInUsd).minus(_amountOutUsd);
|
|
128
|
+
const isBridgeFee = checkIsBridgeFee(params);
|
|
111
129
|
let bridgeFeeValue = Big__default.default(0);
|
|
130
|
+
if (isBridgeFee) {
|
|
131
|
+
bridgeFeeValue = BridgeFee.reduce((acc, item) => {
|
|
132
|
+
return acc.plus(
|
|
133
|
+
Big__default.default(params.amountWei).div(10 ** params.fromToken.decimals).times(Big__default.default(item.fee).div(1e4)).times(core.getPrice(params.prices, params.fromToken.symbol))
|
|
134
|
+
);
|
|
135
|
+
}, Big__default.default(0));
|
|
136
|
+
}
|
|
112
137
|
let destinationGasFee = Big__default.default(netFee).minus(bridgeFeeValue);
|
|
113
138
|
destinationGasFee = Big__default.default(destinationGasFee).lt(0) ? Big__default.default(0) : destinationGasFee;
|
|
114
139
|
if (fromTokenSymbol !== toTokenSymbol) {
|
|
@@ -139,8 +164,6 @@ var OneClickService = class {
|
|
|
139
164
|
fromToken: params.fromToken,
|
|
140
165
|
refundTo: params.refundTo,
|
|
141
166
|
recipient: params.recipient,
|
|
142
|
-
// EXACT_OUTPUT: deposit/approve amountIn (with slippage buffer) so the
|
|
143
|
-
// first step cannot fail due to slippage; excess is refunded to refundTo.
|
|
144
167
|
amountWei: isExactOutput ? res.data?.quote?.amountIn : params.amountWei,
|
|
145
168
|
prices: params.prices,
|
|
146
169
|
evmGasFees: params.evmGasFees,
|
|
@@ -200,10 +223,7 @@ var OneClickService = class {
|
|
|
200
223
|
recipientType: "DESTINATION_CHAIN",
|
|
201
224
|
deadline: new Date(Date.now() + this.offsetTime).toISOString(),
|
|
202
225
|
quoteWaitingTimeMs: 0,
|
|
203
|
-
appFees
|
|
204
|
-
...BridgeFee,
|
|
205
|
-
...appFees
|
|
206
|
-
],
|
|
226
|
+
appFees,
|
|
207
227
|
referral: "stableflow",
|
|
208
228
|
amount: amountWei,
|
|
209
229
|
slippageTolerance: slippageTolerance * 100
|
|
@@ -214,6 +234,14 @@ var OneClickService = class {
|
|
|
214
234
|
}
|
|
215
235
|
quoteParams[k] = restParams[k];
|
|
216
236
|
}
|
|
237
|
+
const isBridgeFee = checkIsBridgeFee(params);
|
|
238
|
+
if (isBridgeFee) {
|
|
239
|
+
if (Array.isArray(quoteParams.appFees)) {
|
|
240
|
+
quoteParams.appFees = quoteParams.appFees.concat(BridgeFee.map((it) => ({ recipient: it.recipient, fee: it.fee })));
|
|
241
|
+
} else {
|
|
242
|
+
quoteParams.appFees = BridgeFee.map((it) => ({ recipient: it.recipient, fee: it.fee }));
|
|
243
|
+
}
|
|
244
|
+
}
|
|
217
245
|
execTime.breakpoint();
|
|
218
246
|
const response = await core.postRequest("/v0/quote", quoteParams);
|
|
219
247
|
execTime.log("/v0/quote");
|
|
@@ -476,7 +504,7 @@ var getQuoteModes = (params) => {
|
|
|
476
504
|
if (typeof quoteDataService === "undefined") {
|
|
477
505
|
return false;
|
|
478
506
|
}
|
|
479
|
-
if ([core.Service.OneClickUsdt0].includes(quoteDataService)) {
|
|
507
|
+
if ([core.Service.OneClickUsdt0, core.Service.OneClickCCTP].includes(quoteDataService)) {
|
|
480
508
|
return true;
|
|
481
509
|
}
|
|
482
510
|
if (quoteDataService === core.Service.OneClickFraxZero) {
|
|
@@ -492,7 +520,7 @@ var getQuoteModes = (params) => {
|
|
|
492
520
|
if (typeof quoteDataService === "undefined") {
|
|
493
521
|
return false;
|
|
494
522
|
}
|
|
495
|
-
if ([core.Service.OneClickUsdt0, core.Service.OneClick].includes(quoteDataService)) {
|
|
523
|
+
if ([core.Service.OneClickUsdt0, core.Service.OneClick, core.Service.OneClickCCTP].includes(quoteDataService)) {
|
|
496
524
|
return true;
|
|
497
525
|
}
|
|
498
526
|
if (quoteDataService === core.Service.OneClickFraxZero) {
|
|
@@ -508,7 +536,7 @@ var getQuoteModes = (params) => {
|
|
|
508
536
|
if (typeof quoteDataService === "undefined") {
|
|
509
537
|
return false;
|
|
510
538
|
}
|
|
511
|
-
if ([core.Service.Usdt0OneClick].includes(quoteDataService)) {
|
|
539
|
+
if ([core.Service.Usdt0OneClick, core.Service.CCTPOneClick].includes(quoteDataService)) {
|
|
512
540
|
return true;
|
|
513
541
|
}
|
|
514
542
|
if (quoteDataService === core.Service.FraxZeroOneClick) {
|
|
@@ -524,7 +552,7 @@ var getQuoteModes = (params) => {
|
|
|
524
552
|
isExactOutput: getIsExactOutput(),
|
|
525
553
|
isOneClickService: getIsOneClickService(),
|
|
526
554
|
isQuoteParamDepositAddress: getIsQuoteParamDepositAddress(),
|
|
527
|
-
isPermitWithNonce: typeof quoteDataService === "undefined" ? false : [core.Service.OneClickUsdt0, core.Service.OneClickFraxZero, core.Service.FraxZeroOneClick].includes(quoteDataService)
|
|
555
|
+
isPermitWithNonce: typeof quoteDataService === "undefined" ? false : [core.Service.OneClickUsdt0, core.Service.OneClickCCTP, core.Service.OneClickFraxZero, core.Service.FraxZeroOneClick].includes(quoteDataService)
|
|
528
556
|
};
|
|
529
557
|
};
|
|
530
558
|
function zeroPadValue(hex, lengthBytes) {
|
|
@@ -4011,8 +4039,9 @@ var CCTP_TOKEN_PROXY_ABI = [
|
|
|
4011
4039
|
"type": "function"
|
|
4012
4040
|
}
|
|
4013
4041
|
];
|
|
4014
|
-
|
|
4015
|
-
|
|
4042
|
+
var MIDDLE_TOKEN_CHAIN2 = core.usdcChains["arb"];
|
|
4043
|
+
var CCTP_PROXY_RELAY_CONTRACT = "0x0da5336C5CEb9d15e7659Ae376CC41d86Edd8802";
|
|
4044
|
+
var MIDDLE_CHAIN_REFOUND_ADDRESS2 = "0x654E7B96E1DE0b54E53D9ae8082fC2219E66dAC3";
|
|
4016
4045
|
var CCTP_DOMAINS = {
|
|
4017
4046
|
Ethereum: 0,
|
|
4018
4047
|
Arbitrum: 3,
|
|
@@ -5516,6 +5545,279 @@ var OneClickUsdt0Service = class {
|
|
|
5516
5545
|
}
|
|
5517
5546
|
};
|
|
5518
5547
|
var from_oneclick_default2 = new OneClickUsdt0Service();
|
|
5548
|
+
var excludeFees5 = ["estimateGasUsd"];
|
|
5549
|
+
var CCTPOneClickService = class {
|
|
5550
|
+
async quote(params) {
|
|
5551
|
+
const {
|
|
5552
|
+
dry,
|
|
5553
|
+
evmWallet,
|
|
5554
|
+
evmAddress
|
|
5555
|
+
} = params;
|
|
5556
|
+
const cs = new core.Csl(core.OpenAPI.DEBUG);
|
|
5557
|
+
const csl = cs.log;
|
|
5558
|
+
const execTime = new core.ExecTime({ type: "CCTPOneClickService", logStyle: "lime-700", isDebug: core.OpenAPI.DEBUG });
|
|
5559
|
+
if (!evmWallet) {
|
|
5560
|
+
throw new Error("evmWallet is required");
|
|
5561
|
+
}
|
|
5562
|
+
if (!evmAddress) {
|
|
5563
|
+
throw new Error("evmAddress is required");
|
|
5564
|
+
}
|
|
5565
|
+
const cctpParams = {
|
|
5566
|
+
...params,
|
|
5567
|
+
toToken: MIDDLE_TOKEN_CHAIN2,
|
|
5568
|
+
destinationChain: MIDDLE_TOKEN_CHAIN2.chainName,
|
|
5569
|
+
recipient: MIDDLE_CHAIN_REFOUND_ADDRESS2
|
|
5570
|
+
};
|
|
5571
|
+
const oneClickParams = {
|
|
5572
|
+
...params,
|
|
5573
|
+
fromToken: MIDDLE_TOKEN_CHAIN2,
|
|
5574
|
+
originAsset: MIDDLE_TOKEN_CHAIN2.assetId,
|
|
5575
|
+
swapType: core.OneClickSwapType.Flex,
|
|
5576
|
+
isProxy: false,
|
|
5577
|
+
refundTo: evmAddress,
|
|
5578
|
+
wallet: evmWallet
|
|
5579
|
+
};
|
|
5580
|
+
let cctpResult;
|
|
5581
|
+
let oneClickResult;
|
|
5582
|
+
if (!dry) {
|
|
5583
|
+
execTime.breakpoint();
|
|
5584
|
+
oneClickResult = await oneclick_default.quote({
|
|
5585
|
+
...oneClickParams,
|
|
5586
|
+
amountWei: Big__default.default(0.01).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0)
|
|
5587
|
+
});
|
|
5588
|
+
execTime.log("CCTPOneClickService.quote", "oneClickService.quote: %o", oneClickResult);
|
|
5589
|
+
if (oneClickResult.errMsg) {
|
|
5590
|
+
return oneClickResult;
|
|
5591
|
+
}
|
|
5592
|
+
cctpParams.recipient = oneClickResult.quote.depositAddress;
|
|
5593
|
+
execTime.breakpoint();
|
|
5594
|
+
cctpResult = await cctp_default.quote(cctpParams);
|
|
5595
|
+
execTime.log("CCTPOneClickService.quote", "cctpService.quote: %o", cctpResult);
|
|
5596
|
+
execTime.breakpoint();
|
|
5597
|
+
try {
|
|
5598
|
+
const oneClickResult2 = await oneclick_default.quote({
|
|
5599
|
+
...oneClickParams,
|
|
5600
|
+
dry: true,
|
|
5601
|
+
amountWei: Big__default.default(cctpResult.outputAmount || 0).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0)
|
|
5602
|
+
});
|
|
5603
|
+
oneClickResult.fees = oneClickResult2.fees;
|
|
5604
|
+
oneClickResult.outputAmount = oneClickResult2.outputAmount;
|
|
5605
|
+
oneClickResult.estimateTime = oneClickResult2.estimateTime;
|
|
5606
|
+
oneClickResult.priceImpact = oneClickResult2.priceImpact;
|
|
5607
|
+
oneClickResult.exchangeRate = oneClickResult2.exchangeRate;
|
|
5608
|
+
execTime.log("CCTPOneClickService.quote", "confirm get actual output amount result: %o", oneClickResult2);
|
|
5609
|
+
} catch (err) {
|
|
5610
|
+
execTime.log("CCTPOneClickService.quote", "confirm get actual output amount error: %o", err);
|
|
5611
|
+
}
|
|
5612
|
+
} else {
|
|
5613
|
+
execTime.breakpoint();
|
|
5614
|
+
cctpResult = await cctp_default.quote(cctpParams);
|
|
5615
|
+
execTime.log("CCTPOneClickService.quote", "cctpService.quote dry: %o", cctpResult);
|
|
5616
|
+
if (cctpResult.errMsg) {
|
|
5617
|
+
return cctpResult;
|
|
5618
|
+
}
|
|
5619
|
+
oneClickParams.amountWei = Big__default.default(cctpResult.outputAmount || 0).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0);
|
|
5620
|
+
execTime.breakpoint();
|
|
5621
|
+
oneClickResult = await oneclick_default.quote(oneClickParams);
|
|
5622
|
+
execTime.log("CCTPOneClickService.quote", "oneClickService.quote: %o", oneClickResult);
|
|
5623
|
+
}
|
|
5624
|
+
if (oneClickResult.errMsg) {
|
|
5625
|
+
return oneClickResult;
|
|
5626
|
+
}
|
|
5627
|
+
if (cctpResult.errMsg) {
|
|
5628
|
+
return cctpResult;
|
|
5629
|
+
}
|
|
5630
|
+
csl("CCTPOneClickService quote", "rose-600", "oneClickResult: %o", oneClickResult);
|
|
5631
|
+
csl("CCTPOneClickService quote", "rose-600", "cctpResult: %o", cctpResult);
|
|
5632
|
+
let totalFeesUsd = Big__default.default(0);
|
|
5633
|
+
const fees = {
|
|
5634
|
+
...cctpResult.fees
|
|
5635
|
+
};
|
|
5636
|
+
for (const feeKey in oneClickResult.fees) {
|
|
5637
|
+
if (excludeFees.includes(feeKey)) {
|
|
5638
|
+
continue;
|
|
5639
|
+
}
|
|
5640
|
+
fees[feeKey] = oneClickResult.fees[feeKey];
|
|
5641
|
+
}
|
|
5642
|
+
for (const feeKey in fees) {
|
|
5643
|
+
if (excludeFees5.includes(feeKey)) {
|
|
5644
|
+
continue;
|
|
5645
|
+
}
|
|
5646
|
+
totalFeesUsd = Big__default.default(totalFeesUsd || 0).plus(fees[feeKey] || 0);
|
|
5647
|
+
}
|
|
5648
|
+
execTime.logTotal("CCTPOneClickService.quote");
|
|
5649
|
+
return {
|
|
5650
|
+
...cctpResult,
|
|
5651
|
+
fees,
|
|
5652
|
+
totalFeesUsd: core.numberRemoveEndZero(Big__default.default(totalFeesUsd).toFixed(20)),
|
|
5653
|
+
estimateTime: cctpResult.estimateTime + oneClickResult.estimateTime,
|
|
5654
|
+
outputAmount: oneClickResult.outputAmount,
|
|
5655
|
+
priceImpact: oneClickResult.priceImpact,
|
|
5656
|
+
exchangeRate: oneClickResult.exchangeRate,
|
|
5657
|
+
quoteParam: {
|
|
5658
|
+
...cctpResult.quoteParam,
|
|
5659
|
+
toToken: params.toToken,
|
|
5660
|
+
middleToken: MIDDLE_TOKEN_CHAIN2,
|
|
5661
|
+
recipient: params.recipient,
|
|
5662
|
+
depositAddress: oneClickResult.quote.depositAddress
|
|
5663
|
+
},
|
|
5664
|
+
sourceQuoteParams: params
|
|
5665
|
+
};
|
|
5666
|
+
}
|
|
5667
|
+
async estimateTransaction(params, quoteData) {
|
|
5668
|
+
return cctp_default.estimateTransaction(params, quoteData);
|
|
5669
|
+
}
|
|
5670
|
+
async send(params) {
|
|
5671
|
+
const {
|
|
5672
|
+
wallet,
|
|
5673
|
+
...rest
|
|
5674
|
+
} = params;
|
|
5675
|
+
return wallet.send(core.SendType.SEND, rest);
|
|
5676
|
+
}
|
|
5677
|
+
getStatus(params) {
|
|
5678
|
+
return core.getRequest("/v0/trade", {
|
|
5679
|
+
deposit_address: params.depositAddress
|
|
5680
|
+
});
|
|
5681
|
+
}
|
|
5682
|
+
};
|
|
5683
|
+
var to_oneclick_default3 = new CCTPOneClickService();
|
|
5684
|
+
var OneClickCCTPService = class {
|
|
5685
|
+
async quote(params) {
|
|
5686
|
+
const {
|
|
5687
|
+
evmWallet,
|
|
5688
|
+
evmAddress,
|
|
5689
|
+
fromToken,
|
|
5690
|
+
prices
|
|
5691
|
+
} = params;
|
|
5692
|
+
const execTime = new core.ExecTime({ type: "OneClickCCTP", logStyle: "lime-500", isDebug: core.OpenAPI.DEBUG });
|
|
5693
|
+
if (!evmWallet) {
|
|
5694
|
+
throw new Error("evmWallet is required");
|
|
5695
|
+
}
|
|
5696
|
+
if (!evmAddress) {
|
|
5697
|
+
throw new Error("evmAddress is required");
|
|
5698
|
+
}
|
|
5699
|
+
let secondStepAmountWei = Big__default.default(params.amountWei || 0).div(10 ** fromToken.decimals).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0);
|
|
5700
|
+
if (!core.isStableToken(fromToken)) {
|
|
5701
|
+
const inputPrice = core.getPrice(prices, fromToken.symbol);
|
|
5702
|
+
const inputValue = Big__default.default(params.amountWei || 0).div(10 ** fromToken.decimals).times(inputPrice);
|
|
5703
|
+
secondStepAmountWei = Big__default.default(inputValue).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0);
|
|
5704
|
+
}
|
|
5705
|
+
const cctpParams = {
|
|
5706
|
+
...params,
|
|
5707
|
+
amountWei: secondStepAmountWei,
|
|
5708
|
+
fromToken: MIDDLE_TOKEN_CHAIN2,
|
|
5709
|
+
originChain: MIDDLE_TOKEN_CHAIN2.chainName,
|
|
5710
|
+
refundTo: MIDDLE_CHAIN_REFOUND_ADDRESS2,
|
|
5711
|
+
wallet: evmWallet
|
|
5712
|
+
};
|
|
5713
|
+
execTime.breakpoint();
|
|
5714
|
+
const cctpResult = await cctp_default.quote(cctpParams);
|
|
5715
|
+
execTime.log("cctpService.quote");
|
|
5716
|
+
const cctpFeeBuffer = 1.2;
|
|
5717
|
+
const cctpMintFeeUsd = core.numberRemoveEndZero(Big__default.default(cctpResult.fees?.estimateMintGasUsd || 0).times(1 + cctpFeeBuffer).toFixed(20));
|
|
5718
|
+
const cctpBridgeFeeUsd = core.numberRemoveEndZero(Big__default.default(cctpResult.fees?.bridgeFeeUsd || 0).times(1 + cctpFeeBuffer).toFixed(20));
|
|
5719
|
+
const cctpTotalFeeUsd = Big__default.default(cctpMintFeeUsd || 0).plus(cctpBridgeFeeUsd || 0).toFixed(20);
|
|
5720
|
+
if (cctpResult.errMsg) {
|
|
5721
|
+
return cctpResult;
|
|
5722
|
+
}
|
|
5723
|
+
const cctpFeeAmountInFromToken = Big__default.default(cctpTotalFeeUsd || 0).div(core.getPrice(prices, fromToken.symbol) || 1).toFixed(fromToken.decimals);
|
|
5724
|
+
const fromTokenAmount = Big__default.default(params.amountWei).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
|
|
5725
|
+
const oneClickFeeRatio = Big__default.default(cctpFeeAmountInFromToken || 0).div(Big__default.default(cctpFeeAmountInFromToken || 0).plus(fromTokenAmount)).times(1e4).toFixed(0, Big__default.default.roundUp);
|
|
5726
|
+
if (Big__default.default(oneClickFeeRatio).gt(1e4)) {
|
|
5727
|
+
return { errMsg: `Amount is too low, at least ${cctpFeeAmountInFromToken}` };
|
|
5728
|
+
}
|
|
5729
|
+
execTime.breakpoint();
|
|
5730
|
+
const oneClickResult = await oneclick_default.quote({
|
|
5731
|
+
...params,
|
|
5732
|
+
amountWei: secondStepAmountWei,
|
|
5733
|
+
toToken: MIDDLE_TOKEN_CHAIN2,
|
|
5734
|
+
destinationAsset: MIDDLE_TOKEN_CHAIN2.assetId,
|
|
5735
|
+
swapType: core.OneClickSwapType.Output,
|
|
5736
|
+
isProxy: true,
|
|
5737
|
+
recipient: evmAddress,
|
|
5738
|
+
appFees: [
|
|
5739
|
+
...params.appFees || [],
|
|
5740
|
+
{
|
|
5741
|
+
recipient: "reffer.near",
|
|
5742
|
+
fee: +oneClickFeeRatio
|
|
5743
|
+
}
|
|
5744
|
+
]
|
|
5745
|
+
});
|
|
5746
|
+
execTime.log("oneClickService.quote");
|
|
5747
|
+
let totalFeesUsd = Big__default.default(0);
|
|
5748
|
+
let _destinationGasFeeUsd = Big__default.default(oneClickResult.fees?.destinationGasFeeUsd || 0).minus(cctpTotalFeeUsd);
|
|
5749
|
+
if (Big__default.default(_destinationGasFeeUsd).lt(0)) {
|
|
5750
|
+
_destinationGasFeeUsd = Big__default.default(0);
|
|
5751
|
+
}
|
|
5752
|
+
const fees = {
|
|
5753
|
+
...oneClickResult.fees,
|
|
5754
|
+
destinationGasFeeUsd: core.numberRemoveEndZero(Big__default.default(_destinationGasFeeUsd).toFixed(20)),
|
|
5755
|
+
estimateMintGasUsd: cctpMintFeeUsd,
|
|
5756
|
+
bridgeFeeUsd: cctpBridgeFeeUsd
|
|
5757
|
+
};
|
|
5758
|
+
for (const feeKey in cctpResult.fees) {
|
|
5759
|
+
if (["estimateGasUsd"].includes(feeKey)) {
|
|
5760
|
+
continue;
|
|
5761
|
+
}
|
|
5762
|
+
if (!fees[feeKey]) {
|
|
5763
|
+
fees[feeKey] = cctpResult.fees[feeKey];
|
|
5764
|
+
}
|
|
5765
|
+
}
|
|
5766
|
+
for (const feeKey in fees) {
|
|
5767
|
+
if (excludeFees.includes(feeKey)) {
|
|
5768
|
+
continue;
|
|
5769
|
+
}
|
|
5770
|
+
totalFeesUsd = Big__default.default(totalFeesUsd || 0).plus(fees[feeKey] || 0);
|
|
5771
|
+
}
|
|
5772
|
+
const cctpSendParam = cctpResult.sendParam?.param;
|
|
5773
|
+
execTime.log("OneClickCCTPService.quote");
|
|
5774
|
+
return {
|
|
5775
|
+
...oneClickResult,
|
|
5776
|
+
needPermit: true,
|
|
5777
|
+
permitSpender: CCTP_PROXY_RELAY_CONTRACT,
|
|
5778
|
+
permitToken: MIDDLE_TOKEN_CHAIN2,
|
|
5779
|
+
permitAmountWei: oneClickResult?.quote?.amountOut,
|
|
5780
|
+
permitAdditionalData: {
|
|
5781
|
+
amount_wei: cctpSendParam?.[0]?.toString(),
|
|
5782
|
+
charged_amount: cctpSendParam?.[1]?.toString(),
|
|
5783
|
+
destination_domain: cctpSendParam?.[2]?.toString(),
|
|
5784
|
+
mint_recipient: cctpParams.recipient,
|
|
5785
|
+
burn_token: cctpSendParam?.[4]?.toString(),
|
|
5786
|
+
destination_caller: cctpSendParam?.[5]?.toString(),
|
|
5787
|
+
max_fee: cctpSendParam?.[6]?.toString(),
|
|
5788
|
+
finality_threshold: cctpSendParam?.[7]?.toString(),
|
|
5789
|
+
receipt_address: params.recipient,
|
|
5790
|
+
source_domain: cctpResult.quoteParam?.sourceDomain,
|
|
5791
|
+
destination_domain_id: cctpResult.quoteParam?.destinationDomain
|
|
5792
|
+
},
|
|
5793
|
+
fees,
|
|
5794
|
+
totalFeesUsd: core.numberRemoveEndZero(Big__default.default(totalFeesUsd).toFixed(20)),
|
|
5795
|
+
estimateTime: cctpResult.estimateTime + oneClickResult.estimateTime,
|
|
5796
|
+
outputAmount: cctpResult.outputAmount,
|
|
5797
|
+
needCreateTokenAccount: cctpResult.needCreateTokenAccount,
|
|
5798
|
+
quoteParam: {
|
|
5799
|
+
...oneClickResult.quoteParam,
|
|
5800
|
+
toToken: params.toToken,
|
|
5801
|
+
middleToken: MIDDLE_TOKEN_CHAIN2,
|
|
5802
|
+
recipient: params.recipient
|
|
5803
|
+
},
|
|
5804
|
+
cctpSendParam,
|
|
5805
|
+
sourceQuoteParams: params
|
|
5806
|
+
};
|
|
5807
|
+
}
|
|
5808
|
+
async estimateTransaction(params, quoteData) {
|
|
5809
|
+
return oneclick_default.estimateTransaction(params, quoteData);
|
|
5810
|
+
}
|
|
5811
|
+
async send(params) {
|
|
5812
|
+
return oneclick_default.send(params);
|
|
5813
|
+
}
|
|
5814
|
+
getStatus(params) {
|
|
5815
|
+
return core.getRequest("/v0/trade", {
|
|
5816
|
+
deposit_address: params.depositAddress
|
|
5817
|
+
});
|
|
5818
|
+
}
|
|
5819
|
+
};
|
|
5820
|
+
var from_oneclick_default3 = new OneClickCCTPService();
|
|
5519
5821
|
|
|
5520
5822
|
// src/native/contract.ts
|
|
5521
5823
|
var NativeChains = {
|
|
@@ -5682,6 +5984,8 @@ var ServiceMap = {
|
|
|
5682
5984
|
[core.Service.OneClickFraxZero]: from_oneclick_default,
|
|
5683
5985
|
[core.Service.Usdt0OneClick]: to_oneclick_default2,
|
|
5684
5986
|
[core.Service.OneClickUsdt0]: from_oneclick_default2,
|
|
5987
|
+
[core.Service.CCTPOneClick]: to_oneclick_default3,
|
|
5988
|
+
[core.Service.OneClickCCTP]: from_oneclick_default3,
|
|
5685
5989
|
[core.Service.Native]: native_default
|
|
5686
5990
|
};
|
|
5687
5991
|
var OVERRIDE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -5933,6 +6237,8 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
5933
6237
|
core.Service.OneClick,
|
|
5934
6238
|
core.Service.Usdt0OneClick,
|
|
5935
6239
|
core.Service.OneClickUsdt0,
|
|
6240
|
+
core.Service.CCTPOneClick,
|
|
6241
|
+
core.Service.OneClickCCTP,
|
|
5936
6242
|
core.Service.FraxZeroOneClick,
|
|
5937
6243
|
core.Service.OneClickFraxZero
|
|
5938
6244
|
].includes(service)) {
|
|
@@ -5947,7 +6253,9 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
5947
6253
|
core.Service.Usdt0,
|
|
5948
6254
|
core.Service.CCTP,
|
|
5949
6255
|
core.Service.Usdt0OneClick,
|
|
5950
|
-
core.Service.OneClickUsdt0
|
|
6256
|
+
core.Service.OneClickUsdt0,
|
|
6257
|
+
core.Service.CCTPOneClick,
|
|
6258
|
+
core.Service.OneClickCCTP
|
|
5951
6259
|
].includes(service)) {
|
|
5952
6260
|
_params.originChain = params.fromToken.chainName;
|
|
5953
6261
|
_params.destinationChain = params.toToken.chainName;
|
|
@@ -5961,6 +6269,8 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
5961
6269
|
}
|
|
5962
6270
|
const isFromUsdt = ["USDT", "USD\u20AE0"].includes(fromToken.symbol);
|
|
5963
6271
|
const isToUsdt = ["USDT", "USD\u20AE0"].includes(toToken.symbol);
|
|
6272
|
+
const isFromUsdc = ["USDC"].includes(fromToken.symbol);
|
|
6273
|
+
const isToUsdc = ["USDC"].includes(toToken.symbol);
|
|
5964
6274
|
const quoteServices = [];
|
|
5965
6275
|
const pushQuoteService = (_service) => {
|
|
5966
6276
|
const serviceStatus = core.getRouteStatus(_service, disabledServices);
|
|
@@ -6005,6 +6315,24 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6005
6315
|
if (fromToken.services.includes(core.Service.OneClick) && toToken.services.includes(core.Service.FraxZero)) {
|
|
6006
6316
|
pushQuoteService(core.Service.OneClickFraxZero);
|
|
6007
6317
|
}
|
|
6318
|
+
if (fromToken.services.includes(core.Service.CCTP) && toToken.services.includes(core.Service.OneClick) && fromToken.chainName !== "Arbitrum") {
|
|
6319
|
+
if (isFromUsdc && isToUsdc) {
|
|
6320
|
+
if (toToken.chainName !== "Arbitrum") {
|
|
6321
|
+
pushQuoteService(core.Service.CCTPOneClick);
|
|
6322
|
+
}
|
|
6323
|
+
} else {
|
|
6324
|
+
pushQuoteService(core.Service.CCTPOneClick);
|
|
6325
|
+
}
|
|
6326
|
+
}
|
|
6327
|
+
if (fromToken.services.includes(core.Service.OneClick) && toToken.services.includes(core.Service.CCTP) && toToken.chainName !== "Arbitrum") {
|
|
6328
|
+
if (isFromUsdc && isToUsdc) {
|
|
6329
|
+
if (fromToken.chainName !== "Arbitrum") {
|
|
6330
|
+
pushQuoteService(core.Service.OneClickCCTP);
|
|
6331
|
+
}
|
|
6332
|
+
} else {
|
|
6333
|
+
pushQuoteService(core.Service.OneClickCCTP);
|
|
6334
|
+
}
|
|
6335
|
+
}
|
|
6008
6336
|
if (params.singleService) {
|
|
6009
6337
|
const quoteService = quoteServices.find((service) => service.service === params.singleService);
|
|
6010
6338
|
if (quoteService) {
|
|
@@ -6135,6 +6463,12 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6135
6463
|
...quote.permitAdditionalData
|
|
6136
6464
|
};
|
|
6137
6465
|
}
|
|
6466
|
+
if ([core.Service.OneClickCCTP].includes(serviceType)) {
|
|
6467
|
+
reportData.cctp_permit = {
|
|
6468
|
+
...permitSignature,
|
|
6469
|
+
...quote.permitAdditionalData
|
|
6470
|
+
};
|
|
6471
|
+
}
|
|
6138
6472
|
if ([core.Service.OneClickFraxZero, core.Service.FraxZeroOneClick].includes(serviceType)) {
|
|
6139
6473
|
reportData.frax_zero_permit = {
|
|
6140
6474
|
...permitSignature,
|
|
@@ -6290,7 +6624,7 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6290
6624
|
result.status = core.TransactionStatus.Failed;
|
|
6291
6625
|
}
|
|
6292
6626
|
}
|
|
6293
|
-
if ([core.Service.OneClickUsdt0, core.Service.Usdt0OneClick, core.Service.FraxZero, core.Service.OneClickFraxZero, core.Service.FraxZeroOneClick].includes(serviceType)) {
|
|
6627
|
+
if ([core.Service.OneClickUsdt0, core.Service.Usdt0OneClick, core.Service.CCTPOneClick, core.Service.OneClickCCTP, core.Service.FraxZero, core.Service.OneClickFraxZero, core.Service.FraxZeroOneClick].includes(serviceType)) {
|
|
6294
6628
|
const _result = response?.data;
|
|
6295
6629
|
const status = _result?.status;
|
|
6296
6630
|
if (status === core.StableflowStatus.SUCCESS) {
|
|
@@ -6338,6 +6672,9 @@ var getHopMsgFee = async (params) => {
|
|
|
6338
6672
|
};
|
|
6339
6673
|
|
|
6340
6674
|
exports.BridgeSFA = BridgeSFA;
|
|
6675
|
+
exports.CCTP_MIDDLE_CHAIN_REFOUND_ADDRESS = MIDDLE_CHAIN_REFOUND_ADDRESS2;
|
|
6676
|
+
exports.CCTP_MIDDLE_TOKEN_CHAIN = MIDDLE_TOKEN_CHAIN2;
|
|
6677
|
+
exports.CCTP_PROXY_RELAY_CONTRACT = CCTP_PROXY_RELAY_CONTRACT;
|
|
6341
6678
|
exports.DATA_HEX_PROTOBUF_EXTRA = DATA_HEX_PROTOBUF_EXTRA;
|
|
6342
6679
|
exports.FRAXZERO_MIDDLE_TOKEN_FRXUSD = FRAXZERO_MIDDLE_TOKEN_FRXUSD;
|
|
6343
6680
|
exports.FRAXZERO_MIDDLE_TOKEN_USDC = FRAXZERO_MIDDLE_TOKEN_USDC;
|