@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/dist/index.mjs CHANGED
@@ -46,18 +46,13 @@ function resolveSwapReportRecordId(reportData) {
46
46
  return "";
47
47
  }
48
48
  function buildOrderStatusQuery(params) {
49
- const normalizedRecordId = String(params.recordId ?? "").trim();
50
- if (normalizedRecordId) {
51
- return { recordId: normalizedRecordId };
49
+ const reportId = String(params.recordId ?? "").trim();
50
+ if (reportId) {
51
+ return { orderId: reportId };
52
52
  }
53
- const query = {};
54
53
  const orderId = params.orderId?.trim();
55
- const txHash = params.txHash?.trim();
56
- if (orderId) {
57
- query.orderId = orderId;
58
- } else if (txHash) {
59
- query.txHash = txHash;
60
- }
54
+ if (!orderId) return {};
55
+ const query = { orderId };
61
56
  const router = params.router?.trim();
62
57
  if (router) query.router = router;
63
58
  const chainId = params.chainId;
@@ -67,19 +62,17 @@ function buildOrderStatusQuery(params) {
67
62
  return query;
68
63
  }
69
64
  function resolveOrderStatusLookup(input) {
70
- const recordId = String(input.recordId ?? "").trim();
71
- if (recordId) {
72
- return { recordId };
65
+ const reportId = String(input.recordId ?? "").trim();
66
+ if (reportId) {
67
+ return { orderId: reportId };
73
68
  }
74
- const router = input.router?.trim();
75
69
  const orderId = input.orderId?.trim();
76
- const txHash = input.txHash?.trim();
77
- const statusKey = orderId || txHash;
78
- if (!statusKey || !router) return void 0;
70
+ if (!orderId) return void 0;
71
+ const router = input.router?.trim();
79
72
  const chainId = input.chainId !== void 0 && input.chainId !== null && String(input.chainId).trim() !== "" ? String(input.chainId).trim() : void 0;
80
73
  return {
81
- ...orderId ? { orderId } : { txHash },
82
- router,
74
+ orderId,
75
+ ...router ? { router } : {},
83
76
  ...chainId ? { chainId } : {}
84
77
  };
85
78
  }
@@ -89,19 +82,18 @@ function assertOrderStatusParams(params) {
89
82
  throw new SwapSdkError(
90
83
  "INVALID_REQUEST",
91
84
  "status",
92
- "Order status requires recordId, or orderId/txHash with router"
85
+ "Order status requires orderId"
93
86
  );
94
87
  }
95
88
  return lookup;
96
89
  }
97
90
  function orderStatusParamsFromHistoryItem(item) {
98
- const recordId = String(item.id ?? "").trim();
99
- if (recordId) {
100
- return { recordId };
91
+ const reportId = String(item.id ?? "").trim();
92
+ if (reportId) {
93
+ return { orderId: reportId };
101
94
  }
102
95
  return {
103
96
  ...item.orderId ? { orderId: item.orderId } : {},
104
- ...item.sourceTxHash ? { txHash: item.sourceTxHash } : {},
105
97
  ...item.router ? { router: item.router } : {}
106
98
  };
107
99
  }
@@ -157,18 +149,11 @@ var ApiClient = class {
157
149
  }
158
150
  getOrderStatus(params, options = {}) {
159
151
  const query = buildOrderStatusQuery(params);
160
- if (!query.recordId && !query.orderId && !query.txHash) {
161
- throw new SwapSdkError(
162
- "INVALID_REQUEST",
163
- "status",
164
- "Order status requires recordId, or orderId/txHash with router"
165
- );
166
- }
167
- if (!query.recordId && !query.router) {
152
+ if (!query.orderId) {
168
153
  throw new SwapSdkError(
169
154
  "INVALID_REQUEST",
170
155
  "status",
171
- "Order status requires router when recordId is absent"
156
+ "Order status requires orderId"
172
157
  );
173
158
  }
174
159
  return this.request("/api/swap/order-status", "status", {
@@ -2305,10 +2290,15 @@ var McaSwapService = class {
2305
2290
  }
2306
2291
  if (input.waitFor === "completed") {
2307
2292
  const statusLookup = resolveOrderStatusLookup({
2308
- recordId: reportRecordId ?? result.report?.recordId,
2309
- orderId,
2310
- router
2311
- }) ?? { 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
+ }
2312
2302
  const status = await this.client.waitForOrder({
2313
2303
  ...statusLookup,
2314
2304
  ...input.orderPolling,
@@ -2532,8 +2522,6 @@ var SwapClient = class {
2532
2522
  emit({ type: "signing-requested", executionId: build.executionId });
2533
2523
  const chainResult = await executor.execute(build.execution, context);
2534
2524
  let orderId = chainResult.orderId ?? build.order?.orderId;
2535
- let orderRouter = build.order?.router;
2536
- let orderChainId = build.order?.chainId;
2537
2525
  if (chainResult.signature) {
2538
2526
  if (build.execution.kind !== "evm-signature") {
2539
2527
  throw new SwapSdkError(
@@ -2556,10 +2544,6 @@ var SwapClient = class {
2556
2544
  { signal: input.signal }
2557
2545
  );
2558
2546
  orderId = submitted.orderId;
2559
- orderRouter = readNonEmptyString(submitted.router) ?? submitRouter;
2560
- orderChainId = String(
2561
- submitted.chainId ?? build.execution.request.chainId
2562
- );
2563
2547
  }
2564
2548
  const result = {
2565
2549
  executionId: build.executionId,
@@ -2620,21 +2604,17 @@ var SwapClient = class {
2620
2604
  reportRecordId
2621
2605
  });
2622
2606
  const statusLookup = resolveOrderStatusLookup({
2623
- recordId: reportRecordId ?? result.report?.recordId,
2624
- orderId,
2625
- txHash: resolveSourceTxHash(chainResult),
2626
- router: orderRouter ?? build.router,
2627
- chainId: orderChainId
2607
+ recordId: reportRecordId ?? result.report?.recordId
2628
2608
  });
2629
2609
  if (shouldPollOrderStatus && !statusLookup) {
2630
2610
  throw new SwapSdkError(
2631
2611
  "INVALID_API_RESPONSE",
2632
2612
  "status",
2633
- "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",
2634
2614
  {
2635
2615
  details: {
2636
2616
  executionId: build.executionId,
2637
- router: orderRouter ?? build.router
2617
+ router: build.router
2638
2618
  }
2639
2619
  }
2640
2620
  );