@rhea-finance/cross-chain-aggregation-dex 2.0.2 → 2.0.4
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 +71 -15
- 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 +59 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -11
- package/dist/index.mjs.map +1 -1
- package/dist/{registry-DjohbPPm.d.mts → shared-D0_DbMT2.d.mts} +44 -9
- package/dist/{registry-DjohbPPm.d.ts → shared-D0_DbMT2.d.ts} +44 -9
- 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(
|
|
@@ -939,7 +975,7 @@ function normalizeQuote(request, raw, receivedAt = Date.now()) {
|
|
|
939
975
|
estimatedOut: bestRoute.amountOut,
|
|
940
976
|
minAmountOut: bestRoute.minAmountOut,
|
|
941
977
|
route: bestRoute,
|
|
942
|
-
alternatives: raw.allQuotes.flatMap((route) => {
|
|
978
|
+
alternatives: readQuoteAlternatives(raw.allQuotes).flatMap((route) => {
|
|
943
979
|
try {
|
|
944
980
|
const normalized = normalizeRoute(route, false);
|
|
945
981
|
return normalized ? [normalized] : [];
|
|
@@ -953,6 +989,13 @@ function normalizeQuote(request, raw, receivedAt = Date.now()) {
|
|
|
953
989
|
raw
|
|
954
990
|
};
|
|
955
991
|
}
|
|
992
|
+
function readQuoteAlternatives(value) {
|
|
993
|
+
if (!Array.isArray(value)) return [];
|
|
994
|
+
return value.filter(isRecord);
|
|
995
|
+
}
|
|
996
|
+
function isRecord(value) {
|
|
997
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
998
|
+
}
|
|
956
999
|
function validateQuoteRequest(request) {
|
|
957
1000
|
assertBaseUnitAmount(request.amountIn);
|
|
958
1001
|
if (!Number.isInteger(request.slippageBps) || request.slippageBps < 0) {
|
|
@@ -1637,6 +1680,7 @@ var McaSwapService = class {
|
|
|
1637
1680
|
const result = await this.client.executeSwap({
|
|
1638
1681
|
build,
|
|
1639
1682
|
waitFor: input.quote.executionMode === "withdraw-near" && input.waitFor === "completed" ? "source-confirmed" : input.waitFor,
|
|
1683
|
+
orderPolling: input.orderPolling,
|
|
1640
1684
|
signal: input.signal,
|
|
1641
1685
|
onEvent: input.onEvent
|
|
1642
1686
|
});
|
|
@@ -1644,6 +1688,7 @@ var McaSwapService = class {
|
|
|
1644
1688
|
const status = await this.client.waitForOrder({
|
|
1645
1689
|
orderId: nearStatusKey,
|
|
1646
1690
|
router: input.quote.route.router,
|
|
1691
|
+
...input.orderPolling,
|
|
1647
1692
|
signal: input.signal
|
|
1648
1693
|
});
|
|
1649
1694
|
this.emitEvent(
|
|
@@ -1885,6 +1930,7 @@ var McaSwapService = class {
|
|
|
1885
1930
|
const status = await this.client.waitForOrder({
|
|
1886
1931
|
orderId,
|
|
1887
1932
|
router,
|
|
1933
|
+
...input.orderPolling,
|
|
1888
1934
|
signal: input.signal
|
|
1889
1935
|
});
|
|
1890
1936
|
emit({ type: "order-status", executionId, status: status.status });
|
|
@@ -2143,6 +2189,7 @@ var SwapClient = class {
|
|
|
2143
2189
|
orderId,
|
|
2144
2190
|
router: orderRouter ?? build.router,
|
|
2145
2191
|
chainId: orderChainId,
|
|
2192
|
+
...input.orderPolling,
|
|
2146
2193
|
signal: input.signal
|
|
2147
2194
|
});
|
|
2148
2195
|
result.status = status.status === "unknown" || status.status === "pending" ? "processing" : status.status;
|
|
@@ -2172,6 +2219,7 @@ var SwapClient = class {
|
|
|
2172
2219
|
return this.executeSwap({
|
|
2173
2220
|
build,
|
|
2174
2221
|
waitFor: regularInput.waitFor,
|
|
2222
|
+
orderPolling: regularInput.orderPolling,
|
|
2175
2223
|
signal: regularInput.signal,
|
|
2176
2224
|
onEvent: regularInput.onEvent,
|
|
2177
2225
|
beforeSign: regularInput.beforeSign
|
|
@@ -2195,8 +2243,8 @@ var SwapClient = class {
|
|
|
2195
2243
|
}
|
|
2196
2244
|
async waitForOrder(input) {
|
|
2197
2245
|
const intervalMs = input.intervalMs ?? 5e3;
|
|
2198
|
-
const timeoutMs = input.timeoutMs
|
|
2199
|
-
const startedAt = this.now();
|
|
2246
|
+
const timeoutMs = input.timeoutMs;
|
|
2247
|
+
const startedAt = timeoutMs === void 0 ? void 0 : this.now();
|
|
2200
2248
|
for (; ; ) {
|
|
2201
2249
|
if (input.signal?.aborted) {
|
|
2202
2250
|
throw new SwapSdkError(
|
|
@@ -2209,7 +2257,7 @@ var SwapClient = class {
|
|
|
2209
2257
|
if (result.status === "completed" || result.status === "failed" || result.status === "refunded" || result.status === "expired") {
|
|
2210
2258
|
return result;
|
|
2211
2259
|
}
|
|
2212
|
-
if (this.now() - startedAt >= timeoutMs) {
|
|
2260
|
+
if (timeoutMs !== void 0 && startedAt !== void 0 && this.now() - startedAt >= timeoutMs) {
|
|
2213
2261
|
throw new SwapSdkError(
|
|
2214
2262
|
"ORDER_TIMEOUT",
|
|
2215
2263
|
"status",
|