@arkade-os/swap 0.1.8 → 0.1.9

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.
package/dist/advanced.cjs CHANGED
@@ -1685,9 +1685,9 @@ function onchainHtlcScript(params, network) {
1685
1685
  if (params.claimKey.length !== 32 || params.refundKey.length !== 32) {
1686
1686
  throw new Error("claimKey and refundKey must be 32-byte x-only keys");
1687
1687
  }
1688
- if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0) {
1688
+ if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0 || params.refundLocktime > 4294967295) {
1689
1689
  throw new Error(
1690
- `refundLocktime must be a positive unix timestamp, got ${params.refundLocktime}`
1690
+ `refundLocktime must be a positive uint32 unix timestamp, got ${params.refundLocktime}`
1691
1691
  );
1692
1692
  }
1693
1693
  if (params.refundLocktime < LOCKTIME_THRESHOLD) {
@@ -1776,15 +1776,20 @@ async function claimOnchainFill(chain, input) {
1776
1776
  }
1777
1777
  async function classifyOnchainHtlc(chain, input) {
1778
1778
  const utxos = await chain.getScriptUtxos(input.htlc.pkScript);
1779
- const best = utxos.sort((a, b) => b.amount > a.amount ? 1 : -1)[0];
1780
- if (!best) {
1781
- if (!input.funding) return { phase: "unfunded" };
1782
- const spend = await chain.getSpendingTx(
1783
- input.funding.txid,
1784
- input.funding.vout,
1785
- input.htlc.pkScript
1786
- );
1787
- if (!spend) return { phase: "unfunded" };
1779
+ const deep = (u) => u.confirmations >= input.minConfirmations;
1780
+ const best = utxos.sort(
1781
+ (a, b) => deep(a) !== deep(b) ? deep(a) ? -1 : 1 : b.amount > a.amount ? 1 : -1
1782
+ )[0];
1783
+ const { funding } = input;
1784
+ let spend = null;
1785
+ if (funding && !utxos.some((u) => u.txid === funding.txid && u.vout === funding.vout)) {
1786
+ try {
1787
+ spend = await chain.getSpendingTx(funding.txid, funding.vout, input.htlc.pkScript);
1788
+ } catch (error) {
1789
+ if (!best) throw error;
1790
+ }
1791
+ }
1792
+ if (spend) {
1788
1793
  const preimage = extractPreimage(spend.txHex, input.htlc.paymentHash);
1789
1794
  const txid = btc.Transaction.fromRaw(import_base4.hex.decode(spend.txHex), {
1790
1795
  allowUnknownInputs: true,
@@ -1792,6 +1797,7 @@ async function classifyOnchainHtlc(chain, input) {
1792
1797
  }).id;
1793
1798
  return preimage ? { phase: "claimed", txid, preimage } : { phase: "swept", txid };
1794
1799
  }
1800
+ if (!best) return { phase: "unfunded" };
1795
1801
  if (best.confirmations < input.minConfirmations)
1796
1802
  return { phase: "awaiting_confirmations", utxo: best };
1797
1803
  const mtp = await chain.getMtp();
@@ -2678,6 +2684,9 @@ var init_rfq = __esm({
2678
2684
  if (input.now >= input.payDeadline) {
2679
2685
  throw gateError("quote_expired", "quote or invoice already expired \u2014 request a fresh one");
2680
2686
  }
2687
+ if (quoteAmountSats(input.quote.from_amount, "from_amount") <= 0n || quoteAmountSats(input.quote.to_amount, "to_amount") <= 0n) {
2688
+ throw gateError("non_positive_amount", "quote carries a non-positive amount");
2689
+ }
2681
2690
  if (input.quote.refund_locktime === void 0) {
2682
2691
  throw gateError("missing_refund_locktime", "receive quote carries no refund_locktime");
2683
2692
  }
@@ -6763,6 +6772,9 @@ async function pushClaim(operator, input) {
6763
6772
  assertFiniteAmount(funded, "lockup_malformed", "the lockup's summed value");
6764
6773
  if (!input.partiallyClaimed) {
6765
6774
  assertFiniteAmount(input.expectedAmount, "invalid_gate_input", "expectedAmount");
6775
+ if (input.expectedAmount <= 0) {
6776
+ throw gateError("invalid_gate_input", "expectedAmount is not positive");
6777
+ }
6766
6778
  if (funded < input.expectedAmount) {
6767
6779
  throw new LockupAmountMismatchError(input.expectedAmount, funded);
6768
6780
  }
@@ -7855,10 +7867,10 @@ var RfqSwapManager = class _RfqSwapManager {
7855
7867
  return;
7856
7868
  }
7857
7869
  if (!partiallyClaimed) {
7858
- if (!Number.isFinite(swap.expectedAmount)) {
7870
+ if (!Number.isSafeInteger(swap.expectedAmount) || swap.expectedAmount <= 0) {
7859
7871
  return this.block(
7860
7872
  swap,
7861
- `expectedAmount is not a finite number (${String(swap.expectedAmount)}), so the funded value cannot be checked \u2014 refusing to publish the preimage`
7873
+ `expectedAmount is not a positive number of sats (${String(swap.expectedAmount)}), so the funded value cannot be checked \u2014 refusing to publish the preimage`
7862
7874
  );
7863
7875
  }
7864
7876
  const locked = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
@@ -8119,6 +8131,9 @@ var RfqSwapManager = class _RfqSwapManager {
8119
8131
  utxo,
8120
8132
  bump ? { bump } : void 0
8121
8133
  );
8134
+ if (swap.funding?.txid !== utxo.txid || swap.funding.vout !== utxo.vout || swap.funding.amount === void 0) {
8135
+ swap.funding = { txid: utxo.txid, vout: utxo.vout, amount: Number(utxo.amount) };
8136
+ }
8122
8137
  swap.claimTxid = txid;
8123
8138
  swap.claimBroadcastAt = this.config.now();
8124
8139
  delete swap.claimConfirmed;
package/dist/advanced.js CHANGED
@@ -139,7 +139,7 @@ import {
139
139
  withCanonicalAmount,
140
140
  withDepositFate,
141
141
  withRfqState
142
- } from "./chunk-ZBJGLLYV.js";
142
+ } from "./chunk-I7WEXXZX.js";
143
143
  import {
144
144
  ACTIVITY_TOKEN,
145
145
  Amount,
@@ -174,7 +174,7 @@ import {
174
174
  recordOutcome,
175
175
  swapOf,
176
176
  toAtomicDecimal
177
- } from "./chunk-ISWLKKSS.js";
177
+ } from "./chunk-FQNG4XMF.js";
178
178
  import {
179
179
  ARKADE_BTC,
180
180
  SwapRefusal,
@@ -183,7 +183,7 @@ import {
183
183
  bindsClaimAmount,
184
184
  rfqPair,
185
185
  sealClaimPacket
186
- } from "./chunk-PDNVKH5L.js";
186
+ } from "./chunk-552GDPBU.js";
187
187
  import "./chunk-5QPJWOCN.js";
188
188
  import "./chunk-A3SHHRX4.js";
189
189
 
@@ -1682,9 +1682,9 @@ function onchainHtlcScript(params, network) {
1682
1682
  if (params.claimKey.length !== 32 || params.refundKey.length !== 32) {
1683
1683
  throw new Error("claimKey and refundKey must be 32-byte x-only keys");
1684
1684
  }
1685
- if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0) {
1685
+ if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0 || params.refundLocktime > 4294967295) {
1686
1686
  throw new Error(
1687
- `refundLocktime must be a positive unix timestamp, got ${params.refundLocktime}`
1687
+ `refundLocktime must be a positive uint32 unix timestamp, got ${params.refundLocktime}`
1688
1688
  );
1689
1689
  }
1690
1690
  if (params.refundLocktime < LOCKTIME_THRESHOLD) {
@@ -1859,15 +1859,20 @@ async function claimOnchainFill(chain, input) {
1859
1859
  }
1860
1860
  async function classifyOnchainHtlc(chain, input) {
1861
1861
  const utxos = await chain.getScriptUtxos(input.htlc.pkScript);
1862
- const best = utxos.sort((a, b) => b.amount > a.amount ? 1 : -1)[0];
1863
- if (!best) {
1864
- if (!input.funding) return { phase: "unfunded" };
1865
- const spend = await chain.getSpendingTx(
1866
- input.funding.txid,
1867
- input.funding.vout,
1868
- input.htlc.pkScript
1869
- );
1870
- if (!spend) return { phase: "unfunded" };
1862
+ const deep = (u) => u.confirmations >= input.minConfirmations;
1863
+ const best = utxos.sort(
1864
+ (a, b) => deep(a) !== deep(b) ? deep(a) ? -1 : 1 : b.amount > a.amount ? 1 : -1
1865
+ )[0];
1866
+ const { funding } = input;
1867
+ let spend = null;
1868
+ if (funding && !utxos.some((u) => u.txid === funding.txid && u.vout === funding.vout)) {
1869
+ try {
1870
+ spend = await chain.getSpendingTx(funding.txid, funding.vout, input.htlc.pkScript);
1871
+ } catch (error) {
1872
+ if (!best) throw error;
1873
+ }
1874
+ }
1875
+ if (spend) {
1871
1876
  const preimage = extractPreimage(spend.txHex, input.htlc.paymentHash);
1872
1877
  const txid = btc.Transaction.fromRaw(hex4.decode(spend.txHex), {
1873
1878
  allowUnknownInputs: true,
@@ -1875,6 +1880,7 @@ async function classifyOnchainHtlc(chain, input) {
1875
1880
  }).id;
1876
1881
  return preimage ? { phase: "claimed", txid, preimage } : { phase: "swept", txid };
1877
1882
  }
1883
+ if (!best) return { phase: "unfunded" };
1878
1884
  if (best.confirmations < input.minConfirmations)
1879
1885
  return { phase: "awaiting_confirmations", utxo: best };
1880
1886
  const mtp = await chain.getMtp();
@@ -3025,6 +3031,9 @@ var assertReceivable = (input) => {
3025
3031
  if (input.now >= input.payDeadline) {
3026
3032
  throw gateError("quote_expired", "quote or invoice already expired \u2014 request a fresh one");
3027
3033
  }
3034
+ if (quoteAmountSats(input.quote.from_amount, "from_amount") <= 0n || quoteAmountSats(input.quote.to_amount, "to_amount") <= 0n) {
3035
+ throw gateError("non_positive_amount", "quote carries a non-positive amount");
3036
+ }
3028
3037
  if (input.quote.refund_locktime === void 0) {
3029
3038
  throw gateError("missing_refund_locktime", "receive quote carries no refund_locktime");
3030
3039
  }
@@ -24,7 +24,7 @@ import {
24
24
  rfqCorridorHandlers,
25
25
  rfqSignerOf,
26
26
  updateAssetSwapBestEffort
27
- } from "./chunk-PDNVKH5L.js";
27
+ } from "./chunk-552GDPBU.js";
28
28
  import {
29
29
  collectRfqSwaps
30
30
  } from "./chunk-A3SHHRX4.js";
@@ -1932,6 +1932,9 @@ async function pushClaim(operator, input) {
1932
1932
  assertFiniteAmount(funded, "lockup_malformed", "the lockup's summed value");
1933
1933
  if (!input.partiallyClaimed) {
1934
1934
  assertFiniteAmount(input.expectedAmount, "invalid_gate_input", "expectedAmount");
1935
+ if (input.expectedAmount <= 0) {
1936
+ throw gateError("invalid_gate_input", "expectedAmount is not positive");
1937
+ }
1935
1938
  if (funded < input.expectedAmount) {
1936
1939
  throw new LockupAmountMismatchError(input.expectedAmount, funded);
1937
1940
  }
@@ -2882,10 +2885,10 @@ var RfqSwapManager = class _RfqSwapManager {
2882
2885
  return;
2883
2886
  }
2884
2887
  if (!partiallyClaimed) {
2885
- if (!Number.isFinite(swap.expectedAmount)) {
2888
+ if (!Number.isSafeInteger(swap.expectedAmount) || swap.expectedAmount <= 0) {
2886
2889
  return this.block(
2887
2890
  swap,
2888
- `expectedAmount is not a finite number (${String(swap.expectedAmount)}), so the funded value cannot be checked \u2014 refusing to publish the preimage`
2891
+ `expectedAmount is not a positive number of sats (${String(swap.expectedAmount)}), so the funded value cannot be checked \u2014 refusing to publish the preimage`
2889
2892
  );
2890
2893
  }
2891
2894
  const locked = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
@@ -3146,6 +3149,9 @@ var RfqSwapManager = class _RfqSwapManager {
3146
3149
  utxo,
3147
3150
  bump ? { bump } : void 0
3148
3151
  );
3152
+ if (swap.funding?.txid !== utxo.txid || swap.funding.vout !== utxo.vout || swap.funding.amount === void 0) {
3153
+ swap.funding = { txid: utxo.txid, vout: utxo.vout, amount: Number(utxo.amount) };
3154
+ }
3149
3155
  swap.claimTxid = txid;
3150
3156
  swap.claimBroadcastAt = this.config.now();
3151
3157
  delete swap.claimConfirmed;
@@ -62,7 +62,7 @@ import {
62
62
  undeliveredCarry,
63
63
  walletOperator,
64
64
  watchOfferSwaps
65
- } from "./chunk-ISWLKKSS.js";
65
+ } from "./chunk-FQNG4XMF.js";
66
66
  import {
67
67
  ARKADE_BTC,
68
68
  ASSET_CARRIER_SATS,
@@ -129,7 +129,7 @@ import {
129
129
  unilateralClaimDelay,
130
130
  verifyOfferAddress,
131
131
  withExitClosure
132
- } from "./chunk-PDNVKH5L.js";
132
+ } from "./chunk-552GDPBU.js";
133
133
  import {
134
134
  assertRfqSwapPageFilter,
135
135
  collectAssetSwaps,
package/dist/index.cjs CHANGED
@@ -138,9 +138,9 @@ function onchainHtlcScript(params, network) {
138
138
  if (params.claimKey.length !== 32 || params.refundKey.length !== 32) {
139
139
  throw new Error("claimKey and refundKey must be 32-byte x-only keys");
140
140
  }
141
- if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0) {
141
+ if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0 || params.refundLocktime > 4294967295) {
142
142
  throw new Error(
143
- `refundLocktime must be a positive unix timestamp, got ${params.refundLocktime}`
143
+ `refundLocktime must be a positive uint32 unix timestamp, got ${params.refundLocktime}`
144
144
  );
145
145
  }
146
146
  if (params.refundLocktime < LOCKTIME_THRESHOLD) {
@@ -229,15 +229,20 @@ async function claimOnchainFill(chain, input) {
229
229
  }
230
230
  async function classifyOnchainHtlc(chain, input) {
231
231
  const utxos = await chain.getScriptUtxos(input.htlc.pkScript);
232
- const best = utxos.sort((a, b) => b.amount > a.amount ? 1 : -1)[0];
233
- if (!best) {
234
- if (!input.funding) return { phase: "unfunded" };
235
- const spend = await chain.getSpendingTx(
236
- input.funding.txid,
237
- input.funding.vout,
238
- input.htlc.pkScript
239
- );
240
- if (!spend) return { phase: "unfunded" };
232
+ const deep = (u) => u.confirmations >= input.minConfirmations;
233
+ const best = utxos.sort(
234
+ (a, b) => deep(a) !== deep(b) ? deep(a) ? -1 : 1 : b.amount > a.amount ? 1 : -1
235
+ )[0];
236
+ const { funding } = input;
237
+ let spend = null;
238
+ if (funding && !utxos.some((u) => u.txid === funding.txid && u.vout === funding.vout)) {
239
+ try {
240
+ spend = await chain.getSpendingTx(funding.txid, funding.vout, input.htlc.pkScript);
241
+ } catch (error) {
242
+ if (!best) throw error;
243
+ }
244
+ }
245
+ if (spend) {
241
246
  const preimage = extractPreimage(spend.txHex, input.htlc.paymentHash);
242
247
  const txid = btc.Transaction.fromRaw(import_base.hex.decode(spend.txHex), {
243
248
  allowUnknownInputs: true,
@@ -245,6 +250,7 @@ async function classifyOnchainHtlc(chain, input) {
245
250
  }).id;
246
251
  return preimage ? { phase: "claimed", txid, preimage } : { phase: "swept", txid };
247
252
  }
253
+ if (!best) return { phase: "unfunded" };
248
254
  if (best.confirmations < input.minConfirmations)
249
255
  return { phase: "awaiting_confirmations", utxo: best };
250
256
  const mtp = await chain.getMtp();
@@ -2808,6 +2814,9 @@ var init_rfq = __esm({
2808
2814
  if (input.now >= input.payDeadline) {
2809
2815
  throw gateError("quote_expired", "quote or invoice already expired \u2014 request a fresh one");
2810
2816
  }
2817
+ if (quoteAmountSats(input.quote.from_amount, "from_amount") <= 0n || quoteAmountSats(input.quote.to_amount, "to_amount") <= 0n) {
2818
+ throw gateError("non_positive_amount", "quote carries a non-positive amount");
2819
+ }
2811
2820
  if (input.quote.refund_locktime === void 0) {
2812
2821
  throw gateError("missing_refund_locktime", "receive quote carries no refund_locktime");
2813
2822
  }
@@ -6726,6 +6735,9 @@ async function pushClaim(operator, input) {
6726
6735
  assertFiniteAmount(funded, "lockup_malformed", "the lockup's summed value");
6727
6736
  if (!input.partiallyClaimed) {
6728
6737
  assertFiniteAmount(input.expectedAmount, "invalid_gate_input", "expectedAmount");
6738
+ if (input.expectedAmount <= 0) {
6739
+ throw gateError("invalid_gate_input", "expectedAmount is not positive");
6740
+ }
6729
6741
  if (funded < input.expectedAmount) {
6730
6742
  throw new LockupAmountMismatchError(input.expectedAmount, funded);
6731
6743
  }
@@ -7818,10 +7830,10 @@ var RfqSwapManager = class _RfqSwapManager {
7818
7830
  return;
7819
7831
  }
7820
7832
  if (!partiallyClaimed) {
7821
- if (!Number.isFinite(swap.expectedAmount)) {
7833
+ if (!Number.isSafeInteger(swap.expectedAmount) || swap.expectedAmount <= 0) {
7822
7834
  return this.block(
7823
7835
  swap,
7824
- `expectedAmount is not a finite number (${String(swap.expectedAmount)}), so the funded value cannot be checked \u2014 refusing to publish the preimage`
7836
+ `expectedAmount is not a positive number of sats (${String(swap.expectedAmount)}), so the funded value cannot be checked \u2014 refusing to publish the preimage`
7825
7837
  );
7826
7838
  }
7827
7839
  const locked = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
@@ -8082,6 +8094,9 @@ var RfqSwapManager = class _RfqSwapManager {
8082
8094
  utxo,
8083
8095
  bump ? { bump } : void 0
8084
8096
  );
8097
+ if (swap.funding?.txid !== utxo.txid || swap.funding.vout !== utxo.vout || swap.funding.amount === void 0) {
8098
+ swap.funding = { txid: utxo.txid, vout: utxo.vout, amount: Number(utxo.amount) };
8099
+ }
8085
8100
  swap.claimTxid = txid;
8086
8101
  swap.claimBroadcastAt = this.config.now();
8087
8102
  delete swap.claimConfirmed;
package/dist/index.js CHANGED
@@ -62,7 +62,7 @@ import {
62
62
  unsignedPsbtBytes,
63
63
  verifyJointGraph,
64
64
  verifyOfferFillPlan
65
- } from "./chunk-ZBJGLLYV.js";
65
+ } from "./chunk-I7WEXXZX.js";
66
66
  import {
67
67
  Amount,
68
68
  AmountFormatError,
@@ -73,7 +73,7 @@ import {
73
73
  isRfqSwapTerminal,
74
74
  quoteIdOfSwapId,
75
75
  toAtomicDecimal
76
- } from "./chunk-ISWLKKSS.js";
76
+ } from "./chunk-FQNG4XMF.js";
77
77
  import {
78
78
  CLAIM_PACKET_TYPE,
79
79
  LockupRegistrationFailed,
@@ -83,7 +83,7 @@ import {
83
83
  appendArkadeScript,
84
84
  claimPacketShape,
85
85
  isRfqRefusalErrorCode
86
- } from "./chunk-PDNVKH5L.js";
86
+ } from "./chunk-552GDPBU.js";
87
87
  import "./chunk-5QPJWOCN.js";
88
88
  import {
89
89
  InMemoryAssetSwapRepository,
package/dist/nostr.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  expectQuote,
3
3
  pairOf
4
- } from "./chunk-PDNVKH5L.js";
4
+ } from "./chunk-552GDPBU.js";
5
5
  import "./chunk-5QPJWOCN.js";
6
6
  import "./chunk-A3SHHRX4.js";
7
7
 
package/dist/protocol.cjs CHANGED
@@ -52,9 +52,9 @@ function onchainHtlcScript(params, network) {
52
52
  if (params.claimKey.length !== 32 || params.refundKey.length !== 32) {
53
53
  throw new Error("claimKey and refundKey must be 32-byte x-only keys");
54
54
  }
55
- if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0) {
55
+ if (!Number.isInteger(params.refundLocktime) || params.refundLocktime <= 0 || params.refundLocktime > 4294967295) {
56
56
  throw new Error(
57
- `refundLocktime must be a positive unix timestamp, got ${params.refundLocktime}`
57
+ `refundLocktime must be a positive uint32 unix timestamp, got ${params.refundLocktime}`
58
58
  );
59
59
  }
60
60
  if (params.refundLocktime < LOCKTIME_THRESHOLD) {
@@ -147,15 +147,20 @@ async function claimOnchainFill(chain, input) {
147
147
  }
148
148
  async function classifyOnchainHtlc(chain, input) {
149
149
  const utxos = await chain.getScriptUtxos(input.htlc.pkScript);
150
- const best = utxos.sort((a, b) => b.amount > a.amount ? 1 : -1)[0];
151
- if (!best) {
152
- if (!input.funding) return { phase: "unfunded" };
153
- const spend = await chain.getSpendingTx(
154
- input.funding.txid,
155
- input.funding.vout,
156
- input.htlc.pkScript
157
- );
158
- if (!spend) return { phase: "unfunded" };
150
+ const deep = (u) => u.confirmations >= input.minConfirmations;
151
+ const best = utxos.sort(
152
+ (a, b) => deep(a) !== deep(b) ? deep(a) ? -1 : 1 : b.amount > a.amount ? 1 : -1
153
+ )[0];
154
+ const { funding } = input;
155
+ let spend = null;
156
+ if (funding && !utxos.some((u) => u.txid === funding.txid && u.vout === funding.vout)) {
157
+ try {
158
+ spend = await chain.getSpendingTx(funding.txid, funding.vout, input.htlc.pkScript);
159
+ } catch (error) {
160
+ if (!best) throw error;
161
+ }
162
+ }
163
+ if (spend) {
159
164
  const preimage = extractPreimage(spend.txHex, input.htlc.paymentHash);
160
165
  const txid = btc.Transaction.fromRaw(import_base.hex.decode(spend.txHex), {
161
166
  allowUnknownInputs: true,
@@ -163,6 +168,7 @@ async function classifyOnchainHtlc(chain, input) {
163
168
  }).id;
164
169
  return preimage ? { phase: "claimed", txid, preimage } : { phase: "swept", txid };
165
170
  }
171
+ if (!best) return { phase: "unfunded" };
166
172
  if (best.confirmations < input.minConfirmations)
167
173
  return { phase: "awaiting_confirmations", utxo: best };
168
174
  const mtp = await chain.getMtp();
@@ -3205,6 +3211,9 @@ var init_rfq = __esm({
3205
3211
  if (input.now >= input.payDeadline) {
3206
3212
  throw gateError("quote_expired", "quote or invoice already expired \u2014 request a fresh one");
3207
3213
  }
3214
+ if (quoteAmountSats(input.quote.from_amount, "from_amount") <= 0n || quoteAmountSats(input.quote.to_amount, "to_amount") <= 0n) {
3215
+ throw gateError("non_positive_amount", "quote carries a non-positive amount");
3216
+ }
3208
3217
  if (input.quote.refund_locktime === void 0) {
3209
3218
  throw gateError("missing_refund_locktime", "receive quote carries no refund_locktime");
3210
3219
  }
@@ -5159,10 +5168,10 @@ var RfqSwapManager = class _RfqSwapManager {
5159
5168
  return;
5160
5169
  }
5161
5170
  if (!partiallyClaimed) {
5162
- if (!Number.isFinite(swap.expectedAmount)) {
5171
+ if (!Number.isSafeInteger(swap.expectedAmount) || swap.expectedAmount <= 0) {
5163
5172
  return this.block(
5164
5173
  swap,
5165
- `expectedAmount is not a finite number (${String(swap.expectedAmount)}), so the funded value cannot be checked \u2014 refusing to publish the preimage`
5174
+ `expectedAmount is not a positive number of sats (${String(swap.expectedAmount)}), so the funded value cannot be checked \u2014 refusing to publish the preimage`
5166
5175
  );
5167
5176
  }
5168
5177
  const locked = vtxos.reduce((sum, vtxo) => sum + vtxo.value, 0);
@@ -5423,6 +5432,9 @@ var RfqSwapManager = class _RfqSwapManager {
5423
5432
  utxo,
5424
5433
  bump ? { bump } : void 0
5425
5434
  );
5435
+ if (swap.funding?.txid !== utxo.txid || swap.funding.vout !== utxo.vout || swap.funding.amount === void 0) {
5436
+ swap.funding = { txid: utxo.txid, vout: utxo.vout, amount: Number(utxo.amount) };
5437
+ }
5426
5438
  swap.claimTxid = txid;
5427
5439
  swap.claimBroadcastAt = this.config.now();
5428
5440
  delete swap.claimConfirmed;
@@ -6081,6 +6093,9 @@ async function pushClaim(operator, input) {
6081
6093
  assertFiniteAmount(funded, "lockup_malformed", "the lockup's summed value");
6082
6094
  if (!input.partiallyClaimed) {
6083
6095
  assertFiniteAmount(input.expectedAmount, "invalid_gate_input", "expectedAmount");
6096
+ if (input.expectedAmount <= 0) {
6097
+ throw gateError("invalid_gate_input", "expectedAmount is not positive");
6098
+ }
6084
6099
  if (funded < input.expectedAmount) {
6085
6100
  throw new LockupAmountMismatchError(input.expectedAmount, funded);
6086
6101
  }
package/dist/protocol.js CHANGED
@@ -42,7 +42,7 @@ import {
42
42
  validatePlan,
43
43
  watchMarkets,
44
44
  watchOfferSwaps
45
- } from "./chunk-ISWLKKSS.js";
45
+ } from "./chunk-FQNG4XMF.js";
46
46
  import {
47
47
  ARKADE_BTC,
48
48
  ASSET_CARRIER_SATS,
@@ -130,7 +130,7 @@ import {
130
130
  verifyLockupAddress,
131
131
  verifyOfferAddress,
132
132
  verifyReceiveInvoice
133
- } from "./chunk-PDNVKH5L.js";
133
+ } from "./chunk-552GDPBU.js";
134
134
  import {
135
135
  ASSET_SWAP_BASELINE,
136
136
  ASSET_SWAP_V2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/swap",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "Client-side Arkade Intents asset swaps: state a route, get an outcome. Pay a bolt11 invoice, receive over Lightning, exchange assets, or withdraw onchain.",
6
6
  "repository": {
@@ -114,7 +114,7 @@
114
114
  "@scure/base": "2.4.0",
115
115
  "@scure/btc-signer": "2.4.1",
116
116
  "light-bolt11-decoder": "3.2.0",
117
- "@arkade-os/sdk": "0.5.8"
117
+ "@arkade-os/sdk": "0.5.9"
118
118
  },
119
119
  "peerDependencies": {
120
120
  "nostr-tools": "2.24.1"