@satora/swap 1.11.0 → 1.12.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 (58) hide show
  1. package/dist/{chunk-EYVSXWCA.cjs → chunk-EL4FUZJO.cjs} +565 -323
  2. package/dist/chunk-EL4FUZJO.cjs.map +1 -0
  3. package/dist/{chunk-ZAQ7YV6W.js → chunk-KECPPSZL.js} +5 -5
  4. package/dist/{chunk-ZAQ7YV6W.js.map → chunk-KECPPSZL.js.map} +1 -1
  5. package/dist/{chunk-M47Z35Z5.cjs → chunk-QJ4EK6UG.cjs} +5 -5
  6. package/dist/{chunk-M47Z35Z5.cjs.map → chunk-QJ4EK6UG.cjs.map} +1 -1
  7. package/dist/{chunk-BVTLZLT2.js → chunk-YBQPH7NH.js} +289 -47
  8. package/dist/chunk-YBQPH7NH.js.map +1 -0
  9. package/dist/delegate.cjs +2 -2
  10. package/dist/delegate.js +1 -1
  11. package/dist/dist-R6DUJG36.cjs +396 -0
  12. package/dist/{dist-RWCRSE4V.cjs.map → dist-R6DUJG36.cjs.map} +1 -1
  13. package/dist/{dist-INHW3D4S.js → dist-Y3ZVHXAJ.js} +5 -3
  14. package/dist/index.cjs +21 -13
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.js +14 -6
  17. package/dist/index.js.map +1 -1
  18. package/dist/types/cjs/pure/api/client.d.cts +1 -0
  19. package/dist/types/cjs/pure/client.d.cts +30 -3
  20. package/dist/types/cjs/pure/compose-quote.d.cts +14 -1
  21. package/dist/types/cjs/pure/create/index.d.cts +2 -1
  22. package/dist/types/cjs/pure/create/spark-to-evm.d.cts +7 -0
  23. package/dist/types/cjs/pure/create/types.d.cts +93 -2
  24. package/dist/types/cjs/pure/generated/api.d.cts +274 -2
  25. package/dist/types/cjs/pure/index.d.cts +3 -3
  26. package/dist/types/cjs/pure/redeem/arkade.d.cts +4 -1
  27. package/dist/types/cjs/pure/swap-verification.d.cts +3 -1
  28. package/dist/types/cjs/pure/tokens.d.cts +5 -0
  29. package/dist/types/cjs/pure/types/chain.d.cts +2 -2
  30. package/dist/types/cjs/pure/types/index.d.cts +1 -0
  31. package/dist/types/cjs/pure/types/promo-code.d.cts +15 -0
  32. package/dist/types/cjs/pure/types/quote.d.cts +7 -0
  33. package/dist/types/cjs/pure/types/referral-fee.d.cts +8 -0
  34. package/dist/types/cjs/pure/version.d.cts +4 -4
  35. package/dist/types/cjs/swap/client.d.cts +2 -0
  36. package/dist/types/esm/pure/api/client.d.ts +1 -0
  37. package/dist/types/esm/pure/client.d.ts +30 -3
  38. package/dist/types/esm/pure/compose-quote.d.ts +14 -1
  39. package/dist/types/esm/pure/create/index.d.ts +2 -1
  40. package/dist/types/esm/pure/create/spark-to-evm.d.ts +7 -0
  41. package/dist/types/esm/pure/create/types.d.ts +93 -2
  42. package/dist/types/esm/pure/generated/api.d.ts +274 -2
  43. package/dist/types/esm/pure/index.d.ts +3 -3
  44. package/dist/types/esm/pure/redeem/arkade.d.ts +4 -1
  45. package/dist/types/esm/pure/swap-verification.d.ts +3 -1
  46. package/dist/types/esm/pure/tokens.d.ts +5 -0
  47. package/dist/types/esm/pure/types/chain.d.ts +2 -2
  48. package/dist/types/esm/pure/types/index.d.ts +1 -0
  49. package/dist/types/esm/pure/types/promo-code.d.ts +15 -0
  50. package/dist/types/esm/pure/types/quote.d.ts +7 -0
  51. package/dist/types/esm/pure/types/referral-fee.d.ts +8 -0
  52. package/dist/types/esm/pure/version.d.ts +4 -4
  53. package/dist/types/esm/swap/client.d.ts +2 -0
  54. package/package.json +2 -2
  55. package/dist/chunk-BVTLZLT2.js.map +0 -1
  56. package/dist/chunk-EYVSXWCA.cjs.map +0 -1
  57. package/dist/dist-RWCRSE4V.cjs +0 -394
  58. /package/dist/{dist-INHW3D4S.js.map → dist-Y3ZVHXAJ.js.map} +0 -0
