@rhea-finance/cross-chain-aggregation-dex 1.0.5 → 2.0.0

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.
Files changed (60) hide show
  1. package/README.md +277 -270
  2. package/dist/executors/aptos.d.mts +19 -0
  3. package/dist/executors/aptos.d.ts +19 -0
  4. package/dist/executors/aptos.js +140 -0
  5. package/dist/executors/aptos.js.map +1 -0
  6. package/dist/executors/aptos.mjs +138 -0
  7. package/dist/executors/aptos.mjs.map +1 -0
  8. package/dist/executors/bitcoin.d.mts +22 -0
  9. package/dist/executors/bitcoin.d.ts +22 -0
  10. package/dist/executors/bitcoin.js +153 -0
  11. package/dist/executors/bitcoin.js.map +1 -0
  12. package/dist/executors/bitcoin.mjs +151 -0
  13. package/dist/executors/bitcoin.mjs.map +1 -0
  14. package/dist/executors/evm.d.mts +18 -0
  15. package/dist/executors/evm.d.ts +18 -0
  16. package/dist/executors/evm.js +233 -0
  17. package/dist/executors/evm.js.map +1 -0
  18. package/dist/executors/evm.mjs +231 -0
  19. package/dist/executors/evm.mjs.map +1 -0
  20. package/dist/executors/near.d.mts +18 -0
  21. package/dist/executors/near.d.ts +18 -0
  22. package/dist/executors/near.js +162 -0
  23. package/dist/executors/near.js.map +1 -0
  24. package/dist/executors/near.mjs +160 -0
  25. package/dist/executors/near.mjs.map +1 -0
  26. package/dist/executors/solana.d.mts +20 -0
  27. package/dist/executors/solana.d.ts +20 -0
  28. package/dist/executors/solana.js +151 -0
  29. package/dist/executors/solana.js.map +1 -0
  30. package/dist/executors/solana.mjs +149 -0
  31. package/dist/executors/solana.mjs.map +1 -0
  32. package/dist/executors/sui.d.mts +19 -0
  33. package/dist/executors/sui.d.ts +19 -0
  34. package/dist/executors/sui.js +154 -0
  35. package/dist/executors/sui.js.map +1 -0
  36. package/dist/executors/sui.mjs +152 -0
  37. package/dist/executors/sui.mjs.map +1 -0
  38. package/dist/executors/tron.d.mts +24 -0
  39. package/dist/executors/tron.d.ts +24 -0
  40. package/dist/executors/tron.js +161 -0
  41. package/dist/executors/tron.js.map +1 -0
  42. package/dist/executors/tron.mjs +159 -0
  43. package/dist/executors/tron.mjs.map +1 -0
  44. package/dist/executors/zcash.d.mts +19 -0
  45. package/dist/executors/zcash.d.ts +19 -0
  46. package/dist/executors/zcash.js +158 -0
  47. package/dist/executors/zcash.js.map +1 -0
  48. package/dist/executors/zcash.mjs +156 -0
  49. package/dist/executors/zcash.mjs.map +1 -0
  50. package/dist/index.d.mts +277 -306
  51. package/dist/index.d.ts +277 -306
  52. package/dist/index.js +2359 -631
  53. package/dist/index.js.map +1 -1
  54. package/dist/index.mjs +2332 -620
  55. package/dist/index.mjs.map +1 -1
  56. package/dist/registry-DRYUqs7T.d.mts +532 -0
  57. package/dist/registry-DRYUqs7T.d.ts +532 -0
  58. package/dist/shared-BdH3hWuP.d.ts +23 -0
  59. package/dist/shared-BqpFeosz.d.mts +23 -0
  60. package/package.json +51 -17
