@rhea-finance/cross-chain-aggregation-dex 2.0.9 → 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/README.md CHANGED
@@ -497,7 +497,7 @@ Important normalized quote fields:
497
497
  | --- | --- | --- | --- |
498
498
  | `quote` | `Quote` | Yes | The value returned by `client.quote()`. Pass it directly without modification. |
499
499
  | `waitFor` | `"submitted" \| "source-confirmed" \| "completed"` | No | Default: `"submitted"`. |
500
- | `orderPolling` | `OrderPollingOptions` | No | Used with `waitFor: "completed"`. `intervalMs` defaults to `5000`; omit `timeoutMs` to poll indefinitely. |
500
+ | `orderPolling` | `OrderPollingOptions` | No | Used when cross-chain or confidential swaps poll order status (`waitFor: "source-confirmed"` or `"completed"`). `intervalMs` defaults to `5000`; omit `timeoutMs` to poll indefinitely. |
501
501
  | `signal` | `AbortSignal` | No | Cancels unfinished SDK requests or waits. It cannot withdraw an already broadcast transaction. |
502
502
  | `onEvent` | `(event) => void` | No | Receives lifecycle events for this swap only. |
503
503
  | `beforeSign` | `(preview) => void \| Promise<void>` | No | Called before each wallet signature or transaction request. It can be used for application confirmation UI. |
@@ -508,8 +508,8 @@ Wait modes:
508
508
  | Mode | Return condition |
509
509
  | --- | --- |
510
510
  | `submitted` | Returns after the wallet signs or broadcasts the source action. |
511
- | `source-confirmed` | Calls the required wallet confirmation method and returns only when it reports `confirmed`. A `failed` or malformed status throws `BROADCAST_FAILED`. |
512
- | `completed` | After source execution, polls the server until a delivery terminal state. Same-chain confidential swaps are included. A cross-chain or confidential swap without a usable status key fails at the `status` stage instead of being reported as completed. |
511
+ | `source-confirmed` | Waits for source-chain confirmation, then reports and polls `/api/swap/order-status` (preferring the report `recordId`) for cross-chain and confidential swaps. A `failed` or malformed source confirmation throws `BROADCAST_FAILED`. |
512
+ | `completed` | Same delivery polling as `source-confirmed`, but also waits through any required source confirmation first. Same-chain confidential swaps are included. A cross-chain or confidential swap without a usable status key fails at the `status` stage instead of being reported as completed. |
513
513
 
514
514
  `waitForOrder()` accepts the same polling values directly:
515
515
 
package/dist/index.d.mts CHANGED
@@ -375,6 +375,12 @@ interface BuildMcaWithdrawRelayerRequestInput {
375
375
  }
376
376
  declare function buildMcaWithdrawRelayerRequest(input: BuildMcaWithdrawRelayerRequestInput): SwapBuildRequestRaw;
377
377
 
378
+ /** Matches multi-chain Trade: poll after source execution when cross-chain or confidential. */
379
+ declare function shouldPollSwapOrderStatus(input: {
380
+ waitFor?: WaitMode;
381
+ isCrossChain: boolean;
382
+ confidentiality?: string;
383
+ }): boolean;
378
384
  declare function resolveSwapReportRecordId(reportData: unknown): string;
379
385
  type OrderStatusLookup = OrderReference;
380
386
  /** Matches multi-chain-lending `resolveSwapOrderStatusQuery` query shape. */
