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

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
@@ -332,6 +332,18 @@ declare function formatGasToTgas(gasInYoctoNEAR: string | number): string;
332
332
  * @returns Formatted gas string in yoctoNEAR
333
333
  */
334
334
  declare function formatGasString(gas: string | number | bigint): string;
335
+ /**
336
+ * Select the best quote from multiple quotes based on maximum amountOut
337
+ */
338
+ declare function selectBestQuote<T extends {
339
+ amountOut: string;
340
+ }, R = any>(quotes: Array<{
341
+ quote: T;
342
+ router: R;
343
+ }>): {
344
+ quote: T;
345
+ router: R;
346
+ };
335
347
 
336
348
  /** NEAR DEX router implementation (FindPath for routing + REF for execution). */
337
349
 
@@ -396,20 +408,12 @@ declare class AggregateDexRouter implements DexRouter {
396
408
  */
397
409
  quote(params: QuoteParams): Promise<QuoteResult>;
398
410
  /**
399
- * Finalize quote with depositAddress (deprecated)
400
- *
401
- * @deprecated No longer needed. executeSwap automatically fetches final quote using receiveUser (depositAddress).
402
- * Kept for interface compatibility only.
411
+ * @deprecated No longer needed. Kept for interface compatibility only.
403
412
  */
404
413
  finalizeQuote(params: QuoteParams, depositAddress: string): Promise<QuoteResult>;
405
- /**
406
- * Execute swap with V2 Router
407
- * Automatically fetches final quote using receiveUser (depositAddress) to ensure correct routerMsg and signature.
408
- */
414
+ private reFetchQuoteWithBalance;
415
+ private ensureQuoteAmountWithinBalance;
409
416
  executeSwap(params: ExecuteParams): Promise<ExecuteResult>;
410
- /**
411
- * Query user token registration status in AGGREGATE_DEX contract
412
- */
413
417
  private queryUserTokensRegistered;
414
418
  }
415
419
 
@@ -436,10 +440,12 @@ interface CompleteQuoteResult {
436
440
  tokenIn: TokenInfo;
437
441
  tokenOut: TokenInfo;
438
442
  executor: DexRouter;
443
+ routeType?: "v1" | "v2";
439
444
  };
440
445
  finalAmountOut: string;
441
446
  totalPriceImpact?: number;
442
447
  totalFee?: number;
448
+ routeType?: "v1" | "v2" | "intents";
443
449
  }
444
450
  interface CompleteQuoteConfig {
445
451
  intentsQuotationAdapter: IntentsQuotationAdapter;
@@ -450,6 +456,8 @@ interface CompleteQuoteConfig {
450
456
  getWrapNearContractId(): string;
451
457
  };
452
458
  currentUserAddress?: string;
459
+ /** Optional function to check if token supports Intents (beyond bluechip tokens) */
460
+ isIntentsSupportedToken?: (token: TokenInfo) => boolean;
453
461
  }
454
462
  /**
455
463
  * Build a "complete quote":
@@ -462,4 +470,27 @@ interface CompleteQuoteConfig {
462
470
  */
463
471
  declare function completeQuote(params: CompleteQuoteParams, config: CompleteQuoteConfig): Promise<CompleteQuoteResult>;
464
472
 
