@rhea-finance/cross-chain-aggregation-dex 2.1.8 → 2.1.10-beta.0

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 (54) hide show
  1. package/README.md +62 -18
  2. package/dist/executors/aptos.d.mts +1 -1
  3. package/dist/executors/aptos.d.ts +1 -1
  4. package/dist/executors/bitcoin.d.mts +1 -1
  5. package/dist/executors/bitcoin.d.ts +1 -1
  6. package/dist/executors/dash.d.mts +21 -0
  7. package/dist/executors/dash.d.ts +21 -0
  8. package/dist/executors/dash.js +184 -0
  9. package/dist/executors/dash.js.map +1 -0
  10. package/dist/executors/dash.mjs +182 -0
  11. package/dist/executors/dash.mjs.map +1 -0
  12. package/dist/executors/evm.d.mts +1 -1
  13. package/dist/executors/evm.d.ts +1 -1
  14. package/dist/executors/near.d.mts +1 -1
  15. package/dist/executors/near.d.ts +1 -1
  16. package/dist/executors/pearl.d.mts +21 -0
  17. package/dist/executors/pearl.d.ts +21 -0
  18. package/dist/executors/pearl.js +240 -0
  19. package/dist/executors/pearl.js.map +1 -0
  20. package/dist/executors/pearl.mjs +238 -0
  21. package/dist/executors/pearl.mjs.map +1 -0
  22. package/dist/executors/qtc.d.mts +21 -0
  23. package/dist/executors/qtc.d.ts +21 -0
  24. package/dist/executors/qtc.js +184 -0
  25. package/dist/executors/qtc.js.map +1 -0
  26. package/dist/executors/qtc.mjs +182 -0
  27. package/dist/executors/qtc.mjs.map +1 -0
  28. package/dist/executors/solana.d.mts +1 -1
  29. package/dist/executors/solana.d.ts +1 -1
  30. package/dist/executors/starknet.d.mts +18 -0
  31. package/dist/executors/starknet.d.ts +18 -0
  32. package/dist/executors/starknet.js +189 -0
  33. package/dist/executors/starknet.js.map +1 -0
  34. package/dist/executors/starknet.mjs +187 -0
  35. package/dist/executors/starknet.mjs.map +1 -0
  36. package/dist/executors/sui.d.mts +1 -1
  37. package/dist/executors/sui.d.ts +1 -1
  38. package/dist/executors/tron.d.mts +1 -1
  39. package/dist/executors/tron.d.ts +1 -1
  40. package/dist/executors/tron.js +50 -7
  41. package/dist/executors/tron.js.map +1 -1
  42. package/dist/executors/tron.mjs +50 -7
  43. package/dist/executors/tron.mjs.map +1 -1
  44. package/dist/executors/zcash.d.mts +1 -1
  45. package/dist/executors/zcash.d.ts +1 -1
  46. package/dist/index.d.mts +9 -5
  47. package/dist/index.d.ts +9 -5
  48. package/dist/index.js +257 -27
  49. package/dist/index.js.map +1 -1
  50. package/dist/index.mjs +255 -28
  51. package/dist/index.mjs.map +1 -1
  52. package/dist/{shared-v1w63b8X.d.mts → shared-B-li1YIV.d.mts} +64 -8
  53. package/dist/{shared-v1w63b8X.d.ts → shared-B-li1YIV.d.ts} +64 -8
  54. package/package.json +21 -1
