@satora/swap 1.10.2 → 1.11.1

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 (85) hide show
  1. package/dist/{chunk-K4BQUZC6.js → chunk-2AULREFC.js} +2 -2
  2. package/dist/chunk-2AULREFC.js.map +1 -0
  3. package/dist/{chunk-2LGHF7A3.cjs → chunk-4NVWIR74.cjs} +755 -439
  4. package/dist/chunk-4NVWIR74.cjs.map +1 -0
  5. package/dist/{chunk-HWK7LVVX.js → chunk-JHZHRY7S.js} +130 -51
  6. package/dist/chunk-JHZHRY7S.js.map +1 -0
  7. package/dist/{chunk-7GOXIT24.cjs → chunk-JZTF4JNH.cjs} +110 -31
  8. package/dist/chunk-JZTF4JNH.cjs.map +1 -0
  9. package/dist/{chunk-OJNQCRHU.cjs → chunk-Q4TOBBAN.cjs} +7 -7
  10. package/dist/{chunk-OJNQCRHU.cjs.map → chunk-Q4TOBBAN.cjs.map} +1 -1
  11. package/dist/{chunk-MYOGO44L.cjs → chunk-TNZW35XA.cjs} +2 -2
  12. package/dist/chunk-TNZW35XA.cjs.map +1 -0
  13. package/dist/{chunk-VBNBVJLB.js → chunk-TT3J2OOS.js} +8 -8
  14. package/dist/{chunk-VBNBVJLB.js.map → chunk-TT3J2OOS.js.map} +1 -1
  15. package/dist/{chunk-S4T4GK5G.js → chunk-WQMAL2VD.js} +391 -75
  16. package/dist/chunk-WQMAL2VD.js.map +1 -0
  17. package/dist/delegate.cjs +3 -3
  18. package/dist/delegate.js +2 -2
  19. package/dist/dist-MHRQ5FFV.cjs +394 -0
  20. package/dist/{dist-MMYSP6LP.cjs.map → dist-MHRQ5FFV.cjs.map} +1 -1
  21. package/dist/{dist-L5LHQNRK.js → dist-SHY7I6SH.js} +13 -13
  22. package/dist/{fundSwap-IUPFISXM-ON5IVSSZ.cjs → fundSwap-UBCHMUP4-BEMQNSFQ.cjs} +15 -15
  23. package/dist/{fundSwap-IUPFISXM-ON5IVSSZ.cjs.map → fundSwap-UBCHMUP4-BEMQNSFQ.cjs.map} +1 -1
  24. package/dist/{fundSwap-IUPFISXM-6IBPJ5O7.js → fundSwap-UBCHMUP4-WBLYE6MC.js} +11 -11
  25. package/dist/index.cjs +28 -24
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.js +17 -13
  28. package/dist/index.js.map +1 -1
  29. package/dist/node.cjs +11 -6
  30. package/dist/node.cjs.map +1 -1
  31. package/dist/node.js +11 -6
  32. package/dist/node.js.map +1 -1
  33. package/dist/types/cjs/pure/cctp/attestation.d.cts +5 -3
  34. package/dist/types/cjs/pure/cctp/types.d.cts +11 -2
  35. package/dist/types/cjs/pure/cctp-inbound/submit.d.cts +2 -0
  36. package/dist/types/cjs/pure/cctp-inbound/types.d.cts +5 -0
  37. package/dist/types/cjs/pure/cctp-inbound/userOp.d.cts +11 -0
  38. package/dist/types/cjs/pure/client.d.cts +61 -18
  39. package/dist/types/cjs/pure/create/arkade-to-lightning.d.cts +8 -0
  40. package/dist/types/cjs/pure/create/bitcoin-to-lightning.d.cts +8 -0
  41. package/dist/types/cjs/pure/create/types.d.cts +16 -4
  42. package/dist/types/cjs/pure/evm/coordinator.d.cts +4 -0
  43. package/dist/types/cjs/pure/evm/wallet.d.cts +4 -4
  44. package/dist/types/cjs/pure/generated/api.d.cts +102 -21
  45. package/dist/types/cjs/pure/redeem/arkade.d.cts +4 -1
  46. package/dist/types/cjs/pure/storage/types.d.cts +2 -0
  47. package/dist/types/cjs/pure/swap-verification.d.cts +12 -0
  48. package/dist/types/cjs/pure/tokens.d.cts +0 -6
  49. package/dist/types/cjs/pure/types/dex-quote.d.cts +9 -1
  50. package/dist/types/cjs/pure/version.d.cts +4 -4
  51. package/dist/types/cjs/swap/client.d.cts +2 -0
  52. package/dist/types/esm/pure/cctp/attestation.d.ts +5 -3
  53. package/dist/types/esm/pure/cctp/types.d.ts +11 -2
  54. package/dist/types/esm/pure/cctp-inbound/submit.d.ts +2 -0
  55. package/dist/types/esm/pure/cctp-inbound/types.d.ts +5 -0
  56. package/dist/types/esm/pure/cctp-inbound/userOp.d.ts +11 -0
  57. package/dist/types/esm/pure/client.d.ts +61 -18
  58. package/dist/types/esm/pure/create/arkade-to-lightning.d.ts +8 -0
  59. package/dist/types/esm/pure/create/bitcoin-to-lightning.d.ts +8 -0
  60. package/dist/types/esm/pure/create/types.d.ts +16 -4
  61. package/dist/types/esm/pure/evm/coordinator.d.ts +4 -0
  62. package/dist/types/esm/pure/evm/wallet.d.ts +4 -4
  63. package/dist/types/esm/pure/generated/api.d.ts +102 -21
  64. package/dist/types/esm/pure/redeem/arkade.d.ts +4 -1
  65. package/dist/types/esm/pure/storage/types.d.ts +2 -0
  66. package/dist/types/esm/pure/swap-verification.d.ts +12 -0
  67. package/dist/types/esm/pure/tokens.d.ts +0 -6
  68. package/dist/types/esm/pure/types/dex-quote.d.ts +9 -1
  69. package/dist/types/esm/pure/version.d.ts +4 -4
  70. package/dist/types/esm/swap/client.d.ts +2 -0
  71. package/dist/wallet-33OJRHX5-4VM7QDPO.cjs +31 -0
  72. package/dist/{wallet-THELKUYT-26NOFCTE.cjs.map → wallet-33OJRHX5-4VM7QDPO.cjs.map} +1 -1
  73. package/dist/{wallet-THELKUYT-TOHSMRGU.js → wallet-33OJRHX5-PR4S3NI3.js} +2 -2
  74. package/package.json +1 -1
  75. package/dist/chunk-2LGHF7A3.cjs.map +0 -1
  76. package/dist/chunk-7GOXIT24.cjs.map +0 -1
  77. package/dist/chunk-HWK7LVVX.js.map +0 -1
  78. package/dist/chunk-K4BQUZC6.js.map +0 -1
  79. package/dist/chunk-MYOGO44L.cjs.map +0 -1
  80. package/dist/chunk-S4T4GK5G.js.map +0 -1
  81. package/dist/dist-MMYSP6LP.cjs +0 -394
  82. package/dist/wallet-THELKUYT-26NOFCTE.cjs +0 -31
  83. /package/dist/{dist-L5LHQNRK.js.map → dist-SHY7I6SH.js.map} +0 -0
  84. /package/dist/{fundSwap-IUPFISXM-6IBPJ5O7.js.map → fundSwap-UBCHMUP4-WBLYE6MC.js.map} +0 -0
  85. /package/dist/{wallet-THELKUYT-TOHSMRGU.js.map → wallet-33OJRHX5-PR4S3NI3.js.map} +0 -0
