@atomiqlabs/lp-lib 14.0.0-dev.6 → 14.0.0-dev.7

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.
@@ -0,0 +1,101 @@
1
+ import { Express } from "express";
2
+ import { FromBtcLnAutoInitSwap, FromBtcLnAutoInitSwapState } from "./FromBtcLnAutoInitSwap";
3
+ import { MultichainData, SwapHandlerType } from "../../SwapHandler";
4
+ import { ISwapPrice } from "../../../prices/ISwapPrice";
5
+ import { ChainSwapType, ClaimEvent, InitializeEvent, RefundEvent, SwapData } from "@atomiqlabs/base";
6
+ import { IIntermediaryStorage } from "../../../storage/IIntermediaryStorage";
7
+ import { FromBtcBaseConfig, FromBtcBaseSwapHandler } from "../FromBtcBaseSwapHandler";
8
+ import { ILightningWallet } from "../../../wallets/ILightningWallet";
9
+ import { LightningAssertions } from "../../assertions/LightningAssertions";
10
+ export type FromBtcLnAutoInitConfig = FromBtcBaseConfig & {
11
+ invoiceTimeoutSeconds?: number;
12
+ minCltv: bigint;
13
+ gracePeriod: bigint;
14
+ };
15
+ export type FromBtcLnAutoInitRequestType = {
16
+ address: string;
17
+ paymentHash: string;
18
+ amount: bigint;
19
+ token: string;
20
+ gasToken: string;
21
+ gasAmount: bigint;
22
+ claimerBounty: bigint;
23
+ descriptionHash?: string;
24
+ exactOut?: boolean;
25
+ };
26
+ /**
27
+ * Swap handler handling from BTCLN swaps using submarine swaps
28
+ */
29
+ export declare class FromBtcLnAutoInit extends FromBtcBaseSwapHandler<FromBtcLnAutoInitSwap, FromBtcLnAutoInitSwapState> {
30
+ readonly type = SwapHandlerType.FROM_BTCLN;
31
+ readonly swapType = ChainSwapType.HTLC;
32
+ readonly config: FromBtcLnAutoInitConfig;
33
+ readonly lightning: ILightningWallet;
34
+ readonly LightningAssertions: LightningAssertions;
35
+ constructor(storageDirectory: IIntermediaryStorage<FromBtcLnAutoInitSwap>, path: string, chains: MultichainData, lightning: ILightningWallet, swapPricing: ISwapPrice, config: FromBtcLnAutoInitConfig);
36
+ protected processPastSwap(swap: FromBtcLnAutoInitSwap): Promise<"REFUND" | "SETTLE" | null>;
37
+ protected refundSwaps(refundSwaps: FromBtcLnAutoInitSwap[]): Promise<void>;
38
+ protected settleInvoices(swaps: FromBtcLnAutoInitSwap[]): Promise<void>;
39
+ /**
40
+ * Checks past swaps, refunds and deletes ones that are already expired.
41
+ */
42
+ protected processPastSwaps(): Promise<void>;
43
+ protected processInitializeEvent(chainIdentifier: string, savedSwap: FromBtcLnAutoInitSwap, event: InitializeEvent<SwapData>): Promise<void>;
44
+ protected processClaimEvent(chainIdentifier: string, savedSwap: FromBtcLnAutoInitSwap, event: ClaimEvent<SwapData>): Promise<void>;
45
+ protected processRefundEvent(chainIdentifier: string, savedSwap: FromBtcLnAutoInitSwap, event: RefundEvent<SwapData>): Promise<void>;
46
+ /**
47
+ * Called when lightning HTLC is received, also signs an init transaction on the smart chain side, expiry of the
48
+ * smart chain authorization starts ticking as soon as this HTLC is received
49
+ *
50
+ * @param invoiceData
51
+ * @param invoice
52
+ */
53
+ private htlcReceived;
54
+ private offerHtlc;
55
+ /**
56
+ * Checks invoice description hash
57
+ *
58
+ * @param descriptionHash
59
+ * @throws {DefinedRuntimeError} will throw an error if the description hash is invalid
60
+ */
61
+ private checkDescriptionHash;
62
+ /**
63
+ * Asynchronously sends the LN node's public key to the client, so he can pre-fetch the node's channels from 1ml api
64
+ *
65
+ * @param responseStream
66
+ */
67
+ private sendPublicKeyAsync;
68
+ /**
69
+ * Returns the CLTV timeout (blockheight) of the received HTLC corresponding to the invoice. If multiple HTLCs are
70
+ * received (MPP) it returns the lowest of the timeouts
71
+ *
72
+ * @param invoice
73
+ */
74
+ private getInvoicePaymentsTimeout;
75
+ /**
76
+ * Checks if the received HTLC's CLTV timeout is large enough to still process the swap
77
+ *
78
+ * @param invoice
79
+ * @throws {DefinedRuntimeError} Will throw if HTLC expires too soon and therefore cannot be processed
80
+ * @returns expiry timeout in seconds
81
+ */
82
+ private checkHtlcExpiry;
83
+ /**
84
+ * Cancels the swap (CANCELED state) & also cancels the LN invoice (including all pending HTLCs)
85
+ *
86
+ * @param invoiceData
87
+ */
88
+ private cancelSwapAndInvoice;
89
+ /**
90
+ *
91
+ * Checks if the lightning invoice is in HELD state (htlcs received but yet unclaimed)
92
+ *
93
+ * @param paymentHash
94
+ * @throws {DefinedRuntimeError} Will throw if the lightning invoice is not found, or if it isn't in the HELD state
95
+ * @returns the fetched lightning invoice
96
+ */
97
+ private checkInvoiceStatus;
98
+ startRestServer(restServer: Express): void;
99
+ init(): Promise<void>;
100
+ getInfoData(): any;
101
+ }