@rhea-finance/cross-chain-aggregation-dex 2.0.1 → 2.0.3
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 +567 -206
- package/dist/executors/aptos.d.mts +3 -4
- package/dist/executors/aptos.d.ts +3 -4
- package/dist/executors/aptos.js +22 -2
- package/dist/executors/aptos.js.map +1 -1
- package/dist/executors/aptos.mjs +22 -2
- package/dist/executors/aptos.mjs.map +1 -1
- package/dist/executors/bitcoin.d.mts +3 -4
- package/dist/executors/bitcoin.d.ts +3 -4
- package/dist/executors/bitcoin.js +22 -2
- package/dist/executors/bitcoin.js.map +1 -1
- package/dist/executors/bitcoin.mjs +22 -2
- package/dist/executors/bitcoin.mjs.map +1 -1
- package/dist/executors/evm.d.mts +3 -4
- package/dist/executors/evm.d.ts +3 -4
- package/dist/executors/evm.js +29 -13
- package/dist/executors/evm.js.map +1 -1
- package/dist/executors/evm.mjs +29 -13
- package/dist/executors/evm.mjs.map +1 -1
- package/dist/executors/near.d.mts +3 -4
- package/dist/executors/near.d.ts +3 -4
- package/dist/executors/near.js +22 -2
- package/dist/executors/near.js.map +1 -1
- package/dist/executors/near.mjs +22 -2
- package/dist/executors/near.mjs.map +1 -1
- package/dist/executors/solana.d.mts +3 -4
- package/dist/executors/solana.d.ts +3 -4
- package/dist/executors/solana.js +22 -2
- package/dist/executors/solana.js.map +1 -1
- package/dist/executors/solana.mjs +22 -2
- package/dist/executors/solana.mjs.map +1 -1
- package/dist/executors/sui.d.mts +3 -4
- package/dist/executors/sui.d.ts +3 -4
- package/dist/executors/sui.js +22 -2
- package/dist/executors/sui.js.map +1 -1
- package/dist/executors/sui.mjs +22 -2
- package/dist/executors/sui.mjs.map +1 -1
- package/dist/executors/tron.d.mts +3 -4
- package/dist/executors/tron.d.ts +3 -4
- package/dist/executors/tron.js +22 -2
- package/dist/executors/tron.js.map +1 -1
- package/dist/executors/tron.mjs +22 -2
- package/dist/executors/tron.mjs.map +1 -1
- package/dist/executors/zcash.d.mts +4 -5
- package/dist/executors/zcash.d.ts +4 -5
- package/dist/executors/zcash.js +24 -10
- package/dist/executors/zcash.js.map +1 -1
- package/dist/executors/zcash.mjs +24 -10
- package/dist/executors/zcash.mjs.map +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +59 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -25
- package/dist/index.mjs.map +1 -1
- package/dist/{registry-DRYUqs7T.d.mts → shared-BEZXY_BM.d.mts} +39 -12
- package/dist/{registry-DRYUqs7T.d.ts → shared-BEZXY_BM.d.ts} +39 -12
- package/package.json +4 -1
- package/dist/shared-BdH3hWuP.d.ts +0 -23
- package/dist/shared-BqpFeosz.d.mts +0 -23
package/dist/index.mjs
CHANGED
|
@@ -301,7 +301,11 @@ var ApiClient = class {
|
|
|
301
301
|
}
|
|
302
302
|
}
|
|
303
303
|
isEnvelope(value) {
|
|
304
|
-
|
|
304
|
+
if (typeof value !== "object" || value === null) return false;
|
|
305
|
+
if (!("code" in value) || typeof value.code !== "number") return false;
|
|
306
|
+
if (!("msg" in value) || typeof value.msg !== "string") return false;
|
|
307
|
+
if (value.code === 0 && !("data" in value)) return false;
|
|
308
|
+
return true;
|
|
305
309
|
}
|
|
306
310
|
readMessage(value) {
|
|
307
311
|
if (typeof value !== "object" || value === null || !("msg" in value)) {
|
|
@@ -510,16 +514,37 @@ function unsupportedChain(chain) {
|
|
|
510
514
|
var decimalStringSchema = z.string().regex(/^(0|[1-9]\d*)$/);
|
|
511
515
|
var nonEmptyStringSchema = z.string().trim().min(1);
|
|
512
516
|
var hexDataSchema = z.string().regex(/^0x(?:[0-9a-fA-F]{2})*$/);
|
|
513
|
-
|
|
517
|
+
z.number().int().positive();
|
|
518
|
+
var evmChainIdSchema = z.preprocess((value) => {
|
|
519
|
+
if (typeof value !== "string") return value;
|
|
520
|
+
const normalized = value.trim();
|
|
521
|
+
if (!/^(?:[1-9]\d*|0x[0-9a-fA-F]+)$/.test(normalized)) {
|
|
522
|
+
return value;
|
|
523
|
+
}
|
|
524
|
+
try {
|
|
525
|
+
const parsed = BigInt(normalized);
|
|
526
|
+
return parsed <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(parsed) : value;
|
|
527
|
+
} catch {
|
|
528
|
+
return value;
|
|
529
|
+
}
|
|
530
|
+
}, z.number().int().positive().max(Number.MAX_SAFE_INTEGER));
|
|
514
531
|
var evmQuantitySchema = z.string().regex(/^(?:0|[1-9]\d*|0x[0-9a-fA-F]+)$/).transform(
|
|
515
532
|
(value) => value.startsWith("0x") ? BigInt(value).toString() : value
|
|
516
533
|
);
|
|
534
|
+
var optionalEvmQuantitySchema = z.preprocess(
|
|
535
|
+
(value) => value === null || value === void 0 || value === "" ? void 0 : value,
|
|
536
|
+
evmQuantitySchema.optional()
|
|
537
|
+
);
|
|
517
538
|
var evmTxSchema = z.object({
|
|
518
539
|
to: nonEmptyStringSchema,
|
|
519
540
|
data: hexDataSchema,
|
|
520
541
|
value: evmQuantitySchema,
|
|
521
|
-
gasLimit:
|
|
522
|
-
|
|
542
|
+
gasLimit: optionalEvmQuantitySchema,
|
|
543
|
+
gasPrice: optionalEvmQuantitySchema,
|
|
544
|
+
maxFeePerGas: optionalEvmQuantitySchema,
|
|
545
|
+
maxPriorityFeePerGas: optionalEvmQuantitySchema,
|
|
546
|
+
from: nonEmptyStringSchema.optional(),
|
|
547
|
+
chainId: evmChainIdSchema
|
|
523
548
|
});
|
|
524
549
|
|
|
525
550
|
// src/normalizers/build.ts
|
|
@@ -544,7 +569,7 @@ var signingRequestSchema = z.object({
|
|
|
544
569
|
type: nonEmptyStringSchema,
|
|
545
570
|
router: nonEmptyStringSchema,
|
|
546
571
|
quoteId: nonEmptyStringSchema,
|
|
547
|
-
chainId:
|
|
572
|
+
chainId: evmChainIdSchema,
|
|
548
573
|
signingScheme: z.string().optional(),
|
|
549
574
|
typedData: z.object({
|
|
550
575
|
domain: z.record(z.string(), z.unknown()),
|
|
@@ -750,11 +775,20 @@ function normalizeEvmApproval(raw, chain) {
|
|
|
750
775
|
assertEvmChainId(chain, approveTx.chainId);
|
|
751
776
|
return {
|
|
752
777
|
tx: approveTx,
|
|
753
|
-
spender: nonEmptyStringSchema.parse(raw.approve.spender)
|
|
778
|
+
spender: readErc20ApproveSpender(approveTx.data) ?? nonEmptyStringSchema.parse(raw.approve.spender)
|
|
754
779
|
};
|
|
755
780
|
}
|
|
756
781
|
return void 0;
|
|
757
782
|
}
|
|
783
|
+
function readErc20ApproveSpender(data) {
|
|
784
|
+
const normalized = data.toLowerCase();
|
|
785
|
+
if (!normalized.startsWith("0x095ea7b3") || normalized.length < 10 + 64) {
|
|
786
|
+
return void 0;
|
|
787
|
+
}
|
|
788
|
+
const addressWord = normalized.slice(10, 10 + 64);
|
|
789
|
+
if (!/^[0-9a-f]{64}$/.test(addressWord)) return void 0;
|
|
790
|
+
return `0x${addressWord.slice(24)}`;
|
|
791
|
+
}
|
|
758
792
|
function laneFromChainType(chainType, fromChain) {
|
|
759
793
|
const normalized = chainType.toLowerCase();
|
|
760
794
|
const aliases = {
|
|
@@ -770,7 +804,9 @@ function laneFromChainType(chainType, fromChain) {
|
|
|
770
804
|
zec: "zcash",
|
|
771
805
|
sui: "sui"
|
|
772
806
|
};
|
|
773
|
-
if (normalized === "cross-chain"
|
|
807
|
+
if (normalized === "cross-chain" || normalized === "utxo") {
|
|
808
|
+
return laneFromChain(fromChain);
|
|
809
|
+
}
|
|
774
810
|
const lane = aliases[normalized];
|
|
775
811
|
if (!lane) {
|
|
776
812
|
throw new SwapSdkError(
|
|
@@ -1637,6 +1673,7 @@ var McaSwapService = class {
|
|
|
1637
1673
|
const result = await this.client.executeSwap({
|
|
1638
1674
|
build,
|
|
1639
1675
|
waitFor: input.quote.executionMode === "withdraw-near" && input.waitFor === "completed" ? "source-confirmed" : input.waitFor,
|
|
1676
|
+
orderPolling: input.orderPolling,
|
|
1640
1677
|
signal: input.signal,
|
|
1641
1678
|
onEvent: input.onEvent
|
|
1642
1679
|
});
|
|
@@ -1644,6 +1681,7 @@ var McaSwapService = class {
|
|
|
1644
1681
|
const status = await this.client.waitForOrder({
|
|
1645
1682
|
orderId: nearStatusKey,
|
|
1646
1683
|
router: input.quote.route.router,
|
|
1684
|
+
...input.orderPolling,
|
|
1647
1685
|
signal: input.signal
|
|
1648
1686
|
});
|
|
1649
1687
|
this.emitEvent(
|
|
@@ -1885,6 +1923,7 @@ var McaSwapService = class {
|
|
|
1885
1923
|
const status = await this.client.waitForOrder({
|
|
1886
1924
|
orderId,
|
|
1887
1925
|
router,
|
|
1926
|
+
...input.orderPolling,
|
|
1888
1927
|
signal: input.signal
|
|
1889
1928
|
});
|
|
1890
1929
|
emit({ type: "order-status", executionId, status: status.status });
|
|
@@ -2108,24 +2147,17 @@ var SwapClient = class {
|
|
|
2108
2147
|
report: { status: "skipped" },
|
|
2109
2148
|
raw: chainResult.raw ?? build.raw
|
|
2110
2149
|
};
|
|
2111
|
-
|
|
2150
|
+
emit({
|
|
2151
|
+
type: "submitted",
|
|
2152
|
+
executionId: build.executionId,
|
|
2153
|
+
...chainResult.txHash ? { txHash: chainResult.txHash } : {},
|
|
2154
|
+
...orderId ? { orderId } : {}
|
|
2155
|
+
});
|
|
2156
|
+
if (chainResult.status === "source-confirmed") {
|
|
2112
2157
|
emit({
|
|
2113
|
-
type: "
|
|
2158
|
+
type: "source-confirmed",
|
|
2114
2159
|
executionId: build.executionId
|
|
2115
2160
|
});
|
|
2116
|
-
} else {
|
|
2117
|
-
emit({
|
|
2118
|
-
type: "submitted",
|
|
2119
|
-
executionId: build.executionId,
|
|
2120
|
-
...chainResult.txHash ? { txHash: chainResult.txHash } : {},
|
|
2121
|
-
...orderId ? { orderId } : {}
|
|
2122
|
-
});
|
|
2123
|
-
if (chainResult.status === "source-confirmed") {
|
|
2124
|
-
emit({
|
|
2125
|
-
type: "source-confirmed",
|
|
2126
|
-
executionId: build.executionId
|
|
2127
|
-
});
|
|
2128
|
-
}
|
|
2129
2161
|
}
|
|
2130
2162
|
const reportRequest = this.createReportRequest(build, result);
|
|
2131
2163
|
if (reportRequest) {
|
|
@@ -2150,6 +2182,7 @@ var SwapClient = class {
|
|
|
2150
2182
|
orderId,
|
|
2151
2183
|
router: orderRouter ?? build.router,
|
|
2152
2184
|
chainId: orderChainId,
|
|
2185
|
+
...input.orderPolling,
|
|
2153
2186
|
signal: input.signal
|
|
2154
2187
|
});
|
|
2155
2188
|
result.status = status.status === "unknown" || status.status === "pending" ? "processing" : status.status;
|
|
@@ -2179,6 +2212,7 @@ var SwapClient = class {
|
|
|
2179
2212
|
return this.executeSwap({
|
|
2180
2213
|
build,
|
|
2181
2214
|
waitFor: regularInput.waitFor,
|
|
2215
|
+
orderPolling: regularInput.orderPolling,
|
|
2182
2216
|
signal: regularInput.signal,
|
|
2183
2217
|
onEvent: regularInput.onEvent,
|
|
2184
2218
|
beforeSign: regularInput.beforeSign
|
|
@@ -2202,8 +2236,8 @@ var SwapClient = class {
|
|
|
2202
2236
|
}
|
|
2203
2237
|
async waitForOrder(input) {
|
|
2204
2238
|
const intervalMs = input.intervalMs ?? 5e3;
|
|
2205
|
-
const timeoutMs = input.timeoutMs
|
|
2206
|
-
const startedAt = this.now();
|
|
2239
|
+
const timeoutMs = input.timeoutMs;
|
|
2240
|
+
const startedAt = timeoutMs === void 0 ? void 0 : this.now();
|
|
2207
2241
|
for (; ; ) {
|
|
2208
2242
|
if (input.signal?.aborted) {
|
|
2209
2243
|
throw new SwapSdkError(
|
|
@@ -2216,7 +2250,7 @@ var SwapClient = class {
|
|
|
2216
2250
|
if (result.status === "completed" || result.status === "failed" || result.status === "refunded" || result.status === "expired") {
|
|
2217
2251
|
return result;
|
|
2218
2252
|
}
|
|
2219
|
-
if (this.now() - startedAt >= timeoutMs) {
|
|
2253
|
+
if (timeoutMs !== void 0 && startedAt !== void 0 && this.now() - startedAt >= timeoutMs) {
|
|
2220
2254
|
throw new SwapSdkError(
|
|
2221
2255
|
"ORDER_TIMEOUT",
|
|
2222
2256
|
"status",
|