@rhea-finance/cross-chain-aggregation-dex 1.0.6 → 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 +278 -250
  51. package/dist/index.d.ts +278 -250
  52. package/dist/index.js +2369 -573
  53. package/dist/index.js.map +1 -1
  54. package/dist/index.mjs +2340 -560
  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.ts CHANGED
@@ -1,278 +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.js';
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.js';
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;
34
+ interface SdkLogger {
35
+ log(entry: SdkLogEntry): void;
31
36
  }
32
- interface QuoteResult {
33
- success: boolean;
34
- tokenIn: TokenInfo;
35
- tokenOut: TokenInfo;
36
- amountIn: string;
37
- amountOut: string;
38
- minAmountOut: string;
39
- routes: Route[];
40
- /**
41
- * Optional: Raw route data returned by chain router/aggregator
42
- * - Used for scenarios where aggregator-specific fields need to be passed through in executeSwap
43
- * - Kept optional to avoid tightly coupling implementation details into core logic
44
- */
45
- rawRoutes?: any[];
46
- priceImpact?: number;
47
- avgFee?: number;
48
- estimatedGas?: string;
49
- error?: 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;
50
47
  }
51
- interface ExecuteParams {
52
- quote: QuoteResult;
53
- recipient: string;
54
- depositAddress?: string;
55
- deadline?: number;
48
+ interface ApiRequestOptions {
49
+ signal?: AbortSignal;
50
+ idempotencyKey?: string;
51
+ }
52
+ interface RetryConfig {
53
+ maxRetries: number;
54
+ baseDelayMs: number;
55
+ maxDelayMs: number;
56
+ jitter: boolean;
57
+ }
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;
79
+ }
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;
87
+ }
88
+ interface McaDepositCollateral {
89
+ useAsCollateral: boolean;
90
+ }
91
+ interface McaWithdrawCollateral {
92
+ needDecrease: boolean;
93
+ decreaseAmountBurrow: string;
94
+ withdrawAll?: boolean;
95
+ }
96
+ interface McaQuoteRequestBase extends QuoteRequest {
97
+ mcaAccountId: string;
98
+ signerChain: McaSignerChain;
99
+ recipientMsgSignatures?: string[];
100
+ depositSignerProofSignatures?: string[];
56
101
  }
