@rhea-finance/cross-chain-aggregation-dex 2.1.1 → 2.1.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/README.md CHANGED
@@ -382,7 +382,7 @@ if (result.status === "completed") {
382
382
  }
383
383
  ```
384
384
 
385
- After `POST /api/swap/report` returns an `id`, the SDK always polls `GET /api/swap/order-status?recordId=...`, including when `waitFor` is `"submitted"`. `"completed"` and `"source-confirmed"` also poll for cross-chain and confidential swaps when no report id is available, falling back to `orderId`/`router`/`chainId` or source `txHash`. Confidential swaps also require order-status polling when they are same-chain. For confidential Near Intents builds, the SDK uses `deposit.orderId` when present and otherwise uses `deposit.depositAddress` as the status key. If a cross-chain or confidential swap provides none of these identifiers, the SDK throws `INVALID_API_RESPONSE` at the `status` stage instead of treating source-chain confirmation as completion.
385
+ After `POST /api/swap/report` returns an `id`, the SDK always polls `GET /api/swap/order-status?orderId=<report id>`. That report id is the only status key. The SDK does not query by `recordId` or source `txHash`. Confidential swaps also require order-status polling when they are same-chain. For confidential Near Intents builds, the SDK uses `deposit.orderId` when present and otherwise uses `deposit.depositAddress` as the status key. If a cross-chain or confidential swap provides none of these identifiers, the SDK throws `INVALID_API_RESPONSE` at the `status` stage instead of treating source-chain confirmation as completion.
386
386
 
387
387
  The default polling interval is 5 seconds. There is no default polling timeout, so polling continues until the order reaches a terminal state or the supplied `AbortSignal` is aborted.
388
388
 
package/dist/index.d.mts CHANGED
@@ -385,7 +385,10 @@ declare function shouldPollSwapOrderStatus(input: {
385
385
  }): boolean;
386
386
  declare function resolveSwapReportRecordId(reportData: unknown): string;
387
387
  type OrderStatusLookup = OrderReference;
388
- /** Matches multi-chain-lending `resolveSwapOrderStatusQuery` query shape. */
388
+ /**
389
+ * Status queries use `orderId`.
390
+ * The report response `id` is that orderId and is sent alone.
391
+ */
389
392
  declare function buildOrderStatusQuery(params: SwapOrderStatusParamsRaw): Record<string, string | number>;
390
393
  declare function resolveOrderStatusLookup(input: {
391
394
  recordId?: string | number;
package/dist/index.d.ts CHANGED
@@ -385,7 +385,10 @@ declare function shouldPollSwapOrderStatus(input: {
385
385
  }): boolean;
386
386
  declare function resolveSwapReportRecordId(reportData: unknown): string;
387
387
  type OrderStatusLookup = OrderReference;
388
- /** Matches multi-chain-lending `resolveSwapOrderStatusQuery` query shape. */
388
+ /**
389
+ * Status queries use `orderId`.
390
+ * The report response `id` is that orderId and is sent alone.
391
+ */
389
392
  declare function buildOrderStatusQuery(params: SwapOrderStatusParamsRaw): Record<string, string | number>;
390
393
  declare function resolveOrderStatusLookup(input: {
391
394
  recordId?: string | number;
package/dist/index.js CHANGED
@@ -48,18 +48,13 @@ function resolveSwapReportRecordId(reportData) {
48
48
  return "";
49
49
  }
50
50
  function buildOrderStatusQuery(params) {
51
- const normalizedRecordId = String(params.recordId ?? "").trim();
52
- if (normalizedRecordId) {
53
- return { recordId: normalizedRecordId };
51
+ const reportId = String(params.recordId ?? "").trim();
52
+ if (reportId) {
53
+ return { orderId: reportId };
54
54
  }
55
- const query = {};
56
55
  const orderId = params.orderId?.trim();
57
- const txHash = params.txHash?.trim();
58
- if (orderId) {
59
- query.orderId = orderId;
60
- } else if (txHash) {
61
- query.txHash = txHash;
62
- }
56
+ if (!orderId) return {};
57
+ const query = { orderId };
63
58
  const router = params.router?.trim();
64
59
  if (router) query.router = router;
65
60
  const chainId = params.chainId;
@@ -69,19 +64,17 @@ function buildOrderStatusQuery(params) {
69
64
  return query;
70
65
  }
71
66
  function resolveOrderStatusLookup(input) {
72
- const recordId = String(input.recordId ?? "").trim();
73
- if (recordId) {
74
- return { recordId };
67
+ const reportId = String(input.recordId ?? "").trim();
68
+ if (reportId) {
69
+ return { orderId: reportId };
75
70
  }
76
- const router = input.router?.trim();
77
71
  const orderId = input.orderId?.trim();
78
- const txHash = input.txHash?.trim();
79
- const statusKey = orderId || txHash;
80
- if (!statusKey || !router) return void 0;
72
+ if (!orderId) return void 0;
73
+ const router = input.router?.trim();
81
74
  const chainId = input.chainId !== void 0 && input.chainId !== null && String(input.chainId).trim() !== "" ? String(input.chainId).trim() : void 0;
82
75
  return {
83
- ...orderId ? { orderId } : { txHash },
84
- router,
76
+ orderId,
77
+ ...router ? { router } : {},
85
78
  ...chainId ? { chainId } : {}
86
79
  };
87
80
  }
@@ -91,19 +84,18 @@ function assertOrderStatusParams(params) {
91
84
  throw new SwapSdkError(
92
85
  "INVALID_REQUEST",
93
86
  "status",
94
- "Order status requires recordId, or orderId/txHash with router"
87
+ "Order status requires orderId"
95
88
  );
96
89
  }
97
90
  return lookup;
98
91
  }
99
92
  function orderStatusParamsFromHistoryItem(item) {
100
- const recordId = String(item.id ?? "").trim();
101
- if (recordId) {
102
- return { recordId };
93
+ const reportId = String(item.id ?? "").trim();
94
+ if (reportId) {
95
+ return { orderId: reportId };
103
96
  }
104
97
  return {
105
98
  ...item.orderId ? { orderId: item.orderId } : {},
106
- ...item.sourceTxHash ? { txHash: item.sourceTxHash } : {},
107
99
  ...item.router ? { router: item.router } : {}
108
100
  };
109
101
  }
@@ -159,18 +151,11 @@ var ApiClient = class {
159
151
  }
160
152
  getOrderStatus(params, options = {}) {
161
153
  const query = buildOrderStatusQuery(params);
162
- if (!query.recordId && !query.orderId && !query.txHash) {
163
- throw new SwapSdkError(
164
- "INVALID_REQUEST",
165
- "status",
166
- "Order status requires recordId, or orderId/txHash with router"
167
- );
168
- }
169
- if (!query.recordId && !query.router) {
154
+ if (!query.orderId) {
170
155
  throw new SwapSdkError(
171
156
  "INVALID_REQUEST",
172
157
  "status",
173
- "Order status requires router when recordId is absent"
158
+ "Order status requires orderId"
174
159
  );
175
160
  }
176
161
  return this.request("/api/swap/order-status", "status", {
@@ -2307,10 +2292,15 @@ var McaSwapService = class {
2307
2292
  }
2308
2293
  if (input.waitFor === "completed") {
2309
2294
  const statusLookup = resolveOrderStatusLookup({
2310
- recordId: reportRecordId ?? result.report?.recordId,
2311
- orderId,
2312
- router
2313
- }) ?? { orderId, router };
2295
+ recordId: reportRecordId ?? result.report?.recordId
2296
+ });
2297
+ if (!statusLookup) {
2298
+ throw new SwapSdkError(
2299
+ "INVALID_API_RESPONSE",
2300
+ "status",
2301
+ "MCA withdraw was reported without an id to query"
2302
+ );
2303
+ }
2314
2304
  const status = await this.client.waitForOrder({
2315
2305
  ...statusLookup,
2316
2306
  ...input.orderPolling,
@@ -2534,8 +2524,6 @@ var SwapClient = class {
2534
2524
  emit({ type: "signing-requested", executionId: build.executionId });
2535
2525
  const chainResult = await executor.execute(build.execution, context);
2536
2526
  let orderId = chainResult.orderId ?? build.order?.orderId;
2537
- let orderRouter = build.order?.router;
2538
- let orderChainId = build.order?.chainId;
2539
2527
  if (chainResult.signature) {
2540
2528
  if (build.execution.kind !== "evm-signature") {
2541
2529
  throw new SwapSdkError(
@@ -2558,10 +2546,6 @@ var SwapClient = class {
2558
2546
  { signal: input.signal }
2559
2547
  );
2560
2548
  orderId = submitted.orderId;
2561
- orderRouter = readNonEmptyString(submitted.router) ?? submitRouter;
2562
- orderChainId = String(
2563
- submitted.chainId ?? build.execution.request.chainId
2564
- );
2565
2549
  }
2566
2550
  const result = {
2567
2551
  executionId: build.executionId,
@@ -2622,21 +2606,17 @@ var SwapClient = class {
2622
2606
  reportRecordId
2623
2607
  });
2624
2608
  const statusLookup = resolveOrderStatusLookup({
2625
- recordId: reportRecordId ?? result.report?.recordId,
2626
- orderId,
2627
- txHash: resolveSourceTxHash(chainResult),
2628
- router: orderRouter ?? build.router,
2629
- chainId: orderChainId
2609
+ recordId: reportRecordId ?? result.report?.recordId
2630
2610
  });
2631
2611
  if (shouldPollOrderStatus && !statusLookup) {
2632
2612
  throw new SwapSdkError(
2633
2613
  "INVALID_API_RESPONSE",
2634
2614
  "status",
2635
- "Swap submitted, but no report record id, status key, or source transaction hash is available",
2615
+ "Swap submitted, but the report response did not include an id to query",
2636
2616
  {
2637
2617
  details: {
2638
2618
  executionId: build.executionId,
2639
- router: orderRouter ?? build.router
2619
+ router: build.router
2640
2620
  }
2641
2621
  }
2642
2622
  );