@rhea-finance/cross-chain-aggregation-dex 2.1.0 → 2.1.2
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 +1 -1
- package/dist/index.d.mts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +39 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -56
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -382,7 +382,7 @@ if (result.status === "completed") {
|
|
|
382
382
|
}
|
|
383
383
|
```
|
|
384
384
|
|
|
385
|
-
`
|
|
385
|
+
After `POST /api/swap/report` returns an `id`, the SDK always polls `GET /api/swap/order-status?orderId=<report id>`. That report id is the only status key. The SDK does not query by `recordId` or source `txHash`. Confidential swaps also require order-status polling when they are same-chain. For confidential Near Intents builds, the SDK uses `deposit.orderId` when present and otherwise uses `deposit.depositAddress` as the status key. If a cross-chain or confidential swap provides none of these identifiers, the SDK throws `INVALID_API_RESPONSE` at the `status` stage instead of treating source-chain confirmation as completion.
|
|
386
386
|
|
|
387
387
|
The default polling interval is 5 seconds. There is no default polling timeout, so polling continues until the order reaches a terminal state or the supplied `AbortSignal` is aborted.
|
|
388
388
|
|
package/dist/index.d.mts
CHANGED
|
@@ -375,15 +375,20 @@ interface BuildMcaWithdrawRelayerRequestInput {
|
|
|
375
375
|
}
|
|
376
376
|
declare function buildMcaWithdrawRelayerRequest(input: BuildMcaWithdrawRelayerRequestInput): SwapBuildRequestRaw;
|
|
377
377
|
|
|
378
|
-
/**
|
|
378
|
+
/** Poll order-status after a report id, or for tracked swaps that wait past broadcast. */
|
|
379
379
|
declare function shouldPollSwapOrderStatus(input: {
|
|
380
380
|
waitFor?: WaitMode;
|
|
381
381
|
isCrossChain: boolean;
|
|
382
382
|
confidentiality?: string;
|
|
383
|
+
/** Present when POST /api/swap/report returned a history row id. */
|
|
384
|
+
reportRecordId?: string;
|
|
383
385
|
}): boolean;
|
|
384
386
|
declare function resolveSwapReportRecordId(reportData: unknown): string;
|
|
385
387
|
type OrderStatusLookup = OrderReference;
|
|
386
|
-
/**
|
|
388
|
+
/**
|
|
389
|
+
* Status queries use `orderId`.
|
|
390
|
+
* The report response `id` is that orderId and is sent alone.
|
|
391
|
+
*/
|
|
387
392
|
declare function buildOrderStatusQuery(params: SwapOrderStatusParamsRaw): Record<string, string | number>;
|
|
388
393
|
declare function resolveOrderStatusLookup(input: {
|
|
389
394
|
recordId?: string | number;
|
package/dist/index.d.ts
CHANGED
|
@@ -375,15 +375,20 @@ interface BuildMcaWithdrawRelayerRequestInput {
|
|
|
375
375
|
}
|
|
376
376
|
declare function buildMcaWithdrawRelayerRequest(input: BuildMcaWithdrawRelayerRequestInput): SwapBuildRequestRaw;
|
|
377
377
|
|
|
378
|
-
/**
|
|
378
|
+
/** Poll order-status after a report id, or for tracked swaps that wait past broadcast. */
|
|
379
379
|
declare function shouldPollSwapOrderStatus(input: {
|
|
380
380
|
waitFor?: WaitMode;
|
|
381
381
|
isCrossChain: boolean;
|
|
382
382
|
confidentiality?: string;
|
|
383
|
+
/** Present when POST /api/swap/report returned a history row id. */
|
|
384
|
+
reportRecordId?: string;
|
|
383
385
|
}): boolean;
|
|
384
386
|
declare function resolveSwapReportRecordId(reportData: unknown): string;
|
|
385
387
|
type OrderStatusLookup = OrderReference;
|
|
386
|
-
/**
|
|
388
|
+
/**
|
|
389
|
+
* Status queries use `orderId`.
|
|
390
|
+
* The report response `id` is that orderId and is sent alone.
|
|
391
|
+
*/
|
|
387
392
|
declare function buildOrderStatusQuery(params: SwapOrderStatusParamsRaw): Record<string, string | number>;
|
|
388
393
|
declare function resolveOrderStatusLookup(input: {
|
|
389
394
|
recordId?: string | number;
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ function asSwapSdkError(error, stage) {
|
|
|
30
30
|
|
|
31
31
|
// src/utils/orderStatus.ts
|
|
32
32
|
function shouldPollSwapOrderStatus(input) {
|
|
33
|
+
if (String(input.reportRecordId ?? "").trim()) return true;
|
|
33
34
|
const waitMode = input.waitFor ?? "submitted";
|
|
34
35
|
const requiresOrderStatus = input.isCrossChain || input.confidentiality === "basic";
|
|
35
36
|
return requiresOrderStatus && waitMode !== "submitted";
|
|
@@ -47,18 +48,13 @@ function resolveSwapReportRecordId(reportData) {
|
|
|
47
48
|
return "";
|
|
48
49
|
}
|
|
49
50
|
function buildOrderStatusQuery(params) {
|
|
50
|
-
const
|
|
51
|
-
if (
|
|
52
|
-
return {
|
|
51
|
+
const reportId = String(params.recordId ?? "").trim();
|
|
52
|
+
if (reportId) {
|
|
53
|
+
return { orderId: reportId };
|
|
53
54
|
}
|
|
54
|
-
const query = {};
|
|
55
55
|
const orderId = params.orderId?.trim();
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
query.orderId = orderId;
|
|
59
|
-
} else if (txHash) {
|
|
60
|
-
query.txHash = txHash;
|
|
61
|
-
}
|
|
56
|
+
if (!orderId) return {};
|
|
57
|
+
const query = { orderId };
|
|
62
58
|
const router = params.router?.trim();
|
|
63
59
|
if (router) query.router = router;
|
|
64
60
|
const chainId = params.chainId;
|
|
@@ -68,19 +64,17 @@ function buildOrderStatusQuery(params) {
|
|
|
68
64
|
return query;
|
|
69
65
|
}
|
|
70
66
|
function resolveOrderStatusLookup(input) {
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
return {
|
|
67
|
+
const reportId = String(input.recordId ?? "").trim();
|
|
68
|
+
if (reportId) {
|
|
69
|
+
return { orderId: reportId };
|
|
74
70
|
}
|
|
75
|
-
const router = input.router?.trim();
|
|
76
71
|
const orderId = input.orderId?.trim();
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
if (!statusKey || !router) return void 0;
|
|
72
|
+
if (!orderId) return void 0;
|
|
73
|
+
const router = input.router?.trim();
|
|
80
74
|
const chainId = input.chainId !== void 0 && input.chainId !== null && String(input.chainId).trim() !== "" ? String(input.chainId).trim() : void 0;
|
|
81
75
|
return {
|
|
82
|
-
|
|
83
|
-
router,
|
|
76
|
+
orderId,
|
|
77
|
+
...router ? { router } : {},
|
|
84
78
|
...chainId ? { chainId } : {}
|
|
85
79
|
};
|
|
86
80
|
}
|
|
@@ -90,19 +84,18 @@ function assertOrderStatusParams(params) {
|
|
|
90
84
|
throw new SwapSdkError(
|
|
91
85
|
"INVALID_REQUEST",
|
|
92
86
|
"status",
|
|
93
|
-
"Order status requires
|
|
87
|
+
"Order status requires orderId"
|
|
94
88
|
);
|
|
95
89
|
}
|
|
96
90
|
return lookup;
|
|
97
91
|
}
|
|
98
92
|
function orderStatusParamsFromHistoryItem(item) {
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
return {
|
|
93
|
+
const reportId = String(item.id ?? "").trim();
|
|
94
|
+
if (reportId) {
|
|
95
|
+
return { orderId: reportId };
|
|
102
96
|
}
|
|
103
97
|
return {
|
|
104
98
|
...item.orderId ? { orderId: item.orderId } : {},
|
|
105
|
-
...item.sourceTxHash ? { txHash: item.sourceTxHash } : {},
|
|
106
99
|
...item.router ? { router: item.router } : {}
|
|
107
100
|
};
|
|
108
101
|
}
|
|
@@ -158,18 +151,11 @@ var ApiClient = class {
|
|
|
158
151
|
}
|
|
159
152
|
getOrderStatus(params, options = {}) {
|
|
160
153
|
const query = buildOrderStatusQuery(params);
|
|
161
|
-
if (!query.
|
|
162
|
-
throw new SwapSdkError(
|
|
163
|
-
"INVALID_REQUEST",
|
|
164
|
-
"status",
|
|
165
|
-
"Order status requires recordId, or orderId/txHash with router"
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
if (!query.recordId && !query.router) {
|
|
154
|
+
if (!query.orderId) {
|
|
169
155
|
throw new SwapSdkError(
|
|
170
156
|
"INVALID_REQUEST",
|
|
171
157
|
"status",
|
|
172
|
-
"Order status requires
|
|
158
|
+
"Order status requires orderId"
|
|
173
159
|
);
|
|
174
160
|
}
|
|
175
161
|
return this.request("/api/swap/order-status", "status", {
|
|
@@ -2306,10 +2292,15 @@ var McaSwapService = class {
|
|
|
2306
2292
|
}
|
|
2307
2293
|
if (input.waitFor === "completed") {
|
|
2308
2294
|
const statusLookup = resolveOrderStatusLookup({
|
|
2309
|
-
recordId: reportRecordId ?? result.report?.recordId
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2295
|
+
recordId: reportRecordId ?? result.report?.recordId
|
|
2296
|
+
});
|
|
2297
|
+
if (!statusLookup) {
|
|
2298
|
+
throw new SwapSdkError(
|
|
2299
|
+
"INVALID_API_RESPONSE",
|
|
2300
|
+
"status",
|
|
2301
|
+
"MCA withdraw was reported without an id to query"
|
|
2302
|
+
);
|
|
2303
|
+
}
|
|
2313
2304
|
const status = await this.client.waitForOrder({
|
|
2314
2305
|
...statusLookup,
|
|
2315
2306
|
...input.orderPolling,
|
|
@@ -2533,8 +2524,6 @@ var SwapClient = class {
|
|
|
2533
2524
|
emit({ type: "signing-requested", executionId: build.executionId });
|
|
2534
2525
|
const chainResult = await executor.execute(build.execution, context);
|
|
2535
2526
|
let orderId = chainResult.orderId ?? build.order?.orderId;
|
|
2536
|
-
let orderRouter = build.order?.router;
|
|
2537
|
-
let orderChainId = build.order?.chainId;
|
|
2538
2527
|
if (chainResult.signature) {
|
|
2539
2528
|
if (build.execution.kind !== "evm-signature") {
|
|
2540
2529
|
throw new SwapSdkError(
|
|
@@ -2557,10 +2546,6 @@ var SwapClient = class {
|
|
|
2557
2546
|
{ signal: input.signal }
|
|
2558
2547
|
);
|
|
2559
2548
|
orderId = submitted.orderId;
|
|
2560
|
-
orderRouter = readNonEmptyString(submitted.router) ?? submitRouter;
|
|
2561
|
-
orderChainId = String(
|
|
2562
|
-
submitted.chainId ?? build.execution.request.chainId
|
|
2563
|
-
);
|
|
2564
2549
|
}
|
|
2565
2550
|
const result = {
|
|
2566
2551
|
executionId: build.executionId,
|
|
@@ -2586,16 +2571,12 @@ var SwapClient = class {
|
|
|
2586
2571
|
});
|
|
2587
2572
|
}
|
|
2588
2573
|
const waitMode = input.waitFor ?? "submitted";
|
|
2589
|
-
const
|
|
2590
|
-
waitFor: waitMode,
|
|
2591
|
-
isCrossChain: build.isCrossChain,
|
|
2592
|
-
confidentiality: build.request?.confidentiality
|
|
2593
|
-
});
|
|
2574
|
+
const requiresTrackedStatus = build.isCrossChain || build.request?.confidentiality === "basic";
|
|
2594
2575
|
const reportRequest = this.createReportRequest(build, result);
|
|
2595
2576
|
if (reportRequest) {
|
|
2596
2577
|
this.reportRequests.set(build.executionId, reportRequest);
|
|
2597
2578
|
}
|
|
2598
|
-
const mustReportForStatus =
|
|
2579
|
+
const mustReportForStatus = requiresTrackedStatus && waitMode !== "submitted" && Boolean(reportRequest);
|
|
2599
2580
|
const shouldReportNow = Boolean(reportRequest) && this.reportMode !== "disabled" && (this.reportMode === "auto" || mustReportForStatus);
|
|
2600
2581
|
let reportRecordId;
|
|
2601
2582
|
if (shouldReportNow && reportRequest) {
|
|
@@ -2618,22 +2599,24 @@ var SwapClient = class {
|
|
|
2618
2599
|
emit({ type: "warning", executionId: build.executionId, warning });
|
|
2619
2600
|
}
|
|
2620
2601
|
}
|
|
2602
|
+
const shouldPollOrderStatus = shouldPollSwapOrderStatus({
|
|
2603
|
+
waitFor: waitMode,
|
|
2604
|
+
isCrossChain: build.isCrossChain,
|
|
2605
|
+
confidentiality: build.request?.confidentiality,
|
|
2606
|
+
reportRecordId
|
|
2607
|
+
});
|
|
2621
2608
|
const statusLookup = resolveOrderStatusLookup({
|
|
2622
|
-
recordId: reportRecordId ?? result.report?.recordId
|
|
2623
|
-
orderId,
|
|
2624
|
-
txHash: resolveSourceTxHash(chainResult),
|
|
2625
|
-
router: orderRouter ?? build.router,
|
|
2626
|
-
chainId: orderChainId
|
|
2609
|
+
recordId: reportRecordId ?? result.report?.recordId
|
|
2627
2610
|
});
|
|
2628
2611
|
if (shouldPollOrderStatus && !statusLookup) {
|
|
2629
2612
|
throw new SwapSdkError(
|
|
2630
2613
|
"INVALID_API_RESPONSE",
|
|
2631
2614
|
"status",
|
|
2632
|
-
"Swap submitted, but
|
|
2615
|
+
"Swap submitted, but the report response did not include an id to query",
|
|
2633
2616
|
{
|
|
2634
2617
|
details: {
|
|
2635
2618
|
executionId: build.executionId,
|
|
2636
|
-
router:
|
|
2619
|
+
router: build.router
|
|
2637
2620
|
}
|
|
2638
2621
|
}
|
|
2639
2622
|
);
|