@rhea-finance/cross-chain-aggregation-dex 2.1.6 → 2.1.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.
Files changed (57) hide show
  1. package/dist/executors/aptos.d.mts +1 -1
  2. package/dist/executors/aptos.d.ts +1 -1
  3. package/dist/executors/aptos.js +2 -0
  4. package/dist/executors/aptos.js.map +1 -1
  5. package/dist/executors/aptos.mjs +2 -0
  6. package/dist/executors/aptos.mjs.map +1 -1
  7. package/dist/executors/bitcoin.d.mts +1 -1
  8. package/dist/executors/bitcoin.d.ts +1 -1
  9. package/dist/executors/bitcoin.js +2 -0
  10. package/dist/executors/bitcoin.js.map +1 -1
  11. package/dist/executors/bitcoin.mjs +2 -0
  12. package/dist/executors/bitcoin.mjs.map +1 -1
  13. package/dist/executors/evm.d.mts +1 -1
  14. package/dist/executors/evm.d.ts +1 -1
  15. package/dist/executors/evm.js +2 -0
  16. package/dist/executors/evm.js.map +1 -1
  17. package/dist/executors/evm.mjs +2 -0
  18. package/dist/executors/evm.mjs.map +1 -1
  19. package/dist/executors/near.d.mts +1 -1
  20. package/dist/executors/near.d.ts +1 -1
  21. package/dist/executors/near.js +2 -0
  22. package/dist/executors/near.js.map +1 -1
  23. package/dist/executors/near.mjs +2 -0
  24. package/dist/executors/near.mjs.map +1 -1
  25. package/dist/executors/solana.d.mts +1 -1
  26. package/dist/executors/solana.d.ts +1 -1
  27. package/dist/executors/solana.js +2 -0
  28. package/dist/executors/solana.js.map +1 -1
  29. package/dist/executors/solana.mjs +2 -0
  30. package/dist/executors/solana.mjs.map +1 -1
  31. package/dist/executors/sui.d.mts +1 -1
  32. package/dist/executors/sui.d.ts +1 -1
  33. package/dist/executors/sui.js +2 -0
  34. package/dist/executors/sui.js.map +1 -1
  35. package/dist/executors/sui.mjs +2 -0
  36. package/dist/executors/sui.mjs.map +1 -1
  37. package/dist/executors/tron.d.mts +8 -2
  38. package/dist/executors/tron.d.ts +8 -2
  39. package/dist/executors/tron.js +157 -39
  40. package/dist/executors/tron.js.map +1 -1
  41. package/dist/executors/tron.mjs +157 -39
  42. package/dist/executors/tron.mjs.map +1 -1
  43. package/dist/executors/zcash.d.mts +1 -1
  44. package/dist/executors/zcash.d.ts +1 -1
  45. package/dist/executors/zcash.js +2 -0
  46. package/dist/executors/zcash.js.map +1 -1
  47. package/dist/executors/zcash.mjs +2 -0
  48. package/dist/executors/zcash.mjs.map +1 -1
  49. package/dist/index.d.mts +16 -3
  50. package/dist/index.d.ts +16 -3
  51. package/dist/index.js +175 -13
  52. package/dist/index.js.map +1 -1
  53. package/dist/index.mjs +173 -14
  54. package/dist/index.mjs.map +1 -1
  55. package/dist/{shared-DpC8G2U4.d.mts → shared-v1w63b8X.d.mts} +20 -1
  56. package/dist/{shared-DpC8G2U4.d.ts → shared-v1w63b8X.d.ts} +20 -1
  57. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,5 +1,67 @@
1
1
  import { z, ZodError } from 'zod';
2
2
 
