@arkade-os/boltz-swap 0.3.31 → 0.3.33

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 (31) hide show
  1. package/README.md +22 -26
  2. package/dist/{arkade-swaps-CS8FZSVL.d.cts → arkade-swaps-9M7FRuq1.d.cts} +57 -5
  3. package/dist/{arkade-swaps-WiKCanCL.d.ts → arkade-swaps-DNsyWeFr.d.ts} +57 -5
  4. package/dist/{chunk-NHBWNN6H.js → chunk-HNQDJOLM.js} +8 -27
  5. package/dist/{chunk-B3Q4TFWT.js → chunk-SJ5SYSMK.js} +551 -779
  6. package/dist/chunk-SJQJQO7P.js +25 -0
  7. package/dist/expo/background.cjs +573 -805
  8. package/dist/expo/background.d.cts +3 -3
  9. package/dist/expo/background.d.ts +3 -3
  10. package/dist/expo/background.js +8 -20
  11. package/dist/expo/index.cjs +574 -783
  12. package/dist/expo/index.d.cts +7 -5
  13. package/dist/expo/index.d.ts +7 -5
  14. package/dist/expo/index.js +17 -20
  15. package/dist/index.cjs +732 -931
  16. package/dist/index.d.cts +80 -10
  17. package/dist/index.d.ts +80 -10
  18. package/dist/index.js +126 -115
  19. package/dist/repositories/realm/index.cjs +10 -22
  20. package/dist/repositories/realm/index.d.cts +7 -5
  21. package/dist/repositories/realm/index.d.ts +7 -5
  22. package/dist/repositories/realm/index.js +8 -22
  23. package/dist/repositories/sqlite/index.cjs +12 -23
  24. package/dist/repositories/sqlite/index.d.cts +1 -1
  25. package/dist/repositories/sqlite/index.d.ts +1 -1
  26. package/dist/repositories/sqlite/index.js +10 -23
  27. package/dist/{swapsPollProcessor-wYOMzldd.d.ts → swapsPollProcessor-CEgeGlbP.d.ts} +3 -3
  28. package/dist/{swapsPollProcessor-BF3uTFae.d.cts → swapsPollProcessor-CuITxZie.d.cts} +3 -3
  29. package/dist/{types-BBI7-KJ0.d.cts → types-CrKkVzBB.d.cts} +9 -3
  30. package/dist/{types-BBI7-KJ0.d.ts → types-CrKkVzBB.d.ts} +9 -3
  31. package/package.json +10 -25
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  InvoiceFailedToPayError,
9
9
  NetworkError,
10
10
  PreimageFetchError,
11
+ QuoteRejectedError,
11
12
  SchemaError,
12
13
  SwapError,
13
14
  SwapExpiredError,
@@ -51,13 +52,17 @@ import {
51
52
  updateReverseSwapStatus,
52
53
  updateSubmarineSwapStatus,
53
54
  verifySignatures
54
- } from "./chunk-B3Q4TFWT.js";
55
+ } from "./chunk-SJ5SYSMK.js";
56
+ import "./chunk-SJQJQO7P.js";
55
57
 
56
58
  // src/serviceWorker/arkade-swaps-message-handler.ts
57
- import {
58
- RestArkProvider,
59
- RestIndexerProvider
60
- } from "@arkade-os/sdk";
59
+ import { RestArkProvider, RestIndexerProvider } from "@arkade-os/sdk";
60
+ function toQuoteTransportError(error) {
61
+ if (error instanceof QuoteRejectedError) {
62
+ return error.toTransportError();
63
+ }
64
+ return error;
65
+ }
61
66
  var DEFAULT_MESSAGE_TAG = "ARKADE_SWAPS_UPDATER";
62
67
  var HANDLER_NOT_INITIALIZED = "ArkadeSwaps handler not initialized";
