@rhea-finance/cross-chain-aggregation-dex 2.1.1 → 2.1.3

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 polls `GET /api/swap/order-status?orderId=<report id>&router=<swap router>`. The router comes from the swap response. 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,9 @@ 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 the report id as `orderId`, plus the swap response `router`.
390
+ */
389
391
  declare function buildOrderStatusQuery(params: SwapOrderStatusParamsRaw): Record<string, string | number>;
390
392
  declare function resolveOrderStatusLookup(input: {
391
393
  recordId?: string | number;
package/dist/index.d.ts CHANGED
@@ -385,7 +385,9 @@ 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 the report id as `orderId`, plus the swap response `router`.
390
+ */
389
391
  declare function buildOrderStatusQuery(params: SwapOrderStatusParamsRaw): Record<string, string | number>;
390
392
  declare function resolveOrderStatusLookup(input: {
391
393
  recordId?: string | number;
package/dist/index.js CHANGED
@@ -48,40 +48,35 @@ 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 };
54
- }
55
- const query = {};
56
- 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
- }
51
+ const reportId = String(params.recordId ?? "").trim();
52
+ const orderId = reportId || params.orderId?.trim();
53
+ if (!orderId) return {};
54
+ const query = { orderId };
63
55
  const router = params.router?.trim();
64
56
  if (router) query.router = router;
65
- const chainId = params.chainId;
66
- if (chainId !== void 0 && chainId !== null && String(chainId).trim() !== "") {
67
- query.chainId = chainId;
57
+ if (!reportId) {
58
+ const chainId = params.chainId;
59
+ if (chainId !== void 0 && chainId !== null && String(chainId).trim() !== "") {
60
+ query.chainId = chainId;
61
+ }
68
62
  }
69
63
  return query;
70
64
  }
71
65
  function resolveOrderStatusLookup(input) {
72
- const recordId = String(input.recordId ?? "").trim();
73
- if (recordId) {
74
- return { recordId };
75
- }
66
+ const reportId = String(input.recordId ?? "").trim();
67
+ const orderId = reportId || input.orderId?.trim();
68
+ if (!orderId) return void 0;
76
69
  const router = input.router?.trim();
77
- const orderId = input.orderId?.trim();
78
- const txHash = input.txHash?.trim();
79
- const statusKey = orderId || txHash;
80
- if (!statusKey || !router) return void 0;
81
- const chainId = input.chainId !== void 0 && input.chainId !== null && String(input.chainId).trim() !== "" ? String(input.chainId).trim() : void 0;
70
+ const chainId = reportId ? void 0 : input.chainId !== void 0 && input.chainId !== null && String(input.chainId).trim() !== "" ? String(input.chainId).trim() : void 0;
71
+ if (reportId) {
72
+ return {
73
+ orderId,
74
+ ...router ? { router } : {}
75
+ };
76
+ }
82
77
  return {
83
- ...orderId ? { orderId } : { txHash },
84
- router,
78
+ orderId,
79
+ ...router ? { router } : {},
85
80
  ...chainId ? { chainId } : {}
86
81
  };
87
82
  }
@@ -91,19 +86,21 @@ function assertOrderStatusParams(params) {
91
86
  throw new SwapSdkError(
92
87
  "INVALID_REQUEST",
93
88
  "status",
94
- "Order status requires recordId, or orderId/txHash with router"
89
+ "Order status requires orderId"
95
90
  );
96
91
  }
97
92
  return lookup;
98
93
  }
