@rhea-finance/cross-chain-aggregation-dex 0.2.0 → 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 +195 -18
- package/dist/index.d.ts +195 -18
- package/dist/index.js +1181 -288
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1177 -289
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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;
|
|
@@ -437,36 +583,39 @@ declare const logger: {
|
|
|
437
583
|
* Unified error messages for the SDK
|
|
438
584
|
* All error messages should be defined here for consistency
|
|
439
585
|
*/
|
|
586
|
+
declare const TRANSACTION_EXECUTION_ERROR_MESSAGE = "Transaction execution error occurred. Please contact support";
|
|
440
587
|
declare const ErrorMessages: {
|
|
441
|
-
readonly MISSING_PARAMS: "Required parameters missing";
|
|
442
|
-
readonly MISSING_TOKEN_ADDRESS: "Token address required";
|
|
443
|
-
readonly INVALID_TOKEN_ADDRESS: "Invalid token address";
|
|
444
|
-
readonly MISSING_USER_ADDRESS: "User address required";
|
|
445
|
-
readonly INVALID_USER_ADDRESS: "Invalid user address";
|
|
446
588
|
readonly QUOTE_FAILED: "Failed to get quote";
|
|
447
|
-
readonly QUOTE_INVALID: "Invalid quote";
|
|
448
|
-
readonly QUOTE_NO_ROUTE: "No route found";
|
|
449
|
-
readonly QUOTE_EXPIRED: "Quote expired, please refresh";
|
|
450
589
|
readonly EXECUTE_FAILED: "Transaction failed";
|
|
451
|
-
readonly EXECUTE_INVALID_QUOTE: "Invalid quote, please refresh";
|
|
452
|
-
readonly EXECUTE_INSUFFICIENT_BALANCE: "Insufficient balance";
|
|
453
|
-
readonly EXECUTE_INSUFFICIENT_LIQUIDITY: "Insufficient liquidity";
|
|
454
|
-
readonly EXECUTE_SLIPPAGE_TOO_HIGH: "Price changed, please refresh";
|
|
455
|
-
readonly NETWORK_ERROR: "Network error, please try again";
|
|
456
|
-
readonly API_ERROR: "Service temporarily unavailable";
|
|
457
|
-
readonly GAS_ESTIMATE_FAILED: "Unable to estimate transaction fee";
|
|
458
|
-
readonly GAS_PRICE_FAILED: "Failed to get transaction fee";
|
|
459
|
-
readonly TRANSACTION_REVERTED: "Transaction would fail, please refresh";
|
|
460
590
|
};
|
|
461
591
|
/**
|
|
462
592
|
* Get user-friendly error message
|
|
463
593
|
* Prioritizes API error messages, falls back to standardized messages
|
|
464
594
|
*/
|
|
465
595
|
declare function getErrorMessage(error: string | undefined | null, fallback?: string): string;
|
|
596
|
+
/**
|
|
597
|
+
* Process error message to determine if it's a user action or system error
|
|
598
|
+
* Returns original message for user actions, unified message for system errors
|
|
599
|
+
*/
|
|
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;
|
|
466
605
|
/**
|
|
467
606
|
* Normalize common error patterns
|
|
468
607
|
*/
|
|
469
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;
|
|
470
619
|
|
|
471
620
|
/** Set the SDK-wide bluechip token config used for NearIntents compatibility and intermediate routing. */
|
|
472
621
|
declare function setBluechipTokensConfig(config: BluechipTokensConfig): void;
|
|
@@ -620,6 +769,27 @@ declare class BitgetRouter implements DexRouter {
|
|
|
620
769
|
private normalizeEvmAddress;
|
|
621
770
|
}
|
|
622
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
|
+
|
|
623
793
|
/** Composite quote: optional NEAR DEX pre-swap + NearIntents quote. */
|
|
624
794
|
|
|
625
795
|
interface CompleteQuoteParams {
|
|
@@ -670,6 +840,13 @@ interface CompleteQuoteConfig {
|
|
|
670
840
|
currentUserAddress?: string;
|
|
671
841
|
/** Optional function to check if token supports Intents (beyond bluechip tokens) */
|
|
672
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;
|
|
673
850
|
}
|
|
674
851
|
/**
|
|
675
852
|
* Build a complete quote with optional pre-swap
|
|
@@ -699,4 +876,4 @@ interface QuoteSameChainSwapResult {
|
|
|
699
876
|
*/
|
|
700
877
|
declare function quoteSameChainSwap(params: QuoteSameChainSwapParams, dexRouters: DexRouter[]): Promise<QuoteSameChainSwapResult>;
|
|
701
878
|
|
|
702
|
-
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, type TokenInfo, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, findBestEvmBluechipToken, formatGasString, formatGasToTgas, getBluechipTokensConfig, getErrorMessage, isEvmIntentsSupportedToken, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeError, normalizeEvmAddress, normalizeTokenId, 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;
|
|
@@ -437,36 +583,39 @@ declare const logger: {
|
|
|
437
583
|
* Unified error messages for the SDK
|
|
438
584
|
* All error messages should be defined here for consistency
|
|
439
585
|
*/
|
|
586
|
+
declare const TRANSACTION_EXECUTION_ERROR_MESSAGE = "Transaction execution error occurred. Please contact support";
|
|
440
587
|
declare const ErrorMessages: {
|
|
441
|
-
readonly MISSING_PARAMS: "Required parameters missing";
|
|
442
|
-
readonly MISSING_TOKEN_ADDRESS: "Token address required";
|
|
443
|
-
readonly INVALID_TOKEN_ADDRESS: "Invalid token address";
|
|
444
|
-
readonly MISSING_USER_ADDRESS: "User address required";
|
|
445
|
-
readonly INVALID_USER_ADDRESS: "Invalid user address";
|
|
446
588
|
readonly QUOTE_FAILED: "Failed to get quote";
|
|
447
|
-
readonly QUOTE_INVALID: "Invalid quote";
|
|
448
|
-
readonly QUOTE_NO_ROUTE: "No route found";
|
|
449
|
-
readonly QUOTE_EXPIRED: "Quote expired, please refresh";
|
|
450
589
|
readonly EXECUTE_FAILED: "Transaction failed";
|
|
451
|
-
readonly EXECUTE_INVALID_QUOTE: "Invalid quote, please refresh";
|
|
452
|
-
readonly EXECUTE_INSUFFICIENT_BALANCE: "Insufficient balance";
|
|
453
|
-
readonly EXECUTE_INSUFFICIENT_LIQUIDITY: "Insufficient liquidity";
|
|
454
|
-
readonly EXECUTE_SLIPPAGE_TOO_HIGH: "Price changed, please refresh";
|
|
455
|
-
readonly NETWORK_ERROR: "Network error, please try again";
|
|
456
|
-
readonly API_ERROR: "Service temporarily unavailable";
|
|
457
|
-
readonly GAS_ESTIMATE_FAILED: "Unable to estimate transaction fee";
|
|
458
|
-
readonly GAS_PRICE_FAILED: "Failed to get transaction fee";
|
|
459
|
-
readonly TRANSACTION_REVERTED: "Transaction would fail, please refresh";
|
|
460
590
|
};
|
|
461
591
|
/**
|
|
462
592
|
* Get user-friendly error message
|
|
463
593
|
* Prioritizes API error messages, falls back to standardized messages
|
|
464
594
|
*/
|
|
465
595
|
declare function getErrorMessage(error: string | undefined | null, fallback?: string): string;
|
|
596
|
+
/**
|
|
597
|
+
* Process error message to determine if it's a user action or system error
|
|
598
|
+
* Returns original message for user actions, unified message for system errors
|
|
599
|
+
*/
|
|
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;
|
|
466
605
|
/**
|
|
467
606
|
* Normalize common error patterns
|
|
468
607
|
*/
|
|
469
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;
|
|
470
619
|
|
|
471
620
|
/** Set the SDK-wide bluechip token config used for NearIntents compatibility and intermediate routing. */
|
|
472
621
|
declare function setBluechipTokensConfig(config: BluechipTokensConfig): void;
|
|
@@ -620,6 +769,27 @@ declare class BitgetRouter implements DexRouter {
|
|
|
620
769
|
private normalizeEvmAddress;
|
|
621
770
|
}
|
|
622
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
|
+
|
|
623
793
|
/** Composite quote: optional NEAR DEX pre-swap + NearIntents quote. */
|
|
624
794
|
|
|
625
795
|
interface CompleteQuoteParams {
|
|
@@ -670,6 +840,13 @@ interface CompleteQuoteConfig {
|
|
|
670
840
|
currentUserAddress?: string;
|
|
671
841
|
/** Optional function to check if token supports Intents (beyond bluechip tokens) */
|
|
672
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;
|
|
673
850
|
}
|
|
674
851
|
/**
|
|
675
852
|
* Build a complete quote with optional pre-swap
|
|
@@ -699,4 +876,4 @@ interface QuoteSameChainSwapResult {
|
|
|
699
876
|
*/
|
|
700
877
|
declare function quoteSameChainSwap(params: QuoteSameChainSwapParams, dexRouters: DexRouter[]): Promise<QuoteSameChainSwapResult>;
|
|
701
878
|
|
|
702
|
-
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, type TokenInfo, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, findBestEvmBluechipToken, formatGasString, formatGasToTgas, getBluechipTokensConfig, getErrorMessage, isEvmIntentsSupportedToken, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeError, normalizeEvmAddress, normalizeTokenId, 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 };
|