@rhea-finance/cross-chain-aggregation-dex 2.0.7 → 2.0.8
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 +21 -8
- package/dist/executors/aptos.d.mts +1 -1
- package/dist/executors/aptos.d.ts +1 -1
- package/dist/executors/bitcoin.d.mts +1 -1
- package/dist/executors/bitcoin.d.ts +1 -1
- package/dist/executors/evm.d.mts +1 -1
- package/dist/executors/evm.d.ts +1 -1
- package/dist/executors/near.d.mts +1 -1
- package/dist/executors/near.d.ts +1 -1
- package/dist/executors/solana.d.mts +1 -1
- package/dist/executors/solana.d.ts +1 -1
- package/dist/executors/sui.d.mts +1 -1
- package/dist/executors/sui.d.ts +1 -1
- package/dist/executors/tron.d.mts +1 -1
- package/dist/executors/tron.d.ts +1 -1
- package/dist/executors/zcash.d.mts +1 -1
- package/dist/executors/zcash.d.ts +1 -1
- package/dist/index.d.mts +25 -7
- package/dist/index.d.ts +25 -7
- package/dist/index.js +155 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +150 -33
- package/dist/index.mjs.map +1 -1
- package/dist/{shared-COkGiqaz.d.mts → shared-BWv_QHdw.d.mts} +18 -7
- package/dist/{shared-COkGiqaz.d.ts → shared-BWv_QHdw.d.ts} +18 -7
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -26,6 +26,79 @@ function asSwapSdkError(error, stage) {
|
|
|
26
26
|
return new SwapSdkError("API_ERROR", stage, message, { cause: error });
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
// src/utils/orderStatus.ts
|
|
30
|
+
function resolveSwapReportRecordId(reportData) {
|
|
31
|
+
if (!reportData || typeof reportData !== "object") return "";
|
|
32
|
+
const id = reportData.id;
|
|
33
|
+
return id === void 0 || id === null ? "" : String(id).trim();
|
|
34
|
+
}
|
|
35
|
+
function buildOrderStatusQuery(params) {
|
|
36
|
+
const normalizedRecordId = String(params.recordId ?? "").trim();
|
|
37
|
+
if (normalizedRecordId) {
|
|
38
|
+
return { recordId: normalizedRecordId };
|
|
39
|
+
}
|
|
40
|
+
const query = {};
|
|
41
|
+
const orderId = params.orderId?.trim();
|
|
42
|
+
const txHash = params.txHash?.trim();
|
|
43
|
+
if (orderId) {
|
|
44
|
+
query.orderId = orderId;
|
|
45
|
+
} else if (txHash) {
|
|
46
|
+
query.txHash = txHash;
|
|
47
|
+
}
|
|
48
|
+
const router = params.router?.trim();
|
|
49
|
+
if (router) query.router = router;
|
|
50
|
+
const chainId = params.chainId;
|
|
51
|
+
if (chainId !== void 0 && chainId !== null && String(chainId).trim() !== "") {
|
|
52
|
+
query.chainId = chainId;
|
|
53
|
+
}
|
|
54
|
+
return query;
|
|
55
|
+
}
|
|
56
|
+
function resolveOrderStatusLookup(input) {
|
|
57
|
+
const recordId = String(input.recordId ?? "").trim();
|
|
58
|
+
if (recordId) {
|
|
59
|
+
return { recordId };
|
|
60
|
+
}
|
|
61
|
+
const router = input.router?.trim();
|
|
62
|
+
const orderId = input.orderId?.trim();
|
|
63
|
+
const txHash = input.txHash?.trim();
|
|
64
|
+
const statusKey = orderId || txHash;
|
|
65
|
+
if (!statusKey || !router) return void 0;
|
|
66
|
+
const chainId = input.chainId !== void 0 && input.chainId !== null && String(input.chainId).trim() !== "" ? String(input.chainId).trim() : void 0;
|
|
67
|
+
return {
|
|
68
|
+
...orderId ? { orderId } : { txHash },
|
|
69
|
+
router,
|
|
70
|
+
...chainId ? { chainId } : {}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function assertOrderStatusParams(params) {
|
|
74
|
+
const lookup = resolveOrderStatusLookup(params);
|
|
75
|
+
if (!lookup) {
|
|
76
|
+
throw new SwapSdkError(
|
|
77
|
+
"INVALID_REQUEST",
|
|
78
|
+
"status",
|
|
79
|
+
"Order status requires recordId, or orderId/txHash with router"
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return lookup;
|
|
83
|
+
}
|
|
84
|
+
function orderStatusParamsFromHistoryItem(item) {
|
|
85
|
+
const recordId = String(item.id ?? "").trim();
|
|
86
|
+
if (recordId) {
|
|
87
|
+
return { recordId };
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
...item.orderId ? { orderId: item.orderId } : {},
|
|
91
|
+
...item.sourceTxHash ? { txHash: item.sourceTxHash } : {},
|
|
92
|
+
...item.router ? { router: item.router } : {}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function resolveSourceTxHash(input) {
|
|
96
|
+
const direct = input.txHash?.trim();
|
|
97
|
+
if (direct) return direct;
|
|
98
|
+
const last = input.txHashes?.[input.txHashes.length - 1]?.trim();
|
|
99
|
+
return last || void 0;
|
|
100
|
+
}
|
|
101
|
+
|
|
29
102
|
// src/api/ApiClient.ts
|
|
30
103
|
var DEFAULT_RETRY = {
|
|
31
104
|
maxRetries: 2,
|
|
@@ -70,15 +143,26 @@ var ApiClient = class {
|
|
|
70
143
|
});
|
|
71
144
|
}
|
|
72
145
|
getOrderStatus(params, options = {}) {
|
|
146
|
+
const query = buildOrderStatusQuery(params);
|
|
147
|
+
if (!query.recordId && !query.orderId && !query.txHash) {
|
|
148
|
+
throw new SwapSdkError(
|
|
149
|
+
"INVALID_REQUEST",
|
|
150
|
+
"status",
|
|
151
|
+
"Order status requires recordId, or orderId/txHash with router"
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
if (!query.recordId && !query.router) {
|
|
155
|
+
throw new SwapSdkError(
|
|
156
|
+
"INVALID_REQUEST",
|
|
157
|
+
"status",
|
|
158
|
+
"Order status requires router when recordId is absent"
|
|
159
|
+
);
|
|
160
|
+
}
|
|
73
161
|
return this.request("/api/swap/order-status", "status", {
|
|
74
162
|
...options,
|
|
75
163
|
method: "GET",
|
|
76
164
|
retryableOperation: true,
|
|
77
|
-
query
|
|
78
|
-
orderId: params.orderId,
|
|
79
|
-
router: params.router,
|
|
80
|
-
chainId: params.chainId
|
|
81
|
-
}
|
|
165
|
+
query
|
|
82
166
|
});
|
|
83
167
|
}
|
|
84
168
|
report(body, options = {}) {
|
|
@@ -1979,9 +2063,13 @@ var McaSwapService = class {
|
|
|
1979
2063
|
onEvent: input.onEvent
|
|
1980
2064
|
});
|
|
1981
2065
|
if (input.quote.executionMode === "withdraw-near" && input.waitFor === "completed") {
|
|
1982
|
-
const
|
|
2066
|
+
const statusLookup = resolveOrderStatusLookup({
|
|
2067
|
+
recordId: result.report?.recordId,
|
|
1983
2068
|
orderId: nearStatusKey,
|
|
1984
|
-
router: input.quote.route.router
|
|
2069
|
+
router: input.quote.route.router
|
|
2070
|
+
}) ?? { orderId: nearStatusKey, router: input.quote.route.router };
|
|
2071
|
+
const status = await this.client.waitForOrder({
|
|
2072
|
+
...statusLookup,
|
|
1985
2073
|
...input.orderPolling,
|
|
1986
2074
|
signal: input.signal
|
|
1987
2075
|
});
|
|
@@ -2207,10 +2295,17 @@ var McaSwapService = class {
|
|
|
2207
2295
|
raw
|
|
2208
2296
|
};
|
|
2209
2297
|
emit({ type: "submitted", executionId, orderId });
|
|
2298
|
+
let reportRecordId;
|
|
2210
2299
|
if (this.reportMode === "auto") {
|
|
2211
2300
|
try {
|
|
2212
|
-
await this.client.reportRaw(reportRequest, {
|
|
2213
|
-
|
|
2301
|
+
const reportData = await this.client.reportRaw(reportRequest, {
|
|
2302
|
+
signal: input.signal
|
|
2303
|
+
});
|
|
2304
|
+
reportRecordId = resolveSwapReportRecordId(reportData) || void 0;
|
|
2305
|
+
result.report = {
|
|
2306
|
+
status: "reported",
|
|
2307
|
+
...reportRecordId ? { recordId: reportRecordId } : {}
|
|
2308
|
+
};
|
|
2214
2309
|
} catch (error) {
|
|
2215
2310
|
const warning = {
|
|
2216
2311
|
code: "REPORT_FAILED",
|
|
@@ -2222,9 +2317,13 @@ var McaSwapService = class {
|
|
|
2222
2317
|
}
|
|
2223
2318
|
}
|
|
2224
2319
|
if (input.waitFor === "completed") {
|
|
2225
|
-
const
|
|
2320
|
+
const statusLookup = resolveOrderStatusLookup({
|
|
2321
|
+
recordId: reportRecordId ?? result.report?.recordId,
|
|
2226
2322
|
orderId,
|
|
2227
|
-
router
|
|
2323
|
+
router
|
|
2324
|
+
}) ?? { orderId, router };
|
|
2325
|
+
const status = await this.client.waitForOrder({
|
|
2326
|
+
...statusLookup,
|
|
2228
2327
|
...input.orderPolling,
|
|
2229
2328
|
signal: input.signal
|
|
2230
2329
|
});
|
|
@@ -2502,10 +2601,17 @@ var SwapClient = class {
|
|
|
2502
2601
|
if (reportRequest) {
|
|
2503
2602
|
this.reportRequests.set(build.executionId, reportRequest);
|
|
2504
2603
|
}
|
|
2604
|
+
let reportRecordId;
|
|
2505
2605
|
if (this.reportMode === "auto" && reportRequest) {
|
|
2506
2606
|
try {
|
|
2507
|
-
await this.api.report(reportRequest, {
|
|
2508
|
-
|
|
2607
|
+
const reportData = await this.api.report(reportRequest, {
|
|
2608
|
+
signal: input.signal
|
|
2609
|
+
});
|
|
2610
|
+
reportRecordId = resolveSwapReportRecordId(reportData) || void 0;
|
|
2611
|
+
result.report = {
|
|
2612
|
+
status: "reported",
|
|
2613
|
+
...reportRecordId ? { recordId: reportRecordId } : {}
|
|
2614
|
+
};
|
|
2509
2615
|
} catch (error) {
|
|
2510
2616
|
const warning = {
|
|
2511
2617
|
code: "REPORT_FAILED",
|
|
@@ -2518,25 +2624,29 @@ var SwapClient = class {
|
|
|
2518
2624
|
}
|
|
2519
2625
|
const waitsForCompletion = (input.waitFor ?? "submitted") === "completed";
|
|
2520
2626
|
const requiresOrderStatus = build.isCrossChain || build.request?.confidentiality === "basic";
|
|
2521
|
-
|
|
2627
|
+
const statusLookup = resolveOrderStatusLookup({
|
|
2628
|
+
recordId: reportRecordId ?? result.report?.recordId,
|
|
2629
|
+
orderId,
|
|
2630
|
+
txHash: resolveSourceTxHash(chainResult),
|
|
2631
|
+
router: orderRouter ?? build.router,
|
|
2632
|
+
chainId: orderChainId
|
|
2633
|
+
});
|
|
2634
|
+
if (waitsForCompletion && requiresOrderStatus && !statusLookup) {
|
|
2522
2635
|
throw new SwapSdkError(
|
|
2523
2636
|
"INVALID_API_RESPONSE",
|
|
2524
2637
|
"status",
|
|
2525
|
-
"Swap submitted, but
|
|
2638
|
+
"Swap submitted, but no report record id, status key, or source transaction hash is available",
|
|
2526
2639
|
{
|
|
2527
2640
|
details: {
|
|
2528
2641
|
executionId: build.executionId,
|
|
2529
|
-
...result.txHash ? { txHash: result.txHash } : {},
|
|
2530
2642
|
router: orderRouter ?? build.router
|
|
2531
2643
|
}
|
|
2532
2644
|
}
|
|
2533
2645
|
);
|
|
2534
2646
|
}
|
|
2535
|
-
if (waitsForCompletion &&
|
|
2647
|
+
if (waitsForCompletion && statusLookup) {
|
|
2536
2648
|
const status = await this.waitForOrder({
|
|
2537
|
-
|
|
2538
|
-
router: orderRouter ?? build.router,
|
|
2539
|
-
chainId: orderChainId,
|
|
2649
|
+
...statusLookup,
|
|
2540
2650
|
...input.orderPolling,
|
|
2541
2651
|
signal: input.signal
|
|
2542
2652
|
});
|
|
@@ -2574,21 +2684,22 @@ var SwapClient = class {
|
|
|
2574
2684
|
});
|
|
2575
2685
|
}
|
|
2576
2686
|
async getOrderStatus(input) {
|
|
2577
|
-
const
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
router: input.router,
|
|
2581
|
-
chainId: input.chainId
|
|
2582
|
-
},
|
|
2583
|
-
{ signal: input.signal }
|
|
2584
|
-
);
|
|
2687
|
+
const { signal, ...reference } = input;
|
|
2688
|
+
const lookup = assertOrderStatusParams(reference);
|
|
2689
|
+
const raw = await this.api.getOrderStatus(lookup, { signal });
|
|
2585
2690
|
return {
|
|
2586
|
-
|
|
2587
|
-
router: input.router,
|
|
2691
|
+
...lookup,
|
|
2692
|
+
...lookup.router || input.router ? { router: lookup.router ?? input.router } : {},
|
|
2588
2693
|
status: normalizeOrderStatus(raw),
|
|
2589
2694
|
raw
|
|
2590
2695
|
};
|
|
2591
2696
|
}
|
|
2697
|
+
async getHistoryOrderStatus(item, options = {}) {
|
|
2698
|
+
return this.getOrderStatus({
|
|
2699
|
+
...orderStatusParamsFromHistoryItem(item),
|
|
2700
|
+
signal: options.signal
|
|
2701
|
+
});
|
|
2702
|
+
}
|
|
2592
2703
|
async waitForOrder(input) {
|
|
2593
2704
|
const intervalMs = input.intervalMs ?? 5e3;
|
|
2594
2705
|
const timeoutMs = input.timeoutMs;
|
|
@@ -2625,7 +2736,7 @@ var SwapClient = class {
|
|
|
2625
2736
|
reportRaw(request, options = {}) {
|
|
2626
2737
|
return this.api.report(request, options);
|
|
2627
2738
|
}
|
|
2628
|
-
report(result) {
|
|
2739
|
+
async report(result) {
|
|
2629
2740
|
const managedReport = this.managedSwapFlow.reportIfManaged(result);
|
|
2630
2741
|
if (managedReport) return managedReport;
|
|
2631
2742
|
const request = this.reportRequests.get(result.executionId);
|
|
@@ -2636,7 +2747,13 @@ var SwapClient = class {
|
|
|
2636
2747
|
`No report context for execution ${result.executionId}`
|
|
2637
2748
|
);
|
|
2638
2749
|
}
|
|
2639
|
-
|
|
2750
|
+
const raw = await this.api.report(request);
|
|
2751
|
+
const recordId = resolveSwapReportRecordId(raw) || void 0;
|
|
2752
|
+
result.report = {
|
|
2753
|
+
status: "reported",
|
|
2754
|
+
...recordId ? { recordId } : {}
|
|
2755
|
+
};
|
|
2756
|
+
return raw;
|
|
2640
2757
|
}
|
|
2641
2758
|
retryReport(result) {
|
|
2642
2759
|
return this.report(result);
|
|
@@ -2791,6 +2908,6 @@ function delay(ms, signal) {
|
|
|
2791
2908
|
});
|
|
2792
2909
|
}
|
|
2793
2910
|
|
|
2794
|
-
export { ApiClient, DEFAULT_MCA_SIGNER_PRIORITY, ExecutorRegistry, SwapClient, SwapSdkError, asSwapSdkError, assertBaseUnitAmount, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeOrderStatus, normalizeQuote, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, toApiAssetAddress, toApiChain };
|
|
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 };
|
|
2795
2912
|
//# sourceMappingURL=index.mjs.map
|
|
2796
2913
|
//# sourceMappingURL=index.mjs.map
|