465
- export { AggregateDexRouter, type AggregateDexRouterConfig, type BaseExecuteParams, type BaseQuoteParams, type BluechipTokenConfig, type BluechipTokensConfig, type CompleteQuoteConfig, type CompleteQuoteParams, type CompleteQuoteResult, type ConfigAdapter, type DexRouter, type ExecuteParams, type ExecuteResult, type FindPathAdapter, type FindPathResponse, type IntentsQuotationAdapter, type IntentsQuoteResult, type NearChainAdapter, NearSmartRouter, type NearSmartRouterConfig, type PoolInfo, type QuoteParams, type QuoteResult, type RecipientExecuteParams, type RecipientQuoteParams, type Route, type RouterCapabilities, type SimpleQuoteParams, type SupportedChain, type SwapMultiDexPathAdapter, type SwapMultiDexPathResponse, type TokenInfo, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, formatGasString, formatGasToTgas, getBluechipTokensConfig, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeTokenId, requiresRecipient, requiresRecipientInExecute, setBluechipTokensConfig };
473
+ /**
474
+ * Same-chain swap quote (NEAR -> NEAR)
475
+ * Queries V1 and V2 routers in parallel and selects the best route based on maximum amountOut
476
+ */
477
+
478
+ interface QuoteSameChainSwapParams {
479
+ tokenIn: TokenInfo;
480
+ tokenOut: TokenInfo;
481
+ amountIn: string;
482
+ slippage: number;
483
+ recipient: string;
484
+ currentUserAddress: string;
485
+ }
486
+ interface QuoteSameChainSwapResult {
487
+ quote: QuoteResult;
488
+ router: DexRouter;
489
+ }
490
+ /**
491
+ * Quote same-chain swap (NEAR -> NEAR) by querying V1 and V2 routers in parallel
492
+ * and selecting the best route based on maximum amountOut
493
+ */
494
+ declare function quoteSameChainSwap(params: QuoteSameChainSwapParams, dexRouters: DexRouter[]): Promise<QuoteSameChainSwapResult>;
495
+
496
+ export { AggregateDexRouter, type AggregateDexRouterConfig, type BaseExecuteParams, type BaseQuoteParams, type BluechipTokenConfig, type BluechipTokensConfig, type CompleteQuoteConfig, type CompleteQuoteParams, type CompleteQuoteResult, type ConfigAdapter, type DexRouter, type ExecuteParams, type ExecuteResult, type FindPathAdapter, type FindPathResponse, type IntentsQuotationAdapter, type IntentsQuoteResult, type NearChainAdapter, NearSmartRouter, type NearSmartRouterConfig, type PoolInfo, type QuoteParams, type QuoteResult, type QuoteSameChainSwapParams, type QuoteSameChainSwapResult, type RecipientExecuteParams, type RecipientQuoteParams, type Route, type RouterCapabilities, type SimpleQuoteParams, type SupportedChain, type SwapMultiDexPathAdapter, type SwapMultiDexPathResponse, type TokenInfo, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, formatGasString, formatGasToTgas, getBluechipTokensConfig, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeTokenId, quoteSameChainSwap, requiresRecipient, requiresRecipientInExecute, selectBestQuote, setBluechipTokensConfig };
package/dist/index.d.ts CHANGED
@@ -332,6 +332,18 @@ declare function formatGasToTgas(gasInYoctoNEAR: string | number): string;
332
332
  * @returns Formatted gas string in yoctoNEAR
333
333
  */
334
334
  declare function formatGasString(gas: string | number | bigint): string;
335
+ /**
336
+ * Select the best quote from multiple quotes based on maximum amountOut
337
+ */
338
+ declare function selectBestQuote<T extends {
339
+ amountOut: string;
340
+ }, R = any>(quotes: Array<{
341
+ quote: T;
342
+ router: R;
343
+ }>): {
344
+ quote: T;
345
+ router: R;
346
+ };
335
347
 
336
348
  /** NEAR DEX router implementation (FindPath for routing + REF for execution). */
337
349
 
@@ -396,20 +408,12 @@ declare class AggregateDexRouter implements DexRouter {
396
408
  */
397
409
  quote(params: QuoteParams): Promise<QuoteResult>;
398
410
  /**
399
- * Finalize quote with depositAddress (deprecated)
400
- *
401
- * @deprecated No longer needed. executeSwap automatically fetches final quote using receiveUser (depositAddress).
402
- * Kept for interface compatibility only.
411
+ * @deprecated No longer needed. Kept for interface compatibility only.
403
412
  */
404
413
  finalizeQuote(params: QuoteParams, depositAddress: string): Promise<QuoteResult>;
405
- /**
406
- * Execute swap with V2 Router
407
- * Automatically fetches final quote using receiveUser (depositAddress) to ensure correct routerMsg and signature.
408
- */
414
+ private reFetchQuoteWithBalance;
415
+ private ensureQuoteAmountWithinBalance;
409
416
  executeSwap(params: ExecuteParams): Promise<ExecuteResult>;
410
- /**
411
- * Query user token registration status in AGGREGATE_DEX contract
412
- */
413
417
  private queryUserTokensRegistered;
414
418
  }
415
419
 
@@ -436,10 +440,12 @@ interface CompleteQuoteResult {
436
440
  tokenIn: TokenInfo;
437
441
  tokenOut: TokenInfo;
438
442
  executor: DexRouter;
443
+ routeType?: "v1" | "v2";
439
444
  };
