@arkade-os/swap 0.1.0-rc.21 → 0.1.0-rc.23
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/README.md +7 -2
- package/dist/advanced.cjs +875 -129
- package/dist/advanced.d.cts +158 -14
- package/dist/advanced.d.ts +158 -14
- package/dist/advanced.js +255 -4
- package/dist/{chunk-ITFCQWPG.js → chunk-DQ2DY2L2.js} +223 -11
- package/dist/{chunk-HUQQVBC4.js → chunk-MZX62KMU.js} +220 -12
- package/dist/{chunk-PVB7EBAM.js → chunk-UFJEO4VV.js} +47 -21
- package/dist/{errors-hm7aqnRM.d.cts → errors-5q4e3PnH.d.cts} +48 -16
- package/dist/{errors-C3h8ANmE.d.ts → errors-DQ35FKJf.d.ts} +48 -16
- package/dist/index.cjs +670 -185
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -3
- package/dist/node/index.d.cts +26 -4
- package/dist/node/index.d.ts +26 -4
- package/dist/nostr.cjs +12 -9
- package/dist/nostr.d.cts +1 -1
- package/dist/nostr.d.ts +1 -1
- package/dist/nostr.js +3 -1
- package/dist/{offer-Bd9Yvd8Z.d.ts → offer--IpfzhIm.d.ts} +1 -1
- package/dist/{offer-F88rtL_I.d.cts → offer-DqTXQeP1.d.cts} +1 -1
- package/dist/protocol.cjs +395 -156
- package/dist/protocol.d.cts +45 -8
- package/dist/protocol.d.ts +45 -8
- package/dist/protocol.js +10 -3
- package/dist/repositories/realm/index.d.cts +2 -2
- package/dist/repositories/realm/index.d.ts +2 -2
- package/dist/repositories/sqlite/index.d.cts +2 -2
- package/dist/repositories/sqlite/index.d.ts +2 -2
- package/dist/{repository-DYnRLPt-.d.ts → repository-B4rQWmS2.d.cts} +88 -20
- package/dist/{repository-BuYWGAKz.d.cts → repository-D_qvJk1S.d.ts} +88 -20
- package/dist/{rfq-60PGpQ_x.d.cts → rfq-BgdgO9OO.d.cts} +16 -7
- package/dist/{rfq-60PGpQ_x.d.ts → rfq-BgdgO9OO.d.ts} +16 -7
- package/dist/{watch-BTyiBLSd.d.ts → watch-BkPz0vf8.d.ts} +1 -1
- package/dist/{watch-M_KY-5ho.d.cts → watch-RRhKuBkh.d.cts} +1 -1
- package/package.json +3 -3
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
sleep,
|
|
24
24
|
swapSecretsToRecord,
|
|
25
25
|
updateAssetSwapBestEffort
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-UFJEO4VV.js";
|
|
27
27
|
import {
|
|
28
28
|
collectRfqSwaps
|
|
29
29
|
} from "./chunk-A3SHHRX4.js";
|
|
@@ -255,9 +255,80 @@ var OnchainSendCorridor = {
|
|
|
255
255
|
// Our own L1 claim only: `funding` is the solver's tx, not a row this wallet made.
|
|
256
256
|
activityTxids: (profile) => profile.claimTxid ? [profile.claimTxid] : []
|
|
257
257
|
};
|
|
258
|
+
function onchainReceiveProfile(result) {
|
|
259
|
+
return {
|
|
260
|
+
claimKey: hex.encode(result.htlcParams.claimKey),
|
|
261
|
+
refundKey: hex.encode(result.htlcParams.refundKey),
|
|
262
|
+
htlcLocktime: result.htlcParams.refundLocktime,
|
|
263
|
+
network: result.l1Network,
|
|
264
|
+
htlcAddress: result.htlc.address,
|
|
265
|
+
minConfirmations: result.minConfirmations,
|
|
266
|
+
refundPkScript: hex.encode(result.refundPkScript),
|
|
267
|
+
...result.refundDescriptor === void 0 ? {} : { refundDescriptor: result.refundDescriptor }
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
var OnchainReceiveCorridor = {
|
|
271
|
+
kind: "onchain_receive",
|
|
272
|
+
project: (swap) => {
|
|
273
|
+
const receive = swap;
|
|
274
|
+
return {
|
|
275
|
+
expectedAmount: receive.expectedAmount,
|
|
276
|
+
...receive.claimTxid ? { claimTxid: receive.claimTxid } : {},
|
|
277
|
+
...receive.funding ? { funding: receive.funding } : {}
|
|
278
|
+
};
|
|
279
|
+
},
|
|
280
|
+
hydrate(profile) {
|
|
281
|
+
const { paymentHash } = hydrateHashlock(profile);
|
|
282
|
+
if (typeof profile.expectedAmount !== "number" || !Number.isFinite(profile.expectedAmount)) {
|
|
283
|
+
throw new Error("onchain_receive record carries no expectedAmount; it cannot claim");
|
|
284
|
+
}
|
|
285
|
+
if (!profile.claimKey || !profile.refundKey) {
|
|
286
|
+
throw new Error(
|
|
287
|
+
"onchain_receive record carries no L1 keys; its HTLC cannot be rebuilt and the trader's own funding could never be taken back"
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
if (!Number.isInteger(profile.minConfirmations) || profile.minConfirmations < 1) {
|
|
291
|
+
throw new Error(
|
|
292
|
+
`onchain_receive record carries no usable minConfirmations (${String(profile.minConfirmations)}); the confirmation gate cannot be checked`
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
if (!profile.refundPkScript) {
|
|
296
|
+
throw new Error(
|
|
297
|
+
"onchain_receive record carries no refundPkScript; its L1 refund could not be built, so the trader's funding would be stranded"
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
const htlc = onchainHtlcScript(
|
|
301
|
+
{
|
|
302
|
+
paymentHash,
|
|
303
|
+
claimKey: hex.decode(profile.claimKey),
|
|
304
|
+
refundKey: hex.decode(profile.refundKey),
|
|
305
|
+
refundLocktime: profile.htlcLocktime
|
|
306
|
+
},
|
|
307
|
+
profile.network
|
|
308
|
+
);
|
|
309
|
+
if (htlc.address !== profile.htlcAddress) {
|
|
310
|
+
throw new Error(
|
|
311
|
+
`onchain_receive record's L1 inputs derive ${htlc.address}, but the funding went to ${String(profile.htlcAddress)} \u2014 these are not this swap's`
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
return {
|
|
315
|
+
paymentHash,
|
|
316
|
+
htlc,
|
|
317
|
+
expectedAmount: profile.expectedAmount,
|
|
318
|
+
minConfirmations: profile.minConfirmations,
|
|
319
|
+
refundPkScript: hex.decode(profile.refundPkScript),
|
|
320
|
+
...profile.claimTxid ? { claimTxid: profile.claimTxid } : {},
|
|
321
|
+
...profile.funding ? { funding: profile.funding } : {}
|
|
322
|
+
};
|
|
323
|
+
},
|
|
324
|
+
claimSecret: (profile) => ({ ...profile.signer, ...profile.hashlock }),
|
|
325
|
+
// The L1 refund is the record's own `refundTxid`, read by the activity resolver directly.
|
|
326
|
+
activityTxids: (profile) => profile.claimTxid ? [profile.claimTxid] : []
|
|
327
|
+
};
|
|
258
328
|
rfqCorridorHandlers.register(LightningSendCorridor);
|
|
259
329
|
rfqCorridorHandlers.register(LightningReceiveCorridor);
|
|
260
330
|
rfqCorridorHandlers.register(OnchainSendCorridor);
|
|
331
|
+
rfqCorridorHandlers.register(OnchainReceiveCorridor);
|
|
261
332
|
|
|
262
333
|
// src/client/corridors/lightning.ts
|
|
263
334
|
import { invoiceTarget } from "@arkade-os/sdk";
|
|
@@ -350,6 +421,14 @@ var ONCHAIN_DRIVE = {
|
|
|
350
421
|
],
|
|
351
422
|
actions: ["claimOnchain", "refundArkade"],
|
|
352
423
|
seams: ["indexer", "chain"]
|
|
424
|
+
},
|
|
425
|
+
give: {
|
|
426
|
+
lockups: [
|
|
427
|
+
{ covenant: "arkade_lockup", owner: "solver", deadline: "refund_locktime" },
|
|
428
|
+
{ covenant: "onchain_htlc", owner: "trader", deadline: "htlc_refund_locktime" }
|
|
429
|
+
],
|
|
430
|
+
actions: ["claimLockup", "refundOnchain"],
|
|
431
|
+
seams: ["indexer", "chain"]
|
|
353
432
|
}
|
|
354
433
|
};
|
|
355
434
|
var onchainCorridor = Object.assign(
|
|
@@ -385,12 +464,14 @@ var onchainCorridor = Object.assign(
|
|
|
385
464
|
var CORRIDOR_PASS = {
|
|
386
465
|
lightning_send: LIGHTNING_DRIVE.take,
|
|
387
466
|
lightning_receive: LIGHTNING_DRIVE.give,
|
|
388
|
-
onchain_send: ONCHAIN_DRIVE.take
|
|
467
|
+
onchain_send: ONCHAIN_DRIVE.take,
|
|
468
|
+
onchain_receive: ONCHAIN_DRIVE.give
|
|
389
469
|
};
|
|
390
470
|
var LOCKUP_OWNER = {
|
|
391
471
|
lightning_send: CORRIDOR_PASS.lightning_send.lockups[0].owner,
|
|
392
472
|
lightning_receive: CORRIDOR_PASS.lightning_receive.lockups[0].owner,
|
|
393
|
-
onchain_send: CORRIDOR_PASS.onchain_send.lockups[0].owner
|
|
473
|
+
onchain_send: CORRIDOR_PASS.onchain_send.lockups[0].owner,
|
|
474
|
+
onchain_receive: CORRIDOR_PASS.onchain_receive.lockups[0].owner
|
|
394
475
|
};
|
|
395
476
|
var readsChain = (kind) => CORRIDOR_PASS[kind].seams.includes("chain");
|
|
396
477
|
var at = (outcome) => () => outcome;
|
|
@@ -412,8 +493,9 @@ var CORRIDOR_OUTCOME = {
|
|
|
412
493
|
needs_counterparty: at("needs_recovery"),
|
|
413
494
|
// Matched by the hash, not our txid, so a claim that lands without us counts.
|
|
414
495
|
settled: at("claimed"),
|
|
415
|
-
// The inversion: a receive lockup's non-claim leaves are all the solver's.
|
|
416
|
-
refunded
|
|
496
|
+
// The inversion: a receive lockup's non-claim leaves are all the solver's. On
|
|
497
|
+
// `onchain_receive` the swap is `refunded` only once the trader's own L1 half is.
|
|
498
|
+
refunded: (kind) => kind === "onchain_receive" ? "refunded" : "lapsed",
|
|
417
499
|
failed: at("failed")
|
|
418
500
|
}
|
|
419
501
|
};
|
|
@@ -459,6 +541,7 @@ var ACTIVITY_TOKEN = {
|
|
|
459
541
|
import { base64, hex as hex2 } from "@scure/base";
|
|
460
542
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
461
543
|
import {
|
|
544
|
+
assertTimerMs,
|
|
462
545
|
ConditionWitness,
|
|
463
546
|
Transaction,
|
|
464
547
|
assertSubmittedArkTxid,
|
|
@@ -652,6 +735,7 @@ async function pushRefundWithoutReceiver(operator, input) {
|
|
|
652
735
|
var REFUND_MTP_LAG_SECONDS = 2 * 60 * 60;
|
|
653
736
|
async function refundIfUnresolved(transport, operator, contracts, indexer, input) {
|
|
654
737
|
const pollMs = input.pollMs ?? 5e3;
|
|
738
|
+
assertTimerMs("pollMs", pollMs);
|
|
655
739
|
const now = input.now ?? (() => Math.floor(Date.now() / 1e3));
|
|
656
740
|
const attemptDeadline = input.attemptDeadline ?? input.refundLocktime + REFUND_MTP_LAG_SECONDS;
|
|
657
741
|
for (; ; ) {
|
|
@@ -708,7 +792,7 @@ import {
|
|
|
708
792
|
registryIndexUrl,
|
|
709
793
|
sideLimits
|
|
710
794
|
} from "@arkade-os/solver-discovery";
|
|
711
|
-
import { isSubdust } from "@arkade-os/sdk";
|
|
795
|
+
import { assertNonNegativeMs, isSubdust } from "@arkade-os/sdk";
|
|
712
796
|
|
|
713
797
|
// src/marketShape.ts
|
|
714
798
|
var MARKET_CORRIDORS = ["arkade", "bolt11", "bitcoin", "eip155"];
|
|
@@ -749,6 +833,7 @@ var marketPairLabel = (market) => `${sideLabel(market, "base")}/${sideLabel(mark
|
|
|
749
833
|
// src/markets.ts
|
|
750
834
|
var QUOTE_OPTIONS = { safetyBps: 0 };
|
|
751
835
|
var makeCachedFeedFetch = (ttlMs = 3e4, fetchImpl = fetch) => {
|
|
836
|
+
assertNonNegativeMs("ttlMs", ttlMs);
|
|
752
837
|
const cache = /* @__PURE__ */ new Map();
|
|
753
838
|
const inflight = /* @__PURE__ */ new Map();
|
|
754
839
|
return async (input, init) => {
|
|
@@ -1393,6 +1478,7 @@ function arkadeRefunder(deps) {
|
|
|
1393
1478
|
import { hex as hex5 } from "@scure/base";
|
|
1394
1479
|
import {
|
|
1395
1480
|
ArkErrorName,
|
|
1481
|
+
assertTimerMs as assertTimerMs2,
|
|
1396
1482
|
isArkError,
|
|
1397
1483
|
isContractVtxoEvent,
|
|
1398
1484
|
maybeArkError
|
|
@@ -1412,12 +1498,29 @@ function nextOnchainAction(input) {
|
|
|
1412
1498
|
return input.htlcLocktime - input.now >= ONCHAIN_CLAIM_MARGIN_SECONDS ? "claim" : "claim_window_closed";
|
|
1413
1499
|
}
|
|
1414
1500
|
}
|
|
1501
|
+
function nextOnchainReceiveAction(input) {
|
|
1502
|
+
switch (input.phase.phase) {
|
|
1503
|
+
case "unfunded":
|
|
1504
|
+
case "awaiting_confirmations":
|
|
1505
|
+
case "claimable":
|
|
1506
|
+
return "wait";
|
|
1507
|
+
case "claimed":
|
|
1508
|
+
return "taken";
|
|
1509
|
+
case "swept":
|
|
1510
|
+
return "refunded";
|
|
1511
|
+
case "refundable":
|
|
1512
|
+
return input.settled ? "taken" : "refund";
|
|
1513
|
+
}
|
|
1514
|
+
}
|
|
1415
1515
|
var RFQ_CONFIGURATION_REFUSAL = {
|
|
1416
1516
|
noClaimLockupCallback: "no claimLockup callback is wired, so this wallet cannot claim the lockup",
|
|
1417
1517
|
noCallbacksForClaim: "no callbacks are wired, so this wallet cannot claim the lockup",
|
|
1418
1518
|
noClaimOnchainCallback: "no claimOnchain callback is wired, so this wallet cannot claim the L1 fill",
|
|
1419
1519
|
autoActionsDisabled: "automatic actions are disabled, so this wallet will not push the refund",
|
|
1420
|
-
noCallbacksForRefund: "no callbacks are wired, so this wallet cannot push the refund"
|
|
1520
|
+
noCallbacksForRefund: "no callbacks are wired, so this wallet cannot push the refund",
|
|
1521
|
+
noRefundOnchainCallback: "no refundOnchain callback is wired, so this wallet cannot take the L1 funding back",
|
|
1522
|
+
noCallbacksForL1Refund: "no callbacks are wired, so this wallet cannot take the L1 funding back",
|
|
1523
|
+
autoActionsDisabledForL1Refund: "automatic actions are disabled, so this wallet will not push the L1 refund"
|
|
1421
1524
|
};
|
|
1422
1525
|
var RFQ_CONFIGURATION_REFUSALS = Object.values(RFQ_CONFIGURATION_REFUSAL);
|
|
1423
1526
|
var isRfqConfigurationRefusal = (reason) => reason !== void 0 && RFQ_CONFIGURATION_REFUSALS.includes(reason);
|
|
@@ -1432,6 +1535,16 @@ var RfqSwapOriginRequired = class extends Error {
|
|
|
1432
1535
|
this.rfqId = rfqId;
|
|
1433
1536
|
}
|
|
1434
1537
|
};
|
|
1538
|
+
var OnchainReceiveNeedsChainSource = class extends Error {
|
|
1539
|
+
rfqId;
|
|
1540
|
+
constructor(rfqId) {
|
|
1541
|
+
super(
|
|
1542
|
+
`rfq swap ${rfqId} is an onchain_receive swap and this manager has no ChainSource; its L1 refund could be neither seen nor made, so it is refused rather than monitored blind`
|
|
1543
|
+
);
|
|
1544
|
+
this.name = "OnchainReceiveNeedsChainSource";
|
|
1545
|
+
this.rfqId = rfqId;
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1435
1548
|
var notify = (listeners, call) => {
|
|
1436
1549
|
for (const listener of listeners) {
|
|
1437
1550
|
try {
|
|
@@ -1496,6 +1609,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
1496
1609
|
timer = null;
|
|
1497
1610
|
running = false;
|
|
1498
1611
|
constructor(deps, config = {}) {
|
|
1612
|
+
assertTimerMs2("pollIntervalMs", config.pollIntervalMs);
|
|
1499
1613
|
this.deps = deps;
|
|
1500
1614
|
this.config = {
|
|
1501
1615
|
enableAutoActions: config.enableAutoActions ?? true,
|
|
@@ -1551,6 +1665,9 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
1551
1665
|
let swap;
|
|
1552
1666
|
try {
|
|
1553
1667
|
swap = rebuildRfqSwap(record, await params(record));
|
|
1668
|
+
if (swap.kind === "onchain_receive" && !this.deps.chain) {
|
|
1669
|
+
throw new OnchainReceiveNeedsChainSource(swap.rfqId);
|
|
1670
|
+
}
|
|
1554
1671
|
} catch (error) {
|
|
1555
1672
|
failed.push({
|
|
1556
1673
|
rfqId: record.rfqId,
|
|
@@ -1685,6 +1802,9 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
1685
1802
|
* origin, one remembered from an earlier `addSwap`, or the stored record (one read).
|
|
1686
1803
|
*/
|
|
1687
1804
|
async admit(swap, origin) {
|
|
1805
|
+
if (swap.kind === "onchain_receive" && !this.deps.chain) {
|
|
1806
|
+
throw new OnchainReceiveNeedsChainSource(swap.rfqId);
|
|
1807
|
+
}
|
|
1688
1808
|
if (origin) {
|
|
1689
1809
|
assertSameSwap(origin, swap);
|
|
1690
1810
|
this.origins.set(swap.rfqId, origin);
|
|
@@ -1951,6 +2071,7 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
1951
2071
|
} catch {
|
|
1952
2072
|
fate = { fate: "unknown" };
|
|
1953
2073
|
}
|
|
2074
|
+
if (swap.kind === "onchain_receive") return this.driveOnchainReceive(swap, fate);
|
|
1954
2075
|
if (fate.fate === "claimed" || fate.fate === "returned") {
|
|
1955
2076
|
this.stampLockupSpends(swap, fate.spends);
|
|
1956
2077
|
if (fate.fate === "claimed") this.stampSettlementPreimage(swap, fate.preimage);
|
|
@@ -2073,6 +2194,94 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
2073
2194
|
this.emitFailed(swap, error);
|
|
2074
2195
|
}
|
|
2075
2196
|
}
|
|
2197
|
+
/** `settled` ends the swap; `returned` does NOT, signalling their L1
|
|
2198
|
+
* funding is stranded. */
|
|
2199
|
+
async driveOnchainReceive(swap, fate) {
|
|
2200
|
+
const settled = fate.fate === "claimed";
|
|
2201
|
+
if (settled || fate.fate === "returned") this.stampLockupSpends(swap, fate.spends);
|
|
2202
|
+
if (settled) {
|
|
2203
|
+
this.setState(swap, "settled");
|
|
2204
|
+
return;
|
|
2205
|
+
}
|
|
2206
|
+
const l1 = await this.driveOnchainRefund(swap, swap.claimTxid !== void 0);
|
|
2207
|
+
if (fate.fate === "returned") {
|
|
2208
|
+
if (l1.verdict === "resolved") this.setState(swap, "refunded");
|
|
2209
|
+
else if (l1.blocked) this.block(swap, l1.blocked);
|
|
2210
|
+
return;
|
|
2211
|
+
}
|
|
2212
|
+
if (fate.fate === "exited") return this.blockExitedLockup(swap, fate);
|
|
2213
|
+
if (l1.verdict === "live" && this.config.now() >= swap.refundLocktime + REFUND_MTP_LAG_SECONDS) {
|
|
2214
|
+
return this.block(
|
|
2215
|
+
swap,
|
|
2216
|
+
l1.blocked ?? "the Arkade claim window closed unclaimed and the L1 HTLC is still funded \u2014 holding the swap open until its refund leaf opens"
|
|
2217
|
+
);
|
|
2218
|
+
}
|
|
2219
|
+
if (swap.refundTxid || l1.attempted) {
|
|
2220
|
+
return this.block(
|
|
2221
|
+
swap,
|
|
2222
|
+
"the L1 funding was refunded, so claiming the lockup too would take both sides of the trade \u2014 the solver's reclaim ends this swap"
|
|
2223
|
+
);
|
|
2224
|
+
}
|
|
2225
|
+
await this.driveReceiveClaim(swap);
|
|
2226
|
+
if (l1.blocked && !isRfqSwapTerminal(swap.state)) this.block(swap, l1.blocked);
|
|
2227
|
+
}
|
|
2228
|
+
/** `resolved`: the HTLC can hold nothing more. `blocked` is a refusal the
|
|
2229
|
+
* caller applies once the Arkade arm has run. No give-up branch. */
|
|
2230
|
+
async driveOnchainRefund(swap, claimSubmitted) {
|
|
2231
|
+
if (!this.deps.chain) return { verdict: "live" };
|
|
2232
|
+
let phase;
|
|
2233
|
+
try {
|
|
2234
|
+
phase = await classifyOnchainHtlc(this.deps.chain, {
|
|
2235
|
+
htlc: swap.htlc,
|
|
2236
|
+
minConfirmations: swap.minConfirmations,
|
|
2237
|
+
funding: swap.funding
|
|
2238
|
+
});
|
|
2239
|
+
} catch {
|
|
2240
|
+
return { verdict: "live" };
|
|
2241
|
+
}
|
|
2242
|
+
if ("utxo" in phase && !swap.funding) {
|
|
2243
|
+
swap.funding = { txid: phase.utxo.txid, vout: phase.utxo.vout };
|
|
2244
|
+
this.touch(swap);
|
|
2245
|
+
}
|
|
2246
|
+
if (phase.phase === "unfunded" && !swap.funding) return { verdict: "resolved" };
|
|
2247
|
+
switch (nextOnchainReceiveAction({ phase, settled: claimSubmitted })) {
|
|
2248
|
+
case "taken":
|
|
2249
|
+
return { verdict: "resolved" };
|
|
2250
|
+
case "refunded":
|
|
2251
|
+
if (phase.phase === "swept" && !swap.refundTxid) {
|
|
2252
|
+
swap.refundTxid = phase.txid;
|
|
2253
|
+
this.touch(swap);
|
|
2254
|
+
}
|
|
2255
|
+
return { verdict: "resolved" };
|
|
2256
|
+
case "wait":
|
|
2257
|
+
return { verdict: "live" };
|
|
2258
|
+
case "refund":
|
|
2259
|
+
break;
|
|
2260
|
+
}
|
|
2261
|
+
if (phase.phase !== "refundable") return { verdict: "live" };
|
|
2262
|
+
if (swap.refundTxid) return { verdict: "live" };
|
|
2263
|
+
if (!this.callbacks?.refundOnchain) {
|
|
2264
|
+
return {
|
|
2265
|
+
verdict: "live",
|
|
2266
|
+
blocked: this.callbacks ? RFQ_CONFIGURATION_REFUSAL.noRefundOnchainCallback : RFQ_CONFIGURATION_REFUSAL.noCallbacksForL1Refund
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
if (!this.config.enableAutoActions) {
|
|
2270
|
+
return {
|
|
2271
|
+
verdict: "live",
|
|
2272
|
+
blocked: RFQ_CONFIGURATION_REFUSAL.autoActionsDisabledForL1Refund
|
|
2273
|
+
};
|
|
2274
|
+
}
|
|
2275
|
+
try {
|
|
2276
|
+
const { txid } = await this.callbacks.refundOnchain(swap, phase.utxo);
|
|
2277
|
+
swap.refundTxid = txid;
|
|
2278
|
+
this.touch(swap);
|
|
2279
|
+
this.emitAction(swap, "refundOnchain");
|
|
2280
|
+
} catch (error) {
|
|
2281
|
+
this.emitFailed(swap, error);
|
|
2282
|
+
}
|
|
2283
|
+
return { verdict: "live", attempted: true };
|
|
2284
|
+
}
|
|
2076
2285
|
/** `handled` ends the pass; `continue` falls through to the refund gate. */
|
|
2077
2286
|
async driveOnchain(swap) {
|
|
2078
2287
|
if (!this.deps.chain) {
|
|
@@ -2351,10 +2560,10 @@ var RfqSwapManager = class _RfqSwapManager {
|
|
|
2351
2560
|
this.waiters.delete(swap.rfqId);
|
|
2352
2561
|
}
|
|
2353
2562
|
};
|
|
2354
|
-
var traderClaimTxid = (swap) => swap.kind === "
|
|
2563
|
+
var traderClaimTxid = (swap) => swap.kind === "lightning_send" ? void 0 : swap.claimTxid;
|
|
2355
2564
|
var isPayoutDecided = (swap) => swap.state === "settled" || swap.state === "refunded" || swap.kind === "onchain_send" && swap.claimTxid !== void 0;
|
|
2356
2565
|
var outcomeOf = (swap) => {
|
|
2357
|
-
const lostReceive = swap.kind === "lightning_receive" && swap.state === "refunded";
|
|
2566
|
+
const lostReceive = (swap.kind === "lightning_receive" || swap.kind === "onchain_receive") && swap.state === "refunded";
|
|
2358
2567
|
return {
|
|
2359
2568
|
state: swap.state,
|
|
2360
2569
|
txid: lostReceive ? swap.refundTxid : traderClaimTxid(swap) ?? swap.refundTxid
|
|
@@ -2362,11 +2571,11 @@ var outcomeOf = (swap) => {
|
|
|
2362
2571
|
};
|
|
2363
2572
|
var outcomeOfRecord = (stored) => {
|
|
2364
2573
|
const record = normalizeRfqSwapRecord(stored);
|
|
2365
|
-
const profileClaim = record.kind === "
|
|
2574
|
+
const profileClaim = record.kind === "lightning_send" ? void 0 : record.profile.claimTxid;
|
|
2366
2575
|
const claimTxid = typeof profileClaim === "string" ? profileClaim : void 0;
|
|
2367
2576
|
return {
|
|
2368
2577
|
state: record.state,
|
|
2369
|
-
txid: record.kind === "lightning_receive" && record.state === "refunded" ? record.refundTxid : claimTxid ?? record.refundTxid
|
|
2578
|
+
txid: (record.kind === "lightning_receive" || record.kind === "onchain_receive") && record.state === "refunded" ? record.refundTxid : claimTxid ?? record.refundTxid
|
|
2370
2579
|
};
|
|
2371
2580
|
};
|
|
2372
2581
|
var errorMessage = (error) => error instanceof Error ? error.message : String(error);
|
|
@@ -2469,6 +2678,7 @@ export {
|
|
|
2469
2678
|
rfqClaimSecretOf,
|
|
2470
2679
|
rfqClaimDestinationOf,
|
|
2471
2680
|
onchainSendProfile,
|
|
2681
|
+
onchainReceiveProfile,
|
|
2472
2682
|
INVOICE_HRPS,
|
|
2473
2683
|
networksOfInvoiceHrp,
|
|
2474
2684
|
PAYMENT_HASH,
|
|
@@ -2521,8 +2731,10 @@ export {
|
|
|
2521
2731
|
senderIdentityForSwapRecord,
|
|
2522
2732
|
arkadeRefunder,
|
|
2523
2733
|
nextOnchainAction,
|
|
2734
|
+
nextOnchainReceiveAction,
|
|
2524
2735
|
isRfqConfigurationRefusal,
|
|
2525
2736
|
RfqSwapOriginRequired,
|
|
2737
|
+
OnchainReceiveNeedsChainSource,
|
|
2526
2738
|
RfqSwapManager,
|
|
2527
2739
|
watchOfferSwaps
|
|
2528
2740
|
};
|