@stableflow/bridges 3.1.0 → 3.1.1-beta-0b82f1112c-20260722
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 +4 -3
- package/dist/index.d.mts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +355 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +354 -37
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ var ONECLICK_PROXY = {
|
|
|
23
23
|
["Avalanche"]: "0xc8dB1175132C64e311D01258dD05D4e2e75fD7b8",
|
|
24
24
|
["Ethereum"]: "0xc8dB1175132C64e311D01258dD05D4e2e75fD7b8",
|
|
25
25
|
["Berachain"]: "0x1766A6B8453c7dbcA8c70d17980B6EA87ACA4F60",
|
|
26
|
+
["Gnosis"]: "0x53812Feae0fd2C43f8E6D8847A7f5d035F1d1f8f",
|
|
26
27
|
["Tron"]: "TMqM35eVd3D9d7JbShRrMzMPyWLFweKYvW",
|
|
27
28
|
["Solana"]: "HWk6MsFEGzXxpe9B4mfEHpvVoCwNeVVMFxb5Mi7qNTM",
|
|
28
29
|
["Near"]: "stbflow.near",
|
|
@@ -74,7 +75,7 @@ var OneClickService = class {
|
|
|
74
75
|
async formatQuoteData(res) {
|
|
75
76
|
const { params } = res;
|
|
76
77
|
const { isProxy = true, prices } = params;
|
|
77
|
-
const isExactOutput = params.swapType ===
|
|
78
|
+
const isExactOutput = params.swapType === core.OneClickSwapType.Output;
|
|
78
79
|
core.getPrice(prices, params.fromToken.nativeToken.symbol);
|
|
79
80
|
params.fromToken.nativeToken.decimals;
|
|
80
81
|
const cs = new core.Csl(core.OpenAPI.DEBUG);
|
|
@@ -91,11 +92,6 @@ var OneClickService = class {
|
|
|
91
92
|
let priceImpact = Big__default.default(0);
|
|
92
93
|
let _amountInUsd = res.data?.quote?.amountInUsd || 0;
|
|
93
94
|
let _amountOutUsd = res.data?.quote?.amountOutUsd || 0;
|
|
94
|
-
if (isExactOutput) {
|
|
95
|
-
res.data.quote.amountInFormatted = core.numberRemoveEndZero(Big__default.default(res.data?.quote?.minAmountIn || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, Big__default.default.roundUp));
|
|
96
|
-
_amountInUsd = Big__default.default(res.data.quote.amountInFormatted).times(core.getPrice(params.prices, params.fromToken.symbol));
|
|
97
|
-
_amountOutUsd = Big__default.default(res.data?.quote?.amountOutFormatted || 0).times(core.getPrice(params.prices, params.fromToken.symbol));
|
|
98
|
-
}
|
|
99
95
|
try {
|
|
100
96
|
priceImpact = Big__default.default(Big__default.default(_amountInUsd).minus(_amountOutUsd)).div(_amountInUsd || 1);
|
|
101
97
|
if (Big__default.default(priceImpact).lt(0)) {
|
|
@@ -143,7 +139,7 @@ var OneClickService = class {
|
|
|
143
139
|
fromToken: params.fromToken,
|
|
144
140
|
refundTo: params.refundTo,
|
|
145
141
|
recipient: params.recipient,
|
|
146
|
-
amountWei: isExactOutput ? res.data?.quote?.
|
|
142
|
+
amountWei: isExactOutput ? res.data?.quote?.amountIn : params.amountWei,
|
|
147
143
|
prices: params.prices,
|
|
148
144
|
evmGasFees: params.evmGasFees,
|
|
149
145
|
depositAddress: res.data?.quote?.depositAddress ?? core.DefaultAddresses[params.fromToken.chainType]
|
|
@@ -187,7 +183,7 @@ var OneClickService = class {
|
|
|
187
183
|
prices,
|
|
188
184
|
amountWei,
|
|
189
185
|
appFees = [],
|
|
190
|
-
swapType =
|
|
186
|
+
swapType = core.OneClickSwapType.Input,
|
|
191
187
|
isProxy = true,
|
|
192
188
|
slippageTolerance,
|
|
193
189
|
...restParams
|
|
@@ -196,7 +192,7 @@ var OneClickService = class {
|
|
|
196
192
|
const execTime = new core.ExecTime({ type: _quoteType, logStyle: "lime-400", isDebug: core.OpenAPI.DEBUG });
|
|
197
193
|
const quoteParams = {
|
|
198
194
|
depositMode: "SIMPLE",
|
|
199
|
-
swapType: swapType ||
|
|
195
|
+
swapType: swapType || core.OneClickSwapType.Input,
|
|
200
196
|
depositType: "ORIGIN_CHAIN",
|
|
201
197
|
sessionId: `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
202
198
|
recipientType: "DESTINATION_CHAIN",
|
|
@@ -210,9 +206,6 @@ var OneClickService = class {
|
|
|
210
206
|
amount: amountWei,
|
|
211
207
|
slippageTolerance: slippageTolerance * 100
|
|
212
208
|
};
|
|
213
|
-
if (swapType === "EXACT_OUTPUT") {
|
|
214
|
-
quoteParams.amount = Big__default.default(amountWei || 0).div(10 ** fromToken.decimals).times(10 ** toToken.decimals).toFixed(0);
|
|
215
|
-
}
|
|
216
209
|
for (const k in restParams) {
|
|
217
210
|
if (["evmAddress", "evmWallet", "destinationChain", "originChain"].includes(k)) {
|
|
218
211
|
continue;
|
|
@@ -481,7 +474,7 @@ var getQuoteModes = (params) => {
|
|
|
481
474
|
if (typeof quoteDataService === "undefined") {
|
|
482
475
|
return false;
|
|
483
476
|
}
|
|
484
|
-
if ([core.Service.OneClickUsdt0].includes(quoteDataService)) {
|
|
477
|
+
if ([core.Service.OneClickUsdt0, core.Service.OneClickCCTP].includes(quoteDataService)) {
|
|
485
478
|
return true;
|
|
486
479
|
}
|
|
487
480
|
if (quoteDataService === core.Service.OneClickFraxZero) {
|
|
@@ -497,7 +490,7 @@ var getQuoteModes = (params) => {
|
|
|
497
490
|
if (typeof quoteDataService === "undefined") {
|
|
498
491
|
return false;
|
|
499
492
|
}
|
|
500
|
-
if ([core.Service.OneClickUsdt0, core.Service.OneClick].includes(quoteDataService)) {
|
|
493
|
+
if ([core.Service.OneClickUsdt0, core.Service.OneClick, core.Service.OneClickCCTP].includes(quoteDataService)) {
|
|
501
494
|
return true;
|
|
502
495
|
}
|
|
503
496
|
if (quoteDataService === core.Service.OneClickFraxZero) {
|
|
@@ -513,7 +506,7 @@ var getQuoteModes = (params) => {
|
|
|
513
506
|
if (typeof quoteDataService === "undefined") {
|
|
514
507
|
return false;
|
|
515
508
|
}
|
|
516
|
-
if ([core.Service.Usdt0OneClick].includes(quoteDataService)) {
|
|
509
|
+
if ([core.Service.Usdt0OneClick, core.Service.CCTPOneClick].includes(quoteDataService)) {
|
|
517
510
|
return true;
|
|
518
511
|
}
|
|
519
512
|
if (quoteDataService === core.Service.FraxZeroOneClick) {
|
|
@@ -529,7 +522,7 @@ var getQuoteModes = (params) => {
|
|
|
529
522
|
isExactOutput: getIsExactOutput(),
|
|
530
523
|
isOneClickService: getIsOneClickService(),
|
|
531
524
|
isQuoteParamDepositAddress: getIsQuoteParamDepositAddress(),
|
|
532
|
-
isPermitWithNonce: typeof quoteDataService === "undefined" ? false : [core.Service.OneClickUsdt0, core.Service.OneClickFraxZero, core.Service.FraxZeroOneClick].includes(quoteDataService)
|
|
525
|
+
isPermitWithNonce: typeof quoteDataService === "undefined" ? false : [core.Service.OneClickUsdt0, core.Service.OneClickCCTP, core.Service.OneClickFraxZero, core.Service.FraxZeroOneClick].includes(quoteDataService)
|
|
533
526
|
};
|
|
534
527
|
};
|
|
535
528
|
function zeroPadValue(hex, lengthBytes) {
|
|
@@ -3939,7 +3932,8 @@ var CCTP_TOKEN_PROXY = {
|
|
|
3939
3932
|
["Optimism"]: "0x54Cf68aB8f68813F2a2dF20Af72D19c44485a0b2",
|
|
3940
3933
|
["Avalanche"]: "0xB6E3a1165aC3E0c370e316C27E959482460dBeDD",
|
|
3941
3934
|
["Solana"]: "8whUZNSbjJXC2UDRpo3PXo5MHzhptwVTTwpSYuTgQJNY",
|
|
3942
|
-
["Base"]: "0x7092B8E5445Fca836B0f9780c77C38C7cbb9A43D"
|
|
3935
|
+
["Base"]: "0x7092B8E5445Fca836B0f9780c77C38C7cbb9A43D",
|
|
3936
|
+
["Pharos"]: "0x53812feae0fd2c43f8e6d8847a7f5d035f1d1f8f"
|
|
3943
3937
|
};
|
|
3944
3938
|
var CCTP_TOKEN_PROXY_ABI = [
|
|
3945
3939
|
{
|
|
@@ -4015,8 +4009,9 @@ var CCTP_TOKEN_PROXY_ABI = [
|
|
|
4015
4009
|
"type": "function"
|
|
4016
4010
|
}
|
|
4017
4011
|
];
|
|
4018
|
-
|
|
4019
|
-
|
|
4012
|
+
var MIDDLE_TOKEN_CHAIN2 = core.usdcChains["arb"];
|
|
4013
|
+
var CCTP_PROXY_RELAY_CONTRACT = "0x0da5336C5CEb9d15e7659Ae376CC41d86Edd8802";
|
|
4014
|
+
var MIDDLE_CHAIN_REFOUND_ADDRESS2 = "0x654E7B96E1DE0b54E53D9ae8082fC2219E66dAC3";
|
|
4020
4015
|
var CCTP_DOMAINS = {
|
|
4021
4016
|
Ethereum: 0,
|
|
4022
4017
|
Arbitrum: 3,
|
|
@@ -4024,7 +4019,8 @@ var CCTP_DOMAINS = {
|
|
|
4024
4019
|
Optimism: 2,
|
|
4025
4020
|
Avalanche: 1,
|
|
4026
4021
|
Solana: 5,
|
|
4027
|
-
Base: 6
|
|
4022
|
+
Base: 6,
|
|
4023
|
+
Pharos: 31
|
|
4028
4024
|
};
|
|
4029
4025
|
var excludeFees3 = ["estimateGasUsd"];
|
|
4030
4026
|
var CCTPService = class {
|
|
@@ -4843,7 +4839,7 @@ var FraxZero2OneClickService = class extends FraxZeroService {
|
|
|
4843
4839
|
amountWei: ethereumUSDCAmountWei,
|
|
4844
4840
|
fromToken: FRAXZERO_MIDDLE_TOKEN_USDC,
|
|
4845
4841
|
originAsset: FRAXZERO_MIDDLE_TOKEN_USDC.assetId,
|
|
4846
|
-
swapType:
|
|
4842
|
+
swapType: core.OneClickSwapType.Flex,
|
|
4847
4843
|
isProxy: false,
|
|
4848
4844
|
refundTo: middleChainRecipientAddress,
|
|
4849
4845
|
wallet: middleChainWallet,
|
|
@@ -5009,10 +5005,16 @@ var OneClick2FraxZeroService = class extends FraxZeroService {
|
|
|
5009
5005
|
gasLimit = FRAXZERO_GAS_USED.MINT.TO_FRAXTAL;
|
|
5010
5006
|
}
|
|
5011
5007
|
gasLimit = gasLimit * 120n / 100n;
|
|
5008
|
+
let firstStepAmountWei = Big__default.default(params.amountWei || 0).div(10 ** fromToken.decimals).times(10 ** FRAXZERO_MIDDLE_TOKEN_USDC.decimals).toFixed(0, 0);
|
|
5009
|
+
if (!core.isStableToken(fromToken)) {
|
|
5010
|
+
const inputPrice = core.getPrice(prices, fromToken.symbol);
|
|
5011
|
+
const inputValue = Big__default.default(params.amountWei || 0).div(10 ** fromToken.decimals).times(inputPrice);
|
|
5012
|
+
firstStepAmountWei = Big__default.default(inputValue).times(10 ** FRAXZERO_MIDDLE_TOKEN_USDC.decimals).toFixed(0, 0);
|
|
5013
|
+
}
|
|
5012
5014
|
execTime.breakpoint();
|
|
5013
5015
|
previewMintResult = await middleChainWallet.previewMintFrxUSD({
|
|
5014
5016
|
dry,
|
|
5015
|
-
amountWei:
|
|
5017
|
+
amountWei: firstStepAmountWei,
|
|
5016
5018
|
fromToken: FRAXZERO_MIDDLE_TOKEN_USDC,
|
|
5017
5019
|
abi: FRAXZERO_REDEEM_MINT_ABI,
|
|
5018
5020
|
usdcCustodianAddress: FRAXZERO_REDEEM_USDC_CONTRACT
|
|
@@ -5062,9 +5064,10 @@ var OneClick2FraxZeroService = class extends FraxZeroService {
|
|
|
5062
5064
|
execTime.breakpoint();
|
|
5063
5065
|
const firstStepResult2 = await oneclick_default.quote({
|
|
5064
5066
|
...params,
|
|
5067
|
+
amountWei: firstStepAmountWei,
|
|
5065
5068
|
toToken: FRAXZERO_MIDDLE_TOKEN_USDC,
|
|
5066
5069
|
destinationAsset: FRAXZERO_MIDDLE_TOKEN_USDC.assetId,
|
|
5067
|
-
swapType:
|
|
5070
|
+
swapType: core.OneClickSwapType.Output,
|
|
5068
5071
|
isProxy: true,
|
|
5069
5072
|
recipient: middleChainRecipientAddress,
|
|
5070
5073
|
appFees: [
|
|
@@ -5128,7 +5131,7 @@ var OneClick2FraxZeroService = class extends FraxZeroService {
|
|
|
5128
5131
|
isOneClickTransfer: !firstStepResult2.sendParam ? {
|
|
5129
5132
|
originAsset: fromToken.contractAddress,
|
|
5130
5133
|
depositAddress: firstStepResult2.quote?.depositAddress,
|
|
5131
|
-
amount: firstStepResult2.quote?.
|
|
5134
|
+
amount: firstStepResult2.quote?.amountIn
|
|
5132
5135
|
} : false,
|
|
5133
5136
|
isFromEthereumUSDC,
|
|
5134
5137
|
isToEthereumFrxUSD
|
|
@@ -5297,7 +5300,7 @@ var Usdt0OneClickService = class {
|
|
|
5297
5300
|
...params,
|
|
5298
5301
|
fromToken: MIDDLE_TOKEN_CHAIN,
|
|
5299
5302
|
originAsset: MIDDLE_TOKEN_CHAIN.assetId,
|
|
5300
|
-
swapType:
|
|
5303
|
+
swapType: core.OneClickSwapType.Flex,
|
|
5301
5304
|
isProxy: false,
|
|
5302
5305
|
refundTo: middleChainRecipientAddress,
|
|
5303
5306
|
wallet: middleChainWallet
|
|
@@ -5392,9 +5395,15 @@ var OneClickUsdt0Service = class {
|
|
|
5392
5395
|
if (!middleChainRecipientAddress) {
|
|
5393
5396
|
throw new Error("evmAddress is required");
|
|
5394
5397
|
}
|
|
5398
|
+
let secondStepAmountWei = Big__default.default(params.amountWei || 0).div(10 ** fromToken.decimals).times(10 ** MIDDLE_TOKEN_CHAIN.decimals).toFixed(0);
|
|
5399
|
+
if (!core.isStableToken(fromToken)) {
|
|
5400
|
+
const inputPrice = core.getPrice(prices, fromToken.symbol);
|
|
5401
|
+
const inputValue = Big__default.default(params.amountWei || 0).div(10 ** fromToken.decimals).times(inputPrice);
|
|
5402
|
+
secondStepAmountWei = Big__default.default(inputValue).times(10 ** MIDDLE_TOKEN_CHAIN.decimals).toFixed(0);
|
|
5403
|
+
}
|
|
5395
5404
|
const usdt0Params = {
|
|
5396
5405
|
...params,
|
|
5397
|
-
amountWei:
|
|
5406
|
+
amountWei: secondStepAmountWei,
|
|
5398
5407
|
fromToken: MIDDLE_TOKEN_CHAIN,
|
|
5399
5408
|
originChain: MIDDLE_TOKEN_CHAIN.chainName,
|
|
5400
5409
|
refundTo: middleChainRecipientAddress,
|
|
@@ -5407,20 +5416,22 @@ var OneClickUsdt0Service = class {
|
|
|
5407
5416
|
usdt0Result.fees.nativeFeeUsd = core.numberRemoveEndZero(Big__default.default(usdt0Result.fees?.nativeFeeUsd || 0).times(1 + usdt0MessageFeeBuffer).toFixed(20));
|
|
5408
5417
|
usdt0Result.fees.nativeFee = core.numberRemoveEndZero(Big__default.default(usdt0Result.fees?.nativeFee || 0).times(1 + usdt0MessageFeeBuffer).toFixed(fromToken.nativeToken.decimals));
|
|
5409
5418
|
const usdt0MessageFeeUsd = usdt0Result.fees.nativeFeeUsd;
|
|
5410
|
-
const usdt0MessageFeeAmount = Big__default.default(usdt0MessageFeeUsd || 0).div(core.getPrice(prices, MIDDLE_TOKEN_CHAIN.symbol) || 1).toFixed(MIDDLE_TOKEN_CHAIN.decimals);
|
|
5411
5419
|
if (usdt0Result.errMsg) {
|
|
5412
5420
|
return usdt0Result;
|
|
5413
5421
|
}
|
|
5414
|
-
const
|
|
5422
|
+
const usdt0MessageFeeAmountInFromToken = Big__default.default(usdt0MessageFeeUsd || 0).div(core.getPrice(prices, fromToken.symbol) || 1).toFixed(fromToken.decimals);
|
|
5423
|
+
const fromTokenAmount = Big__default.default(params.amountWei).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
|
|
5424
|
+
const oneClickFeeRatio = Big__default.default(usdt0MessageFeeAmountInFromToken || 0).div(Big__default.default(usdt0MessageFeeAmountInFromToken || 0).plus(fromTokenAmount)).times(1e4).toFixed(0, Big__default.default.roundUp);
|
|
5415
5425
|
if (Big__default.default(oneClickFeeRatio).gt(1e4)) {
|
|
5416
|
-
return { errMsg: `Amount is too low, at least ${
|
|
5426
|
+
return { errMsg: `Amount is too low, at least ${usdt0MessageFeeAmountInFromToken}` };
|
|
5417
5427
|
}
|
|
5418
5428
|
execTime.breakpoint();
|
|
5419
5429
|
const oneClickResult = await oneclick_default.quote({
|
|
5420
5430
|
...params,
|
|
5431
|
+
amountWei: secondStepAmountWei,
|
|
5421
5432
|
toToken: MIDDLE_TOKEN_CHAIN,
|
|
5422
5433
|
destinationAsset: MIDDLE_TOKEN_CHAIN.assetId,
|
|
5423
|
-
swapType:
|
|
5434
|
+
swapType: core.OneClickSwapType.Output,
|
|
5424
5435
|
isProxy: true,
|
|
5425
5436
|
recipient: middleChainRecipientAddress,
|
|
5426
5437
|
appFees: [
|
|
@@ -5504,6 +5515,279 @@ var OneClickUsdt0Service = class {
|
|
|
5504
5515
|
}
|
|
5505
5516
|
};
|
|
5506
5517
|
var from_oneclick_default2 = new OneClickUsdt0Service();
|
|
5518
|
+
var excludeFees5 = ["estimateGasUsd"];
|
|
5519
|
+
var CCTPOneClickService = class {
|
|
5520
|
+
async quote(params) {
|
|
5521
|
+
const {
|
|
5522
|
+
dry,
|
|
5523
|
+
evmWallet,
|
|
5524
|
+
evmAddress
|
|
5525
|
+
} = params;
|
|
5526
|
+
const cs = new core.Csl(core.OpenAPI.DEBUG);
|
|
5527
|
+
const csl = cs.log;
|
|
5528
|
+
const execTime = new core.ExecTime({ type: "CCTPOneClickService", logStyle: "lime-700", isDebug: core.OpenAPI.DEBUG });
|
|
5529
|
+
if (!evmWallet) {
|
|
5530
|
+
throw new Error("evmWallet is required");
|
|
5531
|
+
}
|
|
5532
|
+
if (!evmAddress) {
|
|
5533
|
+
throw new Error("evmAddress is required");
|
|
5534
|
+
}
|
|
5535
|
+
const cctpParams = {
|
|
5536
|
+
...params,
|
|
5537
|
+
toToken: MIDDLE_TOKEN_CHAIN2,
|
|
5538
|
+
destinationChain: MIDDLE_TOKEN_CHAIN2.chainName,
|
|
5539
|
+
recipient: MIDDLE_CHAIN_REFOUND_ADDRESS2
|
|
5540
|
+
};
|
|
5541
|
+
const oneClickParams = {
|
|
5542
|
+
...params,
|
|
5543
|
+
fromToken: MIDDLE_TOKEN_CHAIN2,
|
|
5544
|
+
originAsset: MIDDLE_TOKEN_CHAIN2.assetId,
|
|
5545
|
+
swapType: core.OneClickSwapType.Flex,
|
|
5546
|
+
isProxy: false,
|
|
5547
|
+
refundTo: evmAddress,
|
|
5548
|
+
wallet: evmWallet
|
|
5549
|
+
};
|
|
5550
|
+
let cctpResult;
|
|
5551
|
+
let oneClickResult;
|
|
5552
|
+
if (!dry) {
|
|
5553
|
+
execTime.breakpoint();
|
|
5554
|
+
oneClickResult = await oneclick_default.quote({
|
|
5555
|
+
...oneClickParams,
|
|
5556
|
+
amountWei: Big__default.default(0.01).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0)
|
|
5557
|
+
});
|
|
5558
|
+
execTime.log("CCTPOneClickService.quote", "oneClickService.quote: %o", oneClickResult);
|
|
5559
|
+
if (oneClickResult.errMsg) {
|
|
5560
|
+
return oneClickResult;
|
|
5561
|
+
}
|
|
5562
|
+
cctpParams.recipient = oneClickResult.quote.depositAddress;
|
|
5563
|
+
execTime.breakpoint();
|
|
5564
|
+
cctpResult = await cctp_default.quote(cctpParams);
|
|
5565
|
+
execTime.log("CCTPOneClickService.quote", "cctpService.quote: %o", cctpResult);
|
|
5566
|
+
execTime.breakpoint();
|
|
5567
|
+
try {
|
|
5568
|
+
const oneClickResult2 = await oneclick_default.quote({
|
|
5569
|
+
...oneClickParams,
|
|
5570
|
+
dry: true,
|
|
5571
|
+
amountWei: Big__default.default(cctpResult.outputAmount || 0).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0)
|
|
5572
|
+
});
|
|
5573
|
+
oneClickResult.fees = oneClickResult2.fees;
|
|
5574
|
+
oneClickResult.outputAmount = oneClickResult2.outputAmount;
|
|
5575
|
+
oneClickResult.estimateTime = oneClickResult2.estimateTime;
|
|
5576
|
+
oneClickResult.priceImpact = oneClickResult2.priceImpact;
|
|
5577
|
+
oneClickResult.exchangeRate = oneClickResult2.exchangeRate;
|
|
5578
|
+
execTime.log("CCTPOneClickService.quote", "confirm get actual output amount result: %o", oneClickResult2);
|
|
5579
|
+
} catch (err) {
|
|
5580
|
+
execTime.log("CCTPOneClickService.quote", "confirm get actual output amount error: %o", err);
|
|
5581
|
+
}
|
|
5582
|
+
} else {
|
|
5583
|
+
execTime.breakpoint();
|
|
5584
|
+
cctpResult = await cctp_default.quote(cctpParams);
|
|
5585
|
+
execTime.log("CCTPOneClickService.quote", "cctpService.quote dry: %o", cctpResult);
|
|
5586
|
+
if (cctpResult.errMsg) {
|
|
5587
|
+
return cctpResult;
|
|
5588
|
+
}
|
|
5589
|
+
oneClickParams.amountWei = Big__default.default(cctpResult.outputAmount || 0).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0);
|
|
5590
|
+
execTime.breakpoint();
|
|
5591
|
+
oneClickResult = await oneclick_default.quote(oneClickParams);
|
|
5592
|
+
execTime.log("CCTPOneClickService.quote", "oneClickService.quote: %o", oneClickResult);
|
|
5593
|
+
}
|
|
5594
|
+
if (oneClickResult.errMsg) {
|
|
5595
|
+
return oneClickResult;
|
|
5596
|
+
}
|
|
5597
|
+
if (cctpResult.errMsg) {
|
|
5598
|
+
return cctpResult;
|
|
5599
|
+
}
|
|
5600
|
+
csl("CCTPOneClickService quote", "rose-600", "oneClickResult: %o", oneClickResult);
|
|
5601
|
+
csl("CCTPOneClickService quote", "rose-600", "cctpResult: %o", cctpResult);
|
|
5602
|
+
let totalFeesUsd = Big__default.default(0);
|
|
5603
|
+
const fees = {
|
|
5604
|
+
...cctpResult.fees
|
|
5605
|
+
};
|
|
5606
|
+
for (const feeKey in oneClickResult.fees) {
|
|
5607
|
+
if (excludeFees.includes(feeKey)) {
|
|
5608
|
+
continue;
|
|
5609
|
+
}
|
|
5610
|
+
fees[feeKey] = oneClickResult.fees[feeKey];
|
|
5611
|
+
}
|
|
5612
|
+
for (const feeKey in fees) {
|
|
5613
|
+
if (excludeFees5.includes(feeKey)) {
|
|
5614
|
+
continue;
|
|
5615
|
+
}
|
|
5616
|
+
totalFeesUsd = Big__default.default(totalFeesUsd || 0).plus(fees[feeKey] || 0);
|
|
5617
|
+
}
|
|
5618
|
+
execTime.logTotal("CCTPOneClickService.quote");
|
|
5619
|
+
return {
|
|
5620
|
+
...cctpResult,
|
|
5621
|
+
fees,
|
|
5622
|
+
totalFeesUsd: core.numberRemoveEndZero(Big__default.default(totalFeesUsd).toFixed(20)),
|
|
5623
|
+
estimateTime: cctpResult.estimateTime + oneClickResult.estimateTime,
|
|
5624
|
+
outputAmount: oneClickResult.outputAmount,
|
|
5625
|
+
priceImpact: oneClickResult.priceImpact,
|
|
5626
|
+
exchangeRate: oneClickResult.exchangeRate,
|
|
5627
|
+
quoteParam: {
|
|
5628
|
+
...cctpResult.quoteParam,
|
|
5629
|
+
toToken: params.toToken,
|
|
5630
|
+
middleToken: MIDDLE_TOKEN_CHAIN2,
|
|
5631
|
+
recipient: params.recipient,
|
|
5632
|
+
depositAddress: oneClickResult.quote.depositAddress
|
|
5633
|
+
},
|
|
5634
|
+
sourceQuoteParams: params
|
|
5635
|
+
};
|
|
5636
|
+
}
|
|
5637
|
+
async estimateTransaction(params, quoteData) {
|
|
5638
|
+
return cctp_default.estimateTransaction(params, quoteData);
|
|
5639
|
+
}
|
|
5640
|
+
async send(params) {
|
|
5641
|
+
const {
|
|
5642
|
+
wallet,
|
|
5643
|
+
...rest
|
|
5644
|
+
} = params;
|
|
5645
|
+
return wallet.send(core.SendType.SEND, rest);
|
|
5646
|
+
}
|
|
5647
|
+
getStatus(params) {
|
|
5648
|
+
return core.getRequest("/v0/trade", {
|
|
5649
|
+
deposit_address: params.depositAddress
|
|
5650
|
+
});
|
|
5651
|
+
}
|
|
5652
|
+
};
|
|
5653
|
+
var to_oneclick_default3 = new CCTPOneClickService();
|
|
5654
|
+
var OneClickCCTPService = class {
|
|
5655
|
+
async quote(params) {
|
|
5656
|
+
const {
|
|
5657
|
+
evmWallet,
|
|
5658
|
+
evmAddress,
|
|
5659
|
+
fromToken,
|
|
5660
|
+
prices
|
|
5661
|
+
} = params;
|
|
5662
|
+
const execTime = new core.ExecTime({ type: "OneClickCCTP", logStyle: "lime-500", isDebug: core.OpenAPI.DEBUG });
|
|
5663
|
+
if (!evmWallet) {
|
|
5664
|
+
throw new Error("evmWallet is required");
|
|
5665
|
+
}
|
|
5666
|
+
if (!evmAddress) {
|
|
5667
|
+
throw new Error("evmAddress is required");
|
|
5668
|
+
}
|
|
5669
|
+
let secondStepAmountWei = Big__default.default(params.amountWei || 0).div(10 ** fromToken.decimals).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0);
|
|
5670
|
+
if (!core.isStableToken(fromToken)) {
|
|
5671
|
+
const inputPrice = core.getPrice(prices, fromToken.symbol);
|
|
5672
|
+
const inputValue = Big__default.default(params.amountWei || 0).div(10 ** fromToken.decimals).times(inputPrice);
|
|
5673
|
+
secondStepAmountWei = Big__default.default(inputValue).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0);
|
|
5674
|
+
}
|
|
5675
|
+
const cctpParams = {
|
|
5676
|
+
...params,
|
|
5677
|
+
amountWei: secondStepAmountWei,
|
|
5678
|
+
fromToken: MIDDLE_TOKEN_CHAIN2,
|
|
5679
|
+
originChain: MIDDLE_TOKEN_CHAIN2.chainName,
|
|
5680
|
+
refundTo: MIDDLE_CHAIN_REFOUND_ADDRESS2,
|
|
5681
|
+
wallet: evmWallet
|
|
5682
|
+
};
|
|
5683
|
+
execTime.breakpoint();
|
|
5684
|
+
const cctpResult = await cctp_default.quote(cctpParams);
|
|
5685
|
+
execTime.log("cctpService.quote");
|
|
5686
|
+
const cctpFeeBuffer = 1.2;
|
|
5687
|
+
const cctpMintFeeUsd = core.numberRemoveEndZero(Big__default.default(cctpResult.fees?.estimateMintGasUsd || 0).times(1 + cctpFeeBuffer).toFixed(20));
|
|
5688
|
+
const cctpBridgeFeeUsd = core.numberRemoveEndZero(Big__default.default(cctpResult.fees?.bridgeFeeUsd || 0).times(1 + cctpFeeBuffer).toFixed(20));
|
|
5689
|
+
const cctpTotalFeeUsd = Big__default.default(cctpMintFeeUsd || 0).plus(cctpBridgeFeeUsd || 0).toFixed(20);
|
|
5690
|
+
if (cctpResult.errMsg) {
|
|
5691
|
+
return cctpResult;
|
|
5692
|
+
}
|
|
5693
|
+
const cctpFeeAmountInFromToken = Big__default.default(cctpTotalFeeUsd || 0).div(core.getPrice(prices, fromToken.symbol) || 1).toFixed(fromToken.decimals);
|
|
5694
|
+
const fromTokenAmount = Big__default.default(params.amountWei).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
|
|
5695
|
+
const oneClickFeeRatio = Big__default.default(cctpFeeAmountInFromToken || 0).div(Big__default.default(cctpFeeAmountInFromToken || 0).plus(fromTokenAmount)).times(1e4).toFixed(0, Big__default.default.roundUp);
|
|
5696
|
+
if (Big__default.default(oneClickFeeRatio).gt(1e4)) {
|
|
5697
|
+
return { errMsg: `Amount is too low, at least ${cctpFeeAmountInFromToken}` };
|
|
5698
|
+
}
|
|
5699
|
+
execTime.breakpoint();
|
|
5700
|
+
const oneClickResult = await oneclick_default.quote({
|
|
5701
|
+
...params,
|
|
5702
|
+
amountWei: secondStepAmountWei,
|
|
5703
|
+
toToken: MIDDLE_TOKEN_CHAIN2,
|
|
5704
|
+
destinationAsset: MIDDLE_TOKEN_CHAIN2.assetId,
|
|
5705
|
+
swapType: core.OneClickSwapType.Output,
|
|
5706
|
+
isProxy: true,
|
|
5707
|
+
recipient: evmAddress,
|
|
5708
|
+
appFees: [
|
|
5709
|
+
...params.appFees || [],
|
|
5710
|
+
{
|
|
5711
|
+
recipient: "reffer.near",
|
|
5712
|
+
fee: +oneClickFeeRatio
|
|
5713
|
+
}
|
|
5714
|
+
]
|
|
5715
|
+
});
|
|
5716
|
+
execTime.log("oneClickService.quote");
|
|
5717
|
+
let totalFeesUsd = Big__default.default(0);
|
|
5718
|
+
let _destinationGasFeeUsd = Big__default.default(oneClickResult.fees?.destinationGasFeeUsd || 0).minus(cctpTotalFeeUsd);
|
|
5719
|
+
if (Big__default.default(_destinationGasFeeUsd).lt(0)) {
|
|
5720
|
+
_destinationGasFeeUsd = Big__default.default(0);
|
|
5721
|
+
}
|
|
5722
|
+
const fees = {
|
|
5723
|
+
...oneClickResult.fees,
|
|
5724
|
+
destinationGasFeeUsd: core.numberRemoveEndZero(Big__default.default(_destinationGasFeeUsd).toFixed(20)),
|
|
5725
|
+
estimateMintGasUsd: cctpMintFeeUsd,
|
|
5726
|
+
bridgeFeeUsd: cctpBridgeFeeUsd
|
|
5727
|
+
};
|
|
5728
|
+
for (const feeKey in cctpResult.fees) {
|
|
5729
|
+
if (["estimateGasUsd"].includes(feeKey)) {
|
|
5730
|
+
continue;
|
|
5731
|
+
}
|
|
5732
|
+
if (!fees[feeKey]) {
|
|
5733
|
+
fees[feeKey] = cctpResult.fees[feeKey];
|
|
5734
|
+
}
|
|
5735
|
+
}
|
|
5736
|
+
for (const feeKey in fees) {
|
|
5737
|
+
if (excludeFees.includes(feeKey)) {
|
|
5738
|
+
continue;
|
|
5739
|
+
}
|
|
5740
|
+
totalFeesUsd = Big__default.default(totalFeesUsd || 0).plus(fees[feeKey] || 0);
|
|
5741
|
+
}
|
|
5742
|
+
const cctpSendParam = cctpResult.sendParam?.param;
|
|
5743
|
+
execTime.log("OneClickCCTPService.quote");
|
|
5744
|
+
return {
|
|
5745
|
+
...oneClickResult,
|
|
5746
|
+
needPermit: true,
|
|
5747
|
+
permitSpender: CCTP_PROXY_RELAY_CONTRACT,
|
|
5748
|
+
permitToken: MIDDLE_TOKEN_CHAIN2,
|
|
5749
|
+
permitAmountWei: oneClickResult?.quote?.amountOut,
|
|
5750
|
+
permitAdditionalData: {
|
|
5751
|
+
amount_wei: cctpSendParam?.[0]?.toString(),
|
|
5752
|
+
charged_amount: cctpSendParam?.[1]?.toString(),
|
|
5753
|
+
destination_domain: cctpSendParam?.[2]?.toString(),
|
|
5754
|
+
mint_recipient: cctpParams.recipient,
|
|
5755
|
+
burn_token: cctpSendParam?.[4]?.toString(),
|
|
5756
|
+
destination_caller: cctpSendParam?.[5]?.toString(),
|
|
5757
|
+
max_fee: cctpSendParam?.[6]?.toString(),
|
|
5758
|
+
finality_threshold: cctpSendParam?.[7]?.toString(),
|
|
5759
|
+
receipt_address: params.recipient,
|
|
5760
|
+
source_domain: cctpResult.quoteParam?.sourceDomain,
|
|
5761
|
+
destination_domain_id: cctpResult.quoteParam?.destinationDomain
|
|
5762
|
+
},
|
|
5763
|
+
fees,
|
|
5764
|
+
totalFeesUsd: core.numberRemoveEndZero(Big__default.default(totalFeesUsd).toFixed(20)),
|
|
5765
|
+
estimateTime: cctpResult.estimateTime + oneClickResult.estimateTime,
|
|
5766
|
+
outputAmount: cctpResult.outputAmount,
|
|
5767
|
+
needCreateTokenAccount: cctpResult.needCreateTokenAccount,
|
|
5768
|
+
quoteParam: {
|
|
5769
|
+
...oneClickResult.quoteParam,
|
|
5770
|
+
toToken: params.toToken,
|
|
5771
|
+
middleToken: MIDDLE_TOKEN_CHAIN2,
|
|
5772
|
+
recipient: params.recipient
|
|
5773
|
+
},
|
|
5774
|
+
cctpSendParam,
|
|
5775
|
+
sourceQuoteParams: params
|
|
5776
|
+
};
|
|
5777
|
+
}
|
|
5778
|
+
async estimateTransaction(params, quoteData) {
|
|
5779
|
+
return oneclick_default.estimateTransaction(params, quoteData);
|
|
5780
|
+
}
|
|
5781
|
+
async send(params) {
|
|
5782
|
+
return oneclick_default.send(params);
|
|
5783
|
+
}
|
|
5784
|
+
getStatus(params) {
|
|
5785
|
+
return core.getRequest("/v0/trade", {
|
|
5786
|
+
deposit_address: params.depositAddress
|
|
5787
|
+
});
|
|
5788
|
+
}
|
|
5789
|
+
};
|
|
5790
|
+
var from_oneclick_default3 = new OneClickCCTPService();
|
|
5507
5791
|
|
|
5508
5792
|
// src/native/contract.ts
|
|
5509
5793
|
var NativeChains = {
|
|
@@ -5670,6 +5954,8 @@ var ServiceMap = {
|
|
|
5670
5954
|
[core.Service.OneClickFraxZero]: from_oneclick_default,
|
|
5671
5955
|
[core.Service.Usdt0OneClick]: to_oneclick_default2,
|
|
5672
5956
|
[core.Service.OneClickUsdt0]: from_oneclick_default2,
|
|
5957
|
+
[core.Service.CCTPOneClick]: to_oneclick_default3,
|
|
5958
|
+
[core.Service.OneClickCCTP]: from_oneclick_default3,
|
|
5673
5959
|
[core.Service.Native]: native_default
|
|
5674
5960
|
};
|
|
5675
5961
|
var OVERRIDE_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -5709,7 +5995,7 @@ var getSendAmountWei = (serviceType, quote) => {
|
|
|
5709
5995
|
bridgeStore: { quoteDataService: serviceType }
|
|
5710
5996
|
});
|
|
5711
5997
|
if (isExactOutput) {
|
|
5712
|
-
return quote?.quote?.
|
|
5998
|
+
return quote?.quote?.amountIn;
|
|
5713
5999
|
}
|
|
5714
6000
|
return quote?.quoteParam?.amountWei;
|
|
5715
6001
|
};
|
|
@@ -5902,6 +6188,7 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
5902
6188
|
if (!params.fromToken || !params.fromToken.contractAddress || !params.toToken || !params.toToken.contractAddress || !params.refundTo || !params.recipient || !params.amountWei || Big__default.default(params.amountWei).lte(minInputAmount)) {
|
|
5903
6189
|
throw new Error("Invalid parameters");
|
|
5904
6190
|
}
|
|
6191
|
+
params.prices = await core.getPrices();
|
|
5905
6192
|
const formatQuoteParams = (service) => {
|
|
5906
6193
|
const _params = {
|
|
5907
6194
|
dry: params.dry,
|
|
@@ -5920,6 +6207,8 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
5920
6207
|
core.Service.OneClick,
|
|
5921
6208
|
core.Service.Usdt0OneClick,
|
|
5922
6209
|
core.Service.OneClickUsdt0,
|
|
6210
|
+
core.Service.CCTPOneClick,
|
|
6211
|
+
core.Service.OneClickCCTP,
|
|
5923
6212
|
core.Service.FraxZeroOneClick,
|
|
5924
6213
|
core.Service.OneClickFraxZero
|
|
5925
6214
|
].includes(service)) {
|
|
@@ -5934,7 +6223,9 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
5934
6223
|
core.Service.Usdt0,
|
|
5935
6224
|
core.Service.CCTP,
|
|
5936
6225
|
core.Service.Usdt0OneClick,
|
|
5937
|
-
core.Service.OneClickUsdt0
|
|
6226
|
+
core.Service.OneClickUsdt0,
|
|
6227
|
+
core.Service.CCTPOneClick,
|
|
6228
|
+
core.Service.OneClickCCTP
|
|
5938
6229
|
].includes(service)) {
|
|
5939
6230
|
_params.originChain = params.fromToken.chainName;
|
|
5940
6231
|
_params.destinationChain = params.toToken.chainName;
|
|
@@ -5948,6 +6239,8 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
5948
6239
|
}
|
|
5949
6240
|
const isFromUsdt = ["USDT", "USD\u20AE0"].includes(fromToken.symbol);
|
|
5950
6241
|
const isToUsdt = ["USDT", "USD\u20AE0"].includes(toToken.symbol);
|
|
6242
|
+
const isFromUsdc = ["USDC"].includes(fromToken.symbol);
|
|
6243
|
+
const isToUsdc = ["USDC"].includes(toToken.symbol);
|
|
5951
6244
|
const quoteServices = [];
|
|
5952
6245
|
const pushQuoteService = (_service) => {
|
|
5953
6246
|
const serviceStatus = core.getRouteStatus(_service, disabledServices);
|
|
@@ -5992,6 +6285,24 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
5992
6285
|
if (fromToken.services.includes(core.Service.OneClick) && toToken.services.includes(core.Service.FraxZero)) {
|
|
5993
6286
|
pushQuoteService(core.Service.OneClickFraxZero);
|
|
5994
6287
|
}
|
|
6288
|
+
if (fromToken.services.includes(core.Service.CCTP) && toToken.services.includes(core.Service.OneClick) && fromToken.chainName !== "Arbitrum") {
|
|
6289
|
+
if (isFromUsdc && isToUsdc) {
|
|
6290
|
+
if (toToken.chainName !== "Arbitrum") {
|
|
6291
|
+
pushQuoteService(core.Service.CCTPOneClick);
|
|
6292
|
+
}
|
|
6293
|
+
} else {
|
|
6294
|
+
pushQuoteService(core.Service.CCTPOneClick);
|
|
6295
|
+
}
|
|
6296
|
+
}
|
|
6297
|
+
if (fromToken.services.includes(core.Service.OneClick) && toToken.services.includes(core.Service.CCTP) && toToken.chainName !== "Arbitrum") {
|
|
6298
|
+
if (isFromUsdc && isToUsdc) {
|
|
6299
|
+
if (fromToken.chainName !== "Arbitrum") {
|
|
6300
|
+
pushQuoteService(core.Service.OneClickCCTP);
|
|
6301
|
+
}
|
|
6302
|
+
} else {
|
|
6303
|
+
pushQuoteService(core.Service.OneClickCCTP);
|
|
6304
|
+
}
|
|
6305
|
+
}
|
|
5995
6306
|
if (params.singleService) {
|
|
5996
6307
|
const quoteService = quoteServices.find((service) => service.service === params.singleService);
|
|
5997
6308
|
if (quoteService) {
|
|
@@ -6059,7 +6370,7 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6059
6370
|
const sendParam = quote.sendParam;
|
|
6060
6371
|
let _amountWei = quote.quoteParam?.amountWei;
|
|
6061
6372
|
if (isExactOutput) {
|
|
6062
|
-
_amountWei = quote.quote?.
|
|
6373
|
+
_amountWei = quote.quote?.amountIn;
|
|
6063
6374
|
}
|
|
6064
6375
|
if (isOneClickService) {
|
|
6065
6376
|
sendParams.sendParam = sendParam;
|
|
@@ -6100,7 +6411,7 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6100
6411
|
const toToken = quote.quoteParam.toToken;
|
|
6101
6412
|
let _amountWei = quote.quoteParam?.amountWei;
|
|
6102
6413
|
if (isExactOutput) {
|
|
6103
|
-
_amountWei = quote.quote?.
|
|
6414
|
+
_amountWei = quote.quote?.amountIn;
|
|
6104
6415
|
}
|
|
6105
6416
|
const reportData = {
|
|
6106
6417
|
project: core.ServiceBackend[serviceType],
|
|
@@ -6122,6 +6433,12 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6122
6433
|
...quote.permitAdditionalData
|
|
6123
6434
|
};
|
|
6124
6435
|
}
|
|
6436
|
+
if ([core.Service.OneClickCCTP].includes(serviceType)) {
|
|
6437
|
+
reportData.cctp_permit = {
|
|
6438
|
+
...permitSignature,
|
|
6439
|
+
...quote.permitAdditionalData
|
|
6440
|
+
};
|
|
6441
|
+
}
|
|
6125
6442
|
if ([core.Service.OneClickFraxZero, core.Service.FraxZeroOneClick].includes(serviceType)) {
|
|
6126
6443
|
reportData.frax_zero_permit = {
|
|
6127
6444
|
...permitSignature,
|
|
@@ -6277,7 +6594,7 @@ var BridgeSFA = class _BridgeSFA {
|
|
|
6277
6594
|
result.status = core.TransactionStatus.Failed;
|
|
6278
6595
|
}
|
|
6279
6596
|
}
|
|
6280
|
-
if ([core.Service.OneClickUsdt0, core.Service.Usdt0OneClick, core.Service.FraxZero, core.Service.OneClickFraxZero, core.Service.FraxZeroOneClick].includes(serviceType)) {
|
|
6597
|
+
if ([core.Service.OneClickUsdt0, core.Service.Usdt0OneClick, core.Service.CCTPOneClick, core.Service.OneClickCCTP, core.Service.FraxZero, core.Service.OneClickFraxZero, core.Service.FraxZeroOneClick].includes(serviceType)) {
|
|
6281
6598
|
const _result = response?.data;
|
|
6282
6599
|
const status = _result?.status;
|
|
6283
6600
|
if (status === core.StableflowStatus.SUCCESS) {
|
|
@@ -6325,6 +6642,9 @@ var getHopMsgFee = async (params) => {
|
|
|
6325
6642
|
};
|
|
6326
6643
|
|
|
6327
6644
|
exports.BridgeSFA = BridgeSFA;
|
|
6645
|
+
exports.CCTP_MIDDLE_CHAIN_REFOUND_ADDRESS = MIDDLE_CHAIN_REFOUND_ADDRESS2;
|
|
6646
|
+
exports.CCTP_MIDDLE_TOKEN_CHAIN = MIDDLE_TOKEN_CHAIN2;
|
|
6647
|
+
exports.CCTP_PROXY_RELAY_CONTRACT = CCTP_PROXY_RELAY_CONTRACT;
|
|
6328
6648
|
exports.DATA_HEX_PROTOBUF_EXTRA = DATA_HEX_PROTOBUF_EXTRA;
|
|
6329
6649
|
exports.FRAXZERO_MIDDLE_TOKEN_FRXUSD = FRAXZERO_MIDDLE_TOKEN_FRXUSD;
|
|
6330
6650
|
exports.FRAXZERO_MIDDLE_TOKEN_USDC = FRAXZERO_MIDDLE_TOKEN_USDC;
|