@rhea-finance/cross-chain-aggregation-dex 2.1.8 → 2.1.9

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
@@ -920,6 +920,10 @@ function normalizeTronExecution(raw, chain) {
920
920
  }
921
921
  function isTronRawDataTx(value) {
922
922
  if (typeof value !== "object" || value === null) return false;
923
+ const kind = Reflect.get(value, "kind");
924
+ if (typeof kind === "string" && kind.toLowerCase() === "tron_contract") {
925
+ return true;
926
+ }
923
927
  const format = Reflect.get(value, "format");
924
928
  if (typeof format === "string" && format.toLowerCase() === "tron-raw-data") {
925
929
  return true;
@@ -1136,6 +1140,7 @@ function serializeQuoteRequest(request) {
1136
1140
  quoteWaitingTimeMs: request.quoteWaitingTimeMs ?? DEFAULT_QUOTE_WAITING_TIME_MS,
1137
1141
  sameChainTimeoutMs: request.sameChainTimeoutMs ?? DEFAULT_SAME_CHAIN_TIMEOUT_MS,
1138
1142
  crossChainTimeoutMs: request.crossChainTimeoutMs ?? DEFAULT_CROSS_CHAIN_TIMEOUT_MS,
1143
+ ...request.excludeDexs !== void 0 ? { excludeDexs: [...request.excludeDexs] } : {},
1139
1144
  ...request.confidentiality ? { confidentiality: request.confidentiality } : {},
1140
1145
  sender: request.sender.trim(),
1141
1146
  ...request.recipient?.trim() ? { recipient: request.recipient.trim() } : {}
@@ -2592,18 +2597,63 @@ var SwapClient = class {
2592
2597
  if (input.onEvent !== this.config.onEvent) input.onEvent?.(event);
2593
2598
  };
2594
2599
  try {
2600
+ let activeBuild = build;
2595
2601
  const executor = this.registry.get(build.execution.kind);
2602
+ if (build.execution.kind === "tron-transaction" && build.execution.approval && !build.request) {
2603
+ throw new SwapSdkError(
2604
+ "INVALID_REQUEST",
2605
+ "sign",
2606
+ "Tron approval builds require the original build request to rebuild after approval"
2607
+ );
2608
+ }
2609
+ const needsTronRebuild = build.execution.kind === "tron-transaction" && Boolean(build.execution.approval) && Boolean(build.request);
2596
2610
  const context = {
2597
2611
  executionId: build.executionId,
2598
2612
  signal: input.signal,
2599
2613
  waitFor: input.waitFor ?? "submitted",
2600
2614
  emit,
2601
- ...input.beforeSign ? { beforeSign: input.beforeSign } : {}
2615
+ ...input.beforeSign ? { beforeSign: input.beforeSign } : {},
2616
+ ...needsTronRebuild ? {
2617
+ refreshTronExecution: async () => {
2618
+ const request = build.request;
2619
+ if (!request) {
2620
+ throw new SwapSdkError(
2621
+ "INVALID_REQUEST",
2622
+ "build",
2623
+ "Missing build request to rebuild Tron swap after approval"
2624
+ );
2625
+ }
2626
+ const raw = await this.api.build(request, {
2627
+ signal: input.signal
2628
+ });
2629
+ const refreshed = normalizeBuild(
2630
+ raw,
2631
+ build.executionId,
2632
+ request
2633
+ );
2634
+ if (refreshed.execution.kind !== "tron-transaction") {
2635
+ throw new SwapSdkError(
2636
+ "INVALID_API_RESPONSE",
2637
+ "build",
2638
+ "Rebuilt Tron swap must return a tron-transaction execution"
2639
+ );
2640
+ }
2641
+ if (refreshed.execution.approval) {
2642
+ throw new SwapSdkError(
2643
+ "INVALID_API_RESPONSE",
2644
+ "build",
2645
+ "Tron approval is still required after rebuild"
2646
+ );
2647
+ }
2648
+ activeBuild = refreshed;
2649
+ return refreshed.execution;
2650
+ }
2651
+ } : {}
2602
2652
  };
2603
2653
  await executor.validate(build.execution, context);
2604
2654
  emit({ type: "signing-requested", executionId: build.executionId });
2605
2655
  const chainResult = await executor.execute(build.execution, context);
2606
- let orderId = chainResult.orderId ?? build.order?.orderId;
2656
+ let orderId = chainResult.orderId ?? activeBuild.order?.orderId;
2607
2657
  if (chainResult.signature) {
2608
2658
  if (build.execution.kind !== "evm-signature") {
2609
2659
  throw new SwapSdkError(
@@ -2628,33 +2678,33 @@ var SwapClient = class {
2628
2678
  orderId = submitted.orderId;
2629
2679
  }
2630
2680
  const result = {
2631
- executionId: build.executionId,
2681
+ executionId: activeBuild.executionId,
2632
2682
  status: chainResult.status,
2633
- router: build.router,
2683
+ router: activeBuild.router,
2634
2684
  ...chainResult.txHash ? { txHash: chainResult.txHash } : {},
2635
2685
  ...chainResult.txHashes ? { txHashes: chainResult.txHashes } : {},
2636
2686
  ...orderId ? { orderId } : {},
2637
- ...build.deposit?.depositAddress ? { depositAddress: build.deposit.depositAddress } : {},
2687
+ ...activeBuild.deposit?.depositAddress ? { depositAddress: activeBuild.deposit.depositAddress } : {},
2638
2688
  report: { status: "skipped" },
2639
- raw: chainResult.raw ?? build.raw
2689
+ raw: chainResult.raw ?? activeBuild.raw
2640
2690
  };
2641
2691
  emit({
2642
2692
  type: "submitted",
2643
- executionId: build.executionId,
2693
+ executionId: activeBuild.executionId,
2644
2694
  ...chainResult.txHash ? { txHash: chainResult.txHash } : {},
2645
2695
  ...orderId ? { orderId } : {}
2646
2696
  });
2647
2697
  if (chainResult.status === "source-confirmed") {
2648
2698
  emit({
2649
2699
  type: "source-confirmed",
2650
- executionId: build.executionId
2700
+ executionId: activeBuild.executionId
2651
2701
  });
2652
2702
  }
2653
2703
  const waitMode = input.waitFor ?? "submitted";
2654
- const requiresTrackedStatus = build.isCrossChain || build.request?.confidentiality === "basic";
2655
- const reportRequest = this.createReportRequest(build, result);
2704
+ const requiresTrackedStatus = activeBuild.isCrossChain || activeBuild.request?.confidentiality === "basic";
2705
+ const reportRequest = this.createReportRequest(activeBuild, result);
2656
2706
  if (reportRequest) {
2657
- this.reportRequests.set(build.executionId, reportRequest);
2707
+ this.reportRequests.set(activeBuild.executionId, reportRequest);
2658
2708
  }
2659
2709
  const mustReportForStatus = requiresTrackedStatus && waitMode !== "submitted" && Boolean(reportRequest);
2660
2710
  const shouldReportNow = Boolean(reportRequest) && this.reportMode !== "disabled" && (this.reportMode === "auto" || mustReportForStatus);
@@ -2677,18 +2727,22 @@ var SwapClient = class {
2677
2727
  cause: error
2678
2728
  };
2679
2729
  result.report = { status: "failed", warning };
2680
- emit({ type: "warning", executionId: build.executionId, warning });
2730
+ emit({
2731
+ type: "warning",
2732
+ executionId: activeBuild.executionId,
2733
+ warning
2734
+ });
2681
2735
  }
2682
2736
  }
2683
2737
  const shouldPollOrderStatus = shouldPollSwapOrderStatus({
2684
2738
  waitFor: waitMode,
2685
- isCrossChain: build.isCrossChain,
2686
- confidentiality: build.request?.confidentiality,
2739
+ isCrossChain: activeBuild.isCrossChain,
2740
+ confidentiality: activeBuild.request?.confidentiality,
2687
2741
  reportRecordId
2688
2742
  });
2689
2743
  const statusLookup = resolveOrderStatusLookup({
2690
2744
  recordId: reportRecordId ?? result.report?.recordId,
2691
- router: build.order?.router ?? build.router
2745
+ router: activeBuild.order?.router ?? activeBuild.router
2692
2746
  });
2693
2747
  if (shouldPollOrderStatus && !statusLookup) {
2694
2748
  throw new SwapSdkError(
@@ -2697,8 +2751,8 @@ var SwapClient = class {
2697
2751
  "Swap submitted, but the report response did not include an id to query",
2698
2752
  {
2699
2753
  details: {
2700
- executionId: build.executionId,
2701
- router: build.router
2754
+ executionId: activeBuild.executionId,
2755
+ router: activeBuild.router
2702
2756
  }
2703
2757
  }
2704
2758
  );