@satora/swap 1.7.2 → 1.8.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.
- package/dist/index.cjs +135 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +107 -79
- package/dist/index.d.ts +107 -79
- package/dist/index.js +135 -18
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
package/dist/index.d.cts
CHANGED
|
@@ -396,6 +396,81 @@ interface ContractManager {
|
|
|
396
396
|
dispose(): void;
|
|
397
397
|
}
|
|
398
398
|
|
|
399
|
+
/**
|
|
400
|
+
* A standalone subscriber to the server's swap-status WebSocket (`GET /ws`).
|
|
401
|
+
*
|
|
402
|
+
* Holds a single reconnecting connection, tracks a live set of subscribed swap
|
|
403
|
+
* ids, and emits `{ swapId, status }` on every status transition the server
|
|
404
|
+
* pushes — including the snapshot the server sends right after a subscribe. This
|
|
405
|
+
* is a *hint* feed only: it neither trusts nor acts on the status. A consumer is
|
|
406
|
+
* expected to verify against the chain (the contract managers) before doing
|
|
407
|
+
* anything with it.
|
|
408
|
+
*
|
|
409
|
+
* Protocol (see `swap/src/api/ws.rs`):
|
|
410
|
+
* → {"op":"subscribe","channel":"swap_status","args":[<uuid>,...]} (≤64 ids/frame)
|
|
411
|
+
* ← {"channel":"swap_status","data":{"<uuid>":"<status>",...}}
|
|
412
|
+
* ← {"op":"subscribed",...} (ack) ← {"op":...,"message":...} (error)
|
|
413
|
+
* A single connection carries up to 256 subscriptions; that cap is enforced
|
|
414
|
+
* client-side (see {@link WsStatusSource.subscribe}) because the server silently
|
|
415
|
+
* drops the overflow.
|
|
416
|
+
*/
|
|
417
|
+
|
|
418
|
+
/** A status update pushed by the server for one swap. */
|
|
419
|
+
type SwapStatusUpdate = {
|
|
420
|
+
swapId: string;
|
|
421
|
+
status: SwapStatus;
|
|
422
|
+
};
|
|
423
|
+
/** The minimal WebSocket surface the source needs (the global `WebSocket` satisfies it). */
|
|
424
|
+
interface WebSocketLike {
|
|
425
|
+
send(data: string): void;
|
|
426
|
+
close(): void;
|
|
427
|
+
onopen: (() => void) | null;
|
|
428
|
+
onmessage: ((event: {
|
|
429
|
+
data: unknown;
|
|
430
|
+
}) => void) | null;
|
|
431
|
+
onclose: (() => void) | null;
|
|
432
|
+
onerror: ((event: unknown) => void) | null;
|
|
433
|
+
}
|
|
434
|
+
type WsStatusSourceOptions = {
|
|
435
|
+
/** Server base URL (http/https); the `ws(s)://…/ws` endpoint is derived from it. */
|
|
436
|
+
serverUrl: string;
|
|
437
|
+
/** WebSocket factory — defaults to the global `WebSocket` (browsers, Node ≥ 22). */
|
|
438
|
+
webSocketFactory?: (url: string) => WebSocketLike;
|
|
439
|
+
/** Reconnect backoff floor/ceiling (ms). Defaults: 1_000 / 30_000. */
|
|
440
|
+
reconnectMinMs?: number;
|
|
441
|
+
reconnectMaxMs?: number;
|
|
442
|
+
};
|
|
443
|
+
declare class WsStatusSource {
|
|
444
|
+
#private;
|
|
445
|
+
constructor(options: WsStatusSourceOptions);
|
|
446
|
+
/** Open the connection and begin (re)subscribing. Idempotent. */
|
|
447
|
+
start(): void;
|
|
448
|
+
/** Close the connection and stop reconnecting. */
|
|
449
|
+
stop(): void;
|
|
450
|
+
/** Emit for each pushed status update. Returns an unsubscribe fn. */
|
|
451
|
+
onStatus(cb: (update: SwapStatusUpdate) => void): () => void;
|
|
452
|
+
/**
|
|
453
|
+
* Emit whenever the socket comes (back) up after a disruption — a drop, or a
|
|
454
|
+
* first connect that had to be retried. NOT emitted on a pristine first open:
|
|
455
|
+
* hints were never live before it, so there is no gap to recover from. While
|
|
456
|
+
* the socket was down, pushed transitions were lost for good (the server only
|
|
457
|
+
* snapshots on subscribe), so a consumer should re-verify its world against
|
|
458
|
+
* the chain on this signal.
|
|
459
|
+
*/
|
|
460
|
+
onReconnect(cb: () => void): () => void;
|
|
461
|
+
/**
|
|
462
|
+
* Track these swap ids — subscribe on the socket now if open, else on next open.
|
|
463
|
+
*
|
|
464
|
+
* Enforces the server's per-connection cap locally. The server silently stops
|
|
465
|
+
* adding once it is full (it breaks out of the loop but still acks every id),
|
|
466
|
+
* so sending more would leave us believing ids are subscribed that will never
|
|
467
|
+
* receive an update. Overflow is queued instead and promoted as slots free.
|
|
468
|
+
*/
|
|
469
|
+
subscribe(swapIds: string[]): void;
|
|
470
|
+
/** Stop tracking these swap ids, promoting queued ones into the freed slots. */
|
|
471
|
+
unsubscribe(swapIds: string[]): void;
|
|
472
|
+
}
|
|
473
|
+
|
|
399
474
|
/**
|
|
400
475
|
* The reactive orchestration.
|
|
401
476
|
*
|
|
@@ -476,7 +551,9 @@ declare class SwapTracker {
|
|
|
476
551
|
* status hint drives. Reconciles just that swap's legs (targeted, on the
|
|
477
552
|
* managers), then recomputes its action. The hint is only a *trigger*: the
|
|
478
553
|
* chain stays the source of truth, so a premature hint that the chain doesn't
|
|
479
|
-
* yet reflect changes nothing
|
|
554
|
+
* yet reflect changes nothing, except that a hint saying the server's HTLC is
|
|
555
|
+
* funded is followed by a few more reads of that leg until the chain shows it.
|
|
556
|
+
* A no-op for an untracked swap.
|
|
480
557
|
*/
|
|
481
558
|
applyHint(swapId: string, opts?: {
|
|
482
559
|
force?: boolean;
|
|
@@ -533,6 +610,8 @@ type TrackingConfig = {
|
|
|
533
610
|
* remain the source of truth.
|
|
534
611
|
*/
|
|
535
612
|
serverUrl?: string;
|
|
613
|
+
/** WebSocket factory for the hint feed; defaults to the global `WebSocket` (testing). */
|
|
614
|
+
webSocketFactory?: (url: string) => WebSocketLike;
|
|
536
615
|
/** Explicit per-ledger managers, bypassing auto-construction (advanced/testing). */
|
|
537
616
|
managers?: Map<Ledger, ContractManager>;
|
|
538
617
|
/** Ark server URL override; defaults to the mainnet server when unset. */
|
|
@@ -651,8 +730,6 @@ declare class Client {
|
|
|
651
730
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
652
731
|
getQuote(...args: Parameters<Client$1["getQuote"]>): ReturnType<Client$1["getQuote"]>;
|
|
653
732
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
654
|
-
createLightningToEvmSwap(...args: Parameters<Client$1["createLightningToEvmSwap"]>): ReturnType<Client$1["createLightningToEvmSwap"]>;
|
|
655
|
-
/** Delegated to the legacy client (migration checkpoint). */
|
|
656
733
|
getLightningSendQuote(...args: Parameters<Client$1["getLightningSendQuote"]>): ReturnType<Client$1["getLightningSendQuote"]>;
|
|
657
734
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
658
735
|
getSwap(...args: Parameters<Client$1["getSwap"]>): ReturnType<Client$1["getSwap"]>;
|
|
@@ -675,6 +752,7 @@ declare class Client {
|
|
|
675
752
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
676
753
|
claim(...args: Parameters<Client$1["claim"]>): ReturnType<Client$1["claim"]>;
|
|
677
754
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
755
|
+
canSponsorClaim(...args: Parameters<Client$1["canSponsorClaim"]>): boolean;
|
|
678
756
|
claimEvmWithSigner(...args: Parameters<Client$1["claimEvmWithSigner"]>): ReturnType<Client$1["claimEvmWithSigner"]>;
|
|
679
757
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
680
758
|
claimViaGasless(...args: Parameters<Client$1["claimViaGasless"]>): ReturnType<Client$1["claimViaGasless"]>;
|
|
@@ -689,6 +767,16 @@ declare class Client {
|
|
|
689
767
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
690
768
|
buildCollabRefundEvmTypedData(...args: Parameters<Client$1["buildCollabRefundEvmTypedData"]>): ReturnType<Client$1["buildCollabRefundEvmTypedData"]>;
|
|
691
769
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
770
|
+
getCollabRefundEvmSignature(...args: Parameters<Client$1["getCollabRefundEvmSignature"]>): ReturnType<Client$1["getCollabRefundEvmSignature"]>;
|
|
771
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
772
|
+
getRehashEvmParams(...args: Parameters<Client$1["getRehashEvmParams"]>): ReturnType<Client$1["getRehashEvmParams"]>;
|
|
773
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
774
|
+
signRehashEvm(...args: Parameters<Client$1["signRehashEvm"]>): ReturnType<Client$1["signRehashEvm"]>;
|
|
775
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
776
|
+
retrySwapWithInvoice(...args: Parameters<Client$1["retrySwapWithInvoice"]>): ReturnType<Client$1["retrySwapWithInvoice"]>;
|
|
777
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
778
|
+
retrySwapWithInvoiceWithSigner(...args: Parameters<Client$1["retrySwapWithInvoiceWithSigner"]>): ReturnType<Client$1["retrySwapWithInvoiceWithSigner"]>;
|
|
779
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
692
780
|
collabRefundEvmSwap(...args: Parameters<Client$1["collabRefundEvmSwap"]>): ReturnType<Client$1["collabRefundEvmSwap"]>;
|
|
693
781
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
694
782
|
submitCollabRefundEvm(...args: Parameters<Client$1["submitCollabRefundEvm"]>): ReturnType<Client$1["submitCollabRefundEvm"]>;
|
|
@@ -705,6 +793,8 @@ declare class Client {
|
|
|
705
793
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
706
794
|
createArkadeToLightningSwap(...args: Parameters<Client$1["createArkadeToLightningSwap"]>): ReturnType<Client$1["createArkadeToLightningSwap"]>;
|
|
707
795
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
796
|
+
createLightningToEvmSwap(...args: Parameters<Client$1["createLightningToEvmSwap"]>): ReturnType<Client$1["createLightningToEvmSwap"]>;
|
|
797
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
708
798
|
createLightningToBitcoinSwap(...args: Parameters<Client$1["createLightningToBitcoinSwap"]>): ReturnType<Client$1["createLightningToBitcoinSwap"]>;
|
|
709
799
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
710
800
|
createBitcoinToLightningSwap(...args: Parameters<Client$1["createBitcoinToLightningSwap"]>): ReturnType<Client$1["createBitcoinToLightningSwap"]>;
|
|
@@ -718,7 +808,10 @@ declare class Client {
|
|
|
718
808
|
getCoordinatorFundingCallDataPermit2(...args: Parameters<Client$1["getCoordinatorFundingCallDataPermit2"]>): ReturnType<Client$1["getCoordinatorFundingCallDataPermit2"]>;
|
|
719
809
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
720
810
|
getPermit2FundingParamsUnsigned(...args: Parameters<Client$1["getPermit2FundingParamsUnsigned"]>): ReturnType<Client$1["getPermit2FundingParamsUnsigned"]>;
|
|
721
|
-
/**
|
|
811
|
+
/**
|
|
812
|
+
* Fund the swap, then re-verify it against the chain so the lock shows up
|
|
813
|
+
* in the derived actions without waiting on a server hint.
|
|
814
|
+
*/
|
|
722
815
|
fundSwap(...args: Parameters<Client$1["fundSwap"]>): ReturnType<Client$1["fundSwap"]>;
|
|
723
816
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
724
817
|
fundSwapFromSolana(...args: Parameters<Client$1["fundSwapFromSolana"]>): ReturnType<Client$1["fundSwapFromSolana"]>;
|
|
@@ -733,6 +826,8 @@ declare class Client {
|
|
|
733
826
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
734
827
|
fundSwapGasless(...args: Parameters<Client$1["fundSwapGasless"]>): ReturnType<Client$1["fundSwapGasless"]>;
|
|
735
828
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
829
|
+
getEvmFundingExpectation(...args: Parameters<Client$1["getEvmFundingExpectation"]>): ReturnType<Client$1["getEvmFundingExpectation"]>;
|
|
830
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
736
831
|
getSwapDepositorKey(...args: Parameters<Client$1["getSwapDepositorKey"]>): ReturnType<Client$1["getSwapDepositorKey"]>;
|
|
737
832
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
738
833
|
getEvmDepositorKey(...args: Parameters<Client$1["getEvmDepositorKey"]>): ReturnType<Client$1["getEvmDepositorKey"]>;
|
|
@@ -1538,7 +1633,7 @@ type SwapWorkerOptions = {
|
|
|
1538
1633
|
* Resolve once submitted. OMIT for observe-only mode: hints still trigger
|
|
1539
1634
|
* chain re-verifies (fast, cheap derivations), but nothing is ever run.
|
|
1540
1635
|
*/
|
|
1541
|
-
execute?: (swapId: string, actionId: SwapActionId) => Promise<void>;
|
|
1636
|
+
execute?: (swapId: string, actionId: SwapActionId, actions: SwapActions) => Promise<void>;
|
|
1542
1637
|
/**
|
|
1543
1638
|
* Surface an action that needs the user rather than being auto-run — a manual
|
|
1544
1639
|
* `fund`, a refund the user must confirm, or a claim whose retries are spent.
|
|
@@ -1553,83 +1648,16 @@ declare class SwapWorker {
|
|
|
1553
1648
|
constructor(options: SwapWorkerOptions);
|
|
1554
1649
|
/** Watch tracked swaps on the hint feed, wire hints → verify, react to actions. */
|
|
1555
1650
|
start(): void;
|
|
1556
|
-
/** Stop reacting, cancel pending retries, and close the hint feed. */
|
|
1557
|
-
stop(): void;
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
/**
|
|
1561
|
-
* A standalone subscriber to the server's swap-status WebSocket (`GET /ws`).
|
|
1562
|
-
*
|
|
1563
|
-
* Holds a single reconnecting connection, tracks a live set of subscribed swap
|
|
1564
|
-
* ids, and emits `{ swapId, status }` on every status transition the server
|
|
1565
|
-
* pushes — including the snapshot the server sends right after a subscribe. This
|
|
1566
|
-
* is a *hint* feed only: it neither trusts nor acts on the status. A consumer is
|
|
1567
|
-
* expected to verify against the chain (the contract managers) before doing
|
|
1568
|
-
* anything with it.
|
|
1569
|
-
*
|
|
1570
|
-
* Protocol (see `swap/src/api/ws.rs`):
|
|
1571
|
-
* → {"op":"subscribe","channel":"swap_status","args":[<uuid>,...]} (≤64 ids/frame)
|
|
1572
|
-
* ← {"channel":"swap_status","data":{"<uuid>":"<status>",...}}
|
|
1573
|
-
* ← {"op":"subscribed",...} (ack) ← {"op":...,"message":...} (error)
|
|
1574
|
-
* A single connection carries up to 256 subscriptions; that cap is enforced
|
|
1575
|
-
* client-side (see {@link WsStatusSource.subscribe}) because the server silently
|
|
1576
|
-
* drops the overflow.
|
|
1577
|
-
*/
|
|
1578
|
-
|
|
1579
|
-
/** A status update pushed by the server for one swap. */
|
|
1580
|
-
type SwapStatusUpdate = {
|
|
1581
|
-
swapId: string;
|
|
1582
|
-
status: SwapStatus;
|
|
1583
|
-
};
|
|
1584
|
-
/** The minimal WebSocket surface the source needs (the global `WebSocket` satisfies it). */
|
|
1585
|
-
interface WebSocketLike {
|
|
1586
|
-
send(data: string): void;
|
|
1587
|
-
close(): void;
|
|
1588
|
-
onopen: (() => void) | null;
|
|
1589
|
-
onmessage: ((event: {
|
|
1590
|
-
data: unknown;
|
|
1591
|
-
}) => void) | null;
|
|
1592
|
-
onclose: (() => void) | null;
|
|
1593
|
-
onerror: ((event: unknown) => void) | null;
|
|
1594
|
-
}
|
|
1595
|
-
type WsStatusSourceOptions = {
|
|
1596
|
-
/** Server base URL (http/https); the `ws(s)://…/ws` endpoint is derived from it. */
|
|
1597
|
-
serverUrl: string;
|
|
1598
|
-
/** WebSocket factory — defaults to the global `WebSocket` (browsers, Node ≥ 22). */
|
|
1599
|
-
webSocketFactory?: (url: string) => WebSocketLike;
|
|
1600
|
-
/** Reconnect backoff floor/ceiling (ms). Defaults: 1_000 / 30_000. */
|
|
1601
|
-
reconnectMinMs?: number;
|
|
1602
|
-
reconnectMaxMs?: number;
|
|
1603
|
-
};
|
|
1604
|
-
declare class WsStatusSource {
|
|
1605
|
-
#private;
|
|
1606
|
-
constructor(options: WsStatusSourceOptions);
|
|
1607
|
-
/** Open the connection and begin (re)subscribing. Idempotent. */
|
|
1608
|
-
start(): void;
|
|
1609
|
-
/** Close the connection and stop reconnecting. */
|
|
1610
|
-
stop(): void;
|
|
1611
|
-
/** Emit for each pushed status update. Returns an unsubscribe fn. */
|
|
1612
|
-
onStatus(cb: (update: SwapStatusUpdate) => void): () => void;
|
|
1613
|
-
/**
|
|
1614
|
-
* Emit whenever the socket comes (back) up after a disruption — a drop, or a
|
|
1615
|
-
* first connect that had to be retried. NOT emitted on a pristine first open:
|
|
1616
|
-
* hints were never live before it, so there is no gap to recover from. While
|
|
1617
|
-
* the socket was down, pushed transitions were lost for good (the server only
|
|
1618
|
-
* snapshots on subscribe), so a consumer should re-verify its world against
|
|
1619
|
-
* the chain on this signal.
|
|
1620
|
-
*/
|
|
1621
|
-
onReconnect(cb: () => void): () => void;
|
|
1622
1651
|
/**
|
|
1623
|
-
*
|
|
1624
|
-
*
|
|
1625
|
-
*
|
|
1626
|
-
*
|
|
1627
|
-
*
|
|
1628
|
-
* receive an update. Overflow is queued instead and promoted as slots free.
|
|
1652
|
+
* Put swaps on the hint feed as soon as they are tracked. {@link #onActions}
|
|
1653
|
+
* subscribes a swap when its first action is emitted, but a swap whose leg
|
|
1654
|
+
* cannot be classified yet (an unfunded lock on a chain without `eth_getLogs`)
|
|
1655
|
+
* emits nothing, and without this it would never receive the server hint
|
|
1656
|
+
* that its funding landed.
|
|
1629
1657
|
*/
|
|
1630
1658
|
subscribe(swapIds: string[]): void;
|
|
1631
|
-
/** Stop
|
|
1632
|
-
|
|
1659
|
+
/** Stop reacting, cancel pending retries, and close the hint feed. */
|
|
1660
|
+
stop(): void;
|
|
1633
1661
|
}
|
|
1634
1662
|
|
|
1635
1663
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -396,6 +396,81 @@ interface ContractManager {
|
|
|
396
396
|
dispose(): void;
|
|
397
397
|
}
|
|
398
398
|
|
|
399
|
+
/**
|
|
400
|
+
* A standalone subscriber to the server's swap-status WebSocket (`GET /ws`).
|
|
401
|
+
*
|
|
402
|
+
* Holds a single reconnecting connection, tracks a live set of subscribed swap
|
|
403
|
+
* ids, and emits `{ swapId, status }` on every status transition the server
|
|
404
|
+
* pushes — including the snapshot the server sends right after a subscribe. This
|
|
405
|
+
* is a *hint* feed only: it neither trusts nor acts on the status. A consumer is
|
|
406
|
+
* expected to verify against the chain (the contract managers) before doing
|
|
407
|
+
* anything with it.
|
|
408
|
+
*
|
|
409
|
+
* Protocol (see `swap/src/api/ws.rs`):
|
|
410
|
+
* → {"op":"subscribe","channel":"swap_status","args":[<uuid>,...]} (≤64 ids/frame)
|
|
411
|
+
* ← {"channel":"swap_status","data":{"<uuid>":"<status>",...}}
|
|
412
|
+
* ← {"op":"subscribed",...} (ack) ← {"op":...,"message":...} (error)
|
|
413
|
+
* A single connection carries up to 256 subscriptions; that cap is enforced
|
|
414
|
+
* client-side (see {@link WsStatusSource.subscribe}) because the server silently
|
|
415
|
+
* drops the overflow.
|
|
416
|
+
*/
|
|
417
|
+
|
|
418
|
+
/** A status update pushed by the server for one swap. */
|
|
419
|
+
type SwapStatusUpdate = {
|
|
420
|
+
swapId: string;
|
|
421
|
+
status: SwapStatus;
|
|
422
|
+
};
|
|
423
|
+
/** The minimal WebSocket surface the source needs (the global `WebSocket` satisfies it). */
|
|
424
|
+
interface WebSocketLike {
|
|
425
|
+
send(data: string): void;
|
|
426
|
+
close(): void;
|
|
427
|
+
onopen: (() => void) | null;
|
|
428
|
+
onmessage: ((event: {
|
|
429
|
+
data: unknown;
|
|
430
|
+
}) => void) | null;
|
|
431
|
+
onclose: (() => void) | null;
|
|
432
|
+
onerror: ((event: unknown) => void) | null;
|
|
433
|
+
}
|
|
434
|
+
type WsStatusSourceOptions = {
|
|
435
|
+
/** Server base URL (http/https); the `ws(s)://…/ws` endpoint is derived from it. */
|
|
436
|
+
serverUrl: string;
|
|
437
|
+
/** WebSocket factory — defaults to the global `WebSocket` (browsers, Node ≥ 22). */
|
|
438
|
+
webSocketFactory?: (url: string) => WebSocketLike;
|
|
439
|
+
/** Reconnect backoff floor/ceiling (ms). Defaults: 1_000 / 30_000. */
|
|
440
|
+
reconnectMinMs?: number;
|
|
441
|
+
reconnectMaxMs?: number;
|
|
442
|
+
};
|
|
443
|
+
declare class WsStatusSource {
|
|
444
|
+
#private;
|
|
445
|
+
constructor(options: WsStatusSourceOptions);
|
|
446
|
+
/** Open the connection and begin (re)subscribing. Idempotent. */
|
|
447
|
+
start(): void;
|
|
448
|
+
/** Close the connection and stop reconnecting. */
|
|
449
|
+
stop(): void;
|
|
450
|
+
/** Emit for each pushed status update. Returns an unsubscribe fn. */
|
|
451
|
+
onStatus(cb: (update: SwapStatusUpdate) => void): () => void;
|
|
452
|
+
/**
|
|
453
|
+
* Emit whenever the socket comes (back) up after a disruption — a drop, or a
|
|
454
|
+
* first connect that had to be retried. NOT emitted on a pristine first open:
|
|
455
|
+
* hints were never live before it, so there is no gap to recover from. While
|
|
456
|
+
* the socket was down, pushed transitions were lost for good (the server only
|
|
457
|
+
* snapshots on subscribe), so a consumer should re-verify its world against
|
|
458
|
+
* the chain on this signal.
|
|
459
|
+
*/
|
|
460
|
+
onReconnect(cb: () => void): () => void;
|
|
461
|
+
/**
|
|
462
|
+
* Track these swap ids — subscribe on the socket now if open, else on next open.
|
|
463
|
+
*
|
|
464
|
+
* Enforces the server's per-connection cap locally. The server silently stops
|
|
465
|
+
* adding once it is full (it breaks out of the loop but still acks every id),
|
|
466
|
+
* so sending more would leave us believing ids are subscribed that will never
|
|
467
|
+
* receive an update. Overflow is queued instead and promoted as slots free.
|
|
468
|
+
*/
|
|
469
|
+
subscribe(swapIds: string[]): void;
|
|
470
|
+
/** Stop tracking these swap ids, promoting queued ones into the freed slots. */
|
|
471
|
+
unsubscribe(swapIds: string[]): void;
|
|
472
|
+
}
|
|
473
|
+
|
|
399
474
|
/**
|
|
400
475
|
* The reactive orchestration.
|
|
401
476
|
*
|
|
@@ -476,7 +551,9 @@ declare class SwapTracker {
|
|
|
476
551
|
* status hint drives. Reconciles just that swap's legs (targeted, on the
|
|
477
552
|
* managers), then recomputes its action. The hint is only a *trigger*: the
|
|
478
553
|
* chain stays the source of truth, so a premature hint that the chain doesn't
|
|
479
|
-
* yet reflect changes nothing
|
|
554
|
+
* yet reflect changes nothing, except that a hint saying the server's HTLC is
|
|
555
|
+
* funded is followed by a few more reads of that leg until the chain shows it.
|
|
556
|
+
* A no-op for an untracked swap.
|
|
480
557
|
*/
|
|
481
558
|
applyHint(swapId: string, opts?: {
|
|
482
559
|
force?: boolean;
|
|
@@ -533,6 +610,8 @@ type TrackingConfig = {
|
|
|
533
610
|
* remain the source of truth.
|
|
534
611
|
*/
|
|
535
612
|
serverUrl?: string;
|
|
613
|
+
/** WebSocket factory for the hint feed; defaults to the global `WebSocket` (testing). */
|
|
614
|
+
webSocketFactory?: (url: string) => WebSocketLike;
|
|
536
615
|
/** Explicit per-ledger managers, bypassing auto-construction (advanced/testing). */
|
|
537
616
|
managers?: Map<Ledger, ContractManager>;
|
|
538
617
|
/** Ark server URL override; defaults to the mainnet server when unset. */
|
|
@@ -651,8 +730,6 @@ declare class Client {
|
|
|
651
730
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
652
731
|
getQuote(...args: Parameters<Client$1["getQuote"]>): ReturnType<Client$1["getQuote"]>;
|
|
653
732
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
654
|
-
createLightningToEvmSwap(...args: Parameters<Client$1["createLightningToEvmSwap"]>): ReturnType<Client$1["createLightningToEvmSwap"]>;
|
|
655
|
-
/** Delegated to the legacy client (migration checkpoint). */
|
|
656
733
|
getLightningSendQuote(...args: Parameters<Client$1["getLightningSendQuote"]>): ReturnType<Client$1["getLightningSendQuote"]>;
|
|
657
734
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
658
735
|
getSwap(...args: Parameters<Client$1["getSwap"]>): ReturnType<Client$1["getSwap"]>;
|
|
@@ -675,6 +752,7 @@ declare class Client {
|
|
|
675
752
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
676
753
|
claim(...args: Parameters<Client$1["claim"]>): ReturnType<Client$1["claim"]>;
|
|
677
754
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
755
|
+
canSponsorClaim(...args: Parameters<Client$1["canSponsorClaim"]>): boolean;
|
|
678
756
|
claimEvmWithSigner(...args: Parameters<Client$1["claimEvmWithSigner"]>): ReturnType<Client$1["claimEvmWithSigner"]>;
|
|
679
757
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
680
758
|
claimViaGasless(...args: Parameters<Client$1["claimViaGasless"]>): ReturnType<Client$1["claimViaGasless"]>;
|
|
@@ -689,6 +767,16 @@ declare class Client {
|
|
|
689
767
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
690
768
|
buildCollabRefundEvmTypedData(...args: Parameters<Client$1["buildCollabRefundEvmTypedData"]>): ReturnType<Client$1["buildCollabRefundEvmTypedData"]>;
|
|
691
769
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
770
|
+
getCollabRefundEvmSignature(...args: Parameters<Client$1["getCollabRefundEvmSignature"]>): ReturnType<Client$1["getCollabRefundEvmSignature"]>;
|
|
771
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
772
|
+
getRehashEvmParams(...args: Parameters<Client$1["getRehashEvmParams"]>): ReturnType<Client$1["getRehashEvmParams"]>;
|
|
773
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
774
|
+
signRehashEvm(...args: Parameters<Client$1["signRehashEvm"]>): ReturnType<Client$1["signRehashEvm"]>;
|
|
775
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
776
|
+
retrySwapWithInvoice(...args: Parameters<Client$1["retrySwapWithInvoice"]>): ReturnType<Client$1["retrySwapWithInvoice"]>;
|
|
777
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
778
|
+
retrySwapWithInvoiceWithSigner(...args: Parameters<Client$1["retrySwapWithInvoiceWithSigner"]>): ReturnType<Client$1["retrySwapWithInvoiceWithSigner"]>;
|
|
779
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
692
780
|
collabRefundEvmSwap(...args: Parameters<Client$1["collabRefundEvmSwap"]>): ReturnType<Client$1["collabRefundEvmSwap"]>;
|
|
693
781
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
694
782
|
submitCollabRefundEvm(...args: Parameters<Client$1["submitCollabRefundEvm"]>): ReturnType<Client$1["submitCollabRefundEvm"]>;
|
|
@@ -705,6 +793,8 @@ declare class Client {
|
|
|
705
793
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
706
794
|
createArkadeToLightningSwap(...args: Parameters<Client$1["createArkadeToLightningSwap"]>): ReturnType<Client$1["createArkadeToLightningSwap"]>;
|
|
707
795
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
796
|
+
createLightningToEvmSwap(...args: Parameters<Client$1["createLightningToEvmSwap"]>): ReturnType<Client$1["createLightningToEvmSwap"]>;
|
|
797
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
708
798
|
createLightningToBitcoinSwap(...args: Parameters<Client$1["createLightningToBitcoinSwap"]>): ReturnType<Client$1["createLightningToBitcoinSwap"]>;
|
|
709
799
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
710
800
|
createBitcoinToLightningSwap(...args: Parameters<Client$1["createBitcoinToLightningSwap"]>): ReturnType<Client$1["createBitcoinToLightningSwap"]>;
|
|
@@ -718,7 +808,10 @@ declare class Client {
|
|
|
718
808
|
getCoordinatorFundingCallDataPermit2(...args: Parameters<Client$1["getCoordinatorFundingCallDataPermit2"]>): ReturnType<Client$1["getCoordinatorFundingCallDataPermit2"]>;
|
|
719
809
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
720
810
|
getPermit2FundingParamsUnsigned(...args: Parameters<Client$1["getPermit2FundingParamsUnsigned"]>): ReturnType<Client$1["getPermit2FundingParamsUnsigned"]>;
|
|
721
|
-
/**
|
|
811
|
+
/**
|
|
812
|
+
* Fund the swap, then re-verify it against the chain so the lock shows up
|
|
813
|
+
* in the derived actions without waiting on a server hint.
|
|
814
|
+
*/
|
|
722
815
|
fundSwap(...args: Parameters<Client$1["fundSwap"]>): ReturnType<Client$1["fundSwap"]>;
|
|
723
816
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
724
817
|
fundSwapFromSolana(...args: Parameters<Client$1["fundSwapFromSolana"]>): ReturnType<Client$1["fundSwapFromSolana"]>;
|
|
@@ -733,6 +826,8 @@ declare class Client {
|
|
|
733
826
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
734
827
|
fundSwapGasless(...args: Parameters<Client$1["fundSwapGasless"]>): ReturnType<Client$1["fundSwapGasless"]>;
|
|
735
828
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
829
|
+
getEvmFundingExpectation(...args: Parameters<Client$1["getEvmFundingExpectation"]>): ReturnType<Client$1["getEvmFundingExpectation"]>;
|
|
830
|
+
/** Delegated to the legacy client (migration checkpoint). */
|
|
736
831
|
getSwapDepositorKey(...args: Parameters<Client$1["getSwapDepositorKey"]>): ReturnType<Client$1["getSwapDepositorKey"]>;
|
|
737
832
|
/** Delegated to the legacy client (migration checkpoint). */
|
|
738
833
|
getEvmDepositorKey(...args: Parameters<Client$1["getEvmDepositorKey"]>): ReturnType<Client$1["getEvmDepositorKey"]>;
|
|
@@ -1538,7 +1633,7 @@ type SwapWorkerOptions = {
|
|
|
1538
1633
|
* Resolve once submitted. OMIT for observe-only mode: hints still trigger
|
|
1539
1634
|
* chain re-verifies (fast, cheap derivations), but nothing is ever run.
|
|
1540
1635
|
*/
|
|
1541
|
-
execute?: (swapId: string, actionId: SwapActionId) => Promise<void>;
|
|
1636
|
+
execute?: (swapId: string, actionId: SwapActionId, actions: SwapActions) => Promise<void>;
|
|
1542
1637
|
/**
|
|
1543
1638
|
* Surface an action that needs the user rather than being auto-run — a manual
|
|
1544
1639
|
* `fund`, a refund the user must confirm, or a claim whose retries are spent.
|
|
@@ -1553,83 +1648,16 @@ declare class SwapWorker {
|
|
|
1553
1648
|
constructor(options: SwapWorkerOptions);
|
|
1554
1649
|
/** Watch tracked swaps on the hint feed, wire hints → verify, react to actions. */
|
|
1555
1650
|
start(): void;
|
|
1556
|
-
/** Stop reacting, cancel pending retries, and close the hint feed. */
|
|
1557
|
-
stop(): void;
|
|
1558
|
-
}
|
|
1559
|
-
|
|
1560
|
-
/**
|
|
1561
|
-
* A standalone subscriber to the server's swap-status WebSocket (`GET /ws`).
|
|
1562
|
-
*
|
|
1563
|
-
* Holds a single reconnecting connection, tracks a live set of subscribed swap
|
|
1564
|
-
* ids, and emits `{ swapId, status }` on every status transition the server
|
|
1565
|
-
* pushes — including the snapshot the server sends right after a subscribe. This
|
|
1566
|
-
* is a *hint* feed only: it neither trusts nor acts on the status. A consumer is
|
|
1567
|
-
* expected to verify against the chain (the contract managers) before doing
|
|
1568
|
-
* anything with it.
|
|
1569
|
-
*
|
|
1570
|
-
* Protocol (see `swap/src/api/ws.rs`):
|
|
1571
|
-
* → {"op":"subscribe","channel":"swap_status","args":[<uuid>,...]} (≤64 ids/frame)
|
|
1572
|
-
* ← {"channel":"swap_status","data":{"<uuid>":"<status>",...}}
|
|
1573
|
-
* ← {"op":"subscribed",...} (ack) ← {"op":...,"message":...} (error)
|
|
1574
|
-
* A single connection carries up to 256 subscriptions; that cap is enforced
|
|
1575
|
-
* client-side (see {@link WsStatusSource.subscribe}) because the server silently
|
|
1576
|
-
* drops the overflow.
|
|
1577
|
-
*/
|
|
1578
|
-
|
|
1579
|
-
/** A status update pushed by the server for one swap. */
|
|
1580
|
-
type SwapStatusUpdate = {
|
|
1581
|
-
swapId: string;
|
|
1582
|
-
status: SwapStatus;
|
|
1583
|
-
};
|
|
1584
|
-
/** The minimal WebSocket surface the source needs (the global `WebSocket` satisfies it). */
|
|
1585
|
-
interface WebSocketLike {
|
|
1586
|
-
send(data: string): void;
|
|
1587
|
-
close(): void;
|
|
1588
|
-
onopen: (() => void) | null;
|
|
1589
|
-
onmessage: ((event: {
|
|
1590
|
-
data: unknown;
|
|
1591
|
-
}) => void) | null;
|
|
1592
|
-
onclose: (() => void) | null;
|
|
1593
|
-
onerror: ((event: unknown) => void) | null;
|
|
1594
|
-
}
|
|
1595
|
-
type WsStatusSourceOptions = {
|
|
1596
|
-
/** Server base URL (http/https); the `ws(s)://…/ws` endpoint is derived from it. */
|
|
1597
|
-
serverUrl: string;
|
|
1598
|
-
/** WebSocket factory — defaults to the global `WebSocket` (browsers, Node ≥ 22). */
|
|
1599
|
-
webSocketFactory?: (url: string) => WebSocketLike;
|
|
1600
|
-
/** Reconnect backoff floor/ceiling (ms). Defaults: 1_000 / 30_000. */
|
|
1601
|
-
reconnectMinMs?: number;
|
|
1602
|
-
reconnectMaxMs?: number;
|
|
1603
|
-
};
|
|
1604
|
-
declare class WsStatusSource {
|
|
1605
|
-
#private;
|
|
1606
|
-
constructor(options: WsStatusSourceOptions);
|
|
1607
|
-
/** Open the connection and begin (re)subscribing. Idempotent. */
|
|
1608
|
-
start(): void;
|
|
1609
|
-
/** Close the connection and stop reconnecting. */
|
|
1610
|
-
stop(): void;
|
|
1611
|
-
/** Emit for each pushed status update. Returns an unsubscribe fn. */
|
|
1612
|
-
onStatus(cb: (update: SwapStatusUpdate) => void): () => void;
|
|
1613
|
-
/**
|
|
1614
|
-
* Emit whenever the socket comes (back) up after a disruption — a drop, or a
|
|
1615
|
-
* first connect that had to be retried. NOT emitted on a pristine first open:
|
|
1616
|
-
* hints were never live before it, so there is no gap to recover from. While
|
|
1617
|
-
* the socket was down, pushed transitions were lost for good (the server only
|
|
1618
|
-
* snapshots on subscribe), so a consumer should re-verify its world against
|
|
1619
|
-
* the chain on this signal.
|
|
1620
|
-
*/
|
|
1621
|
-
onReconnect(cb: () => void): () => void;
|
|
1622
1651
|
/**
|
|
1623
|
-
*
|
|
1624
|
-
*
|
|
1625
|
-
*
|
|
1626
|
-
*
|
|
1627
|
-
*
|
|
1628
|
-
* receive an update. Overflow is queued instead and promoted as slots free.
|
|
1652
|
+
* Put swaps on the hint feed as soon as they are tracked. {@link #onActions}
|
|
1653
|
+
* subscribes a swap when its first action is emitted, but a swap whose leg
|
|
1654
|
+
* cannot be classified yet (an unfunded lock on a chain without `eth_getLogs`)
|
|
1655
|
+
* emits nothing, and without this it would never receive the server hint
|
|
1656
|
+
* that its funding landed.
|
|
1629
1657
|
*/
|
|
1630
1658
|
subscribe(swapIds: string[]): void;
|
|
1631
|
-
/** Stop
|
|
1632
|
-
|
|
1659
|
+
/** Stop reacting, cancel pending retries, and close the hint feed. */
|
|
1660
|
+
stop(): void;
|
|
1633
1661
|
}
|
|
1634
1662
|
|
|
1635
1663
|
/**
|