@rhea-finance/cross-chain-aggregation-dex 2.0.2 → 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 +47 -13
- 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 +3 -4
- package/dist/executors/zcash.d.ts +3 -4
- package/dist/executors/zcash.js +22 -2
- package/dist/executors/zcash.js.map +1 -1
- package/dist/executors/zcash.mjs +22 -2
- 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 +51 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -10
- package/dist/index.mjs.map +1 -1
- package/dist/{registry-DjohbPPm.d.mts → shared-BEZXY_BM.d.mts} +37 -7
- package/dist/{registry-DjohbPPm.d.ts → shared-BEZXY_BM.d.ts} +37 -7
- package/package.json +4 -1
- package/dist/shared-BbfGrWrJ.d.ts +0 -18
- package/dist/shared-BxJ0H20s.d.mts +0 -18
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 });
|
|
@@ -2143,6 +2182,7 @@ var SwapClient = class {
|
|
|
2143
2182
|
orderId,
|
|
2144
2183
|
router: orderRouter ?? build.router,
|
|
2145
2184
|
chainId: orderChainId,
|
|
2185
|
+
...input.orderPolling,
|
|
2146
2186
|
signal: input.signal
|
|
2147
2187
|
});
|
|
2148
2188
|
result.status = status.status === "unknown" || status.status === "pending" ? "processing" : status.status;
|
|
@@ -2172,6 +2212,7 @@ var SwapClient = class {
|
|
|
2172
2212
|
return this.executeSwap({
|
|
2173
2213
|
build,
|
|
2174
2214
|
waitFor: regularInput.waitFor,
|
|
2215
|
+
orderPolling: regularInput.orderPolling,
|
|
2175
2216
|
signal: regularInput.signal,
|
|
2176
2217
|
onEvent: regularInput.onEvent,
|
|
2177
2218
|
beforeSign: regularInput.beforeSign
|
|
@@ -2195,8 +2236,8 @@ var SwapClient = class {
|
|
|
2195
2236
|
}
|
|
2196
2237
|
async waitForOrder(input) {
|
|
2197
2238
|
const intervalMs = input.intervalMs ?? 5e3;
|
|
2198
|
-
const timeoutMs = input.timeoutMs
|
|
2199
|
-
const startedAt = this.now();
|
|
2239
|
+
const timeoutMs = input.timeoutMs;
|
|
2240
|
+
const startedAt = timeoutMs === void 0 ? void 0 : this.now();
|
|
2200
2241
|
for (; ; ) {
|
|
2201
2242
|
if (input.signal?.aborted) {
|
|
2202
2243
|
throw new SwapSdkError(
|
|
@@ -2209,7 +2250,7 @@ var SwapClient = class {
|
|
|
2209
2250
|
if (result.status === "completed" || result.status === "failed" || result.status === "refunded" || result.status === "expired") {
|
|
2210
2251
|
return result;
|
|
2211
2252
|
}
|
|
2212
|
-
if (this.now() - startedAt >= timeoutMs) {
|
|
2253
|
+
if (timeoutMs !== void 0 && startedAt !== void 0 && this.now() - startedAt >= timeoutMs) {
|
|
2213
2254
|
throw new SwapSdkError(
|
|
2214
2255
|
"ORDER_TIMEOUT",
|
|
2215
2256
|
"status",
|