@rhea-finance/cross-chain-aggregation-dex 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -90,6 +90,8 @@ interface BaseExecuteParams {
90
90
  recipient: string;
91
91
  depositAddress?: string;
92
92
  deadline?: number;
93
+ /** Optional sender address (for native NEAR wrap operations) */
94
+ sender?: string;
93
95
  }
94
96
  /**
95
97
  * Recipient execute parameters (V2 NEAR, EVM, etc.)
@@ -298,7 +300,7 @@ declare const logger: {
298
300
 
299
301
  /** Set the SDK-wide bluechip token config used for NearIntents compatibility and intermediate routing. */
300
302
  declare function setBluechipTokensConfig(config: BluechipTokensConfig): void;
301
- /** Get the bluechip token config; returns an empty object (and warns) if unset. */
303
+ /** Get the bluechip token config; returns an empty object if unset. */
302
304
  declare function getBluechipTokensConfig(): BluechipTokensConfig;
303
305
  /**
304
306
  * Normalize a NEAR asset id:
@@ -428,6 +430,11 @@ interface CompleteQuoteParams {
428
430
  slippage: number;
429
431
  recipient: string;
430
432
  refundTo?: string;
433
+ customRecipientMsg?: string;
434
+ appFees?: Array<{
435
+ recipient: string;
436
+ fee: number;
437
+ }>;
431
438
  }
432
439
  interface CompleteQuoteResult {
433
440
  intents: {
package/dist/index.d.ts CHANGED
@@ -90,6 +90,8 @@ interface BaseExecuteParams {
90
90
  recipient: string;
91
91
  depositAddress?: string;
92
92
  deadline?: number;
93
+ /** Optional sender address (for native NEAR wrap operations) */
94
+ sender?: string;
93
95
  }
94
96
  /**
95
97
  * Recipient execute parameters (V2 NEAR, EVM, etc.)
@@ -298,7 +300,7 @@ declare const logger: {
298
300
 
299
301
  /** Set the SDK-wide bluechip token config used for NearIntents compatibility and intermediate routing. */
300
302
  declare function setBluechipTokensConfig(config: BluechipTokensConfig): void;
301
- /** Get the bluechip token config; returns an empty object (and warns) if unset. */
303
+ /** Get the bluechip token config; returns an empty object if unset. */
302
304
  declare function getBluechipTokensConfig(): BluechipTokensConfig;
