@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,16 +39,13 @@
39
39
 
40
40
 
41
41
 
42
- var _chunk7GOXIT24cjs = require('./chunk-7GOXIT24.cjs');
42
+ var _chunkJZTF4JNHcjs = require('./chunk-JZTF4JNH.cjs');
43
43
 
44
44
 
45
45
 
46
46
  var _chunkK6TGBXTTcjs = require('./chunk-K6TGBXTT.cjs');
47
47
 
48
48
 
49
- var _chunkEWN43VZBcjs = require('./chunk-EWN43VZB.cjs');
50
-
51
-
52
49
 
53
50
 
54
51
 
@@ -83,7 +80,7 @@ var _chunkTKFOVRJRcjs = require('./chunk-TKFOVRJR.cjs');
83
80
 
84
81
 
85
82
 
86
- var _chunkMYOGO44Lcjs = require('./chunk-MYOGO44L.cjs');
83
+ var _chunkTNZW35XAcjs = require('./chunk-TNZW35XA.cjs');
87
84
 
88
85
 
89
86
 
@@ -118,16 +115,14 @@ var _chunkMYOGO44Lcjs = require('./chunk-MYOGO44L.cjs');
118
115
 
119
116
 
120
117
 
121
- var _chunkOJNQCRHUcjs = require('./chunk-OJNQCRHU.cjs');
118
+ var _chunkQ4TOBBANcjs = require('./chunk-Q4TOBBAN.cjs');
122
119
 
123
120
 
124
- var _chunkBUOHHQORcjs = require('./chunk-BUOHHQOR.cjs');
125
121
 
126
122
 
127
123
 
128
124
 
129
125
 
130
- var _chunk4FGIWZAVcjs = require('./chunk-4FGIWZAV.cjs');
131
126
 
132
127
 
133
128
 
@@ -145,29 +140,34 @@ var _chunk4FGIWZAVcjs = require('./chunk-4FGIWZAV.cjs');
145
140
 
146
141
 
147
142
 
143
+ var _chunkBEW62OUTcjs = require('./chunk-BEW62OUT.cjs');
148
144
 
149
145
 
146
+ var _chunkBUOHHQORcjs = require('./chunk-BUOHHQOR.cjs');
150
147
 
151
148
 
152
149
 
153
150
 
154
151
 
155
- var _chunkBEW62OUTcjs = require('./chunk-BEW62OUT.cjs');
156
152
 
153
+ var _chunk5JR6AJ3Ycjs = require('./chunk-5JR6AJ3Y.cjs');
157
154
 
158
155
 
159
156
 
160
157
 
161
158
 
162
- var _chunk5JR6AJ3Ycjs = require('./chunk-5JR6AJ3Y.cjs');
163
159
 
164
160
 
161
+ var _chunkRYZSWESUcjs = require('./chunk-RYZSWESU.cjs');
165
162
 
166
163
 
164
+ var _chunkEWN43VZBcjs = require('./chunk-EWN43VZB.cjs');
167
165
 
168
166
 
169
167
 
170
- var _chunkRYZSWESUcjs = require('./chunk-RYZSWESU.cjs');
168
+
169
+
170
+ var _chunk4FGIWZAVcjs = require('./chunk-4FGIWZAV.cjs');
171
171
 
172
172
 
173
173
 
@@ -6848,8 +6848,8 @@ function removeTrailingSlash(url) {
6848
6848
  }