@@ -115,7 +115,7 @@ import {
115
115
  sha2562,
116
116
  sha512,
117
117
  utils
118
- } from "./chunk-ZAQ7YV6W.js";
118
+ } from "./chunk-KECPPSZL.js";
119
119
  import {
120
120
  ArkAddress,
121
121
  CSVMultisigTapscript,
@@ -156,6 +156,7 @@ import {
156
156
  base58check,
157
157
  base64,
158
158
  bech32,
159
+ bech32m,
159
160
  hex,
160
161
  init_base
161
162
  } from "./chunk-OBFZJKRF.js";
@@ -7949,6 +7950,7 @@ var TBTC_ETHEREUM = "0x18084fbA666a33d37592fA2633fD49a74DD93a88";
7949
7950
  var TBTC_ARBITRUM = "0x6c84a8f1c29108F47a79964b5Fe888D4f4D0dE40";
7950
7951
  var Asset = {
7951
7952
  // Bitcoin
7953
+ BTC_SPARK: { chain: "Spark", tokenId: "btc" },
7952
7954
  BTC_LIGHTNING: { chain: "Lightning", tokenId: "btc" },
7953
7955
  BTC_ARKADE: { chain: "Arkade", tokenId: "btc" },
7954
7956
  BTC_ONCHAIN: { chain: "Bitcoin", tokenId: "btc" },
@@ -8039,7 +8041,7 @@ function isBtcOnchain(token) {
8039
8041
  return token.chain.toLowerCase() === "bitcoin";
8040
8042
  }
8041
8043
  function isBtc(token) {
8042
- return isLightning(token) || isArkade(token) || isBtcOnchain(token);
8044
+ return isSpark(token) || isLightning(token) || isArkade(token) || isBtcOnchain(token);
8043
8045
  }
8044
8046
  function isBtcPegged(token) {
8045
8047
  const sym = token.symbol.toLowerCase();
@@ -8126,6 +8128,7 @@ function toChain(str) {
8126
8128
  if (c === "arbitrum" || c === "42161") return "42161";
8127
8129
  if (c === "rootstock" || c === "30") return "30";
8128
8130
  if (c === "31") return "31";
8131
+ if (c === "spark") return "Spark";
8129
8132
  if (c === "lightning") return "Lightning";
8130
8133
  if (c === "arkade") return "Arkade";
8131
8134
  if (c === "bitcoin") return "Bitcoin";
@@ -8183,6 +8186,9 @@ function getUsdt0BridgeTokens() {
8183
8186
  }
8184
8187
  return tokens;
8185
8188
  }
8189
+ function isSpark(token) {
8190
+ return token.chain.toLowerCase() === "spark";
8191
+ }
8186
8192
  function pivotForChain(chainConfig, chain) {
8187
8193
  const entry = chainConfig.chains.find((c) => c.chain === chain);
8188
8194
  if (!entry) return void 0;
@@ -8388,9 +8394,10 @@ async function composeBtcToEvm(params, deps) {
8388
8394
  );
8389
8395
  }
8390
8396
  const { btcSats, evmSmallest, evmDecimals } = pivot;
8397
+ ensureWithinPromoCap(deps, btcSats);
8391
8398
  let { bridgeFee } = pivot;
8392
8399
  const networkFeeSats = baseNetworkFeeSats + pivot.bridgeNativeFeeSats;
8393
- const effectiveFeePct = (deps.referralBaseFeeRate ?? pair.fee_percentage) + (deps.referralExtraFeeRate ?? 0);
8400
+ const effectiveFeePct = baseFeePct(deps, pair.fee_percentage) + (deps.referralExtraFeeRate ?? 0);
8394
8401
  const FEE_SCALE = 10n ** 18n;
8395
8402
  const feePctScaled = BigInt(Math.round(effectiveFeePct * Number(FEE_SCALE)));
8396
8403
  const protocolFee = Number(btcSats * feePctScaled / FEE_SCALE);
@@ -8430,7 +8437,7 @@ async function composeBtcToEvm(params, deps) {
8430
8437
  protocol_fee: protocolFee,
8431
8438
  protocol_fee_rate: effectiveFeePct,
8432
8439
  min_amount: pair.min_sats,
8433
- max_amount: pair.max_sats,
8440
+ max_amount: maxSats(deps, pair.max_sats),
8434
8441
  source_amount: btcSats.toString(),
8435
8442
  // Source-pinned: `evmSmallest` is the delivered (fee-netted) DEX output, so
8436
8443
  // gross it back up by the bridge fee — `target_amount` is the gross output
@@ -8442,7 +8449,8 @@ async function composeBtcToEvm(params, deps) {
8442
8449
  target_amount: (params.sourceAmount != null ? grossTarget : evmSmallest).toString(),
8443
8450
  net_source_amount: netSource.toString(),
8444
8451
  net_target_amount: netTarget.toString(),
8445
- bridge_fee: bridgeFee > 0n ? Number(bridgeFee) : void 0
8452
+ bridge_fee: bridgeFee > 0n ? Number(bridgeFee) : void 0,
8453
+ promo: deps.referralPromo
8446
8454
  };
8447
8455
  }
8448
8456
  async function dexSourcePinned(btcSats, params, deps, btcPegged, pivotChainId, toToken, pivotScale) {
@@ -8551,7 +8559,8 @@ async function composeEvmToBtc(params, deps) {
8551
8559
  );
8552
8560
  }
8553
8561
  const { btcSats, evmSmallest, evmDecimals, bridgeFee } = pivot;
8554
- const effectiveFeePct = (deps.referralBaseFeeRate ?? pair.fee_percentage) + (deps.referralExtraFeeRate ?? 0);
8562
+ ensureWithinPromoCap(deps, btcSats);
8563
+ const effectiveFeePct = baseFeePct(deps, pair.fee_percentage) + (deps.referralExtraFeeRate ?? 0);
8555
8564
  const FEE_SCALE = 10n ** 18n;
8556
8565
  const feePctScaled = BigInt(Math.round(effectiveFeePct * Number(FEE_SCALE)));
8557
8566
  const protocolFee = Number(btcSats * feePctScaled / FEE_SCALE);
@@ -8573,7 +8582,7 @@ async function composeEvmToBtc(params, deps) {
8573
8582
  protocol_fee: protocolFee,
8574
8583
  protocol_fee_rate: effectiveFeePct,
8575
8584
  min_amount: pair.min_sats,
8576
- max_amount: pair.max_sats,
8585
+ max_amount: maxSats(deps, pair.max_sats),
8577
8586
  // EVM→BTC: the EVM source is the bridged side. The dex-quote already
8578
8587
  // reports `evmSmallest` as the gross the user supplies (the inbound fee was
8579
8588
  // folded onto it), so `source_amount` needs no adjustment — just surface
@@ -8582,7 +8591,8 @@ async function composeEvmToBtc(params, deps) {
8582
8591
  target_amount: btcSats.toString(),
8583
8592
  net_source_amount: netSource.toString(),
8584
8593
  net_target_amount: netTarget.toString(),
8585
- bridge_fee: bridgeFee > 0n ? Number(bridgeFee) : void 0
8594
+ bridge_fee: bridgeFee > 0n ? Number(bridgeFee) : void 0,
8595
+ promo: deps.referralPromo
8586
8596
  };
8587
8597
  }
8588
8598
  async function dexEvmToBtcSourcePinned(evmSmallest, params, deps, btcPegged, pivotChainId, tokenChainId, pivotScale) {
@@ -8636,6 +8646,20 @@ function calculateExchangeRate(btcSats, evmSmallest, evmDecimals) {
8636
8646
  frac = frac.replace(/0+$/, "");
8637
8647
  return frac.length === 0 ? intPart.toString() : `${intPart}.${frac}`;
8638
8648
  }
8649
+ function baseFeePct(deps, pairFeePct) {
8650
+ return deps.referralPromo?.fee_rate ?? deps.referralBaseFeeRate ?? pairFeePct;
8651
+ }
8652
+ function ensureWithinPromoCap(deps, btcSats) {
8653
+ const promo = deps.referralPromo;
8654
+ if (promo && btcSats > BigInt(promo.max_amount_sats)) {
8655
+ throw new Error(
8656
+ `promo code only applies to swaps up to ${promo.max_amount_sats} sats`
8657
+ );
8658
+ }
8659
+ }
8660
+ function maxSats(deps, pairMaxSats) {
8661
+ return deps.referralPromo ? Math.max(pairMaxSats, deps.referralPromo.max_amount_sats) : pairMaxSats;
8662
+ }
8639
8663
  init_sha2();
8640
8664
  init_utils();
8641
8665
  init_bip32();
@@ -11797,6 +11821,9 @@ function recoveredKeysChange(stored, index, derivedPreimageHash) {
11797
11821
  function unboundTerms(fresh, swapParams) {
11798
11822
  try {
11799
11823
  switch (fresh.direction) {
11824
+ case "spark_to_evm":
11825
+ assertSparkFunding(fresh, bytesToHex(swapParams.preimageHash));
11826
+ break;
11800
11827
  case "lightning_to_arkade":
11801
11828
  case "lightning_to_evm":
11802
11829
  case "lightning_to_bitcoin":
@@ -11878,6 +11905,7 @@ var PAYOUT_FIELD = {
11878
11905
  arkade_to_evm: "target_evm_address",
11879
11906
  bitcoin_to_evm: "target_evm_address",
11880
11907
  lightning_to_evm: "target_evm_address",
11908
+ spark_to_evm: "target_evm_address",
11881
11909
  evm_to_bitcoin: "target_btc_address",
11882
11910
  lightning_to_bitcoin: "target_btc_address",
11883
11911
  btc_to_arkade: "target_arkade_address",
@@ -11931,6 +11959,15 @@ function withStoredTerms(stored, fresh, refused) {
11931
11959
  if (field in before) kept[field] = before[field];
11932
11960
  else if (condemned.includes(field)) delete kept[field];
11933
11961
  }
11962
+ if (stored.response.direction === "spark_to_evm") {
11963
+ const original = stored.response;
11964
+ kept.funding = {
11965
+ ...original.funding,
11966
+ payment_id: fresh.direction === "spark_to_evm" ? fresh.funding?.payment_id ?? original.funding.payment_id : original.funding.payment_id
11967
+ };
11968
+ kept.source_amount = original.source_amount;
11969
+ kept.network = original.network;
11970
+ }
11934
11971
  return kept;
11935
11972
  }
11936
11973
  function swapTermsChange(stored, fresh) {
@@ -11954,6 +11991,30 @@ function swapTermsChange(stored, fresh) {
11954
11991
  };
11955
11992
  const payout = compare(["direction", "bridge_target_chain"], (value) => value) ?? compare(PAYOUT_FIELDS, addressKey);
11956
11993
  if (payout) return payout;
11994
+ if (stored.response.direction === "spark_to_evm" && fresh.direction === "spark_to_evm") {
11995
+ const old = stored.response;
11996
+ if (old.funding.address !== fresh.funding.address)
11997
+ return changed(
11998
+ "funding.address",
11999
+ old.funding.address,
12000
+ fresh.funding.address
12001
+ );
12002
+ if (old.funding.expiry_duration_secs !== fresh.funding.expiry_duration_secs)
12003
+ return changed(
12004
+ "funding.expiry_duration_secs",
12005
+ String(old.funding.expiry_duration_secs),
12006
+ String(fresh.funding.expiry_duration_secs)
12007
+ );
12008
+ if (old.source_amount !== fresh.source_amount)
12009
+ return changed("source_amount", old.source_amount, fresh.source_amount);
12010
+ if (old.network !== fresh.network)
12011
+ return changed("network", old.network, fresh.network);
12012
+ try {
12013
+ assertSparkFunding(fresh, stored.preimageHash);
12014
+ } catch (error) {
12015
+ return error instanceof SwapVerificationError ? error : changed("funding", "valid native Spark terms", String(error));
12016
+ }
12017
+ }
11957
12018
  if (EVM_SOURCED.has(stored.response.direction)) return void 0;
11958
12019
  const difference = compare(HASH_FIELDS, normalizeHash) ?? compare(ADDRESS_FIELDS, (address2) => address2.toLowerCase()) ?? compare(INVOICE_FIELDS, invoiceKey);
11959
12020
  if (difference) return difference;
@@ -11971,6 +12032,50 @@ function swapTermsChange(stored, fresh) {
11971
12032
  }
11972
12033
  return void 0;
11973
12034
  }
12035
+ function assertSparkFunding(data, ownHash) {
12036
+ const fail = (field, expected, received) => {
12037
+ throw new SwapVerificationError("Invalid native Spark funding terms", {
12038
+ field,
12039
+ expected,
12040
+ received,
12041
+ swapId: data.id
12042
+ });
12043
+ };
12044
+ if (normalizeHash(data.hash_lock) !== normalizeHash(ownHash)) {
12045
+ fail("hash_lock", ownHash, data.hash_lock);
12046
+ }
12047
+ let prefix;
12048
+ try {
12049
+ prefix = bech32m.decode(
12050
+ data.funding.address,
12051
+ 1023
12052
+ ).prefix;
12053
+ } catch {
12054
+ fail(
12055
+ "funding.address",
12056
+ "valid Spark bech32m address",
12057
+ data.funding.address
12058
+ );
12059
+ return;
12060
+ }
12061
+ const expectedPrefix = data.network === "bitcoin" ? "spark" : data.network === "regtest" ? "sparkrt" : void 0;
12062
+ if (!expectedPrefix || prefix !== expectedPrefix)
12063
+ fail(
12064
+ "funding.address",
12065
+ expectedPrefix ?? "supported Spark network",
12066
+ prefix
12067
+ );
12068
+ if (!Number.isSafeInteger(data.funding.expiry_duration_secs) || data.funding.expiry_duration_secs <= 0) {
12069
+ fail(
12070
+ "funding.expiry_duration_secs",
12071
+ "positive safe integer",
12072
+ String(data.funding.expiry_duration_secs)
12073
+ );
12074
+ }
12075
+ if (!/^[1-9][0-9]*$/.test(data.source_amount) || BigInt(data.source_amount) > 18446744073709551615n) {
12076
+ fail("source_amount", "positive u64 sats", data.source_amount);
12077
+ }
12078
+ }
11974
12079
  var MAX_RETRIES = 10;
11975
12080
  var SKIP_COUNT = 10;
11976
12081
  function isHashCollisionError(message) {
@@ -12024,6 +12129,7 @@ async function createArkadeToEvmSwapGeneric(options, ctx, claimingAddressOverrid
12024
12129
  amount_out: options.targetAmount?.toString(),
12025
12130
  referral_code: options.referralCode ?? ctx.referralCode,
12026
12131
  extra_fees: options.extraFees,
12132
+ promo_code: options.promoCode,
12027
12133
  gasless: options.gasless ?? true,
12028
12134
  bridge_target_chain: options.bridgeParams?.targetChain,
12029
12135
  bridge_target_token_address: options.bridgeParams?.targetTokenAddress,
@@ -12089,7 +12195,8 @@ async function createArkadeToLightningSwap(options, ctx) {
12089
12195
  user_id: userId,
12090
12196
  arkade_htlc_script_version: ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12091
12197
  referral_code: options.referralCode ?? ctx.referralCode,
12092
- extra_fees: options.extraFees
12198
+ extra_fees: options.extraFees,
12199
+ promo_code: options.promoCode
12093
12200
  };
12094
12201
  const { data, error } = await ctx.apiClient.POST("/swap/arkade/lightning", {
12095
12202
  body
@@ -12129,6 +12236,7 @@ async function createBitcoinToEvmSwap(options, ctx, claimingAddressOverride) {
12129
12236
  amount_out: options.targetAmount?.toString(),
12130
12237
  referral_code: options.referralCode ?? ctx.referralCode,
12131
12238
  extra_fees: options.extraFees,
12239
+ promo_code: options.promoCode,
12132
12240
  gasless: options.gasless ?? true,
12133
12241
  bridge_target_chain: options.bridgeParams?.targetChain,
12134
12242
  bridge_target_token_address: options.bridgeParams?.targetTokenAddress,
@@ -12180,6 +12288,7 @@ async function createBitcoinToArkadeSwap(options, ctx) {
12180
12288
  target_arkade_address: options.targetAddress,
12181
12289
  referral_code: options.referralCode ?? ctx.referralCode,
12182
12290
  extra_fees: options.extraFees,
12291
+ promo_code: options.promoCode,
12183
12292
  btc_htlc_script_version: BTC_HTLC_SCRIPT_VERSION_STRICT,
12184
12293
  arkade_htlc_script_version: ARKADE_HTLC_SCRIPT_VERSION_STRICT
12185
12294
  };
@@ -12237,7 +12346,8 @@ async function createBitcoinToLightningSwap(options, ctx) {
12237
12346
  user_id: userId,
12238
12347
  btc_htlc_script_version: BTC_HTLC_SCRIPT_VERSION_STRICT,
12239
12348
  referral_code: options.referralCode ?? ctx.referralCode,
12240
- extra_fees: options.extraFees
12349
+ extra_fees: options.extraFees,
12350
+ promo_code: options.promoCode
12241
12351
  };
12242
12352
  const { data, error } = await ctx.apiClient.POST("/swap/bitcoin/lightning", {
12243
12353
  body
@@ -12295,6 +12405,7 @@ async function createEvmToArkadeSwapGeneric(options, ctx) {
12295
12405
  amount_out: options.targetAmount ? Number(options.targetAmount) : void 0,
12296
12406
  referral_code: options.referralCode ?? ctx.referralCode,
12297
12407
  extra_fees: options.extraFees,
12408
+ promo_code: options.promoCode,
12298
12409
  gasless: options.gasless ?? false,
12299
12410
  arkade_htlc_script_version: ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12300
12411
  bridge_source_chain: options.inboundBridgeParams?.sourceChain,
@@ -12343,6 +12454,7 @@ async function createEvmToBitcoinSwap(options, ctx) {
12343
12454
  amount_out: options.targetAmount ? Number(options.targetAmount) : void 0,
12344
12455
  referral_code: options.referralCode ?? ctx.referralCode,
12345
12456
  extra_fees: options.extraFees,
12457
+ promo_code: options.promoCode,
12346
12458
  gasless: options.gasless ?? false,
12347
12459
  bridge_source_chain: options.inboundBridgeParams?.sourceChain,
12348
12460
  bridge_source_token_address: options.inboundBridgeParams?.sourceTokenAddress
@@ -12402,6 +12514,7 @@ async function createEvmToLightningSwap(options, ctx) {
12402
12514
  user_id: userId,
12403
12515
  referral_code: options.referralCode ?? ctx.referralCode,
12404
12516
  extra_fees: options.extraFees,
12517
+ promo_code: options.promoCode,
12405
12518
  gasless: options.gasless ?? false,
12406
12519
  bridge_source_chain: options.inboundBridgeParams?.sourceChain,
12407
12520
  bridge_source_token_address: options.inboundBridgeParams?.sourceTokenAddress
@@ -12449,6 +12562,7 @@ async function createLightningToArkadeSwap(options, ctx) {
12449
12562
  arkade_htlc_script_version: ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12450
12563
  referral_code: options.referralCode ?? ctx.referralCode,
12451
12564
  extra_fees: options.extraFees,
12565
+ promo_code: options.promoCode,
12452
12566
  // `undefined` is omitted from the JSON body so the server applies its
12453
12567
  // default; an explicit "" is sent to blank the invoice description.
12454
12568
  invoice_description: options.invoiceDescription
@@ -12491,6 +12605,7 @@ async function createLightningToBitcoinSwap(options, ctx) {
12491
12605
  btc_htlc_script_version: BTC_HTLC_SCRIPT_VERSION_STRICT,
12492
12606
  referral_code: options.referralCode ?? ctx.referralCode,
12493
12607
  extra_fees: options.extraFees,
12608
+ promo_code: options.promoCode,
12494
12609
  invoice_description: options.invoiceDescription
12495
12610
  };
12496
12611
  const { data, error } = await ctx.apiClient.POST(
@@ -12535,6 +12650,7 @@ async function createLightningToEvmSwap(options, ctx, claimingAddressOverride) {
12535
12650
  invoice_description: options.invoiceDescription,
12536
12651
  referral_code: options.referralCode ?? ctx.referralCode,
12537
12652
  extra_fees: options.extraFees,
12653
+ promo_code: options.promoCode,
12538
12654
  gasless: options.gasless ?? true,
12539
12655
  bridge_target_chain: options.bridgeParams?.targetChain,
12540
12656
  bridge_target_token_address: options.bridgeParams?.targetTokenAddress,
@@ -12568,6 +12684,68 @@ async function createLightningToEvmSwap(options, ctx, claimingAddressOverride) {
12568
12684
  return { response: data, swapParams };
12569
12685
  });
12570
12686
  }
12687
+ async function createSparkToEvmSwap(options, ctx, claimingAddressOverride) {
12688
+ if (options.sourceAmount == null === (options.targetAmount == null)) {
12689
+ throw new Error("Provide exactly one of sourceAmount or targetAmount");
12690
+ }
12691
+ if (options.sourceAmount != null && (!Number.isSafeInteger(options.sourceAmount) || options.sourceAmount <= 0)) {
12692
+ throw new Error("sourceAmount must be a positive safe integer in sats");
12693
+ }
12694
+ return retryOnHashCollision(ctx, async () => {
12695
+ const swapParams = await ctx.deriveSwapParams();
12696
+ const hashLock = `0x${bytesToHex(swapParams.preimageHash)}`;
12697
+ const userId = bytesToHex(swapParams.userId);
12698
+ const claimingAddress = claimingAddressOverride ?? deriveEvmAddress(swapParams.secretKey);
12699
+ const body = {
12700
+ hash_lock: hashLock,
12701
+ user_id: userId,
12702
+ claiming_address: claimingAddress,
12703
+ target_address: options.targetAddress,
12704
+ token_address: options.tokenAddress,
12705
+ evm_chain_id: options.evmChainId,
12706
+ amount_in: options.sourceAmount,
12707
+ amount_out: options.targetAmount?.toString(),
12708
+ referral_code: options.referralCode ?? ctx.referralCode,
12709
+ extra_fees: options.extraFees,
12710
+ promo_code: options.promoCode,
12711
+ gasless: options.gasless ?? true,
12712
+ bridge_target_chain: options.bridgeParams?.targetChain,
12713
+ bridge_target_token_address: options.bridgeParams?.targetTokenAddress,
12714
+ bridge_recipient_setup: options.bridgeParams?.recipientSetup
12715
+ };
12716
+ const { data, error } = await ctx.apiClient.POST("/swap/spark/evm", {
12717
+ body
12718
+ });
12719
+ if (error) {
12720
+ throw new Error(`Failed to create swap: ${JSON.stringify(error)}`);
12721
+ }
12722
+ if (!data) {
12723
+ throw new Error("No swap data returned");
12724
+ }
12725
+ assertSparkFunding(data, hashLock);
12726
+ if (options.sourceAmount != null && BigInt(data.source_amount) !== BigInt(options.sourceAmount)) {
12727
+ throw new Error(
12728
+ "Native Spark source amount differs from the requested amount"
12729
+ );
12730
+ }
12731
+ assertAddressEchoed(data, "target_evm_address", options.targetAddress);
12732
+ assertAddressEchoed(data, "client_evm_address", claimingAddress);
12733
+ await ctx.storeSwap(
12734
+ data.id,
12735
+ swapParams,
12736
+ {
12737
+ ...data,
12738
+ direction: "spark_to_evm"
12739
+ },
12740
+ options.targetAddress,
12741
+ {
12742
+ recipient: options.bridgeParams?.recipient,
12743
+ recipientWallet: options.bridgeParams?.recipientWallet
12744
+ }
12745
+ );
12746
+ return { response: data, swapParams };
12747
+ });
12748
+ }
12571
12749
  init_sha2();
12572
12750
  init_utils();
12573
12751
  var REQUEST_TIMEOUT_MS = 5e3;
@@ -13796,8 +13974,7 @@ async function buildArkadeClaim(params) {
13796
13974
  // The preimage will be added to the witness during signing
13797
13975
  witnessData: preimageBytes
13798
13976
  }));
13799
- const { ArkAddress: ArkAddress2 } = await import("./dist-OHZT2JOQ-IUFU3NGC.js");
13800
- const destAddr = ArkAddress2.decode(destinationAddress);
13977
+ const destAddr = ArkAddress.decode(destinationAddress);
13801
13978
  const destPkScript = destAddr.pkScript;
13802
13979
  const outputs = [
13803
13980
  {
@@ -13867,7 +14044,7 @@ async function continueArkadeClaim(params) {
13867
14044
  unilateralClaimDelay,
13868
14045
  unilateralRefundDelay,
13869
14046
  unilateralRefundWithoutReceiverDelay,
13870
- // destinationAddress not needed — we continue an existing pending tx
14047
+ destinationAddress,
13871
14048
  network,
13872
14049
  arkadeHtlcScriptVersion,
13873
14050
  arkadeServerUrl
@@ -13948,7 +14125,6 @@ async function continueArkadeClaim(params) {
13948
14125
  throw new Error("Total VTXO amount is zero");
13949
14126
  }
13950
14127
  const claimLeafScript = vhtlc.claim();
13951
- const claimScriptByte = claimLeafScript[1];
13952
14128
  const tapTree = vhtlc.encode();
13953
14129
  logger.info({
13954
14130
  event: "arkade.claim.continue_vtxos_found",
@@ -13996,6 +14172,25 @@ async function continueArkadeClaim(params) {
13996
14172
  "No pending transactions found at the VHTLC address. The claim may have already been finalized or was never submitted."
13997
14173
  );
13998
14174
  }
14175
+ if (destinationAddress) {
14176
+ const expectedScript = hex.encode(
14177
+ ArkAddress.decode(destinationAddress).pkScript
14178
+ );
14179
+ for (const { arkTxid, finalArkTx } of pendingTxs) {
14180
+ const arkTx = Transaction2.fromPSBT(base64.decode(finalArkTx));
14181
+ if (arkTx.id !== arkTxid) {
14182
+ throw new Error(
14183
+ "Pending Arkade claim transaction ID does not match its PSBT."
14184
+ );
14185
+ }
14186
+ const { amount, script } = arkTx.getOutput(0);
14187
+ if (!amount || !script || hex.encode(script) !== expectedScript) {
14188
+ throw new Error(
14189
+ "Pending Arkade claim does not pay the requested destination address."
14190
+ );
14191
+ }
14192
+ }
14193
+ }
13999
14194
  logger.info({
14000
14195
  event: "arkade.claim.pending_txs_found",
14001
14196
  message: "Found pending Arkade claim transactions",
@@ -14007,9 +14202,6 @@ async function continueArkadeClaim(params) {
14007
14202
  const finalCheckpoints = await Promise.all(
14008
14203
  signedCheckpointTxs.map(async (c) => {
14009
14204
  const checkpointTx = Transaction2.fromPSBT(base64.decode(c));
14010
- checkpointTx.updateInput(0, {
14011
- witnessScript: claimScriptByte
14012
- });
14013
14205
  for (let i = 0; i < checkpointTx.inputsLength; i++) {
14014
14206
  ensureConditionWitness(checkpointTx, i, preimageBytes);
14015
14207
  }
@@ -14957,13 +15149,15 @@ function fromWireQuoteResponse(wire) {
14957
15149
  target_amount: wire.target_amount,
14958
15150
  net_source_amount: wire.net_source_amount,
14959
15151
  net_target_amount: wire.net_target_amount,
14960
- bridge_fee: wire.bridge_fee ?? void 0
15152
+ bridge_fee: wire.bridge_fee ?? void 0,
15153
+ promo: wire.promo ?? void 0
14961
15154
  };
14962
15155
  }
14963
15156
  function fromWireReferralFeeResponse(wire) {
14964
15157
  return {
14965
15158
  extra_fee_rate: wire.extra_fee_rate,
14966
15159
  base_fee_rate: wire.base_fee_rate ?? void 0,
15160
+ promo: wire.promo ?? void 0,
14967
15161
  referral_label: wire.referral_label ?? void 0
14968
15162
  };
14969
15163
  }
@@ -15411,7 +15605,8 @@ function satsToLightningOptions(options, sourceName) {
15411
15605
  const kind = classifyLightningDestination(destination);
15412
15606
  const common = {
15413
15607
  referralCode: options.referralCode,
15414
- extraFees: options.extraFees
15608
+ extraFees: options.extraFees,
15609
+ promoCode: options.promoCode
15415
15610
  };
15416
15611
  if (kind === "invoice") {
15417
15612
  if (options.sourceAmount != null && options.targetAmount != null) {
@@ -16249,7 +16444,11 @@ var Client = class _Client {
16249
16444
  async getReferralFee(params) {
16250
16445
  const { data, error } = await this.#apiClient.GET("/referral-fee", {
16251
16446
  params: {
16252
- query: { ref: params.referralCode, extra_fees: params.extraFees }
16447
+ query: {
16448
+ ref: params.referralCode,
16449
+ extra_fees: params.extraFees,
16450
+ promo_code: params.promoCode
16451
+ }
16253
16452
  }
16254
16453
  });
16255
16454
  if (error || !data) {
@@ -16320,12 +16519,14 @@ var Client = class _Client {
16320
16519
  ...params,
16321
16520
  referralCode: params.referralCode ?? this.#config.referralCode
16322
16521
  };
16323
- const referralFee = params.referralCode != null || params.extraFees != null ? this.#composeStatic(
16522
+ const fetchReferralFee = () => this.getReferralFee({
16523
+ referralCode: params.referralCode,
16524
+ extraFees: params.extraFees,
16525
+ promoCode: params.promoCode
16526
+ });
16527
+ const referralFee = params.promoCode != null ? fetchReferralFee() : params.referralCode != null || params.extraFees != null ? this.#composeStatic(
16324
16528
  `referral-fee|${params.referralCode ?? ""}|${params.extraFees ?? ""}`,
16325
- () => this.getReferralFee({
16326
- referralCode: params.referralCode,
16327
- extraFees: params.extraFees
16328
- })
16529
+ fetchReferralFee
16329
16530
  ) : Promise.resolve(void 0);
16330
16531
  const [swapPairs, networkFees, chainConfig, referral] = await Promise.all([
16331
16532
  this.#composeStatic("swap-pairs", () => this.getSwapPairs()),
@@ -16339,6 +16540,7 @@ var Client = class _Client {
16339
16540
  chainConfig,
16340
16541
  referralExtraFeeRate: referral?.extra_fee_rate,
16341
16542
  referralBaseFeeRate: referral?.base_fee_rate,
16543
+ referralPromo: referral?.promo,
16342
16544
  getDexQuote: (p) => this.getDexQuote(p)
16343
16545
  });
16344
16546
  }
@@ -16412,6 +16614,7 @@ var Client = class _Client {
16412
16614
  // Per-call referral wins; fall back to the client default.
16413
16615
  referralCode: params.referralCode ?? this.#config.referralCode,
16414
16616
  extraFees: params.extraFees,
16617
+ promoCode: params.promoCode,
16415
16618
  bridgeRecipientSetup: params.bridgeRecipientSetup
16416
16619
  });
16417
16620
  } catch (err) {
@@ -16465,7 +16668,8 @@ var Client = class _Client {
16465
16668
  target_amount_sats: params.targetAmountSats,
16466
16669
  // Per-call referral wins; fall back to the client default.
16467
16670
  ref: params.referralCode ?? this.#config.referralCode,
16468
- extra_fees: params.extraFees
16671
+ extra_fees: params.extraFees,
16672
+ promo_code: params.promoCode
16469
16673
  }
16470
16674
  }
16471
16675
  });
@@ -16490,7 +16694,8 @@ var Client = class _Client {
16490
16694
  protocolFeeRate: data.protocol_fee_rate,
16491
16695
  minAmountSats: data.min_amount_sats,
16492
16696
  maxAmountSats: data.max_amount_sats,
16493
- exchangeRate: data.exchange_rate
16697
+ exchangeRate: data.exchange_rate,
16698
+ promo: data.promo ?? void 0
16494
16699
  };
16495
16700
  }
16496
16701
  /**
@@ -16518,7 +16723,8 @@ var Client = class _Client {
16518
16723
  lnurl: kind === "lnurl" ? destination : void 0,
16519
16724
  targetAmountSats,
16520
16725
  referralCode: params.referralCode,
16521
- extraFees: params.extraFees
16726
+ extraFees: params.extraFees,
16727
+ promoCode: params.promoCode
16522
16728
  });
16523
16729
  const sourceAmountOut = evmSource ? q.sourceAmount : sourcePinned ? q.sourceAmount : String(q.targetAmountSats);
16524
16730
  const targetAmountOut = !evmSource && sourcePinned ? q.sourceAmount : String(q.targetAmountSats);
@@ -16533,7 +16739,8 @@ var Client = class _Client {
16533
16739
  source_amount: sourceAmountOut,
16534
16740
  target_amount: targetAmountOut,
16535
16741
  net_source_amount: q.sourceAmount,
16536
- net_target_amount: String(q.targetAmountSats)
16742
+ net_target_amount: String(q.targetAmountSats),
16743
+ promo: q.promo
16537
16744
  };
16538
16745
  }
16539
16746
  /**
@@ -16626,7 +16833,8 @@ var Client = class _Client {
16626
16833
  // Per-call referralCode wins; fall back to the client config default
16627
16834
  // (set via withReferralCode / withOrgCode).
16628
16835
  ref: params.referralCode ?? this.#config.referralCode,
16629
- extra_fees: params.extraFees
16836
+ extra_fees: params.extraFees,
16837
+ promo_code: params.promoCode
16630
16838
  };
16631
16839
  const { data, error } = await this.#apiClient.GET("/quote", {
16632
16840
  params: {
@@ -17001,7 +17209,7 @@ var Client = class _Client {
17001
17209
  }
17002
17210
  const swap = storedSwap.response;
17003
17211
  const secret = storedSwap.preimage;
17004
- if (swap.direction === "arkade_to_evm" || swap.direction === "bitcoin_to_evm" || swap.direction === "lightning_to_evm") {
17212
+ if (swap.direction === "arkade_to_evm" || swap.direction === "bitcoin_to_evm" || swap.direction === "lightning_to_evm" || swap.direction === "spark_to_evm") {
17005
17213
  const evmSwap = swap;
17006
17214
  const bridgeTargetChain = evmSwap.bridge_target_chain;
17007
17215
  const isSolanaBridge = bridgeTargetChain === "Solana";
@@ -17073,7 +17281,7 @@ var Client = class _Client {
17073
17281
  const swap = await this.getSwap(id, {
17074
17282
  updateStorage: true
17075
17283
  });
17076
- if (swap.direction !== "arkade_to_evm" && swap.direction !== "bitcoin_to_evm" && swap.direction !== "lightning_to_evm") {
17284
+ if (swap.direction !== "arkade_to_evm" && swap.direction !== "bitcoin_to_evm" && swap.direction !== "lightning_to_evm" && swap.direction !== "spark_to_evm") {
17077
17285
  throw new Error(
17078
17286
  `Expected an EVM-targeted swap (arkade_to_evm, bitcoin_to_evm or lightning_to_evm), got ${swap.direction}.`
17079
17287
  );
@@ -17261,7 +17469,7 @@ var Client = class _Client {
17261
17469
  }
17262
17470
  /** Whether an EVM claim can use the existing automatic sponsorship path. */
17263
17471
  canSponsorClaim(swap) {
17264
- return (swap.direction === "arkade_to_evm" || swap.direction === "bitcoin_to_evm" || swap.direction === "lightning_to_evm") && swap.evm_chain_id !== 30 && swap.evm_chain_id !== 31;
17472
+ return (swap.direction === "arkade_to_evm" || swap.direction === "bitcoin_to_evm" || swap.direction === "lightning_to_evm" || swap.direction === "spark_to_evm") && swap.evm_chain_id !== 30 && swap.evm_chain_id !== 31;
17265
17473
  }
17266
17474
  /**
17267
17475
  * Claims through the existing server relay or configured Arbitrum UserOp.
@@ -17439,12 +17647,7 @@ var Client = class _Client {
17439
17647
  };
17440
17648
  }
17441
17649
  if (vtxoStatus === "spent") {
17442
- const continued = await this.continueArkadeClaimSwap(id);
17443
- if (continued.success) return continued;
17444
- return {
17445
- success: false,
17446
- message: "All VTXOs have already been spent."
17447
- };
17650
+ return this.#continueArkadeClaim(claimParams, options);
17448
17651
  }
17449
17652
  if (vtxoStatus === "spendable") {
17450
17653
  return this.#claimArkadeOffchain(claimParams, options);
@@ -17675,13 +17878,16 @@ var Client = class _Client {
17675
17878
  message: `Expected an Arkade-destination swap, got ${swap.direction}.`
17676
17879
  };
17677
17880
  }
17678
- const claimParams = this.#extractArkadeClaimParams(id, storedSwap);
17881
+ return this.#continueArkadeClaim(
17882
+ this.#extractArkadeClaimParams(id, storedSwap)
17883
+ );
17884
+ }
17885
+ async #continueArkadeClaim(claimParams, options) {
17679
17886
  try {
17680
17887
  const result = await continueArkadeClaim({
17681
17888
  ...claimParams,
17682
- destinationAddress: "",
17683
- // not needed for continue
17684
- arkadeServerUrl: this.#config.arkadeServerUrl,
17889
+ destinationAddress: options?.destinationAddress,
17890
+ arkadeServerUrl: options?.arkadeServerUrl ?? this.#config.arkadeServerUrl,
17685
17891
  logger: this.#config.logger,
17686
17892
  logLevel: this.#config.logLevel
17687
17893
  });
@@ -20060,6 +20266,7 @@ network='${network}'`
20060
20266
  sourceAmount: options.sourceAmount,
20061
20267
  referralCode: options.referralCode,
20062
20268
  extraFees: options.extraFees,
20269
+ promoCode: options.promoCode,
20063
20270
  bridgeRecipientSetup: options.bridgeRecipientSetup
20064
20271
  });
20065
20272
  if (BigInt(quote.net_target_amount) <= 0n) {
@@ -20111,6 +20318,7 @@ network='${network}'`
20111
20318
  targetAmount: options.targetAmount ? BigInt(options.targetAmount) : void 0,
20112
20319
  referralCode: options.referralCode,
20113
20320
  extraFees: options.extraFees,
20321
+ promoCode: options.promoCode,
20114
20322
  bridgeParams
20115
20323
  });
20116
20324
  }
@@ -20136,7 +20344,8 @@ network='${network}'`
20136
20344
  ...options.sourceAmount != null ? { sourceAmountSats: Number(options.sourceAmount) } : { targetAmountSats: Number(options.targetAmount) },
20137
20345
  targetAddress: options.targetAddress,
20138
20346
  referralCode: options.referralCode,
20139
- extraFees: options.extraFees
20347
+ extraFees: options.extraFees,
20348
+ promoCode: options.promoCode
20140
20349
  });
20141
20350
  }
20142
20351
  if (isLightning(sourceAsset) && isBtcOnchain(targetAsset)) {
@@ -20149,7 +20358,8 @@ network='${network}'`
20149
20358
  ...options.sourceAmount != null ? { sourceAmountSats: Number(options.sourceAmount) } : { targetAmountSats: Number(options.targetAmount) },
20150
20359
  targetAddress: options.targetAddress,
20151
20360
  referralCode: options.referralCode,
20152
- extraFees: options.extraFees
20361
+ extraFees: options.extraFees,
20362
+ promoCode: options.promoCode
20153
20363
  });
20154
20364
  }
20155
20365
  if (isLightning(sourceAsset) && isEvmToken(targetChain)) {
@@ -20166,6 +20376,25 @@ network='${network}'`
20166
20376
  targetAmount: options.targetAmount == null ? void 0 : BigInt(options.targetAmount),
20167
20377
  referralCode: options.referralCode,
20168
20378
  extraFees: options.extraFees,
20379
+ promoCode: options.promoCode,
20380
+ bridgeParams
20381
+ });
20382
+ }
20383
+ if (sourceAsset.chain === "Spark" && isEvmToken(targetChain)) {
20384
+ if (options.sourceAmount == null === (options.targetAmount == null)) {
20385
+ throw new Error(
20386
+ "Provide exactly one of sourceAmount (sats on Spark) or targetAmount (token units to receive) for Spark \u2192 EVM swaps"
20387
+ );
20388
+ }
20389
+ return this.createSparkToEvmSwap({
20390
+ targetAddress: options.targetAddress,
20391
+ tokenAddress,
20392
+ evmChainId: Number(targetChain),
20393
+ sourceAmount: options.sourceAmount == null ? void 0 : Number(options.sourceAmount),
20394
+ targetAmount: options.targetAmount == null ? void 0 : BigInt(options.targetAmount),
20395
+ referralCode: options.referralCode,
20396
+ extraFees: options.extraFees,
20397
+ promoCode: options.promoCode,
20169
20398
  bridgeParams
20170
20399
  });
20171
20400
  }
@@ -20178,6 +20407,7 @@ network='${network}'`
20178
20407
  targetAmount: options.targetAmount == null ? void 0 : BigInt(options.targetAmount),
20179
20408
  referralCode: options.referralCode,
20180
20409
  extraFees: options.extraFees,
20410
+ promoCode: options.promoCode,
20181
20411
  bridgeParams
20182
20412
  });
20183
20413
  }
@@ -20191,7 +20421,8 @@ network='${network}'`
20191
20421
  satsReceive: Number(options.targetAmount),
20192
20422
  targetAddress: options.targetAddress,
20193
20423
  referralCode: options.referralCode,
20194
- extraFees: options.extraFees
20424
+ extraFees: options.extraFees,
20425
+ promoCode: options.promoCode
20195
20426
  });
20196
20427
  }
20197
20428
  if (isEvmSwapSource(sourceChain, sourceTokenId) && isLightning(targetAsset)) {
@@ -20208,6 +20439,7 @@ network='${network}'`
20208
20439
  userAddress: options.userAddress,
20209
20440
  referralCode: options.referralCode,
20210
20441
  extraFees: options.extraFees,
20442
+ promoCode: options.promoCode,
20211
20443
  gasless: options.gasless,
20212
20444
  inboundBridgeParams
20213
20445
  };
@@ -20257,6 +20489,7 @@ network='${network}'`
20257
20489
  targetAmount: options.targetAmount == null ? void 0 : Number(options.targetAmount),
20258
20490
  referralCode: options.referralCode,
20259
20491
  extraFees: options.extraFees,
20492
+ promoCode: options.promoCode,
20260
20493
  gasless: options.gasless,
20261
20494
  inboundBridgeParams
20262
20495
  });
@@ -20276,6 +20509,7 @@ network='${network}'`
20276
20509
  targetAmount: options.targetAmount == null ? void 0 : Number(options.targetAmount),
20277
20510
  referralCode: options.referralCode,
20278
20511
  extraFees: options.extraFees,
20512
+ promoCode: options.promoCode,
20279
20513
  gasless: options.gasless,
20280
20514
  inboundBridgeParams
20281
20515
  });
@@ -20463,6 +20697,13 @@ network='${network}'`
20463
20697
  await this.#rifClaimAddress(options)
20464
20698
  );
20465
20699
  }
20700
+ async createSparkToEvmSwap(options) {
20701
+ return createSparkToEvmSwap(
20702
+ options,
20703
+ this.#getCreateContext(),
20704
+ await this.#rifClaimAddress(options)
20705
+ );
20706
+ }
20466
20707
  // =========================================================================
20467
20708
  // Swap Creation - Arkade to Lightning
20468
20709
  // =========================================================================
@@ -22943,6 +23184,7 @@ export {
22943
23184
  getBridgeTargetChain,
22944
23185
  getCctpBridgeTokens,
22945
23186
  getUsdt0BridgeTokens,
23187
+ isSpark,
22946
23188
  Signer,
22947
23189
  computeHash160,
22948
23190
  buildOnchainClaimTransaction,
@@ -22993,4 +23235,4 @@ export {
22993
23235
  @scure/bip39/index.js:
22994
23236
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
22995
23237
  */
22996
- //# sourceMappingURL=chunk-BVTLZLT2.js.map
23238
+ //# sourceMappingURL=chunk-YBQPH7NH.js.map