@rhea-finance/cross-chain-aggregation-dex 0.2.1 → 0.2.2

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
@@ -6,6 +6,10 @@ interface TokenInfo {
6
6
  symbol: string;
7
7
  decimals: number;
8
8
  chain: string;
9
+ /** Optional: Intents assetId (e.g., nep245:..., nep141:...) provided by backend */
10
+ assetId?: string;
11
+ /** Optional: Platform identifier ("nearIntents" | "okx" | "bitget") */
12
+ platform?: string;
9
13
  }
10
14
  interface Route {
11
15
  pools: PoolInfo[];
@@ -425,6 +429,148 @@ interface EvmChainAdapter {
425
429
  */
426
430
  getSigner?(): Promise<any>;
427
431
  }
432
+ /** OKX DEX Aggregator API Quote response. */
433
+ interface OkxQuoteResponse {
434
+ code?: string | number;
435
+ msg?: string;
436
+ data?: Array<{
437
+ chainIndex?: string;
438
+ fromToken: {
439
+ tokenSymbol?: string;
440
+ decimal: string | number;
441
+ tokenAddress?: string;
442
+ isHoneyPot?: boolean;
443
+ taxRate?: string;
444
+ [key: string]: any;
445
+ };
446
+ toToken: {
447
+ tokenSymbol?: string;
448
+ decimal: string | number;
449
+ tokenAddress?: string;
450
+ isHoneyPot?: boolean;
451
+ taxRate?: string;
452
+ [key: string]: any;
453
+ };
454
+ fromTokenAmount: string;
455
+ toTokenAmount: string;
456
+ estimateGasFee?: string;
457
+ priceImpactPercent?: string;
458
+ dexRouterList?: any[];
459
+ router?: string;
460
+ swapMode?: string;
461
+ tradeFee?: string;
462
+ contextSlot?: number;
463
+ fromAmount?: string;
464
+ toAmount?: string;
465
+ minToAmount?: string;
466
+ estimatedGas?: string;
467
+ priceImpact?: string;
468
+ routes?: any[];
469
+ [key: string]: any;
470
+ }>;
471
+ }
472
+ /** OKX DEX Aggregator API Swap response. */
473
+ interface OkxSwapResponse {
474
+ code?: string | number;
475
+ msg?: string;
476
+ data?: {
477
+ transaction?: {
478
+ data?: string;
479
+ to?: string;
480
+ value?: string;
481
+ gas?: string;
482
+ gasPrice?: string;
483
+ estimateRevert?: boolean;
484
+ };
485
+ tx?: string | {
486
+ data?: string;
487
+ to?: string;
488
+ value?: string;
489
+ gas?: string;
490
+ gasPrice?: string;
491
+ estimateRevert?: boolean;
492
+ [key: string]: any;
493
+ };
494
+ data?: string;
495
+ to?: string;
496
+ value?: string;
497
+ gas?: string;
498
+ gasPrice?: string;
499
+ txHash?: string;
500
+ explorerUrl?: string;
501
+ estimateRevert?: boolean;
502
+ [key: string]: any;
503
+ } | Array<{
504
+ tx?: string | {
505
+ data?: string;
506
+ to?: string;
507
+ value?: string;
508
+ gas?: string;
509
+ gasPrice?: string;
510
+ estimateRevert?: boolean;
511
+ [key: string]: any;
512
+ };
513
+ transaction?: {
514
+ data?: string;
515
+ to?: string;
516
+ value?: string;
517
+ gas?: string;
518
+ gasPrice?: string;
519
+ estimateRevert?: boolean;
520
+ };
521
+ [key: string]: any;
522
+ }>;
523
+ }
524
+ /** Adapter for OKX DEX Aggregator API. */
525
+ interface OkxAdapter {
526
+ quote(params: {
527
+ chainId: number;
528
+ tokenIn: string;
529
+ tokenOut: string;
530
+ amountIn: string;
531
+ slippage: number;
532
+ userAddress: string;
533
+ tokenInSymbol?: string;
534
+ tokenInDecimals?: number;
535
+ tokenOutSymbol?: string;
536
+ tokenOutDecimals?: number;
537
+ }): Promise<OkxQuoteResponse>;
538
+ /**
539
+ * Get final calldata for swap execution
540
+ */
541
+ swap(params: {
542
+ chainId: number;
543
+ tokenIn: string;
544
+ tokenOut: string;
545
+ amountIn: string;
546
+ minAmountOut?: string;
547
+ slippage: number;
548
+ fromAddress: string;
549
+ toAddress: string;
550
+ tokenInSymbol?: string;
551
+ tokenInDecimals?: number;
552
+ tokenOutSymbol?: string;
553
+ tokenOutDecimals?: number;
554
+ }): Promise<OkxSwapResponse>;
555
+ /**
556
+ * Get OKX approve transaction data
557
+ * Reference: https://web3.okx.com/zh-hans/onchain-os/dev-docs/trade-api/dex-approve-transaction
558
+ */
559
+ getApproveTransaction(params: {
560
+ chainId: number;
561
+ tokenAddress: string;
562
+ approveAmount: string;
563
+ }): Promise<{
564
+ code: string | number;
565
+ msg?: string;
566
+ data?: {
567
+ data: string;
568
+ dexContractAddress: string;
569
+ gasLimit: string;
570
+ gasPrice: string;
571
+ };
572
+ }>;
573
+ }
428
574
 
429
575
  declare const logger: {
430
576
  debug: (...args: any[]) => void;
@@ -452,10 +598,24 @@ declare function getErrorMessage(error: string | undefined | null, fallback?: st
452
598
  * Returns original message for user actions, unified message for system errors
453
599
  */
454
600
  declare function processErrorMessage(errorMessage: string): string;
601
+ /**
602
+ * Normalize error for Intents API only
603
+ */
604
+ declare function normalizeErrorForIntents(error: string | undefined | null): string;
455
605
  /**
456
606
  * Normalize common error patterns
457
607
  */
458
608
  declare function normalizeError(error: string | undefined | null): string;
609
+ /**
610
+ * Format error message for intents API errors
611
+ * Simplified version that preserves detailed error messages while applying common formatting rules
612
+ */
613
+ declare function formatErrorMessage({ error, fallbackMessage, originAsset, friendly, }: {
614
+ error?: any;
615
+ fallbackMessage?: string;
616
+ originAsset?: string;
617
+ friendly?: boolean;
618
+ }): string;
459
619
 
460
620
  /** Set the SDK-wide bluechip token config used for NearIntents compatibility and intermediate routing. */
461
621
  declare function setBluechipTokensConfig(config: BluechipTokensConfig): void;
@@ -609,6 +769,27 @@ declare class BitgetRouter implements DexRouter {
609
769
  private normalizeEvmAddress;
610
770
  }
611
771
 
772
+ interface OkxRouterConfig {
773
+ okxAdapter: OkxAdapter;
774
+ evmChainAdapter: EvmChainAdapter;
775
+ chainId: number;
776
+ }
777
+ /**
778
+ * OKX Router implementation for EVM chains
779
+ */
780
+ declare class OkxRouter implements DexRouter {
781
+ private okxAdapter;
782
+ private evmChainAdapter;
783
+ private chainId;
784
+ constructor(config: OkxRouterConfig);
785
+ getCapabilities(): RouterCapabilities;
786
+ getSupportedChain(): "evm";
787
+ getChainId(): number;
788
+ quote(params: QuoteParams): Promise<QuoteResult>;
789
+ executeSwap(params: ExecuteParams): Promise<ExecuteResult>;
790
+ private normalizeEvmAddress;
791
+ }
792
+
612
793
  /** Composite quote: optional NEAR DEX pre-swap + NearIntents quote. */
613
794
 
614
795
  interface CompleteQuoteParams {
@@ -659,6 +840,13 @@ interface CompleteQuoteConfig {
659
840
  currentUserAddress?: string;
660
841
  /** Optional function to check if token supports Intents (beyond bluechip tokens) */
661
842
  isIntentsSupportedToken?: (token: TokenInfo) => boolean;
843
+ /** Optional function to format error messages (for consistency with frontend error handling) */
844
+ formatErrorMessage?: (params: {
845
+ error?: any;
846
+ fallbackMessage?: string;
847
+ originAsset?: string;
848
+ friendly?: boolean;
849
+ }) => string;
662
850
  }
663
851
  /**
664
852
  * Build a complete quote with optional pre-swap
@@ -688,4 +876,4 @@ interface QuoteSameChainSwapResult {
688
876
  */
689
877
  declare function quoteSameChainSwap(params: QuoteSameChainSwapParams, dexRouters: DexRouter[]): Promise<QuoteSameChainSwapResult>;
690
878
 
691
- export { AggregateDexRouter, type AggregateDexRouterConfig, type BaseExecuteParams, type BaseQuoteParams, type BitgetAdapter, type BitgetQuoteResponse, BitgetRouter, type BitgetRouterConfig, type BitgetSwapResponse, type BluechipTokenConfig, type BluechipTokensConfig, type CompleteQuoteConfig, type CompleteQuoteParams, type CompleteQuoteResult, type ConfigAdapter, type DexRouter, ErrorMessages, type EvmChainAdapter, 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, TRANSACTION_EXECUTION_ERROR_MESSAGE, type TokenInfo, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, findBestEvmBluechipToken, formatGasString, formatGasToTgas, getBluechipTokensConfig, getErrorMessage, isEvmIntentsSupportedToken, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeError, normalizeEvmAddress, normalizeTokenId, processErrorMessage, quoteSameChainSwap, requiresRecipient, requiresRecipientInExecute, selectBestQuote, setBluechipTokensConfig };
879
+ export { AggregateDexRouter, type AggregateDexRouterConfig, type BaseExecuteParams, type BaseQuoteParams, type BitgetAdapter, type BitgetQuoteResponse, BitgetRouter, type BitgetRouterConfig, type BitgetSwapResponse, type BluechipTokenConfig, type BluechipTokensConfig, type CompleteQuoteConfig, type CompleteQuoteParams, type CompleteQuoteResult, type ConfigAdapter, type DexRouter, ErrorMessages, type EvmChainAdapter, type ExecuteParams, type ExecuteResult, type FindPathAdapter, type FindPathResponse, type IntentsQuotationAdapter, type IntentsQuoteResult, type NearChainAdapter, NearSmartRouter, type NearSmartRouterConfig, type OkxAdapter, type OkxQuoteResponse, OkxRouter, type OkxRouterConfig, type OkxSwapResponse, 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, TRANSACTION_EXECUTION_ERROR_MESSAGE, type TokenInfo, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, findBestEvmBluechipToken, formatErrorMessage, formatGasString, formatGasToTgas, getBluechipTokensConfig, getErrorMessage, isEvmIntentsSupportedToken, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeError, normalizeErrorForIntents, normalizeEvmAddress, normalizeTokenId, processErrorMessage, quoteSameChainSwap, requiresRecipient, requiresRecipientInExecute, selectBestQuote, setBluechipTokensConfig };
package/dist/index.d.ts CHANGED
@@ -6,6 +6,10 @@ interface TokenInfo {
6
6
  symbol: string;
7
7
  decimals: number;
8
8
  chain: string;
9
+ /** Optional: Intents assetId (e.g., nep245:..., nep141:...) provided by backend */
10
+ assetId?: string;
11
+ /** Optional: Platform identifier ("nearIntents" | "okx" | "bitget") */
12
+ platform?: string;
9
13
  }
10
14
  interface Route {
11
15
  pools: PoolInfo[];
@@ -425,6 +429,148 @@ interface EvmChainAdapter {
425
429
  */
426
430
  getSigner?(): Promise<any>;
427
431
  }
432
+ /** OKX DEX Aggregator API Quote response. */
433
+ interface OkxQuoteResponse {
434
+ code?: string | number;
435
+ msg?: string;
436
+ data?: Array<{
437
+ chainIndex?: string;
438
+ fromToken: {
439
+ tokenSymbol?: string;
440
+ decimal: string | number;
441
+ tokenAddress?: string;
442
+ isHoneyPot?: boolean;
443
+ taxRate?: string;
444
+ [key: string]: any;
445
+ };
446
+ toToken: {
447
+ tokenSymbol?: string;
448
+ decimal: string | number;
449
+ tokenAddress?: string;
450
+ isHoneyPot?: boolean;
451
+ taxRate?: string;
452
+ [key: string]: any;
453
+ };
454
+ fromTokenAmount: string;
455
+ toTokenAmount: string;
456
+ estimateGasFee?: string;
457
+ priceImpactPercent?: string;
458
+ dexRouterList?: any[];
459
+ router?: string;
460
+ swapMode?: string;
461
+ tradeFee?: string;
462
+ contextSlot?: number;
463
+ fromAmount?: string;
464
+ toAmount?: string;
465
+ minToAmount?: string;
466
+ estimatedGas?: string;
467
+ priceImpact?: string;
468
+ routes?: any[];
469
+ [key: string]: any;
470
+ }>;
471
+ }
472
+ /** OKX DEX Aggregator API Swap response. */
473
+ interface OkxSwapResponse {
474
+ code?: string | number;
475
+ msg?: string;
476
+ data?: {
477
+ transaction?: {
478
+ data?: string;
479
+ to?: string;
480
+ value?: string;
481
+ gas?: string;
482
+ gasPrice?: string;
483
+ estimateRevert?: boolean;
484
+ };
485
+ tx?: string | {
486
+ data?: string;
487
+ to?: string;
488
+ value?: string;
489
+ gas?: string;
490
+ gasPrice?: string;
491
+ estimateRevert?: boolean;
492
+ [key: string]: any;
493
+ };
494
+ data?: string;
495
+ to?: string;
496
+ value?: string;
497
+ gas?: string;
498
+ gasPrice?: string;
499
+ txHash?: string;
500
+ explorerUrl?: string;
501
+ estimateRevert?: boolean;
502
+ [key: string]: any;
503
+ } | Array<{
504
+ tx?: string | {
505
+ data?: string;
506
+ to?: string;
507
+ value?: string;
508
+ gas?: string;
509
+ gasPrice?: string;
510
+ estimateRevert?: boolean;
511
+ [key: string]: any;
512
+ };
513
+ transaction?: {
514
+ data?: string;
515
+ to?: string;
516
+ value?: string;
517
+ gas?: string;
518
+ gasPrice?: string;
519
+ estimateRevert?: boolean;
520
+ };
521
+ [key: string]: any;
522
+ }>;
523
+ }
524
+ /** Adapter for OKX DEX Aggregator API. */
525
+ interface OkxAdapter {
526
+ quote(params: {
527
+ chainId: number;
528
+ tokenIn: string;
529
+ tokenOut: string;
530
+ amountIn: string;
531
+ slippage: number;
532
+ userAddress: string;
533
+ tokenInSymbol?: string;
534
+ tokenInDecimals?: number;
535
+ tokenOutSymbol?: string;
536
+ tokenOutDecimals?: number;
537
+ }): Promise<OkxQuoteResponse>;
538
+ /**
539
+ * Get final calldata for swap execution
540
+ */
541
+ swap(params: {
542
+ chainId: number;
543
+ tokenIn: string;
544
+ tokenOut: string;
545
+ amountIn: string;
546
+ minAmountOut?: string;
547
+ slippage: number;
548
+ fromAddress: string;
549
+ toAddress: string;
550
+ tokenInSymbol?: string;
551
+ tokenInDecimals?: number;
552
+ tokenOutSymbol?: string;
553
+ tokenOutDecimals?: number;
554
+ }): Promise<OkxSwapResponse>;
555
+ /**
556
+ * Get OKX approve transaction data
557
+ * Reference: https://web3.okx.com/zh-hans/onchain-os/dev-docs/trade-api/dex-approve-transaction
558
+ */
559
+ getApproveTransaction(params: {
560
+ chainId: number;
561
+ tokenAddress: string;
562
+ approveAmount: string;
563
+ }): Promise<{
564
+ code: string | number;
565
+ msg?: string;
566
+ data?: {
567
+ data: string;
568
+ dexContractAddress: string;
569
+ gasLimit: string;
570
+ gasPrice: string;
571
+ };
572
+ }>;
573
+ }
428
574
 
429
575
  declare const logger: {
430
576
  debug: (...args: any[]) => void;
@@ -452,10 +598,24 @@ declare function getErrorMessage(error: string | undefined | null, fallback?: st
452
598
  * Returns original message for user actions, unified message for system errors
453
599
  */
454
600
  declare function processErrorMessage(errorMessage: string): string;
601
+ /**
602
+ * Normalize error for Intents API only
603
+ */
604
+ declare function normalizeErrorForIntents(error: string | undefined | null): string;
455
605
  /**
456
606
  * Normalize common error patterns
457
607
  */
458
608
  declare function normalizeError(error: string | undefined | null): string;
609
+ /**
610
+ * Format error message for intents API errors
611
+ * Simplified version that preserves detailed error messages while applying common formatting rules
612
+ */
613
+ declare function formatErrorMessage({ error, fallbackMessage, originAsset, friendly, }: {
614
+ error?: any;
615
+ fallbackMessage?: string;
616
+ originAsset?: string;
617
+ friendly?: boolean;
618
+ }): string;
459
619
 
460
620
  /** Set the SDK-wide bluechip token config used for NearIntents compatibility and intermediate routing. */
461
621
  declare function setBluechipTokensConfig(config: BluechipTokensConfig): void;
@@ -609,6 +769,27 @@ declare class BitgetRouter implements DexRouter {
609
769
  private normalizeEvmAddress;
610
770
  }
611
771
 
772
+ interface OkxRouterConfig {
773
+ okxAdapter: OkxAdapter;
774
+ evmChainAdapter: EvmChainAdapter;
775
+ chainId: number;
776
+ }
777
+ /**
778
+ * OKX Router implementation for EVM chains
779
+ */
780
+ declare class OkxRouter implements DexRouter {
781
+ private okxAdapter;
782
+ private evmChainAdapter;
783
+ private chainId;
784
+ constructor(config: OkxRouterConfig);
785
+ getCapabilities(): RouterCapabilities;
786
+ getSupportedChain(): "evm";
787
+ getChainId(): number;
788
+ quote(params: QuoteParams): Promise<QuoteResult>;
789
+ executeSwap(params: ExecuteParams): Promise<ExecuteResult>;
790
+ private normalizeEvmAddress;
791
+ }
792
+
612
793
  /** Composite quote: optional NEAR DEX pre-swap + NearIntents quote. */
613
794
 
614
795
  interface CompleteQuoteParams {
@@ -659,6 +840,13 @@ interface CompleteQuoteConfig {
659
840
  currentUserAddress?: string;
660
841
  /** Optional function to check if token supports Intents (beyond bluechip tokens) */
661
842
  isIntentsSupportedToken?: (token: TokenInfo) => boolean;
843
+ /** Optional function to format error messages (for consistency with frontend error handling) */
844
+ formatErrorMessage?: (params: {
845
+ error?: any;
846
+ fallbackMessage?: string;
847
+ originAsset?: string;
848
+ friendly?: boolean;
849
+ }) => string;
662
850
  }
663
851
  /**
664
852
  * Build a complete quote with optional pre-swap
@@ -688,4 +876,4 @@ interface QuoteSameChainSwapResult {
688
876
  */
689
877
  declare function quoteSameChainSwap(params: QuoteSameChainSwapParams, dexRouters: DexRouter[]): Promise<QuoteSameChainSwapResult>;
690
878
 
691
- export { AggregateDexRouter, type AggregateDexRouterConfig, type BaseExecuteParams, type BaseQuoteParams, type BitgetAdapter, type BitgetQuoteResponse, BitgetRouter, type BitgetRouterConfig, type BitgetSwapResponse, type BluechipTokenConfig, type BluechipTokensConfig, type CompleteQuoteConfig, type CompleteQuoteParams, type CompleteQuoteResult, type ConfigAdapter, type DexRouter, ErrorMessages, type EvmChainAdapter, 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, TRANSACTION_EXECUTION_ERROR_MESSAGE, type TokenInfo, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, findBestEvmBluechipToken, formatGasString, formatGasToTgas, getBluechipTokensConfig, getErrorMessage, isEvmIntentsSupportedToken, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeError, normalizeEvmAddress, normalizeTokenId, processErrorMessage, quoteSameChainSwap, requiresRecipient, requiresRecipientInExecute, selectBestQuote, setBluechipTokensConfig };
879
+ export { AggregateDexRouter, type AggregateDexRouterConfig, type BaseExecuteParams, type BaseQuoteParams, type BitgetAdapter, type BitgetQuoteResponse, BitgetRouter, type BitgetRouterConfig, type BitgetSwapResponse, type BluechipTokenConfig, type BluechipTokensConfig, type CompleteQuoteConfig, type CompleteQuoteParams, type CompleteQuoteResult, type ConfigAdapter, type DexRouter, ErrorMessages, type EvmChainAdapter, type ExecuteParams, type ExecuteResult, type FindPathAdapter, type FindPathResponse, type IntentsQuotationAdapter, type IntentsQuoteResult, type NearChainAdapter, NearSmartRouter, type NearSmartRouterConfig, type OkxAdapter, type OkxQuoteResponse, OkxRouter, type OkxRouterConfig, type OkxSwapResponse, 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, TRANSACTION_EXECUTION_ERROR_MESSAGE, type TokenInfo, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, findBestEvmBluechipToken, formatErrorMessage, formatGasString, formatGasToTgas, getBluechipTokensConfig, getErrorMessage, isEvmIntentsSupportedToken, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeError, normalizeErrorForIntents, normalizeEvmAddress, normalizeTokenId, processErrorMessage, quoteSameChainSwap, requiresRecipient, requiresRecipientInExecute, selectBestQuote, setBluechipTokensConfig };