@@ -39,14 +39,11 @@ import {
39
39
  refundForAsOwnRefund,
40
40
  submitCctpInboundBalanceUserOp,
41
41
  submitCctpInboundUserOp
42
- } from "./chunk-HWK7LVVX.js";
42
+ } from "./chunk-JHZHRY7S.js";
43
43
  import {
44
44
  createPublicClient,
45
45
  http
46
46
  } from "./chunk-5XYV6L5B.js";
47
- import {
48
- privateKeyToAccount
49
- } from "./chunk-BVGEKZAT.js";
50
47
  import {
51
48
  arbitrum,
52
49
  avalanche,
@@ -83,7 +80,7 @@ import {
83
80
  parseSignature,
84
81
  simulateTransaction,
85
82
  txTypeFor
86
- } from "./chunk-K4BQUZC6.js";
83
+ } from "./chunk-2AULREFC.js";
87
84
  import {
88
85
  ARKADE_HTLC_SCRIPT_VERSION_STRICT,
89
86
  Address,
@@ -118,16 +115,7 @@ import {
118
115
  sha2562,
119
116
  sha512,
120
117
  utils
121
- } from "./chunk-VBNBVJLB.js";
122
- import {
123
- createSdkLogger
124
- } from "./chunk-G6NZFSWU.js";
125
- import {
126
- encodeFunctionData,
127
- erc20Abi,
128
- parseAbi,
129
- toHex
130
- } from "./chunk-KFRNRKGA.js";
118
+ } from "./chunk-TT3J2OOS.js";
131
119
  import {
132
120
  ArkAddress,
133
121
  CSVMultisigTapscript,
@@ -153,6 +141,9 @@ import {
153
141
  secp256k12,
154
142
  setArkPsbtField
155
143
  } from "./chunk-UM6TUP4E.js";
144
+ import {
145
+ createSdkLogger
146
+ } from "./chunk-G6NZFSWU.js";
156
147
  import {
157
148
  bytesToHex,
158
149
  hexToBytes,
@@ -168,6 +159,15 @@ import {
168
159
  hex,
169
160
  init_base
170
161
  } from "./chunk-OBFZJKRF.js";
162
+ import {
163
+ privateKeyToAccount
164
+ } from "./chunk-BVGEKZAT.js";
165
+ import {
166
+ encodeFunctionData,
167
+ erc20Abi,
168
+ parseAbi,
169
+ toHex
170
+ } from "./chunk-KFRNRKGA.js";
171
171
  import {
172
172
  __commonJS,
173
173
  __toESM
@@ -8387,7 +8387,8 @@ async function composeBtcToEvm(params, deps) {
8387
8387
  "composeQuote: no amount pinned (unreachable)"
8388
8388
  );
8389
8389
  }
8390
- const { btcSats, evmSmallest, evmDecimals, bridgeFee } = pivot;
8390
+ const { btcSats, evmSmallest, evmDecimals } = pivot;
8391
+ let { bridgeFee } = pivot;
8391
8392
  const networkFeeSats = baseNetworkFeeSats + pivot.bridgeNativeFeeSats;
8392
8393
  const effectiveFeePct = (deps.referralBaseFeeRate ?? pair.fee_percentage) + (deps.referralExtraFeeRate ?? 0);
8393
8394
  const FEE_SCALE = 10n ** 18n;
@@ -8396,13 +8397,26 @@ async function composeBtcToEvm(params, deps) {
8396
8397
  const totalFeeSats = networkFeeSats + gaslessNetworkFee + protocolFee;
8397
8398
  let netSource;
8398
8399
  let netTarget;
8400
+ const grossTarget = evmSmallest + bridgeFee;
8399
8401
  if (params.sourceAmount != null) {
8400
8402
  const effectiveSats = btcSats - BigInt(totalFeeSats);
8403
+ if (pivot.selfRelayed === true && effectiveSats > 0n) {
8404
+ const net = await dexSourcePinned(
8405
+ effectiveSats,
8406
+ params,
8407
+ deps,
8408
+ btcPegged,
8409
+ pivotChainId,
8410
+ toToken,
8411
+ pivotScale
8412
+ );
8413
+ bridgeFee = net.bridgeFee;
8414
+ }
8401
8415
  netSource = btcSats;
8402
8416
  netTarget = netTargetSourcePinned(
8403
8417
  btcSats,
8404
8418
  effectiveSats,
8405
- evmSmallest,
8419
+ grossTarget - bridgeFee,
8406
8420
  bridgeFee
8407
8421
  );
8408
8422
  } else {
@@ -8425,7 +8439,7 @@ async function composeBtcToEvm(params, deps) {
8425
8439
  // `net_target_amount` above); the server already covers the fee on the input
8426
8440
  // side (`expected_amount_in`), so adding it here would overshoot the pin.
8427
8441
  // Keyed on the same predicate as `net_target` above.
8428
- target_amount: (params.sourceAmount != null ? evmSmallest + bridgeFee : evmSmallest).toString(),
8442
+ target_amount: (params.sourceAmount != null ? grossTarget : evmSmallest).toString(),
8429
8443
  net_source_amount: netSource.toString(),
8430
8444
  net_target_amount: netTarget.toString(),
8431
8445
  bridge_fee: bridgeFee > 0n ? Number(bridgeFee) : void 0
@@ -8445,9 +8459,13 @@ async function dexSourcePinned(btcSats, params, deps, btcPegged, pivotChainId, t
8445
8459
  evmSmallest: BigInt(dexQuote.estimated_amount_out.raw),
8446
8460
  evmDecimals: dexQuote.estimated_amount_out.decimals,
8447
8461
  bridgeFee: BigInt(dexQuote.bridge_fee ?? "0"),
8448
- bridgeNativeFeeSats: bridgeNativeFeeSats(dexQuote)
8462
+ bridgeNativeFeeSats: bridgeNativeFeeSats(dexQuote),
8463
+ selfRelayed: isSelfRelayed(dexQuote)
8449
8464
  };
8450
8465
  }
8466
+ function isSelfRelayed(dexQuote) {
8467
+ return dexQuote.bridge_rate?.router === "cctp" && dexQuote.bridge_rate.self_relayed === true;
8468
+ }
8451
8469
  async function dexTargetPinned(evmSmallest, params, deps, btcPegged, pivotChainId, toToken, pivotScale) {
8452
8470
  const dexQuote = await deps.getDexQuote({
8453
8471
  from: { kind: "evm", chain_id: pivotChainId, address: btcPegged.address },
@@ -11527,6 +11545,24 @@ var SwapVerificationError = class extends Error {
11527
11545
  this.swapId = details.swapId;
11528
11546
  }
11529
11547
  };
11548
+ function assertFixedLockAmount(options, data) {
11549
+ if (options.lightningInvoice === void 0 || options.sourceAmountSats === void 0) {
11550
+ return;
11551
+ }
11552
+ const expected = BigInt(options.sourceAmountSats);
11553
+ const received = BigInt(data.source_amount);
11554
+ if (received !== expected) {
11555
+ throw new SwapVerificationError(
11556
+ `The server asks for a lock of ${received} sats, not the requested ${expected}; do not fund the swap`,
11557
+ {
11558
+ field: "source_amount",
11559
+ expected: expected.toString(),
11560
+ received: received.toString(),
11561
+ swapId: data.id
11562
+ }
11563
+ );
11564
+ }
11565
+ }
11530
11566
  function normalizeHash(hash) {
11531
11567
  return hash.toLowerCase().replace(/^0x/, "");
11532
11568
  }
@@ -11986,7 +12022,7 @@ async function createArkadeToEvmSwapGeneric(options, ctx, claimingAddressOverrid
11986
12022
  evm_chain_id: options.evmChainId,
11987
12023
  amount_in: options.sourceAmount ? Number(options.sourceAmount) : void 0,
11988
12024
  amount_out: options.targetAmount?.toString(),
11989
- referral_code: options.referralCode,
12025
+ referral_code: options.referralCode ?? ctx.referralCode,
11990
12026
  extra_fees: options.extraFees,
11991
12027
  gasless: options.gasless ?? true,
11992
12028
  bridge_target_chain: options.bridgeParams?.targetChain,
@@ -12052,7 +12088,7 @@ async function createArkadeToLightningSwap(options, ctx) {
12052
12088
  refund_pk: refundPk,
12053
12089
  user_id: userId,
12054
12090
  arkade_htlc_script_version: ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12055
- referral_code: options.referralCode,
12091
+ referral_code: options.referralCode ?? ctx.referralCode,
12056
12092
  extra_fees: options.extraFees
12057
12093
  };
12058
12094
  const { data, error } = await ctx.apiClient.POST("/swap/arkade/lightning", {
@@ -12065,6 +12101,7 @@ async function createArkadeToLightningSwap(options, ctx) {
12065
12101
  throw new Error("No swap data returned");
12066
12102
  }
12067
12103
  const { hash } = checkedLightningPaymentHash(options, data);
12104
+ assertFixedLockAmount(options, data);
12068
12105
  assertArkadeToLightningVhtlc(data, normalizeHash(hash), swapParams.publicKey);
12069
12106
  await ctx.storeSwap(data.id, swapParams, {
12070
12107
  ...data,
@@ -12090,7 +12127,7 @@ async function createBitcoinToEvmSwap(options, ctx, claimingAddressOverride) {
12090
12127
  evm_chain_id: options.evmChainId,
12091
12128
  amount_in: options.sourceAmount,
12092
12129
  amount_out: options.targetAmount?.toString(),
12093
- referral_code: options.referralCode,
12130
+ referral_code: options.referralCode ?? ctx.referralCode,
12094
12131
  extra_fees: options.extraFees,
12095
12132
  gasless: options.gasless ?? true,
12096
12133
  bridge_target_chain: options.bridgeParams?.targetChain,
@@ -12141,7 +12178,7 @@ async function createBitcoinToArkadeSwap(options, ctx) {
12141
12178
  user_id: userId,
12142
12179
  sats_receive: options.satsReceive,
12143
12180
  target_arkade_address: options.targetAddress,
12144
- referral_code: options.referralCode,
12181
+ referral_code: options.referralCode ?? ctx.referralCode,
12145
12182
  extra_fees: options.extraFees,
12146
12183
  btc_htlc_script_version: BTC_HTLC_SCRIPT_VERSION_STRICT,
12147
12184
  arkade_htlc_script_version: ARKADE_HTLC_SCRIPT_VERSION_STRICT
@@ -12199,7 +12236,7 @@ async function createBitcoinToLightningSwap(options, ctx) {
12199
12236
  refund_pk: refundPk,
12200
12237
  user_id: userId,
12201
12238
  btc_htlc_script_version: BTC_HTLC_SCRIPT_VERSION_STRICT,
12202
- referral_code: options.referralCode,
12239
+ referral_code: options.referralCode ?? ctx.referralCode,
12203
12240
  extra_fees: options.extraFees
12204
12241
  };
12205
12242
  const { data, error } = await ctx.apiClient.POST("/swap/bitcoin/lightning", {
@@ -12212,6 +12249,7 @@ async function createBitcoinToLightningSwap(options, ctx) {
12212
12249
  throw new Error("No swap data returned");
12213
12250
  }
12214
12251
  const { hash } = checkedLightningPaymentHash(options, data);
12252
+ assertFixedLockAmount(options, data);
12215
12253
  assertBitcoinToLightningHtlc(data, normalizeHash(hash), swapParams.publicKey);
12216
12254
  await ctx.storeSwap(data.id, swapParams, {
12217
12255
  ...data,
@@ -12255,7 +12293,7 @@ async function createEvmToArkadeSwapGeneric(options, ctx) {
12255
12293
  user_address: userAddress,
12256
12294
  amount_in: options.sourceAmount ? options.sourceAmount.toString() : void 0,
12257
12295
  amount_out: options.targetAmount ? Number(options.targetAmount) : void 0,
12258
- referral_code: options.referralCode,
12296
+ referral_code: options.referralCode ?? ctx.referralCode,
12259
12297
  extra_fees: options.extraFees,
12260
12298
  gasless: options.gasless ?? false,
12261
12299
  arkade_htlc_script_version: ARKADE_HTLC_SCRIPT_VERSION_STRICT,
@@ -12303,7 +12341,7 @@ async function createEvmToBitcoinSwap(options, ctx) {
12303
12341
  target_address: options.targetAddress,
12304
12342
  amount_in: options.sourceAmount ? options.sourceAmount.toString() : void 0,
12305
12343
  amount_out: options.targetAmount ? Number(options.targetAmount) : void 0,
12306
- referral_code: options.referralCode,
12344
+ referral_code: options.referralCode ?? ctx.referralCode,
12307
12345
  extra_fees: options.extraFees,
12308
12346
  gasless: options.gasless ?? false,
12309
12347
  bridge_source_chain: options.inboundBridgeParams?.sourceChain,
@@ -12362,7 +12400,7 @@ async function createEvmToLightningSwap(options, ctx) {
12362
12400
  target_amount_sats: options.targetAmountSats,
12363
12401
  user_address: userAddress ?? "",
12364
12402
  user_id: userId,
12365
- referral_code: options.referralCode,
12403
+ referral_code: options.referralCode ?? ctx.referralCode,
12366
12404
  extra_fees: options.extraFees,
12367
12405
  gasless: options.gasless ?? false,
12368
12406
  bridge_source_chain: options.inboundBridgeParams?.sourceChain,
@@ -12409,7 +12447,7 @@ async function createLightningToArkadeSwap(options, ctx) {
12409
12447
  target_amount_sats: options.targetAmountSats,
12410
12448
  target_arkade_address: options.targetAddress,
12411
12449
  arkade_htlc_script_version: ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12412
- referral_code: options.referralCode,
12450
+ referral_code: options.referralCode ?? ctx.referralCode,
12413
12451
  extra_fees: options.extraFees,
12414
12452
  // `undefined` is omitted from the JSON body so the server applies its
12415
12453
  // default; an explicit "" is sent to blank the invoice description.
@@ -12451,7 +12489,7 @@ async function createLightningToBitcoinSwap(options, ctx) {
12451
12489
  target_amount_sats: options.targetAmountSats,
12452
12490
  target_address: options.targetAddress,
12453
12491
  btc_htlc_script_version: BTC_HTLC_SCRIPT_VERSION_STRICT,
12454
- referral_code: options.referralCode,
12492
+ referral_code: options.referralCode ?? ctx.referralCode,
12455
12493
  extra_fees: options.extraFees,
12456
12494
  invoice_description: options.invoiceDescription
12457
12495
  };
@@ -12495,7 +12533,7 @@ async function createLightningToEvmSwap(options, ctx, claimingAddressOverride) {
12495
12533
  amount_in: options.sourceAmount,
12496
12534
  amount_out: options.targetAmount?.toString(),
12497
12535
  invoice_description: options.invoiceDescription,
12498
- referral_code: options.referralCode,
12536
+ referral_code: options.referralCode ?? ctx.referralCode,
12499
12537
  extra_fees: options.extraFees,
12500
12538
  gasless: options.gasless ?? true,
12501
12539
  bridge_target_chain: options.bridgeParams?.targetChain,
@@ -13758,8 +13796,7 @@ async function buildArkadeClaim(params) {
13758
13796
  // The preimage will be added to the witness during signing
13759
13797
  witnessData: preimageBytes
13760
13798
  }));
13761
- const { ArkAddress: ArkAddress2 } = await import("./dist-OHZT2JOQ-IUFU3NGC.js");
13762
- const destAddr = ArkAddress2.decode(destinationAddress);
13799
+ const destAddr = ArkAddress.decode(destinationAddress);
13763
13800
  const destPkScript = destAddr.pkScript;
13764
13801
  const outputs = [
13765
13802
  {
@@ -13829,7 +13866,7 @@ async function continueArkadeClaim(params) {
13829
13866
  unilateralClaimDelay,
13830
13867
  unilateralRefundDelay,
13831
13868
  unilateralRefundWithoutReceiverDelay,
13832
- // destinationAddress not needed — we continue an existing pending tx
13869
+ destinationAddress,
13833
13870
  network,
13834
13871
  arkadeHtlcScriptVersion,
13835
13872
  arkadeServerUrl
@@ -13910,7 +13947,6 @@ async function continueArkadeClaim(params) {
13910
13947
  throw new Error("Total VTXO amount is zero");
13911
13948
  }
13912
13949
  const claimLeafScript = vhtlc.claim();
13913
- const claimScriptByte = claimLeafScript[1];
13914
13950
  const tapTree = vhtlc.encode();
13915
13951
  logger.info({
13916
13952
  event: "arkade.claim.continue_vtxos_found",
@@ -13958,6 +13994,25 @@ async function continueArkadeClaim(params) {
13958
13994
  "No pending transactions found at the VHTLC address. The claim may have already been finalized or was never submitted."
13959
13995
  );
13960
13996
  }
13997
+ if (destinationAddress) {
13998
+ const expectedScript = hex.encode(
13999
+ ArkAddress.decode(destinationAddress).pkScript
14000
+ );
14001
+ for (const { arkTxid, finalArkTx } of pendingTxs) {
14002
+ const arkTx = Transaction2.fromPSBT(base64.decode(finalArkTx));
14003
+ if (arkTx.id !== arkTxid) {
14004
+ throw new Error(
14005
+ "Pending Arkade claim transaction ID does not match its PSBT."
14006
+ );
14007
+ }
14008
+ const { amount, script } = arkTx.getOutput(0);
14009
+ if (!amount || !script || hex.encode(script) !== expectedScript) {
14010
+ throw new Error(
14011
+ "Pending Arkade claim does not pay the requested destination address."
14012
+ );
14013
+ }
14014
+ }
14015
+ }
13961
14016
  logger.info({
13962
14017
  event: "arkade.claim.pending_txs_found",
13963
14018
  message: "Found pending Arkade claim transactions",
@@ -13969,9 +14024,6 @@ async function continueArkadeClaim(params) {
13969
14024
  const finalCheckpoints = await Promise.all(
13970
14025
  signedCheckpointTxs.map(async (c) => {
13971
14026
  const checkpointTx = Transaction2.fromPSBT(base64.decode(c));
13972
- checkpointTx.updateInput(0, {
13973
- witnessScript: claimScriptByte
13974
- });
13975
14027
  for (let i = 0; i < checkpointTx.inputsLength; i++) {
13976
14028
  ensureConditionWitness(checkpointTx, i, preimageBytes);
13977
14029
  }
@@ -14887,7 +14939,8 @@ function fromWireBridgeRate(wire) {
14887
14939
  fee_token: wire.fee_token,
14888
14940
  proportional_fee_millionths: wire.proportional_fee_millionths,
14889
14941
  flat: wire.flat,
14890
- flat_with_setup: wire.flat_with_setup
14942
+ flat_with_setup: wire.flat_with_setup,
14943
+ self_relayed: wire.self_relayed ?? void 0
14891
14944
  };
14892
14945
  }
14893
14946
  return { router: "layerzero", native_fee_sats: wire.native_fee_sats };
@@ -15375,11 +15428,18 @@ function satsToLightningOptions(options, sourceName) {
15375
15428
  extraFees: options.extraFees
15376
15429
  };
15377
15430
  if (kind === "invoice") {
15378
- if (options.sourceAmount != null) {
15431
+ if (options.sourceAmount != null && options.targetAmount != null) {
15379
15432
  throw new Error(
15380
- "sourceAmount cannot be combined with a BOLT11 invoice destination (the invoice fixes the payout)"
15433
+ "Provide at most one of sourceAmount (fixed lock) or targetAmount with a BOLT11 invoice destination"
15381
15434
  );
15382
15435
  }
15436
+ if (options.sourceAmount != null) {
15437
+ return {
15438
+ lightningInvoice: destination,
15439
+ sourceAmountSats: Number(options.sourceAmount),
15440
+ ...common
15441
+ };
15442
+ }
15383
15443
  return {
15384
15444
  lightningInvoice: destination,
15385
15445
  ...options.targetAmount != null ? { targetAmountSats: Number(options.targetAmount) } : {},
@@ -15438,8 +15498,11 @@ var ClientBuilder = class {
15438
15498
  return this;
15439
15499
  }
15440
15500
  /**
15441
- * Sets a default referral code for every `createSwap` / `getQuote`
15442
- * call. Per-call `referralCode` always wins.
15501
+ * Sets a default referral code for every quote (`getQuote`,
15502
+ * `composeQuote`, `getLightningSendQuote`) and every create
15503
+ * (`createSwap` and the direct `create*Swap` methods), so quote and
15504
+ * create are priced with the same fees. Per-call `referralCode` always
15505
+ * wins.
15443
15506
  * @returns The builder instance for chaining.
15444
15507
  */
15445
15508
  withReferralCode(referralCode) {
@@ -15450,7 +15513,8 @@ var ClientBuilder = class {
15450
15513
  * @deprecated Use {@link withReferralCode}. Kept as a backwards-compat
15451
15514
  * alias for SDK consumers that haven't migrated from the old
15452
15515
  * `X-Org-Code` model — both sides flow through the same per-call
15453
- * `referral_code` plumbing now.
15516
+ * `referral_code` plumbing now, so the default applies to every quote
15517
+ * and create exactly like {@link withReferralCode}.
15454
15518
  */
15455
15519
  withOrgCode(orgCode) {
15456
15520
  return this.withReferralCode(orgCode);
@@ -15676,6 +15740,7 @@ var ClientBuilder = class {
15676
15740
  }
15677
15741
  };
15678
15742
  var AA_CHAIN_ID = 42161;
15743
+ var gaslessFundingInFlight = /* @__PURE__ */ new Set();
15679
15744
  var Client = class _Client {
15680
15745
  #apiClient;
15681
15746
  #config;
@@ -16265,6 +16330,10 @@ var Client = class _Client {
16265
16330
  * which takes pre-fetched primitives as a dependency object.
16266
16331
  */
16267
16332
  async composeQuote(params) {
16333
+ params = {
16334
+ ...params,
16335
+ referralCode: params.referralCode ?? this.#config.referralCode
16336
+ };
16268
16337
  const referralFee = params.referralCode != null || params.extraFees != null ? this.#composeStatic(
16269
16338
  `referral-fee|${params.referralCode ?? ""}|${params.extraFees ?? ""}`,
16270
16339
  () => this.getReferralFee({
@@ -16615,6 +16684,15 @@ var Client = class _Client {
16615
16684
  if (!data) {
16616
16685
  throw new Error("No swap data returned");
16617
16686
  }
16687
+ const comparableId = (value) => {
16688
+ const uuid = value.match(
16689
+ /^(?:([0-9a-f]{32})|([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})|\{([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\}|urn:uuid:([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}))$/i
16690
+ );
16691
+ return uuid ? uuid.slice(1).find((part) => part !== void 0).replace(/-/g, "").toLowerCase() : value;
16692
+ };
16693
+ if (comparableId(data.id) !== comparableId(id)) {
16694
+ throw new Error(`Requested swap ${id}, but server returned ${data.id}`);
16695
+ }
16618
16696
  if (options?.updateStorage && this.#swapStorage) {
16619
16697
  const stored = await this.#swapStorage.get(id);
16620
16698
  const changed = stored ? swapTermsChange(stored, data) : void 0;
@@ -17107,7 +17185,10 @@ var Client = class _Client {
17107
17185
  amount: { kind: "exact_in", value: String(swap.evm_expected_sats) },
17108
17186
  sender: swap.evm_coordinator_address,
17109
17187
  slippage_bps: slippageBps,
17110
- bridge_recipient: bridgeRecipientParam
17188
+ bridge_recipient: bridgeRecipientParam,
17189
+ // Names the swap so the server can deliver its bridged payout
17190
+ // itself instead of charging Circle's forwarding fee.
17191
+ swap_id: swap.id
17111
17192
  }
17112
17193
  });
17113
17194
  if (fundResp.error || !fundResp.data) {
@@ -17372,12 +17453,7 @@ var Client = class _Client {
17372
17453
  };
17373
17454
  }
17374
17455
  if (vtxoStatus === "spent") {
17375
- const continued = await this.continueArkadeClaimSwap(id);
17376
- if (continued.success) return continued;
17377
- return {
17378
- success: false,
17379
- message: "All VTXOs have already been spent."
17380
- };
17456
+ return this.#continueArkadeClaim(claimParams, options);
17381
17457
  }
17382
17458
  if (vtxoStatus === "spendable") {
17383
17459
  return this.#claimArkadeOffchain(claimParams, options);
@@ -17608,13 +17684,16 @@ var Client = class _Client {
17608
17684
  message: `Expected an Arkade-destination swap, got ${swap.direction}.`
17609
17685
  };
17610
17686
  }
17611
- const claimParams = this.#extractArkadeClaimParams(id, storedSwap);
17687
+ return this.#continueArkadeClaim(
17688
+ this.#extractArkadeClaimParams(id, storedSwap)
17689
+ );
17690
+ }
17691
+ async #continueArkadeClaim(claimParams, options) {
17612
17692
  try {
17613
17693
  const result = await continueArkadeClaim({
17614
17694
  ...claimParams,
17615
- destinationAddress: "",
17616
- // not needed for continue
17617
- arkadeServerUrl: this.#config.arkadeServerUrl,
17695
+ destinationAddress: options?.destinationAddress,
17696
+ arkadeServerUrl: options?.arkadeServerUrl ?? this.#config.arkadeServerUrl,
17618
17697
  logger: this.#config.logger,
17619
17698
  logLevel: this.#config.logLevel
17620
17699
  });
@@ -19846,6 +19925,7 @@ network='${network}'`
19846
19925
  baseUrl: this.#config.baseUrl,
19847
19926
  deriveSwapParams: () => this.deriveSwapParams(),
19848
19927
  evmAddress: this.getEvmAddress(),
19928
+ referralCode: this.#config.referralCode,
19849
19929
  logger: this.#config.logger,
19850
19930
  logLevel: this.#config.logLevel,
19851
19931
  skipKeyIndices: async (n) => {
@@ -19888,6 +19968,7 @@ network='${network}'`
19888
19968
  bridgeRecipient: bridge?.recipient,
19889
19969
  bridgeRecipientWallet: bridge?.recipientWallet,
19890
19970
  evmFundTxid: existing?.evmFundTxid,
19971
+ evmFundingUserOpHash: existing?.evmFundingUserOpHash,
19891
19972
  // Fixed at creation and never taken from a server answer: recovery
19892
19973
  // rebuilding the swap keeps it, and a fresh device has none.
19893
19974
  lightningPaymentHash: commitments?.lightningPaymentHash ?? existing?.lightningPaymentHash,
@@ -20733,6 +20814,7 @@ network='${network}'`
20733
20814
  * nonce: params.nonce,
20734
20815
  * deadline: params.deadline,
20735
20816
  * signature,
20817
+ * depositorCode: (await publicClient.getCode({ address: userWalletAddress })) ?? "0x",
20736
20818
  * },
20737
20819
  * );
20738
20820
  * ```
@@ -20835,6 +20917,7 @@ network='${network}'`
20835
20917
  * const signer: EvmSigner = {
20836
20918
  * address: walletClient.account.address,
20837
20919
  * chainId: walletClient.chain.id,
20920
+ * getCode: async (address) => (await publicClient.getCode({ address })) ?? "0x",
20838
20921
  * signTypedData: (td) => walletClient.signTypedData({ ...td, account: walletClient.account }),
20839
20922
  * sendTransaction: (tx) => walletClient.sendTransaction({ to: tx.to, data: tx.data, value: tx.value, type: tx.type, chain, gas: tx.gas }),
20840
20923
  * waitForReceipt: (hash) => publicClient.waitForReceipt({ hash }),
@@ -21003,6 +21086,13 @@ network='${network}'`
21003
21086
  });
21004
21087
  }
21005
21088
  const signature = await signer.signTypedData(freshFunding.typedData);
21089
+ let depositorCode;
21090
+ if (/^0x[0-9a-fA-F]{128}0[01]$/.test(signature) && signer.getCode) {
21091
+ try {
21092
+ depositorCode = await signer.getCode(signer.address);
21093
+ } catch {
21094
+ }
21095
+ }
21006
21096
  const encoded = encodeExecuteAndCreateWithPermit2(
21007
21097
  freshFunding.coordinatorAddress,
21008
21098
  {
@@ -21016,7 +21106,8 @@ network='${network}'`
21016
21106
  sourceAmount: freshFunding.sourceAmount,
21017
21107
  nonce: freshFunding.nonce,
21018
21108
  deadline: freshFunding.deadline,
21019
- signature
21109
+ signature,
21110
+ depositorCode
21020
21111
  }
21021
21112
  );
21022
21113
  await simulateTransaction(signer, encoded, "Funding transaction");
@@ -21025,14 +21116,21 @@ network='${network}'`
21025
21116
  data: encoded.data,
21026
21117
  gas: await gasLimitFor(signer, encoded, PERMIT2_FUND_GAS)
21027
21118
  });
21028
- const mined = await this.#awaitFunding(swapId, signer, txHash, encoded, {
21029
- htlcAddress: freshFunding.htlcAddress,
21030
- preimageHash: freshFunding.preimageHash,
21031
- claimAddress: freshFunding.claimAddress,
21032
- coordinatorAddress: freshFunding.coordinatorAddress,
21033
- lockSender: freshFunding.lockSender,
21034
- token: freshFunding.lockTokenAddress
21035
- });
21119
+ const mined = await this.#awaitFunding(
21120
+ swapId,
21121
+ signer,
21122
+ txHash,
21123
+ encoded,
21124
+ {
21125
+ htlcAddress: freshFunding.htlcAddress,
21126
+ preimageHash: freshFunding.preimageHash,
21127
+ claimAddress: freshFunding.claimAddress,
21128
+ coordinatorAddress: freshFunding.coordinatorAddress,
21129
+ lockSender: freshFunding.lockSender,
21130
+ token: freshFunding.lockTokenAddress
21131
+ },
21132
+ { forgetFailed: true }
21133
+ );
21036
21134
  return { txHash: mined };
21037
21135
  }
21038
21136
  /**
@@ -21108,7 +21206,7 @@ network='${network}'`
21108
21206
  }),
21109
21207
  amount
21110
21208
  );
21111
- const { cctpFundSwapFromSolana } = await import("./fundSwap-IUPFISXM-6IBPJ5O7.js");
21209
+ const { cctpFundSwapFromSolana } = await import("./fundSwap-UBCHMUP4-WBLYE6MC.js");
21112
21210
  const { aa } = this.cctpInbound;
21113
21211
  const cctp = await cctpFundSwapFromSolana(
21114
21212
  { apiClient: this.#apiClient, aa },
@@ -21840,22 +21938,77 @@ network='${network}'`
21840
21938
  })).data ?? "0x";
21841
21939
  }
21842
21940
  /**
21843
- * Fund an EVM-sourced swap via the gasless relay.
21941
+ * How {@link fundSwapGasless} funds a gasless swap locking on `chainId`,
21942
+ * decided before the user is shown a deposit address:
21844
21943
  *
21845
- * Signs the Permit2 authorization and (optionally) an EIP-2612 permit
21846
- * off-chain, then POSTs them to the server which submits the on-chain
21847
- * transactions on behalf of the user. No wallet or ETH required.
21944
+ * - `sponsored` on Arbitrum, where the paymaster runs: this SDK submits
21945
+ * `approve(Permit2)` + `executeAndCreateWithPermit2` itself as one
21946
+ * paymaster-sponsored UserOp from the depositor's Kernel account. No
21947
+ * server relay, no ETH on the deposit account.
21948
+ * - `relay` on every other chain, which has no sponsorship policy: the
21949
+ * server's legacy relay submits the funding from the signed permits.
21950
+ *
21951
+ * Throws when the sponsored path applies but this client was built
21952
+ * without AA config and a paymaster policy. Explicit self-paid testing
21953
+ * returns `self-paid` and requires native ETH on the account,
21954
+ * so callers can refuse to request a deposit that
21955
+ * could not be moved afterwards.
21956
+ */
21957
+ gaslessFundingPlan(chainId) {
21958
+ if (chainId !== AA_CHAIN_ID) return { mode: "relay" };
21959
+ if (!this.#config.aa) {
21960
+ throw new Error(
21961
+ `Gasless funding on chain ${chainId} is submitted by this SDK as a sponsored UserOp and requires AA config. Call \`.withAa({ bundlerUrl, paymasterPolicyId })\` on the ClientBuilder before \`.build()\`.`
21962
+ );
21963
+ }
21964
+ if (!this.#config.aa.paymasterPolicyId?.trim()) {
21965
+ if (this.#config.aa.allowSelfPaidFunding) return { mode: "self-paid" };
21966
+ throw new Error(
21967
+ "Sponsored funding requires a paymasterPolicyId. Self-paid local tests must explicitly set allowSelfPaidFunding and prefund the account with ETH."
21968
+ );
21969
+ }
21970
+ return { mode: "sponsored" };
21971
+ }
21972
+ /**
21973
+ * Fund an EVM-sourced gasless swap. No wallet or ETH is required by
21974
+ * default; explicit self-paid testing requires native ETH.
21975
+ * {@link gaslessFundingPlan} decides the path from the swap's chain:
21976
+ *
21977
+ * On Arbitrum the SDK funds the swap itself: it submits
21978
+ * `approve(Permit2)` (only when the allowance needs it, with a zero-reset
21979
+ * for USDT-style tokens — no EIP-2612 support needed) +
21980
+ * `executeAndCreateWithPermit2` as one paymaster-sponsored UserOp from
21981
+ * the depositor's own Kernel account (EIP-7702), the same mechanism the
21982
+ * CCTP-inbound settlement and refund continuations use. A sponsorship or
21983
+ * configuration failure surfaces as an error — there is no fallback to
21984
+ * the server relay.
21985
+ *
21986
+ * On other chains it signs the Permit2 authorization and (optionally) an
21987
+ * EIP-2612 permit off-chain, then POSTs them to the server's legacy
21988
+ * relay, which submits the on-chain transactions on behalf of the user.
21848
21989
  *
21849
21990
  * @param swapId - The UUID of the swap (must have been created with gasless=true)
21850
- * @returns The relay transaction hash
21991
+ * @returns The funding transaction hash
21851
21992
  *
21852
21993
  * @example
21853
21994
  * ```ts
21854
21995
  * const result = await client.fundSwapGasless(swap.response.id);
21855
- * console.log("Funded via relay:", result.txHash);
21996
+ * console.log("Funded:", result.txHash);
21856
21997
  * ```
21857
21998
  */
21858
21999
  async fundSwapGasless(swapId, options) {
22000
+ const lock = `${this.#config.baseUrl}:${swapId.toLowerCase()}`;
22001
+ if (gaslessFundingInFlight.has(lock)) {
22002
+ throw new Error(`Funding already in progress for swap ${swapId}`);
22003
+ }
22004
+ gaslessFundingInFlight.add(lock);
22005
+ try {
22006
+ return await this.#fundSwapGaslessOnce(swapId, options);
22007
+ } finally {
22008
+ gaslessFundingInFlight.delete(lock);
22009
+ }
22010
+ }
22011
+ async #fundSwapGaslessOnce(swapId, options) {
21859
22012
  const storedSwap = await this.getStoredSwap(swapId);
21860
22013
  if (!storedSwap) {
21861
22014
  throw new Error(
@@ -21869,6 +22022,9 @@ network='${network}'`
21869
22022
  );
21870
22023
  }
21871
22024
  const chainId = swap.evm_chain_id;
22025
+ if (this.gaslessFundingPlan(chainId).mode !== "relay") {
22026
+ return this.#fundSwapGaslessSponsored(swapId, storedSwap, swap, options);
22027
+ }
21872
22028
  const baseUrl = this.#config.baseUrl.replace(/\/$/, "");
21873
22029
  const url = `${baseUrl}/swap/${swapId}/swap-and-lock-calldata-permit2`;
21874
22030
  const resp = await fetch(url, {
@@ -21997,6 +22153,154 @@ network='${network}'`
21997
22153
  });
21998
22154
  return { txHash: result.tx_hash };
21999
22155
  }
22156
+ /**
22157
+ * The sponsored arm of {@link fundSwapGasless}: the deposit sits on the
22158
+ * depositor's own address, so funding is exactly a refund continuation's
22159
+ * balance UserOp — `approve(Permit2)` (as the allowance requires) +
22160
+ * `executeAndCreateWithPermit2`, sponsored by the paymaster, from the
22161
+ * Kernel account the depositor key owns under EIP-7702. The batch is
22162
+ * checked against the swap's recorded terms and hash lock before anything
22163
+ * is signed, and capped at the swap's recorded input.
22164
+ */
22165
+ async #fundSwapGaslessSponsored(swapId, stored, swap, options) {
22166
+ if (!this.#swapStorage)
22167
+ throw new Error("Sponsored funding requires swap storage");
22168
+ if (stored.evmFundingUserOpHash) {
22169
+ const key2 = this.#gaslessDepositorKey(swapId, stored, swap);
22170
+ const { client } = await this.cctpInbound.createSmartAccountClient({
22171
+ signer: keyToKernelOwnerSigner(
22172
+ hexToBytes(key2.replace(/^0x/, "")),
22173
+ AA_CHAIN_ID
22174
+ )
22175
+ });
22176
+ const receipt = await client.getUserOperationReceipt({
22177
+ hash: stored.evmFundingUserOpHash
22178
+ }).catch(() => null);
22179
+ if (!receipt) {
22180
+ throw new Error(
22181
+ `Funding outcome unknown for ${stored.evmFundingUserOpHash}; retry later to check it. No new funding was submitted.`
22182
+ );
22183
+ }
22184
+ if (!receipt.success) {
22185
+ await this.#setFundingUserOp(swapId, void 0);
22186
+ throw new Error(
22187
+ "Previous funding operation reverted; retry funding again."
22188
+ );
22189
+ }
22190
+ const txHash2 = receipt.receipt.transactionHash;
22191
+ await this.#recordEvmFunding(swapId, { txid: txHash2 });
22192
+ await this.#hintEvmFunding(swapId, txHash2);
22193
+ return { txHash: txHash2 };
22194
+ }
22195
+ const expected = {
22196
+ ...this.#fundingExpectation(swapId, stored),
22197
+ pins: options?.funding
22198
+ };
22199
+ if (expected.terms.chainId !== AA_CHAIN_ID) {
22200
+ throw new Error(
22201
+ `Swap ${swapId} locks on chain ${expected.terms.chainId}, not the sponsored chain ${AA_CHAIN_ID}; refusing to fund it there`
22202
+ );
22203
+ }
22204
+ if (stored.evmFundTxid) {
22205
+ const { createPublicClient: createPublicClient2, http: http2 } = await import("./_esm-4ZKYBBIE-FLHB4OLO.js");
22206
+ const { arbitrum: arbitrum2 } = await import("./chains-D6LHJZMI-QZJMCUG3.js");
22207
+ const rpc = createPublicClient2({
22208
+ chain: arbitrum2,
22209
+ transport: http2(this.#config.aa?.rpcUrl ?? this.#config.aa?.bundlerUrl)
22210
+ });
22211
+ const receipt = await rpc.getTransactionReceipt({
22212
+ hash: stored.evmFundTxid
22213
+ }).catch(() => null);
22214
+ if (!receipt) {
22215
+ throw new Error(
22216
+ `Funding transaction ${stored.evmFundTxid} is pending or its outcome is unknown; no new funding was submitted.`
22217
+ );
22218
+ }
22219
+ if (receipt.status === "reverted") {
22220
+ await this.#forgetEvmFunding(swapId, stored.evmFundTxid);
22221
+ } else if (receipt.status === "success" && receipt.logs !== void 0) {
22222
+ const sender = (expected.terms.htlcVersion ?? 0) >= 7 ? deriveEvmAddress(this.#gaslessDepositorKey(swapId, stored, swap)) : expected.terms.coordinator;
22223
+ const locks = findSwapCreated(receipt.logs, {
22224
+ htlcAddress: expected.terms.htlcAddress,
22225
+ hashLock: expected.hashLock,
22226
+ claimAddress: expected.terms.claimAddress,
22227
+ senders: [sender],
22228
+ token: expected.terms.lockToken
22229
+ });
22230
+ if (locks.length > 0) {
22231
+ await this.#hintEvmFunding(swapId, receipt.transactionHash);
22232
+ return { txHash: receipt.transactionHash };
22233
+ }
22234
+ if (provesNoLockUnder(receipt, expected.hashLock)) {
22235
+ await this.#forgetEvmFunding(swapId, stored.evmFundTxid);
22236
+ } else {
22237
+ throw new Error(
22238
+ "Recorded funding has an unexpected lock; refusing to fund again."
22239
+ );
22240
+ }
22241
+ } else {
22242
+ throw new Error(
22243
+ "Cannot verify recorded funding; no new funding was submitted."
22244
+ );
22245
+ }
22246
+ }
22247
+ const key = this.#gaslessDepositorKey(swapId, stored, swap);
22248
+ const owner = keyToKernelOwnerSigner(
22249
+ hexToBytes(key.replace(/^0x/, "")),
22250
+ AA_CHAIN_ID
22251
+ );
22252
+ const submitted = await this.cctpInbound.submitBalanceUserOp({
22253
+ swapId,
22254
+ onSigned: (hash) => this.#setFundingUserOp(swapId, hash),
22255
+ expected,
22256
+ signer: owner,
22257
+ // The deposit the user was asked for; calldata demanding more must
22258
+ // fail rather than draw on unrelated balance in the account.
22259
+ expectedMaxSourceAmount: BigInt(expected.terms.sourceAmount)
22260
+ });
22261
+ const txHash = submitted.transactionHash;
22262
+ if (!txHash) {
22263
+ throw new Error(
22264
+ `Sponsored funding UserOp ${submitted.userOpHash} for swap ${swapId} returned no transaction hash`
22265
+ );
22266
+ }
22267
+ await this.#recordEvmFunding(swapId, {
22268
+ txid: txHash,
22269
+ coordinatorAddress: expected.terms.coordinator
22270
+ });
22271
+ await this.#hintEvmFunding(swapId, txHash);
22272
+ return { txHash };
22273
+ }
22274
+ async #setFundingUserOp(swapId, hash) {
22275
+ const current = await this.#swapStorage?.get(swapId);
22276
+ if (!current || !this.#swapStorage)
22277
+ throw new Error("Cannot persist funding operation");
22278
+ await this.#swapStorage.store({
22279
+ ...current,
22280
+ evmFundingUserOpHash: hash,
22281
+ updatedAt: Date.now()
22282
+ });
22283
+ }
22284
+ /**
22285
+ * The SDK-controlled key whose address the swap's deposit was sent to:
22286
+ * the wallet-level key for current gasless swaps, the per-swap key for
22287
+ * legacy ones. The sponsored funding runs from that address's own Kernel
22288
+ * account, so a depositor this SDK does not control cannot be funded
22289
+ * here.
22290
+ */
22291
+ #gaslessDepositorKey(swapId, stored, swap) {
22292
+ const depositor = swap.client_evm_address?.toLowerCase();
22293
+ const sharedKey = this.#getEvmSigningKey();
22294
+ if (!depositor || depositor === deriveEvmAddress(sharedKey).toLowerCase()) {
22295
+ return sharedKey;
22296
+ }
22297
+ if (depositor === deriveEvmAddress(stored.secretKey).toLowerCase()) {
22298
+ return stored.secretKey;
22299
+ }
22300
+ throw new Error(
22301
+ `Cannot fund swap ${swapId} sponsored: its depositor ${depositor} is not an SDK-controlled account. Fund it from that wallet with fundSwap.`
22302
+ );
22303
+ }
22000
22304
  /**
22001
22305
  * Get the ephemeral depositor key for a gasless swap funded swap.
22002
22306
  *
@@ -22025,7 +22329,19 @@ network='${network}'`
22025
22329
  `Swap ${swapId} not found in local storage. Cannot recover without the secret key.`
22026
22330
  );
22027
22331
  }
22028
- const evmKey = this.#getEvmSigningKey();
22332
+ const response = storedSwap.response;
22333
+ const depositor = response.client_evm_address?.toLowerCase();
22334
+ const sharedKey = this.#getEvmSigningKey();
22335
+ const sharedAddress = deriveEvmAddress(sharedKey).toLowerCase();
22336
+ const swapAddress = deriveEvmAddress(storedSwap.secretKey).toLowerCase();
22337
+ let evmKey = sharedKey;
22338
+ if (depositor === swapAddress) {
22339
+ evmKey = storedSwap.secretKey;
22340
+ } else if (depositor && depositor !== sharedAddress && response.gasless) {
22341
+ throw new Error(
22342
+ `Cannot export a deposit key for swap ${swapId}: depositor ${response.client_evm_address} is not an SDK-controlled account. Use the depositor wallet.`
22343
+ );
22344
+ }
22029
22345
  const privateKey = evmKey.startsWith("0x") ? evmKey : `0x${evmKey}`;
22030
22346
  const address2 = deriveEvmAddress(evmKey);
22031
22347
  return { privateKey, address: address2 };
@@ -22035,8 +22351,8 @@ network='${network}'`
22035
22351
  * deterministic EVM signing key for this wallet without requiring a
22036
22352
  * specific swap to be stored locally.
22037
22353
  *
22038
- * Same key, same address as {@link getSwapDepositorKey} (both derive
22039
- * from `m/44'/60'/0'/0/0`). Intended for standalone recovery tools
22354
+ * This returns only the shared `m/44'/60'/0'/0/0` account, not a
22355
+ * per-swap deposit key. Intended for legacy standalone recovery tools
22040
22356
  * where the user supplies the burn details manually and a per-swap
22041
22357
  * record may no longer exist (e.g. fresh device, cleared site data).
22042
22358
  */
@@ -22141,7 +22457,7 @@ network='${network}'`
22141
22457
  );
22142
22458
  }
22143
22459
  const tokenAddress = swap.source_token.token_id;
22144
- const { encodeBalanceOfCall: encodeBalanceOfCall2, encodeTransferCall, decodeUint256: decodeUint2562 } = await import("./wallet-THELKUYT-TOHSMRGU.js");
22460
+ const { encodeBalanceOfCall: encodeBalanceOfCall2, encodeTransferCall, decodeUint256: decodeUint2562 } = await import("./wallet-33OJRHX5-PR4S3NI3.js");
22145
22461
  const balanceCall = encodeBalanceOfCall2(
22146
22462
  tokenAddress,
22147
22463
  depositorSigner.address
@@ -22689,4 +23005,4 @@ export {
22689
23005
  @scure/bip39/index.js:
22690
23006
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
22691
23007
  */
22692
- //# sourceMappingURL=chunk-S4T4GK5G.js.map
23008
+ //# sourceMappingURL=chunk-WQMAL2VD.js.map