@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
@@ -0,0 +1,532 @@
1
+ interface SwapApiResponse<T> {
2
+ code: number;
3
+ msg: string;
4
+ data: T;
5
+ }
6
+ interface SwapApiTokenMetaRaw {
7
+ address: string;
8
+ symbol: string;
9
+ decimals: number;
10
+ }
11
+ interface SwapMcaSignerPayloadRaw {
12
+ chain: string;
13
+ identityKey: string;
14
+ }
15
+ interface SwapMcaPayloadRaw {
16
+ flow?: "deposit" | "withdraw";
17
+ mcaFlow?: "deposit" | "withdraw";
18
+ mcaAccountId?: string;
19
+ mca_id?: string;
20
+ signer?: SwapMcaSignerPayloadRaw;
21
+ depositSigner?: SwapMcaSignerPayloadRaw;
22
+ amountBurrow?: string;
23
+ amount_with_inner_decimal?: string;
24
+ amount_burrow?: string;
25
+ recipientMsgSignatures?: string[];
26
+ depositSignerProofSignatures?: string[];
27
+ useAsCollateral?: boolean;
28
+ needDecreaseCollateral?: boolean;
29
+ decreaseCollateralAmountBurrow?: string;
30
+ withdrawAll?: boolean;
31
+ [key: string]: unknown;
32
+ }
33
+ interface SwapMcaRelayerRequestRaw {
34
+ mcaAccountId?: string;
35
+ mca_id?: string;
36
+ wallet: string | Record<string, unknown>;
37
+ business: Record<string, unknown>;
38
+ signature: string;
39
+ [key: string]: unknown;
40
+ }
41
+ interface SwapQuoteRequestRaw {
42
+ fromChain: string;
43
+ toChain: string;
44
+ tokenIn: string;
45
+ tokenOut: string;
46
+ amountIn: string;
47
+ slippage?: number;
48
+ quoteWaitingTimeMs?: number;
49
+ sender: string;
50
+ recipient?: string;
51
+ useAsCollateral?: boolean;
52
+ mca?: SwapMcaPayloadRaw;
53
+ }
54
+ interface SwapQuoteDataRaw {
55
+ isCrossChain: boolean;
56
+ chainType: string;
57
+ bestQuote: Record<string, unknown>;
58
+ allQuotes: Record<string, unknown>[];
59
+ errors?: unknown;
60
+ nearDepositTx?: unknown;
61
+ nearDepositTxError?: string;
62
+ nearMcaWithdrawTx?: unknown;
63
+ nearMcaWithdrawTxError?: string;
64
+ nearMcaWithdraw?: Record<string, unknown>;
65
+ mcaContext?: Record<string, unknown>;
66
+ mcaWithdrawToIntents?: unknown;
67
+ [key: string]: unknown;
68
+ }
69
+ interface SwapBuildRequestRaw extends SwapQuoteRequestRaw {
70
+ router: string;
71
+ market?: string;
72
+ expectedOut: string;
73
+ minAmountOut: string;
74
+ preSwap: unknown | null;
75
+ bridge: unknown | null;
76
+ nearMcaWithdrawTx?: unknown;
77
+ mcaRelayer?: SwapMcaRelayerRequestRaw;
78
+ deposit_address?: string;
79
+ is_cross_chain?: boolean;
80
+ tx_type?: string;
81
+ multi_addr?: string;
82
+ quoteId?: string;
83
+ [key: string]: unknown;
84
+ }
85
+ interface SwapSigningRequestRaw {
86
+ type: string;
87
+ router: string;
88
+ quoteId: string;
89
+ chainId: number;
90
+ signingScheme?: string;
91
+ typedData: {
92
+ domain: Record<string, unknown>;
93
+ types: Record<string, Array<{
94
+ name: string;
95
+ type: string;
96
+ }>>;
97
+ primaryType: string;
98
+ message: Record<string, unknown>;
99
+ };
100
+ submit?: {
101
+ endpoint: string;
102
+ method: string;
103
+ params: Record<string, string>;
104
+ };
105
+ }
106
+ interface SwapBuildApproveRaw {
107
+ tx: Record<string, unknown>;
108
+ spender: string;
109
+ }
110
+ interface SwapBuildDataRaw {
111
+ isCrossChain: boolean;
112
+ chainType: string;
113
+ router: string;
114
+ fromChain: string;
115
+ toChain: string;
116
+ tokenIn: SwapApiTokenMetaRaw;
117
+ tokenOut: SwapApiTokenMetaRaw;
118
+ amountIn: string;
119
+ estimatedOut: string;
120
+ minAmountOut: string;
121
+ executionType?: "transaction" | "signature";
122
+ signingRequest?: SwapSigningRequestRaw | null;
123
+ needsApprove?: boolean;
124
+ tx: unknown;
125
+ approve: SwapBuildApproveRaw | null;
126
+ orderId?: string;
127
+ statusRouter?: string;
128
+ deposit?: Record<string, unknown>;
129
+ [key: string]: unknown;
130
+ }
131
+ interface SwapOrderSubmitRequestRaw {
132
+ router: string;
133
+ quoteId: string;
134
+ signature: string;
135
+ signingScheme?: string;
136
+ }
137
+ interface SwapOrderSubmitDataRaw {
138
+ router: string;
139
+ orderId: string;
140
+ chainId?: number;
141
+ raw?: Record<string, unknown>;
142
+ }
143
+ interface SwapOrderStatusParamsRaw {
144
+ orderId: string;
145
+ router: string;
146
+ chainId?: string | number;
147
+ }
148
+ type SwapOrderStatusDataRaw = Record<string, unknown> & {
149
+ status?: string;
150
+ state?: string;
151
+ };
152
+ interface SwapReportRequestRaw {
153
+ sender: string;
154
+ recipient: string;
155
+ from_hash: string;
156
+ from_token: string;
157
+ to_token: string;
158
+ deposit_address: string;
159
+ from_chain?: string;
160
+ to_chain?: string;
161
+ is_cross_chain?: boolean;
162
+ amount_in?: string;
163
+ estimated_out?: string;
164
+ router?: string;
165
+ tx_type?: string;
166
+ multi_addr?: string;
167
+ swap_id?: string;
168
+ swapId?: string;
169
+ extra?: Record<string, unknown>;
170
+ }
171
+ interface SwapReportDataRaw {
172
+ id: number;
173
+ from_hash: string;
174
+ }
175
+ interface SwapHistoryParamsRaw {
176
+ sender: string;
177
+ pageNumber?: number;
178
+ pageSize?: number;
179
+ }
180
+ interface SwapHistoryRecordRaw {
181
+ id: number;
182
+ sender: string;
183
+ recipient?: unknown;
184
+ from_hash: string;
185
+ to_hash?: string | null;
186
+ deposit_address?: string;
187
+ from_token: string;
188
+ to_token: string;
189
+ from_chain: string;
190
+ to_chain: string;
191
+ amount_in?: string;
192
+ estimated_out?: string;
193
+ actual_out?: string | null;
194
+ router?: string;
195
+ tx_type?: string;
196
+ is_cross_chain?: number;
197
+ status?: string;
198
+ multi_addr?: string | null;
199
+ swap_id?: string | null;
200
+ extra?: Record<string, unknown>;
201
+ status_response?: Record<string, unknown>;
202
+ created_at?: string;
203
+ updated_at?: string;
204
+ [key: string]: unknown;
205
+ }
206
+ interface SwapHistoryDataRaw {
207
+ record_list: SwapHistoryRecordRaw[];
208
+ page_number: number;
209
+ page_size: number;
210
+ total_page: number;
211
+ total_size: number;
212
+ }
213
+
214
+ type ChainRef = `${number}` | "solana" | "aptos" | "near" | "tron" | "btc" | "zcash" | "sui";
215
+ type BaseUnitAmount = string;
216
+ interface AssetRef {
217
+ chain: ChainRef;
218
+ address: string;
219
+ symbol?: string;
220
+ decimals?: number;
221
+ isNative?: boolean;
222
+ }
223
+ declare function assertBaseUnitAmount(value: string): BaseUnitAmount;
224
+
225
+ interface EvmTx {
226
+ to: string;
227
+ data: string;
228
+ value: BaseUnitAmount;
229
+ gasLimit: BaseUnitAmount;
230
+ chainId: number;
231
+ }
232
+ interface EvmApproval {
233
+ tx: EvmTx;
234
+ spender: string;
235
+ }
236
+ type EvmSigningRequest = SwapSigningRequestRaw;
237
+ interface SolanaMetadata {
238
+ addressLookupTableAddresses?: string[];
239
+ recentBlockhash?: string;
240
+ txValidUntil?: number;
241
+ transactionSize?: number;
242
+ }
243
+ interface NearTransaction {
244
+ signerId?: string;
245
+ receiverId: string;
246
+ actions: unknown[];
247
+ }
248
+ interface OrderReference {
249
+ orderId: string;
250
+ router: string;
251
+ chainId?: string;
252
+ }
253
+ interface DepositInfo {
254
+ depositAddress: string;
255
+ depositMemo?: string;
256
+ orderId?: string;
257
+ estimatedOut?: BaseUnitAmount;
258
+ minAmountOut?: BaseUnitAmount;
259
+ timeEstimate?: number | string;
260
+ }
261
+ interface SwapReportContext {
262
+ sender?: string;
263
+ recipient?: string;
264
+ fromHash?: string;
265
+ depositAddress?: string;
266
+ isCrossChain?: boolean;
267
+ txType?: string;
268
+ multiAddr?: string;
269
+ swapId?: string;
270
+ }
271
+ type SwapExecution = {
272
+ kind: "evm-transaction";
273
+ chain: ChainRef;
274
+ tx: EvmTx;
275
+ approval?: EvmApproval;
276
+ } | {
277
+ kind: "evm-signature";
278
+ chain: ChainRef;
279
+ request: EvmSigningRequest;
280
+ approval?: EvmApproval;
281
+ } | {
282
+ kind: "solana-transaction";
283
+ chain: ChainRef;
284
+ transaction: string;
285
+ format: string;
286
+ metadata?: SolanaMetadata;
287
+ } | {
288
+ kind: "aptos-entry-function";
289
+ chain: ChainRef;
290
+ function: string;
291
+ typeArguments: string[];
292
+ functionArguments: unknown[];
293
+ } | {
294
+ kind: "near-transaction-batch";
295
+ chain: ChainRef;
296
+ transactions: NearTransaction[];
297
+ } | {
298
+ kind: "tron-transfer";
299
+ chain: ChainRef;
300
+ amount: BaseUnitAmount;
301
+ depositAddress: string;
302
+ tokenAddress?: string;
303
+ standard?: string;
304
+ } | {
305
+ kind: "bitcoin-transfer";
306
+ chain: ChainRef;
307
+ amount: BaseUnitAmount;
308
+ depositAddress: string;
309
+ feeRate?: number;
310
+ } | {
311
+ kind: "zcash-transfer";
312
+ chain: ChainRef;
313
+ amount: BaseUnitAmount;
314
+ depositAddress: string;
315
+ decimals?: number;
316
+ } | {
317
+ kind: "sui-transfer";
318
+ chain: ChainRef;
319
+ amount: BaseUnitAmount;
320
+ depositAddress: string;
321
+ coinType: string;
322
+ };
323
+ interface SwapBuild {
324
+ executionId: string;
325
+ quoteId?: string;
326
+ isCrossChain: boolean;
327
+ fromChain: ChainRef;
328
+ toChain: ChainRef;
329
+ tokenIn: AssetRef;
330
+ tokenOut: AssetRef;
331
+ amountIn: BaseUnitAmount;
332
+ estimatedOut: BaseUnitAmount;
333
+ minAmountOut: BaseUnitAmount;
334
+ router: string;
335
+ execution: SwapExecution;
336
+ order?: OrderReference;
337
+ deposit?: DepositInfo;
338
+ reportContext?: SwapReportContext;
339
+ request?: SwapBuildRequestRaw;
340
+ raw: SwapBuildDataRaw;
341
+ }
342
+
343
+ interface QuoteRequest {
344
+ fromChain: ChainRef;
345
+ toChain: ChainRef;
346
+ tokenIn: AssetRef;
347
+ tokenOut: AssetRef;
348
+ amountIn: BaseUnitAmount;
349
+ slippageBps: number;
350
+ /** Near Intents quote waiting time in milliseconds. Defaults to 3000. */
351
+ quoteWaitingTimeMs?: number;
352
+ sender: string;
353
+ recipient?: string;
354
+ extensions?: Record<string, unknown>;
355
+ }
356
+ interface RouteSummary {
357
+ router: string;
358
+ market?: string;
359
+ amountOut: BaseUnitAmount;
360
+ minAmountOut: BaseUnitAmount;
361
+ raw: Record<string, unknown>;
362
+ }
363
+ interface BuildContext {
364
+ readonly request: SwapQuoteRequestRaw;
365
+ readonly router: string;
366
+ readonly market?: string;
367
+ readonly expectedOut: BaseUnitAmount;
368
+ readonly minAmountOut: BaseUnitAmount;
369
+ readonly preSwap: unknown | null;
370
+ readonly bridge: unknown | null;
371
+ readonly quoteId?: string;
372
+ }
373
+ interface Quote {
374
+ id?: string;
375
+ fromChain: ChainRef;
376
+ toChain: ChainRef;
377
+ tokenIn: AssetRef;
378
+ tokenOut: AssetRef;
379
+ amountIn: BaseUnitAmount;
380
+ estimatedOut: BaseUnitAmount;
381
+ minAmountOut: BaseUnitAmount;
382
+ route: RouteSummary;
383
+ alternatives: RouteSummary[];
384
+ receivedAt: number;
385
+ expiresAt?: number;
386
+ buildContext: Readonly<BuildContext>;
387
+ raw: SwapQuoteDataRaw;
388
+ }
389
+
390
+ type WaitMode = "submitted" | "source-confirmed" | "completed";
391
+ interface SwapWarning {
392
+ code: "REPORT_FAILED";
393
+ message: string;
394
+ cause?: unknown;
395
+ }
396
+ interface SignRequestPreview {
397
+ chain: ChainRef;
398
+ kind: string;
399
+ summary: Record<string, unknown>;
400
+ }
401
+ type OrderStatus = "pending" | "processing" | "completed" | "failed" | "refunded" | "expired" | "unknown";
402
+ type SwapLifecycleEvent = {
403
+ type: "build-started";
404
+ executionId: string;
405
+ } | {
406
+ type: "build-completed";
407
+ executionId: string;
408
+ } | {
409
+ type: "approval-requested";
410
+ executionId: string;
411
+ } | {
412
+ type: "approval-submitted";
413
+ executionId: string;
414
+ txHash: string;
415
+ } | {
416
+ type: "signing-requested";
417
+ executionId: string;
418
+ } | {
419
+ type: "submitted";
420
+ executionId: string;
421
+ txHash?: string;
422
+ orderId?: string;
423
+ } | {
424
+ type: "source-confirmed";
425
+ executionId: string;
426
+ } | {
427
+ type: "order-status";
428
+ executionId: string;
429
+ status: OrderStatus;
430
+ } | {
431
+ type: "completed";
432
+ executionId: string;
433
+ } | {
434
+ type: "requires-user-action";
435
+ executionId: string;
436
+ } | {
437
+ type: "warning";
438
+ executionId: string;
439
+ warning: SwapWarning;
440
+ } | {
441
+ type: "failed";
442
+ executionId: string;
443
+ error: Error;
444
+ };
445
+ interface SwapExecutionResult {
446
+ executionId: string;
447
+ status: "submitted" | "source-confirmed" | "processing" | "completed" | "failed" | "refunded" | "expired" | "requires-user-action";
448
+ router: string;
449
+ txHash?: string;
450
+ txHashes?: string[];
451
+ orderId?: string;
452
+ depositAddress?: string;
453
+ report?: {
454
+ status: "reported" | "failed" | "skipped";
455
+ warning?: SwapWarning;
456
+ };
457
+ raw: unknown;
458
+ }
459
+ interface ExecuteSwapInput {
460
+ build: SwapBuild;
461
+ waitFor?: WaitMode;
462
+ signal?: AbortSignal;
463
+ onEvent?: (event: SwapLifecycleEvent) => void;
464
+ beforeSign?: (preview: SignRequestPreview) => void | Promise<void>;
465
+ }
466
+ interface SwapInput extends Omit<ExecuteSwapInput, "build"> {
467
+ quote: Quote;
468
+ idempotencyKey?: string;
469
+ }
470
+ interface OrderStatusResult {
471
+ orderId: string;
472
+ router: string;
473
+ status: OrderStatus;
474
+ raw: SwapOrderStatusDataRaw;
475
+ }
476
+ interface WaitForOrderInput extends OrderReference {
477
+ signal?: AbortSignal;
478
+ intervalMs?: number;
479
+ timeoutMs?: number;
480
+ }
481
+ declare function normalizeOrderStatus(raw: SwapOrderStatusDataRaw): OrderStatus;
482
+
483
+ interface ChainExecutionResult {
484
+ status: "submitted" | "source-confirmed" | "requires-user-action";
485
+ txHash?: string;
486
+ txHashes?: string[];
487
+ orderId?: string;
488
+ signature?: string;
489
+ signingScheme?: string;
490
+ raw?: unknown;
491
+ }
492
+ interface ExecutionContext {
493
+ executionId: string;
494
+ signal?: AbortSignal;
495
+ waitFor: WaitMode;
496
+ emit(event: SwapLifecycleEvent): void;
497
+ beforeSign?: (preview: SignRequestPreview) => void | Promise<void>;
498
+ }
499
+ interface MessageSignOptions {
500
+ signal?: AbortSignal;
501
+ context?: Readonly<Record<string, unknown>>;
502
+ }
503
+ interface ExecutorIdentityProvider {
504
+ readonly signerChain: string;
505
+ getIdentityKey(): string | Promise<string>;
506
+ signMessage?(message: string, options?: MessageSignOptions): Promise<string>;
507
+ }
508
+ interface ExecutorMessageSigner extends ExecutorIdentityProvider {
509
+ signMessage(message: string, options?: MessageSignOptions): Promise<string>;
510
+ }
511
+ interface ChainExecutor<K extends SwapExecution["kind"] = SwapExecution["kind"]> {
512
+ readonly kinds: readonly K[];
513
+ readonly signerChain?: string;
514
+ getIdentityKey?(): string | Promise<string>;
515
+ signMessage?(message: string, options?: MessageSignOptions): Promise<string>;
516
+ validate(execution: Extract<SwapExecution, {
517
+ kind: K;
518
+ }>, context: ExecutionContext): void | Promise<void>;
519
+ execute(execution: Extract<SwapExecution, {
520
+ kind: K;
521
+ }>, context: ExecutionContext): Promise<ChainExecutionResult>;
522
+ }
523
+ declare class ExecutorRegistry {
524
+ private readonly executors;
525
+ constructor(executors?: readonly ChainExecutor[]);
526
+ register(executor: ChainExecutor, allowOverride?: boolean): void;
527
+ get<K extends SwapExecution["kind"]>(kind: K): ChainExecutor<K>;
528
+ getSigner(chain: string, requireSignMessage: true): ExecutorMessageSigner;
529
+ getSigner(chain: string, requireSignMessage?: false): ExecutorIdentityProvider;
530
+ }
531
+
532
+ export { type SwapExecution as $, type AssetRef as A, type BaseUnitAmount as B, type ChainRef as C, type SwapBuildApproveRaw as D, ExecutorRegistry as E, type SwapWarning as F, type SignRequestPreview as G, type OrderStatus as H, normalizeOrderStatus as I, type ChainExecutionResult as J, type ExecutionContext as K, type ExecutorIdentityProvider as L, type MessageSignOptions as M, type NearTransaction as N, type OrderStatusResult as O, type ExecutorMessageSigner as P, type QuoteRequest as Q, assertBaseUnitAmount as R, type SwapQuoteRequestRaw as S, type EvmTx as T, type EvmApproval as U, type EvmSigningRequest as V, type WaitMode as W, type SolanaMetadata as X, type OrderReference as Y, type DepositInfo as Z, type SwapReportContext as _, type SwapQuoteDataRaw as a, type RouteSummary as a0, type BuildContext as a1, type SwapBuildRequestRaw as b, type SwapBuildDataRaw as c, type SwapOrderSubmitRequestRaw as d, type SwapOrderSubmitDataRaw as e, type SwapOrderStatusParamsRaw as f, type SwapOrderStatusDataRaw as g, type SwapReportRequestRaw as h, type SwapReportDataRaw as i, type SwapHistoryParamsRaw as j, type SwapHistoryDataRaw as k, type Quote as l, type SwapMcaPayloadRaw as m, type SwapLifecycleEvent as n, type SwapExecutionResult as o, type SwapHistoryRecordRaw as p, type ChainExecutor as q, type SwapBuild as r, type ExecuteSwapInput as s, type SwapInput as t, type WaitForOrderInput as u, type SwapMcaRelayerRequestRaw as v, type SwapApiResponse as w, type SwapApiTokenMetaRaw as x, type SwapMcaSignerPayloadRaw as y, type SwapSigningRequestRaw as z };