57
- interface ExecuteResult {
58
- success: boolean;
59
- txHash?: string;
60
- txHashArray?: string[];
61
- error?: string;
102
+ interface McaDepositQuoteRequest extends McaQuoteRequestBase {
103
+ flow: "deposit";
104
+ collateral: McaDepositCollateral;
62
105
  }
63
- type SupportedChain = "near" | "evm" | "solana";
64
- /**
65
- * DEX aggregator router abstract interface
66
- * Each chain/aggregator implements its own quote/executeSwap
67
- */
68
- interface DexRouter {
69
- /** Router's chain (near/evm/solana...) */
70
- getSupportedChain(): SupportedChain | string;
71
- quote(params: QuoteParams): Promise<QuoteResult>;
72
- executeSwap(params: ExecuteParams): Promise<ExecuteResult>;
106
+ interface McaWithdrawQuoteRequest extends McaQuoteRequestBase {
107
+ flow: "withdraw";
108
+ collateral: McaWithdrawCollateral;
109
+ executionPreference?: "auto" | "near" | "relayer";
110
+ boundNearAccountId?: string;
73
111
  }
74
- /**
75
- * Bluechip token configuration
76
- */
77
- interface BluechipTokenConfig {
78
- address: string;
79
- symbol: string;
80
- decimals: number;
81
- assetId?: string;
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;
82
120
  }
83
- /**
84
- * Bluechip tokens list configuration
85
- */
86
- interface BluechipTokensConfig {
87
- USDT?: BluechipTokenConfig;
88
- USDC?: BluechipTokenConfig;
89
- NEAR?: BluechipTokenConfig;
90
- [key: string]: BluechipTokenConfig | undefined;
121
+ interface McaDepositQuote extends McaQuoteBase {
122
+ flow: "deposit";
123
+ executionMode: "deposit";
124
+ request: McaDepositQuoteRequest;
125
+ nearDepositTx?: unknown;
91
126
  }
127
+ interface McaWithdrawNearQuote extends McaQuoteBase {
128
+ flow: "withdraw";
129
+ executionMode: "withdraw-near";
130
+ request: McaWithdrawQuoteRequest;
131
+ preview: Record<string, unknown>;
132
+ }
133
+ interface McaWithdrawRelayerQuote extends McaQuoteBase {
134
+ flow: "withdraw";
135
+ executionMode: "withdraw-relayer";
136
+ request: McaWithdrawQuoteRequest;
137
+ preview: Record<string, unknown>;
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;
92
154
 
93
- /** FindPath API response. */
94
- interface FindPathResponse {
95
- result_code: number;
96
- result_msg?: string;
97
- result_message?: string;
98
- result_data: {
99
- routes: any[];
100
- amount_out: string;
101
- } | null;
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[];
102
161
  }
103
- /** Adapter for querying DEX routes (FindPath). */
104
- interface FindPathAdapter {
105
- findPath(params: {
106
- tokenIn: string;
107
- tokenOut: string;
108
- amountIn: string;
109
- slippage: number;
110
- supportLedger?: boolean;
111
- }): Promise<FindPathResponse>;
162
+ interface SwapHistoryPage {
163
+ items: SwapHistoryItem[];
164
+ page: number;
165
+ pageSize: number;
166
+ totalPages: number;
167
+ totalItems: number;
168
+ filteredLocally?: boolean;
112
169
  }
113
- /** NearIntents quote result. */
114
- interface IntentsQuoteResult {
115
- quoteStatus: "success" | "error";
116
- message?: string;
117
- quoteSuccessResult?: {
118
- quote: {
119
- amountOut: string;
120
- depositAddress: string;
121
- [key: string]: any;
122
- };
123
- [key: string]: any;
124
- };
125
- [key: string]: any;
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;
126
191
  }
127
- /** Adapter for fetching NearIntents quotes. */
128
- interface IntentsQuotationAdapter {
129
- quote(params: {
130
- originAsset: string;
131
- destinationAsset: string;
132
- amount: string;
133
- refundTo: string;
134
- recipient: string;
135
- slippageTolerance: number;
136
- swapType?: "EXACT_INPUT" | "EXACT_OUTPUT" | "FLEX_INPUT";
137
- [key: string]: any;
138
- }): Promise<IntentsQuoteResult>;
192
+
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;
139
199
  }
140
- /** Adapter for interacting with NEAR (call/view). */
141
- interface NearChainAdapter {
142
- call(params: {
143
- transactions: Array<{
144
- contractId: string;
145
- methodName: string;
146
- args: any;
147
- gas?: string;
148
- expandDeposit?: string;
149
- }>;
150
- }): Promise<{
151
- status: "success" | "error";
152
- txHash?: string;
153
- txHashArr?: string[];
154
- message?: string;
155
- }>;
156
- view(params: {
157
- contractId: string;
158
- methodName: string;
159
- args?: any;
160
- }): Promise<any>;
200
+ interface BuildSwapInput {
201
+ quote: Quote;
202
+ signal?: AbortSignal;
203
+ idempotencyKey?: string;
161
204
  }
162
- /** Chain-specific configuration provider. */
163
- interface ConfigAdapter {
164
- getRefExchangeId(): string;
165
- getWrapNearContractId(): string;
166
- getFindPathUrl(): string;
167
- /** Storage deposit amount (yoctoNEAR) for `storage_deposit` when needed. */
168
- getTokenStorageDepositRead?(): string;
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;
169
242
  }
170
243
 
171
- declare const logger: {
172
- debug: (...args: any[]) => void;
173
- info: (...args: any[]) => void;
174
- warn: (...args: any[]) => void;
175
- error: (...args: any[]) => void;
176
- };
244
+ declare function normalizeBuild(raw: SwapBuildDataRaw, executionId?: string, request?: SwapBuildRequestRaw): SwapBuild;
245
+ declare function createExecutionId(): string;
177
246
 
178
- /** Set the SDK-wide bluechip token config used for NearIntents compatibility and intermediate routing. */
179
- declare function setBluechipTokensConfig(config: BluechipTokensConfig): void;
180
- /** Get the bluechip token config; returns an empty object (and warns) if unset. */
181
- declare function getBluechipTokensConfig(): BluechipTokensConfig;
182
- /**
183
- * Normalize a NEAR asset id:
184
- * - strip `nep141:` prefix (if present)
185
- * - map `near` -> `wrap.near` (overridable via `wrapNearContractId`)
186
- */
187
- declare function normalizeTokenId(tokenId: string | undefined | null, wrapNearContractId?: string): string;
188
- /** True if the token matches a NearIntents-supported bluechip token (by symbol + address/assetId). */
189
- declare function isNearIntentsSupportedToken(token: TokenInfo, bluechipTokens?: BluechipTokensConfig): boolean;
190
- /** Pick an intermediate bluechip token (priority: USDT > USDC > wNEAR; fallback to `wrapNearContractId`). */
191
- declare function findBestBluechipToken(bluechipTokens: BluechipTokensConfig, wrapNearContractId?: string): TokenInfo;
192
- /**
193
- * Convert slippage input into bps (1 bps = 0.01%).
194
- * - `>= 1`: bps (e.g. 50 = 0.5%)
195
- * - `[0.01, 1)`: percent (e.g. 0.5 = 0.5%)
196
- * - `(0, 0.01)`: decimal (e.g. 0.005 = 0.5%)
197
- */
198
- declare function convertSlippageToBasisPoints(slippage: number): number;
199
- /** Normalize NearIntents `destinationAsset` (prefix + `near` -> `wrap.near`). */
200
- declare function normalizeDestinationAsset(assetId: string, wrapNearContractId?: string): string;
247
+ declare function toApiChain(chain: ChainRef): string;
248
+ declare function fromApiChain(chain: string): ChainRef;
249
+ declare function toApiAssetAddress(asset: AssetRef): string;
201
250
 
202
- /** NEAR DEX router implementation (FindPath for routing + REF for execution). */
251
+ declare function normalizeHistory(raw: SwapHistoryDataRaw): SwapHistoryPage;
252
+ declare function normalizeHistoryStatus(status: unknown): HistoryStatus;
203
253
 
204
- interface NearSmartRouterConfig {
205
- findPathAdapter: FindPathAdapter;
206
- nearChainAdapter: NearChainAdapter;
207
- configAdapter: ConfigAdapter;
208
- }
209
- declare class NearSmartRouter implements DexRouter {
210
- private findPathAdapter;
211
- private nearChainAdapter;
212
- private configAdapter;
213
- private wrapNearContractId;
214
- private refExchangeId;
215
- private tokenStorageDepositRead;
216
- constructor(config: NearSmartRouterConfig);
217
- /**
218
- * Get a swap quote (normalizes token ids and queries FindPath for routes).
219
- */
220
- quote(params: QuoteParams): Promise<QuoteResult>;
221
- /**
222
- * Execute a swap: optionally adds `storage_deposit` for the recipient, then calls REF via `ft_transfer_call`.
223
- */
224
- executeSwap(params: ExecuteParams): Promise<ExecuteResult>;
225
- /**
226
- * Get supported chain
227
- */
228
- getSupportedChain(): "near";
254
+ declare function serializeQuoteRequest(request: QuoteRequest): SwapQuoteRequestRaw;
255
+ declare function normalizeQuote(request: QuoteRequest, raw: SwapQuoteDataRaw, receivedAt?: number): Quote;
256
+
257
+ interface ResolveMcaWithdrawPolicyInput {
258
+ collateralBalance: string;
259
+ availableBalance: string;
260
+ amountIn: string;
261
+ isMax: boolean;
229
262
  }
263
+ declare function resolveMcaWithdrawPolicy(input: ResolveMcaWithdrawPolicyInput): McaWithdrawCollateral & {
264
+ withdrawAll: boolean;
265
+ };
230
266
 
231
- /** Composite quote: optional NEAR DEX pre-swap + NearIntents quote. */
267
+ declare function serializeMcaQuoteRequest(request: McaQuoteRequest, signer: McaSignerIdentity): SwapQuoteRequestRaw;
268
+ declare function normalizeMcaQuote(request: McaQuoteRequest, signer: McaSignerIdentity, quote: Quote): McaQuote;
232
269
 
233
- interface CompleteQuoteParams {
234
- sourceToken: TokenInfo;
235
- targetToken: TokenInfo;
236
- sourceChain: string;
237
- targetChain: string;
238
- amountIn: string;
239
- slippage: number;
240
- recipient: string;
241
- refundTo?: string;
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;
242
284
  }
243
- interface CompleteQuoteResult {
244
- intents: {
245
- /** Raw NearIntents response (passed through). */
246
- quote: any;
247
- depositAddress: string;
248
- };
249
- preSwap?: {
250
- quote: QuoteResult;
251
- tokenIn: TokenInfo;
252
- tokenOut: TokenInfo;
253
- executor: DexRouter;
254
- };
255
- finalAmountOut: string;
256
- totalPriceImpact?: number;
257
- totalFee?: number;
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;
258
291
  }
259
- interface CompleteQuoteConfig {
260
- intentsQuotationAdapter: IntentsQuotationAdapter;
261
- dexRouter: DexRouter;
262
- bluechipTokens: BluechipTokensConfig;
263
- configAdapter: {
264
- getWrapNearContractId(): string;
265
- };
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;
266
300
  }
267
- /**
268
- * Build a "complete quote":
269
- * - If `sourceToken` is not NearIntents-supported, pre-swap to a bluechip token on NEAR DEX.
270
- * - Quote NearIntents using (pre-swap output) or `amountIn`.
271
- *
272
- * Notes:
273
- * - Prefer `slippage` in bps (e.g. 50 = 0.5%); we also accept percent/decimal inputs.
274
- * - `targetChain` is currently reserved for future use.
275
- */
276
- 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;
277
305
 
278
- 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 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 };