@rhea-finance/cross-chain-aggregation-dex 2.0.8 → 2.1.0

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
@@ -27,10 +27,22 @@ function asSwapSdkError(error, stage) {
27
27
  }
28
28
 
29
29
  // src/utils/orderStatus.ts
30
+ function shouldPollSwapOrderStatus(input) {
31
+ const waitMode = input.waitFor ?? "submitted";
32
+ const requiresOrderStatus = input.isCrossChain || input.confidentiality === "basic";
33
+ return requiresOrderStatus && waitMode !== "submitted";
34
+ }
30
35
  function resolveSwapReportRecordId(reportData) {
31
36
  if (!reportData || typeof reportData !== "object") return "";
32
- const id = reportData.id;
33
- return id === void 0 || id === null ? "" : String(id).trim();
37
+ const record = reportData;
38
+ for (const key of ["id", "recordId", "record_id"]) {
39
+ const value = record[key];
40
+ if (value !== void 0 && value !== null) {
41
+ const normalized = String(value).trim();
42
+ if (normalized) return normalized;
43
+ }
44
+ }
45
+ return "";
34
46
  }
35
47
  function buildOrderStatusQuery(params) {
36
48
  const normalizedRecordId = String(params.recordId ?? "").trim();
@@ -2055,41 +2067,13 @@ var McaSwapService = class {
2055
2067
  "MCA NEAR withdraw is missing a status deposit address"
2056
2068
  );
2057
2069
  }
2058
- const result = await this.client.executeSwap({
2070
+ return this.client.executeSwap({
2059
2071
  build,
2060
2072
  waitFor: input.quote.executionMode === "withdraw-near" && input.waitFor === "completed" ? "source-confirmed" : input.waitFor,
2061
2073
  orderPolling: input.orderPolling,
2062
2074
  signal: input.signal,
2063
2075
  onEvent: input.onEvent
2064
2076
  });
2065
- if (input.quote.executionMode === "withdraw-near" && input.waitFor === "completed") {
2066
- const statusLookup = resolveOrderStatusLookup({
2067
- recordId: result.report?.recordId,
2068
- orderId: nearStatusKey,
2069
- router: input.quote.route.router
2070
- }) ?? { orderId: nearStatusKey, router: input.quote.route.router };
2071
- const status = await this.client.waitForOrder({
2072
- ...statusLookup,
2073
- ...input.orderPolling,
2074
- signal: input.signal
2075
- });
2076
- this.emitEvent(
2077
- {
2078
- type: "order-status",
2079
- executionId: result.executionId,
2080
- status: status.status
2081
- },
2082
- input.onEvent
2083
- );
2084
- result.status = status.status === "unknown" || status.status === "pending" ? "processing" : status.status;
2085
- if (status.status === "completed") {
2086
- this.emitEvent(
2087
- { type: "completed", executionId: result.executionId },
2088
- input.onEvent
2089
- );
2090
- }
2091
- }
2092
- return result;
2093
2077
  }
2094
2078
  reportIfManaged(result) {
2095
2079
  const request = this.relayerReports.get(result.executionId);
@@ -2295,8 +2279,10 @@ var McaSwapService = class {
2295
2279
  raw
2296
2280
  };
2297
2281
  emit({ type: "submitted", executionId, orderId });
2282
+ const mustReportForStatus = input.waitFor === "completed";
2283
+ const shouldReportNow = this.reportMode !== "disabled" && (this.reportMode === "auto" || mustReportForStatus);
2298
2284
  let reportRecordId;
2299
- if (this.reportMode === "auto") {
2285
+ if (shouldReportNow) {
2300
2286
  try {
2301
2287
  const reportData = await this.client.reportRaw(reportRequest, {
2302
2288
  signal: input.signal
@@ -2597,12 +2583,20 @@ var SwapClient = class {
2597
2583
  executionId: build.executionId
2598
2584
  });
2599
2585
  }
2586
+ const waitMode = input.waitFor ?? "submitted";
2587
+ const shouldPollOrderStatus = shouldPollSwapOrderStatus({
2588
+ waitFor: waitMode,
2589
+ isCrossChain: build.isCrossChain,
2590
+ confidentiality: build.request?.confidentiality
2591
+ });
2600
2592
  const reportRequest = this.createReportRequest(build, result);
2601
2593
  if (reportRequest) {
2602
2594
  this.reportRequests.set(build.executionId, reportRequest);
2603
2595
  }
2596
+ const mustReportForStatus = shouldPollOrderStatus && Boolean(reportRequest);
2597
+ const shouldReportNow = Boolean(reportRequest) && this.reportMode !== "disabled" && (this.reportMode === "auto" || mustReportForStatus);
2604
2598
  let reportRecordId;
2605
- if (this.reportMode === "auto" && reportRequest) {
2599
+ if (shouldReportNow && reportRequest) {
2606
2600
  try {
2607
2601
  const reportData = await this.api.report(reportRequest, {
2608
2602
  signal: input.signal
@@ -2622,8 +2616,6 @@ var SwapClient = class {
2622
2616
  emit({ type: "warning", executionId: build.executionId, warning });
2623
2617
  }
2624
2618
  }
2625
- const waitsForCompletion = (input.waitFor ?? "submitted") === "completed";
2626
- const requiresOrderStatus = build.isCrossChain || build.request?.confidentiality === "basic";
2627
2619
  const statusLookup = resolveOrderStatusLookup({
2628
2620
  recordId: reportRecordId ?? result.report?.recordId,
2629
2621
  orderId,
@@ -2631,7 +2623,7 @@ var SwapClient = class {
2631
2623
  router: orderRouter ?? build.router,
2632
2624
  chainId: orderChainId
2633
2625
  });
2634
- if (waitsForCompletion && requiresOrderStatus && !statusLookup) {
2626
+ if (shouldPollOrderStatus && !statusLookup) {
2635
2627
  throw new SwapSdkError(
2636
2628
  "INVALID_API_RESPONSE",
2637
2629
  "status",
@@ -2644,7 +2636,7 @@ var SwapClient = class {
2644
2636
  }
2645
2637
  );
2646
2638
  }
2647
- if (waitsForCompletion && statusLookup) {
2639
+ if (shouldPollOrderStatus && statusLookup) {
2648
2640
  const status = await this.waitForOrder({
2649
2641
  ...statusLookup,
2650
2642
  ...input.orderPolling,
@@ -2908,6 +2900,6 @@ function delay(ms, signal) {
2908
2900
  });
2909
2901
  }
2910
2902
 
2911
- export { ApiClient, DEFAULT_MCA_SIGNER_PRIORITY, ExecutorRegistry, SwapClient, SwapSdkError, asSwapSdkError, assertBaseUnitAmount, assertOrderStatusParams, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, buildOrderStatusQuery, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeOrderStatus, normalizeQuote, orderStatusParamsFromHistoryItem, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, resolveOrderStatusLookup, resolveSourceTxHash, resolveSwapReportRecordId, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, toApiAssetAddress, toApiChain };
2903
+ export { ApiClient, DEFAULT_MCA_SIGNER_PRIORITY, ExecutorRegistry, SwapClient, SwapSdkError, asSwapSdkError, assertBaseUnitAmount, assertOrderStatusParams, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, buildOrderStatusQuery, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeOrderStatus, normalizeQuote, orderStatusParamsFromHistoryItem, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, resolveOrderStatusLookup, resolveSourceTxHash, resolveSwapReportRecordId, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, shouldPollSwapOrderStatus, toApiAssetAddress, toApiChain };
2912
2904
  //# sourceMappingURL=index.mjs.map
2913
2905
  //# sourceMappingURL=index.mjs.map