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