303
305
  /**
304
306
  * Normalize a NEAR asset id:
@@ -428,6 +430,11 @@ interface CompleteQuoteParams {
428
430
  slippage: number;
429
431
  recipient: string;
430
432
  refundTo?: string;
433
+ customRecipientMsg?: string;
434
+ appFees?: Array<{
435
+ recipient: string;
436
+ fee: number;
437
+ }>;
431
438
  }
432
439
  interface CompleteQuoteResult {
433
440
  intents: {
package/dist/index.js CHANGED
@@ -58,34 +58,26 @@ var logger = {
58
58
  }
59
59
  }
60
60
  };
61
+
62
+ // src/utils/index.ts
61
63
  var bluechipTokensConfig = null;
62
64
  function setBluechipTokensConfig(config) {
63
65
  bluechipTokensConfig = config;
64
66
  }
65
67
  function getBluechipTokensConfig() {
66
68
  if (!bluechipTokensConfig) {
67
- logger.warn(
68
- "getBluechipTokensConfig - Bluechip tokens config not set, returning empty config"
69
- );
70
69
  return {};
71
70
  }
72
71
  return bluechipTokensConfig;
73
72
  }
74
73
  function normalizeTokenId(tokenId, wrapNearContractId = "wrap.near") {
75
74
  if (!tokenId) {
76
- logger.error("normalizeTokenId - Empty tokenId:", tokenId);
77
75
  return "";
78
76
  }
79
77
  let normalized = tokenId.replace(/^nep141:/, "");
80
78
  if (normalized === "near") {
81
79
  normalized = wrapNearContractId;
82
80
  }
83
- if (!normalized) {
84
- logger.error("normalizeTokenId - Result is empty:", {
85
- tokenId,
86
- normalized
87
- });
88
- }
89
81
  return normalized;
90
82
  }
91
83
  function isNearIntentsSupportedToken(token, bluechipTokens) {
@@ -132,9 +124,6 @@ function findBestBluechipToken(bluechipTokens, wrapNearContractId = "wrap.near")
132
124
  });
133
125
  }
134
126
  if (preferredTokens.length === 0) {
135
- logger.warn(
136
- "findBestBluechipToken - No preferred tokens found, using wrap.near"
137
- );
138
127
  return {
139
128
  address: wrapNearContractId,
140
129
  symbol: "wNEAR",
@@ -142,7 +131,6 @@ function findBestBluechipToken(bluechipTokens, wrapNearContractId = "wrap.near")
142
131
  chain: "near"
143
132
  };
144
133
  }
145
- logger.debug("findBestBluechipToken - Selected token:", preferredTokens[0]);
146
134
  return preferredTokens[0];
147
135
  }
148
136
  function convertSlippageToBasisPoints(slippage) {
@@ -159,6 +147,13 @@ function convertSlippageToBasisPoints(slippage) {
159
147
  }
160
148
  function normalizeDestinationAsset(assetId, wrapNearContractId = "wrap.near") {
161
149
  if (!assetId) return assetId;
150
+ if (assetId.startsWith("1cs_v1:")) {
151
+ const parts = assetId.split(":");
152
+ const nep141Index = parts.findIndex((p) => p === "nep141");
153
+ if (nep141Index >= 0 && nep141Index < parts.length - 1) {
154
+ return `nep141:${parts.slice(nep141Index + 1).join(":")}`;
155
+ }
156
+ }
162
157
  if (assetId.startsWith("nep141:") || assetId.startsWith("nep245:")) {
163
158
  return assetId;
164
159
  }
@@ -196,10 +191,6 @@ function formatGasToTgas(gasInYoctoNEAR) {
196
191
  const tgasBigInt = gasBigInt / BigInt("1000000000000");
197
192
  return tgasBigInt.toString();
198
193
  } catch (error) {
199
- logger.error("formatGasToTgas - Error formatting gas:", {
200
- gasInYoctoNEAR,
201
- error
202
- });
203
194
  return "0";
204
195
  }
205
196
  }
@@ -295,16 +286,6 @@ var NearSmartRouter = class {
295
286
  this.wrapNearContractId
296
287
  );
297
288
  if (!normalizedTokenIn || !normalizedTokenOut) {
298
- logger.error("SmartRouter quote - Invalid token addresses:", {
299
- tokenIn: {
300
- original: tokenIn.address,
301
- normalized: normalizedTokenIn
302
- },
303
- tokenOut: {
304
- original: tokenOut.address,
305
- normalized: normalizedTokenOut
306
- }
307
- });
308
289
  return {
309
290
  success: false,
310
291
  tokenIn: params.tokenIn,
@@ -313,18 +294,11 @@ var NearSmartRouter = class {
313
294
  amountOut: "0",
314
295
  minAmountOut: "0",
315
296
  routes: [],
316
- error: `Invalid token address: tokenIn=${normalizedTokenIn || "empty"}, tokenOut=${normalizedTokenOut || "empty"}`
297
+ error: "Invalid token address"
317
298
  };
318
299
  }
319
300
  const slippageBps = convertSlippageToBasisPoints(slippage);
320
301
  const slippageDecimalForApi = slippageBps / 1e4;
321
- logger.debug("SmartRouter quote - Calling findPath:", {
322
- tokenIn: normalizedTokenIn,
323
- tokenOut: normalizedTokenOut,
324
- amountIn,
325
- slippage: slippageDecimalForApi,
326
- slippageBps
327
- });
328
302
  const response = await this.findPathAdapter.findPath({
329
303
  tokenIn: normalizedTokenIn,
330
304
  tokenOut: normalizedTokenOut,
@@ -332,11 +306,6 @@ var NearSmartRouter = class {
332
306
  slippage: slippageDecimalForApi,
333
307
  supportLedger: false
334
308
  });
335
- logger.debug("SmartRouter quote - findPath response:", {
336
- result_code: response?.result_code,
337
- result_msg: response?.result_msg || response?.result_message,
338
- hasRoutes: !!response?.result_data?.routes?.length
339
- });
340
309
  if (response?.result_code !== 0 || !response?.result_data?.routes?.length) {
341
310
  return {
342
311
  success: false,
@@ -421,7 +390,43 @@ var NearSmartRouter = class {
421
390
  };
422
391
  }
423
392
  const finalRecipient = depositAddress || recipient;
393
+ const sender = params.sender || finalRecipient;
424
394
  const transactions = [];
395
+ const isNativeNear = quote.tokenIn.address === "near" || quote.tokenIn.address === this.wrapNearContractId && quote.tokenIn.symbol === "NEAR" || !quote.tokenIn.address && quote.tokenIn.symbol === "NEAR";
396
+ if (isNativeNear) {
397
+ let wrapNearStorageBalance = null;
398
+ try {
399
+ wrapNearStorageBalance = await this.nearChainAdapter.view({
400
+ contractId: this.wrapNearContractId,
401
+ methodName: "storage_balance_of",
402
+ args: {
403
+ account_id: sender
404
+ }
405
+ });
406
+ } catch (err) {
407
+ wrapNearStorageBalance = null;
408
+ }
409
+ if (!wrapNearStorageBalance) {
410
+ transactions.push({
411
+ contractId: this.wrapNearContractId,
412
+ methodName: "storage_deposit",
413
+ args: {
414
+ account_id: sender,
415
+ registration_only: true
416
+ },
417
+ gas: "50000000000000",
418
+ expandDeposit: "1250000000000000000000"
419
+ // 0.00125 NEAR
420
+ });
421
+ }
422
+ transactions.push({
423
+ contractId: this.wrapNearContractId,
424
+ methodName: "near_deposit",
425
+ args: {},
426
+ gas: "50000000000000",
427
+ expandDeposit: quote.amountIn
428
+ });
429
+ }
425
430
  if (finalRecipient && quote.tokenOut?.address) {
426
431
  let isRegistered = false;
427
432
  try {
@@ -437,10 +442,6 @@ var NearSmartRouter = class {
437
442
  isRegistered = false;
438
443
  }
439
444
  if (!isRegistered) {
440
- logger.debug("SmartRouter - Registering recipient account:", {
441
- contractId: quote.tokenOut.address,
442
- accountId: finalRecipient
443
- });
444
445
  transactions.push({
445
446
  contractId: quote.tokenOut.address,
446
447
  methodName: "storage_deposit",
@@ -461,17 +462,9 @@ var NearSmartRouter = class {
461
462
  if (finalRecipient) {
462
463
  swapMsg.swap_out_recipient = finalRecipient;
463
464
  }
464
- logger.debug("SmartRouter - Executing swap:", {
465
- contractId: quote.tokenIn.address,
466
- receiver_id: this.refExchangeId,
467
- amount: quote.amountIn,
468
- swapMsg,
469
- swapActionsCount: swapActions.length,
470
- recipient: finalRecipient,
471
- tokenOut: quote.tokenOut?.address
472
- });
465
+ const tokenInAddress = isNativeNear ? this.wrapNearContractId : quote.tokenIn.address;
473
466
  transactions.push({
474
- contractId: quote.tokenIn.address,
467
+ contractId: tokenInAddress,
475
468
  methodName: "ft_transfer_call",
476
469
  args: {
477
470
  receiver_id: this.refExchangeId,
@@ -532,11 +525,7 @@ var AggregateDexRouter = class {
532
525
  this.configAdapter = config.configAdapter;
533
526
  this.aggregateDexContractId = this.configAdapter.getAggregateDexContractId?.() || "";
534
527
  this.wrapNearContractId = this.configAdapter.getWrapNearContractId();
535
- if (!this.aggregateDexContractId) {
536
- logger.error(
537
- "AggregateDexRouter - AGGREGATE_DEX_CONTRACT_ID not configured"
538
- );
539
- }
528
+ if (!this.aggregateDexContractId) ;
540
529
  }
541
530
  /**
542
531
  * Get Router capabilities
@@ -566,15 +555,11 @@ var AggregateDexRouter = class {
566
555
  amountOut: "0",
567
556
  minAmountOut: "0",
568
557
  routes: [],
569
- error: "V2 Router requires sender and recipient parameters"
558
+ error: "Missing sender or recipient"
570
559
  };
571
560
  }
572
561
  const { tokenIn, tokenOut, amountIn, slippage, sender, recipient } = params;
573
562
  if (!sender || !recipient) {
574
- logger.error("AggregateDexRouter quote - Missing sender or recipient:", {
575
- sender,
576
- recipient
577
- });
578
563
  return {
579
564
  success: false,
580
565
  tokenIn: params.tokenIn,
@@ -583,7 +568,7 @@ var AggregateDexRouter = class {
583
568
  amountOut: "0",
584
569
  minAmountOut: "0",
585
570
  routes: [],
586
- error: `V2 Router requires non-empty sender and recipient. Got sender="${sender}", recipient="${recipient}"`
571
+ error: "Missing sender or recipient"
587
572
  };
588
573
  }
589
574
  if (!tokenIn?.address || !tokenOut?.address) {
@@ -607,16 +592,6 @@ var AggregateDexRouter = class {
607
592
  this.wrapNearContractId
608
593
  );
609
594
  if (!normalizedTokenIn || !normalizedTokenOut) {
610
- logger.error("AggregateDexRouter quote - Invalid token addresses:", {
611
- tokenIn: {
612
- original: tokenIn.address,
613
- normalized: normalizedTokenIn
614
- },
615
- tokenOut: {
616
- original: tokenOut.address,
617
- normalized: normalizedTokenOut
618
- }
619
- });
620
595
  return {
621
596
  success: false,
622
597
  tokenIn: params.tokenIn,
@@ -625,7 +600,7 @@ var AggregateDexRouter = class {
625
600
  amountOut: "0",
626
601
  minAmountOut: "0",
627
602
  routes: [],
628
- error: `Invalid token address: tokenIn=${normalizedTokenIn || "empty"}, tokenOut=${normalizedTokenOut || "empty"}`
603
+ error: "Invalid token address"
629
604
  };
630
605
  }
631
606
  const slippageBps = convertSlippageToBasisPoints(slippage);
@@ -648,7 +623,7 @@ var AggregateDexRouter = class {
648
623
  amountOut: "0",
649
624
  minAmountOut: "0",
650
625
  routes: [],
651
- error: response.result_message || "V2 Router API call failed"
626
+ error: "Failed to get quote"
652
627
  };
653
628
  }
654
629
  const {
@@ -676,7 +651,6 @@ var AggregateDexRouter = class {
676
651
  slippage
677
652
  };
678
653
  } catch (error) {
679
- logger.error("AggregateDexRouter quote - Error:", error);
680
654
  return {
681
655
  success: false,
682
656
  tokenIn: params.tokenIn,
@@ -685,7 +659,7 @@ var AggregateDexRouter = class {
685
659
  amountOut: "0",
686
660
  minAmountOut: "0",
687
661
  routes: [],
688
- error: error?.message || "Quote failed"
662
+ error: "Failed to get quote"
689
663
  };
690
664
  }
691
665
  }
@@ -701,21 +675,17 @@ var AggregateDexRouter = class {
701
675
  recipient: depositAddress
702
676
  });
703
677
  }
704
- async reFetchQuoteWithBalance(quoteParams, actualBalance, context) {
678
+ async reFetchQuoteWithBalance(quoteParams, actualBalance, _context) {
705
679
  const balanceBig = new Big3__default.default(actualBalance);
706
680
  const adjustedParams = {
707
681
  ...quoteParams,
708
682
  amountIn: balanceBig.toFixed(0)
709
683
  };
710
- logger.warn(`AggregateDexRouter - ${context}: re-fetching quote with actual balance:`, {
711
- requestedAmount: quoteParams.amountIn,
712
- actualBalance
713
- });
714
684
  const adjustedQuote = await this.quote(adjustedParams);
715
685
  if (adjustedQuote.success && adjustedQuote.routerMsg && adjustedQuote.signature) {
716
686
  return adjustedQuote;
717
687
  } else {
718
- throw new Error(`Failed to re-fetch quote with actual balance: ${adjustedQuote.error || "Unknown error"}`);
688
+ throw new Error("Failed to get quote");
719
689
  }
720
690
  }
721
691
  async ensureQuoteAmountWithinBalance(quoteParams, actualBalance, context) {
@@ -735,31 +705,31 @@ var AggregateDexRouter = class {
735
705
  }
736
706
  }
737
707
  if (requestedAmountBig.gt(effectiveBalanceBig) && balanceBig.gt(0)) {
738
- return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, `${context} (requested amount exceeds available balance${isNativeNear ? " minus gas reserve" : ""})`);
708
+ return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, context);
739
709
  }
740
710
  if (balanceBig.gt(0) && requestedAmountBig.lt(balanceBig)) {
741
711
  const diff = balanceBig.minus(requestedAmountBig);
742
712
  const diffPercent = diff.div(balanceBig).times(100);
743
713
  const isMaxSwap = diffPercent.lt(0.1) || diff.lt(1e3);
744
714
  if (isMaxSwap) {
745
- return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, `${context} (MAX swap detected, using ${isNativeNear ? "balance minus gas reserve" : "actual balance"})`);
715
+ return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, context);
746
716
  }
747
717
  }
748
718
  const quote = await this.quote(quoteParams);
749
719
  if (!quote.success) {
750
- throw new Error(`Failed to fetch quote: ${quote.error || "Unknown error"}`);
720
+ throw new Error("Failed to get quote");
751
721
  }
752
722
  if (quote.amountIn !== quoteParams.amountIn) {
753
723
  const apiAmountBig = new Big3__default.default(quote.amountIn);
754
724
  if (apiAmountBig.gt(effectiveBalanceBig) && balanceBig.gt(0)) {
755
- return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, `${context} (API returned amount_in exceeds available balance)`);
725
+ return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, context);
756
726
  }
757
727
  if (apiAmountBig.lt(balanceBig) && balanceBig.gt(0)) {
758
728
  const diff = balanceBig.minus(apiAmountBig);
759
729
  const diffPercent = diff.div(balanceBig).times(100);
760
730
  const isMaxSwap = diffPercent.lt(0.1) || diff.lt(1e3);
761
731
  if (isMaxSwap) {
762
- return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, `${context} (API returned amount_in close to balance, MAX swap detected)`);
732
+ return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, context);
763
733
  }
764
734
  }
765
735
  }
@@ -770,7 +740,7 @@ var AggregateDexRouter = class {
770
740
  if (!requiresRecipientInExecute(params)) {
771
741
  return {
772
742
  success: false,
773
- error: "V2 Router requires sender and receiveUser parameters"
743
+ error: "Missing sender or receiveUser"
774
744
  };
775
745
  }
776
746
  const { quote, sender, receiveUser } = params;
@@ -783,13 +753,13 @@ var AggregateDexRouter = class {
783
753
  if (!receiveUser || receiveUser.trim() === "") {
784
754
  return {
785
755
  success: false,
786
- error: "receiveUser (depositAddress) is required"
756
+ error: "Missing receiveUser"
787
757
  };
788
758
  }
789
759
  if (receiveUser.startsWith("0x") && receiveUser.length === 42) {
790
760
  return {
791
761
  success: false,
792
- error: `receiveUser appears to be an EVM address (${receiveUser}). For NEAR chain swaps, depositAddress must be a NEAR account (64 hex chars or .near format)`
762
+ error: "Invalid receiveUser address"
793
763
  };
794
764
  }
795
765
  const slippage = quote.slippage || 5e-3;
@@ -819,10 +789,9 @@ var AggregateDexRouter = class {
819
789
  "Re-fetching quote with receiveUser"
820
790
  );
821
791
  } catch (error) {
822
- logger.error("AggregateDexRouter - Failed to fetch quote with receiveUser:", error);
823
792
  return {
824
793
  success: false,
825
- error: `Failed to fetch quote with receiveUser="${receiveUser}": ${error?.message || "Unknown error"}`
794
+ error: "Failed to get quote"
826
795
  };
827
796
  }
828
797
  const routerMsg = finalQuote.routerMsg;
@@ -830,7 +799,7 @@ var AggregateDexRouter = class {
830
799
  if (!routerMsg || !signature) {
831
800
  return {
832
801
  success: false,
833
- error: `Quote fetched with receiveUser="${receiveUser}" is missing routerMsg or signature.`
802
+ error: "Failed to get quote"
834
803
  };
835
804
  }
836
805
  const tokens = finalQuote.tokens || [];
@@ -897,14 +866,7 @@ var AggregateDexRouter = class {
897
866
  const receiveUserStorageBalance = await getStorageBalance(
898
867
  finalQuote.tokenOut.address,
899
868
  receiveUser
900
- ).catch((error) => {
901
- logger.warn("AggregateDexRouter - Failed to check receiveUser storage balance:", {
902
- receiveUser,
903
- tokenOut: finalQuote.tokenOut.address,
904
- error: error?.message
905
- });
906
- return null;
907
- });
869
+ ).catch(() => null);
908
870
  if (!receiveUserStorageBalance) {
909
871
  transactions.push({
910
872
  contractId: finalQuote.tokenOut.address,
@@ -989,10 +951,9 @@ var AggregateDexRouter = class {
989
951
  "Final balance check before execution"
990
952
  );
991
953
  } catch (error) {
992
- logger.error("AggregateDexRouter - Failed final balance check:", error);
993
954
  return {
994
955
  success: false,
995
- error: `Failed final balance check: ${error?.message || "Unknown error"}`
956
+ error: "Failed to get quote"
996
957
  };
997
958
  }
998
959
  const finalAmountToTransfer = finalQuoteForExecution.amountIn;
@@ -1023,14 +984,13 @@ var AggregateDexRouter = class {
1023
984
  } else {
1024
985
  return {
1025
986
  success: false,
1026
- error: result.message || "Execute swap failed"
987
+ error: "Execute swap failed"
1027
988
  };
1028
989
  }
1029
990
  } catch (error) {
1030
- logger.error("AggregateDexRouter executeSwap - Error:", error);
1031
991
  return {
1032
992
  success: false,
1033
- error: error?.message || "Execute swap failed"
993
+ error: "Execute swap failed"
1034
994
  };
1035
995
  }
1036
996
  }
@@ -1048,10 +1008,6 @@ var AggregateDexRouter = class {
1048
1008
  }
1049
1009
  });
1050
1010
  } catch (error) {
1051
- logger.error(
1052
- "AggregateDexRouter - Failed to query user tokens registered:",
1053
- error
1054
- );
1055
1011
  return tokens.map(() => false);
1056
1012
  }
1057
1013
  }
@@ -1067,7 +1023,9 @@ async function completeQuote(params, config) {
1067
1023
  amountIn,
1068
1024
  slippage,
1069
1025
  recipient,
1070
- refundTo
1026
+ refundTo,
1027
+ customRecipientMsg,
1028
+ appFees
1071
1029
  } = params;
1072
1030
  const {
1073
1031
  intentsQuotationAdapter,
@@ -1099,10 +1057,6 @@ async function completeQuote(params, config) {
1099
1057
  wrapNearContractId
1100
1058
  );
1101
1059
  if (!bluechipToken?.address) {
1102
- logger.error("DEX Aggregator - Failed to find bluechip token:", {
1103
- bluechipToken,
1104
- bluechipTokens
1105
- });
1106
1060
  throw new Error("Failed to find bluechip token address");
1107
1061
  }
1108
1062
  const quotePaths = [];
@@ -1130,21 +1084,21 @@ async function completeQuote(params, config) {
1130
1084
  promise: (async () => {
1131
1085
  const preSwapQuote = await router.quote(quoteParams);
1132
1086
  if (!preSwapQuote.success) {
1133
- throw new Error(
1134
- `${routeType} pre-swap failed: ${preSwapQuote.error}`
1135
- );
1087
+ throw new Error("Failed to get quote");
1136
1088
  }
1137
1089
  const bluechipKey = bluechipToken.symbol?.toUpperCase() === "WNEAR" ? "NEAR" : bluechipToken.symbol?.toUpperCase();
1138
1090
  const bluechipTokenConfig = bluechipKey && bluechipTokens[bluechipKey] || void 0;
1139
1091
  const normalizedSourceAsset = bluechipTokenConfig?.assetId ? bluechipTokenConfig.assetId : `nep141:${bluechipToken.address}`;
1140
1092
  let normalizedTargetAsset = targetToken.address;
1141
- if (normalizedTargetAsset && !normalizedTargetAsset.startsWith("nep141:") && !normalizedTargetAsset.startsWith("nep245:") && normalizedTargetAsset.includes(".")) {
1093
+ if (normalizedTargetAsset?.startsWith("1cs_v1:")) ; else if (normalizedTargetAsset && !normalizedTargetAsset.startsWith("nep141:") && !normalizedTargetAsset.startsWith("nep245:") && normalizedTargetAsset.includes(".")) {
1142
1094
  normalizedTargetAsset = `nep141:${normalizeTokenId(
1143
1095
  normalizedTargetAsset,
1144
1096
  wrapNearContractId
1145
1097
  )}`;
1146
1098
  }
1147
- normalizedTargetAsset = normalizeDestinationAsset(normalizedTargetAsset, wrapNearContractId) || normalizedTargetAsset;
1099
+ if (!normalizedTargetAsset?.startsWith("1cs_v1:")) {
1100
+ normalizedTargetAsset = normalizeDestinationAsset(normalizedTargetAsset, wrapNearContractId) || normalizedTargetAsset;
1101
+ }
1148
1102
  const slippageBps = convertSlippageToBasisPoints(slippage);
1149
1103
  const intentsQuote = await intentsQuotationAdapter.quote({
1150
1104
  originAsset: normalizedSourceAsset,
@@ -1153,12 +1107,12 @@ async function completeQuote(params, config) {
1153
1107
  refundTo: refundTo || recipient,
1154
1108
  recipient,
1155
1109
  slippageTolerance: slippageBps,
1156
- swapType: "FLEX_INPUT"
1110
+ swapType: "FLEX_INPUT",
1111
+ ...customRecipientMsg ? { customRecipientMsg } : {},
1112
+ ...appFees ? { appFees } : {}
1157
1113
  });
1158
1114
  if (intentsQuote.quoteStatus !== "success") {
1159
- throw new Error(
1160
- `${routeType} Intents quote failed: ${intentsQuote.message}`
1161
- );
1115
+ throw new Error("Failed to get quote");
1162
1116
  }
1163
1117
  return {
1164
1118
  intentsQuote,
@@ -1198,13 +1152,15 @@ async function completeQuote(params, config) {
1198
1152
  }
1199
1153
  }
1200
1154
  let normalizedTargetAsset = targetToken.address;
1201
- if (normalizedTargetAsset && !normalizedTargetAsset.startsWith("nep141:") && !normalizedTargetAsset.startsWith("nep245:") && normalizedTargetAsset.includes(".")) {
1155
+ if (normalizedTargetAsset?.startsWith("1cs_v1:")) ; else if (normalizedTargetAsset && !normalizedTargetAsset.startsWith("nep141:") && !normalizedTargetAsset.startsWith("nep245:") && normalizedTargetAsset.includes(".")) {
1202
1156
  normalizedTargetAsset = `nep141:${normalizeTokenId(
1203
1157
  normalizedTargetAsset,
1204
1158
  wrapNearContractId
1205
1159
  )}`;
1206
1160
  }
1207
- normalizedTargetAsset = normalizeDestinationAsset(normalizedTargetAsset, wrapNearContractId) || normalizedTargetAsset;
1161
+ if (!normalizedTargetAsset?.startsWith("1cs_v1:")) {
1162
+ normalizedTargetAsset = normalizeDestinationAsset(normalizedTargetAsset, wrapNearContractId) || normalizedTargetAsset;
1163
+ }
1208
1164
  const slippageBps = convertSlippageToBasisPoints(slippage);
1209
1165
  const intentsQuote = await intentsQuotationAdapter.quote({
1210
1166
  originAsset: normalizedSourceAsset,
@@ -1213,12 +1169,11 @@ async function completeQuote(params, config) {
1213
1169
  refundTo: refundTo || recipient,
1214
1170
  recipient,
1215
1171
  slippageTolerance: slippageBps,
1216
- swapType: "EXACT_INPUT"
1172
+ swapType: "EXACT_INPUT",
1173
+ ...customRecipientMsg ? { customRecipientMsg } : {}
1217
1174
  });
1218
1175
  if (intentsQuote.quoteStatus !== "success") {
1219
- throw new Error(
1220
- `Direct Intents quote failed: ${intentsQuote.message}`
1221
- );
1176
+ throw new Error("Failed to get quote");
1222
1177
  }
1223
1178
  return {
1224
1179
  intentsQuote,
@@ -1238,34 +1193,16 @@ async function completeQuote(params, config) {
1238
1193
  type: pathType,
1239
1194
  ...result.value
1240
1195
  });
1241
- } else {
1242
- logger.warn(`Path ${pathType} failed:`, result.reason);
1243
1196
  }
1244
1197
  });
1245
- logger.debug("Cross-chain Quote Comparison:", {
1246
- paths: validPaths.map((p) => ({
1247
- type: p.type.toUpperCase(),
1248
- finalAmountOut: p.finalAmountOut
1249
- }))
1250
- });
1251
1198
  if (validPaths.length === 0) {
1252
- const errors = pathResults.map((r, index) => {
1253
- const pathType = quotePaths[index].type;
1254
- if (r.status === "rejected") {
1255
- return `${pathType}: ${r.reason}`;
1256
- }
1257
- return null;
1258
- }).filter(Boolean);
1259
- throw new Error(`All quote paths failed: ${errors.join("; ")}`);
1199
+ throw new Error("Failed to get quote");
1260
1200
  }
1261
1201
  const bestPath = validPaths.reduce((best, current) => {
1262
1202
  const bestAmount = new Big3__default.default(best.finalAmountOut);
1263
1203
  const currentAmount = new Big3__default.default(current.finalAmountOut);
1264
1204
  return currentAmount.gt(bestAmount) ? current : best;
1265
1205
  });
1266
- logger.debug(
1267
- `\u2713 Selected best path: [${bestPath.type.toUpperCase()}] with finalAmountOut: ${bestPath.finalAmountOut}`
1268
- );
1269
1206
  const depositAddress = bestPath.intentsQuote.quoteSuccessResult?.quote?.depositAddress || "";
1270
1207
  if (!depositAddress) {
1271
1208
  throw new Error("Deposit address not found in intents quote");