@rhea-finance/cross-chain-aggregation-dex 0.1.3 → 0.1.4
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 +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +35 -148
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -148
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -298,7 +298,7 @@ declare const logger: {
|
|
|
298
298
|
|
|
299
299
|
/** Set the SDK-wide bluechip token config used for NearIntents compatibility and intermediate routing. */
|
|
300
300
|
declare function setBluechipTokensConfig(config: BluechipTokensConfig): void;
|
|
301
|
-
/** Get the bluechip token config; returns an empty object
|
|
301
|
+
/** Get the bluechip token config; returns an empty object if unset. */
|
|
302
302
|
declare function getBluechipTokensConfig(): BluechipTokensConfig;
|
|
303
303
|
/**
|
|
304
304
|
* Normalize a NEAR asset id:
|
|
@@ -428,6 +428,7 @@ interface CompleteQuoteParams {
|
|
|
428
428
|
slippage: number;
|
|
429
429
|
recipient: string;
|
|
430
430
|
refundTo?: string;
|
|
431
|
+
customRecipientMsg?: string;
|
|
431
432
|
}
|
|
432
433
|
interface CompleteQuoteResult {
|
|
433
434
|
intents: {
|
package/dist/index.d.ts
CHANGED
|
@@ -298,7 +298,7 @@ declare const logger: {
|
|
|
298
298
|
|
|
299
299
|
/** Set the SDK-wide bluechip token config used for NearIntents compatibility and intermediate routing. */
|
|
300
300
|
declare function setBluechipTokensConfig(config: BluechipTokensConfig): void;
|
|
301
|
-
/** Get the bluechip token config; returns an empty object
|
|
301
|
+
/** Get the bluechip token config; returns an empty object if unset. */
|
|
302
302
|
declare function getBluechipTokensConfig(): BluechipTokensConfig;
|
|
303
303
|
/**
|
|
304
304
|
* Normalize a NEAR asset id:
|
|
@@ -428,6 +428,7 @@ interface CompleteQuoteParams {
|
|
|
428
428
|
slippage: number;
|
|
429
429
|
recipient: string;
|
|
430
430
|
refundTo?: string;
|
|
431
|
+
customRecipientMsg?: string;
|
|
431
432
|
}
|
|
432
433
|
interface CompleteQuoteResult {
|
|
433
434
|
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) {
|
|
@@ -196,10 +184,6 @@ function formatGasToTgas(gasInYoctoNEAR) {
|
|
|
196
184
|
const tgasBigInt = gasBigInt / BigInt("1000000000000");
|
|
197
185
|
return tgasBigInt.toString();
|
|
198
186
|
} catch (error) {
|
|
199
|
-
logger.error("formatGasToTgas - Error formatting gas:", {
|
|
200
|
-
gasInYoctoNEAR,
|
|
201
|
-
error
|
|
202
|
-
});
|
|
203
187
|
return "0";
|
|
204
188
|
}
|
|
205
189
|
}
|
|
@@ -295,16 +279,6 @@ var NearSmartRouter = class {
|
|
|
295
279
|
this.wrapNearContractId
|
|
296
280
|
);
|
|
297
281
|
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
282
|
return {
|
|
309
283
|
success: false,
|
|
310
284
|
tokenIn: params.tokenIn,
|
|
@@ -313,18 +287,11 @@ var NearSmartRouter = class {
|
|
|
313
287
|
amountOut: "0",
|
|
314
288
|
minAmountOut: "0",
|
|
315
289
|
routes: [],
|
|
316
|
-
error:
|
|
290
|
+
error: "Invalid token address"
|
|
317
291
|
};
|
|
318
292
|
}
|
|
319
293
|
const slippageBps = convertSlippageToBasisPoints(slippage);
|
|
320
294
|
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
295
|
const response = await this.findPathAdapter.findPath({
|
|
329
296
|
tokenIn: normalizedTokenIn,
|
|
330
297
|
tokenOut: normalizedTokenOut,
|
|
@@ -332,11 +299,6 @@ var NearSmartRouter = class {
|
|
|
332
299
|
slippage: slippageDecimalForApi,
|
|
333
300
|
supportLedger: false
|
|
334
301
|
});
|
|
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
302
|
if (response?.result_code !== 0 || !response?.result_data?.routes?.length) {
|
|
341
303
|
return {
|
|
342
304
|
success: false,
|
|
@@ -437,10 +399,6 @@ var NearSmartRouter = class {
|
|
|
437
399
|
isRegistered = false;
|
|
438
400
|
}
|
|
439
401
|
if (!isRegistered) {
|
|
440
|
-
logger.debug("SmartRouter - Registering recipient account:", {
|
|
441
|
-
contractId: quote.tokenOut.address,
|
|
442
|
-
accountId: finalRecipient
|
|
443
|
-
});
|
|
444
402
|
transactions.push({
|
|
445
403
|
contractId: quote.tokenOut.address,
|
|
446
404
|
methodName: "storage_deposit",
|
|
@@ -461,15 +419,6 @@ var NearSmartRouter = class {
|
|
|
461
419
|
if (finalRecipient) {
|
|
462
420
|
swapMsg.swap_out_recipient = finalRecipient;
|
|
463
421
|
}
|
|
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
|
-
});
|
|
473
422
|
transactions.push({
|
|
474
423
|
contractId: quote.tokenIn.address,
|
|
475
424
|
methodName: "ft_transfer_call",
|
|
@@ -532,11 +481,7 @@ var AggregateDexRouter = class {
|
|
|
532
481
|
this.configAdapter = config.configAdapter;
|
|
533
482
|
this.aggregateDexContractId = this.configAdapter.getAggregateDexContractId?.() || "";
|
|
534
483
|
this.wrapNearContractId = this.configAdapter.getWrapNearContractId();
|
|
535
|
-
if (!this.aggregateDexContractId)
|
|
536
|
-
logger.error(
|
|
537
|
-
"AggregateDexRouter - AGGREGATE_DEX_CONTRACT_ID not configured"
|
|
538
|
-
);
|
|
539
|
-
}
|
|
484
|
+
if (!this.aggregateDexContractId) ;
|
|
540
485
|
}
|
|
541
486
|
/**
|
|
542
487
|
* Get Router capabilities
|
|
@@ -566,15 +511,11 @@ var AggregateDexRouter = class {
|
|
|
566
511
|
amountOut: "0",
|
|
567
512
|
minAmountOut: "0",
|
|
568
513
|
routes: [],
|
|
569
|
-
error: "
|
|
514
|
+
error: "Missing sender or recipient"
|
|
570
515
|
};
|
|
571
516
|
}
|
|
572
517
|
const { tokenIn, tokenOut, amountIn, slippage, sender, recipient } = params;
|
|
573
518
|
if (!sender || !recipient) {
|
|
574
|
-
logger.error("AggregateDexRouter quote - Missing sender or recipient:", {
|
|
575
|
-
sender,
|
|
576
|
-
recipient
|
|
577
|
-
});
|
|
578
519
|
return {
|
|
579
520
|
success: false,
|
|
580
521
|
tokenIn: params.tokenIn,
|
|
@@ -583,7 +524,7 @@ var AggregateDexRouter = class {
|
|
|
583
524
|
amountOut: "0",
|
|
584
525
|
minAmountOut: "0",
|
|
585
526
|
routes: [],
|
|
586
|
-
error:
|
|
527
|
+
error: "Missing sender or recipient"
|
|
587
528
|
};
|
|
588
529
|
}
|
|
589
530
|
if (!tokenIn?.address || !tokenOut?.address) {
|
|
@@ -607,16 +548,6 @@ var AggregateDexRouter = class {
|
|
|
607
548
|
this.wrapNearContractId
|
|
608
549
|
);
|
|
609
550
|
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
551
|
return {
|
|
621
552
|
success: false,
|
|
622
553
|
tokenIn: params.tokenIn,
|
|
@@ -625,7 +556,7 @@ var AggregateDexRouter = class {
|
|
|
625
556
|
amountOut: "0",
|
|
626
557
|
minAmountOut: "0",
|
|
627
558
|
routes: [],
|
|
628
|
-
error:
|
|
559
|
+
error: "Invalid token address"
|
|
629
560
|
};
|
|
630
561
|
}
|
|
631
562
|
const slippageBps = convertSlippageToBasisPoints(slippage);
|
|
@@ -648,7 +579,7 @@ var AggregateDexRouter = class {
|
|
|
648
579
|
amountOut: "0",
|
|
649
580
|
minAmountOut: "0",
|
|
650
581
|
routes: [],
|
|
651
|
-
error:
|
|
582
|
+
error: "Failed to get quote"
|
|
652
583
|
};
|
|
653
584
|
}
|
|
654
585
|
const {
|
|
@@ -676,7 +607,6 @@ var AggregateDexRouter = class {
|
|
|
676
607
|
slippage
|
|
677
608
|
};
|
|
678
609
|
} catch (error) {
|
|
679
|
-
logger.error("AggregateDexRouter quote - Error:", error);
|
|
680
610
|
return {
|
|
681
611
|
success: false,
|
|
682
612
|
tokenIn: params.tokenIn,
|
|
@@ -685,7 +615,7 @@ var AggregateDexRouter = class {
|
|
|
685
615
|
amountOut: "0",
|
|
686
616
|
minAmountOut: "0",
|
|
687
617
|
routes: [],
|
|
688
|
-
error:
|
|
618
|
+
error: "Failed to get quote"
|
|
689
619
|
};
|
|
690
620
|
}
|
|
691
621
|
}
|
|
@@ -701,21 +631,17 @@ var AggregateDexRouter = class {
|
|
|
701
631
|
recipient: depositAddress
|
|
702
632
|
});
|
|
703
633
|
}
|
|
704
|
-
async reFetchQuoteWithBalance(quoteParams, actualBalance,
|
|
634
|
+
async reFetchQuoteWithBalance(quoteParams, actualBalance, _context) {
|
|
705
635
|
const balanceBig = new Big3__default.default(actualBalance);
|
|
706
636
|
const adjustedParams = {
|
|
707
637
|
...quoteParams,
|
|
708
638
|
amountIn: balanceBig.toFixed(0)
|
|
709
639
|
};
|
|
710
|
-
logger.warn(`AggregateDexRouter - ${context}: re-fetching quote with actual balance:`, {
|
|
711
|
-
requestedAmount: quoteParams.amountIn,
|
|
712
|
-
actualBalance
|
|
713
|
-
});
|
|
714
640
|
const adjustedQuote = await this.quote(adjustedParams);
|
|
715
641
|
if (adjustedQuote.success && adjustedQuote.routerMsg && adjustedQuote.signature) {
|
|
716
642
|
return adjustedQuote;
|
|
717
643
|
} else {
|
|
718
|
-
throw new Error(
|
|
644
|
+
throw new Error("Failed to get quote");
|
|
719
645
|
}
|
|
720
646
|
}
|
|
721
647
|
async ensureQuoteAmountWithinBalance(quoteParams, actualBalance, context) {
|
|
@@ -735,31 +661,31 @@ var AggregateDexRouter = class {
|
|
|
735
661
|
}
|
|
736
662
|
}
|
|
737
663
|
if (requestedAmountBig.gt(effectiveBalanceBig) && balanceBig.gt(0)) {
|
|
738
|
-
return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr,
|
|
664
|
+
return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, context);
|
|
739
665
|
}
|
|
740
666
|
if (balanceBig.gt(0) && requestedAmountBig.lt(balanceBig)) {
|
|
741
667
|
const diff = balanceBig.minus(requestedAmountBig);
|
|
742
668
|
const diffPercent = diff.div(balanceBig).times(100);
|
|
743
669
|
const isMaxSwap = diffPercent.lt(0.1) || diff.lt(1e3);
|
|
744
670
|
if (isMaxSwap) {
|
|
745
|
-
return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr,
|
|
671
|
+
return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, context);
|
|
746
672
|
}
|
|
747
673
|
}
|
|
748
674
|
const quote = await this.quote(quoteParams);
|
|
749
675
|
if (!quote.success) {
|
|
750
|
-
throw new Error(
|
|
676
|
+
throw new Error("Failed to get quote");
|
|
751
677
|
}
|
|
752
678
|
if (quote.amountIn !== quoteParams.amountIn) {
|
|
753
679
|
const apiAmountBig = new Big3__default.default(quote.amountIn);
|
|
754
680
|
if (apiAmountBig.gt(effectiveBalanceBig) && balanceBig.gt(0)) {
|
|
755
|
-
return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr,
|
|
681
|
+
return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, context);
|
|
756
682
|
}
|
|
757
683
|
if (apiAmountBig.lt(balanceBig) && balanceBig.gt(0)) {
|
|
758
684
|
const diff = balanceBig.minus(apiAmountBig);
|
|
759
685
|
const diffPercent = diff.div(balanceBig).times(100);
|
|
760
686
|
const isMaxSwap = diffPercent.lt(0.1) || diff.lt(1e3);
|
|
761
687
|
if (isMaxSwap) {
|
|
762
|
-
return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr,
|
|
688
|
+
return await this.reFetchQuoteWithBalance(quoteParams, effectiveBalanceStr, context);
|
|
763
689
|
}
|
|
764
690
|
}
|
|
765
691
|
}
|
|
@@ -770,7 +696,7 @@ var AggregateDexRouter = class {
|
|
|
770
696
|
if (!requiresRecipientInExecute(params)) {
|
|
771
697
|
return {
|
|
772
698
|
success: false,
|
|
773
|
-
error: "
|
|
699
|
+
error: "Missing sender or receiveUser"
|
|
774
700
|
};
|
|
775
701
|
}
|
|
776
702
|
const { quote, sender, receiveUser } = params;
|
|
@@ -783,13 +709,13 @@ var AggregateDexRouter = class {
|
|
|
783
709
|
if (!receiveUser || receiveUser.trim() === "") {
|
|
784
710
|
return {
|
|
785
711
|
success: false,
|
|
786
|
-
error: "receiveUser
|
|
712
|
+
error: "Missing receiveUser"
|
|
787
713
|
};
|
|
788
714
|
}
|
|
789
715
|
if (receiveUser.startsWith("0x") && receiveUser.length === 42) {
|
|
790
716
|
return {
|
|
791
717
|
success: false,
|
|
792
|
-
error:
|
|
718
|
+
error: "Invalid receiveUser address"
|
|
793
719
|
};
|
|
794
720
|
}
|
|
795
721
|
const slippage = quote.slippage || 5e-3;
|
|
@@ -819,10 +745,9 @@ var AggregateDexRouter = class {
|
|
|
819
745
|
"Re-fetching quote with receiveUser"
|
|
820
746
|
);
|
|
821
747
|
} catch (error) {
|
|
822
|
-
logger.error("AggregateDexRouter - Failed to fetch quote with receiveUser:", error);
|
|
823
748
|
return {
|
|
824
749
|
success: false,
|
|
825
|
-
error:
|
|
750
|
+
error: "Failed to get quote"
|
|
826
751
|
};
|
|
827
752
|
}
|
|
828
753
|
const routerMsg = finalQuote.routerMsg;
|
|
@@ -830,7 +755,7 @@ var AggregateDexRouter = class {
|
|
|
830
755
|
if (!routerMsg || !signature) {
|
|
831
756
|
return {
|
|
832
757
|
success: false,
|
|
833
|
-
error:
|
|
758
|
+
error: "Failed to get quote"
|
|
834
759
|
};
|
|
835
760
|
}
|
|
836
761
|
const tokens = finalQuote.tokens || [];
|
|
@@ -897,14 +822,7 @@ var AggregateDexRouter = class {
|
|
|
897
822
|
const receiveUserStorageBalance = await getStorageBalance(
|
|
898
823
|
finalQuote.tokenOut.address,
|
|
899
824
|
receiveUser
|
|
900
|
-
).catch((
|
|
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
|
-
});
|
|
825
|
+
).catch(() => null);
|
|
908
826
|
if (!receiveUserStorageBalance) {
|
|
909
827
|
transactions.push({
|
|
910
828
|
contractId: finalQuote.tokenOut.address,
|
|
@@ -989,10 +907,9 @@ var AggregateDexRouter = class {
|
|
|
989
907
|
"Final balance check before execution"
|
|
990
908
|
);
|
|
991
909
|
} catch (error) {
|
|
992
|
-
logger.error("AggregateDexRouter - Failed final balance check:", error);
|
|
993
910
|
return {
|
|
994
911
|
success: false,
|
|
995
|
-
error:
|
|
912
|
+
error: "Failed to get quote"
|
|
996
913
|
};
|
|
997
914
|
}
|
|
998
915
|
const finalAmountToTransfer = finalQuoteForExecution.amountIn;
|
|
@@ -1023,14 +940,13 @@ var AggregateDexRouter = class {
|
|
|
1023
940
|
} else {
|
|
1024
941
|
return {
|
|
1025
942
|
success: false,
|
|
1026
|
-
error:
|
|
943
|
+
error: "Execute swap failed"
|
|
1027
944
|
};
|
|
1028
945
|
}
|
|
1029
946
|
} catch (error) {
|
|
1030
|
-
logger.error("AggregateDexRouter executeSwap - Error:", error);
|
|
1031
947
|
return {
|
|
1032
948
|
success: false,
|
|
1033
|
-
error:
|
|
949
|
+
error: "Execute swap failed"
|
|
1034
950
|
};
|
|
1035
951
|
}
|
|
1036
952
|
}
|
|
@@ -1048,10 +964,6 @@ var AggregateDexRouter = class {
|
|
|
1048
964
|
}
|
|
1049
965
|
});
|
|
1050
966
|
} catch (error) {
|
|
1051
|
-
logger.error(
|
|
1052
|
-
"AggregateDexRouter - Failed to query user tokens registered:",
|
|
1053
|
-
error
|
|
1054
|
-
);
|
|
1055
967
|
return tokens.map(() => false);
|
|
1056
968
|
}
|
|
1057
969
|
}
|
|
@@ -1067,7 +979,8 @@ async function completeQuote(params, config) {
|
|
|
1067
979
|
amountIn,
|
|
1068
980
|
slippage,
|
|
1069
981
|
recipient,
|
|
1070
|
-
refundTo
|
|
982
|
+
refundTo,
|
|
983
|
+
customRecipientMsg
|
|
1071
984
|
} = params;
|
|
1072
985
|
const {
|
|
1073
986
|
intentsQuotationAdapter,
|
|
@@ -1099,10 +1012,6 @@ async function completeQuote(params, config) {
|
|
|
1099
1012
|
wrapNearContractId
|
|
1100
1013
|
);
|
|
1101
1014
|
if (!bluechipToken?.address) {
|
|
1102
|
-
logger.error("DEX Aggregator - Failed to find bluechip token:", {
|
|
1103
|
-
bluechipToken,
|
|
1104
|
-
bluechipTokens
|
|
1105
|
-
});
|
|
1106
1015
|
throw new Error("Failed to find bluechip token address");
|
|
1107
1016
|
}
|
|
1108
1017
|
const quotePaths = [];
|
|
@@ -1130,9 +1039,7 @@ async function completeQuote(params, config) {
|
|
|
1130
1039
|
promise: (async () => {
|
|
1131
1040
|
const preSwapQuote = await router.quote(quoteParams);
|
|
1132
1041
|
if (!preSwapQuote.success) {
|
|
1133
|
-
throw new Error(
|
|
1134
|
-
`${routeType} pre-swap failed: ${preSwapQuote.error}`
|
|
1135
|
-
);
|
|
1042
|
+
throw new Error("Failed to get quote");
|
|
1136
1043
|
}
|
|
1137
1044
|
const bluechipKey = bluechipToken.symbol?.toUpperCase() === "WNEAR" ? "NEAR" : bluechipToken.symbol?.toUpperCase();
|
|
1138
1045
|
const bluechipTokenConfig = bluechipKey && bluechipTokens[bluechipKey] || void 0;
|
|
@@ -1153,12 +1060,11 @@ async function completeQuote(params, config) {
|
|
|
1153
1060
|
refundTo: refundTo || recipient,
|
|
1154
1061
|
recipient,
|
|
1155
1062
|
slippageTolerance: slippageBps,
|
|
1156
|
-
swapType: "FLEX_INPUT"
|
|
1063
|
+
swapType: "FLEX_INPUT",
|
|
1064
|
+
...customRecipientMsg ? { customRecipientMsg } : {}
|
|
1157
1065
|
});
|
|
1158
1066
|
if (intentsQuote.quoteStatus !== "success") {
|
|
1159
|
-
throw new Error(
|
|
1160
|
-
`${routeType} Intents quote failed: ${intentsQuote.message}`
|
|
1161
|
-
);
|
|
1067
|
+
throw new Error("Failed to get quote");
|
|
1162
1068
|
}
|
|
1163
1069
|
return {
|
|
1164
1070
|
intentsQuote,
|
|
@@ -1213,12 +1119,11 @@ async function completeQuote(params, config) {
|
|
|
1213
1119
|
refundTo: refundTo || recipient,
|
|
1214
1120
|
recipient,
|
|
1215
1121
|
slippageTolerance: slippageBps,
|
|
1216
|
-
swapType: "EXACT_INPUT"
|
|
1122
|
+
swapType: "EXACT_INPUT",
|
|
1123
|
+
...customRecipientMsg ? { customRecipientMsg } : {}
|
|
1217
1124
|
});
|
|
1218
1125
|
if (intentsQuote.quoteStatus !== "success") {
|
|
1219
|
-
throw new Error(
|
|
1220
|
-
`Direct Intents quote failed: ${intentsQuote.message}`
|
|
1221
|
-
);
|
|
1126
|
+
throw new Error("Failed to get quote");
|
|
1222
1127
|
}
|
|
1223
1128
|
return {
|
|
1224
1129
|
intentsQuote,
|
|
@@ -1238,34 +1143,16 @@ async function completeQuote(params, config) {
|
|
|
1238
1143
|
type: pathType,
|
|
1239
1144
|
...result.value
|
|
1240
1145
|
});
|
|
1241
|
-
} else {
|
|
1242
|
-
logger.warn(`Path ${pathType} failed:`, result.reason);
|
|
1243
1146
|
}
|
|
1244
1147
|
});
|
|
1245
|
-
logger.debug("Cross-chain Quote Comparison:", {
|
|
1246
|
-
paths: validPaths.map((p) => ({
|
|
1247
|
-
type: p.type.toUpperCase(),
|
|
1248
|
-
finalAmountOut: p.finalAmountOut
|
|
1249
|
-
}))
|
|
1250
|
-
});
|
|
1251
1148
|
if (validPaths.length === 0) {
|
|
1252
|
-
|
|
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("; ")}`);
|
|
1149
|
+
throw new Error("Failed to get quote");
|
|
1260
1150
|
}
|
|
1261
1151
|
const bestPath = validPaths.reduce((best, current) => {
|
|
1262
1152
|
const bestAmount = new Big3__default.default(best.finalAmountOut);
|
|
1263
1153
|
const currentAmount = new Big3__default.default(current.finalAmountOut);
|
|
1264
1154
|
return currentAmount.gt(bestAmount) ? current : best;
|
|
1265
1155
|
});
|
|
1266
|
-
logger.debug(
|
|
1267
|
-
`\u2713 Selected best path: [${bestPath.type.toUpperCase()}] with finalAmountOut: ${bestPath.finalAmountOut}`
|
|
1268
|
-
);
|
|
1269
1156
|
const depositAddress = bestPath.intentsQuote.quoteSuccessResult?.quote?.depositAddress || "";
|
|
1270
1157
|
if (!depositAddress) {
|
|
1271
1158
|
throw new Error("Deposit address not found in intents quote");
|