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