package/dist/index.d.mts CHANGED
@@ -1,335 +1,306 @@
1
- /**
2
- * Cross-chain DEX aggregation SDK core type definitions
3
- */
4
- interface TokenInfo {
5
- address: string;
6
- symbol: string;
7
- decimals: number;
8
- chain: string;
1
+ import { S as SwapQuoteRequestRaw, a as SwapQuoteDataRaw, b as SwapBuildRequestRaw, c as SwapBuildDataRaw, d as SwapOrderSubmitRequestRaw, e as SwapOrderSubmitDataRaw, f as SwapOrderStatusParamsRaw, g as SwapOrderStatusDataRaw, h as SwapReportRequestRaw, i as SwapReportDataRaw, j as SwapHistoryParamsRaw, k as SwapHistoryDataRaw, Q as QuoteRequest, l as Quote, m as SwapMcaPayloadRaw, W as WaitMode, n as SwapLifecycleEvent, o as SwapExecutionResult, C as ChainRef, A as AssetRef, B as BaseUnitAmount, p as SwapHistoryRecordRaw, q as ChainExecutor, E as ExecutorRegistry, r as SwapBuild, s as ExecuteSwapInput, t as SwapInput, O as OrderStatusResult, u as WaitForOrderInput, N as NearTransaction, v as SwapMcaRelayerRequestRaw } from './registry-DRYUqs7T.mjs';
2
+ export { a1 as BuildContext, J as ChainExecutionResult, Z as DepositInfo, U as EvmApproval, V as EvmSigningRequest, T as EvmTx, K as ExecutionContext, L as ExecutorIdentityProvider, P as ExecutorMessageSigner, M as MessageSignOptions, Y as OrderReference, H as OrderStatus, a0 as RouteSummary, G as SignRequestPreview, X as SolanaMetadata, w as SwapApiResponse, x as SwapApiTokenMetaRaw, D as SwapBuildApproveRaw, $ as SwapExecution, y as SwapMcaSignerPayloadRaw, _ as SwapReportContext, z as SwapSigningRequestRaw, F as SwapWarning, R as assertBaseUnitAmount, I as normalizeOrderStatus } from './registry-DRYUqs7T.mjs';
3
+
4
+ type SwapErrorCode = "HTTP_ERROR" | "API_ERROR" | "RATE_LIMITED" | "AUTH_FAILED" | "REQUEST_ABORTED" | "REQUEST_TIMEOUT" | "INVALID_REQUEST" | "INVALID_API_RESPONSE" | "QUOTE_EXPIRED" | "ROUTE_NOT_FOUND" | "EXECUTOR_NOT_FOUND" | "UNSUPPORTED_CHAIN" | "CHAIN_MISMATCH" | "INVALID_TRANSACTION" | "USER_REJECTED" | "INSUFFICIENT_BALANCE" | "APPROVAL_FAILED" | "SIGNING_FAILED" | "BROADCAST_FAILED" | "ORDER_SUBMIT_FAILED" | "ORDER_TIMEOUT" | "REPORT_FAILED";
5
+ type SwapErrorStage = "quote" | "build" | "approve" | "sign" | "broadcast" | "submit" | "report" | "status" | "history";
6
+ interface SwapSdkErrorOptions {
7
+ retryable?: boolean;
8
+ cause?: unknown;
9
+ details?: Record<string, unknown>;
9
10
  }
10
- interface Route {
11
- pools: PoolInfo[];
12
- amountIn: string;
13
- amountOut: string;
11
+ declare class SwapSdkError extends Error {
12
+ readonly code: SwapErrorCode;
13
+ readonly stage: SwapErrorStage;
14
+ readonly options: SwapSdkErrorOptions;
15
+ readonly name = "SwapSdkError";
16
+ constructor(code: SwapErrorCode, stage: SwapErrorStage, message: string, options?: SwapSdkErrorOptions);
17
+ get retryable(): boolean;
18
+ get cause(): unknown;
19
+ get details(): Record<string, unknown> | undefined;
14
20
  }
15
- interface PoolInfo {
16
- pool_id: number;
17
- token_in: string;
18
- token_out: string;
19
- amount_in?: string;
20
- amount_out?: string;
21
- fee?: number;
21
+ declare function asSwapSdkError(error: unknown, stage: SwapErrorStage): SwapSdkError;
22
+
23
+ type SdkLogLevel = "debug" | "warn";
24
+ interface SdkLogEntry {
25
+ level: SdkLogLevel;
26
+ event: "api.request" | "api.response" | "api.retry";
27
+ path: string;
28
+ stage: SwapErrorStage;
29
+ attempt: number;
30
+ status?: number;
31
+ durationMs?: number;
32
+ code?: SwapErrorCode;
22
33
  }
23
- interface QuoteParams {
24
- tokenIn: TokenInfo;
25
- tokenOut: TokenInfo;
26
- amountIn: string;
27
- /** Slippage tolerance in bps (e.g. 50 = 0.5%). */
28
- slippage: number;
29
- swapType?: "EXACT_INPUT" | "EXACT_OUTPUT";
30
- recipient?: string;
31
- /** Fallback account for SmartX user/receiveUser when recipient is absent. */
32
- refundTo?: string;
33
- /** Optional: Deposit address from intents. If provided, will be used for SmartX second call. */
34
- depositAddress?: string;
34
+ interface SdkLogger {
35
+ log(entry: SdkLogEntry): void;
35
36
  }
36
- interface QuoteResult {
37
- success: boolean;
38
- tokenIn: TokenInfo;
39
- tokenOut: TokenInfo;
40
- amountIn: string;
41
- amountOut: string;
42
- minAmountOut: string;
43
- routes: Route[];
44
- /**
45
- * Optional: Raw route data returned by chain router/aggregator
46
- * - Used for scenarios where aggregator-specific fields need to be passed through in executeSwap
47
- * - Kept optional to avoid tightly coupling implementation details into core logic
48
- */
49
- rawRoutes?: any[];
50
- /** Quote source identifier (used when multiple quote backends are supported). */
51
- quoteSource?: "findPath" | "smartx";
52
- /** SmartX quote payload (present when quoteSource === "smartx"). */
53
- smartxResult?: {
54
- amountIn: string;
55
- amountOut: string;
56
- minAmountOut: string;
57
- dexs?: string[];
58
- msg?: string;
59
- signature?: string;
60
- tokens?: string[];
61
- };
62
- priceImpact?: number;
63
- avgFee?: number;
64
- estimatedGas?: string;
65
- error?: string;
66
- /** Optional: Deposit address for cross-chain swaps (e.g., from Intents). Passed from quote to executeSwap. */
67
- depositAddress?: string;
37
+
38
+ interface ApiClientConfig {
39
+ baseUrl: string;
40
+ apiKey?: string;
41
+ getAccessToken?: () => string | Promise<string>;
42
+ fetch?: typeof globalThis.fetch;
43
+ headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
44
+ timeoutMs?: number;
45
+ retry?: Partial<RetryConfig>;
46
+ logger?: SdkLogger;
68
47
  }
69
- interface ExecuteParams {
70
- quote: QuoteResult;
71
- recipient: string;
72
- depositAddress?: string;
73
- deadline?: number;
48
+ interface ApiRequestOptions {
49
+ signal?: AbortSignal;
50
+ idempotencyKey?: string;
74
51
  }
75
- interface ExecuteResult {
76
- success: boolean;
77
- txHash?: string;
78
- txHashArray?: string[];
79
- error?: string;
52
+ interface RetryConfig {
53
+ maxRetries: number;
54
+ baseDelayMs: number;
55
+ maxDelayMs: number;
56
+ jitter: boolean;
80
57
  }
81
- type SupportedChain = "near" | "evm" | "solana";
82
- /**
83
- * DEX aggregator router abstract interface
84
- * Each chain/aggregator implements its own quote/executeSwap
85
- */
86
- interface DexRouter {
87
- /** Router's chain (near/evm/solana...) */
88
- getSupportedChain(): SupportedChain | string;
89
- quote(params: QuoteParams): Promise<QuoteResult>;
90
- executeSwap(params: ExecuteParams): Promise<ExecuteResult>;
58
+ declare class ApiClient {
59
+ private readonly config;
60
+ private readonly baseUrl;
61
+ private readonly fetchImpl;
62
+ constructor(config: ApiClientConfig);
63
+ quote(body: SwapQuoteRequestRaw, options?: ApiRequestOptions): Promise<SwapQuoteDataRaw>;
64
+ build(body: SwapBuildRequestRaw, options?: ApiRequestOptions): Promise<SwapBuildDataRaw>;
65
+ submitOrder(body: SwapOrderSubmitRequestRaw, options?: ApiRequestOptions): Promise<SwapOrderSubmitDataRaw>;
66
+ getOrderStatus(params: SwapOrderStatusParamsRaw, options?: ApiRequestOptions): Promise<SwapOrderStatusDataRaw>;
67
+ report(body: SwapReportRequestRaw, options?: ApiRequestOptions): Promise<SwapReportDataRaw>;
68
+ getHistory(params: SwapHistoryParamsRaw, options?: ApiRequestOptions): Promise<SwapHistoryDataRaw>;
69
+ private request;
70
+ private requestOnce;
71
+ private buildUrl;
72
+ private buildHeaders;
73
+ private retryConfig;
74
+ private retryDelay;
75
+ private log;
76
+ private parseResponse;
77
+ private isEnvelope;
78
+ private readMessage;
91
79
  }
92
- /**
93
- * Bluechip token configuration
94
- */
95
- interface BluechipTokenConfig {
96
- address: string;
97
- symbol: string;
98
- decimals: number;
99
- assetId?: string;
80
+
81
+ type McaFlow = "deposit" | "withdraw";
82
+ type McaSignerChain = "evm" | "solana" | "btc" | "near" | "aptos" | "sui" | "zcash" | "tron";
83
+ interface McaSignerIdentity {
84
+ chain: McaSignerChain;
85
+ identityKey: string;
86
+ accountId?: string;
100
87
  }
101
- /**
102
- * Bluechip tokens list configuration
103
- */
104
- interface BluechipTokensConfig {
105
- USDT?: BluechipTokenConfig;
106
- USDC?: BluechipTokenConfig;
107
- NEAR?: BluechipTokenConfig;
108
- [key: string]: BluechipTokenConfig | undefined;
88
+ interface McaDepositCollateral {
89
+ useAsCollateral: boolean;
109
90
  }
110
-
111
- /** FindPath API response. */
112
- interface FindPathResponse {
113
- result_code: number;
114
- result_msg?: string;
115
- result_message?: string;
116
- result_data: {
117
- routes: any[];
118
- amount_out: string;
119
- } | null;
91
+ interface McaWithdrawCollateral {
92
+ needDecrease: boolean;
93
+ decreaseAmountBurrow: string;
94
+ withdrawAll?: boolean;
120
95
  }
121
- /** Adapter for querying DEX routes (FindPath). */
122
- interface FindPathAdapter {
123
- findPath(params: {
124
- tokenIn: string;
125
- tokenOut: string;
126
- amountIn: string;
127
- slippage: number;
128
- supportLedger?: boolean;
129
- }): Promise<FindPathResponse>;
96
+ interface McaQuoteRequestBase extends QuoteRequest {
97
+ mcaAccountId: string;
98
+ signerChain: McaSignerChain;
99
+ recipientMsgSignatures?: string[];
100
+ depositSignerProofSignatures?: string[];
130
101
  }
131
- /** SmartX swapMultiDexPath response. */
132
- interface SwapMultiDexPathResponse {
133
- result_code: number;
134
- result_message?: string;
135
- result_data: {
136
- amount_in: string;
137
- amount_out: string;
138
- min_amount_out: string;
139
- dexs?: string[];
140
- msg?: string;
141
- signature?: string;
142
- tokens?: string[];
143
- [key: string]: any;
144
- } | null;
102
+ interface McaDepositQuoteRequest extends McaQuoteRequestBase {
103
+ flow: "deposit";
104
+ collateral: McaDepositCollateral;
145
105
  }
146
- /** Adapter for querying SmartX swapMultiDexPath. */
147
- interface SwapMultiDexPathAdapter {
148
- swapMultiDexPath(params: {
149
- amountIn: string;
150
- tokenIn: string;
151
- tokenOut: string;
152
- slippage: number;
153
- pathDeep: number;
154
- chainId: number;
155
- routerCount: number;
156
- skipUnwrapNativeToken: boolean;
157
- user: string;
158
- receiveUser: string;
159
- [key: string]: any;
160
- }): Promise<SwapMultiDexPathResponse>;
106
+ interface McaWithdrawQuoteRequest extends McaQuoteRequestBase {
107
+ flow: "withdraw";
108
+ collateral: McaWithdrawCollateral;
109
+ executionPreference?: "auto" | "near" | "relayer";
110
+ boundNearAccountId?: string;
161
111
  }
162
- /** NearIntents quote result. */
163
- interface IntentsQuoteResult {
164
- quoteStatus: "success" | "error";
165
- message?: string;
166
- quoteSuccessResult?: {
167
- quote: {
168
- amountOut: string;
169
- depositAddress: string;
170
- [key: string]: any;
171
- };
172
- [key: string]: any;
173
- };
174
- [key: string]: any;
112
+ type McaQuoteRequest = McaDepositQuoteRequest | McaWithdrawQuoteRequest;
113
+ interface McaQuoteBase extends Quote {
114
+ flow: McaFlow;
115
+ mcaAccountId: string;
116
+ signer: Readonly<McaSignerIdentity>;
117
+ request: McaQuoteRequest;
118
+ mca: Readonly<SwapMcaPayloadRaw>;
119
+ raw: SwapQuoteDataRaw;
175
120
  }
176
- /** Adapter for fetching NearIntents quotes. */
177
- interface IntentsQuotationAdapter {
178
- quote(params: {
179
- originAsset: string;
180
- destinationAsset: string;
181
- amount: string;
182
- refundTo: string;
183
- recipient: string;
184
- slippageTolerance: number;
185
- swapType?: "EXACT_INPUT" | "EXACT_OUTPUT" | "FLEX_INPUT";
186
- [key: string]: any;
187
- }): Promise<IntentsQuoteResult>;
121
+ interface McaDepositQuote extends McaQuoteBase {
122
+ flow: "deposit";
123
+ executionMode: "deposit";
124
+ request: McaDepositQuoteRequest;
125
+ nearDepositTx?: unknown;
188
126
  }
189
- /** Adapter for interacting with NEAR (call/view). */
190
- interface NearChainAdapter {
191
- call(params: {
192
- transactions: Array<{
193
- contractId: string;
194
- methodName: string;
195
- args: any;
196
- gas?: string;
197
- expandDeposit?: string;
198
- }>;
199
- }): Promise<{
200
- status: "success" | "error";
201
- txHash?: string;
202
- txHashArr?: string[];
203
- message?: string;
204
- }>;
205
- view(params: {
206
- contractId: string;
207
- methodName: string;
208
- args?: any;
209
- }): Promise<any>;
127
+ interface McaWithdrawNearQuote extends McaQuoteBase {
128
+ flow: "withdraw";
129
+ executionMode: "withdraw-near";
130
+ request: McaWithdrawQuoteRequest;
131
+ preview: Record<string, unknown>;
210
132
  }
211
- /** Chain-specific configuration provider. */
212
- interface ConfigAdapter {
213
- getRefExchangeId(): string;
214
- getWrapNearContractId(): string;
215
- getFindPathUrl(): string;
216
- /** Storage deposit amount (yoctoNEAR) for `storage_deposit` when needed. */
217
- getTokenStorageDepositRead?(): string;
218
- /** Aggregate DEX contract id for SmartX execution. */
219
- getAggregateDexContractId?(): string;
133
+ interface McaWithdrawRelayerQuote extends McaQuoteBase {
134
+ flow: "withdraw";
135
+ executionMode: "withdraw-relayer";
136
+ request: McaWithdrawQuoteRequest;
137
+ preview: Record<string, unknown>;
220
138
  }
139
+ type McaQuote = McaDepositQuote | McaWithdrawNearQuote | McaWithdrawRelayerQuote;
140
+ interface McaSwapInput {
141
+ quote: McaQuote;
142
+ waitFor?: WaitMode;
143
+ signal?: AbortSignal;
144
+ idempotencyKey?: string;
145
+ onEvent?: (event: SwapLifecycleEvent) => void;
146
+ beforeSign?: (preview: {
147
+ chain: McaSignerChain;
148
+ identityKey: string;
149
+ message: string;
150
+ business: Readonly<Record<string, unknown>>;
151
+ }) => void | Promise<void>;
152
+ }
153
+ type McaSwapResult = SwapExecutionResult;
221
154
 
222
- declare const logger: {
223
- debug: (...args: any[]) => void;
224
- info: (...args: any[]) => void;
225
- warn: (...args: any[]) => void;
226
- error: (...args: any[]) => void;
227
- };
228
-
229
- /** Set the SDK-wide bluechip token config used for NearIntents compatibility and intermediate routing. */
230
- declare function setBluechipTokensConfig(config: BluechipTokensConfig): void;
231
- /** Get the bluechip token config; returns an empty object (and warns) if unset. */
232
- declare function getBluechipTokensConfig(): BluechipTokensConfig;
233
- /**
234
- * Normalize a NEAR asset id:
235
- * - strip `nep141:` prefix (if present)
236
- * - map `near` -> `wrap.near` (overridable via `wrapNearContractId`)
237
- */
238
- declare function normalizeTokenId(tokenId: string | undefined | null, wrapNearContractId?: string): string;
239
- /** True if the token matches a NearIntents-supported bluechip token (by symbol + address/assetId). */
240
- declare function isNearIntentsSupportedToken(token: TokenInfo, bluechipTokens?: BluechipTokensConfig): boolean;
241
- /** Pick an intermediate bluechip token (priority: USDT > USDC > wNEAR; fallback to `wrapNearContractId`). */
242
- declare function findBestBluechipToken(bluechipTokens: BluechipTokensConfig, wrapNearContractId?: string): TokenInfo;
243
- /**
244
- * Convert slippage input into bps (1 bps = 0.01%).
245
- * - `>= 1`: bps (e.g. 50 = 0.5%)
246
- * - `[0.01, 1)`: percent (e.g. 0.5 = 0.5%)
247
- * - `(0, 0.01)`: decimal (e.g. 0.005 = 0.5%)
248
- */
249
- declare function convertSlippageToBasisPoints(slippage: number): number;
250
- /** Normalize NearIntents `destinationAsset` (prefix + `near` -> `wrap.near`). */
251
- declare function normalizeDestinationAsset(assetId: string, wrapNearContractId?: string): string;
155
+ type HistoryStatus = "pending" | "processing" | "completed" | "failed" | "refunded" | "expired" | "unknown";
156
+ interface HistoryRequest {
157
+ sender: string;
158
+ page?: number;
159
+ pageSize?: number;
160
+ status?: HistoryStatus[];
161
+ }
162
+ interface SwapHistoryPage {
163
+ items: SwapHistoryItem[];
164
+ page: number;
165
+ pageSize: number;
166
+ totalPages: number;
167
+ totalItems: number;
168
+ filteredLocally?: boolean;
169
+ }
170
+ interface SwapHistoryItem {
171
+ id: string;
172
+ sender: string;
173
+ recipient?: string;
174
+ fromChain: ChainRef;
175
+ toChain: ChainRef;
176
+ tokenIn: AssetRef;
177
+ tokenOut: AssetRef;
178
+ amountIn?: BaseUnitAmount;
179
+ estimatedOut?: BaseUnitAmount;
180
+ actualOut?: BaseUnitAmount;
181
+ sourceTxHash?: string;
182
+ destinationTxHash?: string;
183
+ orderId?: string;
184
+ depositAddress?: string;
185
+ router?: string;
186
+ status: HistoryStatus;
187
+ createdAt?: string;
188
+ updatedAt?: string;
189
+ statusResponse?: Record<string, unknown>;
190
+ raw: SwapHistoryRecordRaw;
191
+ }
252
192
 
253
- interface NearSmartRouterConfig {
254
- findPathAdapter: FindPathAdapter;
255
- swapMultiDexPathAdapter?: SwapMultiDexPathAdapter;
256
- nearChainAdapter: NearChainAdapter;
257
- configAdapter: ConfigAdapter;
258
- intentsQuotationAdapter?: IntentsQuotationAdapter;
193
+ interface SwapClientConfig extends ApiClientConfig {
194
+ maxQuoteAgeMs?: number | null;
195
+ reportMode?: "auto" | "manual" | "disabled";
196
+ executors?: readonly ChainExecutor[];
197
+ onEvent?: (event: SwapLifecycleEvent) => void;
198
+ now?: () => number;
259
199
  }
260
- declare class NearSmartRouter implements DexRouter {
261
- private findPathAdapter;
262
- private swapMultiDexPathAdapter?;
263
- private nearChainAdapter;
264
- private configAdapter;
265
- private intentsQuotationAdapter?;
266
- private wrapNearContractId;
267
- private refExchangeId;
268
- private tokenStorageDepositRead;
269
- private aggregateDexContractId?;
270
- constructor(config: NearSmartRouterConfig);
271
- /**
272
- * 核心报价逻辑:并行比价 -> 获取 Intent 地址 -> SmartX 二次修正
273
- */
274
- quote(params: QuoteParams): Promise<QuoteResult>;
275
- /**
276
- * 执行逻辑:基于 quote 准备好的数据进行分发
277
- */
278
- executeSwap(params: ExecuteParams): Promise<ExecuteResult>;
279
- private executeSmartX;
280
- private executeRef;
281
- private checkRegistration;
282
- private handleCallResult;
283
- getSupportedChain(): "near";
200
+ interface BuildSwapInput {
201
+ quote: Quote;
202
+ signal?: AbortSignal;
203
+ idempotencyKey?: string;
284
204
  }
205
+ declare class SwapClient {
206
+ private readonly managedSwapFlow;
207
+ protected readonly api: ApiClient;
208
+ protected readonly registry: ExecutorRegistry;
209
+ protected readonly reportMode: "auto" | "manual" | "disabled";
210
+ protected readonly config: SwapClientConfig;
211
+ private readonly now;
212
+ private readonly inFlight;
213
+ private readonly reportRequests;
214
+ constructor(config: SwapClientConfig);
215
+ quoteRaw(request: SwapQuoteRequestRaw, options?: ApiRequestOptions): Promise<SwapQuoteDataRaw>;
216
+ quote(request: McaQuoteRequest, options?: ApiRequestOptions): Promise<McaQuote>;
217
+ quote(request: QuoteRequest, options?: ApiRequestOptions): Promise<Quote>;
218
+ private quoteStandard;
219
+ buildRaw(request: SwapBuildRequestRaw, options?: ApiRequestOptions): Promise<SwapBuildDataRaw>;
220
+ buildSwap(input: BuildSwapInput): Promise<SwapBuild>;
221
+ private buildStandardSwap;
222
+ executeSwap(input: ExecuteSwapInput): Promise<SwapExecutionResult>;
223
+ swap(input: McaSwapInput): Promise<McaSwapResult>;
224
+ swap(input: SwapInput): Promise<SwapExecutionResult>;
225
+ getOrderStatus(input: {
226
+ orderId: string;
227
+ router: string;
228
+ chainId?: string;
229
+ signal?: AbortSignal;
230
+ }): Promise<OrderStatusResult>;
231
+ waitForOrder(input: WaitForOrderInput): Promise<OrderStatusResult>;
232
+ submitOrderRaw(request: Parameters<ApiClient["submitOrder"]>[0], options?: ApiRequestOptions): Promise<SwapOrderSubmitDataRaw>;
233
+ getOrderStatusRaw(request: Parameters<ApiClient["getOrderStatus"]>[0], options?: ApiRequestOptions): Promise<SwapOrderStatusDataRaw>;
234
+ reportRaw(request: SwapReportRequestRaw, options?: ApiRequestOptions): Promise<SwapReportDataRaw>;
235
+ report(result: SwapExecutionResult): Promise<SwapReportDataRaw>;
236
+ retryReport(result: SwapExecutionResult): Promise<SwapReportDataRaw>;
237
+ getHistoryRaw(params: SwapHistoryParamsRaw, options?: ApiRequestOptions): Promise<SwapHistoryDataRaw>;
238
+ getHistory(request: HistoryRequest, options?: ApiRequestOptions): Promise<SwapHistoryPage>;
239
+ protected emit(event: SwapLifecycleEvent): void;
240
+ private assertQuoteFresh;
241
+ private createReportRequest;
242
+ }
243
+
244
+ declare function normalizeBuild(raw: SwapBuildDataRaw, executionId?: string, request?: SwapBuildRequestRaw): SwapBuild;
245
+ declare function createExecutionId(): string;
246
+
247
+ declare function toApiChain(chain: ChainRef): string;
248
+ declare function fromApiChain(chain: string): ChainRef;
249
+ declare function toApiAssetAddress(asset: AssetRef): string;
250
+
251
+ declare function normalizeHistory(raw: SwapHistoryDataRaw): SwapHistoryPage;
252
+ declare function normalizeHistoryStatus(status: unknown): HistoryStatus;
285
253
 
286
- /** Composite quote: optional NEAR DEX pre-swap + NearIntents quote. */
254
+ declare function serializeQuoteRequest(request: QuoteRequest): SwapQuoteRequestRaw;
255
+ declare function normalizeQuote(request: QuoteRequest, raw: SwapQuoteDataRaw, receivedAt?: number): Quote;
287
256
 
288
- interface CompleteQuoteParams {
289
- sourceToken: TokenInfo;
290
- targetToken: TokenInfo;
291
- sourceChain: string;
292
- targetChain: string;
257
+ interface ResolveMcaWithdrawPolicyInput {
258
+ collateralBalance: string;
259
+ availableBalance: string;
293
260
  amountIn: string;
294
- slippage: number;
295
- recipient: string;
296
- refundTo?: string;
297
- /** Optional: Deposit address from intents. If provided, will be passed to dexRouter.quote() for SmartX second call. */
298
- depositAddress?: string;
261
+ isMax: boolean;
299
262
  }
300
- interface CompleteQuoteResult {
301
- intents: {
302
- /** Raw NearIntents response (passed through). */
303
- quote: any;
304
- depositAddress: string;
305
- };
306
- preSwap?: {
307
- quote: QuoteResult;
308
- tokenIn: TokenInfo;
309
- tokenOut: TokenInfo;
310
- executor: DexRouter;
311
- };
312
- finalAmountOut: string;
313
- totalPriceImpact?: number;
314
- totalFee?: number;
263
+ declare function resolveMcaWithdrawPolicy(input: ResolveMcaWithdrawPolicyInput): McaWithdrawCollateral & {
264
+ withdrawAll: boolean;
265
+ };
266
+
267
+ declare function serializeMcaQuoteRequest(request: McaQuoteRequest, signer: McaSignerIdentity): SwapQuoteRequestRaw;
268
+ declare function normalizeMcaQuote(request: McaQuoteRequest, signer: McaSignerIdentity, quote: Quote): McaQuote;
269
+
270
+ type McaWalletKey = "EVM" | "Solana" | "Bitcoin" | "Near" | "Aptos" | "Sui" | "Zcash" | "Tron";
271
+ type McaWalletDescriptor = Partial<Record<McaWalletKey, string>>;
272
+ declare const DEFAULT_MCA_SIGNER_PRIORITY: readonly ["evm", "solana", "btc", "aptos", "near", "zcash", "sui", "tron"];
273
+ declare function formatMcaWallet(chain: McaSignerChain, identityKey: string): McaWalletDescriptor;
274
+ declare function selectMcaSigner(boundWallets: ReadonlyArray<Readonly<Record<string, unknown>>>, connectedSigners: readonly McaSignerIdentity[], priority?: readonly McaSignerChain[]): McaSignerIdentity | undefined;
275
+ declare function isSameMcaSignerIdentity(a: Pick<McaSignerIdentity, "chain" | "identityKey">, b: Pick<McaSignerIdentity, "chain" | "identityKey">): boolean;
276
+
277
+ declare function extractMcaWithdrawBusiness(preview: unknown): Record<string, unknown> | undefined;
278
+ declare function extractMcaWithdrawSignerWallet(preview: unknown): Record<string, unknown> | undefined;
279
+ interface ExtractMcaWithdrawDepositAddressInput {
280
+ bestQuote?: unknown;
281
+ preview?: unknown;
282
+ snapshotDepositAddress?: string | null;
283
+ storeDepositAddress?: string | null;
284
+ }
285
+ declare function extractMcaWithdrawDepositAddress(input: ExtractMcaWithdrawDepositAddressInput): string;
286
+ interface BuildNearMcaWithdrawTransactionsInput {
287
+ business: Record<string, unknown>;
288
+ signerWallet: Record<string, unknown>;
289
+ signature?: string;
290
+ mcaAccountId: string;
315
291
  }
316
- interface CompleteQuoteConfig {
317
- intentsQuotationAdapter: IntentsQuotationAdapter;
318
- dexRouter: DexRouter;
319
- bluechipTokens: BluechipTokensConfig;
320
- configAdapter: {
321
- getWrapNearContractId(): string;
322
- };
292
+ declare function buildNearMcaWithdrawTransactions(preview: unknown, input: BuildNearMcaWithdrawTransactionsInput): NearTransaction[];
293
+ interface BuildMcaWithdrawRelayerRequestInput {
294
+ quoteBuild: SwapBuildRequestRaw;
295
+ mcaRelayer: SwapMcaRelayerRequestRaw;
296
+ isCrossChain: boolean;
297
+ depositAddress: string;
298
+ mcaAccountId: string;
299
+ recipientFallback?: string | null;
323
300
  }
324
- /**
325
- * Build a "complete quote":
326
- * - If `sourceToken` is not NearIntents-supported, pre-swap to a bluechip token on NEAR DEX.
327
- * - Quote NearIntents using (pre-swap output) or `amountIn`.
328
- *
329
- * Notes:
330
- * - Prefer `slippage` in bps (e.g. 50 = 0.5%); we also accept percent/decimal inputs.
331
- * - `targetChain` is currently reserved for future use.
332
- */
333
- declare function completeQuote(params: CompleteQuoteParams, config: CompleteQuoteConfig): Promise<CompleteQuoteResult>;
301
+ declare function buildMcaWithdrawRelayerRequest(input: BuildMcaWithdrawRelayerRequestInput): SwapBuildRequestRaw;
302
+
303
+ declare function parseUnits(value: string, decimals: number): BaseUnitAmount;
304
+ declare function formatUnits(value: BaseUnitAmount, decimals: number): string;
334
305
 
335
- export { 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 Route, type SupportedChain, type SwapMultiDexPathAdapter, type SwapMultiDexPathResponse, type TokenInfo, completeQuote, convertSlippageToBasisPoints, findBestBluechipToken, getBluechipTokensConfig, isNearIntentsSupportedToken, logger, normalizeDestinationAsset, normalizeTokenId, setBluechipTokensConfig };
306
+ export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaWithdrawPolicyInput, type RetryConfig, type SdkLogEntry, type SdkLogLevel, type SdkLogger, SwapBuild, SwapBuildDataRaw, SwapBuildRequestRaw, SwapClient, type SwapClientConfig, type SwapErrorCode, type SwapErrorStage, SwapExecutionResult, SwapHistoryDataRaw, type SwapHistoryItem, type SwapHistoryPage, SwapHistoryParamsRaw, SwapHistoryRecordRaw, SwapInput, SwapLifecycleEvent, SwapMcaPayloadRaw, SwapMcaRelayerRequestRaw, SwapOrderStatusDataRaw, SwapOrderStatusParamsRaw, SwapOrderSubmitDataRaw, SwapOrderSubmitRequestRaw, SwapQuoteDataRaw, SwapQuoteRequestRaw, SwapReportDataRaw, SwapReportRequestRaw, SwapSdkError, type SwapSdkErrorOptions, WaitForOrderInput, WaitMode, asSwapSdkError, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeQuote, parseUnits, resolveMcaWithdrawPolicy, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, toApiAssetAddress, toApiChain };