63
68
  var HandlerNotInitializedError = class extends Error {
@@ -173,9 +178,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
173
178
  try {
174
179
  switch (message.type) {
175
180
  case "CREATE_LIGHTNING_INVOICE": {
176
- const res = await this.handler.createLightningInvoice(
177
- message.payload
178
- );
181
+ const res = await this.handler.createLightningInvoice(message.payload);
179
182
  return this.tagged({
180
183
  id,
181
184
  type: "LIGHTNING_INVOICE_CREATED",
@@ -183,9 +186,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
183
186
  });
184
187
  }
185
188
  case "SEND_LIGHTNING_PAYMENT": {
186
- const res = await this.handler.sendLightningPayment(
187
- message.payload
188
- );
189
+ const res = await this.handler.sendLightningPayment(message.payload);
189
190
  return this.tagged({
190
191
  id,
191
192
  type: "LIGHTNING_PAYMENT_SENT",
@@ -193,9 +194,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
193
194
  });
194
195
  }
195
196
  case "CREATE_SUBMARINE_SWAP": {
196
- const res = await this.handler.createSubmarineSwap(
197
- message.payload
198
- );
197
+ const res = await this.handler.createSubmarineSwap(message.payload);
199
198
  return this.tagged({
200
199
  id,
201
200
  type: "SUBMARINE_SWAP_CREATED",
@@ -203,9 +202,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
203
202
  });
204
203
  }
205
204
  case "CREATE_REVERSE_SWAP": {
206
- const res = await this.handler.createReverseSwap(
207
- message.payload
208
- );
205
+ const res = await this.handler.createReverseSwap(message.payload);
209
206
  return this.tagged({
210
207
  id,
211
208
  type: "REVERSE_SWAP_CREATED",
@@ -216,9 +213,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
216
213
  await this.handler.claimVHTLC(message.payload);
217
214
  return this.tagged({ id, type: "VHTLC_CLAIMED" });
218
215
  case "REFUND_VHTLC": {
219
- const outcome = await this.handler.refundVHTLC(
220
- message.payload
221
- );
216
+ const outcome = await this.handler.refundVHTLC(message.payload);
222
217
  return this.tagged({
223
218
  id,
224
219
  type: "VHTLC_REFUNDED",
@@ -226,9 +221,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
226
221
  });
227
222
  }
228
223
  case "INSPECT_SUBMARINE_RECOVERY": {
229
- const info = await this.handler.inspectSubmarineRecovery(
230
- message.payload
231
- );
224
+ const info = await this.handler.inspectSubmarineRecovery(message.payload);
232
225
  return this.tagged({
233
226
  id,
234
227
  type: "SUBMARINE_RECOVERY_INSPECTED",
@@ -244,9 +237,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
244
237
  });
245
238
  }
246
239
  case "RECOVER_SUBMARINE_FUNDS": {
247
- const outcome = await this.handler.recoverSubmarineFunds(
248
- message.payload
249
- );
240
+ const outcome = await this.handler.recoverSubmarineFunds(message.payload);
250
241
  return this.tagged({
251
242
  id,
252
243
  type: "SUBMARINE_FUNDS_RECOVERED",
@@ -254,9 +245,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
254
245
  });
255
246
  }
256
247
  case "RECOVER_ALL_SUBMARINE_FUNDS": {
257
- const results = await this.handler.recoverAllSubmarineFunds(
258
- message.payload
259
- );
248
+ const results = await this.handler.recoverAllSubmarineFunds(message.payload);
260
249
  return this.tagged({
261
250
  id,
262
251
  type: "ALL_SUBMARINE_FUNDS_RECOVERED",
@@ -264,9 +253,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
264
253
  });
265
254
  }
266
255
  case "WAIT_AND_CLAIM": {
267
- const res = await this.handler.waitAndClaim(
268
- message.payload
269
- );
256
+ const res = await this.handler.waitAndClaim(message.payload);
270
257
  return this.tagged({
271
258
  id,
272
259
  type: "WAIT_AND_CLAIMED",
@@ -274,9 +261,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
274
261
  });
275
262
  }
276
263
  case "WAIT_FOR_SWAP_SETTLEMENT": {
277
- const res = await this.handler.waitForSwapSettlement(
278
- message.payload
279
- );
264
+ const res = await this.handler.waitForSwapSettlement(message.payload);
280
265
  return this.tagged({
281
266
  id,
282
267
  type: "SWAP_SETTLED",
@@ -284,9 +269,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
284
269
  });
285
270
  }
286
271
  case "RESTORE_SWAPS": {
287
- const res = await this.handler.restoreSwaps(
288
- message.payload
289
- );
272
+ const res = await this.handler.restoreSwaps(message.payload);
290
273
  return this.tagged({
291
274
  id,
292
275
  type: "SWAPS_RESTORED",
@@ -316,23 +299,15 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
316
299
  });
317
300
  }
318
301
  case "GET_FEES": {
319
- const res = message.payload ? await this.handler.getFees(
320
- message.payload.from,
321
- message.payload.to
322
- ) : await this.handler.getFees();
302
+ const res = message.payload ? await this.handler.getFees(message.payload.from, message.payload.to) : await this.handler.getFees();
323
303
  return this.tagged({ id, type: "FEES", payload: res });
324
304
  }
325
305
  case "GET_LIMITS": {
326
- const res = message.payload ? await this.handler.getLimits(
327
- message.payload.from,
328
- message.payload.to
329
- ) : await this.handler.getLimits();
306
+ const res = message.payload ? await this.handler.getLimits(message.payload.from, message.payload.to) : await this.handler.getLimits();
330
307
  return this.tagged({ id, type: "LIMITS", payload: res });
331
308
  }
332
309
  case "GET_SWAP_STATUS": {
333
- const res = await this.handler.getSwapStatus(
334
- message.payload.swapId
335
- );
310
+ const res = await this.handler.getSwapStatus(message.payload.swapId);
336
311
  return this.tagged({
337
312
  id,
338
313
  type: "SWAP_STATUS",
@@ -391,9 +366,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
391
366
  });
392
367
  }
393
368
  case "CREATE_CHAIN_SWAP": {
394
- const res = await this.handler.createChainSwap(
395
- message.payload
396
- );
369
+ const res = await this.handler.createChainSwap(message.payload);
397
370
  return this.tagged({
398
371
  id,
399
372
  type: "CHAIN_SWAP_CREATED",
@@ -401,9 +374,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
401
374
  });
402
375
  }
403
376
  case "WAIT_AND_CLAIM_CHAIN": {
404
- const res = await this.handler.waitAndClaimChain(
405
- message.payload
406
- );
377
+ const res = await this.handler.waitAndClaimChain(message.payload);
407
378
  return this.tagged({
408
379
  id,
409
380
  type: "CHAIN_CLAIMED",
@@ -411,9 +382,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
411
382
  });
412
383
  }
413
384
  case "WAIT_AND_CLAIM_ARK": {
414
- const res = await this.handler.waitAndClaimArk(
415
- message.payload
416
- );
385
+ const res = await this.handler.waitAndClaimArk(message.payload);
417
386
  return this.tagged({
418
387
  id,
419
388
  type: "ARK_CLAIMED",
@@ -421,9 +390,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
421
390
  });
422
391
  }
423
392
  case "WAIT_AND_CLAIM_BTC": {
424
- const res = await this.handler.waitAndClaimBtc(
425
- message.payload
426
- );
393
+ const res = await this.handler.waitAndClaimBtc(message.payload);
427
394
  return this.tagged({
428
395
  id,
429
396
  type: "BTC_CLAIMED",
@@ -440,9 +407,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
440
407
  await this.handler.refundArk(message.payload);
441
408
  return this.tagged({ id, type: "ARK_REFUND_EXECUTED" });
442
409
  case "SIGN_SERVER_CLAIM":
443
- await this.handler.signCooperativeClaimForServer(
444
- message.payload
445
- );
410
+ await this.handler.signCooperativeClaimForServer(message.payload);
446
411
  return this.tagged({ id, type: "SERVER_CLAIM_SIGNED" });
447
412
  case "VERIFY_CHAIN_SWAP": {
448
413
  const verified = await this.handler.verifyChainSwap({
@@ -455,14 +420,47 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
455
420
  });
456
421
  }
457
422
  case "QUOTE_SWAP": {
458
- const amount = await this.handler.quoteSwap(
459
- message.payload.swapId
460
- );
461
- return this.tagged({
462
- id,
463
- type: "SWAP_QUOTED",
464
- payload: { amount }
465
- });
423
+ try {
424
+ const amount = await this.handler.quoteSwap(
425
+ message.payload.swapId,
426
+ message.payload.options
427
+ );
428
+ return this.tagged({
429
+ id,
430
+ type: "SWAP_QUOTED",
431
+ payload: { amount }
432
+ });
433
+ } catch (e) {
434
+ throw toQuoteTransportError(e);
435
+ }
436
+ }
437
+ case "GET_SWAP_QUOTE": {
438
+ try {
439
+ const amount = await this.handler.getSwapQuote(message.payload.swapId);
440
+ return this.tagged({
441
+ id,
442
+ type: "SWAP_QUOTE_RETRIEVED",
443
+ payload: { amount }
444
+ });
445
+ } catch (e) {
446
+ throw toQuoteTransportError(e);
447
+ }
448
+ }
449
+ case "ACCEPT_SWAP_QUOTE": {
450
+ try {
451
+ const amount = await this.handler.acceptSwapQuote(
452
+ message.payload.swapId,
453
+ message.payload.amount,
454
+ message.payload.options
455
+ );
456
+ return this.tagged({
457
+ id,
458
+ type: "SWAP_QUOTE_ACCEPTED",
459
+ payload: { amount }
460
+ });
461
+ } catch (e) {
462
+ throw toQuoteTransportError(e);
463
+ }
466
464
  }
467
465
  /* --- SwapManager methods --- */
468
466
  case "SM-START": {
@@ -478,9 +476,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
478
476
  return this.tagged({ id, type: "SM-SWAP_ADDED" });
479
477
  }
480
478
  case "SM-REMOVE_SWAP": {
481
- await this.getSwapManagerOrThrow().removeSwap(
482
- message.payload.swapId
483
- );
479
+ await this.getSwapManagerOrThrow().removeSwap(message.payload.swapId);
484
480
  return this.tagged({ id, type: "SM-SWAP_REMOVED" });
485
481
  }
486
482
  case "SM-GET_PENDING_SWAPS": {
@@ -492,9 +488,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
492
488
  });
493
489
  }
494
490
  case "SM-HAS_SWAP": {
495
- const has = await this.getSwapManagerOrThrow().hasSwap(
496
- message.payload.swapId
497
- );
491
+ const has = await this.getSwapManagerOrThrow().hasSwap(message.payload.swapId);
498
492
  return this.tagged({
499
493
  id,
500
494
  type: "SM-HAS_SWAP_RESULT",
@@ -608,6 +602,7 @@ var ArkadeSwapsMessageHandler = class _ArkadeSwapsMessageHandler {
608
602
 
609
603
  // src/serviceWorker/arkade-swaps-runtime.ts
610
604
  import {
605
+ getRandomId,
611
606
  MESSAGE_BUS_NOT_INITIALIZED,
612
607
  ServiceWorkerTimeoutError
613
608
  } from "@arkade-os/sdk";
@@ -617,6 +612,11 @@ function isMessageBusNotInitializedError(error) {
617
612
  function isHandlerNotInitializedError(error) {
618
613
  return error instanceof Error && error.message.includes(HANDLER_NOT_INITIALIZED);
619
614
  }
615
+ function rethrowIfQuoteRejected(error) {
616
+ if (error instanceof QuoteRejectedError) throw error;
617
+ const rebuilt = QuoteRejectedError.fromTransportError(error);
618
+ if (rebuilt) throw rebuilt;
619
+ }
620
620
  var DEFAULT_MESSAGE_TIMEOUT_MS = 3e4;
621
621
  var NO_MESSAGE_TIMEOUT_MS = 0;
622
622
  var DEDUPABLE_REQUEST_TYPES = /* @__PURE__ */ new Set([
@@ -1117,19 +1117,48 @@ var ServiceWorkerArkadeSwaps = class _ServiceWorkerArkadeSwaps {
1117
1117
  throw new Error("Cannot verify chain swap", { cause: e });
1118
1118
  }
1119
1119
  }
1120
- async quoteSwap(swapId) {
1120
+ async quoteSwap(swapId, options) {
1121
1121
  try {
1122
1122
  const res = await this.sendMessage({
1123
1123
  id: getRandomId(),
1124
1124
  tag: this.messageTag,
1125
1125
  type: "QUOTE_SWAP",
1126
- payload: { swapId }
1126
+ payload: { swapId, options }
1127
1127
  });
1128
1128
  return res.payload.amount;
1129
1129
  } catch (e) {
1130
+ rethrowIfQuoteRejected(e);
1130
1131
  throw new Error("Cannot quote swap", { cause: e });
1131
1132
  }
1132
1133
  }
1134
+ async getSwapQuote(swapId) {
1135
+ try {
1136
+ const res = await this.sendMessage({
1137
+ id: getRandomId(),
1138
+ tag: this.messageTag,
1139
+ type: "GET_SWAP_QUOTE",
1140
+ payload: { swapId }
1141
+ });
1142
+ return res.payload.amount;
1143
+ } catch (e) {
1144
+ rethrowIfQuoteRejected(e);
1145
+ throw new Error("Cannot get swap quote", { cause: e });
1146
+ }
1147
+ }
1148
+ async acceptSwapQuote(swapId, amount, options) {
1149
+ try {
1150
+ const res = await this.sendMessage({
1151
+ id: getRandomId(),
1152
+ tag: this.messageTag,
1153
+ type: "ACCEPT_SWAP_QUOTE",
1154
+ payload: { swapId, amount, options }
1155
+ });
1156
+ return res.payload.amount;
1157
+ } catch (e) {
1158
+ rethrowIfQuoteRejected(e);
1159
+ throw new Error("Cannot accept swap quote", { cause: e });
1160
+ }
1161
+ }
1133
1162
  enrichReverseSwapPreimage(swap, preimage) {
1134
1163
  return enrichReverseSwapPreimage(swap, preimage);
1135
1164
  }
@@ -1137,9 +1166,7 @@ var ServiceWorkerArkadeSwaps = class _ServiceWorkerArkadeSwaps {
1137
1166
  return enrichSubmarineSwapInvoice(swap, invoice);
1138
1167
  }
1139
1168
  createVHTLCScript(_args) {
1140
- throw new Error(
1141
- "createVHTLCScript is not supported via service worker"
1142
- );
1169
+ throw new Error("createVHTLCScript is not supported via service worker");
1143
1170
  }
1144
1171
  async joinBatch(_identity, _input, _output, _arkInfo, _isRecoverable = true) {
1145
1172
  throw new Error("joinBatch is not supported via service worker");
@@ -1269,10 +1296,7 @@ var ServiceWorkerArkadeSwaps = class _ServiceWorkerArkadeSwaps {
1269
1296
  return new Promise((resolve, reject) => {
1270
1297
  const cleanup = () => {
1271
1298
  clearTimeout(timeoutId);
1272
- navigator.serviceWorker.removeEventListener(
1273
- "message",
1274
- messageHandler
1275
- );
1299
+ navigator.serviceWorker.removeEventListener("message", messageHandler);
1276
1300
  };
1277
1301
  const timeoutId = timeoutMs > 0 ? setTimeout(() => {
1278
1302
  cleanup();
@@ -1317,18 +1341,11 @@ var ServiceWorkerArkadeSwaps = class _ServiceWorkerArkadeSwaps {
1317
1341
  const pingId = getRandomId();
1318
1342
  const cleanup = () => {
1319
1343
  clearTimeout(timeoutId);
1320
- navigator.serviceWorker.removeEventListener(
1321
- "message",
1322
- onMessage
1323
- );
1344
+ navigator.serviceWorker.removeEventListener("message", onMessage);
1324
1345
  };
1325
1346
  const timeoutId = setTimeout(() => {
1326
1347
  cleanup();
1327
- reject(
1328
- new ServiceWorkerTimeoutError(
1329
- "Service worker ping timed out"
1330
- )
1331
- );
1348
+ reject(new ServiceWorkerTimeoutError("Service worker ping timed out"));
1332
1349
  }, 2e3);
1333
1350
  const onMessage = (event) => {
1334
1351
  if (event.data?.id === pingId && event.data?.tag === "PONG") {
@@ -1356,9 +1373,7 @@ var ServiceWorkerArkadeSwaps = class _ServiceWorkerArkadeSwaps {
1356
1373
  await this.reinitialize();
1357
1374
  }
1358
1375
  }
1359
- const timeoutMs = LONG_RUNNING_ARKADE_SWAPS_REQUEST_TYPES.has(
1360
- request.type
1361
- ) ? NO_MESSAGE_TIMEOUT_MS : DEFAULT_MESSAGE_TIMEOUT_MS;
1376
+ const timeoutMs = LONG_RUNNING_ARKADE_SWAPS_REQUEST_TYPES.has(request.type) ? NO_MESSAGE_TIMEOUT_MS : DEFAULT_MESSAGE_TIMEOUT_MS;
1362
1377
  const maxRetries = 2;
1363
1378
  for (let attempt = 0; ; attempt++) {
1364
1379
  try {
@@ -1384,10 +1399,7 @@ var ServiceWorkerArkadeSwaps = class _ServiceWorkerArkadeSwaps {
1384
1399
  id: getRandomId(),
1385
1400
  payload: this.initPayload
1386
1401
  };
1387
- await this.sendMessageDirect(
1388
- initMessage,
1389
- DEFAULT_MESSAGE_TIMEOUT_MS
1390
- );
1402
+ await this.sendMessageDirect(initMessage, DEFAULT_MESSAGE_TIMEOUT_MS);
1391
1403
  })().finally(() => {
1392
1404
  this.reinitPromise = null;
1393
1405
  });
@@ -1396,10 +1408,7 @@ var ServiceWorkerArkadeSwaps = class _ServiceWorkerArkadeSwaps {
1396
1408
  initEventStream() {
1397
1409
  if (this.eventListenerInitialized) return;
1398
1410
  this.eventListenerInitialized = true;
1399
- navigator.serviceWorker.addEventListener(
1400
- "message",
1401
- this.handleEventMessage
1402
- );
1411
+ navigator.serviceWorker.addEventListener("message", this.handleEventMessage);
1403
1412
  }
1404
1413
  handleEventMessage = (event) => {
1405
1414
  const data = event.data;
@@ -1446,9 +1455,6 @@ var ServiceWorkerArkadeSwaps = class _ServiceWorkerArkadeSwaps {
1446
1455
  }
1447
1456
  };
1448
1457
  };
1449
- function getRandomId() {
1450
- return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 10)}`;
1451
- }
1452
1458
 
1453
1459
  // src/repositories/migrationFromContracts.ts
1454
1460
  var MIGRATION_KEY = "migration-from-storage-adapter-swaps";
@@ -1458,8 +1464,14 @@ async function migrateToSwapRepository(storageAdapter, fresh) {
1458
1464
  if (migration === "done") {
1459
1465
  return false;
1460
1466
  }
1461
- const reverseSwaps = await getContractCollection(storageAdapter, "reverseSwaps");
1462
- const submarineSwaps = await getContractCollection(storageAdapter, "submarineSwaps");
1467
+ const reverseSwaps = await getContractCollection(
1468
+ storageAdapter,
1469
+ "reverseSwaps"
1470
+ );
1471
+ const submarineSwaps = await getContractCollection(
1472
+ storageAdapter,
1473
+ "submarineSwaps"
1474
+ );
1463
1475
  for (const swap of reverseSwaps) {
1464
1476
  await fresh.saveSwap(swap);
1465
1477
  }
@@ -1469,9 +1481,7 @@ async function migrateToSwapRepository(storageAdapter, fresh) {
1469
1481
  await storageAdapter.setItem(MIGRATION_KEY, "done");
1470
1482
  return true;
1471
1483
  } catch (error) {
1472
- if (error instanceof Error && error.message.includes(
1473
- "One of the specified object stores was not found."
1474
- )) {
1484
+ if (error instanceof Error && error.message.includes("One of the specified object stores was not found.")) {
1475
1485
  return false;
1476
1486
  }
1477
1487
  throw error;
@@ -1501,6 +1511,7 @@ export {
1501
1511
  InvoiceFailedToPayError,
1502
1512
  NetworkError,
1503
1513
  PreimageFetchError,
1514
+ QuoteRejectedError,
1504
1515
  SchemaError,
1505
1516
  ServiceWorkerArkadeSwaps as ServiceWorkerArkadeLightning,
1506
1517
  ServiceWorkerArkadeSwaps,
@@ -26,9 +26,14 @@ __export(realm_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(realm_exports);
28
28
 
29
+ // src/repositories/swap-repository.ts
30
+ function hasImpossibleSwapsFilter(filter) {
31
+ if (!filter) return false;
32
+ return Array.isArray(filter.id) && filter.id.length === 0 || Array.isArray(filter.status) && filter.status.length === 0 || Array.isArray(filter.type) && filter.type.length === 0;
33
+ }
34
+
29
35
  // src/repositories/realm/swap-repository.ts
30
36
  var RealmSwapRepository = class {
31
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
32
37
  constructor(realm) {
33
38
  this.realm = realm;
34
39
  }
@@ -66,21 +71,13 @@ var RealmSwapRepository = class {
66
71
  }
67
72
  async getAllSwaps(filter) {
68
73
  await this.ensureInit();
69
- if (Array.isArray(filter?.id) && filter.id.length === 0 || Array.isArray(filter?.status) && filter.status.length === 0 || Array.isArray(filter?.type) && filter.type.length === 0) {
70
- return [];
71
- }
74
+ if (hasImpossibleSwapsFilter(filter)) return [];
72
75
  let results = this.realm.objects("BoltzSwap");
73
76
  if (filter) {
74
77
  const filterParts = [];
75
78
  const filterArgs = [];
76
79
  let argIndex = 0;
77
- argIndex = this.addFilterCondition(
78
- filterParts,
79
- filterArgs,
80
- "id",
81
- filter.id,
82
- argIndex
83
- );
80
+ argIndex = this.addFilterCondition(filterParts, filterArgs, "id", filter.id, argIndex);
84
81
  argIndex = this.addFilterCondition(
85
82
  filterParts,
86
83
  filterArgs,
@@ -88,13 +85,7 @@ var RealmSwapRepository = class {
88
85
  filter.status,
89
86
  argIndex
90
87
  );
91
- this.addFilterCondition(
92
- filterParts,
93
- filterArgs,
94
- "type",
95
- filter.type,
96
- argIndex
97
- );
88
+ this.addFilterCondition(filterParts, filterArgs, "type", filter.type, argIndex);
98
89
  if (filterParts.length > 0) {
99
90
  const query = filterParts.join(" AND ");
100
91
  results = results.filtered(query, ...filterArgs);
@@ -104,10 +95,7 @@ var RealmSwapRepository = class {
104
95
  const reverse = filter.orderDirection === "desc";
105
96
  results = results.sorted("createdAt", reverse);
106
97
  }
107
- return [...results].map(
108
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
109
- (obj) => JSON.parse(obj.data)
110
- );
98
+ return [...results].map((obj) => JSON.parse(obj.data));
111
99
  }
112
100
  async clear() {
113
101
  await this.ensureInit();
@@ -1,12 +1,14 @@
1
- import { m as SwapRepository, B as BoltzSwap, o as GetSwapsFilter } from '../../types-BBI7-KJ0.cjs';
1
+ import { RealmLike } from '@arkade-os/sdk/repositories/realm';
2
+ import { m as SwapRepository, B as BoltzSwap, o as GetSwapsFilter } from '../../types-CrKkVzBB.cjs';
2
3
  import '@arkade-os/sdk';
3
4
 
4
5
  /**
5
6
  * Realm-based implementation of SwapRepository.
6
7
  *
7
- * Since `realm` is a peer dependency and not installed in this package,
8
- * the Realm instance is typed as `any`. Consumers must open Realm with
9
- * the schemas from `./schemas.ts` and pass the instance to the constructor.
8
+ * `realm` is a peer dependency and not installed in this package; consumers
9
+ * open Realm with the schemas from `./schemas.ts` and pass the instance to
10
+ * the constructor, where it is validated against the shared `RealmLike`
11
+ * shape exported by `@arkade-os/sdk`.
10
12
  *
11
13
  * Realm handles schema creation on open, so `ensureInit()` is a no-op.
12
14
  * The consumer owns the Realm lifecycle — `[Symbol.asyncDispose]` is a no-op.
@@ -14,7 +16,7 @@ import '@arkade-os/sdk';
14
16
  declare class RealmSwapRepository implements SwapRepository {
15
17
  private readonly realm;
16
18
  readonly version: 1;
17
- constructor(realm: any);
19
+ constructor(realm: RealmLike);
18
20
  private ensureInit;
19
21
  [Symbol.asyncDispose](): Promise<void>;
20
22
  saveSwap<T extends BoltzSwap>(swap: T): Promise<void>;
@@ -1,12 +1,14 @@
1
- import { m as SwapRepository, B as BoltzSwap, o as GetSwapsFilter } from '../../types-BBI7-KJ0.js';
1
+ import { RealmLike } from '@arkade-os/sdk/repositories/realm';
2
+ import { m as SwapRepository, B as BoltzSwap, o as GetSwapsFilter } from '../../types-CrKkVzBB.js';
2
3
  import '@arkade-os/sdk';
3
4
 
4
5
  /**
5
6
  * Realm-based implementation of SwapRepository.
6
7
  *
7
- * Since `realm` is a peer dependency and not installed in this package,
8
- * the Realm instance is typed as `any`. Consumers must open Realm with
9
- * the schemas from `./schemas.ts` and pass the instance to the constructor.
8
+ * `realm` is a peer dependency and not installed in this package; consumers
9
+ * open Realm with the schemas from `./schemas.ts` and pass the instance to
10
+ * the constructor, where it is validated against the shared `RealmLike`
11
+ * shape exported by `@arkade-os/sdk`.
10
12
  *
11
13
  * Realm handles schema creation on open, so `ensureInit()` is a no-op.
12
14
  * The consumer owns the Realm lifecycle — `[Symbol.asyncDispose]` is a no-op.
@@ -14,7 +16,7 @@ import '@arkade-os/sdk';
14
16
  declare class RealmSwapRepository implements SwapRepository {
15
17
  private readonly realm;
16
18
  readonly version: 1;
17
- constructor(realm: any);
19
+ constructor(realm: RealmLike);
18
20
  private ensureInit;
19
21
  [Symbol.asyncDispose](): Promise<void>;
20
22
  saveSwap<T extends BoltzSwap>(swap: T): Promise<void>;
@@ -1,6 +1,9 @@
1
+ import {
2
+ hasImpossibleSwapsFilter
3
+ } from "../../chunk-SJQJQO7P.js";
4
+
1
5
  // src/repositories/realm/swap-repository.ts
2
6
  var RealmSwapRepository = class {
3
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
7
  constructor(realm) {
5
8
  this.realm = realm;
6
9
  }
@@ -38,21 +41,13 @@ var RealmSwapRepository = class {
38
41
  }
39
42
  async getAllSwaps(filter) {
40
43
  await this.ensureInit();
41
- if (Array.isArray(filter?.id) && filter.id.length === 0 || Array.isArray(filter?.status) && filter.status.length === 0 || Array.isArray(filter?.type) && filter.type.length === 0) {
42
- return [];
43
- }
44
+ if (hasImpossibleSwapsFilter(filter)) return [];
44
45
  let results = this.realm.objects("BoltzSwap");
45
46
  if (filter) {
46
47
  const filterParts = [];
47
48
  const filterArgs = [];
48
49
  let argIndex = 0;
49
- argIndex = this.addFilterCondition(
50
- filterParts,
51
- filterArgs,
52
- "id",
53
- filter.id,
54
- argIndex
55
- );
50
+ argIndex = this.addFilterCondition(filterParts, filterArgs, "id", filter.id, argIndex);
56
51
  argIndex = this.addFilterCondition(
57
52
  filterParts,
58
53
  filterArgs,
@@ -60,13 +55,7 @@ var RealmSwapRepository = class {
60
55
  filter.status,
61
56
  argIndex
62
57
  );
63
- this.addFilterCondition(
64
- filterParts,
65
- filterArgs,
66
- "type",
67
- filter.type,
68
- argIndex
69
- );
58
+ this.addFilterCondition(filterParts, filterArgs, "type", filter.type, argIndex);
70
59
  if (filterParts.length > 0) {
71
60
  const query = filterParts.join(" AND ");
72
61
  results = results.filtered(query, ...filterArgs);
@@ -76,10 +65,7 @@ var RealmSwapRepository = class {
76
65
  const reverse = filter.orderDirection === "desc";
77
66
  results = results.sorted("createdAt", reverse);
78
67
  }
79
- return [...results].map(
80
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
- (obj) => JSON.parse(obj.data)
82
- );
68
+ return [...results].map((obj) => JSON.parse(obj.data));
83
69
  }
84
70
  async clear() {
85
71
  await this.ensureInit();