@stableflow/bridges 3.1.1-rc-d5f36a0408-20260723 → 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 +317 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +315 -11
- 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
|
@@ -164,8 +164,6 @@ var OneClickService = class {
|
|
|
164
164
|
fromToken: params.fromToken,
|
|
165
165
|
refundTo: params.refundTo,
|
|
166
166
|
recipient: params.recipient,
|
|
167
|
-
// EXACT_OUTPUT: deposit/approve amountIn (with slippage buffer) so the
|
|
168
|
-
// first step cannot fail due to slippage; excess is refunded to refundTo.
|
|
169
167
|
amountWei: isExactOutput ? res.data?.quote?.amountIn : params.amountWei,
|
|
170
168
|
prices: params.prices,
|
|
171
169
|
evmGasFees: params.evmGasFees,
|
|
@@ -506,7 +504,7 @@ var getQuoteModes = (params) => {
|
|
|
506
504
|
if (typeof quoteDataService === "undefined") {
|
|
507
505
|
return false;
|
|
508
506
|
}
|
|
509
|
-
if ([core.Service.OneClickUsdt0].includes(quoteDataService)) {
|
|
507
|
+
if ([core.Service.OneClickUsdt0, core.Service.OneClickCCTP].includes(quoteDataService)) {
|
|
510
508
|
return true;
|
|
511
509
|
}
|
|
512
510
|
if (quoteDataService === core.Service.OneClickFraxZero) {
|
|
@@ -522,7 +520,7 @@ var getQuoteModes = (params) => {
|
|
|
522
520
|
if (typeof quoteDataService === "undefined") {
|
|
523
521
|
return false;
|
|
524
522
|
}
|
|
525
|
-
if ([core.Service.OneClickUsdt0, core.Service.OneClick].includes(quoteDataService)) {
|
|
523
|
+
if ([core.Service.OneClickUsdt0, core.Service.OneClick, core.Service.OneClickCCTP].includes(quoteDataService)) {
|
|
526
524
|
return true;
|
|
527
525
|
}
|
|
528
526
|
if (quoteDataService === core.Service.OneClickFraxZero) {
|
|
@@ -538,7 +536,7 @@ var getQuoteModes = (params) => {
|
|
|
538
536
|
if (typeof quoteDataService === "undefined") {
|
|
539
537
|
return false;
|
|
540
538
|
}
|
|
541
|
-
if ([core.Service.Usdt0OneClick].includes(quoteDataService)) {
|
|
539
|
+
if ([core.Service.Usdt0OneClick, core.Service.CCTPOneClick].includes(quoteDataService)) {
|
|
542
540
|
return true;
|
|
543
541
|
}
|
|
544
542
|
if (quoteDataService === core.Service.FraxZeroOneClick) {
|
|
@@ -554,7 +552,7 @@ var getQuoteModes = (params) => {
|
|
|
554
552
|
isExactOutput: getIsExactOutput(),
|
|
555
553
|
isOneClickService: getIsOneClickService(),
|
|
556
554
|
isQuoteParamDepositAddress: getIsQuoteParamDepositAddress(),
|
|
557
|
-
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)
|
|
558
556
|
};
|
|
559
557
|
};
|
|
560
558
|
function zeroPadValue(hex, lengthBytes) {
|
|
@@ -4041,8 +4039,9 @@ var CCTP_TOKEN_PROXY_ABI = [
|
|
|
4041
4039
|
"type": "function"
|
|
4042
4040
|
}
|
|
4043
4041
|
];
|
|
4044
|
-
|
|
4045
|
-
|
|
4042
|
+
var MIDDLE_TOKEN_CHAIN2 = core.usdcChains["arb"];
|
|
4043
|
+
var CCTP_PROXY_RELAY_CONTRACT = "0x0da5336C5CEb9d15e7659Ae376CC41d86Edd8802";
|
|
4044
|
+
var MIDDLE_CHAIN_REFOUND_ADDRESS2 = "0x654E7B96E1DE0b54E53D9ae8082fC2219E66dAC3";
|
|
4046
4045
|
var CCTP_DOMAINS = {
|
|
4047
4046
|
Ethereum: 0,
|
|
4048
4047
|
Arbitrum: 3,
|
|
@@ -5546,6 +5545,279 @@ var OneClickUsdt0Service = class {
|
|
|
5546
5545
|
}
|
|
5547
5546
|
};
|
|
5548
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();
|
|
5549
5821
|
|
|
5550
5822
|
// src/native/contract.ts
|
|
5551
5823
|
var NativeChains = {
|
|
@@ -5712,6 +5984,8 @@ var ServiceMap = {
|
|
|
5712
5984
|
[core.Service.OneClickFraxZero]: from_oneclick_default,
|
|
5713
5985
|
[core.Service.Usdt0OneClick]: to_oneclick_default2,
|
|
5714
5986
|
[core.Service.OneClickUsdt0]: from_oneclick_default2,
|
|
5987
|
+
[core.Service.CCTPOneClick]: to_oneclick_default3,
|
|
5988
|
+
[core.Service.OneClickCCTP]: from_oneclick_default3,
|
|
5715
5989
|
[core.Service.Native]: native_default
|
|
5716
5990
|
};
|
|
5717
5991
|
var OVERRIDE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -5963,6 +6237,8 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
5963
6237
|
core.Service.OneClick,
|
|
5964
6238
|
core.Service.Usdt0OneClick,
|
|
5965
6239
|
core.Service.OneClickUsdt0,
|
|
6240
|
+
core.Service.CCTPOneClick,
|
|
6241
|
+
core.Service.OneClickCCTP,
|
|
5966
6242
|
core.Service.FraxZeroOneClick,
|
|
5967
6243
|
core.Service.OneClickFraxZero
|
|
5968
6244
|
].includes(service)) {
|
|
@@ -5977,7 +6253,9 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
5977
6253
|
core.Service.Usdt0,
|
|
5978
6254
|
core.Service.CCTP,
|
|
5979
6255
|
core.Service.Usdt0OneClick,
|
|
5980
|
-
core.Service.OneClickUsdt0
|
|
6256
|
+
core.Service.OneClickUsdt0,
|
|
6257
|
+
core.Service.CCTPOneClick,
|
|
6258
|
+
core.Service.OneClickCCTP
|
|
5981
6259
|
].includes(service)) {
|
|
5982
6260
|
_params.originChain = params.fromToken.chainName;
|
|
5983
6261
|
_params.destinationChain = params.toToken.chainName;
|
|
@@ -5991,6 +6269,8 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
5991
6269
|
}
|
|
5992
6270
|
const isFromUsdt = ["USDT", "USD\u20AE0"].includes(fromToken.symbol);
|
|
5993
6271
|
const isToUsdt = ["USDT", "USD\u20AE0"].includes(toToken.symbol);
|
|
6272
|
+
const isFromUsdc = ["USDC"].includes(fromToken.symbol);
|
|
6273
|
+
const isToUsdc = ["USDC"].includes(toToken.symbol);
|
|
5994
6274
|
const quoteServices = [];
|
|
5995
6275
|
const pushQuoteService = (_service) => {
|
|
5996
6276
|
const serviceStatus = core.getRouteStatus(_service, disabledServices);
|
|
@@ -6035,6 +6315,24 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6035
6315
|
if (fromToken.services.includes(core.Service.OneClick) && toToken.services.includes(core.Service.FraxZero)) {
|
|
6036
6316
|
pushQuoteService(core.Service.OneClickFraxZero);
|
|
6037
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
|
+
}
|
|
6038
6336
|
if (params.singleService) {
|
|
6039
6337
|
const quoteService = quoteServices.find((service) => service.service === params.singleService);
|
|
6040
6338
|
if (quoteService) {
|
|
@@ -6165,6 +6463,12 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6165
6463
|
...quote.permitAdditionalData
|
|
6166
6464
|
};
|
|
6167
6465
|
}
|
|
6466
|
+
if ([core.Service.OneClickCCTP].includes(serviceType)) {
|
|
6467
|
+
reportData.cctp_permit = {
|
|
6468
|
+
...permitSignature,
|
|
6469
|
+
...quote.permitAdditionalData
|
|
6470
|
+
};
|
|
6471
|
+
}
|
|
6168
6472
|
if ([core.Service.OneClickFraxZero, core.Service.FraxZeroOneClick].includes(serviceType)) {
|
|
6169
6473
|
reportData.frax_zero_permit = {
|
|
6170
6474
|
...permitSignature,
|
|
@@ -6320,7 +6624,7 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6320
6624
|
result.status = core.TransactionStatus.Failed;
|
|
6321
6625
|
}
|
|
6322
6626
|
}
|
|
6323
|
-
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)) {
|
|
6324
6628
|
const _result = response?.data;
|
|
6325
6629
|
const status = _result?.status;
|
|
6326
6630
|
if (status === core.StableflowStatus.SUCCESS) {
|
|
@@ -6368,6 +6672,9 @@ var getHopMsgFee = async (params) => {
|
|
|
6368
6672
|
};
|
|
6369
6673
|
|
|
6370
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;
|
|
6371
6678
|
exports.DATA_HEX_PROTOBUF_EXTRA = DATA_HEX_PROTOBUF_EXTRA;
|
|
6372
6679
|
exports.FRAXZERO_MIDDLE_TOKEN_FRXUSD = FRAXZERO_MIDDLE_TOKEN_FRXUSD;
|
|
6373
6680
|
exports.FRAXZERO_MIDDLE_TOKEN_USDC = FRAXZERO_MIDDLE_TOKEN_USDC;
|