@@ -396,4 +402,4 @@ declare function resolveSourceTxHash(input: {
396
402
  declare function parseUnits(value: string, decimals: number): BaseUnitAmount;
397
403
  declare function formatUnits(value: BaseUnitAmount, decimals: number): string;
398
404
 
399
- export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderReference, type OrderStatusLookup, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaRequiredCollateralDecreaseInput, type ResolveMcaWithdrawPolicyInput, type RetryConfig, type SdkLogEntry, type SdkLogLevel, type SdkLogger, SwapBuild, SwapBuildDataRaw, SwapBuildRequestRaw, SwapClient, type SwapClientConfig, SwapCrossChainToTokensDataRaw, type SwapErrorCode, type SwapErrorStage, SwapExecutionResult, SwapFromTokensDataRaw, SwapHistoryAuthChallengeRaw, SwapHistoryAuthChallengeRequestRaw, SwapHistoryAuthProofRaw, SwapHistoryAuthTokenRaw, SwapHistoryAuthVerifyRequestRaw, SwapHistoryDataRaw, type SwapHistoryItem, type SwapHistoryPage, SwapHistoryParamsRaw, SwapHistoryRecordRaw, SwapInput, SwapLifecycleEvent, SwapMcaPayloadRaw, SwapMcaRelayerRequestRaw, SwapOrderStatusDataRaw, SwapOrderStatusParamsRaw, SwapOrderSubmitDataRaw, SwapOrderSubmitRequestRaw, SwapQuoteDataRaw, SwapQuoteRequestRaw, SwapReportDataRaw, SwapReportRequestRaw, SwapSdkError, type SwapSdkErrorOptions, type SwapTokenListItem, type TokenListRequest, WaitForOrderInput, WaitMode, asSwapSdkError, assertOrderStatusParams, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, buildOrderStatusQuery, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeQuote, orderStatusParamsFromHistoryItem, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, resolveOrderStatusLookup, resolveSourceTxHash, resolveSwapReportRecordId, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, toApiAssetAddress, toApiChain };
405
+ export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderReference, type OrderStatusLookup, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaRequiredCollateralDecreaseInput, type ResolveMcaWithdrawPolicyInput, type RetryConfig, type SdkLogEntry, type SdkLogLevel, type SdkLogger, SwapBuild, SwapBuildDataRaw, SwapBuildRequestRaw, SwapClient, type SwapClientConfig, SwapCrossChainToTokensDataRaw, type SwapErrorCode, type SwapErrorStage, SwapExecutionResult, SwapFromTokensDataRaw, SwapHistoryAuthChallengeRaw, SwapHistoryAuthChallengeRequestRaw, SwapHistoryAuthProofRaw, SwapHistoryAuthTokenRaw, SwapHistoryAuthVerifyRequestRaw, SwapHistoryDataRaw, type SwapHistoryItem, type SwapHistoryPage, SwapHistoryParamsRaw, SwapHistoryRecordRaw, SwapInput, SwapLifecycleEvent, SwapMcaPayloadRaw, SwapMcaRelayerRequestRaw, SwapOrderStatusDataRaw, SwapOrderStatusParamsRaw, SwapOrderSubmitDataRaw, SwapOrderSubmitRequestRaw, SwapQuoteDataRaw, SwapQuoteRequestRaw, SwapReportDataRaw, SwapReportRequestRaw, SwapSdkError, type SwapSdkErrorOptions, type SwapTokenListItem, type TokenListRequest, WaitForOrderInput, WaitMode, asSwapSdkError, assertOrderStatusParams, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, buildOrderStatusQuery, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeQuote, orderStatusParamsFromHistoryItem, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, resolveOrderStatusLookup, resolveSourceTxHash, resolveSwapReportRecordId, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, shouldPollSwapOrderStatus, toApiAssetAddress, toApiChain };
package/dist/index.d.ts CHANGED
@@ -375,6 +375,12 @@ interface BuildMcaWithdrawRelayerRequestInput {
375
375
  }
376
376
  declare function buildMcaWithdrawRelayerRequest(input: BuildMcaWithdrawRelayerRequestInput): SwapBuildRequestRaw;
377
377
 
378
+ /** Matches multi-chain Trade: poll after source execution when cross-chain or confidential. */
379
+ declare function shouldPollSwapOrderStatus(input: {
380
+ waitFor?: WaitMode;
381
+ isCrossChain: boolean;
382
+ confidentiality?: string;
383
+ }): boolean;
378
384
  declare function resolveSwapReportRecordId(reportData: unknown): string;
379
385
  type OrderStatusLookup = OrderReference;
380
386
  /** Matches multi-chain-lending `resolveSwapOrderStatusQuery` query shape. */