6849
6849
  function createApiClient(options) {
6850
6850
  const headers = {
6851
- "X-Lendaswap-Client": _chunkOJNQCRHUcjs.CLIENT_AGENT,
6852
- ..._chunkOJNQCRHUcjs.PROTOCOL_HEADERS,
6851
+ "X-Lendaswap-Client": _chunkQ4TOBBANcjs.CLIENT_AGENT,
6852
+ ..._chunkQ4TOBBANcjs.PROTOCOL_HEADERS,
6853
6853
  ..._nullishCoalesce(options.defaultHeaders, () => ( {}))
6854
6854
  };
6855
6855
  return createClient({
@@ -6862,7 +6862,7 @@ async function getVhtlcAmounts(params) {
6862
6862
  const { vhtlcAddress, network, arkadeServerUrl } = params;
6863
6863
  const decoded = _chunkBEW62OUTcjs.ArkAddress.decode(vhtlcAddress);
6864
6864
  const pkScript = _chunkRYZSWESUcjs.hex.encode(decoded.pkScript);
6865
- const serverUrl = _chunkOJNQCRHUcjs.resolveArkadeServerUrl.call(void 0, network, arkadeServerUrl);
6865
+ const serverUrl = _chunkQ4TOBBANcjs.resolveArkadeServerUrl.call(void 0, network, arkadeServerUrl);
6866
6866
  const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
6867
6867
  const [spendableResult, spentResult, recoverableResult] = await Promise.all([
6868
6868
  indexerProvider.getVtxos({ scripts: [pkScript], spendableOnly: true }),
@@ -6897,7 +6897,7 @@ function parseArkadeAddress(address2, network) {
6897
6897
  throw new Error(`Invalid Arkade address: ${reason}`);
6898
6898
  }
6899
6899
  if (network !== void 0) {
6900
- const expectedHrp = _chunkOJNQCRHUcjs.getNetworkHrp.call(void 0, _chunkOJNQCRHUcjs.getNetworkName.call(void 0, network));
6900
+ const expectedHrp = _chunkQ4TOBBANcjs.getNetworkHrp.call(void 0, _chunkQ4TOBBANcjs.getNetworkName.call(void 0, network));
6901
6901
  if (decoded.hrp !== expectedHrp) {
6902
6902
  throw new Error(
6903
6903
  `Arkade address has wrong network: expected "${expectedHrp}1..." prefix, got "${decoded.hrp}1..."`
@@ -7193,7 +7193,7 @@ function ensureBytes32(value) {
7193
7193
  );
7194
7194
  }
7195
7195
  function keccak256Hex(input) {
7196
- return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunk7GOXIT24cjs.keccak_256.call(void 0, new TextEncoder().encode(input)))}`;
7196
+ return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkJZTF4JNHcjs.keccak_256.call(void 0, new TextEncoder().encode(input)))}`;
7197
7197
  }
7198
7198
  function encodeUint256(value) {
7199
7199
  if (value < 0n) throw new Error("uint256 cannot be negative");
@@ -7323,7 +7323,7 @@ async function cctpFundSwap(context, params) {
7323
7323
  const source = cctpMetaForChainId(signer.chainId);
7324
7324
  const destination = cctpMetaForChainId(settlementChain.id);
7325
7325
  const minFinalityThreshold = finalityForChainId(signer.chainId);
7326
- const { accountAddress: smartAccountAddress } = await _chunk7GOXIT24cjs.createSwapSmartAccountClient.call(void 0, {
7326
+ const { accountAddress: smartAccountAddress } = await _chunkJZTF4JNHcjs.createSwapSmartAccountClient.call(void 0, {
7327
7327
  signer: ownerSigner,
7328
7328
  aa: context.aa,
7329
7329
  chain: settlementChain
@@ -7350,14 +7350,14 @@ async function cctpFundSwap(context, params) {
7350
7350
  _optionalChain([onProgress, 'optionalCall', _29 => _29({ phase: "burning", burnTxHash })]);
7351
7351
  burnTxHash = await confirmBurn(signer, burnTxHash, onBurn);
7352
7352
  _optionalChain([onProgress, 'optionalCall', _30 => _30({ phase: "attestation" })]);
7353
- const { message, attestation } = await _chunk7GOXIT24cjs.fetchAttestation.call(void 0, {
7353
+ const { message, attestation } = await _chunkJZTF4JNHcjs.fetchAttestation.call(void 0, {
7354
7354
  sourceChain: source.name,
7355
7355
  txHash: burnTxHash,
7356
7356
  irisApiUrl,
7357
7357
  signal
7358
7358
  });
7359
7359
  _optionalChain([onProgress, 'optionalCall', _31 => _31({ phase: "submitting" })]);
7360
- const submit = await _chunk7GOXIT24cjs.submitCctpInboundUserOp.call(void 0, context, {
7360
+ const submit = await _chunkJZTF4JNHcjs.submitCctpInboundUserOp.call(void 0, context, {
7361
7361
  swapId,
7362
7362
  expected: params.expected,
7363
7363
  signer: ownerSigner,
@@ -7410,7 +7410,7 @@ var CctpInboundClient = class {
7410
7410
  aa: this.#aa,
7411
7411
  chain: args.chain
7412
7412
  };
7413
- return _chunk7GOXIT24cjs.createSwapSmartAccountClient.call(void 0, params);
7413
+ return _chunkJZTF4JNHcjs.createSwapSmartAccountClient.call(void 0, params);
7414
7414
  }
7415
7415
  /**
7416
7416
  * Compose the 3-call UserOp batch (receiveMessage + USDC.approve +
@@ -7422,7 +7422,7 @@ var CctpInboundClient = class {
7422
7422
  * which composes batch + send + wait-for-receipt.
7423
7423
  */
7424
7424
  buildUserOpBatch(params) {
7425
- return _chunk7GOXIT24cjs.buildCctpInboundBatch.call(void 0, params);
7425
+ return _chunkJZTF4JNHcjs.buildCctpInboundBatch.call(void 0, params);
7426
7426
  }
7427
7427
  /**
7428
7428
  * End-to-end settlement UserOp: fetch calldata, build Kernel client,
@@ -7435,7 +7435,7 @@ var CctpInboundClient = class {
7435
7435
  * caller's signer.
7436
7436
  */
7437
7437
  submitUserOp(params) {
7438
- return _chunk7GOXIT24cjs.submitCctpInboundUserOp.call(void 0,
7438
+ return _chunkJZTF4JNHcjs.submitCctpInboundUserOp.call(void 0,
7439
7439
  { apiClient: this.#apiClient, aa: this.#aa },
7440
7440
  {
7441
7441
  ...params,
@@ -7452,7 +7452,7 @@ var CctpInboundClient = class {
7452
7452
  * paymaster-sponsored UserOp.
7453
7453
  */
7454
7454
  submitBalanceUserOp(params) {
7455
- return _chunk7GOXIT24cjs.submitCctpInboundBalanceUserOp.call(void 0,
7455
+ return _chunkJZTF4JNHcjs.submitCctpInboundBalanceUserOp.call(void 0,
7456
7456
  { apiClient: this.#apiClient, aa: this.#aa },
7457
7457
  {
7458
7458
  ...params,
@@ -7484,7 +7484,7 @@ var CctpInboundClient = class {
7484
7484
  * `signal` (AbortSignal) to cancel early.
7485
7485
  */
7486
7486
  waitForAttestation(options) {
7487
- return _chunk7GOXIT24cjs.fetchAttestation.call(void 0, options);
7487
+ return _chunkJZTF4JNHcjs.fetchAttestation.call(void 0, options);
7488
7488
  }
7489
7489
  /**
7490
7490
  * One-shot CCTP-inbound swap: approve + burn on the source chain,
@@ -7506,7 +7506,7 @@ _chunk5JR6AJ3Ycjs.init_utils.call(void 0, );
7506
7506
  function deriveEvmAddress(secretKey) {
7507
7507
  const keyBytes = typeof secretKey === "string" ? _chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, secretKey.replace(/^0x/, "")) : secretKey;
7508
7508
  const uncompressedPubkey = _chunkBEW62OUTcjs.secp256k12.getPublicKey(keyBytes, false);
7509
- const hash = _chunk7GOXIT24cjs.keccak_256.call(void 0, uncompressedPubkey.slice(1));
7509
+ const hash = _chunkJZTF4JNHcjs.keccak_256.call(void 0, uncompressedPubkey.slice(1));
7510
7510
  const addressBytes = hash.slice(12);
7511
7511
  const addressHex2 = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, addressBytes);
7512
7512
  return toChecksumAddress(addressHex2);
@@ -7537,11 +7537,11 @@ ${body.length}`
7537
7537
  const whole = new Uint8Array(prefix.length + body.length);
7538
7538
  whole.set(prefix, 0);
7539
7539
  whole.set(body, prefix.length);
7540
- return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunk7GOXIT24cjs.keccak_256.call(void 0, whole))}`;
7540
+ return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkJZTF4JNHcjs.keccak_256.call(void 0, whole))}`;
7541
7541
  }
7542
7542
  function toChecksumAddress(address2) {
7543
7543
  const clean2 = address2.replace(/^0x/, "").toLowerCase();
7544
- const hash = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunk7GOXIT24cjs.keccak_256.call(void 0, new TextEncoder().encode(clean2)));
7544
+ const hash = _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkJZTF4JNHcjs.keccak_256.call(void 0, new TextEncoder().encode(clean2)));
7545
7545
  let checksummed = "0x";
7546
7546
  for (let i = 0; i < 40; i++) {
7547
7547
  checksummed += parseInt(hash[i], 16) >= 8 ? clean2[i].toUpperCase() : clean2[i];
@@ -7550,7 +7550,7 @@ function toChecksumAddress(address2) {
7550
7550
  }
7551
7551
  var MAX_UINT256 = (1n << 256n) - 1n;
7552
7552
  function signEip2612Permit(params) {
7553
- const spender = _nullishCoalesce(params.spender, () => ( _chunk7GOXIT24cjs.PERMIT2_ADDRESS));
7553
+ const spender = _nullishCoalesce(params.spender, () => ( _chunkJZTF4JNHcjs.PERMIT2_ADDRESS));
7554
7554
  const digestParams = {
7555
7555
  domainSeparator: params.domainSeparator,
7556
7556
  owner: params.owner,
@@ -7559,7 +7559,7 @@ function signEip2612Permit(params) {
7559
7559
  nonce: params.nonce,
7560
7560
  deadline: params.deadline
7561
7561
  };
7562
- const digest = _chunk7GOXIT24cjs.buildEip2612PermitDigest.call(void 0, digestParams);
7562
+ const digest = _chunkJZTF4JNHcjs.buildEip2612PermitDigest.call(void 0, digestParams);
7563
7563
  const sig = signEvmDigest(params.secretKey, digest);
7564
7564
  return {
7565
7565
  v: sig.v,
@@ -7584,14 +7584,14 @@ var USDC_DOMAIN_FIELDS = {
7584
7584
  }
7585
7585
  };
7586
7586
  function keccak256Hex2(input) {
7587
- return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunk7GOXIT24cjs.keccak_256.call(void 0, new TextEncoder().encode(input)))}`;
7587
+ return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkJZTF4JNHcjs.keccak_256.call(void 0, new TextEncoder().encode(input)))}`;
7588
7588
  }
7589
7589
  function keccak256HexBytes(hexInput) {
7590
7590
  const bytes = new Uint8Array(hexInput.length / 2);
7591
7591
  for (let i = 0; i < bytes.length; i++) {
7592
7592
  bytes[i] = parseInt(hexInput.slice(i * 2, i * 2 + 2), 16);
7593
7593
  }
7594
- return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunk7GOXIT24cjs.keccak_256.call(void 0, bytes))}`;
7594
+ return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunkJZTF4JNHcjs.keccak_256.call(void 0, bytes))}`;
7595
7595
  }
7596
7596
  function strip(hex2) {
7597
7597
  return hex2.replace(/^0x/, "").toLowerCase();
@@ -7603,7 +7603,7 @@ function addressHex(address2) {
7603
7603
  return address2.replace(/^0x/, "").toLowerCase().padStart(64, "0");
7604
7604
  }
7605
7605
  function signPermit2Witness(params) {
7606
- const digest = _chunk7GOXIT24cjs.buildPermit2FundingDigest.call(void 0, params.funding);
7606
+ const digest = _chunkJZTF4JNHcjs.buildPermit2FundingDigest.call(void 0, params.funding);
7607
7607
  const sig = signEvmDigest(params.secretKey, digest);
7608
7608
  const r = sig.r.replace(/^0x/, "");
7609
7609
  const s = sig.s.replace(/^0x/, "");
@@ -7655,7 +7655,7 @@ async function recoverCctpInbound(context, params) {
7655
7655
  onProgress,
7656
7656
  signal
7657
7657
  } = params;
7658
- const { client: aaClient, accountAddress } = await _chunk7GOXIT24cjs.createSwapSmartAccountClient.call(void 0, { signer, aa: context.aa, chain });
7658
+ const { client: aaClient, accountAddress } = await _chunkJZTF4JNHcjs.createSwapSmartAccountClient.call(void 0, { signer, aa: context.aa, chain });
7659
7659
  const publicClient = _chunkK6TGBXTTcjs.createPublicClient.call(void 0, {
7660
7660
  chain,
7661
7661
  transport: _chunkK6TGBXTTcjs.http.call(void 0, _nullishCoalesce(context.aa.rpcUrl, () => ( context.aa.bundlerUrl)))
@@ -7666,7 +7666,7 @@ async function recoverCctpInbound(context, params) {
7666
7666
  const usdcAddress = _chunkTKFOVRJRcjs.USDC_ADDRESSES.Arbitrum;
7667
7667
  if (!cctpMessage || !cctpAttestation) {
7668
7668
  _optionalChain([onProgress, 'optionalCall', _37 => _37({ phase: "attestation" })]);
7669
- const fetched = await _chunk7GOXIT24cjs.fetchAttestation.call(void 0, {
7669
+ const fetched = await _chunkJZTF4JNHcjs.fetchAttestation.call(void 0, {
7670
7670
  sourceChain,
7671
7671
  txHash: burnTxHash,
7672
7672
  irisApiUrl,
@@ -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 = (_nullishCoalesce(deps.referralBaseFeeRate, () => ( pair.fee_percentage))) + (_nullishCoalesce(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(_nullishCoalesce(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 _optionalChain([dexQuote, 'access', _57 => _57.bridge_rate, 'optionalAccess', _58 => _58.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 },
@@ -8466,7 +8484,7 @@ async function dexTargetPinned(evmSmallest, params, deps, btcPegged, pivotChainI
8466
8484
  };
8467
8485
  }
8468
8486
  function bridgeNativeFeeSats(dexQuote) {
8469
- return _optionalChain([dexQuote, 'access', _57 => _57.bridge_rate, 'optionalAccess', _58 => _58.router]) === "layerzero" ? Number(dexQuote.bridge_rate.native_fee_sats) : 0;
8487
+ return _optionalChain([dexQuote, 'access', _59 => _59.bridge_rate, 'optionalAccess', _60 => _60.router]) === "layerzero" ? Number(dexQuote.bridge_rate.native_fee_sats) : 0;
8470
8488
  }
8471
8489
  function lookupPair(swapPairs, source, target) {
8472
8490
  const pair = swapPairs.pairs.find(
@@ -8622,18 +8640,18 @@ _chunk5JR6AJ3Ycjs.init_sha2.call(void 0, );
8622
8640
  _chunk5JR6AJ3Ycjs.init_utils.call(void 0, );
8623
8641
  _chunkBEW62OUTcjs.init_bip32.call(void 0, );
8624
8642
  function pbkdf2Init(hash, _password, _salt, _opts) {
8625
- _chunkOJNQCRHUcjs.ahash.call(void 0, hash);
8626
- const opts = _chunkOJNQCRHUcjs.checkOpts.call(void 0, { dkLen: 32, asyncTick: 10 }, _opts);
8643
+ _chunkQ4TOBBANcjs.ahash.call(void 0, hash);
8644
+ const opts = _chunkQ4TOBBANcjs.checkOpts.call(void 0, { dkLen: 32, asyncTick: 10 }, _opts);
8627
8645
  const { c, dkLen, asyncTick } = opts;
8628
- _chunkOJNQCRHUcjs.anumber.call(void 0, c, "c");
8629
- _chunkOJNQCRHUcjs.anumber.call(void 0, dkLen, "dkLen");
8630
- _chunkOJNQCRHUcjs.anumber.call(void 0, asyncTick, "asyncTick");
8646
+ _chunkQ4TOBBANcjs.anumber.call(void 0, c, "c");
8647
+ _chunkQ4TOBBANcjs.anumber.call(void 0, dkLen, "dkLen");
8648
+ _chunkQ4TOBBANcjs.anumber.call(void 0, asyncTick, "asyncTick");
8631
8649
  if (c < 1)
8632
8650
  throw new Error("iterations (c) must be >= 1");
8633
- const password = _chunkOJNQCRHUcjs.kdfInputToBytes.call(void 0, _password, "password");
8634
- const salt = _chunkOJNQCRHUcjs.kdfInputToBytes.call(void 0, _salt, "salt");
8651
+ const password = _chunkQ4TOBBANcjs.kdfInputToBytes.call(void 0, _password, "password");
8652
+ const salt = _chunkQ4TOBBANcjs.kdfInputToBytes.call(void 0, _salt, "salt");
8635
8653
  const DK = new Uint8Array(dkLen);
8636
- const PRF = _chunkOJNQCRHUcjs.hmac.create(hash, password);
8654
+ const PRF = _chunkQ4TOBBANcjs.hmac.create(hash, password);
8637
8655
  const PRFSalt = PRF._cloneInto().update(salt);
8638
8656
  return { c, dkLen, asyncTick, DK, PRF, PRFSalt };
8639
8657
  }
@@ -8642,14 +8660,14 @@ function pbkdf2Output(PRF, PRFSalt, DK, prfW, u) {
8642
8660
  PRFSalt.destroy();
8643
8661
  if (prfW)
8644
8662
  prfW.destroy();
8645
- _chunkOJNQCRHUcjs.clean.call(void 0, u);
8663
+ _chunkQ4TOBBANcjs.clean.call(void 0, u);
8646
8664
  return DK;
8647
8665
  }
8648
8666
  function pbkdf2(hash, password, salt, opts) {
8649
8667
  const { c, dkLen, DK, PRF, PRFSalt } = pbkdf2Init(hash, password, salt, opts);
8650
8668
  let prfW;
8651
8669
  const arr = new Uint8Array(4);
8652
- const view = _chunkOJNQCRHUcjs.createView.call(void 0, arr);
8670
+ const view = _chunkQ4TOBBANcjs.createView.call(void 0, arr);
8653
8671
  const u = new Uint8Array(PRF.outputLen);
8654
8672
  for (let ti = 1, pos = 0; pos < dkLen; ti++, pos += PRF.outputLen) {
8655
8673
  const Ti = DK.subarray(pos, pos + PRF.outputLen);
@@ -8678,19 +8696,19 @@ function normalize(str) {
8678
8696
  return { nfkd: norm, words };
8679
8697
  }
8680
8698
  function aentropy(ent) {
8681
- _chunkOJNQCRHUcjs.abytes.call(void 0, ent);
8699
+ _chunkQ4TOBBANcjs.abytes.call(void 0, ent);
8682
8700
  if (![16, 20, 24, 28, 32].includes(ent.length))
8683
8701
  throw new Error("invalid entropy length");
8684
8702
  }
8685
8703
  function generateMnemonic(wordlist2, strength = 128) {
8686
- _chunkOJNQCRHUcjs.anumber.call(void 0, strength);
8704
+ _chunkQ4TOBBANcjs.anumber.call(void 0, strength);
8687
8705
  if (strength % 32 !== 0 || strength > 256)
8688
8706
  throw new TypeError("Invalid entropy");
8689
- return entropyToMnemonic(_chunkOJNQCRHUcjs.randomBytes.call(void 0, strength / 8), wordlist2);
8707
+ return entropyToMnemonic(_chunkQ4TOBBANcjs.randomBytes.call(void 0, strength / 8), wordlist2);
8690
8708
  }
8691
8709
  var calcChecksum = (entropy) => {
8692
8710
  const bitsLeft = 8 - entropy.length / 4;
8693
- return new Uint8Array([_chunkOJNQCRHUcjs.sha2562.call(void 0, entropy)[0] >> bitsLeft << bitsLeft]);
8711
+ return new Uint8Array([_chunkQ4TOBBANcjs.sha2562.call(void 0, entropy)[0] >> bitsLeft << bitsLeft]);
8694
8712
  };
8695
8713
  function getCoder(wordlist2) {
8696
8714
  if (!Array.isArray(wordlist2) || wordlist2.length !== 2048 || typeof wordlist2[0] !== "string")
@@ -8699,7 +8717,7 @@ function getCoder(wordlist2) {
8699
8717
  if (typeof i !== "string")
8700
8718
  throw new Error("wordlist: non-string element: " + i);
8701
8719
  });
8702
- return _chunkOJNQCRHUcjs.utils.chain(_chunkOJNQCRHUcjs.utils.checksum(1, calcChecksum), _chunkOJNQCRHUcjs.utils.radix2(11, true), _chunkOJNQCRHUcjs.utils.alphabet(wordlist2));
8720
+ return _chunkQ4TOBBANcjs.utils.chain(_chunkQ4TOBBANcjs.utils.checksum(1, calcChecksum), _chunkQ4TOBBANcjs.utils.radix2(11, true), _chunkQ4TOBBANcjs.utils.alphabet(wordlist2));
8703
8721
  }
8704
8722
  function mnemonicToEntropy(mnemonic, wordlist2) {
8705
8723
  const { words } = normalize(mnemonic);
@@ -8722,7 +8740,7 @@ function validateMnemonic(mnemonic, wordlist2) {
8722
8740
  }
8723
8741
  var psalt = (passphrase) => nfkd("mnemonic" + passphrase);
8724
8742
  function mnemonicToSeedSync(mnemonic, passphrase = "") {
8725
- return pbkdf2(_chunkOJNQCRHUcjs.sha512, normalize(mnemonic).nfkd, psalt(passphrase), { c: 2048, dkLen: 64 });
8743
+ return pbkdf2(_chunkQ4TOBBANcjs.sha512, normalize(mnemonic).nfkd, psalt(passphrase), { c: 2048, dkLen: 64 });
8726
8744
  }
8727
8745
  var wordlist = `abandon
8728
8746
  ability
@@ -11040,12 +11058,12 @@ function parseXOnlyPubKey(pubKeyHex) {
11040
11058
  );
11041
11059
  }
11042
11060
  function refundableVhtlc(params) {
11043
- if (params.scriptVersion !== void 0 && params.scriptVersion !== _chunkOJNQCRHUcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
11061
+ if (params.scriptVersion !== void 0 && params.scriptVersion !== _chunkQ4TOBBANcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
11044
11062
  throw new Error(
11045
11063
  `Unsupported Arkade HTLC script version: ${params.scriptVersion}`
11046
11064
  );
11047
11065
  }
11048
- return new (0, _chunkOJNQCRHUcjs.StrictVhtlcScript)({
11066
+ return new (0, _chunkQ4TOBBANcjs.StrictVhtlcScript)({
11049
11067
  sender: parseXOnlyPubKey(params.senderPubKey),
11050
11068
  receiver: parseXOnlyPubKey(params.receiverPubKey),
11051
11069
  server: parseXOnlyPubKey(params.serverPubKey),
@@ -11096,8 +11114,8 @@ async function buildArkadeRefund(params) {
11096
11114
  `Invalid hash lock length: expected 20 or 32, got ${hashLockBytes.length}`
11097
11115
  );
11098
11116
  }
11099
- const networkName = _chunkOJNQCRHUcjs.getNetworkName.call(void 0, network);
11100
- const serverUrl = _chunkOJNQCRHUcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
11117
+ const networkName = _chunkQ4TOBBANcjs.getNetworkName.call(void 0, network);
11118
+ const serverUrl = _chunkQ4TOBBANcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
11101
11119
  const arkProvider = new (0, _chunkBEW62OUTcjs.RestOperatorProvider)(serverUrl);
11102
11120
  const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
11103
11121
  const serverInfo = await arkProvider.getInfo();
@@ -11112,7 +11130,7 @@ async function buildArkadeRefund(params) {
11112
11130
  unilateralRefundWithoutReceiverDelay,
11113
11131
  scriptVersion: arkadeHtlcScriptVersion
11114
11132
  });
11115
- const hrp = _chunkOJNQCRHUcjs.getNetworkHrp.call(void 0, networkName);
11133
+ const hrp = _chunkQ4TOBBANcjs.getNetworkHrp.call(void 0, networkName);
11116
11134
  const computedAddress = vhtlc.address(hrp, serverPkBytes);
11117
11135
  const computedAddressStr = computedAddress.encode();
11118
11136
  if (computedAddressStr !== vhtlcAddress) {
@@ -11209,10 +11227,10 @@ var REGTEST_NETWORK = {
11209
11227
  function getNetwork(network) {
11210
11228
  switch (network) {
11211
11229
  case "mainnet":
11212
- return _chunkOJNQCRHUcjs.NETWORK;
11230
+ return _chunkQ4TOBBANcjs.NETWORK;
11213
11231
  case "testnet":
11214
11232
  case "signet":
11215
- return _chunkOJNQCRHUcjs.TEST_NETWORK;
11233
+ return _chunkQ4TOBBANcjs.TEST_NETWORK;
11216
11234
  case "regtest":
11217
11235
  return REGTEST_NETWORK;
11218
11236
  default:
@@ -11235,10 +11253,10 @@ function buildHashlockScript(hashLock, serverPubKey, btcHtlcScriptVersion = 1) {
11235
11253
  hashLock,
11236
11254
  "EQUAL"
11237
11255
  ];
11238
- return _chunkOJNQCRHUcjs.Script.encode(script);
11256
+ return _chunkQ4TOBBANcjs.Script.encode(script);
11239
11257
  }
11240
11258
  function buildTimelockScript(userPubKey, refundLocktime) {
11241
- return _chunkOJNQCRHUcjs.Script.encode([
11259
+ return _chunkQ4TOBBANcjs.Script.encode([
11242
11260
  refundLocktime,
11243
11261
  "CHECKLOCKTIMEVERIFY",
11244
11262
  "DROP",
@@ -11256,7 +11274,7 @@ function buildHtlcTaprootInfo(hashLock, serverPubKey, userPubKey, refundLocktime
11256
11274
  btcHtlcScriptVersion
11257
11275
  );
11258
11276
  const timelockScript = buildTimelockScript(userPubKey, refundLocktime);
11259
- const p2tr2 = _chunkOJNQCRHUcjs.p2tr.call(void 0,
11277
+ const p2tr2 = _chunkQ4TOBBANcjs.p2tr.call(void 0,
11260
11278
  NUMS_POINT.slice(1),
11261
11279
  // Remove the 02/03 prefix for x-only
11262
11280
  [{ script: hashlockScript }, { script: timelockScript }],
@@ -11339,7 +11357,7 @@ function buildOnchainClaimTransaction(params) {
11339
11357
  throw new Error("Failed to build tapLeafScript for hashlock");
11340
11358
  }
11341
11359
  const hashlockLeaf = tapLeafScript[0];
11342
- const tx = new (0, _chunkOJNQCRHUcjs.Transaction2)({
11360
+ const tx = new (0, _chunkQ4TOBBANcjs.Transaction2)({
11343
11361
  allowUnknownOutputs: true,
11344
11362
  allowUnknownInputs: true
11345
11363
  });
@@ -11360,7 +11378,7 @@ function buildOnchainClaimTransaction(params) {
11360
11378
  const sighash = tx.preimageWitnessV1(
11361
11379
  0,
11362
11380
  [p2tr2.script],
11363
- _chunkOJNQCRHUcjs.SigHash.DEFAULT,
11381
+ _chunkQ4TOBBANcjs.SigHash.DEFAULT,
11364
11382
  [htlcAmount],
11365
11383
  void 0,
11366
11384
  leafScript,
@@ -11381,7 +11399,7 @@ function buildOnchainClaimTransaction(params) {
11381
11399
  });
11382
11400
  const txHex = _chunkRYZSWESUcjs.hex.encode(tx.extract());
11383
11401
  const txId = tx.id;
11384
- const htlcAddress2 = _chunkOJNQCRHUcjs.Address.call(void 0, networkConfig).encode({
11402
+ const htlcAddress2 = _chunkQ4TOBBANcjs.Address.call(void 0, networkConfig).encode({
11385
11403
  type: "tr",
11386
11404
  pubkey: p2tr2.tweakedPubkey
11387
11405
  });
@@ -11451,7 +11469,7 @@ function buildOnchainRefundTransaction(params) {
11451
11469
  throw new Error("Failed to build tapLeafScript for timelock");
11452
11470
  }
11453
11471
  const timelockLeaf = tapLeafScript[1];
11454
- const tx = new (0, _chunkOJNQCRHUcjs.Transaction2)({
11472
+ const tx = new (0, _chunkQ4TOBBANcjs.Transaction2)({
11455
11473
  allowUnknownOutputs: true,
11456
11474
  allowUnknownInputs: true,
11457
11475
  lockTime: refundLocktime
@@ -11472,7 +11490,7 @@ function buildOnchainRefundTransaction(params) {
11472
11490
  tx.finalize();
11473
11491
  const txHex = _chunkRYZSWESUcjs.hex.encode(tx.extract());
11474
11492
  const txId = tx.id;
11475
- const htlcAddress2 = _chunkOJNQCRHUcjs.Address.call(void 0, networkConfig).encode({
11493
+ const htlcAddress2 = _chunkQ4TOBBANcjs.Address.call(void 0, networkConfig).encode({
11476
11494
  type: "tr",
11477
11495
  pubkey: p2tr2.tweakedPubkey
11478
11496
  });
@@ -11505,7 +11523,7 @@ function htlcAddress(hashLock, serverPubKey, userPubKey, refundLocktime, network
11505
11523
  refundLocktime,
11506
11524
  btcHtlcScriptVersion
11507
11525
  );
11508
- return _chunkOJNQCRHUcjs.Address.call(void 0, getNetwork(network)).encode({
11526
+ return _chunkQ4TOBBANcjs.Address.call(void 0, getNetwork(network)).encode({
11509
11527
  type: "tr",
11510
11528
  pubkey: p2tr2.tweakedPubkey
11511
11529
  });
@@ -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
  }
@@ -11604,12 +11640,12 @@ function checkedLightningPaymentHash(options, data) {
11604
11640
  }
11605
11641
  function assertFundedVhtlc(response, addressField, address2, hash160, refundPublicKey, lockDescription) {
11606
11642
  const swapId = response.id;
11607
- if (response.arkade_htlc_script_version !== _chunkOJNQCRHUcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
11643
+ if (response.arkade_htlc_script_version !== _chunkQ4TOBBANcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
11608
11644
  throw new SwapVerificationError(
11609
11645
  `Swap ${swapId} uses Arkade HTLC script version ${response.arkade_htlc_script_version}, which this client cannot refund; do not fund it`,
11610
11646
  {
11611
11647
  field: "arkade_htlc_script_version",
11612
- expected: String(_chunkOJNQCRHUcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT),
11648
+ expected: String(_chunkQ4TOBBANcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT),
11613
11649
  received: String(response.arkade_htlc_script_version),
11614
11650
  swapId
11615
11651
  }
@@ -11626,7 +11662,7 @@ function assertFundedVhtlc(response, addressField, address2, hash160, refundPubl
11626
11662
  unilateralRefundDelay: response.unilateral_refund_delay,
11627
11663
  unilateralRefundWithoutReceiverDelay: response.unilateral_refund_without_receiver_delay
11628
11664
  });
11629
- const expected = vhtlc.address(_chunkOJNQCRHUcjs.getNetworkHrp.call(void 0, _chunkOJNQCRHUcjs.getNetworkName.call(void 0, response.network)), server).encode();
11665
+ const expected = vhtlc.address(_chunkQ4TOBBANcjs.getNetworkHrp.call(void 0, _chunkQ4TOBBANcjs.getNetworkName.call(void 0, response.network)), server).encode();
11630
11666
  if (expected !== address2) {
11631
11667
  throw new SwapVerificationError(
11632
11668
  `Swap ${swapId}'s VHTLC address ${address2} does not lock to ${lockDescription} and this client's refund key (expected ${expected}); do not fund it`,
@@ -11670,12 +11706,12 @@ function assertHashLock(swapId, field, hashLock, accepted) {
11670
11706
  }
11671
11707
  function assertFundedHtlc(response, hashField, hashLock, serverPk, hash160, refundPublicKey, lockDescription) {
11672
11708
  const swapId = response.id;
11673
- if (response.btc_htlc_script_version !== _chunkOJNQCRHUcjs.BTC_HTLC_SCRIPT_VERSION_STRICT) {
11709
+ if (response.btc_htlc_script_version !== _chunkQ4TOBBANcjs.BTC_HTLC_SCRIPT_VERSION_STRICT) {
11674
11710
  throw new SwapVerificationError(
11675
11711
  `Swap ${swapId} uses Bitcoin HTLC script version ${response.btc_htlc_script_version}, which this client cannot refund; do not fund it`,
11676
11712
  {
11677
11713
  field: "btc_htlc_script_version",
11678
- expected: String(_chunkOJNQCRHUcjs.BTC_HTLC_SCRIPT_VERSION_STRICT),
11714
+ expected: String(_chunkQ4TOBBANcjs.BTC_HTLC_SCRIPT_VERSION_STRICT),
11679
11715
  received: String(response.btc_htlc_script_version),
11680
11716
  swapId
11681
11717
  }
@@ -11688,7 +11724,7 @@ function assertFundedHtlc(response, hashField, hashLock, serverPk, hash160, refu
11688
11724
  { field: hashField, expected: hash160, received: serverHash160, swapId }
11689
11725
  );
11690
11726
  }
11691
- const name = _chunkOJNQCRHUcjs.getNetworkName.call(void 0, response.network);
11727
+ const name = _chunkQ4TOBBANcjs.getNetworkName.call(void 0, response.network);
11692
11728
  const network = name === "bitcoin" ? "mainnet" : name === "mutinynet" ? "signet" : name;
11693
11729
  const binds = verifyHtlcAddress(
11694
11730
  response.btc_htlc_address,
@@ -11977,7 +12013,7 @@ async function createArkadeToEvmSwapGeneric(options, ctx, claimingAddressOverrid
11977
12013
  const claimingAddress = _nullishCoalesce(claimingAddressOverride, () => ( deriveEvmAddress(swapParams.secretKey)));
11978
12014
  const body = {
11979
12015
  hash_lock: hashLock,
11980
- arkade_htlc_script_version: _chunkOJNQCRHUcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12016
+ arkade_htlc_script_version: _chunkQ4TOBBANcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
11981
12017
  refund_pk: refundPk,
11982
12018
  user_id: userId,
11983
12019
  claiming_address: claimingAddress,
@@ -11985,13 +12021,13 @@ async function createArkadeToEvmSwapGeneric(options, ctx, claimingAddressOverrid
11985
12021
  token_address: options.tokenAddress,
11986
12022
  evm_chain_id: options.evmChainId,
11987
12023
  amount_in: options.sourceAmount ? Number(options.sourceAmount) : void 0,
11988
- amount_out: _optionalChain([options, 'access', _59 => _59.targetAmount, 'optionalAccess', _60 => _60.toString, 'call', _61 => _61()]),
11989
- referral_code: options.referralCode,
12024
+ amount_out: _optionalChain([options, 'access', _61 => _61.targetAmount, 'optionalAccess', _62 => _62.toString, 'call', _63 => _63()]),
12025
+ referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
11990
12026
  extra_fees: options.extraFees,
11991
12027
  gasless: _nullishCoalesce(options.gasless, () => ( true)),
11992
- bridge_target_chain: _optionalChain([options, 'access', _62 => _62.bridgeParams, 'optionalAccess', _63 => _63.targetChain]),
11993
- bridge_target_token_address: _optionalChain([options, 'access', _64 => _64.bridgeParams, 'optionalAccess', _65 => _65.targetTokenAddress]),
11994
- bridge_recipient_setup: _optionalChain([options, 'access', _66 => _66.bridgeParams, 'optionalAccess', _67 => _67.recipientSetup])
12028
+ bridge_target_chain: _optionalChain([options, 'access', _64 => _64.bridgeParams, 'optionalAccess', _65 => _65.targetChain]),
12029
+ bridge_target_token_address: _optionalChain([options, 'access', _66 => _66.bridgeParams, 'optionalAccess', _67 => _67.targetTokenAddress]),
12030
+ bridge_recipient_setup: _optionalChain([options, 'access', _68 => _68.bridgeParams, 'optionalAccess', _69 => _69.recipientSetup])
11995
12031
  };
11996
12032
  const { data, error } = await ctx.apiClient.POST("/swap/arkade/evm", {
11997
12033
  body
@@ -12014,8 +12050,8 @@ async function createArkadeToEvmSwapGeneric(options, ctx, claimingAddressOverrid
12014
12050
  },
12015
12051
  options.targetAddress,
12016
12052
  {
12017
- recipient: _optionalChain([options, 'access', _68 => _68.bridgeParams, 'optionalAccess', _69 => _69.recipient]),
12018
- recipientWallet: _optionalChain([options, 'access', _70 => _70.bridgeParams, 'optionalAccess', _71 => _71.recipientWallet])
12053
+ recipient: _optionalChain([options, 'access', _70 => _70.bridgeParams, 'optionalAccess', _71 => _71.recipient]),
12054
+ recipientWallet: _optionalChain([options, 'access', _72 => _72.bridgeParams, 'optionalAccess', _73 => _73.recipientWallet])
12019
12055
  }
12020
12056
  );
12021
12057
  return { response: data, swapParams };
@@ -12051,8 +12087,8 @@ async function createArkadeToLightningSwap(options, ctx) {
12051
12087
  target_amount_sats: options.targetAmountSats,
12052
12088
  refund_pk: refundPk,
12053
12089
  user_id: userId,
12054
- arkade_htlc_script_version: _chunkOJNQCRHUcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12055
- referral_code: options.referralCode,
12090
+ arkade_htlc_script_version: _chunkQ4TOBBANcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12091
+ referral_code: _nullishCoalesce(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,
@@ -12081,7 +12118,7 @@ async function createBitcoinToEvmSwap(options, ctx, claimingAddressOverride) {
12081
12118
  const claimingAddress = _nullishCoalesce(claimingAddressOverride, () => ( deriveEvmAddress(swapParams.secretKey)));
12082
12119
  const body = {
12083
12120
  hash_lock: hashLock,
12084
- btc_htlc_script_version: _chunkOJNQCRHUcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
12121
+ btc_htlc_script_version: _chunkQ4TOBBANcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
12085
12122
  refund_pk: refundPk,
12086
12123
  user_id: userId,
12087
12124
  claiming_address: claimingAddress,
@@ -12089,13 +12126,13 @@ async function createBitcoinToEvmSwap(options, ctx, claimingAddressOverride) {
12089
12126
  token_address: options.tokenAddress,
12090
12127
  evm_chain_id: options.evmChainId,
12091
12128
  amount_in: options.sourceAmount,
12092
- amount_out: _optionalChain([options, 'access', _72 => _72.targetAmount, 'optionalAccess', _73 => _73.toString, 'call', _74 => _74()]),
12093
- referral_code: options.referralCode,
12129
+ amount_out: _optionalChain([options, 'access', _74 => _74.targetAmount, 'optionalAccess', _75 => _75.toString, 'call', _76 => _76()]),
12130
+ referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
12094
12131
  extra_fees: options.extraFees,
12095
12132
  gasless: _nullishCoalesce(options.gasless, () => ( true)),
12096
- bridge_target_chain: _optionalChain([options, 'access', _75 => _75.bridgeParams, 'optionalAccess', _76 => _76.targetChain]),
12097
- bridge_target_token_address: _optionalChain([options, 'access', _77 => _77.bridgeParams, 'optionalAccess', _78 => _78.targetTokenAddress]),
12098
- bridge_recipient_setup: _optionalChain([options, 'access', _79 => _79.bridgeParams, 'optionalAccess', _80 => _80.recipientSetup])
12133
+ bridge_target_chain: _optionalChain([options, 'access', _77 => _77.bridgeParams, 'optionalAccess', _78 => _78.targetChain]),
12134
+ bridge_target_token_address: _optionalChain([options, 'access', _79 => _79.bridgeParams, 'optionalAccess', _80 => _80.targetTokenAddress]),
12135
+ bridge_recipient_setup: _optionalChain([options, 'access', _81 => _81.bridgeParams, 'optionalAccess', _82 => _82.recipientSetup])
12099
12136
  };
12100
12137
  const { data, error } = await ctx.apiClient.POST("/swap/bitcoin/evm", {
12101
12138
  body
@@ -12118,8 +12155,8 @@ async function createBitcoinToEvmSwap(options, ctx, claimingAddressOverride) {
12118
12155
  },
12119
12156
  options.targetAddress,
12120
12157
  {
12121
- recipient: _optionalChain([options, 'access', _81 => _81.bridgeParams, 'optionalAccess', _82 => _82.recipient]),
12122
- recipientWallet: _optionalChain([options, 'access', _83 => _83.bridgeParams, 'optionalAccess', _84 => _84.recipientWallet])
12158
+ recipient: _optionalChain([options, 'access', _83 => _83.bridgeParams, 'optionalAccess', _84 => _84.recipient]),
12159
+ recipientWallet: _optionalChain([options, 'access', _85 => _85.bridgeParams, 'optionalAccess', _86 => _86.recipientWallet])
12123
12160
  }
12124
12161
  );
12125
12162
  return { response: data, swapParams };
@@ -12141,10 +12178,10 @@ 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: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
12145
12182
  extra_fees: options.extraFees,
12146
- btc_htlc_script_version: _chunkOJNQCRHUcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
12147
- arkade_htlc_script_version: _chunkOJNQCRHUcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT
12183
+ btc_htlc_script_version: _chunkQ4TOBBANcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
12184
+ arkade_htlc_script_version: _chunkQ4TOBBANcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT
12148
12185
  };
12149
12186
  const { data, error } = await ctx.apiClient.POST("/swap/bitcoin/arkade", {
12150
12187
  body
@@ -12198,8 +12235,8 @@ async function createBitcoinToLightningSwap(options, ctx) {
12198
12235
  target_amount_sats: options.targetAmountSats,
12199
12236
  refund_pk: refundPk,
12200
12237
  user_id: userId,
12201
- btc_htlc_script_version: _chunkOJNQCRHUcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
12202
- referral_code: options.referralCode,
12238
+ btc_htlc_script_version: _chunkQ4TOBBANcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
12239
+ referral_code: _nullishCoalesce(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,
@@ -12220,7 +12258,7 @@ async function createBitcoinToLightningSwap(options, ctx) {
12220
12258
  return { response: data, swapParams };
12221
12259
  }
12222
12260
  function fundingTermsOf(data) {
12223
- if (!data.evm_chain_id || !data.evm_coordinator_address || !data.evm_htlc_address || !data.server_evm_address || !data.evm_refund_locktime || data.source_amount === void 0 || data.source_amount === null || !_optionalChain([data, 'access', _85 => _85.source_token, 'optionalAccess', _86 => _86.token_id])) {
12261
+ if (!data.evm_chain_id || !data.evm_coordinator_address || !data.evm_htlc_address || !data.server_evm_address || !data.evm_refund_locktime || data.source_amount === void 0 || data.source_amount === null || !_optionalChain([data, 'access', _87 => _87.source_token, 'optionalAccess', _88 => _88.token_id])) {
12224
12262
  return void 0;
12225
12263
  }
12226
12264
  return {
@@ -12233,7 +12271,7 @@ function fundingTermsOf(data) {
12233
12271
  timelock: data.evm_refund_locktime,
12234
12272
  sourceToken: data.source_token.token_id.toLowerCase(),
12235
12273
  sourceAmount: String(data.source_amount),
12236
- lockToken: _optionalChain([data, 'access', _87 => _87.evm_htlc_token, 'optionalAccess', _88 => _88.toLowerCase, 'call', _89 => _89()])
12274
+ lockToken: _optionalChain([data, 'access', _89 => _89.evm_htlc_token, 'optionalAccess', _90 => _90.toLowerCase, 'call', _91 => _91()])
12237
12275
  };
12238
12276
  }
12239
12277
  async function createEvmToArkadeSwapGeneric(options, ctx) {
@@ -12255,12 +12293,12 @@ 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: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
12259
12297
  extra_fees: options.extraFees,
12260
12298
  gasless: _nullishCoalesce(options.gasless, () => ( false)),
12261
- arkade_htlc_script_version: _chunkOJNQCRHUcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12262
- bridge_source_chain: _optionalChain([options, 'access', _90 => _90.inboundBridgeParams, 'optionalAccess', _91 => _91.sourceChain]),
12263
- bridge_source_token_address: _optionalChain([options, 'access', _92 => _92.inboundBridgeParams, 'optionalAccess', _93 => _93.sourceTokenAddress])
12299
+ arkade_htlc_script_version: _chunkQ4TOBBANcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12300
+ bridge_source_chain: _optionalChain([options, 'access', _92 => _92.inboundBridgeParams, 'optionalAccess', _93 => _93.sourceChain]),
12301
+ bridge_source_token_address: _optionalChain([options, 'access', _94 => _94.inboundBridgeParams, 'optionalAccess', _95 => _95.sourceTokenAddress])
12264
12302
  }
12265
12303
  });
12266
12304
  if (error) {
@@ -12294,7 +12332,7 @@ async function createEvmToBitcoinSwap(options, ctx) {
12294
12332
  const { data, error } = await ctx.apiClient.POST("/swap/evm/bitcoin", {
12295
12333
  body: {
12296
12334
  hash_lock: hashLock,
12297
- btc_htlc_script_version: _chunkOJNQCRHUcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
12335
+ btc_htlc_script_version: _chunkQ4TOBBANcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
12298
12336
  claim_pk: claimPk,
12299
12337
  user_id: userId,
12300
12338
  token_address: options.tokenAddress,
@@ -12303,11 +12341,11 @@ 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: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
12307
12345
  extra_fees: options.extraFees,
12308
12346
  gasless: _nullishCoalesce(options.gasless, () => ( false)),
12309
- bridge_source_chain: _optionalChain([options, 'access', _94 => _94.inboundBridgeParams, 'optionalAccess', _95 => _95.sourceChain]),
12310
- bridge_source_token_address: _optionalChain([options, 'access', _96 => _96.inboundBridgeParams, 'optionalAccess', _97 => _97.sourceTokenAddress])
12347
+ bridge_source_chain: _optionalChain([options, 'access', _96 => _96.inboundBridgeParams, 'optionalAccess', _97 => _97.sourceChain]),
12348
+ bridge_source_token_address: _optionalChain([options, 'access', _98 => _98.inboundBridgeParams, 'optionalAccess', _99 => _99.sourceTokenAddress])
12311
12349
  }
12312
12350
  });
12313
12351
  if (error) {
@@ -12362,11 +12400,11 @@ async function createEvmToLightningSwap(options, ctx) {
12362
12400
  target_amount_sats: options.targetAmountSats,
12363
12401
  user_address: _nullishCoalesce(userAddress, () => ( "")),
12364
12402
  user_id: userId,
12365
- referral_code: options.referralCode,
12403
+ referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
12366
12404
  extra_fees: options.extraFees,
12367
12405
  gasless: _nullishCoalesce(options.gasless, () => ( false)),
12368
- bridge_source_chain: _optionalChain([options, 'access', _98 => _98.inboundBridgeParams, 'optionalAccess', _99 => _99.sourceChain]),
12369
- bridge_source_token_address: _optionalChain([options, 'access', _100 => _100.inboundBridgeParams, 'optionalAccess', _101 => _101.sourceTokenAddress])
12406
+ bridge_source_chain: _optionalChain([options, 'access', _100 => _100.inboundBridgeParams, 'optionalAccess', _101 => _101.sourceChain]),
12407
+ bridge_source_token_address: _optionalChain([options, 'access', _102 => _102.inboundBridgeParams, 'optionalAccess', _103 => _103.sourceTokenAddress])
12370
12408
  }
12371
12409
  });
12372
12410
  if (error) {
@@ -12408,8 +12446,8 @@ async function createLightningToArkadeSwap(options, ctx) {
12408
12446
  source_amount_sats: options.sourceAmountSats,
12409
12447
  target_amount_sats: options.targetAmountSats,
12410
12448
  target_arkade_address: options.targetAddress,
12411
- arkade_htlc_script_version: _chunkOJNQCRHUcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12412
- referral_code: options.referralCode,
12449
+ arkade_htlc_script_version: _chunkQ4TOBBANcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT,
12450
+ referral_code: _nullishCoalesce(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.
@@ -12450,8 +12488,8 @@ async function createLightningToBitcoinSwap(options, ctx) {
12450
12488
  source_amount_sats: options.sourceAmountSats,
12451
12489
  target_amount_sats: options.targetAmountSats,
12452
12490
  target_address: options.targetAddress,
12453
- btc_htlc_script_version: _chunkOJNQCRHUcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
12454
- referral_code: options.referralCode,
12491
+ btc_htlc_script_version: _chunkQ4TOBBANcjs.BTC_HTLC_SCRIPT_VERSION_STRICT,
12492
+ referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
12455
12493
  extra_fees: options.extraFees,
12456
12494
  invoice_description: options.invoiceDescription
12457
12495
  };
@@ -12493,14 +12531,14 @@ async function createLightningToEvmSwap(options, ctx, claimingAddressOverride) {
12493
12531
  token_address: options.tokenAddress,
12494
12532
  evm_chain_id: options.evmChainId,
12495
12533
  amount_in: options.sourceAmount,
12496
- amount_out: _optionalChain([options, 'access', _102 => _102.targetAmount, 'optionalAccess', _103 => _103.toString, 'call', _104 => _104()]),
12534
+ amount_out: _optionalChain([options, 'access', _104 => _104.targetAmount, 'optionalAccess', _105 => _105.toString, 'call', _106 => _106()]),
12497
12535
  invoice_description: options.invoiceDescription,
12498
- referral_code: options.referralCode,
12536
+ referral_code: _nullishCoalesce(options.referralCode, () => ( ctx.referralCode)),
12499
12537
  extra_fees: options.extraFees,
12500
12538
  gasless: _nullishCoalesce(options.gasless, () => ( true)),
12501
- bridge_target_chain: _optionalChain([options, 'access', _105 => _105.bridgeParams, 'optionalAccess', _106 => _106.targetChain]),
12502
- bridge_target_token_address: _optionalChain([options, 'access', _107 => _107.bridgeParams, 'optionalAccess', _108 => _108.targetTokenAddress]),
12503
- bridge_recipient_setup: _optionalChain([options, 'access', _109 => _109.bridgeParams, 'optionalAccess', _110 => _110.recipientSetup])
12539
+ bridge_target_chain: _optionalChain([options, 'access', _107 => _107.bridgeParams, 'optionalAccess', _108 => _108.targetChain]),
12540
+ bridge_target_token_address: _optionalChain([options, 'access', _109 => _109.bridgeParams, 'optionalAccess', _110 => _110.targetTokenAddress]),
12541
+ bridge_recipient_setup: _optionalChain([options, 'access', _111 => _111.bridgeParams, 'optionalAccess', _112 => _112.recipientSetup])
12504
12542
  };
12505
12543
  const { data, error } = await ctx.apiClient.POST("/swap/lightning/evm", {
12506
12544
  body
@@ -12523,8 +12561,8 @@ async function createLightningToEvmSwap(options, ctx, claimingAddressOverride) {
12523
12561
  },
12524
12562
  options.targetAddress,
12525
12563
  {
12526
- recipient: _optionalChain([options, 'access', _111 => _111.bridgeParams, 'optionalAccess', _112 => _112.recipient]),
12527
- recipientWallet: _optionalChain([options, 'access', _113 => _113.bridgeParams, 'optionalAccess', _114 => _114.recipientWallet])
12564
+ recipient: _optionalChain([options, 'access', _113 => _113.bridgeParams, 'optionalAccess', _114 => _114.recipient]),
12565
+ recipientWallet: _optionalChain([options, 'access', _115 => _115.bridgeParams, 'optionalAccess', _116 => _116.recipientWallet])
12528
12566
  }
12529
12567
  );
12530
12568
  return { response: data, swapParams };
@@ -12548,10 +12586,10 @@ var REGTEST_NETWORK2 = {
12548
12586
  function toBtcSignerNetwork(network) {
12549
12587
  switch (network) {
12550
12588
  case "mainnet":
12551
- return _chunkOJNQCRHUcjs.NETWORK;
12589
+ return _chunkQ4TOBBANcjs.NETWORK;
12552
12590
  case "testnet":
12553
12591
  case "signet":
12554
- return _chunkOJNQCRHUcjs.TEST_NETWORK;
12592
+ return _chunkQ4TOBBANcjs.TEST_NETWORK;
12555
12593
  case "regtest":
12556
12594
  return REGTEST_NETWORK2;
12557
12595
  default:
@@ -12560,9 +12598,9 @@ function toBtcSignerNetwork(network) {
12560
12598
  }
12561
12599
  function addressToScriptHash(address2, network) {
12562
12600
  const net = toBtcSignerNetwork(network);
12563
- const decoded = _chunkOJNQCRHUcjs.Address.call(void 0, net).decode(address2);
12601
+ const decoded = _chunkQ4TOBBANcjs.Address.call(void 0, net).decode(address2);
12564
12602
  if (!decoded) throw new Error(`Unrecognised Bitcoin address: ${address2}`);
12565
- const script = _chunkOJNQCRHUcjs.OutScript.encode(decoded);
12603
+ const script = _chunkQ4TOBBANcjs.OutScript.encode(decoded);
12566
12604
  return _chunk5JR6AJ3Ycjs.bytesToHex.call(void 0, _chunk5JR6AJ3Ycjs.sha256.call(void 0, script).reverse());
12567
12605
  }
12568
12606
  var ElectrumWsClient = class {
@@ -12581,7 +12619,7 @@ var ElectrumWsClient = class {
12581
12619
  #closed = false;
12582
12620
  constructor(url, opts) {
12583
12621
  this.#url = url;
12584
- this.#log = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _115 => _115.onLog]), () => ( (() => {
12622
+ this.#log = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _117 => _117.onLog]), () => ( (() => {
12585
12623
  })));
12586
12624
  }
12587
12625
  /**
@@ -12654,7 +12692,7 @@ var ElectrumWsClient = class {
12654
12692
  handlers.delete(onChange);
12655
12693
  if (handlers.size > 0) return;
12656
12694
  this.#scriptHashHandlers.delete(scripthash);
12657
- if (_optionalChain([this, 'access', _116 => _116.#socket, 'optionalAccess', _117 => _117.readyState]) === WebSocket.OPEN) {
12695
+ if (_optionalChain([this, 'access', _118 => _118.#socket, 'optionalAccess', _119 => _119.readyState]) === WebSocket.OPEN) {
12658
12696
  this.request("blockchain.scripthash.unsubscribe", [scripthash]).catch(
12659
12697
  () => {
12660
12698
  }
@@ -12674,7 +12712,7 @@ var ElectrumWsClient = class {
12674
12712
  }
12675
12713
  async #ensureConnected() {
12676
12714
  if (this.#closed) throw new Error("Electrum client closed");
12677
- if (_optionalChain([this, 'access', _118 => _118.#socket, 'optionalAccess', _119 => _119.readyState]) === WebSocket.OPEN) return;
12715
+ if (_optionalChain([this, 'access', _120 => _120.#socket, 'optionalAccess', _121 => _121.readyState]) === WebSocket.OPEN) return;
12678
12716
  this.#connecting ??= this.#connect().finally(() => {
12679
12717
  this.#connecting = null;
12680
12718
  });
@@ -12787,7 +12825,7 @@ var ElectrumWsClient = class {
12787
12825
  #startPing() {
12788
12826
  this.#stopPing();
12789
12827
  this.#pingTimer = setInterval(() => {
12790
- if (_optionalChain([this, 'access', _120 => _120.#socket, 'optionalAccess', _121 => _121.readyState]) !== WebSocket.OPEN) return;
12828
+ if (_optionalChain([this, 'access', _122 => _122.#socket, 'optionalAccess', _123 => _123.readyState]) !== WebSocket.OPEN) return;
12791
12829
  this.request("server.ping", []).catch(() => {
12792
12830
  if (this.#socket && this.#socket.readyState === WebSocket.OPEN) {
12793
12831
  this.#teardownSocket(new Error("Electrum keepalive timed out"));
@@ -12874,7 +12912,7 @@ async function electrumFetchTransactionOutputs(client, txid) {
12874
12912
  return null;
12875
12913
  }
12876
12914
  try {
12877
- const tx = _chunkOJNQCRHUcjs.Transaction2.fromRaw(_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, rawHex), {
12915
+ const tx = _chunkQ4TOBBANcjs.Transaction2.fromRaw(_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, rawHex), {
12878
12916
  allowUnknownOutputs: true,
12879
12917
  allowUnknownInputs: true,
12880
12918
  disableScriptCheck: true
@@ -12897,7 +12935,7 @@ async function electrumBroadcastTransaction(client, txHex) {
12897
12935
  }
12898
12936
  async function electrumWaitForOutputByAddress(client, address2, network, timeoutMs, opts) {
12899
12937
  const scripthash = addressToScriptHash(address2, network);
12900
- const safetyRecheckMs = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _122 => _122.safetyRecheckMs]), () => ( 5e3));
12938
+ const safetyRecheckMs = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _124 => _124.safetyRecheckMs]), () => ( 5e3));
12901
12939
  return new Promise((resolve, reject) => {
12902
12940
  let settled = false;
12903
12941
  let deadlineTimer = null;
@@ -13143,7 +13181,7 @@ function kernelErc1271Digest(innerHash, account, chainId) {
13143
13181
  concat(KERNEL_WRAPPER_TYPEHASH, bytes32(innerHash))
13144
13182
  );
13145
13183
  return `0x${_chunk5JR6AJ3Ycjs.bytesToHex.call(void 0,
13146
- _chunk7GOXIT24cjs.keccak_256.call(void 0, concat(_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, "1901"), domainSeparator, structHash))
13184
+ _chunkJZTF4JNHcjs.keccak_256.call(void 0, concat(_chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, "1901"), domainSeparator, structHash))
13147
13185
  )}`;
13148
13186
  }
13149
13187
  function wrapKernelErc1271Signature(signature) {
@@ -13156,7 +13194,7 @@ function wrapKernelErc1271Signature(signature) {
13156
13194
  return `0x${ERC1271_SUDO_MODE_PREFIX}${hex2}`;
13157
13195
  }
13158
13196
  function keccak(data) {
13159
- return _chunk7GOXIT24cjs.keccak_256.call(void 0, data);
13197
+ return _chunkJZTF4JNHcjs.keccak_256.call(void 0, data);
13160
13198
  }
13161
13199
  function utf8(s) {
13162
13200
  return new TextEncoder().encode(s);
@@ -13236,7 +13274,7 @@ function encodeNativeCreate(params) {
13236
13274
  abi,
13237
13275
  functionName: "create",
13238
13276
  args: [
13239
- `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, params.preimageHash)}`,
13277
+ `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, params.preimageHash)}`,
13240
13278
  params.claimAddress,
13241
13279
  BigInt(params.timelock)
13242
13280
  ]
@@ -13253,10 +13291,10 @@ function buildNativeClaimTx(params) {
13253
13291
  }
13254
13292
  const preimage = params.preimage.startsWith("0x") ? params.preimage : `0x${params.preimage}`;
13255
13293
  const amount = BigInt(swap.evm_expected_sats);
13256
- const callsHash = _chunk7GOXIT24cjs.computeCoordinatorCallsHash.call(void 0, []);
13294
+ const callsHash = _chunkJZTF4JNHcjs.computeCoordinatorCallsHash.call(void 0, []);
13257
13295
  const signature = signEvmDigest(
13258
13296
  secretKey,
13259
- _chunk7GOXIT24cjs.buildNativeRedeemDigest.call(void 0, {
13297
+ _chunkJZTF4JNHcjs.buildNativeRedeemDigest.call(void 0, {
13260
13298
  htlcAddress: swap.evm_htlc_address,
13261
13299
  chainId: swap.evm_chain_id,
13262
13300
  htlcVersion: swap.evm_htlc_version,
@@ -13266,7 +13304,7 @@ function buildNativeClaimTx(params) {
13266
13304
  timelock: swap.evm_refund_locktime,
13267
13305
  caller,
13268
13306
  destination,
13269
- sweepToken: _chunk7GOXIT24cjs.NATIVE_TOKEN_ADDRESS,
13307
+ sweepToken: _chunkJZTF4JNHcjs.NATIVE_TOKEN_ADDRESS,
13270
13308
  minAmountOut: amount,
13271
13309
  callsHash
13272
13310
  })
@@ -13282,7 +13320,7 @@ function buildNativeClaimTx(params) {
13282
13320
  swap.server_evm_address,
13283
13321
  BigInt(swap.evm_refund_locktime),
13284
13322
  destination,
13285
- _chunk7GOXIT24cjs.NATIVE_TOKEN_ADDRESS,
13323
+ _chunkJZTF4JNHcjs.NATIVE_TOKEN_ADDRESS,
13286
13324
  amount,
13287
13325
  callsHash,
13288
13326
  signature.v,
@@ -13292,7 +13330,7 @@ function buildNativeClaimTx(params) {
13292
13330
  })
13293
13331
  };
13294
13332
  }
13295
- var selector = (signature) => _chunk7GOXIT24cjs.keccak2562.call(void 0, new TextEncoder().encode(signature)).slice(0, 10);
13333
+ var selector = (signature) => _chunkJZTF4JNHcjs.keccak2562.call(void 0, new TextEncoder().encode(signature)).slice(0, 10);
13296
13334
  var SHAPES = {
13297
13335
  // HTLCCoordinator.refundTo: the coordinator is the lock's sender (v6).
13298
13336
  refundTo: {
@@ -13349,30 +13387,30 @@ function decodeRefundCall(data) {
13349
13387
  }
13350
13388
  return `0x${word2.slice(24)}`;
13351
13389
  };
13352
- const timelock = _chunkMYOGO44Lcjs.decodeUint256.call(void 0, values.timelock);
13390
+ const timelock = _chunkTNZW35XAcjs.decodeUint256.call(void 0, values.timelock);
13353
13391
  if (timelock > BigInt(Number.MAX_SAFE_INTEGER)) {
13354
13392
  throw new Error(`The server's ${kind} call has a malformed timelock`);
13355
13393
  }
13356
13394
  return {
13357
13395
  kind,
13358
13396
  preimageHash: `0x${values.hash}`,
13359
- amount: _chunkMYOGO44Lcjs.decodeUint256.call(void 0, values.amount),
13360
- token: "token" in values ? address2("token") : _chunk7GOXIT24cjs.NATIVE_TOKEN_ADDRESS.toLowerCase(),
13397
+ amount: _chunkTNZW35XAcjs.decodeUint256.call(void 0, values.amount),
13398
+ token: "token" in values ? address2("token") : _chunkJZTF4JNHcjs.NATIVE_TOKEN_ADDRESS.toLowerCase(),
13361
13399
  sender: "sender" in values ? address2("sender") : void 0,
13362
13400
  claimAddress: address2("claim"),
13363
13401
  timelock: Number(timelock)
13364
13402
  };
13365
13403
  }
13366
13404
  function encodeRefundCall(to, call) {
13367
- const word2 = (hex2) => _chunk7GOXIT24cjs.normalizeBytes32.call(void 0, hex2);
13405
+ const word2 = (hex2) => _chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, hex2);
13368
13406
  const uint = (value) => BigInt(value).toString(16).padStart(64, "0");
13369
13407
  switch (call.kind) {
13370
13408
  case "refundTo":
13371
- return { to, data: _chunk7GOXIT24cjs.encodeRefundTo.call(void 0, to, call).data };
13409
+ return { to, data: _chunkJZTF4JNHcjs.encodeRefundTo.call(void 0, to, call).data };
13372
13410
  case "nativeRefundTo":
13373
- return { to, data: _chunk7GOXIT24cjs.encodeNativeRefundTo.call(void 0, to, call).data };
13411
+ return { to, data: _chunkJZTF4JNHcjs.encodeNativeRefundTo.call(void 0, to, call).data };
13374
13412
  case "nativeRefund":
13375
- return { to, data: _chunk7GOXIT24cjs.encodeHtlcNativeRefundCallData.call(void 0, to, call).data };
13413
+ return { to, data: _chunkJZTF4JNHcjs.encodeHtlcNativeRefundCallData.call(void 0, to, call).data };
13376
13414
  case "refundFor":
13377
13415
  case "nativeRefundFor": {
13378
13416
  if (call.sender === void 0) {
@@ -13420,12 +13458,12 @@ async function claimViaGasless(params) {
13420
13458
  const targetTokenAddress = String(swap.target_token.token_id);
13421
13459
  const needsDexSwap = targetTokenAddress.toLowerCase() !== wbtcAddress.toLowerCase();
13422
13460
  const sweepToken = needsDexSwap ? targetTokenAddress : wbtcAddress;
13423
- if (!needsDexSwap && _chunk7GOXIT24cjs.normalizeBytes32.call(void 0, callsHash) !== _chunk7GOXIT24cjs.normalizeBytes32.call(void 0, _chunk7GOXIT24cjs.computeCoordinatorCallsHash.call(void 0, []))) {
13461
+ if (!needsDexSwap && _chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, callsHash) !== _chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, _chunkJZTF4JNHcjs.computeCoordinatorCallsHash.call(void 0, []))) {
13424
13462
  throw new Error(
13425
13463
  "Refusing the server's claim: server calls on a direct claim"
13426
13464
  );
13427
13465
  }
13428
- const digest = _chunk7GOXIT24cjs.buildRedeemDigest.call(void 0, {
13466
+ const digest = _chunkJZTF4JNHcjs.buildRedeemDigest.call(void 0, {
13429
13467
  htlcAddress: swap.evm_htlc_address,
13430
13468
  chainId: swap.evm_chain_id,
13431
13469
  preimage: secretHex,
@@ -13462,15 +13500,15 @@ function alreadyClaimedStatus(errorText) {
13462
13500
  const match = /cannot claim a swap in (client_redeeming|client_redeemed|server_redeemed)/.exec(
13463
13501
  errorText
13464
13502
  );
13465
- return _optionalChain([match, 'optionalAccess', _123 => _123[1]]);
13503
+ return _optionalChain([match, 'optionalAccess', _125 => _125[1]]);
13466
13504
  }
13467
13505
  async function postClaim(baseUrl, swapId, body) {
13468
13506
  const response = await fetch(`${baseUrl}/swap/${swapId}/claim-gasless`, {
13469
13507
  method: "POST",
13470
13508
  headers: {
13471
13509
  "Content-Type": "application/json",
13472
- "X-Lendaswap-Client": _chunkOJNQCRHUcjs.CLIENT_AGENT,
13473
- ..._chunkOJNQCRHUcjs.PROTOCOL_HEADERS
13510
+ "X-Lendaswap-Client": _chunkQ4TOBBANcjs.CLIENT_AGENT,
13511
+ ..._chunkQ4TOBBANcjs.PROTOCOL_HEADERS
13474
13512
  },
13475
13513
  body: JSON.stringify(body)
13476
13514
  });
@@ -13693,8 +13731,8 @@ async function buildArkadeClaim(params) {
13693
13731
  `Preimage hash are not equal. '${_chunkRYZSWESUcjs.hex.encode(_chunkBEW62OUTcjs.ripemd1602.call(void 0, _chunkRYZSWESUcjs.hex.decode(preimageHash)))}' vs ${preimageHashBytesString}'`
13694
13732
  );
13695
13733
  }
13696
- const networkName = _chunkOJNQCRHUcjs.getNetworkName.call(void 0, network);
13697
- const serverUrl = _chunkOJNQCRHUcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
13734
+ const networkName = _chunkQ4TOBBANcjs.getNetworkName.call(void 0, network);
13735
+ const serverUrl = _chunkQ4TOBBANcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
13698
13736
  const arkProvider = new (0, _chunkBEW62OUTcjs.RestOperatorProvider)(serverUrl);
13699
13737
  const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
13700
13738
  const serverInfo = await arkProvider.getInfo();
@@ -13710,13 +13748,13 @@ async function buildArkadeClaim(params) {
13710
13748
  unilateralRefundWithoutReceiverDelay
13711
13749
  )
13712
13750
  };
13713
- if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !== _chunkOJNQCRHUcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
13751
+ if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !== _chunkQ4TOBBANcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
13714
13752
  throw new Error(
13715
13753
  `Unsupported Arkade HTLC script version: ${arkadeHtlcScriptVersion}`
13716
13754
  );
13717
13755
  }
13718
- const vhtlc = new (0, _chunkOJNQCRHUcjs.StrictVhtlcScript)(vhtlcOptions);
13719
- const hrp = _chunkOJNQCRHUcjs.getNetworkHrp.call(void 0, networkName);
13756
+ const vhtlc = new (0, _chunkQ4TOBBANcjs.StrictVhtlcScript)(vhtlcOptions);
13757
+ const hrp = _chunkQ4TOBBANcjs.getNetworkHrp.call(void 0, networkName);
13720
13758
  const computedAddress = vhtlc.address(hrp, serverPkBytes);
13721
13759
  const computedAddressStr = computedAddress.encode();
13722
13760
  if (computedAddressStr !== vhtlcAddress) {
@@ -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 Promise.resolve().then(() => _interopRequireWildcard(require("./dist-OHZT2JOQ-G5BFFCIV.cjs")));
13762
- const destAddr = ArkAddress2.decode(destinationAddress);
13799
+ const destAddr = _chunkBEW62OUTcjs.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
@@ -13860,8 +13897,8 @@ async function continueArkadeClaim(params) {
13860
13897
  `Preimage hash are not equal. '${_chunkRYZSWESUcjs.hex.encode(_chunkBEW62OUTcjs.ripemd1602.call(void 0, _chunkRYZSWESUcjs.hex.decode(preimageHash)))}' vs ${preimageHashBytesString}'`
13861
13898
  );
13862
13899
  }
13863
- const networkName = _chunkOJNQCRHUcjs.getNetworkName.call(void 0, network);
13864
- const serverUrl = _chunkOJNQCRHUcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
13900
+ const networkName = _chunkQ4TOBBANcjs.getNetworkName.call(void 0, network);
13901
+ const serverUrl = _chunkQ4TOBBANcjs.resolveArkadeServerUrlByName.call(void 0, networkName, arkadeServerUrl);
13865
13902
  const arkProvider = new (0, _chunkBEW62OUTcjs.RestOperatorProvider)(serverUrl);
13866
13903
  const indexerProvider = new (0, _chunkBEW62OUTcjs.RestIndexerProvider)(serverUrl);
13867
13904
  const vhtlcOptions = {
@@ -13876,13 +13913,13 @@ async function continueArkadeClaim(params) {
13876
13913
  unilateralRefundWithoutReceiverDelay
13877
13914
  )
13878
13915
  };
13879
- if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !== _chunkOJNQCRHUcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
13916
+ if (arkadeHtlcScriptVersion !== void 0 && arkadeHtlcScriptVersion !== _chunkQ4TOBBANcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
13880
13917
  throw new Error(
13881
13918
  `Unsupported Arkade HTLC script version: ${arkadeHtlcScriptVersion}`
13882
13919
  );
13883
13920
  }
13884
- const vhtlc = new (0, _chunkOJNQCRHUcjs.StrictVhtlcScript)(vhtlcOptions);
13885
- const hrp = _chunkOJNQCRHUcjs.getNetworkHrp.call(void 0, networkName);
13921
+ const vhtlc = new (0, _chunkQ4TOBBANcjs.StrictVhtlcScript)(vhtlcOptions);
13922
+ const hrp = _chunkQ4TOBBANcjs.getNetworkHrp.call(void 0, networkName);
13886
13923
  const computedAddress = vhtlc.address(hrp, serverPkBytes);
13887
13924
  const computedAddressStr = computedAddress.encode();
13888
13925
  if (computedAddressStr !== vhtlcAddress) {
@@ -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",
@@ -13931,7 +13967,7 @@ async function continueArkadeClaim(params) {
13931
13967
  amount: BigInt(v.value)
13932
13968
  },
13933
13969
  tapLeafScript: [claimLeafScript],
13934
- sighashType: _chunkOJNQCRHUcjs.SigHash.ALL
13970
+ sighashType: _chunkQ4TOBBANcjs.SigHash.ALL
13935
13971
  }));
13936
13972
  const intentProof = _chunkBEW62OUTcjs.Proof.create(intentMessage, intentInputs);
13937
13973
  for (let i = 0; i < vtxos.length; i++) {
@@ -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 = _chunkRYZSWESUcjs.hex.encode(
13999
+ _chunkBEW62OUTcjs.ArkAddress.decode(destinationAddress).pkScript
14000
+ );
14001
+ for (const { arkTxid, finalArkTx } of pendingTxs) {
14002
+ const arkTx = _chunkBEW62OUTcjs.Transaction2.fromPSBT(_chunkRYZSWESUcjs.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 || _chunkRYZSWESUcjs.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 = _chunkBEW62OUTcjs.Transaction2.fromPSBT(_chunkRYZSWESUcjs.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
  }
@@ -14119,7 +14171,7 @@ async function claimNativeViaRifRelay(params) {
14119
14171
  "/relay",
14120
14172
  rifEnvelope(request, signature)
14121
14173
  );
14122
- const txHash = _nullishCoalesce(relayed.txHash, () => ( _chunk7GOXIT24cjs.keccak2562.call(void 0, relayed.signedTx)));
14174
+ const txHash = _nullishCoalesce(relayed.txHash, () => ( _chunkJZTF4JNHcjs.keccak2562.call(void 0, relayed.signedTx)));
14123
14175
  const receipt = await signer.waitForReceipt(txHash);
14124
14176
  if (receipt.status !== "success") {
14125
14177
  throw new Error(`RIF Relay claim transaction ${txHash} reverted.`);
@@ -14230,13 +14282,13 @@ function encodeNativeRedeem(p) {
14230
14282
  return HTLC_NATIVE_REDEEM_SELECTOR + word(p.preimage) + word(p.amount) + word(p.sender) + word(p.timelock);
14231
14283
  }
14232
14284
  function rifSmartWalletAddress(relay, owner) {
14233
- const salt = _chunk7GOXIT24cjs.keccak2562.call(void 0,
14285
+ const salt = _chunkJZTF4JNHcjs.keccak2562.call(void 0,
14234
14286
  `0x${strip0x(owner).toLowerCase()}${"0".repeat(40)}${word(BigInt(RIF_SMART_WALLET_INDEX))}`
14235
14287
  );
14236
- const initCodeHash = _chunk7GOXIT24cjs.keccak2562.call(void 0,
14288
+ const initCodeHash = _chunkJZTF4JNHcjs.keccak2562.call(void 0,
14237
14289
  `0x602d3d8160093d39f3363d3d373d3d3d3d363d73${strip0x(relay.smart_wallet_template).toLowerCase()}5af43d923d90803e602b57fd5bf3`
14238
14290
  );
14239
- const hash = _chunk7GOXIT24cjs.keccak2562.call(void 0,
14291
+ const hash = _chunkJZTF4JNHcjs.keccak2562.call(void 0,
14240
14292
  `0xff${strip0x(relay.smart_wallet_factory).toLowerCase()}${strip0x(salt)}${strip0x(initCodeHash)}`
14241
14293
  );
14242
14294
  return `0x${hash.slice(-40)}`;
@@ -14310,8 +14362,8 @@ function buildRedeemAndExecuteTx(params) {
14310
14362
  const amount = BigInt(swap.evm_expected_sats);
14311
14363
  const targetTokenAddress = String(swap.target_token.token_id);
14312
14364
  const sweepToken = targetTokenAddress.toLowerCase() !== wbtcAddress.toLowerCase() ? targetTokenAddress : wbtcAddress;
14313
- const callsHash = _chunk7GOXIT24cjs.computeCoordinatorCallsHash.call(void 0, calls);
14314
- const digest = _chunk7GOXIT24cjs.buildRedeemDigest.call(void 0, {
14365
+ const callsHash = _chunkJZTF4JNHcjs.computeCoordinatorCallsHash.call(void 0, calls);
14366
+ const digest = _chunkJZTF4JNHcjs.buildRedeemDigest.call(void 0, {
14315
14367
  htlcAddress: swap.evm_htlc_address,
14316
14368
  chainId: swap.evm_chain_id,
14317
14369
  preimage: secretHex,
@@ -14327,7 +14379,7 @@ function buildRedeemAndExecuteTx(params) {
14327
14379
  htlcVersion: swap.evm_htlc_version
14328
14380
  });
14329
14381
  const sig = signEvmDigest(secretKey, digest);
14330
- const { to, data } = _chunk7GOXIT24cjs.encodeRedeemAndExecute.call(void 0, swap.evm_coordinator_address, {
14382
+ const { to, data } = _chunkJZTF4JNHcjs.encodeRedeemAndExecute.call(void 0, swap.evm_coordinator_address, {
14331
14383
  preimage: secretHex,
14332
14384
  amount,
14333
14385
  token: wbtcAddress,
@@ -14347,7 +14399,7 @@ async function claimViaUserOp(params) {
14347
14399
  const { secretKey, swap, aa } = params;
14348
14400
  const { to, data } = buildRedeemAndExecuteTx(params);
14349
14401
  const signer = keyToKernelOwnerSigner(secretKey, swap.evm_chain_id);
14350
- const { client } = await _chunk7GOXIT24cjs.createSwapSmartAccountClient.call(void 0, {
14402
+ const { client } = await _chunkJZTF4JNHcjs.createSwapSmartAccountClient.call(void 0, {
14351
14403
  signer,
14352
14404
  aa,
14353
14405
  chain: _chunk7BLTE6ETcjs.arbitrum
@@ -14379,15 +14431,15 @@ async function claimViaSigner(params) {
14379
14431
  }
14380
14432
  const native = swap.evm_htlc_kind === "native";
14381
14433
  const tx = native ? buildNativeClaimTx({ ...params, caller: signer.address }) : buildRedeemAndExecuteTx(params);
14382
- await _chunkMYOGO44Lcjs.simulateTransaction.call(void 0, signer, tx, "Claim transaction");
14434
+ await _chunkTNZW35XAcjs.simulateTransaction.call(void 0, signer, tx, "Claim transaction");
14383
14435
  const txHash = await signer.sendTransaction({
14384
14436
  ...tx,
14385
- ...native ? { type: _chunkMYOGO44Lcjs.txTypeFor.call(void 0, signer.chainId) } : {}
14437
+ ...native ? { type: _chunkTNZW35XAcjs.txTypeFor.call(void 0, signer.chainId) } : {}
14386
14438
  });
14387
14439
  const receipt = await signer.waitForReceipt(txHash);
14388
14440
  const minedHash = native ? receipt.transactionHash || txHash : txHash;
14389
14441
  if (receipt.status !== "success") {
14390
- const reason = await _chunkMYOGO44Lcjs.getRevertReason.call(void 0,
14442
+ const reason = await _chunkTNZW35XAcjs.getRevertReason.call(void 0,
14391
14443
  signer,
14392
14444
  minedHash,
14393
14445
  receipt.blockNumber
@@ -14401,7 +14453,7 @@ async function claimViaSigner(params) {
14401
14453
  `Replacement transaction ${minedHash} was mined, but its claim could not yet be verified. Check the swap status or transaction before submitting another claim.`
14402
14454
  );
14403
14455
  }
14404
- if (_optionalChain([mined, 'access', _124 => _124.to, 'optionalAccess', _125 => _125.toLowerCase, 'call', _126 => _126()]) !== tx.to.toLowerCase() || mined.from.toLowerCase() !== signer.address.toLowerCase() || mined.input.toLowerCase() !== tx.data.toLowerCase()) {
14456
+ if (_optionalChain([mined, 'access', _126 => _126.to, 'optionalAccess', _127 => _127.toLowerCase, 'call', _128 => _128()]) !== tx.to.toLowerCase() || mined.from.toLowerCase() !== signer.address.toLowerCase() || mined.input.toLowerCase() !== tx.data.toLowerCase()) {
14405
14457
  throw new Error(
14406
14458
  "The wallet replaced or cancelled the claim transaction. The claim was not submitted; try again from the payout wallet."
14407
14459
  );
@@ -14547,7 +14599,7 @@ function buildRefundScriptVhtlc(params) {
14547
14599
  const lendaswapPkBytes = parseXOnlyPubKey3(params.lendaswapPubKey);
14548
14600
  const serverPkBytes = parseXOnlyPubKey3(params.arkadeServerPubKey);
14549
14601
  const preimageHashBytes = parsePreimageHash(params.hashLock);
14550
- const networkName = _chunkOJNQCRHUcjs.getNetworkName.call(void 0, params.network);
14602
+ const networkName = _chunkQ4TOBBANcjs.getNetworkName.call(void 0, params.network);
14551
14603
  const options = {
14552
14604
  sender: userPkBytes,
14553
14605
  receiver: lendaswapPkBytes,
@@ -14560,13 +14612,13 @@ function buildRefundScriptVhtlc(params) {
14560
14612
  params.unilateralRefundWithoutReceiverDelay
14561
14613
  )
14562
14614
  };
14563
- if (params.arkadeHtlcScriptVersion !== void 0 && params.arkadeHtlcScriptVersion !== _chunkOJNQCRHUcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
14615
+ if (params.arkadeHtlcScriptVersion !== void 0 && params.arkadeHtlcScriptVersion !== _chunkQ4TOBBANcjs.ARKADE_HTLC_SCRIPT_VERSION_STRICT) {
14564
14616
  throw new Error(
14565
14617
  `Unsupported Arkade HTLC script version: ${params.arkadeHtlcScriptVersion}`
14566
14618
  );
14567
14619
  }
14568
- const vhtlc = new (0, _chunkOJNQCRHUcjs.StrictVhtlcScript)(options);
14569
- const hrp = _chunkOJNQCRHUcjs.getNetworkHrp.call(void 0, networkName);
14620
+ const vhtlc = new (0, _chunkQ4TOBBANcjs.StrictVhtlcScript)(options);
14621
+ const hrp = _chunkQ4TOBBANcjs.getNetworkHrp.call(void 0, networkName);
14570
14622
  const computedAddress = vhtlc.address(hrp, serverPkBytes).encode();
14571
14623
  if (computedAddress !== params.vhtlcAddress) {
14572
14624
  throw new Error(
@@ -14577,7 +14629,7 @@ function buildRefundScriptVhtlc(params) {
14577
14629
  }
14578
14630
  async function collabRefundArkadeToEvmOffchain(params) {
14579
14631
  const { vhtlc, networkName } = buildRefundScriptVhtlc(params);
14580
- const serverUrl = _chunkOJNQCRHUcjs.resolveArkadeServerUrlByName.call(void 0,
14632
+ const serverUrl = _chunkQ4TOBBANcjs.resolveArkadeServerUrlByName.call(void 0,
14581
14633
  networkName,
14582
14634
  params.arkadeServerUrl
14583
14635
  );
@@ -14663,7 +14715,7 @@ async function collabRefundArkadeToEvmOffchain(params) {
14663
14715
  }
14664
14716
  async function collabRefundArkadeToEvmDelegate(params) {
14665
14717
  const { vhtlc, networkName } = buildRefundScriptVhtlc(params);
14666
- const serverUrl = _chunkOJNQCRHUcjs.resolveArkadeServerUrlByName.call(void 0,
14718
+ const serverUrl = _chunkQ4TOBBANcjs.resolveArkadeServerUrlByName.call(void 0,
14667
14719
  networkName,
14668
14720
  params.arkadeServerUrl
14669
14721
  );
@@ -14678,13 +14730,13 @@ async function collabRefundArkadeToEvmDelegate(params) {
14678
14730
  }
14679
14731
  const cosignerPkHex = cosignerRes.data.cosigner_pk;
14680
14732
  const btcNetwork = _chunkBEW62OUTcjs.networks[networkName];
14681
- const forfeitDecoded = _chunkOJNQCRHUcjs.Address.call(void 0, btcNetwork).decode(serverInfo.forfeitAddress);
14733
+ const forfeitDecoded = _chunkQ4TOBBANcjs.Address.call(void 0, btcNetwork).decode(serverInfo.forfeitAddress);
14682
14734
  if (!forfeitDecoded) {
14683
14735
  throw new Error(
14684
14736
  `Unrecognised forfeit address: ${serverInfo.forfeitAddress}`
14685
14737
  );
14686
14738
  }
14687
- const forfeitPkScript = _chunkOJNQCRHUcjs.OutScript.encode(forfeitDecoded);
14739
+ const forfeitPkScript = _chunkQ4TOBBANcjs.OutScript.encode(forfeitDecoded);
14688
14740
  const vhtlcPkScript = _chunkRYZSWESUcjs.hex.encode(vhtlc.pkScript);
14689
14741
  const { vtxos: allVtxos } = await indexerProvider.getVtxos({
14690
14742
  scripts: [vhtlcPkScript]
@@ -14717,7 +14769,7 @@ async function collabRefundArkadeToEvmDelegate(params) {
14717
14769
  amount: BigInt(v.value)
14718
14770
  },
14719
14771
  tapLeafScript: [tapLeafScript],
14720
- sighashType: _chunkOJNQCRHUcjs.SigHash.ALL
14772
+ sighashType: _chunkQ4TOBBANcjs.SigHash.ALL
14721
14773
  }));
14722
14774
  const intentProof = _chunkBEW62OUTcjs.Proof.create(intentMessage, intentInputs, [
14723
14775
  { script: destination.pkScript, amount: totalAmount }
@@ -14743,7 +14795,7 @@ async function collabRefundArkadeToEvmDelegate(params) {
14743
14795
  amount: vtxoAmount
14744
14796
  },
14745
14797
  tapLeafScript: [tapLeafScript],
14746
- sighashType: _chunkOJNQCRHUcjs.SigHash.ALL_ANYONECANPAY
14798
+ sighashType: _chunkQ4TOBBANcjs.SigHash.ALL_ANYONECANPAY
14747
14799
  });
14748
14800
  forfeitTx.addOutput({
14749
14801
  script: forfeitPkScript,
@@ -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: _nullishCoalesce(wire.self_relayed, () => ( void 0))
14891
14944
  };
14892
14945
  }
14893
14946
  return { router: "layerzero", native_fee_sats: wire.native_fee_sats };
@@ -15011,7 +15064,7 @@ function createSwapStatusWatcher(baseUrl) {
15011
15064
  });
15012
15065
  socket.addEventListener("error", () => {
15013
15066
  try {
15014
- _optionalChain([socket, 'optionalAccess', _127 => _127.close, 'call', _128 => _128()]);
15067
+ _optionalChain([socket, 'optionalAccess', _129 => _129.close, 'call', _130 => _130()]);
15015
15068
  } catch (e18) {
15016
15069
  }
15017
15070
  });
@@ -15029,7 +15082,7 @@ function createSwapStatusWatcher(baseUrl) {
15029
15082
  }, delay);
15030
15083
  }
15031
15084
  function sendSubscribe(ids) {
15032
- if (ids.length === 0 || _optionalChain([socket, 'optionalAccess', _129 => _129.readyState]) !== WebSocket.OPEN) return;
15085
+ if (ids.length === 0 || _optionalChain([socket, 'optionalAccess', _131 => _131.readyState]) !== WebSocket.OPEN) return;
15033
15086
  const frame = {
15034
15087
  op: "subscribe",
15035
15088
  channel: "swap_status",
@@ -15038,7 +15091,7 @@ function createSwapStatusWatcher(baseUrl) {
15038
15091
  socket.send(JSON.stringify(frame));
15039
15092
  }
15040
15093
  function sendUnsubscribe(ids) {
15041
- if (ids.length === 0 || _optionalChain([socket, 'optionalAccess', _130 => _130.readyState]) !== WebSocket.OPEN) return;
15094
+ if (ids.length === 0 || _optionalChain([socket, 'optionalAccess', _132 => _132.readyState]) !== WebSocket.OPEN) return;
15042
15095
  const frame = {
15043
15096
  op: "unsubscribe",
15044
15097
  channel: "swap_status",
@@ -15054,7 +15107,7 @@ function createSwapStatusWatcher(baseUrl) {
15054
15107
  reconnectTimer = null;
15055
15108
  }
15056
15109
  try {
15057
- _optionalChain([socket, 'optionalAccess', _131 => _131.close, 'call', _132 => _132()]);
15110
+ _optionalChain([socket, 'optionalAccess', _133 => _133.close, 'call', _134 => _134()]);
15058
15111
  } catch (e19) {
15059
15112
  }
15060
15113
  socket = null;
@@ -15171,7 +15224,7 @@ function checkedRefundContext(checked) {
15171
15224
  };
15172
15225
  }
15173
15226
  function permit2RefundAddress(serverData, depositorAddress) {
15174
- if (!_chunk7GOXIT24cjs.depositorIsSender.call(void 0, serverData.htlc_kind, serverData.htlc_version)) {
15227
+ if (!_chunkJZTF4JNHcjs.depositorIsSender.call(void 0, serverData.htlc_kind, serverData.htlc_version)) {
15175
15228
  return serverData.coordinator_address;
15176
15229
  }
15177
15230
  if (!depositorAddress) {
@@ -15182,8 +15235,8 @@ function permit2RefundAddress(serverData, depositorAddress) {
15182
15235
  return depositorAddress;
15183
15236
  }
15184
15237
  function ensureRehashMatchesRequest(signature, paymentHash, params) {
15185
- const signed = `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, signature.newPreimageHash)}`;
15186
- if (signed !== `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, paymentHash)}`) {
15238
+ const signed = `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, signature.newPreimageHash)}`;
15239
+ if (signed !== `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, paymentHash)}`) {
15187
15240
  throw new Error(
15188
15241
  `The server signed a rehash to ${signed}, not to the invoice's payment hash ${paymentHash}`
15189
15242
  );
@@ -15193,18 +15246,18 @@ function ensureRehashMatchesRequest(signature, paymentHash, params) {
15193
15246
  `The server signed a rehash with timelock ${signature.newTimelock}, later than the advertised ${params.newTimelock}`
15194
15247
  );
15195
15248
  }
15196
- if (signature.htlcAddress.toLowerCase() !== params.htlcAddress.toLowerCase() || `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, signature.preimageHash)}` !== `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, params.preimageHash)}`) {
15249
+ if (signature.htlcAddress.toLowerCase() !== params.htlcAddress.toLowerCase() || `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, signature.preimageHash)}` !== `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, params.preimageHash)}`) {
15197
15250
  throw new Error(
15198
15251
  "The server signed a rehash for another lock than the swap's"
15199
15252
  );
15200
15253
  }
15201
15254
  }
15202
15255
  function ensureLockIsOwn(lock, named, what) {
15203
- const native = lock.token === _chunk7GOXIT24cjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
15256
+ const native = lock.token === _chunkJZTF4JNHcjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
15204
15257
  const mismatches = [
15205
15258
  named.htlcAddress.toLowerCase() !== lock.htlcAddress.toLowerCase() && "htlc address",
15206
15259
  named.chainId !== lock.chainId && "chain",
15207
- `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, named.preimageHash)}` !== lock.preimageHash && "preimage hash",
15260
+ `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, named.preimageHash)}` !== lock.preimageHash && "preimage hash",
15208
15261
  BigInt(named.amount) !== lock.amount && "amount",
15209
15262
  // A native lock keys a zero asset word whatever the server calls it.
15210
15263
  !native && named.token.toLowerCase() !== lock.token && "token",
@@ -15229,7 +15282,7 @@ function rehashCallData(signature) {
15229
15282
  r: signature.r,
15230
15283
  s: signature.s
15231
15284
  };
15232
- return signature.htlcKind === "native" ? _chunk7GOXIT24cjs.encodeHtlcNativeRehashCallData.call(void 0, signature.htlcAddress, terms) : _chunk7GOXIT24cjs.encodeHtlcErc20RehashCallData.call(void 0, signature.htlcAddress, {
15285
+ return signature.htlcKind === "native" ? _chunkJZTF4JNHcjs.encodeHtlcNativeRehashCallData.call(void 0, signature.htlcAddress, terms) : _chunkJZTF4JNHcjs.encodeHtlcErc20RehashCallData.call(void 0, signature.htlcAddress, {
15233
15286
  ...terms,
15234
15287
  token: signature.token
15235
15288
  });
@@ -15243,7 +15296,7 @@ function refundBySigCallData(signature) {
15243
15296
  r: signature.r,
15244
15297
  s: signature.s
15245
15298
  };
15246
- return signature.htlcKind === "native" ? _chunk7GOXIT24cjs.encodeHtlcNativeRefundBySigCallData.call(void 0, signature.htlcAddress, terms) : _chunk7GOXIT24cjs.encodeHtlcErc20RefundBySigCallData.call(void 0, signature.htlcAddress, {
15299
+ return signature.htlcKind === "native" ? _chunkJZTF4JNHcjs.encodeHtlcNativeRefundBySigCallData.call(void 0, signature.htlcAddress, terms) : _chunkJZTF4JNHcjs.encodeHtlcErc20RefundBySigCallData.call(void 0, signature.htlcAddress, {
15247
15300
  ...terms,
15248
15301
  token: signature.token
15249
15302
  });
@@ -15263,17 +15316,17 @@ function uniqueAddresses(values) {
15263
15316
  ];
15264
15317
  }
15265
15318
  async function sendCall(signer, call, label, options = {}) {
15266
- await _chunkMYOGO44Lcjs.simulateTransaction.call(void 0, signer, call, label);
15319
+ await _chunkTNZW35XAcjs.simulateTransaction.call(void 0, signer, call, label);
15267
15320
  const sent = await signer.sendTransaction({
15268
15321
  to: call.to,
15269
15322
  data: call.data,
15270
- type: _chunkMYOGO44Lcjs.txTypeFor.call(void 0, signer.chainId),
15271
- gas: await _chunkMYOGO44Lcjs.gasLimitFor.call(void 0, signer, call, _nullishCoalesce(options.fallbackGas, () => ( REFUND_GAS)))
15323
+ type: _chunkTNZW35XAcjs.txTypeFor.call(void 0, signer.chainId),
15324
+ gas: await _chunkTNZW35XAcjs.gasLimitFor.call(void 0, signer, call, _nullishCoalesce(options.fallbackGas, () => ( REFUND_GAS)))
15272
15325
  });
15273
- await _optionalChain([options, 'access', _133 => _133.onSent, 'optionalCall', _134 => _134(sent)]);
15326
+ await _optionalChain([options, 'access', _135 => _135.onSent, 'optionalCall', _136 => _136(sent)]);
15274
15327
  const receipt = await signer.waitForReceipt(sent);
15275
15328
  if (receipt.status !== "success") {
15276
- const reason = await _chunkMYOGO44Lcjs.getRevertReason.call(void 0, signer, sent, receipt.blockNumber);
15329
+ const reason = await _chunkTNZW35XAcjs.getRevertReason.call(void 0, signer, sent, receipt.blockNumber);
15277
15330
  throw new Error(`${label} reverted: ${reason}`);
15278
15331
  }
15279
15332
  const mined = receipt.transactionHash || sent;
@@ -15287,7 +15340,7 @@ async function sendCall(signer, call, label, options = {}) {
15287
15340
  async function isSameCall(signer, hash, call) {
15288
15341
  try {
15289
15342
  const tx = await signer.getTransaction(hash);
15290
- return _optionalChain([tx, 'optionalAccess', _135 => _135.to, 'optionalAccess', _136 => _136.toLowerCase, 'call', _137 => _137()]) === call.to.toLowerCase() && tx.input.toLowerCase() === call.data.toLowerCase();
15343
+ return _optionalChain([tx, 'optionalAccess', _137 => _137.to, 'optionalAccess', _138 => _138.toLowerCase, 'call', _139 => _139()]) === call.to.toLowerCase() && tx.input.toLowerCase() === call.data.toLowerCase();
15291
15344
  } catch (e20) {
15292
15345
  return false;
15293
15346
  }
@@ -15305,10 +15358,10 @@ function dedupeTxids(txids) {
15305
15358
  function clientHashLockOf(stored) {
15306
15359
  switch (stored.response.direction) {
15307
15360
  case "evm_to_lightning":
15308
- return _optionalChain([stored, 'access', _138 => _138.lightningPaymentHash, 'optionalAccess', _139 => _139.hash]);
15361
+ return _optionalChain([stored, 'access', _140 => _140.lightningPaymentHash, 'optionalAccess', _141 => _141.hash]);
15309
15362
  case "evm_to_bitcoin":
15310
15363
  case "evm_to_arkade":
15311
- return stored.preimageHash ? `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, stored.preimageHash)}` : void 0;
15364
+ return stored.preimageHash ? `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, stored.preimageHash)}` : void 0;
15312
15365
  default:
15313
15366
  return void 0;
15314
15367
  }
@@ -15320,7 +15373,7 @@ function evmHashLockOf(swap) {
15320
15373
  return hash;
15321
15374
  }
15322
15375
  function evmSourceLeg(stored) {
15323
- const rehashes = _optionalChain([stored, 'access', _140 => _140.evmRehashes, 'optionalAccess', _141 => _141.length]) ? stored.evmRehashes : void 0;
15376
+ const rehashes = _optionalChain([stored, 'access', _142 => _142.evmRehashes, 'optionalAccess', _143 => _143.length]) ? stored.evmRehashes : void 0;
15324
15377
  const swap = stored.response;
15325
15378
  return {
15326
15379
  chainId: swap.evm_chain_id,
@@ -15330,9 +15383,9 @@ function evmSourceLeg(stored) {
15330
15383
  // without it, and switches to the current hash once a rehash is
15331
15384
  // confirmed). The funding tx's SwapCreated is under the first hash, and
15332
15385
  // the rehashes are followed from there.
15333
- hashLock: _nullishCoalesce(_nullishCoalesce(_optionalChain([rehashes, 'optionalAccess', _142 => _142[0], 'optionalAccess', _143 => _143.fromHashLock]), () => ( clientHashLockOf(stored))), () => ( (swap.direction === "evm_to_bitcoin" ? swap.evm_hash_lock : swap.hash_lock))),
15386
+ hashLock: _nullishCoalesce(_nullishCoalesce(_optionalChain([rehashes, 'optionalAccess', _144 => _144[0], 'optionalAccess', _145 => _145.fromHashLock]), () => ( clientHashLockOf(stored))), () => ( (swap.direction === "evm_to_bitcoin" ? swap.evm_hash_lock : swap.hash_lock))),
15334
15387
  claimAddress: swap.server_evm_address,
15335
- timelock: _nullishCoalesce(_optionalChain([rehashes, 'optionalAccess', _144 => _144.at, 'call', _145 => _145(-1), 'optionalAccess', _146 => _146.timelock]), () => ( swap.evm_refund_locktime)),
15388
+ timelock: _nullishCoalesce(_optionalChain([rehashes, 'optionalAccess', _146 => _146.at, 'call', _147 => _147(-1), 'optionalAccess', _148 => _148.timelock]), () => ( swap.evm_refund_locktime)),
15336
15389
  // This client's own record first, then the server's copy (which names
15337
15390
  // the rehash tx once a rehash is confirmed; that one carries no
15338
15391
  // SwapCreated and is skipped as unavailable).
@@ -15343,20 +15396,20 @@ function evmSourceLeg(stored) {
15343
15396
  // Read from the creation terms first, which a server refresh cannot
15344
15397
  // rewrite; a swap recorded before they named the version falls back to
15345
15398
  // the server's copy.
15346
- depositorIsSender: _optionalChain([stored, 'access', _147 => _147.evmFundingTerms, 'optionalAccess', _148 => _148.htlcVersion]) !== void 0 ? _chunk7GOXIT24cjs.depositorIsSender.call(void 0,
15399
+ depositorIsSender: _optionalChain([stored, 'access', _149 => _149.evmFundingTerms, 'optionalAccess', _150 => _150.htlcVersion]) !== void 0 ? _chunkJZTF4JNHcjs.depositorIsSender.call(void 0,
15347
15400
  stored.evmFundingTerms.htlcKind,
15348
15401
  stored.evmFundingTerms.htlcVersion
15349
- ) : _chunk7GOXIT24cjs.depositorIsSender.call(void 0, swap.evm_htlc_kind, swap.evm_htlc_version)
15402
+ ) : _chunkJZTF4JNHcjs.depositorIsSender.call(void 0, swap.evm_htlc_kind, swap.evm_htlc_version)
15350
15403
  };
15351
15404
  }
15352
15405
  function isDirectNativeLock(terms) {
15353
- return terms.htlcKind === "native" && terms.coordinator.toLowerCase() === _chunk7GOXIT24cjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
15406
+ return terms.htlcKind === "native" && terms.coordinator.toLowerCase() === _chunkJZTF4JNHcjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
15354
15407
  }
15355
15408
  function provesNoLockUnder(receipt, hashLock) {
15356
15409
  if (receipt.logs === void 0) return false;
15357
- const hash = `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, hashLock)}`;
15410
+ const hash = `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, hashLock)}`;
15358
15411
  return !receipt.logs.some(
15359
- (log) => log.topics.some((topic) => `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, topic)}` === hash) || _optionalChain([_chunk7GOXIT24cjs.decodeSwapCreatedLog.call(void 0, log), 'optionalAccess', _149 => _149.preimageHash]) === hash
15412
+ (log) => log.topics.some((topic) => `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, topic)}` === hash) || _optionalChain([_chunkJZTF4JNHcjs.decodeSwapCreatedLog.call(void 0, log), 'optionalAccess', _151 => _151.preimageHash]) === hash
15360
15413
  );
15361
15414
  }
15362
15415
  var serializeAmountInput = (amount) => amount == null ? void 0 : amount.toString();
@@ -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) } : {},
@@ -15407,10 +15467,10 @@ var DEFAULT_ELECTRUM_WS_URLS = {
15407
15467
  mainnet: "wss://electrs.satora.io"
15408
15468
  };
15409
15469
  function defaultAaConfig() {
15410
- if (!_chunkOJNQCRHUcjs.DEFAULT_AA_BUNDLER_URL) return void 0;
15470
+ if (!_chunkQ4TOBBANcjs.DEFAULT_AA_BUNDLER_URL) return void 0;
15411
15471
  return {
15412
- bundlerUrl: _chunkOJNQCRHUcjs.DEFAULT_AA_BUNDLER_URL,
15413
- ..._chunkOJNQCRHUcjs.DEFAULT_AA_POLICY_ID ? { paymasterPolicyId: _chunkOJNQCRHUcjs.DEFAULT_AA_POLICY_ID } : {}
15472
+ bundlerUrl: _chunkQ4TOBBANcjs.DEFAULT_AA_BUNDLER_URL,
15473
+ ..._chunkQ4TOBBANcjs.DEFAULT_AA_POLICY_ID ? { paymasterPolicyId: _chunkQ4TOBBANcjs.DEFAULT_AA_POLICY_ID } : {}
15414
15474
  };
15415
15475
  }
15416
15476
  var ClientBuilder = class {
@@ -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);
@@ -15661,9 +15725,9 @@ var ClientBuilder = class {
15661
15725
  baseUrl: this.#baseUrl.replace(/\/+$/, ""),
15662
15726
  referralCode: this.#referralCode,
15663
15727
  defaultHeaders: this.#defaultHeaders,
15664
- esploraUrl: Array.isArray(this.#esploraUrl) ? this.#esploraUrl.map((url) => url.replace(/\/+$/, "")) : _optionalChain([this, 'access', _150 => _150.#esploraUrl, 'optionalAccess', _151 => _151.replace, 'call', _152 => _152(/\/+$/, "")]),
15665
- electrumWsUrl: _optionalChain([this, 'access', _153 => _153.#electrumWsUrl, 'optionalAccess', _154 => _154.replace, 'call', _155 => _155(/\/+$/, "")]),
15666
- arkadeServerUrl: _optionalChain([this, 'access', _156 => _156.#arkadeServerUrl, 'optionalAccess', _157 => _157.replace, 'call', _158 => _158(/\/+$/, "")]),
15728
+ esploraUrl: Array.isArray(this.#esploraUrl) ? this.#esploraUrl.map((url) => url.replace(/\/+$/, "")) : _optionalChain([this, 'access', _152 => _152.#esploraUrl, 'optionalAccess', _153 => _153.replace, 'call', _154 => _154(/\/+$/, "")]),
15729
+ electrumWsUrl: _optionalChain([this, 'access', _155 => _155.#electrumWsUrl, 'optionalAccess', _156 => _156.replace, 'call', _157 => _157(/\/+$/, "")]),
15730
+ arkadeServerUrl: _optionalChain([this, 'access', _158 => _158.#arkadeServerUrl, 'optionalAccess', _159 => _159.replace, 'call', _160 => _160(/\/+$/, "")]),
15667
15731
  aa: _nullishCoalesce(this.#aa, () => ( defaultAaConfig())),
15668
15732
  solanaRpcUrl: this.#solanaRpcUrl,
15669
15733
  logger: this.#logger,
@@ -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;
@@ -15718,8 +15783,8 @@ var Client = class _Client {
15718
15783
  }
15719
15784
  #apiHeaders(extra) {
15720
15785
  return {
15721
- "X-Lendaswap-Client": _chunkOJNQCRHUcjs.CLIENT_AGENT,
15722
- ..._chunkOJNQCRHUcjs.PROTOCOL_HEADERS,
15786
+ "X-Lendaswap-Client": _chunkQ4TOBBANcjs.CLIENT_AGENT,
15787
+ ..._chunkQ4TOBBANcjs.PROTOCOL_HEADERS,
15723
15788
  ..._nullishCoalesce(this.#config.defaultHeaders, () => ( {})),
15724
15789
  ..._nullishCoalesce(extra, () => ( {}))
15725
15790
  };
@@ -15745,11 +15810,11 @@ var Client = class _Client {
15745
15810
  * Remove `onUpdate` from the given swap ids.
15746
15811
  */
15747
15812
  unsubscribeFromSwaps(swapIds, onUpdate) {
15748
- _optionalChain([this, 'access', _159 => _159.#statusWatcher, 'optionalAccess', _160 => _160.unsubscribe, 'call', _161 => _161(swapIds, onUpdate)]);
15813
+ _optionalChain([this, 'access', _161 => _161.#statusWatcher, 'optionalAccess', _162 => _162.unsubscribe, 'call', _163 => _163(swapIds, onUpdate)]);
15749
15814
  }
15750
15815
  /** Force-close the shared swap-status socket. */
15751
15816
  closeSwapStatusSocket() {
15752
- _optionalChain([this, 'access', _162 => _162.#statusWatcher, 'optionalAccess', _163 => _163.close, 'call', _164 => _164()]);
15817
+ _optionalChain([this, 'access', _164 => _164.#statusWatcher, 'optionalAccess', _165 => _165.close, 'call', _166 => _166()]);
15753
15818
  this.#statusWatcher = null;
15754
15819
  }
15755
15820
  /**
@@ -15939,7 +16004,7 @@ var Client = class _Client {
15939
16004
  * caller falls back to probing.
15940
16005
  */
15941
16006
  #delegationHintFor(swap, depositor, hint) {
15942
- const hinted = _optionalChain([swap, 'access', _165 => _165.client_evm_address, 'optionalAccess', _166 => _166.toLowerCase, 'call', _167 => _167()]);
16007
+ const hinted = _optionalChain([swap, 'access', _167 => _167.client_evm_address, 'optionalAccess', _168 => _168.toLowerCase, 'call', _169 => _169()]);
15943
16008
  return hinted && hinted === depositor.toLowerCase() ? hint : void 0;
15944
16009
  }
15945
16010
  async #isKernelDelegated(address2, chainId, serverHint) {
@@ -15953,7 +16018,7 @@ var Client = class _Client {
15953
16018
  );
15954
16019
  }
15955
16020
  if (chainId !== AA_CHAIN_ID) return false;
15956
- const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _168 => _168.#config, 'access', _169 => _169.aa, 'optionalAccess', _170 => _170.rpcUrl]), () => ( _optionalChain([this, 'access', _171 => _171.#config, 'access', _172 => _172.aa, 'optionalAccess', _173 => _173.bundlerUrl])));
16021
+ const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _170 => _170.#config, 'access', _171 => _171.aa, 'optionalAccess', _172 => _172.rpcUrl]), () => ( _optionalChain([this, 'access', _173 => _173.#config, 'access', _174 => _174.aa, 'optionalAccess', _175 => _175.bundlerUrl])));
15957
16022
  if (!rpcUrl) return false;
15958
16023
  const { createPublicClient: createPublicClient2, http: http2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./_esm-4ZKYBBIE-D33574DC.cjs")));
15959
16024
  const publicClient = createPublicClient2({ transport: http2(rpcUrl) });
@@ -15982,7 +16047,7 @@ var Client = class _Client {
15982
16047
  */
15983
16048
  #getClaimEvmSigningKey(storedSwap) {
15984
16049
  const swapKey = storedSwap.secretKey;
15985
- const clientAddress = _optionalChain([storedSwap, 'access', _174 => _174.response, 'access', _175 => _175.client_evm_address, 'optionalAccess', _176 => _176.toLowerCase, 'call', _177 => _177()]);
16050
+ const clientAddress = _optionalChain([storedSwap, 'access', _176 => _176.response, 'access', _177 => _177.client_evm_address, 'optionalAccess', _178 => _178.toLowerCase, 'call', _179 => _179()]);
15986
16051
  if (swapKey && clientAddress && clientAddress === deriveEvmAddress(swapKey).toLowerCase()) {
15987
16052
  return swapKey;
15988
16053
  }
@@ -16005,7 +16070,7 @@ var Client = class _Client {
16005
16070
  const deterministicKey = this.#getEvmSigningKey();
16006
16071
  const deterministicAddress = deriveEvmAddress(deterministicKey);
16007
16072
  const swapAddress = deriveEvmAddress(swapKey);
16008
- const clientAddress = _optionalChain([response, 'access', _178 => _178.client_evm_address, 'optionalAccess', _179 => _179.toLowerCase, 'call', _180 => _180()]);
16073
+ const clientAddress = _optionalChain([response, 'access', _180 => _180.client_evm_address, 'optionalAccess', _181 => _181.toLowerCase, 'call', _182 => _182()]);
16009
16074
  if (clientAddress === deterministicAddress.toLowerCase() || !clientAddress) {
16010
16075
  return deterministicKey;
16011
16076
  }
@@ -16168,7 +16233,7 @@ var Client = class _Client {
16168
16233
  "chain-config",
16169
16234
  () => this.getChainConfig()
16170
16235
  );
16171
- return _optionalChain([config, 'access', _181 => _181.chains, 'access', _182 => _182.find, 'call', _183 => _183((c) => String(c.chain) === String(chainId)), 'optionalAccess', _184 => _184.rif_relay]);
16236
+ return _optionalChain([config, 'access', _183 => _183.chains, 'access', _184 => _184.find, 'call', _185 => _185((c) => String(c.chain) === String(chainId)), 'optionalAccess', _186 => _186.rif_relay]);
16172
16237
  }
16173
16238
  /**
16174
16239
  * The claim address of a native lock on a chain that claims through RIF
@@ -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: _nullishCoalesce(params.referralCode, () => ( this.#config.referralCode))
16336
+ };
16268
16337
  const referralFee = params.referralCode != null || params.extraFees != null ? this.#composeStatic(
16269
16338
  `referral-fee|${_nullishCoalesce(params.referralCode, () => ( ""))}|${_nullishCoalesce(params.extraFees, () => ( ""))}`,
16270
16339
  () => this.getReferralFee({
@@ -16282,8 +16351,8 @@ var Client = class _Client {
16282
16351
  swapPairs,
16283
16352
  networkFees,
16284
16353
  chainConfig,
16285
- referralExtraFeeRate: _optionalChain([referral, 'optionalAccess', _185 => _185.extra_fee_rate]),
16286
- referralBaseFeeRate: _optionalChain([referral, 'optionalAccess', _186 => _186.base_fee_rate]),
16354
+ referralExtraFeeRate: _optionalChain([referral, 'optionalAccess', _187 => _187.extra_fee_rate]),
16355
+ referralBaseFeeRate: _optionalChain([referral, 'optionalAccess', _188 => _188.base_fee_rate]),
16287
16356
  getDexQuote: (p) => this.getDexQuote(p)
16288
16357
  });
16289
16358
  }
@@ -16615,7 +16684,16 @@ var Client = class _Client {
16615
16684
  if (!data) {
16616
16685
  throw new Error("No swap data returned");
16617
16686
  }
16618
- if (_optionalChain([options, 'optionalAccess', _187 => _187.updateStorage]) && this.#swapStorage) {
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
+ }
16696
+ if (_optionalChain([options, 'optionalAccess', _189 => _189.updateStorage]) && this.#swapStorage) {
16619
16697
  const stored = await this.#swapStorage.get(id);
16620
16698
  const changed = stored ? swapTermsChange(stored, data) : void 0;
16621
16699
  if (stored && changed) {
@@ -16949,15 +17027,15 @@ var Client = class _Client {
16949
17027
  message: "Gasless claim failed: no target address found. This swap may have been created before target address storage was implemented."
16950
17028
  };
16951
17029
  }
16952
- const bridgeRecipient = _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _188 => _188.bridgeRecipient]), () => ( storedSwap.bridgeRecipient)), () => ( (isTronBridge ? storedPayoutTarget(storedSwap) : void 0)));
16953
- const bridgeRecipientWallet = _optionalChain([options, 'optionalAccess', _189 => _189.bridgeRecipient]) !== void 0 ? _optionalChain([options, 'optionalAccess', _190 => _190.bridgeRecipientWallet]) : storedSwap.bridgeRecipientWallet;
17030
+ const bridgeRecipient = _nullishCoalesce(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _190 => _190.bridgeRecipient]), () => ( storedSwap.bridgeRecipient)), () => ( (isTronBridge ? storedPayoutTarget(storedSwap) : void 0)));
17031
+ const bridgeRecipientWallet = _optionalChain([options, 'optionalAccess', _191 => _191.bridgeRecipient]) !== void 0 ? _optionalChain([options, 'optionalAccess', _192 => _192.bridgeRecipientWallet]) : storedSwap.bridgeRecipientWallet;
16954
17032
  if (isSolanaBridge && !bridgeRecipient) {
16955
17033
  return {
16956
17034
  success: false,
16957
17035
  message: "Solana bridge claim requires `bridgeRecipient` (the recipient's USDC ATA) in claim options. Derive it via `deriveSolanaUsdcAta` before calling claim."
16958
17036
  };
16959
17037
  }
16960
- const gaslessResult = (swap.evm_chain_id === 30 || swap.evm_chain_id === 31) && _optionalChain([options, 'optionalAccess', _191 => _191.signer]) ? await this.claimEvmWithSigner(id, options.signer, {
17038
+ const gaslessResult = (swap.evm_chain_id === 30 || swap.evm_chain_id === 31) && _optionalChain([options, 'optionalAccess', _193 => _193.signer]) ? await this.claimEvmWithSigner(id, options.signer, {
16961
17039
  bridgeRecipient,
16962
17040
  bridgeRecipientWallet
16963
17041
  }) : await this.claimViaGasless(id, destination, {
@@ -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) {
@@ -17286,7 +17367,7 @@ var Client = class _Client {
17286
17367
  const targetTokenAddress = String(swap.target_token.token_id);
17287
17368
  const needsDexSwap = targetTokenAddress.toLowerCase() !== swap.wbtc_address.toLowerCase();
17288
17369
  let dexCalldata;
17289
- if (needsDexSwap && _optionalChain([responseData, 'optionalAccess', _192 => _192.dex_calldata])) {
17370
+ if (needsDexSwap && _optionalChain([responseData, 'optionalAccess', _194 => _194.dex_calldata])) {
17290
17371
  dexCalldata = {
17291
17372
  to: responseData.dex_calldata.to,
17292
17373
  data: responseData.dex_calldata.data,
@@ -17334,7 +17415,7 @@ var Client = class _Client {
17334
17415
  * ```
17335
17416
  */
17336
17417
  async claimArkade(id, options) {
17337
- if (!_optionalChain([options, 'optionalAccess', _193 => _193.destinationAddress])) {
17418
+ if (!_optionalChain([options, 'optionalAccess', _195 => _195.destinationAddress])) {
17338
17419
  return {
17339
17420
  success: false,
17340
17421
  message: 'Destination address is required for Arkade claims. Provide it via the options parameter: { destinationAddress: "ark1..." }'
@@ -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);
@@ -17425,7 +17501,7 @@ var Client = class _Client {
17425
17501
  electrum,
17426
17502
  fundTxid
17427
17503
  );
17428
- if (_optionalChain([txData, 'optionalAccess', _194 => _194.vout, 'optionalAccess', _195 => _195[fundVout]])) {
17504
+ if (_optionalChain([txData, 'optionalAccess', _196 => _196.vout, 'optionalAccess', _197 => _197[fundVout]])) {
17429
17505
  return {
17430
17506
  txid: fundTxid,
17431
17507
  vout: fundVout,
@@ -17461,7 +17537,7 @@ var Client = class _Client {
17461
17537
  async #findOnchainHtlcOutputEsplora(esploraUrls, address2, fundTxid, fundVout) {
17462
17538
  if (fundTxid && fundVout !== void 0) {
17463
17539
  const txData = await fetchTransactionOutputs(esploraUrls, fundTxid);
17464
- if (_optionalChain([txData, 'optionalAccess', _196 => _196.vout, 'optionalAccess', _197 => _197[fundVout]])) {
17540
+ if (_optionalChain([txData, 'optionalAccess', _198 => _198.vout, 'optionalAccess', _199 => _199[fundVout]])) {
17465
17541
  return {
17466
17542
  txid: fundTxid,
17467
17543
  vout: fundVout,
@@ -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: _optionalChain([options, 'optionalAccess', _200 => _200.destinationAddress]),
17696
+ arkadeServerUrl: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _201 => _201.arkadeServerUrl]), () => ( this.#config.arkadeServerUrl)),
17618
17697
  logger: this.#config.logger,
17619
17698
  logLevel: this.#config.logLevel
17620
17699
  });
@@ -17732,7 +17811,7 @@ var Client = class _Client {
17732
17811
  */
17733
17812
  async #claimArkadeDelegate(swapId, params, options) {
17734
17813
  try {
17735
- const result = await _chunkOJNQCRHUcjs.delegateClaim.call(void 0, {
17814
+ const result = await _chunkQ4TOBBANcjs.delegateClaim.call(void 0, {
17736
17815
  ...params,
17737
17816
  destinationAddress: options.destinationAddress,
17738
17817
  lendaswapApiUrl: this.#config.baseUrl,
@@ -17805,10 +17884,10 @@ var Client = class _Client {
17805
17884
  }
17806
17885
  if (direction === "evm_to_arkade" || direction === "evm_to_bitcoin" || direction === "evm_to_lightning") {
17807
17886
  const evmOptions = options;
17808
- if (_optionalChain([evmOptions, 'optionalAccess', _198 => _198.collaborative])) {
17887
+ if (_optionalChain([evmOptions, 'optionalAccess', _202 => _202.collaborative])) {
17809
17888
  return this.#collabRefundEvm(id);
17810
17889
  }
17811
- return this.#buildEvmSourceRefund(id, storedSwap, _optionalChain([evmOptions, 'optionalAccess', _199 => _199.signer]));
17890
+ return this.#buildEvmSourceRefund(id, storedSwap, _optionalChain([evmOptions, 'optionalAccess', _203 => _203.signer]));
17812
17891
  }
17813
17892
  return {
17814
17893
  success: false,
@@ -17902,7 +17981,7 @@ var Client = class _Client {
17902
17981
  }
17903
17982
  const btcFundTxid = swap.btc_fund_txid;
17904
17983
  const btcFundVout = swap.btc_fund_vout;
17905
- const waitForFundingMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _200 => _200.waitForFundingMs]), () => ( 3e4));
17984
+ const waitForFundingMs = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _204 => _204.waitForFundingMs]), () => ( 3e4));
17906
17985
  const htlcOutput = await this.#waitForOnchainHtlcOutput(
17907
17986
  esploraUrls,
17908
17987
  network,
@@ -17917,14 +17996,14 @@ var Client = class _Client {
17917
17996
  message: `Could not find UTXO at HTLC address ${btcHtlcAddress} after waiting ${waitForFundingMs}ms. The server may not have funded the HTLC yet.`
17918
17997
  };
17919
17998
  }
17920
- const destinationAddress = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _201 => _201.destinationAddress]), () => ( storedPayoutTarget(storedSwap)));
17999
+ const destinationAddress = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _205 => _205.destinationAddress]), () => ( storedPayoutTarget(storedSwap)));
17921
18000
  if (!destinationAddress) {
17922
18001
  return {
17923
18002
  success: false,
17924
18003
  message: 'Destination address is required to claim BTC. Provide it via options: { destinationAddress: "bc1p..." }'
17925
18004
  };
17926
18005
  }
17927
- const feeRateSatPerVb = await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _202 => _202.feeRateSatPerVb]), async () => ( Math.max(2, await _asyncNullishCoalesce(await fetchFeeRateEstimate(esploraUrls, 2), async () => ( 0)))));
18006
+ const feeRateSatPerVb = await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _206 => _206.feeRateSatPerVb]), async () => ( Math.max(2, await _asyncNullishCoalesce(await fetchFeeRateEstimate(esploraUrls, 2), async () => ( 0)))));
17928
18007
  try {
17929
18008
  const result = buildOnchainClaimTransaction({
17930
18009
  fundingTxId: htlcOutput.txid,
@@ -17946,7 +18025,7 @@ var Client = class _Client {
17946
18025
  esploraUrls,
17947
18026
  network,
17948
18027
  result.txHex,
17949
- _nullishCoalesce(_optionalChain([options, 'optionalAccess', _203 => _203.broadcastRetries]), () => ( 5))
18028
+ _nullishCoalesce(_optionalChain([options, 'optionalAccess', _207 => _207.broadcastRetries]), () => ( 5))
17950
18029
  );
17951
18030
  return {
17952
18031
  success: true,
@@ -17976,7 +18055,7 @@ var Client = class _Client {
17976
18055
  * @internal
17977
18056
  */
17978
18057
  async #buildOnchainRefund(id, swap, options) {
17979
- if (!_optionalChain([options, 'optionalAccess', _204 => _204.destinationAddress])) {
18058
+ if (!_optionalChain([options, 'optionalAccess', _208 => _208.destinationAddress])) {
17980
18059
  return {
17981
18060
  success: false,
17982
18061
  message: 'Destination address is required for on-chain refunds. Provide it via the options parameter: { destinationAddress: "bc1q..." }'
@@ -18182,7 +18261,7 @@ network='${network}'`
18182
18261
  * @internal
18183
18262
  */
18184
18263
  async #buildArkadeRefund(id, swap, options) {
18185
- if (!_optionalChain([options, 'optionalAccess', _205 => _205.destinationAddress])) {
18264
+ if (!_optionalChain([options, 'optionalAccess', _209 => _209.destinationAddress])) {
18186
18265
  return {
18187
18266
  success: false,
18188
18267
  message: 'Destination address is required for Arkade refunds. Provide it via the options parameter: { destinationAddress: "ark1..." }'
@@ -18323,7 +18402,7 @@ network='${network}'`
18323
18402
  */
18324
18403
  async #refundArkadeDelegate(params, options) {
18325
18404
  try {
18326
- const result = await _chunkOJNQCRHUcjs.delegateRefund.call(void 0, {
18405
+ const result = await _chunkQ4TOBBANcjs.delegateRefund.call(void 0, {
18327
18406
  ...params,
18328
18407
  lendaswapApiUrl: this.#config.baseUrl,
18329
18408
  arkadeServerUrl: _nullishCoalesce(options.arkadeServerUrl, () => ( this.#config.arkadeServerUrl)),
@@ -18418,7 +18497,7 @@ network='${network}'`
18418
18497
  const call = decodeRefundCall(server.data);
18419
18498
  const to = server.to.toLowerCase();
18420
18499
  const htlc = leg.htlcAddress.toLowerCase();
18421
- const coordinator = _optionalChain([leg, 'access', _206 => _206.coordinatorAddress, 'optionalAccess', _207 => _207.toLowerCase, 'call', _208 => _208()]);
18500
+ const coordinator = _optionalChain([leg, 'access', _210 => _210.coordinatorAddress, 'optionalAccess', _211 => _211.toLowerCase, 'call', _212 => _212()]);
18422
18501
  const signer = check.signer;
18423
18502
  let lockSender;
18424
18503
  let recipient;
@@ -18439,7 +18518,7 @@ network='${network}'`
18439
18518
  `The server's refund targets ${server.to}, not this swap's HTLC ${leg.htlcAddress}`
18440
18519
  );
18441
18520
  }
18442
- lockSender = _optionalChain([signer, 'optionalAccess', _209 => _209.address, 'access', _210 => _210.toLowerCase, 'call', _211 => _211()]);
18521
+ lockSender = _optionalChain([signer, 'optionalAccess', _213 => _213.address, 'access', _214 => _214.toLowerCase, 'call', _215 => _215()]);
18443
18522
  recipient = lockSender;
18444
18523
  break;
18445
18524
  case "refundTo":
@@ -18484,7 +18563,7 @@ network='${network}'`
18484
18563
  timelock: call.timelock
18485
18564
  };
18486
18565
  const active = await read(
18487
- _chunk7GOXIT24cjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms),
18566
+ _chunkJZTF4JNHcjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms),
18488
18567
  "isActive"
18489
18568
  );
18490
18569
  if (active === 0n) {
@@ -18494,7 +18573,7 @@ network='${network}'`
18494
18573
  }
18495
18574
  if (call.kind === "refundTo" || call.kind === "nativeRefundTo") {
18496
18575
  const deposit = await read(
18497
- _chunk7GOXIT24cjs.encodeDepositsCallData.call(void 0, to, _chunk7GOXIT24cjs.htlcSwapKey.call(void 0, terms)),
18576
+ _chunkJZTF4JNHcjs.encodeDepositsCallData.call(void 0, to, _chunkJZTF4JNHcjs.htlcSwapKey.call(void 0, terms)),
18498
18577
  "deposits"
18499
18578
  );
18500
18579
  if (deposit !== void 0) {
@@ -18535,10 +18614,10 @@ network='${network}'`
18535
18614
  `Swap ${swapId} has no payment hash recorded by this client at creation (it was recovered, or created by an older SDK), so the server's hash lock cannot be checked; refusing to fund or move it. Refund it instead.`
18536
18615
  );
18537
18616
  }
18538
- return `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, stored.lightningPaymentHash.hash)}`;
18617
+ return `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, stored.lightningPaymentHash.hash)}`;
18539
18618
  }
18540
18619
  if (direction === "evm_to_bitcoin" || direction === "evm_to_arkade") {
18541
- return `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, stored.preimageHash)}`;
18620
+ return `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, stored.preimageHash)}`;
18542
18621
  }
18543
18622
  throw new Error(`Swap ${swapId} is ${direction}, not EVM-sourced`);
18544
18623
  }
@@ -18558,7 +18637,7 @@ network='${network}'`
18558
18637
  }
18559
18638
  #fundingExpectation(swapId, stored) {
18560
18639
  const hashLock = this.#clientHashLock(swapId, stored);
18561
- const terms = _optionalChain([stored, 'optionalAccess', _212 => _212.evmFundingTerms]);
18640
+ const terms = _optionalChain([stored, 'optionalAccess', _216 => _216.evmFundingTerms]);
18562
18641
  if (!terms) {
18563
18642
  throw new Error(
18564
18643
  `Swap ${swapId} has no funding terms recorded by this client at creation (it was recovered, or created by an older SDK), so the server's funding payload cannot be checked; refusing to fund it. Refund it instead.`
@@ -18585,7 +18664,7 @@ network='${network}'`
18585
18664
  `Swap ${swapId} locks on chain ${terms.chainId}, not ${chainId}`
18586
18665
  );
18587
18666
  }
18588
- return _chunk7GOXIT24cjs.checkFundingPayload.call(void 0, terms, hashLock, payload, pins);
18667
+ return _chunkJZTF4JNHcjs.checkFundingPayload.call(void 0, terms, hashLock, payload, pins);
18589
18668
  }
18590
18669
  /** Throws unless `hash` is the one {@link #clientHashLock} fixed. */
18591
18670
  async #ensureClientHashLock(swapId, hash, what) {
@@ -18593,7 +18672,7 @@ network='${network}'`
18593
18672
  swapId,
18594
18673
  await this.getStoredSwap(swapId)
18595
18674
  );
18596
- if (`0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, hash)}` !== expected) {
18675
+ if (`0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, hash)}` !== expected) {
18597
18676
  throw new Error(
18598
18677
  `The server's ${what} locks under hash ${hash}, not this swap's ${expected}; refusing to sign or send it`
18599
18678
  );
@@ -18631,7 +18710,7 @@ network='${network}'`
18631
18710
  if (!this.#swapStorage) return;
18632
18711
  try {
18633
18712
  const stored = await this.#swapStorage.get(swapId);
18634
- if (_optionalChain([stored, 'optionalAccess', _213 => _213.evmFundTxid, 'optionalAccess', _214 => _214.toLowerCase, 'call', _215 => _215()]) !== txid.toLowerCase()) return;
18713
+ if (_optionalChain([stored, 'optionalAccess', _217 => _217.evmFundTxid, 'optionalAccess', _218 => _218.toLowerCase, 'call', _219 => _219()]) !== txid.toLowerCase()) return;
18635
18714
  await this.#swapStorage.store({
18636
18715
  ...stored,
18637
18716
  evmFundTxid: void 0,
@@ -18656,7 +18735,7 @@ network='${network}'`
18656
18735
  * `hint` is appended to the error when neither is.
18657
18736
  */
18658
18737
  #depositorOwnerSigner(swapResponse, walletSigner, hint) {
18659
- const depositor = _optionalChain([swapResponse, 'access', _216 => _216.client_evm_address, 'optionalAccess', _217 => _217.toLowerCase, 'call', _218 => _218()]);
18738
+ const depositor = _optionalChain([swapResponse, 'access', _220 => _220.client_evm_address, 'optionalAccess', _221 => _221.toLowerCase, 'call', _222 => _222()]);
18660
18739
  if (depositor === this.getEvmAddress().toLowerCase()) {
18661
18740
  return this.#keyOwnerSigner();
18662
18741
  }
@@ -18728,7 +18807,7 @@ network='${network}'`
18728
18807
  stored.secretKey ? deriveEvmAddress(stored.secretKey) : void 0
18729
18808
  ]);
18730
18809
  const expectedDepositors = uniqueAddresses([
18731
- _optionalChain([signer, 'optionalAccess', _219 => _219.address]),
18810
+ _optionalChain([signer, 'optionalAccess', _223 => _223.address]),
18732
18811
  ...sdkAddresses,
18733
18812
  stored.response.client_evm_address
18734
18813
  ]);
@@ -18754,7 +18833,7 @@ network='${network}'`
18754
18833
  expectedDepositors
18755
18834
  });
18756
18835
  const coordinatorProved = !leg.depositorIsSender && refund.sender !== signer.address.toLowerCase() && stored.evmCoordinatorAddress === void 0;
18757
- if (fundTxid.toLowerCase() !== _optionalChain([stored, 'access', _220 => _220.evmFundTxid, 'optionalAccess', _221 => _221.toLowerCase, 'call', _222 => _222()]) || coordinatorProved) {
18836
+ if (fundTxid.toLowerCase() !== _optionalChain([stored, 'access', _224 => _224.evmFundTxid, 'optionalAccess', _225 => _225.toLowerCase, 'call', _226 => _226()]) || coordinatorProved) {
18758
18837
  await this.#recordEvmFunding(id, {
18759
18838
  txid: fundTxid,
18760
18839
  coordinatorAddress: coordinatorProved ? refund.sender : void 0
@@ -18813,7 +18892,7 @@ network='${network}'`
18813
18892
  async #serverFundTxid(id) {
18814
18893
  const fresh = await this.getSwap(id);
18815
18894
  try {
18816
- await _optionalChain([this, 'access', _223 => _223.#swapStorage, 'optionalAccess', _224 => _224.update, 'call', _225 => _225(id, fresh)]);
18895
+ await _optionalChain([this, 'access', _227 => _227.#swapStorage, 'optionalAccess', _228 => _228.update, 'call', _229 => _229(id, fresh)]);
18817
18896
  } catch (error) {
18818
18897
  this.#logger.warn({
18819
18898
  event: "client.refundSwap.refreshNotStored",
@@ -18826,7 +18905,7 @@ network='${network}'`
18826
18905
  }
18827
18906
  async #refundFromFundingTx(signer, leg) {
18828
18907
  const self2 = signer.address.toLowerCase();
18829
- const coordinator = _optionalChain([leg, 'access', _226 => _226.coordinatorAddress, 'optionalAccess', _227 => _227.toLowerCase, 'call', _228 => _228()]);
18908
+ const coordinator = _optionalChain([leg, 'access', _230 => _230.coordinatorAddress, 'optionalAccess', _231 => _231.toLowerCase, 'call', _232 => _232()]);
18830
18909
  const senders = leg.depositorIsSender ? uniqueAddresses([self2, ...leg.expectedDepositors]) : coordinator === void 0 ? void 0 : [self2, coordinator];
18831
18910
  const { created, terms, hashLock } = await this.#lockFromFundingTx(signer, {
18832
18911
  ...leg,
@@ -18834,14 +18913,14 @@ network='${network}'`
18834
18913
  });
18835
18914
  const active = decodeCallWord(
18836
18915
  await signer.call(
18837
- _chunk7GOXIT24cjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms)
18916
+ _chunkJZTF4JNHcjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms)
18838
18917
  ),
18839
18918
  "isActive"
18840
18919
  );
18841
18920
  if (active === 0n) {
18842
18921
  await this.#ensureSettled(signer, leg.htlcAddress, terms);
18843
18922
  }
18844
- const native = created.token === _chunk7GOXIT24cjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
18923
+ const native = created.token === _chunkJZTF4JNHcjs.NATIVE_TOKEN_ADDRESS.toLowerCase();
18845
18924
  if (leg.depositorIsSender) {
18846
18925
  const { to: to2, data: data2 } = encodeRefundCall(leg.htlcAddress, {
18847
18926
  kind: native ? "nativeRefundFor" : "refundFor",
@@ -18870,7 +18949,7 @@ network='${network}'`
18870
18949
  if (!ownHtlc) {
18871
18950
  const deposit = decodeCallWord(
18872
18951
  await signer.call(
18873
- _chunk7GOXIT24cjs.encodeDepositsCallData.call(void 0, created.refundAddress, created.key)
18952
+ _chunkJZTF4JNHcjs.encodeDepositsCallData.call(void 0, created.refundAddress, created.key)
18874
18953
  ),
18875
18954
  "deposits"
18876
18955
  );
@@ -18887,7 +18966,7 @@ network='${network}'`
18887
18966
  }
18888
18967
  recipient = depositor;
18889
18968
  }
18890
- const { to, data } = ownHtlc ? native ? _chunk7GOXIT24cjs.encodeHtlcNativeRefundCallData.call(void 0, leg.htlcAddress, terms) : _chunk7GOXIT24cjs.encodeHtlcErc20RefundCallData.call(void 0, leg.htlcAddress, terms) : native ? _chunk7GOXIT24cjs.encodeNativeRefundTo.call(void 0, created.refundAddress, terms) : _chunk7GOXIT24cjs.encodeRefundTo.call(void 0, created.refundAddress, terms);
18969
+ const { to, data } = ownHtlc ? native ? _chunkJZTF4JNHcjs.encodeHtlcNativeRefundCallData.call(void 0, leg.htlcAddress, terms) : _chunkJZTF4JNHcjs.encodeHtlcErc20RefundCallData.call(void 0, leg.htlcAddress, terms) : native ? _chunkJZTF4JNHcjs.encodeNativeRefundTo.call(void 0, created.refundAddress, terms) : _chunkJZTF4JNHcjs.encodeRefundTo.call(void 0, created.refundAddress, terms);
18891
18970
  return {
18892
18971
  to,
18893
18972
  data,
@@ -18934,8 +19013,8 @@ network='${network}'`
18934
19013
  "Reading the lock from the chain needs the funding receipt's logs, which this signer's waitForReceipt does not return"
18935
19014
  );
18936
19015
  }
18937
- const hashLock = `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, leg.hashLock)}`;
18938
- const matches = _chunk7GOXIT24cjs.findSwapCreated.call(void 0, receipt.logs, {
19016
+ const hashLock = `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, leg.hashLock)}`;
19017
+ const matches = _chunkJZTF4JNHcjs.findSwapCreated.call(void 0, receipt.logs, {
18939
19018
  htlcAddress: leg.htlcAddress,
18940
19019
  hashLock,
18941
19020
  claimAddress: leg.claimAddress,
@@ -18968,13 +19047,13 @@ network='${network}'`
18968
19047
  */
18969
19048
  async #ensureSettled(signer, htlcAddress2, terms) {
18970
19049
  const state = await this.#swapState(signer, htlcAddress2, terms.key);
18971
- if (state === void 0 || state === _chunk7GOXIT24cjs.HTLC_SWAP_STATE.Redeemed || state === _chunk7GOXIT24cjs.HTLC_SWAP_STATE.Refunded) {
19050
+ if (state === void 0 || state === _chunkJZTF4JNHcjs.HTLC_SWAP_STATE.Redeemed || state === _chunkJZTF4JNHcjs.HTLC_SWAP_STATE.Refunded) {
18972
19051
  throw new HtlcNotActiveError(
18973
19052
  `The HTLC for hash lock ${terms.preimageHash} on ${htlcAddress2} is no longer active; it was already redeemed or refunded`
18974
19053
  );
18975
19054
  }
18976
19055
  throw new Error(
18977
- state === _chunk7GOXIT24cjs.HTLC_SWAP_STATE.Rehashed ? `The HTLC for hash lock ${terms.preimageHash} on ${htlcAddress2} was rehashed to terms this client has no record of` : `No HTLC is open under hash lock ${terms.preimageHash} and timelock ${terms.timelock} on ${htlcAddress2}; this client's record of the lock is stale`
19056
+ state === _chunkJZTF4JNHcjs.HTLC_SWAP_STATE.Rehashed ? `The HTLC for hash lock ${terms.preimageHash} on ${htlcAddress2} was rehashed to terms this client has no record of` : `No HTLC is open under hash lock ${terms.preimageHash} and timelock ${terms.timelock} on ${htlcAddress2}; this client's record of the lock is stale`
18978
19057
  );
18979
19058
  }
18980
19059
  /**
@@ -18984,7 +19063,7 @@ network='${network}'`
18984
19063
  async #swapState(signer, htlcAddress2, key) {
18985
19064
  try {
18986
19065
  return decodeCallWord(
18987
- await signer.call(_chunk7GOXIT24cjs.encodeHtlcSwapsCallData.call(void 0, htlcAddress2, key)),
19066
+ await signer.call(_chunkJZTF4JNHcjs.encodeHtlcSwapsCallData.call(void 0, htlcAddress2, key)),
18988
19067
  "swaps"
18989
19068
  );
18990
19069
  } catch (e23) {
@@ -19019,12 +19098,12 @@ network='${network}'`
19019
19098
  `Rehash tx ${txid} has no readable logs, so the lock's current terms cannot be verified from the chain`
19020
19099
  );
19021
19100
  }
19022
- const moved = _chunk7GOXIT24cjs.findSwapRehashed.call(void 0, receipt.logs, {
19101
+ const moved = _chunkJZTF4JNHcjs.findSwapRehashed.call(void 0, receipt.logs, {
19023
19102
  htlcAddress: htlcAddress2,
19024
19103
  key: terms.key
19025
19104
  });
19026
19105
  if (moved.length === 0) continue;
19027
- const hashLock = `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, rehash.hashLock)}`;
19106
+ const hashLock = `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, rehash.hashLock)}`;
19028
19107
  if (moved.length !== 1 || moved[0].newPreimageHash !== hashLock) {
19029
19108
  throw new Error(
19030
19109
  `Rehash tx ${txid} moved the HTLC for hash lock ${terms.preimageHash} elsewhere than the recorded ${hashLock}`
@@ -19148,8 +19227,8 @@ network='${network}'`
19148
19227
  callsHash: params.callsHash,
19149
19228
  coordinatorVersion: params.coordinatorVersion
19150
19229
  };
19151
- const typedData = _chunk7GOXIT24cjs.buildCollabRefundEvmTypedData.call(void 0, digestParams);
19152
- const digest = _chunk7GOXIT24cjs.buildCollabRefundEvmDigest.call(void 0, digestParams);
19230
+ const typedData = _chunkJZTF4JNHcjs.buildCollabRefundEvmTypedData.call(void 0, digestParams);
19231
+ const digest = _chunkJZTF4JNHcjs.buildCollabRefundEvmDigest.call(void 0, digestParams);
19153
19232
  return { typedData, digest, params };
19154
19233
  }
19155
19234
  /**
@@ -19164,7 +19243,7 @@ network='${network}'`
19164
19243
  */
19165
19244
  async collabRefundEvmSwap(swapId) {
19166
19245
  const storedSwap = await this.getStoredSwap(swapId);
19167
- if (!_optionalChain([storedSwap, 'optionalAccess', _229 => _229.secretKey])) {
19246
+ if (!_optionalChain([storedSwap, 'optionalAccess', _233 => _233.secretKey])) {
19168
19247
  throw new Error(
19169
19248
  "No secret key found for this swap. Cannot sign collab refund."
19170
19249
  );
@@ -19323,11 +19402,11 @@ network='${network}'`
19323
19402
  } else {
19324
19403
  userOpHash = await client.sendUserOperation({ calls });
19325
19404
  }
19326
- await _optionalChain([hooks, 'access', _230 => _230.onSubmitted, 'optionalCall', _231 => _231(userOpHash)]);
19405
+ await _optionalChain([hooks, 'access', _234 => _234.onSubmitted, 'optionalCall', _235 => _235(userOpHash)]);
19327
19406
  const { receipt, success, reason } = await client.waitForUserOperationReceipt({
19328
19407
  hash: userOpHash
19329
19408
  });
19330
- await _optionalChain([hooks, 'access', _232 => _232.onIncluded, 'optionalCall', _233 => _233(receipt.transactionHash, userOpHash)]);
19409
+ await _optionalChain([hooks, 'access', _236 => _236.onIncluded, 'optionalCall', _237 => _237(receipt.transactionHash, userOpHash)]);
19331
19410
  if (!success) {
19332
19411
  throw new Error(
19333
19412
  `Sponsored UserOp ${userOpHash} reverted on-chain${reason ? `: ${reason}` : ""}`
@@ -19548,7 +19627,7 @@ network='${network}'`
19548
19627
  * no AA config, not included, or the bundler cannot be reached).
19549
19628
  */
19550
19629
  async #pendingRehashTx(rehash) {
19551
- const bundlerUrl = _optionalChain([this, 'access', _234 => _234.#config, 'access', _235 => _235.aa, 'optionalAccess', _236 => _236.bundlerUrl]);
19630
+ const bundlerUrl = _optionalChain([this, 'access', _238 => _238.#config, 'access', _239 => _239.aa, 'optionalAccess', _240 => _240.bundlerUrl]);
19552
19631
  if (!rehash.userOpHash || !bundlerUrl) return void 0;
19553
19632
  try {
19554
19633
  const response = await fetch(bundlerUrl, {
@@ -19562,7 +19641,7 @@ network='${network}'`
19562
19641
  })
19563
19642
  });
19564
19643
  const json = await response.json();
19565
- return _nullishCoalesce(_optionalChain([json, 'access', _237 => _237.result, 'optionalAccess', _238 => _238.receipt, 'optionalAccess', _239 => _239.transactionHash]), () => ( void 0));
19644
+ return _nullishCoalesce(_optionalChain([json, 'access', _241 => _241.result, 'optionalAccess', _242 => _242.receipt, 'optionalAccess', _243 => _243.transactionHash]), () => ( void 0));
19566
19645
  } catch (e25) {
19567
19646
  return void 0;
19568
19647
  }
@@ -19572,7 +19651,7 @@ network='${network}'`
19572
19651
  if (!this.#swapStorage) return;
19573
19652
  try {
19574
19653
  const stored = await this.#swapStorage.get(swapId);
19575
- const history = _optionalChain([stored, 'optionalAccess', _240 => _240.evmRehashes]);
19654
+ const history = _optionalChain([stored, 'optionalAccess', _244 => _244.evmRehashes]);
19576
19655
  if (!stored || !history) return;
19577
19656
  let index = -1;
19578
19657
  for (let i = history.length - 1; i >= 0; i--) {
@@ -19623,8 +19702,8 @@ network='${network}'`
19623
19702
  }
19624
19703
  const ownHash = this.#clientHashLock(swapId, stored);
19625
19704
  const leg = evmSourceLeg(stored);
19626
- const firstFrom = _optionalChain([leg, 'access', _241 => _241.rehashes, 'optionalAccess', _242 => _242[0], 'optionalAccess', _243 => _243.fromHashLock]);
19627
- if (firstFrom !== void 0 && `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, firstFrom)}` !== ownHash) {
19705
+ const firstFrom = _optionalChain([leg, 'access', _245 => _245.rehashes, 'optionalAccess', _246 => _246[0], 'optionalAccess', _247 => _247.fromHashLock]);
19706
+ if (firstFrom !== void 0 && `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, firstFrom)}` !== ownHash) {
19628
19707
  throw new Error(
19629
19708
  `The rehash history of swap ${swapId} starts from ${firstFrom}, not from the payment hash this client fixed (${ownHash})`
19630
19709
  );
@@ -19649,7 +19728,7 @@ network='${network}'`
19649
19728
  });
19650
19729
  const active = decodeCallWord(
19651
19730
  await reader.call(
19652
- _chunk7GOXIT24cjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms)
19731
+ _chunkJZTF4JNHcjs.encodeHtlcErc20IsActiveCallData.call(void 0, leg.htlcAddress, terms)
19653
19732
  ),
19654
19733
  "isActive"
19655
19734
  );
@@ -19682,7 +19761,7 @@ network='${network}'`
19682
19761
  * does not read the chain. Arbitrum only, like the paymaster.
19683
19762
  */
19684
19763
  async #aaChainReader(owner) {
19685
- const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _244 => _244.#config, 'access', _245 => _245.aa, 'optionalAccess', _246 => _246.rpcUrl]), () => ( _optionalChain([this, 'access', _247 => _247.#config, 'access', _248 => _248.aa, 'optionalAccess', _249 => _249.bundlerUrl])));
19764
+ const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _248 => _248.#config, 'access', _249 => _249.aa, 'optionalAccess', _250 => _250.rpcUrl]), () => ( _optionalChain([this, 'access', _251 => _251.#config, 'access', _252 => _252.aa, 'optionalAccess', _253 => _253.bundlerUrl])));
19686
19765
  if (!rpcUrl) {
19687
19766
  throw new Error(
19688
19767
  "A sponsored rehash reads the lock over the AA RPC; call `.withAa({ bundlerUrl, paymasterPolicyId })` on the ClientBuilder before `.build()`."
@@ -19733,7 +19812,7 @@ network='${network}'`
19733
19812
  */
19734
19813
  async retrySwapWithInvoice(swapId, invoice) {
19735
19814
  const storedSwap = await this.getStoredSwap(swapId);
19736
- if (!_optionalChain([storedSwap, 'optionalAccess', _250 => _250.secretKey])) {
19815
+ if (!_optionalChain([storedSwap, 'optionalAccess', _254 => _254.secretKey])) {
19737
19816
  throw new Error(
19738
19817
  "No secret key found for this swap. Cannot authorize the rehash."
19739
19818
  );
@@ -19766,8 +19845,8 @@ network='${network}'`
19766
19845
  });
19767
19846
  ensureRehashMatchesRequest(signature, paymentHash, params);
19768
19847
  ensureLockIsOwn(lock, signature, "The server signed a rehash of");
19769
- const newHash = `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, signature.newPreimageHash)}`;
19770
- const isThisPending = (entry) => entry.txid === "" && entry.userOpHash === void 0 && `0x${_chunk7GOXIT24cjs.normalizeBytes32.call(void 0, entry.hashLock)}` === newHash;
19848
+ const newHash = `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, signature.newPreimageHash)}`;
19849
+ const isThisPending = (entry) => entry.txid === "" && entry.userOpHash === void 0 && `0x${_chunkJZTF4JNHcjs.normalizeBytes32.call(void 0, entry.hashLock)}` === newHash;
19771
19850
  await this.#recordEvmRehash(swapId, signature, "");
19772
19851
  let sending = false;
19773
19852
  let signedHash;
@@ -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) => {
@@ -19884,22 +19964,23 @@ network='${network}'`
19884
19964
  updatedAt: Date.now(),
19885
19965
  // The payout this client asked for; claims pay here, never to a
19886
19966
  // server answer. Recovery rebuilding the swap keeps it.
19887
- targetAddress: _nullishCoalesce(targetAddress, () => ( _optionalChain([existing, 'optionalAccess', _251 => _251.targetAddress]))),
19888
- bridgeRecipient: _optionalChain([bridge, 'optionalAccess', _252 => _252.recipient]),
19889
- bridgeRecipientWallet: _optionalChain([bridge, 'optionalAccess', _253 => _253.recipientWallet]),
19890
- evmFundTxid: _optionalChain([existing, 'optionalAccess', _254 => _254.evmFundTxid]),
19967
+ targetAddress: _nullishCoalesce(targetAddress, () => ( _optionalChain([existing, 'optionalAccess', _255 => _255.targetAddress]))),
19968
+ bridgeRecipient: _optionalChain([bridge, 'optionalAccess', _256 => _256.recipient]),
19969
+ bridgeRecipientWallet: _optionalChain([bridge, 'optionalAccess', _257 => _257.recipientWallet]),
19970
+ evmFundTxid: _optionalChain([existing, 'optionalAccess', _258 => _258.evmFundTxid]),
19971
+ evmFundingUserOpHash: _optionalChain([existing, 'optionalAccess', _259 => _259.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
- lightningPaymentHash: _nullishCoalesce(_optionalChain([commitments, 'optionalAccess', _255 => _255.lightningPaymentHash]), () => ( _optionalChain([existing, 'optionalAccess', _256 => _256.lightningPaymentHash]))),
19894
- evmFundingTerms: _nullishCoalesce(_optionalChain([commitments, 'optionalAccess', _257 => _257.evmFundingTerms]), () => ( _optionalChain([existing, 'optionalAccess', _258 => _258.evmFundingTerms]))),
19895
- evmCoordinatorAddress: _optionalChain([existing, 'optionalAccess', _259 => _259.evmCoordinatorAddress]),
19974
+ lightningPaymentHash: _nullishCoalesce(_optionalChain([commitments, 'optionalAccess', _260 => _260.lightningPaymentHash]), () => ( _optionalChain([existing, 'optionalAccess', _261 => _261.lightningPaymentHash]))),
19975
+ evmFundingTerms: _nullishCoalesce(_optionalChain([commitments, 'optionalAccess', _262 => _262.evmFundingTerms]), () => ( _optionalChain([existing, 'optionalAccess', _263 => _263.evmFundingTerms]))),
19976
+ evmCoordinatorAddress: _optionalChain([existing, 'optionalAccess', _264 => _264.evmCoordinatorAddress]),
19896
19977
  // The rehashes this client sent are what let a refund find the lock
19897
19978
  // that exists; the server's copy names only the current hash.
19898
- evmRehashes: _optionalChain([existing, 'optionalAccess', _260 => _260.evmRehashes]),
19979
+ evmRehashes: _optionalChain([existing, 'optionalAccess', _265 => _265.evmRehashes]),
19899
19980
  // A CCTP-inbound burn is the only way to resume or recover once the
19900
19981
  // USDC has left the source chain.
19901
- cctpBurnTxid: _optionalChain([existing, 'optionalAccess', _261 => _261.cctpBurnTxid]),
19902
- cctpBurnLastValidBlockHeight: _optionalChain([existing, 'optionalAccess', _262 => _262.cctpBurnLastValidBlockHeight])
19982
+ cctpBurnTxid: _optionalChain([existing, 'optionalAccess', _266 => _266.cctpBurnTxid]),
19983
+ cctpBurnLastValidBlockHeight: _optionalChain([existing, 'optionalAccess', _267 => _267.cctpBurnLastValidBlockHeight])
19903
19984
  };
19904
19985
  await this.#swapStorage.store(storedSwap);
19905
19986
  }
@@ -19941,7 +20022,7 @@ network='${network}'`
19941
20022
  const targetAsset = "token_id" in tgt ? { chain: tgt.chain, token_id: tgt.token_id } : { chain: tgt.chain, token_id: tgt.tokenId };
19942
20023
  if (isTronToken(sourceAsset.chain))
19943
20024
  throw new Error("Tron is a payout-only destination");
19944
- const isTronTarget = isTronToken(targetAsset.chain) || _optionalChain([options, 'access', _263 => _263.bridgeParams, 'optionalAccess', _264 => _264.targetChain]) === "Tron";
20025
+ const isTronTarget = isTronToken(targetAsset.chain) || _optionalChain([options, 'access', _268 => _268.bridgeParams, 'optionalAccess', _269 => _269.targetChain]) === "Tron";
19945
20026
  if (isTronTarget) {
19946
20027
  if (isTronToken(targetAsset.chain) && targetAsset.token_id !== USDT0_ADDRESSES.Tron) {
19947
20028
  throw new Error("Tron payouts require native USDT");
@@ -19981,7 +20062,7 @@ network='${network}'`
19981
20062
  if (isTronTarget && bridgeParams) {
19982
20063
  bridgeParams = { ...bridgeParams, recipient: options.targetAddress };
19983
20064
  }
19984
- const cctpPayout = !options.bridgeParams && bridgeParams != null && _optionalChain([bridgeParams, 'access', _265 => _265.targetTokenAddress, 'optionalAccess', _266 => _266.toLowerCase, 'call', _267 => _267()]) === _optionalChain([_chunkTKFOVRJRcjs.USDC_ADDRESSES, 'access', _268 => _268[bridgeParams.targetChain], 'optionalAccess', _269 => _269.toLowerCase, 'call', _270 => _270()]);
20065
+ const cctpPayout = !options.bridgeParams && bridgeParams != null && _optionalChain([bridgeParams, 'access', _270 => _270.targetTokenAddress, 'optionalAccess', _271 => _271.toLowerCase, 'call', _272 => _272()]) === _optionalChain([_chunkTKFOVRJRcjs.USDC_ADDRESSES, 'access', _273 => _273[bridgeParams.targetChain], 'optionalAccess', _274 => _274.toLowerCase, 'call', _275 => _275()]);
19985
20066
  if (cctpPayout && options.sourceAmount != null) {
19986
20067
  const quote = await this.getQuote({
19987
20068
  sourceChain: sourceAsset.chain,
@@ -19995,7 +20076,7 @@ network='${network}'`
19995
20076
  });
19996
20077
  if (BigInt(quote.net_target_amount) <= 0n) {
19997
20078
  throw new Error(
19998
- `Amount too small to bridge to ${_optionalChain([bridgeParams, 'optionalAccess', _271 => _271.targetChain])}: the CCTP fee (${_nullishCoalesce(quote.bridge_fee, () => ( "unknown"))} USDC units) leaves nothing to deliver. Increase the amount.`
20079
+ `Amount too small to bridge to ${_optionalChain([bridgeParams, 'optionalAccess', _276 => _276.targetChain])}: the CCTP fee (${_nullishCoalesce(quote.bridge_fee, () => ( "unknown"))} USDC units) leaves nothing to deliver. Increase the amount.`
19999
20080
  );
20000
20081
  }
20001
20082
  }
@@ -20619,7 +20700,7 @@ network='${network}'`
20619
20700
  swapId,
20620
20701
  serverData,
20621
20702
  chainId,
20622
- _optionalChain([options, 'optionalAccess', _272 => _272.funding])
20703
+ _optionalChain([options, 'optionalAccess', _277 => _277.funding])
20623
20704
  );
20624
20705
  const nonceBytes = new Uint8Array(32);
20625
20706
  crypto.getRandomValues(nonceBytes);
@@ -20630,7 +20711,7 @@ network='${network}'`
20630
20711
  const sourceAmount = checked.sourceAmount;
20631
20712
  const evmKey = this.#getEvmSigningKey();
20632
20713
  const depositorAddress = deriveEvmAddress(evmKey);
20633
- const digest = _chunk7GOXIT24cjs.buildPermit2FundingDigest.call(void 0, {
20714
+ const digest = _chunkJZTF4JNHcjs.buildPermit2FundingDigest.call(void 0, {
20634
20715
  chainId,
20635
20716
  coordinatorAddress: checked.coordinator,
20636
20717
  sourceToken: checked.sourceToken,
@@ -20664,7 +20745,7 @@ network='${network}'`
20664
20745
  delegated
20665
20746
  );
20666
20747
  const calls = checked.calls;
20667
- const encoded = _chunk7GOXIT24cjs.encodeExecuteAndCreateWithPermit2.call(void 0, checked.coordinator, {
20748
+ const encoded = _chunkJZTF4JNHcjs.encodeExecuteAndCreateWithPermit2.call(void 0, checked.coordinator, {
20668
20749
  calls,
20669
20750
  preimageHash: checked.preimageHash,
20670
20751
  token: checked.lockToken,
@@ -20680,9 +20761,9 @@ network='${network}'`
20680
20761
  const maxUint256 = BigInt(
20681
20762
  "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
20682
20763
  );
20683
- const approve = _chunk7GOXIT24cjs.encodeApproveCallData.call(void 0,
20764
+ const approve = _chunkJZTF4JNHcjs.encodeApproveCallData.call(void 0,
20684
20765
  checked.sourceToken,
20685
- _chunk7GOXIT24cjs.PERMIT2_ADDRESS,
20766
+ _chunkJZTF4JNHcjs.PERMIT2_ADDRESS,
20686
20767
  maxUint256
20687
20768
  );
20688
20769
  return {
@@ -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
  * ```
@@ -20760,7 +20842,7 @@ network='${network}'`
20760
20842
  swapId,
20761
20843
  serverData,
20762
20844
  chainId,
20763
- _optionalChain([options, 'optionalAccess', _273 => _273.funding])
20845
+ _optionalChain([options, 'optionalAccess', _278 => _278.funding])
20764
20846
  );
20765
20847
  const nonceBytes = new Uint8Array(32);
20766
20848
  crypto.getRandomValues(nonceBytes);
@@ -20788,7 +20870,7 @@ network='${network}'`
20788
20870
  nonce,
20789
20871
  deadline
20790
20872
  };
20791
- const typedData = _chunk7GOXIT24cjs.buildPermit2TypedData.call(void 0, fundingParams);
20873
+ const typedData = _chunkJZTF4JNHcjs.buildPermit2TypedData.call(void 0, fundingParams);
20792
20874
  return {
20793
20875
  coordinatorAddress: checked.coordinator,
20794
20876
  /** The lock's sender: the depositor on HTLCErc20 v7 / HTLCNative v2, the coordinator before. */
@@ -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 }),
@@ -20848,14 +20931,14 @@ network='${network}'`
20848
20931
  */
20849
20932
  async fundSwap(swapId, signer, options) {
20850
20933
  {
20851
- const stored = await _optionalChain([this, 'access', _274 => _274.#swapStorage, 'optionalAccess', _275 => _275.get, 'call', _276 => _276(swapId)]);
20852
- const response = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async _277 => _277.response]), async () => ( await this.getSwap(swapId, { updateStorage: true })));
20934
+ const stored = await _optionalChain([this, 'access', _279 => _279.#swapStorage, 'optionalAccess', _280 => _280.get, 'call', _281 => _281(swapId)]);
20935
+ const response = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async _282 => _282.response]), async () => ( await this.getSwap(swapId, { updateStorage: true })));
20853
20936
  if ((response.direction === "evm_to_lightning" || response.direction === "evm_to_arkade" || response.direction === "evm_to_bitcoin") && response.evm_htlc_kind === "native") {
20854
20937
  const txHash2 = await this.#fundNativeLock(
20855
20938
  swapId,
20856
20939
  response,
20857
20940
  signer,
20858
- _optionalChain([options, 'optionalAccess', _278 => _278.onQuote])
20941
+ _optionalChain([options, 'optionalAccess', _283 => _283.onQuote])
20859
20942
  );
20860
20943
  return { txHash: txHash2 };
20861
20944
  }
@@ -20866,12 +20949,12 @@ network='${network}'`
20866
20949
  }
20867
20950
  }
20868
20951
  if (isCctpOnlySource(signer.chainId)) {
20869
- const stored = await _optionalChain([this, 'access', _279 => _279.#swapStorage, 'optionalAccess', _280 => _280.get, 'call', _281 => _281(swapId)]);
20870
- const swapResponse = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async _282 => _282.response]), async () => ( await this.getSwap(swapId, { updateStorage: true })));
20952
+ const stored = await _optionalChain([this, 'access', _284 => _284.#swapStorage, 'optionalAccess', _285 => _285.get, 'call', _286 => _286(swapId)]);
20953
+ const swapResponse = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async _287 => _287.response]), async () => ( await this.getSwap(swapId, { updateStorage: true })));
20871
20954
  const source = cctpMetaForChainId(signer.chainId);
20872
20955
  const expected = {
20873
20956
  ...this.#fundingExpectation(swapId, stored),
20874
- pins: _optionalChain([options, 'optionalAccess', _283 => _283.funding])
20957
+ pins: _optionalChain([options, 'optionalAccess', _288 => _288.funding])
20875
20958
  };
20876
20959
  await this.#ensureClientHashLock(
20877
20960
  swapId,
@@ -20903,7 +20986,7 @@ network='${network}'`
20903
20986
  }
20904
20987
  const amount = BigInt(rawAmount);
20905
20988
  const destination = cctpMetaForChainId(42161);
20906
- const recordedBurn = _optionalChain([stored, 'optionalAccess', _284 => _284.cctpBurnTxid]);
20989
+ const recordedBurn = _optionalChain([stored, 'optionalAccess', _289 => _289.cctpBurnTxid]);
20907
20990
  if (recordedBurn) {
20908
20991
  const fresh = await this.getSwap(swapId, { updateStorage: true });
20909
20992
  if (fresh.status !== "pending") {
@@ -20912,7 +20995,7 @@ network='${network}'`
20912
20995
  );
20913
20996
  }
20914
20997
  }
20915
- const maxFee = recordedBurn ? 0n : await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _285 => _285.maxFee]), async () => ( computeCctpFastFee(
20998
+ const maxFee = recordedBurn ? 0n : await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _290 => _290.maxFee]), async () => ( computeCctpFastFee(
20916
20999
  await getCachedCctpFee({
20917
21000
  sourceDomain: source.domain,
20918
21001
  destinationDomain: destination.domain
@@ -20932,8 +21015,8 @@ network='${network}'`
20932
21015
  onBurn: (burnTxHash) => this.#recordCctpBurn(swapId, burnTxHash),
20933
21016
  amount,
20934
21017
  maxFee,
20935
- onProgress: _optionalChain([options, 'optionalAccess', _286 => _286.onProgress]),
20936
- signal: _optionalChain([options, 'optionalAccess', _287 => _287.signal])
21018
+ onProgress: _optionalChain([options, 'optionalAccess', _291 => _291.onProgress]),
21019
+ signal: _optionalChain([options, 'optionalAccess', _292 => _292.signal])
20937
21020
  });
20938
21021
  if (cctp.transactionHash) {
20939
21022
  await this.#recordEvmFunding(swapId, { txid: cctp.transactionHash });
@@ -20944,26 +21027,26 @@ network='${network}'`
20944
21027
  swapId,
20945
21028
  signer.chainId,
20946
21029
  signer.address,
20947
- { funding: _optionalChain([options, 'optionalAccess', _288 => _288.funding]) }
21030
+ { funding: _optionalChain([options, 'optionalAccess', _293 => _293.funding]) }
20948
21031
  );
20949
- _optionalChain([options, 'optionalAccess', _289 => _289.onQuote, 'optionalCall', _290 => _290({
21032
+ _optionalChain([options, 'optionalAccess', _294 => _294.onQuote, 'optionalCall', _295 => _295({
20950
21033
  sourceAmount: funding.sourceAmount,
20951
21034
  sourceTokenAddress: funding.sourceTokenAddress
20952
21035
  })]);
20953
21036
  const tokenAddress = funding.sourceTokenAddress;
20954
- const permit2 = _chunk7GOXIT24cjs.PERMIT2_ADDRESS;
20955
- const balanceCall = _chunkMYOGO44Lcjs.encodeBalanceOfCall.call(void 0, tokenAddress, signer.address);
21037
+ const permit2 = _chunkJZTF4JNHcjs.PERMIT2_ADDRESS;
21038
+ const balanceCall = _chunkTNZW35XAcjs.encodeBalanceOfCall.call(void 0, tokenAddress, signer.address);
20956
21039
  const balanceResult = await signer.call({
20957
21040
  to: balanceCall.to,
20958
21041
  data: balanceCall.data
20959
21042
  });
20960
- const balance = _chunkMYOGO44Lcjs.decodeUint256.call(void 0, balanceResult);
21043
+ const balance = _chunkTNZW35XAcjs.decodeUint256.call(void 0, balanceResult);
20961
21044
  if (balance < funding.sourceAmount) {
20962
21045
  throw new Error(
20963
21046
  `Insufficient token balance: have ${balance}, need ${funding.sourceAmount}`
20964
21047
  );
20965
21048
  }
20966
- const allowanceCall = _chunkMYOGO44Lcjs.encodeAllowanceCall.call(void 0,
21049
+ const allowanceCall = _chunkTNZW35XAcjs.encodeAllowanceCall.call(void 0,
20967
21050
  tokenAddress,
20968
21051
  signer.address,
20969
21052
  permit2
@@ -20972,9 +21055,9 @@ network='${network}'`
20972
21055
  to: allowanceCall.to,
20973
21056
  data: allowanceCall.data
20974
21057
  });
20975
- const allowance = _chunkMYOGO44Lcjs.decodeUint256.call(void 0, allowanceResult);
21058
+ const allowance = _chunkTNZW35XAcjs.decodeUint256.call(void 0, allowanceResult);
20976
21059
  if (allowance < funding.sourceAmount) {
20977
- const approveData = _chunkMYOGO44Lcjs.encodeMaxApproveData.call(void 0, tokenAddress, permit2);
21060
+ const approveData = _chunkTNZW35XAcjs.encodeMaxApproveData.call(void 0, tokenAddress, permit2);
20978
21061
  const approveTxHash = await signer.sendTransaction({
20979
21062
  to: approveData.to,
20980
21063
  data: approveData.data,
@@ -20982,7 +21065,7 @@ network='${network}'`
20982
21065
  });
20983
21066
  const approveReceipt = await signer.waitForReceipt(approveTxHash);
20984
21067
  if (approveReceipt.status !== "success") {
20985
- const reason = await _chunkMYOGO44Lcjs.getRevertReason.call(void 0,
21068
+ const reason = await _chunkTNZW35XAcjs.getRevertReason.call(void 0,
20986
21069
  signer,
20987
21070
  approveTxHash,
20988
21071
  approveReceipt.blockNumber
@@ -20994,16 +21077,23 @@ network='${network}'`
20994
21077
  swapId,
20995
21078
  signer.chainId,
20996
21079
  signer.address,
20997
- { funding: _optionalChain([options, 'optionalAccess', _291 => _291.funding]) }
21080
+ { funding: _optionalChain([options, 'optionalAccess', _296 => _296.funding]) }
20998
21081
  );
20999
21082
  if (freshFunding.sourceAmount !== funding.sourceAmount) {
21000
- _optionalChain([options, 'optionalAccess', _292 => _292.onQuote, 'optionalCall', _293 => _293({
21083
+ _optionalChain([options, 'optionalAccess', _297 => _297.onQuote, 'optionalCall', _298 => _298({
21001
21084
  sourceAmount: freshFunding.sourceAmount,
21002
21085
  sourceTokenAddress: freshFunding.sourceTokenAddress
21003
21086
  })]);
21004
21087
  }
21005
21088
  const signature = await signer.signTypedData(freshFunding.typedData);
21006
- const encoded = _chunk7GOXIT24cjs.encodeExecuteAndCreateWithPermit2.call(void 0,
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 (e26) {
21094
+ }
21095
+ }
21096
+ const encoded = _chunkJZTF4JNHcjs.encodeExecuteAndCreateWithPermit2.call(void 0,
21007
21097
  freshFunding.coordinatorAddress,
21008
21098
  {
21009
21099
  calls: freshFunding.calls,
@@ -21016,23 +21106,31 @@ 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
- await _chunkMYOGO44Lcjs.simulateTransaction.call(void 0, signer, encoded, "Funding transaction");
21113
+ await _chunkTNZW35XAcjs.simulateTransaction.call(void 0, signer, encoded, "Funding transaction");
21023
21114
  const txHash = await signer.sendTransaction({
21024
21115
  to: encoded.to,
21025
21116
  data: encoded.data,
21026
- gas: await _chunkMYOGO44Lcjs.gasLimitFor.call(void 0, signer, encoded, PERMIT2_FUND_GAS)
21027
- });
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
21117
+ gas: await _chunkTNZW35XAcjs.gasLimitFor.call(void 0, signer, encoded, PERMIT2_FUND_GAS)
21035
21118
  });
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
  /**
@@ -21058,17 +21156,17 @@ network='${network}'`
21058
21156
  * @returns The Arbitrum settlement tx hash (or UserOp hash) and the burn
21059
21157
  */
21060
21158
  async fundSwapFromSolana(swapId, signer, options) {
21061
- const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _294 => _294.rpcUrl]), () => ( this.#config.solanaRpcUrl));
21159
+ const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _299 => _299.rpcUrl]), () => ( this.#config.solanaRpcUrl));
21062
21160
  if (!rpcUrl) {
21063
21161
  throw new Error(
21064
21162
  "Funding from Solana needs a Solana RPC URL. Pass `rpcUrl` or call `.withSolanaRpcUrl(url)` on the ClientBuilder."
21065
21163
  );
21066
21164
  }
21067
- const stored = await _optionalChain([this, 'access', _295 => _295.#swapStorage, 'optionalAccess', _296 => _296.get, 'call', _297 => _297(swapId)]);
21068
- const swapResponse = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async _298 => _298.response]), async () => ( await this.getSwap(swapId, { updateStorage: true })));
21165
+ const stored = await _optionalChain([this, 'access', _300 => _300.#swapStorage, 'optionalAccess', _301 => _301.get, 'call', _302 => _302(swapId)]);
21166
+ const swapResponse = await _asyncNullishCoalesce(await _asyncOptionalChain([stored, 'optionalAccess', async _303 => _303.response]), async () => ( await this.getSwap(swapId, { updateStorage: true })));
21069
21167
  const expected = {
21070
21168
  ...this.#fundingExpectation(swapId, stored),
21071
- pins: _optionalChain([options, 'optionalAccess', _299 => _299.funding])
21169
+ pins: _optionalChain([options, 'optionalAccess', _304 => _304.funding])
21072
21170
  };
21073
21171
  await this.#ensureClientHashLock(
21074
21172
  swapId,
@@ -21092,7 +21190,7 @@ network='${network}'`
21092
21190
  );
21093
21191
  }
21094
21192
  const amount = BigInt(bridge.source_amount);
21095
- const recordedBurn = _optionalChain([stored, 'optionalAccess', _300 => _300.cctpBurnTxid]);
21193
+ const recordedBurn = _optionalChain([stored, 'optionalAccess', _305 => _305.cctpBurnTxid]);
21096
21194
  if (recordedBurn) {
21097
21195
  const fresh = await this.getSwap(swapId, { updateStorage: true });
21098
21196
  if (fresh.status !== "pending") {
@@ -21101,14 +21199,14 @@ network='${network}'`
21101
21199
  );
21102
21200
  }
21103
21201
  }
21104
- const maxFee = recordedBurn ? 0n : await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _301 => _301.maxFee]), async () => ( computeCctpFastFee(
21202
+ const maxFee = recordedBurn ? 0n : await _asyncNullishCoalesce(await _asyncOptionalChain([options, 'optionalAccess', async _306 => _306.maxFee]), async () => ( computeCctpFastFee(
21105
21203
  await getCachedCctpFee({
21106
21204
  sourceDomain: _chunkTKFOVRJRcjs.CCTP_DOMAINS.Solana,
21107
21205
  destinationDomain: _chunkTKFOVRJRcjs.CCTP_DOMAINS.Arbitrum
21108
21206
  }),
21109
21207
  amount
21110
21208
  )));
21111
- const { cctpFundSwapFromSolana } = await Promise.resolve().then(() => _interopRequireWildcard(require("./fundSwap-IUPFISXM-ON5IVSSZ.cjs")));
21209
+ const { cctpFundSwapFromSolana } = await Promise.resolve().then(() => _interopRequireWildcard(require("./fundSwap-UBCHMUP4-BEMQNSFQ.cjs")));
21112
21210
  const { aa } = this.cctpInbound;
21113
21211
  const cctp = await cctpFundSwapFromSolana(
21114
21212
  { apiClient: this.#apiClient, aa },
@@ -21123,13 +21221,13 @@ network='${network}'`
21123
21221
  ),
21124
21222
  rpcUrl,
21125
21223
  burnSignature: recordedBurn,
21126
- burnLastValidBlockHeight: _optionalChain([stored, 'optionalAccess', _302 => _302.cctpBurnLastValidBlockHeight]),
21224
+ burnLastValidBlockHeight: _optionalChain([stored, 'optionalAccess', _307 => _307.cctpBurnLastValidBlockHeight]),
21127
21225
  onBurn: (burnSignature, lastValidBlockHeight) => this.#recordCctpBurn(swapId, burnSignature, lastValidBlockHeight),
21128
21226
  amount,
21129
21227
  maxFee,
21130
- priorityFeeMicroLamports: _optionalChain([options, 'optionalAccess', _303 => _303.priorityFeeMicroLamports]),
21131
- onProgress: _optionalChain([options, 'optionalAccess', _304 => _304.onProgress]),
21132
- signal: _optionalChain([options, 'optionalAccess', _305 => _305.signal])
21228
+ priorityFeeMicroLamports: _optionalChain([options, 'optionalAccess', _308 => _308.priorityFeeMicroLamports]),
21229
+ onProgress: _optionalChain([options, 'optionalAccess', _309 => _309.onProgress]),
21230
+ signal: _optionalChain([options, 'optionalAccess', _310 => _310.signal])
21133
21231
  }
21134
21232
  );
21135
21233
  if (cctp.transactionHash) {
@@ -21147,7 +21245,7 @@ network='${network}'`
21147
21245
  * `withSolanaRpcUrl` on the builder
21148
21246
  */
21149
21247
  async getSolanaUsdcBalance(owner, options) {
21150
- const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _306 => _306.rpcUrl]), () => ( this.#config.solanaRpcUrl));
21248
+ const rpcUrl = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _311 => _311.rpcUrl]), () => ( this.#config.solanaRpcUrl));
21151
21249
  if (!rpcUrl) {
21152
21250
  throw new Error(
21153
21251
  "Reading a Solana balance needs a Solana RPC URL. Pass `rpcUrl` or call `.withSolanaRpcUrl(url)` on the ClientBuilder."
@@ -21183,16 +21281,16 @@ network='${network}'`
21183
21281
  `The server's swap names HTLC ${swap.evm_htlc_address}, claimer ${swap.server_evm_address} and timelock ${swap.evm_refund_locktime}, not the ${terms.htlcAddress}, ${terms.claimAddress} and ${terms.timelock} it was created with; refusing to fund it`
21184
21282
  );
21185
21283
  }
21186
- _optionalChain([onQuote, 'optionalCall', _307 => _307({
21284
+ _optionalChain([onQuote, 'optionalCall', _312 => _312({
21187
21285
  sourceAmount: amount,
21188
- sourceTokenAddress: _chunk7GOXIT24cjs.NATIVE_TOKEN_ADDRESS
21286
+ sourceTokenAddress: _chunkJZTF4JNHcjs.NATIVE_TOKEN_ADDRESS
21189
21287
  })]);
21190
- if (swap.evm_coordinator_address.toLowerCase() !== _chunk7GOXIT24cjs.NATIVE_TOKEN_ADDRESS) {
21288
+ if (swap.evm_coordinator_address.toLowerCase() !== _chunkJZTF4JNHcjs.NATIVE_TOKEN_ADDRESS) {
21191
21289
  throw new Error(
21192
21290
  "This legacy Rootstock swap requires coordinator funding. Create a new swap with the updated backend before funding."
21193
21291
  );
21194
21292
  }
21195
- if (signer.address.toLowerCase() !== _optionalChain([swap, 'access', _308 => _308.client_evm_address, 'optionalAccess', _309 => _309.toLowerCase, 'call', _310 => _310()])) {
21293
+ if (signer.address.toLowerCase() !== _optionalChain([swap, 'access', _313 => _313.client_evm_address, 'optionalAccess', _314 => _314.toLowerCase, 'call', _315 => _315()])) {
21196
21294
  throw new Error(
21197
21295
  "Connect the source wallet recorded on this swap to fund RBTC."
21198
21296
  );
@@ -21217,24 +21315,24 @@ network='${network}'`
21217
21315
  preimageHash: hashLock,
21218
21316
  claimAddress: swap.server_evm_address,
21219
21317
  lockSender: signer.address,
21220
- token: _chunk7GOXIT24cjs.NATIVE_TOKEN_ADDRESS
21318
+ token: _chunkJZTF4JNHcjs.NATIVE_TOKEN_ADDRESS
21221
21319
  };
21222
21320
  await this.#ensureNativeFundingFailed(
21223
21321
  swapId,
21224
21322
  signer,
21225
21323
  [
21226
- await _asyncOptionalChain([(await this.getStoredSwap(swapId)), 'optionalAccess', async _311 => _311.evmFundTxid]),
21324
+ await _asyncOptionalChain([(await this.getStoredSwap(swapId)), 'optionalAccess', async _316 => _316.evmFundTxid]),
21227
21325
  swap.evm_fund_txid
21228
21326
  ],
21229
21327
  hashLock
21230
21328
  );
21231
- await _chunkMYOGO44Lcjs.simulateTransaction.call(void 0, signer, encoded, "Funding transaction");
21329
+ await _chunkTNZW35XAcjs.simulateTransaction.call(void 0, signer, encoded, "Funding transaction");
21232
21330
  const txHash = await signer.sendTransaction({
21233
21331
  to: encoded.to,
21234
21332
  data: encoded.data,
21235
21333
  value: encoded.value,
21236
- type: _chunkMYOGO44Lcjs.txTypeFor.call(void 0, signer.chainId),
21237
- gas: await _chunkMYOGO44Lcjs.gasLimitFor.call(void 0, signer, encoded, NATIVE_LOCK_GAS)
21334
+ type: _chunkTNZW35XAcjs.txTypeFor.call(void 0, signer.chainId),
21335
+ gas: await _chunkTNZW35XAcjs.gasLimitFor.call(void 0, signer, encoded, NATIVE_LOCK_GAS)
21238
21336
  });
21239
21337
  return this.#awaitFunding(swapId, signer, txHash, encoded, lock, {
21240
21338
  forgetFailed: true
@@ -21257,7 +21355,7 @@ network='${network}'`
21257
21355
  let known;
21258
21356
  try {
21259
21357
  known = await signer.getTransaction(txid);
21260
- } catch (e26) {
21358
+ } catch (e27) {
21261
21359
  known = null;
21262
21360
  }
21263
21361
  if (!known) refuse("the node does not know and may still land");
@@ -21268,7 +21366,7 @@ network='${network}'`
21268
21366
  FUNDING_RECEIPT_WAIT_MS,
21269
21367
  `not mined within ${FUNDING_RECEIPT_WAIT_MS / 1e3}s`
21270
21368
  );
21271
- } catch (e27) {
21369
+ } catch (e28) {
21272
21370
  return refuse("is not mined yet");
21273
21371
  }
21274
21372
  if (receipt.status !== "success") continue;
@@ -21292,8 +21390,8 @@ network='${network}'`
21292
21390
  });
21293
21391
  const receipt = await signer.waitForReceipt(txHash);
21294
21392
  if (receipt.status !== "success") {
21295
- if (_optionalChain([options, 'optionalAccess', _312 => _312.forgetFailed])) await this.#forgetEvmFunding(swapId, txHash);
21296
- const reason = await _chunkMYOGO44Lcjs.getRevertReason.call(void 0, signer, txHash, receipt.blockNumber);
21393
+ if (_optionalChain([options, 'optionalAccess', _317 => _317.forgetFailed])) await this.#forgetEvmFunding(swapId, txHash);
21394
+ const reason = await _chunkTNZW35XAcjs.getRevertReason.call(void 0, signer, txHash, receipt.blockNumber);
21297
21395
  throw new Error(`Funding transaction failed: ${reason}`);
21298
21396
  }
21299
21397
  const mined = receipt.transactionHash || txHash;
@@ -21307,7 +21405,7 @@ network='${network}'`
21307
21405
  });
21308
21406
  created = !replaced || await isSameCall(signer, mined, sent);
21309
21407
  } else {
21310
- created = _chunk7GOXIT24cjs.findSwapCreated.call(void 0, receipt.logs, {
21408
+ created = _chunkJZTF4JNHcjs.findSwapCreated.call(void 0, receipt.logs, {
21311
21409
  htlcAddress: expected.htlcAddress,
21312
21410
  hashLock: expected.preimageHash,
21313
21411
  claimAddress: expected.claimAddress,
@@ -21316,7 +21414,7 @@ network='${network}'`
21316
21414
  }).length > 0;
21317
21415
  }
21318
21416
  if (!created && replaced) {
21319
- if (_optionalChain([options, 'optionalAccess', _313 => _313.forgetFailed]) && provesNoLockUnder(receipt, expected.preimageHash)) {
21417
+ if (_optionalChain([options, 'optionalAccess', _318 => _318.forgetFailed]) && provesNoLockUnder(receipt, expected.preimageHash)) {
21320
21418
  await this.#forgetEvmFunding(swapId, txHash);
21321
21419
  }
21322
21420
  throw new Error(
@@ -21432,7 +21530,7 @@ network='${network}'`
21432
21530
  `Refund timelock has not expired yet (expires ${expiryDate}). Use collabRefundEvmWithSigner for instant refunds.`
21433
21531
  );
21434
21532
  }
21435
- await _chunkMYOGO44Lcjs.simulateTransaction.call(void 0,
21533
+ await _chunkTNZW35XAcjs.simulateTransaction.call(void 0,
21436
21534
  signer,
21437
21535
  result.evmRefundData,
21438
21536
  "Refund transaction"
@@ -21440,12 +21538,12 @@ network='${network}'`
21440
21538
  const txHash = await signer.sendTransaction({
21441
21539
  to: result.evmRefundData.to,
21442
21540
  data: result.evmRefundData.data,
21443
- type: _chunkMYOGO44Lcjs.txTypeFor.call(void 0, signer.chainId),
21444
- gas: await _chunkMYOGO44Lcjs.gasLimitFor.call(void 0, signer, result.evmRefundData, REFUND_GAS)
21541
+ type: _chunkTNZW35XAcjs.txTypeFor.call(void 0, signer.chainId),
21542
+ gas: await _chunkTNZW35XAcjs.gasLimitFor.call(void 0, signer, result.evmRefundData, REFUND_GAS)
21445
21543
  });
21446
21544
  const receipt = await signer.waitForReceipt(txHash);
21447
21545
  if (receipt.status !== "success") {
21448
- const reason = await _chunkMYOGO44Lcjs.getRevertReason.call(void 0, signer, txHash, receipt.blockNumber);
21546
+ const reason = await _chunkTNZW35XAcjs.getRevertReason.call(void 0, signer, txHash, receipt.blockNumber);
21449
21547
  throw new Error(`Refund transaction reverted: ${reason}`);
21450
21548
  }
21451
21549
  return { txHash };
@@ -21473,7 +21571,7 @@ network='${network}'`
21473
21571
  throw new Error(collabRefundUnavailable(swapId, params));
21474
21572
  }
21475
21573
  const signature = await signer.signTypedData(typedData);
21476
- const { v, r, s } = _chunkMYOGO44Lcjs.parseSignature.call(void 0, signature);
21574
+ const { v, r, s } = _chunkTNZW35XAcjs.parseSignature.call(void 0, signature);
21477
21575
  const result = await this.submitCollabRefundEvm(swapId, {
21478
21576
  v,
21479
21577
  r,
@@ -21506,7 +21604,7 @@ network='${network}'`
21506
21604
  }
21507
21605
  async #actualRefundTransfer(oldSwap, smartAccountAddress) {
21508
21606
  const txHash = oldSwap.evm_claim_txid;
21509
- const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _314 => _314.#config, 'access', _315 => _315.aa, 'optionalAccess', _316 => _316.rpcUrl]), () => ( _optionalChain([this, 'access', _317 => _317.#config, 'access', _318 => _318.aa, 'optionalAccess', _319 => _319.bundlerUrl])));
21607
+ const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _319 => _319.#config, 'access', _320 => _320.aa, 'optionalAccess', _321 => _321.rpcUrl]), () => ( _optionalChain([this, 'access', _322 => _322.#config, 'access', _323 => _323.aa, 'optionalAccess', _324 => _324.bundlerUrl])));
21510
21608
  if (!txHash || !rpcUrl) return null;
21511
21609
  const { createPublicClient: createPublicClient2, http: http2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./_esm-4ZKYBBIE-D33574DC.cjs")));
21512
21610
  const { arbitrum: arbitrum2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./chains-D6LHJZMI-AAYKXZGC.cjs")));
@@ -21519,13 +21617,13 @@ network='${network}'`
21519
21617
  receipt = await publicClient.getTransactionReceipt({
21520
21618
  hash: txHash
21521
21619
  });
21522
- } catch (e28) {
21620
+ } catch (e29) {
21523
21621
  return null;
21524
21622
  }
21525
21623
  const transferTopic = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef";
21526
21624
  const paddedRecipient = smartAccountAddress.replace(/^0x/i, "").toLowerCase().padStart(64, "0");
21527
21625
  const transfers = receipt.logs.filter(
21528
- (log) => _optionalChain([log, 'access', _320 => _320.topics, 'access', _321 => _321[0], 'optionalAccess', _322 => _322.toLowerCase, 'call', _323 => _323()]) === transferTopic && _optionalChain([log, 'access', _324 => _324.topics, 'access', _325 => _325[2], 'optionalAccess', _326 => _326.replace, 'call', _327 => _327(/^0x/i, ""), 'access', _328 => _328.toLowerCase, 'call', _329 => _329()]) === paddedRecipient
21626
+ (log) => _optionalChain([log, 'access', _325 => _325.topics, 'access', _326 => _326[0], 'optionalAccess', _327 => _327.toLowerCase, 'call', _328 => _328()]) === transferTopic && _optionalChain([log, 'access', _329 => _329.topics, 'access', _330 => _330[2], 'optionalAccess', _331 => _331.replace, 'call', _332 => _332(/^0x/i, ""), 'access', _333 => _333.toLowerCase, 'call', _334 => _334()]) === paddedRecipient
21529
21627
  ).map((log) => ({
21530
21628
  tokenAddress: log.address,
21531
21629
  amount: BigInt(log.data).toString()
@@ -21612,8 +21710,8 @@ network='${network}'`
21612
21710
  {
21613
21711
  chain: refundChain,
21614
21712
  address: actualRefund.tokenAddress,
21615
- symbol: _nullishCoalesce(_optionalChain([actualMeta, 'optionalAccess', _330 => _330.symbol]), () => ( "ERC-20")),
21616
- decimals: _nullishCoalesce(_optionalChain([actualMeta, 'optionalAccess', _331 => _331.decimals]), () => ( 18)),
21713
+ symbol: _nullishCoalesce(_optionalChain([actualMeta, 'optionalAccess', _335 => _335.symbol]), () => ( "ERC-20")),
21714
+ decimals: _nullishCoalesce(_optionalChain([actualMeta, 'optionalAccess', _336 => _336.decimals]), () => ( 18)),
21617
21715
  amount: actualRefund.amount
21618
21716
  }
21619
21717
  ] : [],
@@ -21624,7 +21722,7 @@ network='${network}'`
21624
21722
  ) === idx
21625
21723
  );
21626
21724
  for (const candidate of candidates) {
21627
- const balanceCall = _chunkMYOGO44Lcjs.encodeBalanceOfCall.call(void 0,
21725
+ const balanceCall = _chunkTNZW35XAcjs.encodeBalanceOfCall.call(void 0,
21628
21726
  candidate.address,
21629
21727
  smartAccountAddress
21630
21728
  );
@@ -21632,7 +21730,7 @@ network='${network}'`
21632
21730
  to: balanceCall.to,
21633
21731
  data: balanceCall.data
21634
21732
  });
21635
- const balance = _chunkMYOGO44Lcjs.decodeUint256.call(void 0, balanceResult || "0x0");
21733
+ const balance = _chunkTNZW35XAcjs.decodeUint256.call(void 0, balanceResult || "0x0");
21636
21734
  const amount = BigInt(candidate.amount);
21637
21735
  if (balance >= amount) {
21638
21736
  return {
@@ -21781,9 +21879,9 @@ network='${network}'`
21781
21879
  }
21782
21880
  const { client_evm_address: depositor, gasless } = stored.response;
21783
21881
  let owner;
21784
- if (_optionalChain([depositor, 'optionalAccess', _332 => _332.toLowerCase, 'call', _333 => _333()]) === this.getEvmAddress().toLowerCase()) {
21882
+ if (_optionalChain([depositor, 'optionalAccess', _337 => _337.toLowerCase, 'call', _338 => _338()]) === this.getEvmAddress().toLowerCase()) {
21785
21883
  owner = this.#keyOwnerSigner();
21786
- } else if (gasless && _optionalChain([depositor, 'optionalAccess', _334 => _334.toLowerCase, 'call', _335 => _335()]) === deriveEvmAddress(stored.secretKey).toLowerCase()) {
21884
+ } else if (gasless && _optionalChain([depositor, 'optionalAccess', _339 => _339.toLowerCase, 'call', _340 => _340()]) === deriveEvmAddress(stored.secretKey).toLowerCase()) {
21787
21885
  owner = keyToKernelOwnerSigner(
21788
21886
  _chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, stored.secretKey.replace(/^0x/, "")),
21789
21887
  42161
@@ -21810,7 +21908,7 @@ network='${network}'`
21810
21908
  const refund = result.evmRefundData;
21811
21909
  return this.#sponsoredUserOp(
21812
21910
  owner,
21813
- (account) => _chunk7GOXIT24cjs.refundForAsOwnRefund.call(void 0, refund, account)
21911
+ (account) => _chunkJZTF4JNHcjs.refundForAsOwnRefund.call(void 0, refund, account)
21814
21912
  );
21815
21913
  }
21816
21914
  /** This client's key as the Kernel owner on Arbitrum. */
@@ -21822,7 +21920,7 @@ network='${network}'`
21822
21920
  * with its key (whose signer does not read the chain).
21823
21921
  */
21824
21922
  async #aaRpcCall() {
21825
- const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _336 => _336.#config, 'access', _337 => _337.aa, 'optionalAccess', _338 => _338.rpcUrl]), () => ( _optionalChain([this, 'access', _339 => _339.#config, 'access', _340 => _340.aa, 'optionalAccess', _341 => _341.bundlerUrl])));
21923
+ const rpcUrl = _nullishCoalesce(_optionalChain([this, 'access', _341 => _341.#config, 'access', _342 => _342.aa, 'optionalAccess', _343 => _343.rpcUrl]), () => ( _optionalChain([this, 'access', _344 => _344.#config, 'access', _345 => _345.aa, 'optionalAccess', _346 => _346.bundlerUrl])));
21826
21924
  if (!rpcUrl) {
21827
21925
  throw new Error(
21828
21926
  "Reading a refunded balance without a signer requires AA config (`.withAa(...)`)."
@@ -21840,22 +21938,77 @@ network='${network}'`
21840
21938
  })).data, async () => ( "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 (!_optionalChain([this, 'access', _347 => _347.#config, 'access', _348 => _348.aa, 'access', _349 => _349.paymasterPolicyId, 'optionalAccess', _350 => _350.trim, 'call', _351 => _351()])) {
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, {
@@ -21885,7 +22041,7 @@ network='${network}'`
21885
22041
  swapId,
21886
22042
  serverData,
21887
22043
  chainId,
21888
- _optionalChain([options, 'optionalAccess', _342 => _342.funding])
22044
+ _optionalChain([options, 'optionalAccess', _352 => _352.funding])
21889
22045
  );
21890
22046
  const nonceBytes = new Uint8Array(32);
21891
22047
  crypto.getRandomValues(nonceBytes);
@@ -21896,7 +22052,7 @@ network='${network}'`
21896
22052
  const sourceAmount = checked.sourceAmount;
21897
22053
  const evmKey = this.#getEvmSigningKey();
21898
22054
  const depositorAddress = deriveEvmAddress(evmKey);
21899
- const digest = _chunk7GOXIT24cjs.buildPermit2FundingDigest.call(void 0, {
22055
+ const digest = _chunkJZTF4JNHcjs.buildPermit2FundingDigest.call(void 0, {
21900
22056
  chainId,
21901
22057
  coordinatorAddress: checked.coordinator,
21902
22058
  sourceToken: checked.sourceToken,
@@ -21930,14 +22086,14 @@ network='${network}'`
21930
22086
  delegated
21931
22087
  );
21932
22088
  let eip2612Permit;
21933
- if (_optionalChain([serverData, 'access', _343 => _343.eip2612, 'optionalAccess', _344 => _344.supported]) && !serverData.eip2612.already_approved) {
22089
+ if (_optionalChain([serverData, 'access', _353 => _353.eip2612, 'optionalAccess', _354 => _354.supported]) && !serverData.eip2612.already_approved) {
21934
22090
  const maxUint256 = BigInt(
21935
22091
  "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
21936
22092
  );
21937
- const eip2612Digest = _chunk7GOXIT24cjs.buildEip2612PermitDigest.call(void 0, {
22093
+ const eip2612Digest = _chunkJZTF4JNHcjs.buildEip2612PermitDigest.call(void 0, {
21938
22094
  domainSeparator: serverData.eip2612.domain_separator,
21939
22095
  owner: depositorAddress,
21940
- spender: _chunk7GOXIT24cjs.PERMIT2_ADDRESS,
22096
+ spender: _chunkJZTF4JNHcjs.PERMIT2_ADDRESS,
21941
22097
  value: maxUint256,
21942
22098
  nonce: serverData.eip2612.nonce,
21943
22099
  deadline
@@ -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
+ _chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, 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: _optionalChain([options, 'optionalAccess', _355 => _355.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 Promise.resolve().then(() => _interopRequireWildcard(require("./_esm-4ZKYBBIE-D33574DC.cjs")));
22206
+ const { arbitrum: arbitrum2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./chains-D6LHJZMI-AAYKXZGC.cjs")));
22207
+ const rpc = createPublicClient2({
22208
+ chain: arbitrum2,
22209
+ transport: http2(_nullishCoalesce(_optionalChain([this, 'access', _356 => _356.#config, 'access', _357 => _357.aa, 'optionalAccess', _358 => _358.rpcUrl]), () => ( _optionalChain([this, 'access', _359 => _359.#config, 'access', _360 => _360.aa, 'optionalAccess', _361 => _361.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 = (_nullishCoalesce(expected.terms.htlcVersion, () => ( 0))) >= 7 ? deriveEvmAddress(this.#gaslessDepositorKey(swapId, stored, swap)) : expected.terms.coordinator;
22223
+ const locks = _chunkJZTF4JNHcjs.findSwapCreated.call(void 0, 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
+ _chunk5JR6AJ3Ycjs.hexToBytes.call(void 0, 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 _optionalChain([this, 'access', _362 => _362.#swapStorage, 'optionalAccess', _363 => _363.get, 'call', _364 => _364(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 = _optionalChain([swap, 'access', _365 => _365.client_evm_address, 'optionalAccess', _366 => _366.toLowerCase, 'call', _367 => _367()]);
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 = _optionalChain([response, 'access', _368 => _368.client_evm_address, 'optionalAccess', _369 => _369.toLowerCase, 'call', _370 => _370()]);
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
  */
@@ -22075,7 +22391,7 @@ network='${network}'`
22075
22391
  if (!sourceChain) {
22076
22392
  throw new Error(`Swap ${swapId} is not a CCTP-inbound swap.`);
22077
22393
  }
22078
- const burnTxHash = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _345 => _345.burnTxHash]), () => ( stored.cctpBurnTxid));
22394
+ const burnTxHash = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _371 => _371.burnTxHash]), () => ( stored.cctpBurnTxid));
22079
22395
  if (!burnTxHash) {
22080
22396
  throw new Error(
22081
22397
  `No CCTP burn is recorded for swap ${swapId}; pass it as \`burnTxHash\`.`
@@ -22086,13 +22402,13 @@ network='${network}'`
22086
22402
  {
22087
22403
  signer: this.#depositorOwnerSigner(
22088
22404
  stored.response,
22089
- _optionalChain([options, 'optionalAccess', _346 => _346.ownerSigner])
22405
+ _optionalChain([options, 'optionalAccess', _372 => _372.ownerSigner])
22090
22406
  ),
22091
22407
  burnTxHash,
22092
22408
  sourceChain,
22093
22409
  recipient,
22094
- onProgress: _optionalChain([options, 'optionalAccess', _347 => _347.onProgress]),
22095
- signal: _optionalChain([options, 'optionalAccess', _348 => _348.signal])
22410
+ onProgress: _optionalChain([options, 'optionalAccess', _373 => _373.onProgress]),
22411
+ signal: _optionalChain([options, 'optionalAccess', _374 => _374.signal])
22096
22412
  }
22097
22413
  );
22098
22414
  }
@@ -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 Promise.resolve().then(() => _interopRequireWildcard(require("./wallet-THELKUYT-26NOFCTE.cjs")));
22460
+ const { encodeBalanceOfCall: encodeBalanceOfCall2, encodeTransferCall, decodeUint256: decodeUint2562 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./wallet-33OJRHX5-4VM7QDPO.cjs")));
22145
22461
  const balanceCall = encodeBalanceOfCall2(
22146
22462
  tokenAddress,
22147
22463
  depositorSigner.address
@@ -22236,14 +22552,14 @@ function b64Encode(u) {
22236
22552
  return btoa(bin);
22237
22553
  }
22238
22554
  function isP2tr(script) {
22239
- return _optionalChain([script, 'optionalAccess', _349 => _349.length]) === 34 && script[0] === 81 && script[1] === 32;
22555
+ return _optionalChain([script, 'optionalAccess', _375 => _375.length]) === 34 && script[0] === 81 && script[1] === 32;
22240
22556
  }
22241
22557
  function parseEscrowPsbt(psbt) {
22242
22558
  const lenient = _chunkBEW62OUTcjs.Transaction2.fromPSBT(psbt, { disableScriptCheck: true });
22243
22559
  let stripped = false;
22244
22560
  for (let i = 0; i < lenient.inputsLength; i++) {
22245
22561
  const input = lenient.getInput(i);
22246
- if (input.witnessScript && isP2tr(_optionalChain([input, 'access', _350 => _350.witnessUtxo, 'optionalAccess', _351 => _351.script]))) {
22562
+ if (input.witnessScript && isP2tr(_optionalChain([input, 'access', _376 => _376.witnessUtxo, 'optionalAccess', _377 => _377.script]))) {
22247
22563
  lenient.updateInput(i, { witnessScript: void 0 }, true);
22248
22564
  stripped = true;
22249
22565
  }
@@ -22375,11 +22691,11 @@ var IdbWalletStorage = class {
22375
22691
  }
22376
22692
  async getMnemonic() {
22377
22693
  const record = await this.#db.wallet.get(MNEMONIC_KEY);
22378
- if (_optionalChain([record, 'optionalAccess', _352 => _352.value])) {
22694
+ if (_optionalChain([record, 'optionalAccess', _378 => _378.value])) {
22379
22695
  return record.value;
22380
22696
  }
22381
22697
  const v2Wallet = await readV2Wallet();
22382
- if (!_optionalChain([v2Wallet, 'optionalAccess', _353 => _353.mnemonic])) {
22698
+ if (!_optionalChain([v2Wallet, 'optionalAccess', _379 => _379.mnemonic])) {
22383
22699
  return null;
22384
22700
  }
22385
22701
  await this.setMnemonic(v2Wallet.mnemonic);
@@ -22394,7 +22710,7 @@ var IdbWalletStorage = class {
22394
22710
  }
22395
22711
  async getKeyIndex() {
22396
22712
  const record = await this.#db.wallet.get(KEY_INDEX_KEY);
22397
- return _nullishCoalesce(_optionalChain([record, 'optionalAccess', _354 => _354.value]), () => ( 0));
22713
+ return _nullishCoalesce(_optionalChain([record, 'optionalAccess', _380 => _380.value]), () => ( 0));
22398
22714
  }
22399
22715
  async setKeyIndex(index) {
22400
22716
  await this.#db.wallet.put({ key: KEY_INDEX_KEY, value: index });
@@ -22402,7 +22718,7 @@ var IdbWalletStorage = class {
22402
22718
  async incrementKeyIndex() {
22403
22719
  return this.#db.transaction("rw", this.#db.wallet, async () => {
22404
22720
  const record = await this.#db.wallet.get(KEY_INDEX_KEY);
22405
- const current = _nullishCoalesce(_optionalChain([record, 'optionalAccess', _355 => _355.value]), () => ( 0));
22721
+ const current = _nullishCoalesce(_optionalChain([record, 'optionalAccess', _381 => _381.value]), () => ( 0));
22406
22722
  await this.#db.wallet.put({ key: KEY_INDEX_KEY, value: current + 1 });
22407
22723
  return current;
22408
22724
  });
@@ -22458,7 +22774,7 @@ function readV2Wallet() {
22458
22774
  }
22459
22775
  const request = indexedDB.open(V2_DB_NAME);
22460
22776
  request.onupgradeneeded = () => {
22461
- _optionalChain([request, 'access', _356 => _356.transaction, 'optionalAccess', _357 => _357.abort, 'call', _358 => _358()]);
22777
+ _optionalChain([request, 'access', _382 => _382.transaction, 'optionalAccess', _383 => _383.abort, 'call', _384 => _384()]);
22462
22778
  };
22463
22779
  request.onerror = () => {
22464
22780
  resolve(null);
@@ -22490,7 +22806,7 @@ function readV2Wallet() {
22490
22806
  db.close();
22491
22807
  resolve(null);
22492
22808
  };
22493
- } catch (e29) {
22809
+ } catch (e30) {
22494
22810
  db.close();
22495
22811
  resolve(null);
22496
22812
  }
@@ -22689,4 +23005,4 @@ exports.createApiClient = createApiClient; exports.getVhtlcAmounts = getVhtlcAmo
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-2LGHF7A3.cjs.map
23008
+ //# sourceMappingURL=chunk-4NVWIR74.cjs.map