3
+ // src/core/catchLog.ts
4
+ var MAX_CAUSE_DEPTH = 8;
5
+ var catchLoggingEnabled = false;
6
+ function setSdkCatchLogging(enabled) {
7
+ catchLoggingEnabled = Boolean(enabled);
8
+ }
9
+ function isSdkCatchLoggingEnabled() {
10
+ return catchLoggingEnabled;
11
+ }
12
+ function readProp(value, key) {
13
+ if (typeof value !== "object" || value === null) return void 0;
14
+ return Reflect.get(value, key);
15
+ }
16
+ function redactSensitive(text) {
17
+ return text.replace(/(https?:\/\/[^\s?'"`]+)\?[^\s'"`]*/gi, "$1?[redacted]");
18
+ }
19
+ function serializeCaughtError(error, depth = 0) {
20
+ if (error === null || error === void 0) {
21
+ return { value: error };
22
+ }
23
+ if (typeof error !== "object") {
24
+ return {
25
+ value: typeof error === "string" ? redactSensitive(error) : error
26
+ };
27
+ }
28
+ const name = typeof readProp(error, "name") === "string" ? readProp(error, "name") : void 0;
29
+ const message = typeof readProp(error, "message") === "string" ? redactSensitive(readProp(error, "message")) : void 0;
30
+ const code = readProp(error, "code");
31
+ const stage = readProp(error, "stage");
32
+ const details = readProp(error, "details");
33
+ const stack = typeof readProp(error, "stack") === "string" ? redactSensitive(readProp(error, "stack")) : void 0;
34
+ const options = readProp(error, "options");
35
+ const optionsCause = typeof options === "object" && options !== null ? Reflect.get(options, "cause") : void 0;
36
+ const directCause = readProp(error, "cause");
37
+ const cause = optionsCause ?? directCause;
38
+ const out = {
39
+ ...name ? { name } : {},
40
+ ...message !== void 0 ? { message } : {},
41
+ ...code !== void 0 ? { code } : {},
42
+ ...stage !== void 0 ? { stage } : {},
43
+ ...details !== void 0 ? { details } : {},
44
+ ...stack ? { stack } : {}
45
+ };
46
+ if (cause !== void 0 && depth < MAX_CAUSE_DEPTH) {
47
+ out.cause = serializeCaughtError(cause, depth + 1);
48
+ } else if (Object.keys(out).length === 0) {
49
+ try {
50
+ out.raw = JSON.parse(
51
+ redactSensitive(JSON.stringify(error) ?? "null")
52
+ );
53
+ } catch {
54
+ out.raw = redactSensitive(String(error));
55
+ }
56
+ }
57
+ return out;
58
+ }
59
+ function logSdkCaughtError(scope, error) {
60
+ if (!catchLoggingEnabled) return;
61
+ const payload = serializeCaughtError(error);
62
+ console.error(`[cross-chain-aggregation-dex] catch:${scope}`, payload);
63
+ }
64
+
3
65
  // src/core/errors.ts
4
66
  var SwapSdkError = class extends Error {
5
67
  constructor(code, stage, message, options = {}) {
@@ -21,6 +83,7 @@ var SwapSdkError = class extends Error {
21
83
  }
22
84
  };
23
85
  function asSwapSdkError(error, stage) {
86
+ logSdkCaughtError(`asSwapSdkError:${stage}`, error);
24
87
  if (error instanceof SwapSdkError) return error;
25
88
  const message = error instanceof Error ? error.message : String(error);
26
89
  return new SwapSdkError("API_ERROR", stage, message, { cause: error });
@@ -118,6 +181,9 @@ var ApiClient = class {
118
181
  constructor(config) {
119
182
  this.config = config;
120
183
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
184
+ if (config.debugCatchLogging !== void 0) {
185
+ setSdkCatchLogging(config.debugCatchLogging);
186
+ }
121
187
  const fetchImpl = config.fetch ?? globalThis.fetch;
122
188
  if (typeof fetchImpl !== "function") {
123
189
  throw new SwapSdkError(
@@ -300,6 +366,7 @@ var ApiClient = class {
300
366
  }
301
367
  return parsed.data;
302
368
  } catch (error) {
369
+ logSdkCaughtError("api/ApiClient.ts", error);
303
370
  if (error instanceof SwapSdkError) throw error;
304
371
  if (controller.signal.aborted) {
305
372
  throw new SwapSdkError(
@@ -360,6 +427,7 @@ var ApiClient = class {
360
427
  try {
361
428
  return text ? JSON.parse(text) : {};
362
429
  } catch (error) {
430
+ logSdkCaughtError("api/ApiClient.ts", error);
363
431
  throw new SwapSdkError(
364
432
  status >= 400 ? "HTTP_ERROR" : "INVALID_API_RESPONSE",
365
433
  stage,
@@ -653,10 +721,23 @@ var transferBaseSchema = z.object({
653
721
  amount: decimalStringSchema,
654
722
  depositAddress: nonEmptyStringSchema
655
723
  });
656
- var tronTxSchema = transferBaseSchema.extend({
724
+ var tronTransferSchema = transferBaseSchema.extend({
657
725
  tokenAddress: z.string().optional(),
658
726
  standard: z.string().optional()
659
727
  });
728
+ var tronUnsignedTxSchema = z.object({
729
+ txID: nonEmptyStringSchema,
730
+ raw_data: z.record(z.string(), z.unknown()),
731
+ raw_data_hex: nonEmptyStringSchema,
732
+ visible: z.boolean().optional()
733
+ }).passthrough();
734
+ var tronRawDataTxSchema = tronUnsignedTxSchema.extend({
735
+ format: z.string().optional(),
736
+ approveTxID: z.string().optional(),
737
+ approve_raw_data: z.record(z.string(), z.unknown()).optional(),
738
+ approve_raw_data_hex: z.string().optional(),
739
+ approveVisible: z.boolean().optional()
740
+ }).passthrough();
660
741
  var bitcoinTxSchema = transferBaseSchema.extend({
661
742
  feeRate: z.number().positive().optional()
662
743
  });
@@ -698,6 +779,7 @@ function normalizeBuild(raw, executionId = createExecutionId(), request) {
698
779
  raw
699
780
  };
700
781
  } catch (error) {
782
+ logSdkCaughtError("normalizers/build.ts", error);
701
783
  if (error instanceof SwapSdkError) throw error;
702
784
  throw invalidBuild(error);
703
785
  }
@@ -739,18 +821,8 @@ function normalizeExecution(raw, lane, chain) {
739
821
  transactions: Array.isArray(transactions) ? transactions : [transactions]
740
822
  };
741
823
  }
742
- case "tron": {
743
- const tx = tronTxSchema.parse(raw.tx);
744
- assertKind(tx.kind, ["tron_transfer"]);
745
- return {
746
- kind: "tron-transfer",
747
- chain,
748
- amount: tx.amount,
749
- depositAddress: tx.depositAddress,
750
- ...tx.tokenAddress ? { tokenAddress: tx.tokenAddress } : {},
751
- ...tx.standard ? { standard: tx.standard } : {}
752
- };
753
- }
824
+ case "tron":
825
+ return normalizeTronExecution(raw, chain);
754
826
  case "bitcoin": {
755
827
  const tx = bitcoinTxSchema.parse(raw.tx);
756
828
  assertKind(tx.kind, ["btc_transfer", "utxo_transfer"]);
@@ -822,6 +894,82 @@ function normalizeEvmApproval(raw, chain) {
822
894
  }
823
895
  return void 0;
824
896
  }
897
+ function normalizeTronExecution(raw, chain) {
898
+ if (isTronRawDataTx(raw.tx)) {
899
+ const tx2 = tronRawDataTxSchema.parse(raw.tx);
900
+ const transaction = toTronUnsignedTransaction(tx2);
901
+ const approval = normalizeTronApproval(tx2, raw);
902
+ return {
903
+ kind: "tron-transaction",
904
+ chain,
905
+ format: normalizeTronFormat(tx2.format),
906
+ transaction,
907
+ ...approval ? { approval } : {}
908
+ };
909
+ }
910
+ const tx = tronTransferSchema.parse(raw.tx);
911
+ assertKind(tx.kind, ["tron_transfer"]);
912
+ return {
913
+ kind: "tron-transfer",
914
+ chain,
915
+ amount: tx.amount,
916
+ depositAddress: tx.depositAddress,
917
+ ...tx.tokenAddress ? { tokenAddress: tx.tokenAddress } : {},
918
+ ...tx.standard ? { standard: tx.standard } : {}
919
+ };
920
+ }
921
+ function isTronRawDataTx(value) {
922
+ if (typeof value !== "object" || value === null) return false;
923
+ const format = Reflect.get(value, "format");
924
+ if (typeof format === "string" && format.toLowerCase() === "tron-raw-data") {
925
+ return true;
926
+ }
927
+ return typeof Reflect.get(value, "txID") === "string" && typeof Reflect.get(value, "raw_data_hex") === "string" && typeof Reflect.get(value, "raw_data") === "object" && Reflect.get(value, "raw_data") !== null;
928
+ }
929
+ function normalizeTronFormat(format) {
930
+ const normalized = format?.trim();
931
+ return normalized && normalized.length > 0 ? normalized : "tron-raw-data";
932
+ }
933
+ function toTronUnsignedTransaction(value) {
934
+ const {
935
+ txID,
936
+ raw_data,
937
+ raw_data_hex,
938
+ visible,
939
+ format: _format,
940
+ approveTxID: _approveTxID,
941
+ approve_raw_data: _approveRawData,
942
+ approve_raw_data_hex: _approveRawDataHex,
943
+ approveVisible: _approveVisible,
944
+ approve_payload: _approvePayload,
945
+ approveTxId: _approveTxId,
946
+ ...rest
947
+ } = value;
948
+ return {
949
+ ...rest,
950
+ txID,
951
+ raw_data,
952
+ raw_data_hex,
953
+ ...visible === void 0 ? {} : { visible }
954
+ };
955
+ }
956
+ function normalizeTronApproval(tx, raw) {
957
+ if (typeof tx.approveTxID === "string" && tx.approveTxID.trim() && tx.approve_raw_data && typeof tx.approve_raw_data_hex === "string" && tx.approve_raw_data_hex.trim()) {
958
+ return {
959
+ transaction: {
960
+ txID: tx.approveTxID.trim(),
961
+ raw_data: tx.approve_raw_data,
962
+ raw_data_hex: tx.approve_raw_data_hex.trim(),
963
+ visible: tx.approveVisible ?? false
964
+ }
965
+ };
966
+ }
967
+ if (raw.approve?.tx && isTronRawDataTx(raw.approve.tx)) {
968
+ const approveTx = tronUnsignedTxSchema.parse(raw.approve.tx);
969
+ return { transaction: toTronUnsignedTransaction(approveTx) };
970
+ }
971
+ return void 0;
972
+ }
825
973
  function readErc20ApproveSpender(data) {
826
974
  const normalized = data.toLowerCase();
827
975
  if (!normalized.startsWith("0x095ea7b3") || normalized.length < 10 + 64) {
@@ -1131,6 +1279,7 @@ function validateResponseAmount(value, field) {
1131
1279
  try {
1132
1280
  return assertBaseUnitAmount(value);
1133
1281
  } catch (error) {
1282
+ logSdkCaughtError("normalizers/quote.ts", error);
1134
1283
  throw invalidQuote(`Quote response has invalid ${field}`, error);
1135
1284
  }
1136
1285
  }
@@ -1893,6 +2042,7 @@ function normalizeDeposit2(value) {
1893
2042
  try {
1894
2043
  return parseUnits(decimal, 24);
1895
2044
  } catch (error) {
2045
+ logSdkCaughtError("mca/withdraw.ts", error);
1896
2046
  throw new SwapSdkError(
1897
2047
  "INVALID_API_RESPONSE",
1898
2048
  "build",
@@ -2114,6 +2264,7 @@ var McaSwapService = class {
2114
2264
  }
2115
2265
  })).trim();
2116
2266
  } catch (error) {
2267
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2117
2268
  if (error instanceof SwapSdkError) throw error;
2118
2269
  throw new SwapSdkError(
2119
2270
  "SIGNING_FAILED",
@@ -2203,6 +2354,7 @@ var McaSwapService = class {
2203
2354
  ...reportRecordId ? { recordId: reportRecordId } : {}
2204
2355
  };
2205
2356
  } catch (error) {
2357
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2206
2358
  const warning = {
2207
2359
  code: "REPORT_FAILED",
2208
2360
  message: "MCA withdraw submitted but report failed",
@@ -2237,6 +2389,7 @@ var McaSwapService = class {
2237
2389
  }
2238
2390
  return result;
2239
2391
  } catch (error) {
2392
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2240
2393
  const sdkError = asSwapSdkError(error, "submit");
2241
2394
  emit({ type: "failed", executionId, error: sdkError });
2242
2395
  throw sdkError;
@@ -2247,6 +2400,7 @@ var McaSwapService = class {
2247
2400
  try {
2248
2401
  identityKey = (await provider.getIdentityKey()).trim();
2249
2402
  } catch (error) {
2403
+ logSdkCaughtError("mca/McaSwapService.ts", error);
2250
2404
  if (error instanceof SwapSdkError) throw error;
2251
2405
  throw new SwapSdkError(
2252
2406
  "SIGNING_FAILED",
@@ -2308,6 +2462,9 @@ var SwapClient = class {
2308
2462
  this.reportRequests = /* @__PURE__ */ new Map();
2309
2463
  this.tokenListCache = /* @__PURE__ */ new Map();
2310
2464
  this.tokenListInflight = /* @__PURE__ */ new Map();
2465
+ if (config.debugCatchLogging !== void 0) {
2466
+ setSdkCatchLogging(config.debugCatchLogging);
2467
+ }
2311
2468
  this.config = config;
2312
2469
  this.api = new ApiClient(config);
2313
2470
  this.registry = new ExecutorRegistry(config.executors ?? []);
@@ -2513,6 +2670,7 @@ var SwapClient = class {
2513
2670
  ...reportRecordId ? { recordId: reportRecordId } : {}
2514
2671
  };
2515
2672
  } catch (error) {
2673
+ logSdkCaughtError("client/SwapClient.ts", error);
2516
2674
  const warning = {
2517
2675
  code: "REPORT_FAILED",
2518
2676
  message: "Swap submitted but report failed",
@@ -2558,6 +2716,7 @@ var SwapClient = class {
2558
2716
  }
2559
2717
  return result;
2560
2718
  } catch (error) {
2719
+ logSdkCaughtError("client/SwapClient.ts", error);
2561
2720
  const sdkError = asSwapSdkError(error, "broadcast");
2562
2721
  emit({ type: "failed", executionId: build.executionId, error: sdkError });
2563
2722
  throw sdkError;
@@ -2809,6 +2968,6 @@ function delay(ms, signal) {
2809
2968
  });
2810
2969
  }
2811
2970
 
2812
- 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, shouldPollSwapOrderStatus, toApiAssetAddress, toApiChain };
2971
+ export { ApiClient, DEFAULT_MCA_SIGNER_PRIORITY, ExecutorRegistry, SwapClient, SwapSdkError, asSwapSdkError, assertBaseUnitAmount, assertOrderStatusParams, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, buildOrderStatusQuery, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, isSdkCatchLoggingEnabled, logSdkCaughtError, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeOrderStatus, normalizeQuote, orderStatusParamsFromHistoryItem, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, resolveOrderStatusLookup, resolveSourceTxHash, resolveSwapReportRecordId, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, setSdkCatchLogging, shouldPollSwapOrderStatus, toApiAssetAddress, toApiChain };
2813
2972
  //# sourceMappingURL=index.mjs.map
2814
2973
  //# sourceMappingURL=index.mjs.map