440
445
  finalAmountOut: string;
441
446
  totalPriceImpact?: number;
442
447
  totalFee?: number;
448
+ routeType?: "v1" | "v2" | "intents";
443
449
  }
444
450
  interface CompleteQuoteConfig {
445
451
  intentsQuotationAdapter: IntentsQuotationAdapter;
@@ -450,6 +456,8 @@ interface CompleteQuoteConfig {
450
456
  getWrapNearContractId(): string;
451
457
  };
452
458
  currentUserAddress?: string;
459
+ /** Optional function to check if token supports Intents (beyond bluechip tokens) */
460
+ isIntentsSupportedToken?: (token: TokenInfo) => boolean;
453
461
  }
454
462
  /**
455
463
  * Build a "complete quote":
@@ -462,4 +470,27 @@ interface CompleteQuoteConfig {
462
470
  */
463
471
  declare function completeQuote(params: CompleteQuoteParams, config: CompleteQuoteConfig): Promise<CompleteQuoteResult>;
464
472
 
465
- export { AggregateDexRouter, type AggregateDexRouterConfig, type BaseExecuteParams, type BaseQuoteParams, type BluechipTokenConfig, type BluechipTokensConfig, type CompleteQuoteConfig, type CompleteQuoteParams, type CompleteQuoteResult, type ConfigAdapter, type DexRouter, type ExecuteParams, type ExecuteResult, type FindPathAdapter, type FindPathResponse, type IntentsQuotationAdapter, type IntentsQuoteResult, type NearChainAdapter, NearSmartRouter, type NearSmartRouterConfig, type PoolInfo, type QuoteParams, type QuoteResult, type RecipientExecuteParams, type RecipientQuoteParams, type Route, type RouterCapabilities, type SimpleQuoteParams, type SupportedChain, type SwapMultiDexPathAdapter, type SwapMultiDexPathResponse, type TokenInfo, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, formatGasString, formatGasToTgas, getBluechipTokensConfig, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeTokenId, requiresRecipient, requiresRecipientInExecute, setBluechipTokensConfig };
473
+ /**
474
+ * Same-chain swap quote (NEAR -> NEAR)
475
+ * Queries V1 and V2 routers in parallel and selects the best route based on maximum amountOut
476
+ */
477
+
478
+ interface QuoteSameChainSwapParams {
479
+ tokenIn: TokenInfo;
480
+ tokenOut: TokenInfo;
481
+ amountIn: string;
482
+ slippage: number;
483
+ recipient: string;
484
+ currentUserAddress: string;
485
+ }
486
+ interface QuoteSameChainSwapResult {
487
+ quote: QuoteResult;
488
+ router: DexRouter;
489
+ }
490
+ /**
491
+ * Quote same-chain swap (NEAR -> NEAR) by querying V1 and V2 routers in parallel
492
+ * and selecting the best route based on maximum amountOut
493
+ */
494
+ declare function quoteSameChainSwap(params: QuoteSameChainSwapParams, dexRouters: DexRouter[]): Promise<QuoteSameChainSwapResult>;
495
+
496
+ export { AggregateDexRouter, type AggregateDexRouterConfig, type BaseExecuteParams, type BaseQuoteParams, type BluechipTokenConfig, type BluechipTokensConfig, type CompleteQuoteConfig, type CompleteQuoteParams, type CompleteQuoteResult, type ConfigAdapter, type DexRouter, type ExecuteParams, type ExecuteResult, type FindPathAdapter, type FindPathResponse, type IntentsQuotationAdapter, type IntentsQuoteResult, type NearChainAdapter, NearSmartRouter, type NearSmartRouterConfig, type PoolInfo, type QuoteParams, type QuoteResult, type QuoteSameChainSwapParams, type QuoteSameChainSwapResult, type RecipientExecuteParams, type RecipientQuoteParams, type Route, type RouterCapabilities, type SimpleQuoteParams, type SupportedChain, type SwapMultiDexPathAdapter, type SwapMultiDexPathResponse, type TokenInfo, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, formatGasString, formatGasToTgas, getBluechipTokensConfig, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeTokenId, quoteSameChainSwap, requiresRecipient, requiresRecipientInExecute, selectBestQuote, setBluechipTokensConfig };