99
94
  function orderStatusParamsFromHistoryItem(item) {
100
- const recordId = String(item.id ?? "").trim();
101
- if (recordId) {
102
- return { recordId };
95
+ const reportId = String(item.id ?? "").trim();
96
+ if (reportId) {
97
+ return {
98
+ orderId: reportId,
99
+ ...item.router ? { router: item.router } : {}
100
+ };
103
101
  }
104
102
  return {
105
103
  ...item.orderId ? { orderId: item.orderId } : {},
106
- ...item.sourceTxHash ? { txHash: item.sourceTxHash } : {},
107
104
  ...item.router ? { router: item.router } : {}
108
105
  };
109
106
  }
@@ -159,18 +156,11 @@ var ApiClient = class {
159
156
  }
160
157
  getOrderStatus(params, options = {}) {
161
158
  const query = buildOrderStatusQuery(params);
162
- if (!query.recordId && !query.orderId && !query.txHash) {
159
+ if (!query.orderId) {
163
160
  throw new SwapSdkError(
164
161
  "INVALID_REQUEST",
165
162
  "status",
166
- "Order status requires recordId, or orderId/txHash with router"
167
- );
168
- }
169
- if (!query.recordId && !query.router) {
170
- throw new SwapSdkError(
171
- "INVALID_REQUEST",
172
- "status",
173
- "Order status requires router when recordId is absent"
163
+ "Order status requires orderId"
174
164
  );
175
165
  }
176
166
  return this.request("/api/swap/order-status", "status", {
@@ -2308,9 +2298,15 @@ var McaSwapService = class {
2308
2298
  if (input.waitFor === "completed") {
2309
2299
  const statusLookup = resolveOrderStatusLookup({
2310
2300
  recordId: reportRecordId ?? result.report?.recordId,
2311
- orderId,
2312
2301
  router
2313
- }) ?? { orderId, router };
2302
+ });
2303
+ if (!statusLookup) {
2304
+ throw new SwapSdkError(
2305
+ "INVALID_API_RESPONSE",
2306
+ "status",
2307
+ "MCA withdraw was reported without an id to query"
2308
+ );
2309
+ }
2314
2310
  const status = await this.client.waitForOrder({
2315
2311
  ...statusLookup,
2316
2312
  ...input.orderPolling,
@@ -2534,8 +2530,6 @@ var SwapClient = class {
2534
2530
  emit({ type: "signing-requested", executionId: build.executionId });
2535
2531
  const chainResult = await executor.execute(build.execution, context);
2536
2532
  let orderId = chainResult.orderId ?? build.order?.orderId;
2537
- let orderRouter = build.order?.router;
2538
- let orderChainId = build.order?.chainId;
2539
2533
  if (chainResult.signature) {
2540
2534
  if (build.execution.kind !== "evm-signature") {
2541
2535
  throw new SwapSdkError(
@@ -2558,10 +2552,6 @@ var SwapClient = class {
2558
2552
  { signal: input.signal }
2559
2553
  );
2560
2554
  orderId = submitted.orderId;
2561
- orderRouter = readNonEmptyString(submitted.router) ?? submitRouter;
2562
- orderChainId = String(
2563
- submitted.chainId ?? build.execution.request.chainId
2564
- );
2565
2555
  }
2566
2556
  const result = {
2567
2557
  executionId: build.executionId,
@@ -2623,20 +2613,17 @@ var SwapClient = class {
2623
2613
  });
2624
2614
  const statusLookup = resolveOrderStatusLookup({
2625
2615
  recordId: reportRecordId ?? result.report?.recordId,
2626
- orderId,
2627
- txHash: resolveSourceTxHash(chainResult),
2628
- router: orderRouter ?? build.router,
2629
- chainId: orderChainId
2616
+ router: build.order?.router ?? build.router
2630
2617
  });
2631
2618
  if (shouldPollOrderStatus && !statusLookup) {
2632
2619
  throw new SwapSdkError(
2633
2620
  "INVALID_API_RESPONSE",
2634
2621
  "status",
2635
- "Swap submitted, but no report record id, status key, or source transaction hash is available",
2622
+ "Swap submitted, but the report response did not include an id to query",
2636
2623
  {
2637
2624
  details: {
2638
2625
  executionId: build.executionId,
2639
- router: orderRouter ?? build.router
2626
+ router: build.router
2640
2627
  }
2641
2628
  }
2642
2629
  );