@@ -396,4 +402,4 @@ declare function resolveSourceTxHash(input: {
396
402
  declare function parseUnits(value: string, decimals: number): BaseUnitAmount;
397
403
  declare function formatUnits(value: BaseUnitAmount, decimals: number): string;
398
404
 
399
- export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderReference, type OrderStatusLookup, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaRequiredCollateralDecreaseInput, type ResolveMcaWithdrawPolicyInput, type RetryConfig, type SdkLogEntry, type SdkLogLevel, type SdkLogger, SwapBuild, SwapBuildDataRaw, SwapBuildRequestRaw, SwapClient, type SwapClientConfig, SwapCrossChainToTokensDataRaw, type SwapErrorCode, type SwapErrorStage, SwapExecutionResult, SwapFromTokensDataRaw, SwapHistoryAuthChallengeRaw, SwapHistoryAuthChallengeRequestRaw, SwapHistoryAuthProofRaw, SwapHistoryAuthTokenRaw, SwapHistoryAuthVerifyRequestRaw, SwapHistoryDataRaw, type SwapHistoryItem, type SwapHistoryPage, SwapHistoryParamsRaw, SwapHistoryRecordRaw, SwapInput, SwapLifecycleEvent, SwapMcaPayloadRaw, SwapMcaRelayerRequestRaw, SwapOrderStatusDataRaw, SwapOrderStatusParamsRaw, SwapOrderSubmitDataRaw, SwapOrderSubmitRequestRaw, SwapQuoteDataRaw, SwapQuoteRequestRaw, SwapReportDataRaw, SwapReportRequestRaw, SwapSdkError, type SwapSdkErrorOptions, type SwapTokenListItem, type TokenListRequest, WaitForOrderInput, WaitMode, asSwapSdkError, assertOrderStatusParams, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, buildOrderStatusQuery, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeQuote, orderStatusParamsFromHistoryItem, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, resolveOrderStatusLookup, resolveSourceTxHash, resolveSwapReportRecordId, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, toApiAssetAddress, toApiChain };
405
+ export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderReference, type OrderStatusLookup, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaRequiredCollateralDecreaseInput, type ResolveMcaWithdrawPolicyInput, type RetryConfig, type SdkLogEntry, type SdkLogLevel, type SdkLogger, SwapBuild, SwapBuildDataRaw, SwapBuildRequestRaw, SwapClient, type SwapClientConfig, SwapCrossChainToTokensDataRaw, type SwapErrorCode, type SwapErrorStage, SwapExecutionResult, SwapFromTokensDataRaw, SwapHistoryAuthChallengeRaw, SwapHistoryAuthChallengeRequestRaw, SwapHistoryAuthProofRaw, SwapHistoryAuthTokenRaw, SwapHistoryAuthVerifyRequestRaw, SwapHistoryDataRaw, type SwapHistoryItem, type SwapHistoryPage, SwapHistoryParamsRaw, SwapHistoryRecordRaw, SwapInput, SwapLifecycleEvent, SwapMcaPayloadRaw, SwapMcaRelayerRequestRaw, SwapOrderStatusDataRaw, SwapOrderStatusParamsRaw, SwapOrderSubmitDataRaw, SwapOrderSubmitRequestRaw, SwapQuoteDataRaw, SwapQuoteRequestRaw, SwapReportDataRaw, SwapReportRequestRaw, SwapSdkError, type SwapSdkErrorOptions, type SwapTokenListItem, type TokenListRequest, WaitForOrderInput, WaitMode, asSwapSdkError, assertOrderStatusParams, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, buildOrderStatusQuery, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeQuote, orderStatusParamsFromHistoryItem, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, resolveOrderStatusLookup, resolveSourceTxHash, resolveSwapReportRecordId, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, shouldPollSwapOrderStatus, toApiAssetAddress, toApiChain };
package/dist/index.js CHANGED
@@ -29,6 +29,11 @@ function asSwapSdkError(error, stage) {
29
29
  }
30
30
 
31
31
  // src/utils/orderStatus.ts
32
+ function shouldPollSwapOrderStatus(input) {
33
+ const waitMode = input.waitFor ?? "submitted";
34
+ const requiresOrderStatus = input.isCrossChain || input.confidentiality === "basic";
35
+ return requiresOrderStatus && waitMode !== "submitted";
36
+ }
32
37
  function resolveSwapReportRecordId(reportData) {
33
38
  if (!reportData || typeof reportData !== "object") return "";
34
39
  const record = reportData;
@@ -2064,41 +2069,13 @@ var McaSwapService = class {
2064
2069
  "MCA NEAR withdraw is missing a status deposit address"
2065
2070
  );
2066
2071
  }