package/dist/index.js CHANGED
@@ -95,7 +95,7 @@ function asSwapSdkError(error, stage) {
95
95
  function shouldPollSwapOrderStatus(input) {
96
96
  if (String(input.reportRecordId ?? "").trim()) return true;
97
97
  const waitMode = input.waitFor ?? "submitted";
98
- const requiresOrderStatus = input.isCrossChain || input.confidentiality === "basic";
98
+ const requiresOrderStatus = input.isCrossChain || Boolean(input.confidentiality);
99
99
  return requiresOrderStatus && waitMode !== "submitted";
100
100
  }
101
101
  function resolveSwapReportRecordId(reportData) {
@@ -179,10 +179,13 @@ function resolveSourceTxHash(input) {
179
179
  }
180
180
 
181
181
  // src/api/ApiClient.ts
182
+ var PRODUCTION_API_BASE_URL = "https://api.rhea.finance";
183
+ var PRIVATE_API_BASE_URL = "https://privateindexer.refburrow.top";
184
+ var DEFAULT_SWAP_REFERRAL = "rhea_crosschain_swap";
182
185
  var ApiClient = class {
183
186
  constructor(config) {
184
187
  this.config = config;
185
- this.baseUrl = config.baseUrl.replace(/\/$/, "");
188
+ this.baseUrl = (config.baseUrl ?? PRIVATE_API_BASE_URL).replace(/\/$/, "");
186
189
  if (config.debugCatchLogging !== void 0) {
187
190
  setSdkCatchLogging(config.debugCatchLogging);
188
191
  }
@@ -197,17 +200,27 @@ var ApiClient = class {
197
200
  this.fetchImpl = fetchImpl.bind(globalThis);
198
201
  }
199
202
  quote(body, options = {}) {
200
- return this.request("/api/v2/swap/quote", "quote", {
203
+ return this.request("/crosschain/swap/quote", "quote", {
201
204
  ...options,
202
205
  method: "POST",
203
- body
206
+ body: {
207
+ ...body,
208
+ fromChain: body.fromChain === "prl" ? "pearl" : body.fromChain,
209
+ toChain: body.toChain === "prl" ? "pearl" : body.toChain,
210
+ referral: body.referral || DEFAULT_SWAP_REFERRAL
211
+ }
204
212
  });
205
213
  }
206
214
  build(body, options = {}) {
207
- return this.request("/api/v2/swap/swap", "build", {
215
+ return this.request("/crosschain/swap/swap", "build", {
208
216
  ...options,
209
217
  method: "POST",
210
- body
218
+ body: {
219
+ ...body,
220
+ fromChain: body.fromChain === "prl" ? "pearl" : body.fromChain,
221
+ toChain: body.toChain === "prl" ? "pearl" : body.toChain,
222
+ referral: body.referral || DEFAULT_SWAP_REFERRAL
223
+ }
211
224
  });
212
225
  }
213
226
  submitOrder(body, options = {}) {
@@ -233,7 +246,7 @@ var ApiClient = class {
233
246
  });
234
247
  }
235
248
  report(body, options = {}) {
236
- return this.request("/api/swap/report", "report", {
249
+ return this.request("/crosschain/swap/report", "report", {
237
250
  ...options,
238
251
  method: "POST",
239
252
  body
@@ -544,6 +557,30 @@ var ExecutorRegistry = class {
544
557
  }
545
558
  };
546
559
 
560
+ // src/utils/starknet.ts
561
+ var FIELD_PRIME = (1n << 251n) + (17n << 192n) + 1n;
562
+ function assertStarknetFelt(value) {
563
+ if (typeof value !== "string" || !/^(0x[0-9a-f]+|\d+)$/i.test(value) || BigInt(value) >= FIELD_PRIME) {
564
+ throw new SwapSdkError("INVALID_TRANSACTION", "build", "Invalid Starknet field element");
565
+ }
566
+ }
567
+ function validateStarknetCalls(value) {
568
+ if (!Array.isArray(value) || !value.length) {
569
+ throw new SwapSdkError("INVALID_TRANSACTION", "build", "Missing Starknet calls");
570
+ }
571
+ return value.map((call) => {
572
+ assertStarknetFelt(call?.contractAddress);
573
+ if (typeof call.entrypoint !== "string" || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(call.entrypoint) || !Array.isArray(call.calldata)) {
574
+ throw new SwapSdkError("INVALID_TRANSACTION", "build", "Invalid Starknet call");
575
+ }
576
+ call.calldata.forEach(assertStarknetFelt);
577
+ return { contractAddress: call.contractAddress, entrypoint: call.entrypoint, calldata: [...call.calldata] };
578
+ });
579
+ }
580
+ function sameSender(a, b, starknet) {
581
+ return starknet && /^0x[0-9a-f]+$/i.test(a) && /^0x[0-9a-f]+$/i.test(b) ? BigInt(a) === BigInt(b) : a === b;
582
+ }
583
+
547
584
  // src/normalizers/chain.ts
548
585
  var CANONICAL_NON_EVM_CHAINS = /* @__PURE__ */ new Set([
549
586
  "solana",
@@ -551,6 +588,10 @@ var CANONICAL_NON_EVM_CHAINS = /* @__PURE__ */ new Set([
551
588
  "near",
552
589
  "tron",
553
590
  "btc",
591
+ "dash",
592
+ "starknet",
593
+ "qtc",
594
+ "pearl",
554
595
  "zcash",
555
596
  "sui"
556
597
  ]);
@@ -560,7 +601,16 @@ var RAW_API_ALIASES = /* @__PURE__ */ new Map([
560
601
  ["637", "aptos"],
561
602
  ["trx", "tron"],
562
603
  ["bitcoin", "btc"],
563
- ["zec", "zcash"]
604
+ ["zec", "zcash"],
605
+ ["quantus", "qtc"],
606
+ ["substrate", "qtc"],
607
+ ["900011", "starknet"],
608
+ ["sn_main", "starknet"],
609
+ ["0x534e5f4d41494e", "starknet"],
610
+ ["900013", "pearl"],
611
+ ["900014", "qtc"],
612
+ ["900015", "dash"],
613
+ ["prl", "pearl"]
564
614
  ]);
565
615
  var NATIVE_ADDRESSES = /* @__PURE__ */ new Map([
566
616
  ["solana", "So11111111111111111111111111111111111111112"],
@@ -569,11 +619,17 @@ var NATIVE_ADDRESSES = /* @__PURE__ */ new Map([
569
619
  ["tron", "trx"],
570
620
  ["btc", "btc"],
571
621
  ["zcash", "nep141:zec.omft.near"],
622
+ ["qtc", "nep141:qtc.omft.near"],
623
+ ["dash", "nep141:dash.omft.near"],
624
+ ["starknet", "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"],
625
+ ["pearl", "nep141:prl.omft.near"],
626
+ ["prl", "nep141:prl.omft.near"],
572
627
  ["sui", "0x2::sui::SUI"]
573
628
  ]);
574
629
  var EVM_ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
575
630
  var DECIMAL_EVM_CHAIN_ID = /^[1-9]\d*$/;
576
631
  function toApiChain(chain) {
632
+ if (chain === "prl") return "pearl";
577
633
  if (DECIMAL_EVM_CHAIN_ID.test(chain) || CANONICAL_NON_EVM_CHAINS.has(chain)) {
578
634
  return chain;
579
635
  }
@@ -721,7 +777,8 @@ var transferBaseSchema = zod.z.object({
721
777
  chainId: zod.z.string().optional(),
722
778
  chain: zod.z.string().optional(),
723
779
  amount: decimalStringSchema,
724
- depositAddress: nonEmptyStringSchema
780
+ depositAddress: nonEmptyStringSchema,
781
+ sender: nonEmptyStringSchema.optional()
725
782
  });
726
783
  var tronTransferSchema = transferBaseSchema.extend({
727
784
  tokenAddress: zod.z.string().optional(),
@@ -760,6 +817,13 @@ function normalizeBuild(raw, executionId = createExecutionId(), request) {
760
817
  const lane = laneFromChainType(common.chainType, fromChain);
761
818
  assertLaneMatchesChain(lane, fromChain);
762
819
  const execution = normalizeExecution(raw, lane, fromChain);
820
+ if (["qtc", "pearl", "dash", "starknet"].includes(lane) && request?.sender) {
821
+ const native = execution;
822
+ if (native.sender && !sameSender(native.sender, request.sender, lane === "starknet")) {
823
+ throw new SwapSdkError("CHAIN_MISMATCH", "build", "Transaction sender differs from quoted sender");
824
+ }
825
+ native.sender = request.sender;
826
+ }
763
827
  const order = normalizeOrder(raw, execution, request);
764
828
  const deposit = normalizeDeposit(raw.deposit);
765
829
  return {
@@ -836,6 +900,25 @@ function normalizeExecution(raw, lane, chain) {
836
900
  ...tx.feeRate === void 0 ? {} : { feeRate: tx.feeRate }
837
901
  };
838
902
  }
903
+ case "starknet":
904
+ return normalizeStarknetExecution(raw, chain);
905
+ case "qtc":
906
+ case "pearl":
907
+ case "dash": {
908
+ assertNativeBuild(raw);
909
+ const tx = zcashTxSchema.parse(raw.tx);
910
+ assertKind(tx.kind, lane === "qtc" ? ["qtc_transfer", "quantus_transfer"] : lane === "dash" ? ["dash_transfer", "utxo_transfer"] : ["prl_transfer", "pearl_transfer", "utxo_transfer"]);
911
+ const decimals = lane === "qtc" ? 12 : 8;
912
+ const symbols = lane === "qtc" ? ["QTC"] : lane === "dash" ? ["DASH"] : ["PRL", "PEARL"];
913
+ const addresses = ["", chain, `nep141:${chain}.omft.near`, `${chain}:mainnet:native`, lane === "qtc" ? "900014" : lane === "dash" ? "900015" : "900013", ...lane === "pearl" ? ["prl", "nep141:prl.omft.near", "prl:mainnet:native"] : []];
914
+ if (!symbols.includes(raw.tokenIn.symbol.toUpperCase()) || !addresses.includes(raw.tokenIn.address.toLowerCase()) || tx.decimals !== void 0 && tx.decimals !== decimals || raw.tokenIn.decimals !== decimals || tx.amount !== raw.amountIn || !/^[1-9]\d*$/.test(tx.amount) || tx.chain !== void 0 && fromApiChain(tx.chain) !== chain || tx.chainId !== void 0 && fromApiChain(tx.chainId) !== chain || raw.deposit?.depositAddress && tx.depositAddress !== raw.deposit.depositAddress) {
915
+ throw new SwapSdkError("INVALID_API_RESPONSE", "build", "Invalid native transfer asset, chain, amount, deposit or decimals");
916
+ }
917
+ const sender = tx.sender;
918
+ const fields = { chain, amount: tx.amount, depositAddress: tx.depositAddress, ...sender ? { sender } : {} };
919
+ if (lane === "qtc") return { kind: "qtc-transfer", ...fields, decimals: 12 };
920
+ return { kind: lane === "dash" ? "dash-transfer" : "pearl-transfer", ...fields, decimals: 8 };
921
+ }
839
922
  case "zcash": {
840
923
  const tx = zcashTxSchema.parse(raw.tx);
841
924
  assertKind(tx.kind, ["zcash_transfer", "utxo_transfer"]);
@@ -922,6 +1005,10 @@ function normalizeTronExecution(raw, chain) {
922
1005
  }
923
1006
  function isTronRawDataTx(value) {
924
1007
  if (typeof value !== "object" || value === null) return false;
1008
+ const kind = Reflect.get(value, "kind");
1009
+ if (typeof kind === "string" && kind.toLowerCase() === "tron_contract") {
1010
+ return true;
1011
+ }
925
1012
  const format = Reflect.get(value, "format");
926
1013
  if (typeof format === "string" && format.toLowerCase() === "tron-raw-data") {
927
1014
  return true;
@@ -992,8 +1079,20 @@ function laneFromChainType(chainType, fromChain) {
992
1079
  tron: "tron",
993
1080
  btc: "bitcoin",
994
1081
  bitcoin: "bitcoin",
1082
+ dash: "dash",
1083
+ starknet: "starknet",
1084
+ sn_main: "starknet",
1085
+ "900011": "starknet",
1086
+ "900013": "pearl",
1087
+ "900014": "qtc",
1088
+ "900015": "dash",
1089
+ qtc: "qtc",
1090
+ prl: "pearl",
1091
+ pearl: "pearl",
995
1092
  zcash: "zcash",
996
1093
  zec: "zcash",
1094
+ quantus: "qtc",
1095
+ substrate: "qtc",
997
1096
  sui: "sui"
998
1097
  };
999
1098
  if (normalized === "cross-chain" || normalized === "utxo") {
@@ -1017,6 +1116,16 @@ function laneFromChain(chain) {
1017
1116
  near: "near",
1018
1117
  tron: "tron",
1019
1118
  btc: "bitcoin",
1119
+ dash: "dash",
1120
+ starknet: "starknet",
1121
+ sn_main: "starknet",
1122
+ "900011": "starknet",
1123
+ "900013": "pearl",
1124
+ "900014": "qtc",
1125
+ "900015": "dash",
1126
+ qtc: "qtc",
1127
+ prl: "pearl",
1128
+ pearl: "pearl",
1020
1129
  zcash: "zcash",
1021
1130
  sui: "sui"
1022
1131
  };
@@ -1061,7 +1170,7 @@ function assertKind(actual, allowed) {
1061
1170
  function normalizeOrder(raw, execution, request) {
1062
1171
  const depositOrderId = readRecordString(raw.deposit, "orderId");
1063
1172
  const router = raw.statusRouter ?? (execution.kind === "evm-signature" ? execution.request.router : void 0) ?? raw.router;
1064
- const confidentialNearIntentsStatusKey = request?.confidentiality === "basic" && router.toLowerCase().includes("nearintents") ? readRecordString(raw.deposit, "depositAddress") : void 0;
1173
+ const confidentialNearIntentsStatusKey = Boolean(request?.confidentiality) && router.toLowerCase().includes("nearintents") ? readRecordString(raw.deposit, "depositAddress") : void 0;
1065
1174
  const orderId = raw.orderId ?? depositOrderId ?? confidentialNearIntentsStatusKey;
1066
1175
  if (!orderId) return void 0;
1067
1176
  const chainId = execution.kind === "evm-signature" ? String(execution.request.chainId) : execution.kind === "evm-transaction" ? String(execution.tx.chainId) : void 0;
@@ -1107,6 +1216,47 @@ function invalidBuild(error) {
1107
1216
  }
1108
1217
  );
1109
1218
  }
1219
+ function assertNativeBuild(raw) {
1220
+ if (raw.executionType === "signature" || raw.signingRequest || raw.approve) {
1221
+ throw new SwapSdkError("INVALID_API_RESPONSE", "build", "Unexpected signature or EVM approval for native build");
1222
+ }
1223
+ }
1224
+ function normalizeStarknetExecution(raw, chain) {
1225
+ assertNativeBuild(raw);
1226
+ const tx = zod.z.object({
1227
+ kind: zod.z.enum(["starknet_call", "starknet_transfer"]),
1228
+ chain: zod.z.string().optional(),
1229
+ chainId: zod.z.string().optional(),
1230
+ sender: nonEmptyStringSchema.optional(),
1231
+ calls: zod.z.unknown().optional(),
1232
+ amount: decimalStringSchema.optional(),
1233
+ depositAddress: nonEmptyStringSchema.optional(),
1234
+ tokenAddress: nonEmptyStringSchema.optional(),
1235
+ decimals: zod.z.number().int().nonnegative().optional()
1236
+ }).parse(raw.tx);
1237
+ for (const hint of [tx.chain, tx.chainId]) {
1238
+ if (hint !== void 0 && fromApiChain(hint) !== chain) {
1239
+ throw new SwapSdkError("CHAIN_MISMATCH", "build", "Wrong Starknet transaction chain");
1240
+ }
1241
+ }
1242
+ let calls;
1243
+ if (tx.kind === "starknet_call") calls = validateStarknetCalls(tx.calls);
1244
+ else {
1245
+ if (!tx.amount || !/^[1-9]\d*$/.test(tx.amount) || tx.amount !== raw.amountIn || BigInt(tx.amount) >= 1n << 256n || tx.decimals !== void 0 && tx.decimals !== raw.tokenIn.decimals || raw.deposit?.depositAddress && tx.depositAddress !== raw.deposit.depositAddress) {
1246
+ throw new SwapSdkError("INVALID_API_RESPONSE", "build", "Invalid Starknet transfer amount, decimals or deposit");
1247
+ }
1248
+ const token = tx.tokenAddress ?? raw.tokenIn.address;
1249
+ assertStarknetFelt(token);
1250
+ assertStarknetFelt(tx.depositAddress);
1251
+ const amount = BigInt(tx.amount);
1252
+ calls = validateStarknetCalls([{
1253
+ contractAddress: token,
1254
+ entrypoint: "transfer",
1255
+ calldata: [tx.depositAddress, String(amount & (1n << 128n) - 1n), String(amount >> 128n)]
1256
+ }]);
1257
+ }
1258
+ return { kind: "starknet-transaction", chain, calls, ...tx.sender ? { sender: tx.sender } : {} };
1259
+ }
1110
1260
 
1111
1261
  // src/types/chain.ts
1112
1262
  var BASE_UNIT_AMOUNT = /^(0|[1-9]\d*)$/;
@@ -1129,6 +1279,10 @@ function serializeQuoteRequest(request) {
1129
1279
  validateQuoteRequest(request);
1130
1280
  return {
1131
1281
  ...request.extensions ?? {},
1282
+ // Destination swaps require a separate wallet action after bridge arrival.
1283
+ // Keep the normalized quote -> swap flow limited to a single source action.
1284
+ enableDestinationSwap: false,
1285
+ ...request.referral ? { referral: request.referral } : {},
1132
1286
  fromChain: toApiChain(request.fromChain),
1133
1287
  toChain: toApiChain(request.toChain),
1134
1288
  tokenIn: toApiAssetAddress(request.tokenIn),
@@ -1138,12 +1292,18 @@ function serializeQuoteRequest(request) {
1138
1292
  quoteWaitingTimeMs: request.quoteWaitingTimeMs ?? DEFAULT_QUOTE_WAITING_TIME_MS,
1139
1293
  sameChainTimeoutMs: request.sameChainTimeoutMs ?? DEFAULT_SAME_CHAIN_TIMEOUT_MS,
1140
1294
  crossChainTimeoutMs: request.crossChainTimeoutMs ?? DEFAULT_CROSS_CHAIN_TIMEOUT_MS,
1295
+ ...request.excludeDexs !== void 0 ? { excludeDexs: [...request.excludeDexs] } : {},
1141
1296
  ...request.confidentiality ? { confidentiality: request.confidentiality } : {},
1142
1297
  sender: request.sender.trim(),
1143
1298
  ...request.recipient?.trim() ? { recipient: request.recipient.trim() } : {}
1144
1299
  };
1145
1300
  }
1146
1301
  function normalizeQuote(request, raw, receivedAt = Date.now()) {
1302
+ if (raw.executionPlan === "BRIDGE_THEN_DESTINATION_SWAP") {
1303
+ throw invalidQuote(
1304
+ "Destination Bridge + Swap requires two wallet actions; use the raw API flow"
1305
+ );
1306
+ }
1147
1307
  const bestRoute = normalizeRoute(raw.bestQuote, true);
1148
1308
  if (!bestRoute) {
1149
1309
  throw invalidQuote("Quote response does not contain a valid best route");
@@ -1347,6 +1507,10 @@ var NATIVE_ASSET_IDS = {
1347
1507
  near: ["near", "wrap.near"],
1348
1508
  tron: ["trx"],
1349
1509
  btc: ["btc", "bitcoin"],
1510
+ dash: ["dash", "nep141:dash.omft.near"],
1511
+ starknet: ["0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"],
1512
+ qtc: ["qtc", "quantus", "nep141:qtc.omft.near"],
1513
+ pearl: ["prl", "pearl", "nep141:prl.omft.near"],
1350
1514
  zcash: ["zec", "zcash", "nep141:zec.omft.near"],
1351
1515
  sui: ["0x2::sui::SUI"]
1352
1516
  };
@@ -1459,6 +1623,10 @@ var TOKEN_LIST_CHAIN_METADATA = /* @__PURE__ */ new Map([
1459
1623
  [900001, { chain: "near", blockchain: "near" }],
1460
1624
  [900002, { chain: "btc", blockchain: "btc" }],
1461
1625
  [900010, { chain: "zcash", blockchain: "zec" }],
1626
+ [900011, { chain: "starknet", blockchain: "starknet" }],
1627
+ [900013, { chain: "pearl", blockchain: "prl" }],
1628
+ [900014, { chain: "qtc", blockchain: "qtc" }],
1629
+ [900015, { chain: "dash", blockchain: "dash" }],
1462
1630
  [900012, { chain: "aptos", blockchain: "aptos" }]
1463
1631
  ]);
1464
1632
  function normalizeFromTokenList(raw, chainId) {
@@ -1533,6 +1701,16 @@ function isNativeToken(input) {
1533
1701
  if (/^[1-9]\d*$/.test(input.chain)) {
1534
1702
  return address === "0x0000000000000000000000000000000000000000" || address === "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" || (input.blockchain === "pol" || input.blockchain === "polygon") && address === "0x0000000000000000000000000000000000001010";
1535
1703
  }
1704
+ if (["qtc", "pearl", "prl", "dash"].includes(input.chain)) {
1705
+ const assetChain = input.chain === "pearl" ? "prl" : input.chain;
1706
+ return [assetChain, `nep141:${assetChain}.omft.near`, `${assetChain}:mainnet:native`].includes(assetId);
1707
+ }
1708
+ if (input.chain === "starknet") {
1709
+ return [
1710
+ "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d",
1711
+ "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
1712
+ ].some((token) => /^0x[0-9a-f]+$/.test(address) && BigInt(token) === BigInt(address));
1713
+ }
1536
1714
  if (input.chain === "solana") {
1537
1715
  return address === "11111111111111111111111111111111" || assetId === "nep141:sol.omft.near";
1538
1716
  }
@@ -2594,18 +2772,63 @@ var SwapClient = class {
2594
2772
  if (input.onEvent !== this.config.onEvent) input.onEvent?.(event);
2595
2773
  };
2596
2774
  try {
2775
+ let activeBuild = build;
2597
2776
  const executor = this.registry.get(build.execution.kind);
2777
+ if (build.execution.kind === "tron-transaction" && build.execution.approval && !build.request) {
2778
+ throw new SwapSdkError(
2779
+ "INVALID_REQUEST",
2780
+ "sign",
2781
+ "Tron approval builds require the original build request to rebuild after approval"
2782
+ );
2783
+ }
2784
+ const needsTronRebuild = build.execution.kind === "tron-transaction" && Boolean(build.execution.approval) && Boolean(build.request);
2598
2785
  const context = {
2599
2786
  executionId: build.executionId,
2600
2787
  signal: input.signal,
2601
2788
  waitFor: input.waitFor ?? "submitted",
2602
2789
  emit,
2603
- ...input.beforeSign ? { beforeSign: input.beforeSign } : {}
2790
+ ...input.beforeSign ? { beforeSign: input.beforeSign } : {},
2791
+ ...needsTronRebuild ? {
2792
+ refreshTronExecution: async () => {
2793
+ const request = build.request;
2794
+ if (!request) {
2795
+ throw new SwapSdkError(
2796
+ "INVALID_REQUEST",
2797
+ "build",
2798
+ "Missing build request to rebuild Tron swap after approval"
2799
+ );
2800
+ }
2801
+ const raw = await this.api.build(request, {
2802
+ signal: input.signal
2803
+ });
2804
+ const refreshed = normalizeBuild(
2805
+ raw,
2806
+ build.executionId,
2807
+ request
2808
+ );
2809
+ if (refreshed.execution.kind !== "tron-transaction") {
2810
+ throw new SwapSdkError(
2811
+ "INVALID_API_RESPONSE",
2812
+ "build",
2813
+ "Rebuilt Tron swap must return a tron-transaction execution"
2814
+ );
2815
+ }
2816
+ if (refreshed.execution.approval) {
2817
+ throw new SwapSdkError(
2818
+ "INVALID_API_RESPONSE",
2819
+ "build",
2820
+ "Tron approval is still required after rebuild"
2821
+ );
2822
+ }
2823
+ activeBuild = refreshed;
2824
+ return refreshed.execution;
2825
+ }
2826
+ } : {}
2604
2827
  };
2605
2828
  await executor.validate(build.execution, context);
2606
2829
  emit({ type: "signing-requested", executionId: build.executionId });
2607
2830
  const chainResult = await executor.execute(build.execution, context);
2608
- let orderId = chainResult.orderId ?? build.order?.orderId;
2831
+ let orderId = chainResult.orderId ?? activeBuild.order?.orderId;
2609
2832
  if (chainResult.signature) {
2610
2833
  if (build.execution.kind !== "evm-signature") {
2611
2834
  throw new SwapSdkError(
@@ -2630,33 +2853,33 @@ var SwapClient = class {
2630
2853
  orderId = submitted.orderId;
2631
2854
  }
2632
2855
  const result = {
2633
- executionId: build.executionId,
2856
+ executionId: activeBuild.executionId,
2634
2857
  status: chainResult.status,
2635
- router: build.router,
2858
+ router: activeBuild.router,
2636
2859
  ...chainResult.txHash ? { txHash: chainResult.txHash } : {},
2637
2860
  ...chainResult.txHashes ? { txHashes: chainResult.txHashes } : {},
2638
2861
  ...orderId ? { orderId } : {},
2639
- ...build.deposit?.depositAddress ? { depositAddress: build.deposit.depositAddress } : {},
2862
+ ...activeBuild.deposit?.depositAddress ? { depositAddress: activeBuild.deposit.depositAddress } : {},
2640
2863
  report: { status: "skipped" },
2641
- raw: chainResult.raw ?? build.raw
2864
+ raw: chainResult.raw ?? activeBuild.raw
2642
2865
  };
2643
2866
  emit({
2644
2867
  type: "submitted",
2645
- executionId: build.executionId,
2868
+ executionId: activeBuild.executionId,
2646
2869
  ...chainResult.txHash ? { txHash: chainResult.txHash } : {},
2647
2870
  ...orderId ? { orderId } : {}
2648
2871
  });
2649
2872
  if (chainResult.status === "source-confirmed") {
2650
2873
  emit({
2651
2874
  type: "source-confirmed",
2652
- executionId: build.executionId
2875
+ executionId: activeBuild.executionId
2653
2876
  });
2654
2877
  }
2655
2878
  const waitMode = input.waitFor ?? "submitted";
2656
- const requiresTrackedStatus = build.isCrossChain || build.request?.confidentiality === "basic";
2657
- const reportRequest = this.createReportRequest(build, result);
2879
+ const requiresTrackedStatus = activeBuild.isCrossChain || Boolean(activeBuild.request?.confidentiality);
2880
+ const reportRequest = this.createReportRequest(activeBuild, result);
2658
2881
  if (reportRequest) {
2659
- this.reportRequests.set(build.executionId, reportRequest);
2882
+ this.reportRequests.set(activeBuild.executionId, reportRequest);
2660
2883
  }
2661
2884
  const mustReportForStatus = requiresTrackedStatus && waitMode !== "submitted" && Boolean(reportRequest);
2662
2885
  const shouldReportNow = Boolean(reportRequest) && this.reportMode !== "disabled" && (this.reportMode === "auto" || mustReportForStatus);
@@ -2679,18 +2902,22 @@ var SwapClient = class {
2679
2902
  cause: error
2680
2903
  };
2681
2904
  result.report = { status: "failed", warning };
2682
- emit({ type: "warning", executionId: build.executionId, warning });
2905
+ emit({
2906
+ type: "warning",
2907
+ executionId: activeBuild.executionId,
2908
+ warning
2909
+ });
2683
2910
  }
2684
2911
  }
2685
2912
  const shouldPollOrderStatus = shouldPollSwapOrderStatus({
2686
2913
  waitFor: waitMode,
2687
- isCrossChain: build.isCrossChain,
2688
- confidentiality: build.request?.confidentiality,
2914
+ isCrossChain: activeBuild.isCrossChain,
2915
+ confidentiality: activeBuild.request?.confidentiality,
2689
2916
  reportRecordId
2690
2917
  });
2691
2918
  const statusLookup = resolveOrderStatusLookup({
2692
2919
  recordId: reportRecordId ?? result.report?.recordId,
2693
- router: build.order?.router ?? build.router
2920
+ router: activeBuild.order?.router ?? activeBuild.router
2694
2921
  });
2695
2922
  if (shouldPollOrderStatus && !statusLookup) {
2696
2923
  throw new SwapSdkError(
@@ -2699,8 +2926,8 @@ var SwapClient = class {
2699
2926
  "Swap submitted, but the report response did not include an id to query",
2700
2927
  {
2701
2928
  details: {
2702
- executionId: build.executionId,
2703
- router: build.router
2929
+ executionId: activeBuild.executionId,
2930
+ router: activeBuild.router
2704
2931
  }
2705
2932
  }
2706
2933
  );
@@ -2972,7 +3199,10 @@ function delay(ms, signal) {
2972
3199
 
2973
3200
  exports.ApiClient = ApiClient;
2974
3201
  exports.DEFAULT_MCA_SIGNER_PRIORITY = DEFAULT_MCA_SIGNER_PRIORITY;
3202
+ exports.DEFAULT_SWAP_REFERRAL = DEFAULT_SWAP_REFERRAL;
2975
3203
  exports.ExecutorRegistry = ExecutorRegistry;
3204
+ exports.PRIVATE_API_BASE_URL = PRIVATE_API_BASE_URL;
3205
+ exports.PRODUCTION_API_BASE_URL = PRODUCTION_API_BASE_URL;
2976
3206
  exports.SwapClient = SwapClient;
2977
3207
  exports.SwapSdkError = SwapSdkError;
2978
3208
  exports.asSwapSdkError = asSwapSdkError;