@rhea-finance/cross-chain-aggregation-dex 2.1.0 → 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/dist/index.mjs CHANGED
@@ -28,6 +28,7 @@ function asSwapSdkError(error, stage) {
28
28
 
29
29
  // src/utils/orderStatus.ts
30
30
  function shouldPollSwapOrderStatus(input) {
31
+ if (String(input.reportRecordId ?? "").trim()) return true;
31
32
  const waitMode = input.waitFor ?? "submitted";
32
33
  const requiresOrderStatus = input.isCrossChain || input.confidentiality === "basic";
33
34
  return requiresOrderStatus && waitMode !== "submitted";
@@ -45,18 +46,13 @@ function resolveSwapReportRecordId(reportData) {
45
46
  return "";
46
47
  }
47
48
  function buildOrderStatusQuery(params) {
48
- const normalizedRecordId = String(params.recordId ?? "").trim();
49
- if (normalizedRecordId) {
50
- return { recordId: normalizedRecordId };
49
+ const reportId = String(params.recordId ?? "").trim();
50
+ if (reportId) {
51
+ return { orderId: reportId };
51
52
  }
52
- const query = {};
53
53
  const orderId = params.orderId?.trim();
54
- const txHash = params.txHash?.trim();
55
- if (orderId) {
56
- query.orderId = orderId;
57
- } else if (txHash) {
58
- query.txHash = txHash;
59
- }
54
+ if (!orderId) return {};
55
+ const query = { orderId };
60
56
  const router = params.router?.trim();
61
57
  if (router) query.router = router;
62
58
  const chainId = params.chainId;
@@ -66,19 +62,17 @@ function buildOrderStatusQuery(params) {
66
62
  return query;
67
63
  }
68
64
  function resolveOrderStatusLookup(input) {
69
- const recordId = String(input.recordId ?? "").trim();
70
- if (recordId) {
71
- return { recordId };
65
+ const reportId = String(input.recordId ?? "").trim();
66
+ if (reportId) {
67
+ return { orderId: reportId };
72
68
  }
73
- const router = input.router?.trim();
74
69
  const orderId = input.orderId?.trim();
75
- const txHash = input.txHash?.trim();
76
- const statusKey = orderId || txHash;
77
- if (!statusKey || !router) return void 0;
70
+ if (!orderId) return void 0;
71
+ const router = input.router?.trim();
78
72
  const chainId = input.chainId !== void 0 && input.chainId !== null && String(input.chainId).trim() !== "" ? String(input.chainId).trim() : void 0;
79
73
  return {
80
- ...orderId ? { orderId } : { txHash },
81
- router,
74
+ orderId,
75
+ ...router ? { router } : {},
82
76
  ...chainId ? { chainId } : {}
83
77
  };
84
78
  }
@@ -88,19 +82,18 @@ function assertOrderStatusParams(params) {
88
82
  throw new SwapSdkError(
89
83
  "INVALID_REQUEST",
90
84
  "status",
91
- "Order status requires recordId, or orderId/txHash with router"
85
+ "Order status requires orderId"
92
86
  );
93
87
  }
94
88
  return lookup;
95
89
  }
96
90
  function orderStatusParamsFromHistoryItem(item) {
97
- const recordId = String(item.id ?? "").trim();
98
- if (recordId) {
99
- return { recordId };
91
+ const reportId = String(item.id ?? "").trim();
92
+ if (reportId) {
93
+ return { orderId: reportId };
100
94
  }
101
95
  return {
102
96
  ...item.orderId ? { orderId: item.orderId } : {},
103
- ...item.sourceTxHash ? { txHash: item.sourceTxHash } : {},
104
97
  ...item.router ? { router: item.router } : {}
105
98
  };
106
99
  }
@@ -156,18 +149,11 @@ var ApiClient = class {
156
149
  }
157
150
  getOrderStatus(params, options = {}) {
158
151
  const query = buildOrderStatusQuery(params);
159
- if (!query.recordId && !query.orderId && !query.txHash) {
160
- throw new SwapSdkError(
161
- "INVALID_REQUEST",
162
- "status",
163
- "Order status requires recordId, or orderId/txHash with router"
164
- );
165
- }
166
- if (!query.recordId && !query.router) {
152
+ if (!query.orderId) {
167
153
  throw new SwapSdkError(
168
154
  "INVALID_REQUEST",
169
155
  "status",
170
- "Order status requires router when recordId is absent"
156
+ "Order status requires orderId"
171
157
  );
172
158
  }
173
159
  return this.request("/api/swap/order-status", "status", {
@@ -2304,10 +2290,15 @@ var McaSwapService = class {
2304
2290
  }
2305
2291
  if (input.waitFor === "completed") {
2306
2292
  const statusLookup = resolveOrderStatusLookup({
2307
- recordId: reportRecordId ?? result.report?.recordId,
2308
- orderId,
2309
- router
2310
- }) ?? { orderId, router };
2293
+ recordId: reportRecordId ?? result.report?.recordId
2294
+ });
2295
+ if (!statusLookup) {
2296
+ throw new SwapSdkError(
2297
+ "INVALID_API_RESPONSE",
2298
+ "status",
2299
+ "MCA withdraw was reported without an id to query"
2300
+ );
2301
+ }
2311
2302
  const status = await this.client.waitForOrder({
2312
2303
  ...statusLookup,
2313
2304
  ...input.orderPolling,
@@ -2531,8 +2522,6 @@ var SwapClient = class {
2531
2522
  emit({ type: "signing-requested", executionId: build.executionId });
2532
2523
  const chainResult = await executor.execute(build.execution, context);
2533
2524
  let orderId = chainResult.orderId ?? build.order?.orderId;
2534
- let orderRouter = build.order?.router;
2535
- let orderChainId = build.order?.chainId;
2536
2525
  if (chainResult.signature) {
2537
2526
  if (build.execution.kind !== "evm-signature") {
2538
2527
  throw new SwapSdkError(
@@ -2555,10 +2544,6 @@ var SwapClient = class {
2555
2544
  { signal: input.signal }
2556
2545
  );
2557
2546
  orderId = submitted.orderId;
2558
- orderRouter = readNonEmptyString(submitted.router) ?? submitRouter;
2559
- orderChainId = String(
2560
- submitted.chainId ?? build.execution.request.chainId
2561
- );
2562
2547
  }
2563
2548
  const result = {
2564
2549
  executionId: build.executionId,
@@ -2584,16 +2569,12 @@ var SwapClient = class {
2584
2569
  });
2585
2570
  }
2586
2571
  const waitMode = input.waitFor ?? "submitted";
2587
- const shouldPollOrderStatus = shouldPollSwapOrderStatus({
2588
- waitFor: waitMode,
2589
- isCrossChain: build.isCrossChain,
2590
- confidentiality: build.request?.confidentiality
2591
- });
2572
+ const requiresTrackedStatus = build.isCrossChain || build.request?.confidentiality === "basic";
2592
2573
  const reportRequest = this.createReportRequest(build, result);
2593
2574
  if (reportRequest) {
2594
2575
  this.reportRequests.set(build.executionId, reportRequest);
2595
2576
  }
2596
- const mustReportForStatus = shouldPollOrderStatus && Boolean(reportRequest);
2577
+ const mustReportForStatus = requiresTrackedStatus && waitMode !== "submitted" && Boolean(reportRequest);
2597
2578
  const shouldReportNow = Boolean(reportRequest) && this.reportMode !== "disabled" && (this.reportMode === "auto" || mustReportForStatus);
2598
2579
  let reportRecordId;
2599
2580
  if (shouldReportNow && reportRequest) {
@@ -2616,22 +2597,24 @@ var SwapClient = class {
2616
2597
  emit({ type: "warning", executionId: build.executionId, warning });
2617
2598
  }
2618
2599
  }
2600
+ const shouldPollOrderStatus = shouldPollSwapOrderStatus({
2601
+ waitFor: waitMode,
2602
+ isCrossChain: build.isCrossChain,
2603
+ confidentiality: build.request?.confidentiality,
2604
+ reportRecordId
2605
+ });
2619
2606
  const statusLookup = resolveOrderStatusLookup({
2620
- recordId: reportRecordId ?? result.report?.recordId,
2621
- orderId,
2622
- txHash: resolveSourceTxHash(chainResult),
2623
- router: orderRouter ?? build.router,
2624
- chainId: orderChainId
2607
+ recordId: reportRecordId ?? result.report?.recordId
2625
2608
  });
2626
2609
  if (shouldPollOrderStatus && !statusLookup) {
2627
2610
  throw new SwapSdkError(
2628
2611
  "INVALID_API_RESPONSE",
2629
2612
  "status",
2630
- "Swap submitted, but no report record id, status key, or source transaction hash is available",
2613
+ "Swap submitted, but the report response did not include an id to query",
2631
2614
  {
2632
2615
  details: {
2633
2616
  executionId: build.executionId,
2634
- router: orderRouter ?? build.router
2617
+ router: build.router
2635
2618
  }
2636
2619
  }
2637
2620
  );