2067
- const result = await this.client.executeSwap({
2072
+ return this.client.executeSwap({
2068
2073
  build,
2069
2074
  waitFor: input.quote.executionMode === "withdraw-near" && input.waitFor === "completed" ? "source-confirmed" : input.waitFor,
2070
2075
  orderPolling: input.orderPolling,
2071
2076
  signal: input.signal,
2072
2077
  onEvent: input.onEvent
2073
2078
  });
2074
- if (input.quote.executionMode === "withdraw-near" && input.waitFor === "completed") {
2075
- const statusLookup = resolveOrderStatusLookup({
2076
- recordId: result.report?.recordId,
2077
- orderId: nearStatusKey,
2078
- router: input.quote.route.router
2079
- }) ?? { orderId: nearStatusKey, router: input.quote.route.router };
2080
- const status = await this.client.waitForOrder({
2081
- ...statusLookup,
2082
- ...input.orderPolling,
2083
- signal: input.signal
2084
- });
2085
- this.emitEvent(
2086
- {
2087
- type: "order-status",
2088
- executionId: result.executionId,
2089
- status: status.status
2090
- },
2091
- input.onEvent
2092
- );
2093
- result.status = status.status === "unknown" || status.status === "pending" ? "processing" : status.status;
2094
- if (status.status === "completed") {
2095
- this.emitEvent(
2096
- { type: "completed", executionId: result.executionId },
2097
- input.onEvent
2098
- );
2099
- }
2100
- }
2101
- return result;
2102
2079
  }
2103
2080
  reportIfManaged(result) {
2104
2081
  const request = this.relayerReports.get(result.executionId);
@@ -2608,13 +2585,17 @@ var SwapClient = class {
2608
2585
  executionId: build.executionId
2609
2586
  });
2610
2587
  }
2611
- const waitsForCompletion = (input.waitFor ?? "submitted") === "completed";
2612
- const requiresOrderStatus = build.isCrossChain || build.request?.confidentiality === "basic";
2588
+ const waitMode = input.waitFor ?? "submitted";
2589
+ const shouldPollOrderStatus = shouldPollSwapOrderStatus({
2590
+ waitFor: waitMode,
2591
+ isCrossChain: build.isCrossChain,
2592
+ confidentiality: build.request?.confidentiality
2593
+ });
2613
2594
  const reportRequest = this.createReportRequest(build, result);
2614
2595
  if (reportRequest) {
2615
2596
  this.reportRequests.set(build.executionId, reportRequest);
2616
2597
  }
2617
- const mustReportForStatus = waitsForCompletion && requiresOrderStatus && Boolean(reportRequest);
2598
+ const mustReportForStatus = shouldPollOrderStatus && Boolean(reportRequest);
2618
2599
  const shouldReportNow = Boolean(reportRequest) && this.reportMode !== "disabled" && (this.reportMode === "auto" || mustReportForStatus);
2619
2600
  let reportRecordId;
2620
2601
  if (shouldReportNow && reportRequest) {
@@ -2644,7 +2625,7 @@ var SwapClient = class {
2644
2625
  router: orderRouter ?? build.router,
2645
2626
  chainId: orderChainId
2646
2627
  });
2647
- if (waitsForCompletion && requiresOrderStatus && !statusLookup) {
2628
+ if (shouldPollOrderStatus && !statusLookup) {
2648
2629
  throw new SwapSdkError(
2649
2630
  "INVALID_API_RESPONSE",
2650
2631
  "status",
@@ -2657,7 +2638,7 @@ var SwapClient = class {
2657
2638
  }
2658
2639
  );
2659
2640
  }
2660
- if (waitsForCompletion && statusLookup) {
2641
+ if (shouldPollOrderStatus && statusLookup) {
2661
2642
  const status = await this.waitForOrder({
2662
2643
  ...statusLookup,
2663
2644
  ...input.orderPolling,
@@ -2959,6 +2940,7 @@ exports.resolveSwapReportRecordId = resolveSwapReportRecordId;
2959
2940
  exports.selectMcaSigner = selectMcaSigner;
2960
2941
  exports.serializeMcaQuoteRequest = serializeMcaQuoteRequest;
2961
2942
  exports.serializeQuoteRequest = serializeQuoteRequest;
2943
+ exports.shouldPollSwapOrderStatus = shouldPollSwapOrderStatus;
2962
2944
  exports.toApiAssetAddress = toApiAssetAddress;
2963
2945
  exports.toApiChain = toApiChain;
2964
2946
  //# sourceMappingURL=index.js.map