@stableflow/bridges 3.1.0 → 3.1.1-beta-a6a26eeb19-20260721

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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import Big from 'big.js';
2
- import { usdt0Chains, usdcChains, frxusdChains, Service, ExecTime, OpenAPI, getRequest, Csl, numberRemoveEndZero, getPrice, SendType, DefaultAddresses, postRequest, erc20Abi, tokens, ServiceBackend, TransactionStatus, StableflowStatus, LayerZeroStatus, OneClickStatus, getRouteStatus } from '@stableflow/core';
2
+ import { usdt0Chains, usdcChains, frxusdChains, Service, ExecTime, OpenAPI, getRequest, Csl, isStableToken, getPrice, numberRemoveEndZero, OneClickSwapType, SendType, DefaultAddresses, postRequest, erc20Abi, tokens, ServiceBackend, TransactionStatus, StableflowStatus, LayerZeroStatus, OneClickStatus, getRouteStatus } from '@stableflow/core';
3
3
  import bs58 from 'bs58';
4
4
  import { Buffer } from 'buffer';
5
5
  import { evmRpcFallbackProvider } from '@stableflow/utils-evm';
@@ -16,6 +16,7 @@ var ONECLICK_PROXY = {
16
16
  ["Avalanche"]: "0xc8dB1175132C64e311D01258dD05D4e2e75fD7b8",
17
17
  ["Ethereum"]: "0xc8dB1175132C64e311D01258dD05D4e2e75fD7b8",
18
18
  ["Berachain"]: "0x1766A6B8453c7dbcA8c70d17980B6EA87ACA4F60",
19
+ ["Gnosis"]: "0x53812Feae0fd2C43f8E6D8847A7f5d035F1d1f8f",
19
20
  ["Tron"]: "TMqM35eVd3D9d7JbShRrMzMPyWLFweKYvW",
20
21
  ["Solana"]: "HWk6MsFEGzXxpe9B4mfEHpvVoCwNeVVMFxb5Mi7qNTM",
21
22
  ["Near"]: "stbflow.near",
@@ -67,7 +68,7 @@ var OneClickService = class {
67
68
  async formatQuoteData(res) {
68
69
  const { params } = res;
69
70
  const { isProxy = true, prices } = params;
70
- const isExactOutput = params.swapType === "EXACT_OUTPUT";
71
+ const isExactOutput = params.swapType === OneClickSwapType.Output;
71
72
  getPrice(prices, params.fromToken.nativeToken.symbol);
72
73
  params.fromToken.nativeToken.decimals;
73
74
  const cs = new Csl(OpenAPI.DEBUG);
@@ -84,11 +85,6 @@ var OneClickService = class {
84
85
  let priceImpact = Big(0);
85
86
  let _amountInUsd = res.data?.quote?.amountInUsd || 0;
86
87
  let _amountOutUsd = res.data?.quote?.amountOutUsd || 0;
87
- if (isExactOutput) {
88
- res.data.quote.amountInFormatted = numberRemoveEndZero(Big(res.data?.quote?.minAmountIn || 0).div(10 ** params.fromToken.decimals).toFixed(params.fromToken.decimals, Big.roundUp));
89
- _amountInUsd = Big(res.data.quote.amountInFormatted).times(getPrice(params.prices, params.fromToken.symbol));
90
- _amountOutUsd = Big(res.data?.quote?.amountOutFormatted || 0).times(getPrice(params.prices, params.fromToken.symbol));
91
- }
92
88
  try {
93
89
  priceImpact = Big(Big(_amountInUsd).minus(_amountOutUsd)).div(_amountInUsd || 1);
94
90
  if (Big(priceImpact).lt(0)) {
@@ -136,7 +132,7 @@ var OneClickService = class {
136
132
  fromToken: params.fromToken,
137
133
  refundTo: params.refundTo,
138
134
  recipient: params.recipient,
139
- amountWei: isExactOutput ? res.data?.quote?.minAmountIn : params.amountWei,
135
+ amountWei: isExactOutput ? res.data?.quote?.amountIn : params.amountWei,
140
136
  prices: params.prices,
141
137
  evmGasFees: params.evmGasFees,
142
138
  depositAddress: res.data?.quote?.depositAddress ?? DefaultAddresses[params.fromToken.chainType]
@@ -180,7 +176,7 @@ var OneClickService = class {
180
176
  prices,
181
177
  amountWei,
182
178
  appFees = [],
183
- swapType = "EXACT_INPUT",
179
+ swapType = OneClickSwapType.Input,
184
180
  isProxy = true,
185
181
  slippageTolerance,
186
182
  ...restParams
@@ -189,7 +185,7 @@ var OneClickService = class {
189
185
  const execTime = new ExecTime({ type: _quoteType, logStyle: "lime-400", isDebug: OpenAPI.DEBUG });
190
186
  const quoteParams = {
191
187
  depositMode: "SIMPLE",
192
- swapType: swapType || "EXACT_INPUT",
188
+ swapType: swapType || OneClickSwapType.Input,
193
189
  depositType: "ORIGIN_CHAIN",
194
190
  sessionId: `session_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
195
191
  recipientType: "DESTINATION_CHAIN",
@@ -203,9 +199,6 @@ var OneClickService = class {
203
199
  amount: amountWei,
204
200
  slippageTolerance: slippageTolerance * 100
205
201
  };
206
- if (swapType === "EXACT_OUTPUT") {
207
- quoteParams.amount = Big(amountWei || 0).div(10 ** fromToken.decimals).times(10 ** toToken.decimals).toFixed(0);
208
- }
209
202
  for (const k in restParams) {
210
203
  if (["evmAddress", "evmWallet", "destinationChain", "originChain"].includes(k)) {
211
204
  continue;
@@ -474,7 +467,7 @@ var getQuoteModes = (params) => {
474
467
  if (typeof quoteDataService === "undefined") {
475
468
  return false;
476
469
  }
477
- if ([Service.OneClickUsdt0].includes(quoteDataService)) {
470
+ if ([Service.OneClickUsdt0, Service.OneClickCCTP].includes(quoteDataService)) {
478
471
  return true;
479
472
  }
480
473
  if (quoteDataService === Service.OneClickFraxZero) {
@@ -490,7 +483,7 @@ var getQuoteModes = (params) => {
490
483
  if (typeof quoteDataService === "undefined") {
491
484
  return false;
492
485
  }
493
- if ([Service.OneClickUsdt0, Service.OneClick].includes(quoteDataService)) {
486
+ if ([Service.OneClickUsdt0, Service.OneClick, Service.OneClickCCTP].includes(quoteDataService)) {
494
487
  return true;
495
488
  }
496
489
  if (quoteDataService === Service.OneClickFraxZero) {
@@ -506,7 +499,7 @@ var getQuoteModes = (params) => {
506
499
  if (typeof quoteDataService === "undefined") {
507
500
  return false;
508
501
  }
509
- if ([Service.Usdt0OneClick].includes(quoteDataService)) {
502
+ if ([Service.Usdt0OneClick, Service.CCTPOneClick].includes(quoteDataService)) {
510
503
  return true;
511
504
  }
512
505
  if (quoteDataService === Service.FraxZeroOneClick) {
@@ -522,7 +515,7 @@ var getQuoteModes = (params) => {
522
515
  isExactOutput: getIsExactOutput(),
523
516
  isOneClickService: getIsOneClickService(),
524
517
  isQuoteParamDepositAddress: getIsQuoteParamDepositAddress(),
525
- isPermitWithNonce: typeof quoteDataService === "undefined" ? false : [Service.OneClickUsdt0, Service.OneClickFraxZero, Service.FraxZeroOneClick].includes(quoteDataService)
518
+ isPermitWithNonce: typeof quoteDataService === "undefined" ? false : [Service.OneClickUsdt0, Service.OneClickCCTP, Service.OneClickFraxZero, Service.FraxZeroOneClick].includes(quoteDataService)
526
519
  };
527
520
  };
528
521
  function zeroPadValue(hex, lengthBytes) {
@@ -3932,7 +3925,8 @@ var CCTP_TOKEN_PROXY = {
3932
3925
  ["Optimism"]: "0x54Cf68aB8f68813F2a2dF20Af72D19c44485a0b2",
3933
3926
  ["Avalanche"]: "0xB6E3a1165aC3E0c370e316C27E959482460dBeDD",
3934
3927
  ["Solana"]: "8whUZNSbjJXC2UDRpo3PXo5MHzhptwVTTwpSYuTgQJNY",
3935
- ["Base"]: "0x7092B8E5445Fca836B0f9780c77C38C7cbb9A43D"
3928
+ ["Base"]: "0x7092B8E5445Fca836B0f9780c77C38C7cbb9A43D",
3929
+ ["Pharos"]: "0x53812feae0fd2c43f8e6d8847a7f5d035f1d1f8f"
3936
3930
  };
3937
3931
  var CCTP_TOKEN_PROXY_ABI = [
3938
3932
  {
@@ -4008,8 +4002,9 @@ var CCTP_TOKEN_PROXY_ABI = [
4008
4002
  "type": "function"
4009
4003
  }
4010
4004
  ];
4011
-
4012
- // src/cctp/config.ts
4005
+ var MIDDLE_TOKEN_CHAIN2 = usdcChains["arb"];
4006
+ var CCTP_PROXY_RELAY_CONTRACT = "0x0da5336C5CEb9d15e7659Ae376CC41d86Edd8802";
4007
+ var MIDDLE_CHAIN_REFOUND_ADDRESS2 = "0x654E7B96E1DE0b54E53D9ae8082fC2219E66dAC3";
4013
4008
  var CCTP_DOMAINS = {
4014
4009
  Ethereum: 0,
4015
4010
  Arbitrum: 3,
@@ -4017,7 +4012,8 @@ var CCTP_DOMAINS = {
4017
4012
  Optimism: 2,
4018
4013
  Avalanche: 1,
4019
4014
  Solana: 5,
4020
- Base: 6
4015
+ Base: 6,
4016
+ Pharos: 31
4021
4017
  };
4022
4018
  var excludeFees3 = ["estimateGasUsd"];
4023
4019
  var CCTPService = class {
@@ -4836,7 +4832,7 @@ var FraxZero2OneClickService = class extends FraxZeroService {
4836
4832
  amountWei: ethereumUSDCAmountWei,
4837
4833
  fromToken: FRAXZERO_MIDDLE_TOKEN_USDC,
4838
4834
  originAsset: FRAXZERO_MIDDLE_TOKEN_USDC.assetId,
4839
- swapType: "FLEX_INPUT",
4835
+ swapType: OneClickSwapType.Flex,
4840
4836
  isProxy: false,
4841
4837
  refundTo: middleChainRecipientAddress,
4842
4838
  wallet: middleChainWallet,
@@ -5002,10 +4998,16 @@ var OneClick2FraxZeroService = class extends FraxZeroService {
5002
4998
  gasLimit = FRAXZERO_GAS_USED.MINT.TO_FRAXTAL;
5003
4999
  }
5004
5000
  gasLimit = gasLimit * 120n / 100n;
5001
+ let firstStepAmountWei = Big(params.amountWei || 0).div(10 ** fromToken.decimals).times(10 ** FRAXZERO_MIDDLE_TOKEN_USDC.decimals).toFixed(0, 0);
5002
+ if (!isStableToken(fromToken)) {
5003
+ const inputPrice = getPrice(prices, fromToken.symbol);
5004
+ const inputValue = Big(params.amountWei || 0).div(10 ** fromToken.decimals).times(inputPrice);
5005
+ firstStepAmountWei = Big(inputValue).times(10 ** FRAXZERO_MIDDLE_TOKEN_USDC.decimals).toFixed(0, 0);
5006
+ }
5005
5007
  execTime.breakpoint();
5006
5008
  previewMintResult = await middleChainWallet.previewMintFrxUSD({
5007
5009
  dry,
5008
- amountWei: Big(amountWei || 0).div(10 ** fromToken.decimals).times(10 ** FRAXZERO_MIDDLE_TOKEN_USDC.decimals).toFixed(0, 0),
5010
+ amountWei: firstStepAmountWei,
5009
5011
  fromToken: FRAXZERO_MIDDLE_TOKEN_USDC,
5010
5012
  abi: FRAXZERO_REDEEM_MINT_ABI,
5011
5013
  usdcCustodianAddress: FRAXZERO_REDEEM_USDC_CONTRACT
@@ -5055,9 +5057,10 @@ var OneClick2FraxZeroService = class extends FraxZeroService {
5055
5057
  execTime.breakpoint();
5056
5058
  const firstStepResult2 = await oneclick_default.quote({
5057
5059
  ...params,
5060
+ amountWei: firstStepAmountWei,
5058
5061
  toToken: FRAXZERO_MIDDLE_TOKEN_USDC,
5059
5062
  destinationAsset: FRAXZERO_MIDDLE_TOKEN_USDC.assetId,
5060
- swapType: "EXACT_OUTPUT",
5063
+ swapType: OneClickSwapType.Output,
5061
5064
  isProxy: true,
5062
5065
  recipient: middleChainRecipientAddress,
5063
5066
  appFees: [
@@ -5121,7 +5124,7 @@ var OneClick2FraxZeroService = class extends FraxZeroService {
5121
5124
  isOneClickTransfer: !firstStepResult2.sendParam ? {
5122
5125
  originAsset: fromToken.contractAddress,
5123
5126
  depositAddress: firstStepResult2.quote?.depositAddress,
5124
- amount: firstStepResult2.quote?.minAmountIn
5127
+ amount: firstStepResult2.quote?.amountIn
5125
5128
  } : false,
5126
5129
  isFromEthereumUSDC,
5127
5130
  isToEthereumFrxUSD
@@ -5290,7 +5293,7 @@ var Usdt0OneClickService = class {
5290
5293
  ...params,
5291
5294
  fromToken: MIDDLE_TOKEN_CHAIN,
5292
5295
  originAsset: MIDDLE_TOKEN_CHAIN.assetId,
5293
- swapType: "FLEX_INPUT",
5296
+ swapType: OneClickSwapType.Flex,
5294
5297
  isProxy: false,
5295
5298
  refundTo: middleChainRecipientAddress,
5296
5299
  wallet: middleChainWallet
@@ -5385,9 +5388,15 @@ var OneClickUsdt0Service = class {
5385
5388
  if (!middleChainRecipientAddress) {
5386
5389
  throw new Error("evmAddress is required");
5387
5390
  }
5391
+ let secondStepAmountWei = Big(params.amountWei || 0).div(10 ** fromToken.decimals).times(10 ** MIDDLE_TOKEN_CHAIN.decimals).toFixed(0);
5392
+ if (!isStableToken(fromToken)) {
5393
+ const inputPrice = getPrice(prices, fromToken.symbol);
5394
+ const inputValue = Big(params.amountWei || 0).div(10 ** fromToken.decimals).times(inputPrice);
5395
+ secondStepAmountWei = Big(inputValue).times(10 ** MIDDLE_TOKEN_CHAIN.decimals).toFixed(0);
5396
+ }
5388
5397
  const usdt0Params = {
5389
5398
  ...params,
5390
- amountWei: Big(params.amountWei || 0).div(10 ** fromToken.decimals).times(10 ** MIDDLE_TOKEN_CHAIN.decimals).toFixed(0),
5399
+ amountWei: secondStepAmountWei,
5391
5400
  fromToken: MIDDLE_TOKEN_CHAIN,
5392
5401
  originChain: MIDDLE_TOKEN_CHAIN.chainName,
5393
5402
  refundTo: middleChainRecipientAddress,
@@ -5400,20 +5409,22 @@ var OneClickUsdt0Service = class {
5400
5409
  usdt0Result.fees.nativeFeeUsd = numberRemoveEndZero(Big(usdt0Result.fees?.nativeFeeUsd || 0).times(1 + usdt0MessageFeeBuffer).toFixed(20));
5401
5410
  usdt0Result.fees.nativeFee = numberRemoveEndZero(Big(usdt0Result.fees?.nativeFee || 0).times(1 + usdt0MessageFeeBuffer).toFixed(fromToken.nativeToken.decimals));
5402
5411
  const usdt0MessageFeeUsd = usdt0Result.fees.nativeFeeUsd;
5403
- const usdt0MessageFeeAmount = Big(usdt0MessageFeeUsd || 0).div(getPrice(prices, MIDDLE_TOKEN_CHAIN.symbol) || 1).toFixed(MIDDLE_TOKEN_CHAIN.decimals);
5404
5412
  if (usdt0Result.errMsg) {
5405
5413
  return usdt0Result;
5406
5414
  }
5407
- const oneClickFeeRatio = Big(usdt0MessageFeeAmount || 0).div(Big(usdt0MessageFeeAmount || 0).plus(Big(params.amountWei).div(10 ** fromToken.decimals).toFixed(fromToken.decimals))).times(1e4).toFixed(0, Big.roundUp);
5415
+ const usdt0MessageFeeAmountInFromToken = Big(usdt0MessageFeeUsd || 0).div(getPrice(prices, fromToken.symbol) || 1).toFixed(fromToken.decimals);
5416
+ const fromTokenAmount = Big(params.amountWei).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
5417
+ const oneClickFeeRatio = Big(usdt0MessageFeeAmountInFromToken || 0).div(Big(usdt0MessageFeeAmountInFromToken || 0).plus(fromTokenAmount)).times(1e4).toFixed(0, Big.roundUp);
5408
5418
  if (Big(oneClickFeeRatio).gt(1e4)) {
5409
- return { errMsg: `Amount is too low, at least ${usdt0MessageFeeAmount}` };
5419
+ return { errMsg: `Amount is too low, at least ${usdt0MessageFeeAmountInFromToken}` };
5410
5420
  }
5411
5421
  execTime.breakpoint();
5412
5422
  const oneClickResult = await oneclick_default.quote({
5413
5423
  ...params,
5424
+ amountWei: secondStepAmountWei,
5414
5425
  toToken: MIDDLE_TOKEN_CHAIN,
5415
5426
  destinationAsset: MIDDLE_TOKEN_CHAIN.assetId,
5416
- swapType: "EXACT_OUTPUT",
5427
+ swapType: OneClickSwapType.Output,
5417
5428
  isProxy: true,
5418
5429
  recipient: middleChainRecipientAddress,
5419
5430
  appFees: [
@@ -5497,6 +5508,279 @@ var OneClickUsdt0Service = class {
5497
5508
  }
5498
5509
  };
5499
5510
  var from_oneclick_default2 = new OneClickUsdt0Service();
5511
+ var excludeFees5 = ["estimateGasUsd"];
5512
+ var CCTPOneClickService = class {
5513
+ async quote(params) {
5514
+ const {
5515
+ dry,
5516
+ evmWallet,
5517
+ evmAddress
5518
+ } = params;
5519
+ const cs = new Csl(OpenAPI.DEBUG);
5520
+ const csl = cs.log;
5521
+ const execTime = new ExecTime({ type: "CCTPOneClickService", logStyle: "lime-700", isDebug: OpenAPI.DEBUG });
5522
+ if (!evmWallet) {
5523
+ throw new Error("evmWallet is required");
5524
+ }
5525
+ if (!evmAddress) {
5526
+ throw new Error("evmAddress is required");
5527
+ }
5528
+ const cctpParams = {
5529
+ ...params,
5530
+ toToken: MIDDLE_TOKEN_CHAIN2,
5531
+ destinationChain: MIDDLE_TOKEN_CHAIN2.chainName,
5532
+ recipient: MIDDLE_CHAIN_REFOUND_ADDRESS2
5533
+ };
5534
+ const oneClickParams = {
5535
+ ...params,
5536
+ fromToken: MIDDLE_TOKEN_CHAIN2,
5537
+ originAsset: MIDDLE_TOKEN_CHAIN2.assetId,
5538
+ swapType: OneClickSwapType.Flex,
5539
+ isProxy: false,
5540
+ refundTo: evmAddress,
5541
+ wallet: evmWallet
5542
+ };
5543
+ let cctpResult;
5544
+ let oneClickResult;
5545
+ if (!dry) {
5546
+ execTime.breakpoint();
5547
+ oneClickResult = await oneclick_default.quote({
5548
+ ...oneClickParams,
5549
+ amountWei: Big(0.01).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0)
5550
+ });
5551
+ execTime.log("oneClickService.quote: %o", oneClickResult);
5552
+ if (oneClickResult.errMsg) {
5553
+ return oneClickResult;
5554
+ }
5555
+ cctpParams.recipient = oneClickResult.quote.depositAddress;
5556
+ execTime.breakpoint();
5557
+ cctpResult = await cctp_default.quote(cctpParams);
5558
+ execTime.log("cctpService.quote: %o", cctpResult);
5559
+ execTime.breakpoint();
5560
+ try {
5561
+ const oneClickResult2 = await oneclick_default.quote({
5562
+ ...oneClickParams,
5563
+ dry: true,
5564
+ amountWei: Big(cctpResult.outputAmount || 0).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0)
5565
+ });
5566
+ oneClickResult.fees = oneClickResult2.fees;
5567
+ oneClickResult.outputAmount = oneClickResult2.outputAmount;
5568
+ oneClickResult.estimateTime = oneClickResult2.estimateTime;
5569
+ oneClickResult.priceImpact = oneClickResult2.priceImpact;
5570
+ oneClickResult.exchangeRate = oneClickResult2.exchangeRate;
5571
+ execTime.log("confirm get actual output amount result: %o", oneClickResult2);
5572
+ } catch (err) {
5573
+ execTime.log("confirm get actual output amount error: %o", err);
5574
+ }
5575
+ } else {
5576
+ execTime.breakpoint();
5577
+ cctpResult = await cctp_default.quote(cctpParams);
5578
+ execTime.log("cctpService.quote dry: %o", cctpResult);
5579
+ if (cctpResult.errMsg) {
5580
+ return cctpResult;
5581
+ }
5582
+ oneClickParams.amountWei = Big(cctpResult.outputAmount || 0).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0, 0);
5583
+ execTime.breakpoint();
5584
+ oneClickResult = await oneclick_default.quote(oneClickParams);
5585
+ execTime.log("oneClickService.quote: %o", oneClickResult);
5586
+ }
5587
+ if (oneClickResult.errMsg) {
5588
+ return oneClickResult;
5589
+ }
5590
+ if (cctpResult.errMsg) {
5591
+ return cctpResult;
5592
+ }
5593
+ csl("CCTPOneClickService quote", "rose-600", "oneClickResult: %o", oneClickResult);
5594
+ csl("CCTPOneClickService quote", "rose-600", "cctpResult: %o", cctpResult);
5595
+ let totalFeesUsd = Big(0);
5596
+ const fees = {
5597
+ ...cctpResult.fees
5598
+ };
5599
+ for (const feeKey in oneClickResult.fees) {
5600
+ if (excludeFees.includes(feeKey)) {
5601
+ continue;
5602
+ }
5603
+ fees[feeKey] = oneClickResult.fees[feeKey];
5604
+ }
5605
+ for (const feeKey in fees) {
5606
+ if (excludeFees5.includes(feeKey)) {
5607
+ continue;
5608
+ }
5609
+ totalFeesUsd = Big(totalFeesUsd || 0).plus(fees[feeKey] || 0);
5610
+ }
5611
+ execTime.logTotal("CCTPOneClickService.quote");
5612
+ return {
5613
+ ...cctpResult,
5614
+ fees,
5615
+ totalFeesUsd: numberRemoveEndZero(Big(totalFeesUsd).toFixed(20)),
5616
+ estimateTime: cctpResult.estimateTime + oneClickResult.estimateTime,
5617
+ outputAmount: oneClickResult.outputAmount,
5618
+ priceImpact: oneClickResult.priceImpact,
5619
+ exchangeRate: oneClickResult.exchangeRate,
5620
+ quoteParam: {
5621
+ ...cctpResult.quoteParam,
5622
+ toToken: params.toToken,
5623
+ middleToken: MIDDLE_TOKEN_CHAIN2,
5624
+ recipient: params.recipient,
5625
+ depositAddress: oneClickResult.quote.depositAddress
5626
+ },
5627
+ sourceQuoteParams: params
5628
+ };
5629
+ }
5630
+ async estimateTransaction(params, quoteData) {
5631
+ return cctp_default.estimateTransaction(params, quoteData);
5632
+ }
5633
+ async send(params) {
5634
+ const {
5635
+ wallet,
5636
+ ...rest
5637
+ } = params;
5638
+ return wallet.send(SendType.SEND, rest);
5639
+ }
5640
+ getStatus(params) {
5641
+ return getRequest("/v0/trade", {
5642
+ deposit_address: params.depositAddress
5643
+ });
5644
+ }
5645
+ };
5646
+ var to_oneclick_default3 = new CCTPOneClickService();
5647
+ var OneClickCCTPService = class {
5648
+ async quote(params) {
5649
+ const {
5650
+ evmWallet,
5651
+ evmAddress,
5652
+ fromToken,
5653
+ prices
5654
+ } = params;
5655
+ const execTime = new ExecTime({ type: "OneClickCCTP", logStyle: "lime-500", isDebug: OpenAPI.DEBUG });
5656
+ if (!evmWallet) {
5657
+ throw new Error("evmWallet is required");
5658
+ }
5659
+ if (!evmAddress) {
5660
+ throw new Error("evmAddress is required");
5661
+ }
5662
+ let secondStepAmountWei = Big(params.amountWei || 0).div(10 ** fromToken.decimals).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0);
5663
+ if (!isStableToken(fromToken)) {
5664
+ const inputPrice = getPrice(prices, fromToken.symbol);
5665
+ const inputValue = Big(params.amountWei || 0).div(10 ** fromToken.decimals).times(inputPrice);
5666
+ secondStepAmountWei = Big(inputValue).times(10 ** MIDDLE_TOKEN_CHAIN2.decimals).toFixed(0);
5667
+ }
5668
+ const cctpParams = {
5669
+ ...params,
5670
+ amountWei: secondStepAmountWei,
5671
+ fromToken: MIDDLE_TOKEN_CHAIN2,
5672
+ originChain: MIDDLE_TOKEN_CHAIN2.chainName,
5673
+ refundTo: MIDDLE_CHAIN_REFOUND_ADDRESS2,
5674
+ wallet: evmWallet
5675
+ };
5676
+ execTime.breakpoint();
5677
+ const cctpResult = await cctp_default.quote(cctpParams);
5678
+ execTime.log("cctpService.quote");
5679
+ const cctpFeeBuffer = 1.2;
5680
+ const cctpMintFeeUsd = numberRemoveEndZero(Big(cctpResult.fees?.estimateMintGasUsd || 0).times(1 + cctpFeeBuffer).toFixed(20));
5681
+ const cctpBridgeFeeUsd = numberRemoveEndZero(Big(cctpResult.fees?.bridgeFeeUsd || 0).times(1 + cctpFeeBuffer).toFixed(20));
5682
+ const cctpTotalFeeUsd = Big(cctpMintFeeUsd || 0).plus(cctpBridgeFeeUsd || 0).toFixed(20);
5683
+ if (cctpResult.errMsg) {
5684
+ return cctpResult;
5685
+ }
5686
+ const cctpFeeAmountInFromToken = Big(cctpTotalFeeUsd || 0).div(getPrice(prices, fromToken.symbol) || 1).toFixed(fromToken.decimals);
5687
+ const fromTokenAmount = Big(params.amountWei).div(10 ** fromToken.decimals).toFixed(fromToken.decimals);
5688
+ const oneClickFeeRatio = Big(cctpFeeAmountInFromToken || 0).div(Big(cctpFeeAmountInFromToken || 0).plus(fromTokenAmount)).times(1e4).toFixed(0, Big.roundUp);
5689
+ if (Big(oneClickFeeRatio).gt(1e4)) {
5690
+ return { errMsg: `Amount is too low, at least ${cctpFeeAmountInFromToken}` };
5691
+ }
5692
+ execTime.breakpoint();
5693
+ const oneClickResult = await oneclick_default.quote({
5694
+ ...params,
5695
+ amountWei: secondStepAmountWei,
5696
+ toToken: MIDDLE_TOKEN_CHAIN2,
5697
+ destinationAsset: MIDDLE_TOKEN_CHAIN2.assetId,
5698
+ swapType: OneClickSwapType.Output,
5699
+ isProxy: true,
5700
+ recipient: evmAddress,
5701
+ appFees: [
5702
+ ...params.appFees || [],
5703
+ {
5704
+ recipient: "reffer.near",
5705
+ fee: +oneClickFeeRatio
5706
+ }
5707
+ ]
5708
+ });
5709
+ execTime.log("oneClickService.quote");
5710
+ let totalFeesUsd = Big(0);
5711
+ let _destinationGasFeeUsd = Big(oneClickResult.fees?.destinationGasFeeUsd || 0).minus(cctpTotalFeeUsd);
5712
+ if (Big(_destinationGasFeeUsd).lt(0)) {
5713
+ _destinationGasFeeUsd = Big(0);
5714
+ }
5715
+ const fees = {
5716
+ ...oneClickResult.fees,
5717
+ destinationGasFeeUsd: numberRemoveEndZero(Big(_destinationGasFeeUsd).toFixed(20)),
5718
+ estimateMintGasUsd: cctpMintFeeUsd,
5719
+ bridgeFeeUsd: cctpBridgeFeeUsd
5720
+ };
5721
+ for (const feeKey in cctpResult.fees) {
5722
+ if (["estimateGasUsd"].includes(feeKey)) {
5723
+ continue;
5724
+ }
5725
+ if (!fees[feeKey]) {
5726
+ fees[feeKey] = cctpResult.fees[feeKey];
5727
+ }
5728
+ }
5729
+ for (const feeKey in fees) {
5730
+ if (excludeFees.includes(feeKey)) {
5731
+ continue;
5732
+ }
5733
+ totalFeesUsd = Big(totalFeesUsd || 0).plus(fees[feeKey] || 0);
5734
+ }
5735
+ const cctpSendParam = cctpResult.sendParam?.param;
5736
+ execTime.log("OneClickCCTPService.quote");
5737
+ return {
5738
+ ...oneClickResult,
5739
+ needPermit: true,
5740
+ permitSpender: CCTP_PROXY_RELAY_CONTRACT,
5741
+ permitToken: MIDDLE_TOKEN_CHAIN2,
5742
+ permitAmountWei: oneClickResult?.quote?.amountOut,
5743
+ permitAdditionalData: {
5744
+ amount_wei: cctpSendParam?.[0]?.toString(),
5745
+ charged_amount: cctpSendParam?.[1]?.toString(),
5746
+ destination_domain: cctpSendParam?.[2]?.toString(),
5747
+ mint_recipient: cctpParams.recipient,
5748
+ burn_token: cctpSendParam?.[4]?.toString(),
5749
+ destination_caller: cctpSendParam?.[5]?.toString(),
5750
+ max_fee: cctpSendParam?.[6]?.toString(),
5751
+ finality_threshold: cctpSendParam?.[7]?.toString(),
5752
+ receipt_address: params.recipient,
5753
+ source_domain: cctpResult.quoteParam?.sourceDomain,
5754
+ destination_domain_id: cctpResult.quoteParam?.destinationDomain
5755
+ },
5756
+ fees,
5757
+ totalFeesUsd: numberRemoveEndZero(Big(totalFeesUsd).toFixed(20)),
5758
+ estimateTime: cctpResult.estimateTime + oneClickResult.estimateTime,
5759
+ outputAmount: cctpResult.outputAmount,
5760
+ needCreateTokenAccount: cctpResult.needCreateTokenAccount,
5761
+ quoteParam: {
5762
+ ...oneClickResult.quoteParam,
5763
+ toToken: params.toToken,
5764
+ middleToken: MIDDLE_TOKEN_CHAIN2,
5765
+ recipient: params.recipient
5766
+ },
5767
+ cctpSendParam,
5768
+ sourceQuoteParams: params
5769
+ };
5770
+ }
5771
+ async estimateTransaction(params, quoteData) {
5772
+ return oneclick_default.estimateTransaction(params, quoteData);
5773
+ }
5774
+ async send(params) {
5775
+ return oneclick_default.send(params);
5776
+ }
5777
+ getStatus(params) {
5778
+ return getRequest("/v0/trade", {
5779
+ deposit_address: params.depositAddress
5780
+ });
5781
+ }
5782
+ };
5783
+ var from_oneclick_default3 = new OneClickCCTPService();
5500
5784
 
5501
5785
  // src/native/contract.ts
5502
5786
  var NativeChains = {
@@ -5663,6 +5947,8 @@ var ServiceMap = {
5663
5947
  [Service.OneClickFraxZero]: from_oneclick_default,
5664
5948
  [Service.Usdt0OneClick]: to_oneclick_default2,
5665
5949
  [Service.OneClickUsdt0]: from_oneclick_default2,
5950
+ [Service.CCTPOneClick]: to_oneclick_default3,
5951
+ [Service.OneClickCCTP]: from_oneclick_default3,
5666
5952
  [Service.Native]: native_default
5667
5953
  };
5668
5954
  var OVERRIDE_KEYS = /* @__PURE__ */ new Set([
@@ -5702,7 +5988,7 @@ var getSendAmountWei = (serviceType, quote) => {
5702
5988
  bridgeStore: { quoteDataService: serviceType }
5703
5989
  });
5704
5990
  if (isExactOutput) {
5705
- return quote?.quote?.minAmountIn;
5991
+ return quote?.quote?.amountIn;
5706
5992
  }
5707
5993
  return quote?.quoteParam?.amountWei;
5708
5994
  };
@@ -5913,6 +6199,8 @@ var BridgeSFA = class _BridgeSFA {
5913
6199
  Service.OneClick,
5914
6200
  Service.Usdt0OneClick,
5915
6201
  Service.OneClickUsdt0,
6202
+ Service.CCTPOneClick,
6203
+ Service.OneClickCCTP,
5916
6204
  Service.FraxZeroOneClick,
5917
6205
  Service.OneClickFraxZero
5918
6206
  ].includes(service)) {
@@ -5927,7 +6215,9 @@ var BridgeSFA = class _BridgeSFA {
5927
6215
  Service.Usdt0,
5928
6216
  Service.CCTP,
5929
6217
  Service.Usdt0OneClick,
5930
- Service.OneClickUsdt0
6218
+ Service.OneClickUsdt0,
6219
+ Service.CCTPOneClick,
6220
+ Service.OneClickCCTP
5931
6221
  ].includes(service)) {
5932
6222
  _params.originChain = params.fromToken.chainName;
5933
6223
  _params.destinationChain = params.toToken.chainName;
@@ -5941,6 +6231,8 @@ var BridgeSFA = class _BridgeSFA {
5941
6231
  }
5942
6232
  const isFromUsdt = ["USDT", "USD\u20AE0"].includes(fromToken.symbol);
5943
6233
  const isToUsdt = ["USDT", "USD\u20AE0"].includes(toToken.symbol);
6234
+ const isFromUsdc = ["USDC"].includes(fromToken.symbol);
6235
+ const isToUsdc = ["USDC"].includes(toToken.symbol);
5944
6236
  const quoteServices = [];
5945
6237
  const pushQuoteService = (_service) => {
5946
6238
  const serviceStatus = getRouteStatus(_service, disabledServices);
@@ -5985,6 +6277,24 @@ var BridgeSFA = class _BridgeSFA {
5985
6277
  if (fromToken.services.includes(Service.OneClick) && toToken.services.includes(Service.FraxZero)) {
5986
6278
  pushQuoteService(Service.OneClickFraxZero);
5987
6279
  }
6280
+ if (fromToken.services.includes(Service.CCTP) && toToken.services.includes(Service.OneClick) && fromToken.chainName !== "Arbitrum") {
6281
+ if (isFromUsdc && isToUsdc) {
6282
+ if (toToken.chainName !== "Arbitrum") {
6283
+ pushQuoteService(Service.CCTPOneClick);
6284
+ }
6285
+ } else {
6286
+ pushQuoteService(Service.CCTPOneClick);
6287
+ }
6288
+ }
6289
+ if (fromToken.services.includes(Service.OneClick) && toToken.services.includes(Service.CCTP) && toToken.chainName !== "Arbitrum") {
6290
+ if (isFromUsdc && isToUsdc) {
6291
+ if (fromToken.chainName !== "Arbitrum") {
6292
+ pushQuoteService(Service.OneClickCCTP);
6293
+ }
6294
+ } else {
6295
+ pushQuoteService(Service.OneClickCCTP);
6296
+ }
6297
+ }
5988
6298
  if (params.singleService) {
5989
6299
  const quoteService = quoteServices.find((service) => service.service === params.singleService);
5990
6300
  if (quoteService) {
@@ -6052,7 +6362,7 @@ var BridgeSFA = class _BridgeSFA {
6052
6362
  const sendParam = quote.sendParam;
6053
6363
  let _amountWei = quote.quoteParam?.amountWei;
6054
6364
  if (isExactOutput) {
6055
- _amountWei = quote.quote?.minAmountIn;
6365
+ _amountWei = quote.quote?.amountIn;
6056
6366
  }
6057
6367
  if (isOneClickService) {
6058
6368
  sendParams.sendParam = sendParam;
@@ -6093,7 +6403,7 @@ var BridgeSFA = class _BridgeSFA {
6093
6403
  const toToken = quote.quoteParam.toToken;
6094
6404
  let _amountWei = quote.quoteParam?.amountWei;
6095
6405
  if (isExactOutput) {
6096
- _amountWei = quote.quote?.minAmountIn;
6406
+ _amountWei = quote.quote?.amountIn;
6097
6407
  }
6098
6408
  const reportData = {
6099
6409
  project: ServiceBackend[serviceType],
@@ -6115,6 +6425,12 @@ var BridgeSFA = class _BridgeSFA {
6115
6425
  ...quote.permitAdditionalData
6116
6426
  };
6117
6427
  }
6428
+ if ([Service.OneClickCCTP].includes(serviceType)) {
6429
+ reportData.cctp_permit = {
6430
+ ...permitSignature,
6431
+ ...quote.permitAdditionalData
6432
+ };
6433
+ }
6118
6434
  if ([Service.OneClickFraxZero, Service.FraxZeroOneClick].includes(serviceType)) {
6119
6435
  reportData.frax_zero_permit = {
6120
6436
  ...permitSignature,
@@ -6270,7 +6586,7 @@ var BridgeSFA = class _BridgeSFA {
6270
6586
  result.status = TransactionStatus.Failed;
6271
6587
  }
6272
6588
  }
6273
- if ([Service.OneClickUsdt0, Service.Usdt0OneClick, Service.FraxZero, Service.OneClickFraxZero, Service.FraxZeroOneClick].includes(serviceType)) {
6589
+ if ([Service.OneClickUsdt0, Service.Usdt0OneClick, Service.CCTPOneClick, Service.OneClickCCTP, Service.FraxZero, Service.OneClickFraxZero, Service.FraxZeroOneClick].includes(serviceType)) {
6274
6590
  const _result = response?.data;
6275
6591
  const status = _result?.status;
6276
6592
  if (status === StableflowStatus.SUCCESS) {
@@ -6317,6 +6633,6 @@ var getHopMsgFee = async (params) => {
6317
6633
  }
6318
6634
  };
6319
6635
 
6320
- export { BridgeSFA, DATA_HEX_PROTOBUF_EXTRA, FRAXZERO_MIDDLE_TOKEN_FRXUSD, FRAXZERO_MIDDLE_TOKEN_USDC, LZ_RECEIVE_VALUE, OFT_ABI, SIGNATURE_SIZE, ServiceMap, USDT0_CONFIG, USDT0_LEGACY_MESH_TRANSFTER_FEE, addressToBytes32, buildApproveTx, buildPermitTypedData, buildSendTx, formatNumber, formatQuoteError, getHopMsgFee, getQuoteModes, quoteSignature };
6636
+ export { BridgeSFA, MIDDLE_CHAIN_REFOUND_ADDRESS2 as CCTP_MIDDLE_CHAIN_REFOUND_ADDRESS, MIDDLE_TOKEN_CHAIN2 as CCTP_MIDDLE_TOKEN_CHAIN, CCTP_PROXY_RELAY_CONTRACT, DATA_HEX_PROTOBUF_EXTRA, FRAXZERO_MIDDLE_TOKEN_FRXUSD, FRAXZERO_MIDDLE_TOKEN_USDC, LZ_RECEIVE_VALUE, OFT_ABI, SIGNATURE_SIZE, ServiceMap, USDT0_CONFIG, USDT0_LEGACY_MESH_TRANSFTER_FEE, addressToBytes32, buildApproveTx, buildPermitTypedData, buildSendTx, formatNumber, formatQuoteError, getHopMsgFee, getQuoteModes, quoteSignature };
6321
6637
  //# sourceMappingURL=index.mjs.map
6322
6638
  //# sourceMappingURL=index.mjs.map