@atomiqlabs/sdk 8.1.8 → 8.3.5
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/bitcoin/coinselect2/utils.d.ts +6 -0
- package/dist/bitcoin/wallet/BitcoinWallet.d.ts +41 -5
- package/dist/bitcoin/wallet/BitcoinWallet.js +36 -1
- package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +52 -2
- package/dist/bitcoin/wallet/IBitcoinWallet.js +2 -1
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +42 -7
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +36 -1
- package/dist/enums/FeeType.d.ts +8 -1
- package/dist/enums/FeeType.js +8 -1
- package/dist/enums/SwapAmountType.d.ts +7 -0
- package/dist/enums/SwapAmountType.js +7 -0
- package/dist/enums/SwapDirection.d.ts +7 -0
- package/dist/enums/SwapDirection.js +7 -0
- package/dist/enums/SwapType.d.ts +62 -1
- package/dist/enums/SwapType.js +62 -1
- package/dist/errors/IntermediaryError.d.ts +4 -0
- package/dist/errors/IntermediaryError.js +1 -0
- package/dist/errors/RequestError.d.ts +15 -1
- package/dist/errors/RequestError.js +8 -0
- package/dist/errors/UserError.d.ts +1 -0
- package/dist/errors/UserError.js +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +7 -6
- package/dist/intermediaries/Intermediary.d.ts +61 -14
- package/dist/intermediaries/Intermediary.js +38 -11
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +62 -29
- package/dist/intermediaries/IntermediaryDiscovery.js +39 -24
- package/dist/prices/RedundantSwapPrice.d.ts +26 -5
- package/dist/prices/RedundantSwapPrice.js +22 -2
- package/dist/prices/SingleSwapPrice.d.ts +10 -7
- package/dist/prices/SingleSwapPrice.js +11 -8
- package/dist/prices/SwapPriceWithChain.d.ts +56 -19
- package/dist/prices/SwapPriceWithChain.js +62 -25
- package/dist/prices/abstract/IPriceProvider.d.ts +4 -4
- package/dist/prices/abstract/IPriceProvider.js +1 -1
- package/dist/prices/abstract/ISwapPrice.d.ts +95 -46
- package/dist/prices/abstract/ISwapPrice.js +104 -56
- package/dist/prices/providers/BinancePriceProvider.d.ts +8 -1
- package/dist/prices/providers/BinancePriceProvider.js +8 -1
- package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +7 -1
- package/dist/prices/providers/CoinGeckoPriceProvider.js +7 -1
- package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +7 -1
- package/dist/prices/providers/CoinPaprikaPriceProvider.js +7 -1
- package/dist/prices/providers/CustomPriceProvider.d.ts +12 -1
- package/dist/prices/providers/CustomPriceProvider.js +12 -1
- package/dist/prices/providers/KrakenPriceProvider.d.ts +10 -1
- package/dist/prices/providers/KrakenPriceProvider.js +10 -1
- package/dist/prices/providers/OKXPriceProvider.d.ts +7 -1
- package/dist/prices/providers/OKXPriceProvider.js +7 -1
- package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +3 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.js +3 -0
- package/dist/storage/IUnifiedStorage.d.ts +19 -7
- package/dist/storage/UnifiedSwapStorage.d.ts +33 -3
- package/dist/storage/UnifiedSwapStorage.js +29 -1
- package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +31 -7
- package/dist/storage-browser/IndexedDBUnifiedStorage.js +29 -6
- package/dist/storage-browser/LocalStorageManager.d.ts +25 -1
- package/dist/storage-browser/LocalStorageManager.js +25 -1
- package/dist/swapper/Swapper.d.ts +380 -226
- package/dist/swapper/Swapper.js +383 -349
- package/dist/swapper/SwapperFactory.d.ts +66 -18
- package/dist/swapper/SwapperFactory.js +24 -3
- package/dist/swapper/SwapperUtils.d.ts +75 -28
- package/dist/swapper/SwapperUtils.js +107 -60
- package/dist/swapper/SwapperWithChain.d.ts +286 -91
- package/dist/swapper/SwapperWithChain.js +218 -64
- package/dist/swapper/SwapperWithSigner.d.ts +229 -80
- package/dist/swapper/SwapperWithSigner.js +190 -44
- package/dist/swaps/IAddressSwap.d.ts +12 -3
- package/dist/swaps/IAddressSwap.js +3 -2
- package/dist/swaps/IBTCWalletSwap.d.ts +26 -8
- package/dist/swaps/IBTCWalletSwap.js +3 -2
- package/dist/swaps/IClaimableSwap.d.ts +38 -6
- package/dist/swaps/IClaimableSwap.js +3 -2
- package/dist/swaps/IClaimableSwapWrapper.d.ts +11 -1
- package/dist/swaps/IRefundableSwap.d.ts +31 -5
- package/dist/swaps/IRefundableSwap.js +3 -2
- package/dist/swaps/ISwap.d.ts +162 -24
- package/dist/swaps/ISwap.js +92 -35
- package/dist/swaps/ISwapWithGasDrop.d.ts +8 -2
- package/dist/swaps/ISwapWithGasDrop.js +2 -1
- package/dist/swaps/ISwapWrapper.d.ts +161 -52
- package/dist/swaps/ISwapWrapper.js +131 -73
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +51 -6
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +22 -12
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +65 -12
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +38 -19
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +39 -9
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +30 -21
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +31 -15
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +33 -18
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +97 -28
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +91 -27
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +22 -9
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +24 -11
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +278 -60
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +519 -241
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +77 -26
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +132 -50
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +313 -52
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +544 -194
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +87 -26
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +147 -58
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +222 -55
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +462 -244
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +77 -23
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +116 -46
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +195 -58
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +324 -191
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +30 -5
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +44 -19
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +61 -20
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +75 -32
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +76 -50
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +106 -101
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +37 -14
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +66 -20
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +46 -17
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +82 -27
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +350 -88
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +482 -215
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +76 -24
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +247 -124
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +148 -20
- package/dist/swaps/trusted/ln/LnForGasSwap.js +175 -45
- package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +29 -10
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +30 -11
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +202 -49
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +232 -80
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +34 -12
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +33 -14
- package/dist/types/AmountData.d.ts +2 -1
- package/dist/types/CustomPriceFunction.d.ts +8 -2
- package/dist/types/PriceInfoType.d.ts +4 -4
- package/dist/types/PriceInfoType.js +3 -3
- package/dist/types/SwapExecutionAction.d.ts +85 -4
- package/dist/types/SwapWithSigner.d.ts +5 -2
- package/dist/types/SwapWithSigner.js +5 -2
- package/dist/types/Token.d.ts +11 -5
- package/dist/types/Token.js +6 -3
- package/dist/types/TokenAmount.d.ts +3 -0
- package/dist/types/TokenAmount.js +2 -0
- package/dist/types/fees/Fee.d.ts +3 -2
- package/dist/types/fees/FeeBreakdown.d.ts +3 -2
- package/dist/types/fees/PercentagePPM.d.ts +4 -2
- package/dist/types/fees/PercentagePPM.js +2 -1
- package/dist/types/lnurl/LNURLPay.d.ts +20 -12
- package/dist/types/lnurl/LNURLPay.js +8 -4
- package/dist/types/lnurl/LNURLWithdraw.d.ts +17 -10
- package/dist/types/lnurl/LNURLWithdraw.js +8 -4
- package/dist/types/wallets/LightningInvoiceCreateService.d.ts +24 -0
- package/dist/types/wallets/LightningInvoiceCreateService.js +15 -0
- package/dist/types/wallets/MinimalBitcoinWalletInterface.d.ts +3 -1
- package/dist/types/wallets/MinimalLightningNetworkWalletInterface.d.ts +4 -2
- package/dist/utils/BitcoinUtils.d.ts +1 -0
- package/dist/utils/BitcoinUtils.js +5 -1
- package/dist/utils/SwapUtils.d.ts +58 -1
- package/dist/utils/SwapUtils.js +55 -1
- package/dist/utils/TokenUtils.d.ts +10 -2
- package/dist/utils/TokenUtils.js +12 -4
- package/package.json +3 -3
- package/src/bitcoin/coinselect2/utils.ts +6 -0
- package/src/bitcoin/wallet/BitcoinWallet.ts +41 -5
- package/src/bitcoin/wallet/IBitcoinWallet.ts +57 -2
- package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +42 -6
- package/src/enums/FeeType.ts +8 -1
- package/src/enums/SwapAmountType.ts +7 -0
- package/src/enums/SwapDirection.ts +7 -0
- package/src/enums/SwapType.ts +62 -2
- package/src/errors/IntermediaryError.ts +4 -0
- package/src/errors/RequestError.ts +15 -1
- package/src/errors/UserError.ts +1 -0
- package/src/index.ts +12 -5
- package/src/intermediaries/Intermediary.ts +61 -14
- package/src/intermediaries/IntermediaryDiscovery.ts +69 -34
- package/src/prices/RedundantSwapPrice.ts +26 -6
- package/src/prices/SingleSwapPrice.ts +11 -8
- package/src/prices/SwapPriceWithChain.ts +63 -26
- package/src/prices/abstract/IPriceProvider.ts +4 -4
- package/src/prices/abstract/ISwapPrice.ts +115 -66
- package/src/prices/providers/BinancePriceProvider.ts +8 -1
- package/src/prices/providers/CoinGeckoPriceProvider.ts +7 -1
- package/src/prices/providers/CoinPaprikaPriceProvider.ts +7 -1
- package/src/prices/providers/CustomPriceProvider.ts +12 -1
- package/src/prices/providers/KrakenPriceProvider.ts +10 -1
- package/src/prices/providers/OKXPriceProvider.ts +7 -1
- package/src/prices/providers/abstract/ExchangePriceProvider.ts +3 -0
- package/src/storage/IUnifiedStorage.ts +19 -7
- package/src/storage/UnifiedSwapStorage.ts +33 -3
- package/src/storage-browser/IndexedDBUnifiedStorage.ts +31 -8
- package/src/storage-browser/LocalStorageManager.ts +25 -1
- package/src/swapper/Swapper.ts +599 -390
- package/src/swapper/SwapperFactory.ts +73 -24
- package/src/swapper/SwapperUtils.ts +107 -60
- package/src/swapper/SwapperWithChain.ts +320 -81
- package/src/swapper/SwapperWithSigner.ts +263 -56
- package/src/swaps/IAddressSwap.ts +13 -3
- package/src/swaps/IBTCWalletSwap.ts +26 -10
- package/src/swaps/IClaimableSwap.ts +41 -6
- package/src/swaps/IClaimableSwapWrapper.ts +11 -2
- package/src/swaps/IRefundableSwap.ts +34 -5
- package/src/swaps/ISwap.ts +224 -85
- package/src/swaps/ISwapWithGasDrop.ts +8 -2
- package/src/swaps/ISwapWrapper.ts +216 -98
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +64 -18
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +83 -37
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +61 -30
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +37 -19
- package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +123 -50
- package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +24 -11
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +562 -258
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +156 -62
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +592 -227
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +177 -74
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +483 -245
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +141 -59
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +350 -195
- package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +48 -23
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +87 -40
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +110 -110
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +89 -34
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +101 -31
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +556 -259
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +292 -148
- package/src/swaps/trusted/ln/LnForGasSwap.ts +186 -47
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +34 -15
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +262 -88
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +41 -19
- package/src/types/AmountData.ts +2 -1
- package/src/types/CustomPriceFunction.ts +8 -2
- package/src/types/PriceInfoType.ts +4 -4
- package/src/types/SwapExecutionAction.ts +97 -5
- package/src/types/SwapWithSigner.ts +8 -4
- package/src/types/Token.ts +12 -5
- package/src/types/TokenAmount.ts +3 -0
- package/src/types/fees/Fee.ts +3 -2
- package/src/types/fees/FeeBreakdown.ts +3 -2
- package/src/types/fees/PercentagePPM.ts +4 -2
- package/src/types/lnurl/LNURLPay.ts +20 -12
- package/src/types/lnurl/LNURLWithdraw.ts +17 -10
- package/src/types/wallets/LightningInvoiceCreateService.ts +30 -0
- package/src/types/wallets/MinimalBitcoinWalletInterface.ts +3 -1
- package/src/types/wallets/MinimalLightningNetworkWalletInterface.ts +4 -2
- package/src/utils/BitcoinUtils.ts +5 -0
- package/src/utils/SwapUtils.ts +63 -1
- package/src/utils/TokenUtils.ts +12 -4
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +0 -68
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +0 -2
- package/dist/bitcoin/LightningNetworkApi.d.ts +0 -12
- package/dist/bitcoin/LightningNetworkApi.js +0 -2
- package/dist/bitcoin/mempool/MempoolApi.d.ts +0 -350
- package/dist/bitcoin/mempool/MempoolApi.js +0 -311
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +0 -44
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +0 -48
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +0 -119
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +0 -361
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +0 -22
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +0 -105
- package/dist/errors/PaymentAuthError.d.ts +0 -11
- package/dist/errors/PaymentAuthError.js +0 -23
- package/src/errors/PaymentAuthError.ts +0 -26
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {decode as bolt11Decode, PaymentRequestObject, TagsObject} from "@atomiqlabs/bolt11";
|
|
2
|
-
import {ToBTCLNSwap} from "./ToBTCLNSwap";
|
|
2
|
+
import {ToBTCLNSwap, ToBTCLNSwapInit} from "./ToBTCLNSwap";
|
|
3
3
|
import {IToBTCDefinition, IToBTCWrapper} from "../IToBTCWrapper";
|
|
4
4
|
import {UserError} from "../../../../errors/UserError";
|
|
5
5
|
import {ChainSwapType, ChainType, SwapCommitState, SwapCommitStateType} from "@atomiqlabs/base";
|
|
@@ -22,20 +22,7 @@ import {AmountData} from "../../../../types/AmountData";
|
|
|
22
22
|
import {LNURLPayParamsWithUrl} from "../../../../types/lnurl/LNURLPay";
|
|
23
23
|
import {tryWithRetries} from "../../../../utils/RetryUtils";
|
|
24
24
|
import {AllOptional, AllRequired} from "../../../../utils/TypeUtils";
|
|
25
|
-
|
|
26
|
-
export type LightningWalletCallback = (valueSats: number, abortSignal?: AbortSignal) => Promise<string>;
|
|
27
|
-
export type InvoiceCreateService = {
|
|
28
|
-
getInvoice: LightningWalletCallback,
|
|
29
|
-
minMsats?: bigint,
|
|
30
|
-
maxMSats?: bigint
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export function isInvoiceCreateService(obj: any): obj is InvoiceCreateService {
|
|
34
|
-
return typeof(obj)==="object" &&
|
|
35
|
-
typeof(obj.getInvoice)==="function" &&
|
|
36
|
-
(obj.minMsats==null || typeof(obj.minMsats)==="bigint") &&
|
|
37
|
-
(obj.maxMSats==null || typeof(obj.maxMSats)==="bigint");
|
|
38
|
-
}
|
|
25
|
+
import {LightningInvoiceCreateService} from "../../../../types/wallets/LightningInvoiceCreateService";
|
|
39
26
|
|
|
40
27
|
export type ToBTCLNOptions = {
|
|
41
28
|
expirySeconds?: number,
|
|
@@ -53,9 +40,17 @@ export type ToBTCLNWrapperOptions = ISwapWrapperOptions & {
|
|
|
53
40
|
|
|
54
41
|
export type ToBTCLNDefinition<T extends ChainType> = IToBTCDefinition<T, ToBTCLNWrapper<T>, ToBTCLNSwap<T>>;
|
|
55
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Escrow based (HTLC) swap for Smart chains -> Bitcoin lightning
|
|
45
|
+
*
|
|
46
|
+
* @category Swaps/Smart chain → Lightning
|
|
47
|
+
*/
|
|
56
48
|
export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCLNDefinition<T>, ToBTCLNWrapperOptions> {
|
|
57
|
-
public readonly TYPE = SwapType.TO_BTCLN;
|
|
58
|
-
|
|
49
|
+
public readonly TYPE: SwapType.TO_BTCLN = SwapType.TO_BTCLN;
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
readonly _swapDeserializer = ToBTCLNSwap;
|
|
59
54
|
|
|
60
55
|
constructor(
|
|
61
56
|
chainIdentifier: string,
|
|
@@ -81,9 +76,9 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
81
76
|
}
|
|
82
77
|
|
|
83
78
|
private toRequiredSwapOptions(amountData: AmountData, options?: ToBTCLNOptions, pricePreFetchPromise?: Promise<bigint | undefined>, abortSignal?: AbortSignal): AllRequired<ToBTCLNOptions> {
|
|
84
|
-
const expirySeconds = options?.expirySeconds ?? this.
|
|
85
|
-
const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this.
|
|
86
|
-
const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this.
|
|
79
|
+
const expirySeconds = options?.expirySeconds ?? this._options.paymentTimeoutSeconds;
|
|
80
|
+
const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this._options.lightningBaseFee);
|
|
81
|
+
const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this._options.lightningFeePPM);
|
|
87
82
|
|
|
88
83
|
let maxFee: bigint | Promise<bigint>;
|
|
89
84
|
if(options?.maxFee!=null) {
|
|
@@ -91,10 +86,10 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
91
86
|
} else if(amountData.exactIn) {
|
|
92
87
|
if(pricePreFetchPromise!=null) {
|
|
93
88
|
maxFee = pricePreFetchPromise
|
|
94
|
-
.then(val => this.
|
|
89
|
+
.then(val => this._prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal, val))
|
|
95
90
|
.then(_maxBaseFee => this.calculateFeeForAmount(amountData.amount, _maxBaseFee, maxRoutingPPM))
|
|
96
91
|
} else {
|
|
97
|
-
maxFee = this.
|
|
92
|
+
maxFee = this._prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal)
|
|
98
93
|
.then(_maxBaseFee => this.calculateFeeForAmount(amountData.amount, _maxBaseFee, maxRoutingPPM))
|
|
99
94
|
}
|
|
100
95
|
} else {
|
|
@@ -110,14 +105,22 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
110
105
|
}
|
|
111
106
|
}
|
|
112
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Verifies whether a given payment hash was already paid by checking the local
|
|
110
|
+
* storage of known swaps
|
|
111
|
+
*
|
|
112
|
+
* @param paymentHash Payment hash to check
|
|
113
|
+
*
|
|
114
|
+
* @private
|
|
115
|
+
*/
|
|
113
116
|
private async checkPaymentHashWasPaid(paymentHash: string) {
|
|
114
117
|
const swaps = await this.unifiedStorage.query(
|
|
115
118
|
[[{key: "type", value: this.TYPE}, {key: "paymentHash", value: paymentHash}]],
|
|
116
|
-
(obj: any) => new this.
|
|
119
|
+
(obj: any) => new this._swapDeserializer(this, obj)
|
|
117
120
|
);
|
|
118
121
|
|
|
119
122
|
for(let value of swaps) {
|
|
120
|
-
if(value.
|
|
123
|
+
if(value._state===ToBTCSwapState.CLAIMED || value._state===ToBTCSwapState.SOFT_CLAIMED)
|
|
121
124
|
throw new UserError("Lightning invoice was already paid!");
|
|
122
125
|
}
|
|
123
126
|
}
|
|
@@ -128,12 +131,14 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
128
131
|
* @param amount BTC amount of the swap in satoshis
|
|
129
132
|
* @param overrideBaseFee Override wrapper's default base fee
|
|
130
133
|
* @param overrideFeePPM Override wrapper's default PPM
|
|
131
|
-
*
|
|
134
|
+
*
|
|
132
135
|
* @returns Maximum lightning routing fee in sats
|
|
136
|
+
*
|
|
137
|
+
* @private
|
|
133
138
|
*/
|
|
134
139
|
private calculateFeeForAmount(amount: bigint, overrideBaseFee?: bigint, overrideFeePPM?: bigint) : bigint {
|
|
135
|
-
return BigInt(overrideBaseFee ?? this.
|
|
136
|
-
+ (amount * BigInt(overrideFeePPM ?? this.
|
|
140
|
+
return BigInt(overrideBaseFee ?? this._options.lightningBaseFee)
|
|
141
|
+
+ (amount * BigInt(overrideFeePPM ?? this._options.lightningFeePPM) / 1000000n);
|
|
137
142
|
}
|
|
138
143
|
|
|
139
144
|
/**
|
|
@@ -147,8 +152,10 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
147
152
|
* @param options Swap options as passed to the swap create function
|
|
148
153
|
* @param data Parsed swap data returned by the LP
|
|
149
154
|
* @param requiredTotal Required total to be paid on the input (for exactIn swaps)
|
|
150
|
-
*
|
|
155
|
+
*
|
|
151
156
|
* @throws {IntermediaryError} In case the response is not valid
|
|
157
|
+
*
|
|
158
|
+
* @private
|
|
152
159
|
*/
|
|
153
160
|
private async verifyReturnedData(
|
|
154
161
|
signer: string,
|
|
@@ -166,7 +173,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
166
173
|
throw new IntermediaryError("Invalid data returned - total amount");
|
|
167
174
|
|
|
168
175
|
if(parsedPr.tagsObject.payment_hash==null) throw new Error("Swap invoice doesn't contain payment hash field!");
|
|
169
|
-
const claimHash = this.
|
|
176
|
+
const claimHash = this._contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
|
|
170
177
|
|
|
171
178
|
if(
|
|
172
179
|
data.getAmount() !== resp.total ||
|
|
@@ -196,6 +203,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
196
203
|
* @param abort Abort signal or controller, if AbortController is passed it is used as-is, when AbortSignal is passed
|
|
197
204
|
* it is extended with extendAbortController and then used
|
|
198
205
|
* @param additionalParams Additional params that should be sent to the LP
|
|
206
|
+
*
|
|
199
207
|
* @private
|
|
200
208
|
*/
|
|
201
209
|
private async getIntermediaryQuote(
|
|
@@ -229,7 +237,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
229
237
|
token: amountData.token,
|
|
230
238
|
feeRate: throwIfUndefined(preFetches.feeRatePromise),
|
|
231
239
|
additionalParams
|
|
232
|
-
}, this.
|
|
240
|
+
}, this._options.postRequestTimeout, abortController.signal, retryCount>0 ? false : undefined);
|
|
233
241
|
|
|
234
242
|
return {
|
|
235
243
|
signDataPromise: preFetches.signDataPrefetchPromise ?? this.preFetchSignData(signDataPrefetch),
|
|
@@ -240,7 +248,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
240
248
|
if(parsedPr.millisatoshis==null) throw new Error("Swap invoice doesn't have msat amount field!");
|
|
241
249
|
const amountOut: bigint = (BigInt(parsedPr.millisatoshis) + 999n) / 1000n;
|
|
242
250
|
const totalFee: bigint = resp.swapFee + resp.maxFee;
|
|
243
|
-
const data: T["Data"] = new this.
|
|
251
|
+
const data: T["Data"] = new this._swapDataDeserializer(resp.data);
|
|
244
252
|
data.setOfferer(signer);
|
|
245
253
|
|
|
246
254
|
await this.verifyReturnedData(signer, resp, parsedPr, amountData.token, lp, options, data);
|
|
@@ -286,20 +294,21 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
286
294
|
}
|
|
287
295
|
|
|
288
296
|
/**
|
|
289
|
-
* Returns a newly created swap
|
|
297
|
+
* Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol,
|
|
298
|
+
* the amount is parsed from the provided lightning network payment request (bolt11 invoice)
|
|
290
299
|
*
|
|
291
|
-
* @param signer
|
|
292
|
-
* @param
|
|
293
|
-
* @param amountData
|
|
294
|
-
* @param lps
|
|
295
|
-
* @param options
|
|
296
|
-
* @param additionalParams
|
|
297
|
-
* @param abortSignal
|
|
298
|
-
* @param preFetches
|
|
300
|
+
* @param signer Source chain signer address initiating the swap
|
|
301
|
+
* @param recipient BOLT11 payment request (bitcoin lightning invoice) you wish to pay
|
|
302
|
+
* @param amountData Token to swap
|
|
303
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
304
|
+
* @param options Optional additional quote options
|
|
305
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
306
|
+
* @param abortSignal Abort signal
|
|
307
|
+
* @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
|
|
299
308
|
*/
|
|
300
309
|
async create(
|
|
301
310
|
signer: string,
|
|
302
|
-
|
|
311
|
+
recipient: string,
|
|
303
312
|
amountData: Omit<AmountData, "amount">,
|
|
304
313
|
lps: Intermediary[],
|
|
305
314
|
options?: ToBTCLNOptions,
|
|
@@ -315,13 +324,13 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
315
324
|
quote: Promise<ToBTCLNSwap<T>>,
|
|
316
325
|
intermediary: Intermediary
|
|
317
326
|
}[]> {
|
|
318
|
-
const parsedPr = bolt11Decode(
|
|
327
|
+
const parsedPr = bolt11Decode(recipient);
|
|
319
328
|
if(parsedPr.millisatoshis==null) throw new UserError("Must be an invoice with amount");
|
|
320
329
|
const amountOut: bigint = (BigInt(parsedPr.millisatoshis) + 999n) / 1000n;
|
|
321
330
|
|
|
322
|
-
const expirySeconds = options?.expirySeconds ?? this.
|
|
323
|
-
const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this.
|
|
324
|
-
const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this.
|
|
331
|
+
const expirySeconds = options?.expirySeconds ?? this._options.paymentTimeoutSeconds;
|
|
332
|
+
const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this._options.lightningBaseFee);
|
|
333
|
+
const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this._options.lightningFeePPM);
|
|
325
334
|
|
|
326
335
|
const _options: AllRequired<ToBTCLNOptions> = {
|
|
327
336
|
expirySeconds,
|
|
@@ -334,20 +343,20 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
334
343
|
if(parsedPr.tagsObject.payment_hash==null) throw new Error("Provided lightning invoice doesn't contain payment hash field!");
|
|
335
344
|
await this.checkPaymentHashWasPaid(parsedPr.tagsObject.payment_hash);
|
|
336
345
|
|
|
337
|
-
const claimHash = this.
|
|
346
|
+
const claimHash = this._contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
|
|
338
347
|
|
|
339
348
|
const _abortController = extendAbortController(abortSignal);
|
|
340
349
|
const _preFetches = preFetches ?? {
|
|
341
350
|
pricePreFetchPromise: this.preFetchPrice(amountData, _abortController.signal),
|
|
342
351
|
feeRatePromise: this.preFetchFeeRate(signer, amountData, claimHash.toString("hex"), _abortController),
|
|
343
352
|
usdPricePrefetchPromise: this.preFetchUsdPrice(_abortController.signal),
|
|
344
|
-
signDataPrefetchPromise: this.
|
|
353
|
+
signDataPrefetchPromise: this._contract.preFetchBlockDataForSignatures==null ? this.preFetchSignData(Promise.resolve(true)) : undefined
|
|
345
354
|
};
|
|
346
355
|
|
|
347
356
|
return lps.map(lp => {
|
|
348
357
|
return {
|
|
349
358
|
intermediary: lp,
|
|
350
|
-
quote: this.getIntermediaryQuote(signer, amountData, lp,
|
|
359
|
+
quote: this.getIntermediaryQuote(signer, amountData, lp, recipient, parsedPr, _options, _preFetches, _abortController.signal, additionalParams)
|
|
351
360
|
}
|
|
352
361
|
});
|
|
353
362
|
}
|
|
@@ -356,14 +365,15 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
356
365
|
* Parses and fetches lnurl pay params from the specified lnurl
|
|
357
366
|
*
|
|
358
367
|
* @param lnurl LNURL to be parsed and fetched
|
|
359
|
-
* @param abortSignal
|
|
360
|
-
* @private
|
|
368
|
+
* @param abortSignal Abort signal
|
|
361
369
|
* @throws {UserError} if the LNURL is invalid or if it's not a LNURL-pay
|
|
370
|
+
*
|
|
371
|
+
* @private
|
|
362
372
|
*/
|
|
363
373
|
private async getLNURLPay(lnurl: string | LNURLPayParamsWithUrl, abortSignal: AbortSignal): Promise<LNURLPayParamsWithUrl> {
|
|
364
374
|
if(typeof(lnurl)!=="string") return lnurl;
|
|
365
375
|
|
|
366
|
-
const res = await LNURL.getLNURL(lnurl, true, this.
|
|
376
|
+
const res = await LNURL.getLNURL(lnurl, true, this._options.getRequestTimeout, abortSignal);
|
|
367
377
|
if(res==null) throw new UserError("Invalid LNURL");
|
|
368
378
|
if(res.tag!=="payRequest") throw new UserError("Not a LNURL-pay");
|
|
369
379
|
return res;
|
|
@@ -372,21 +382,23 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
372
382
|
/**
|
|
373
383
|
* Returns the quote/swap from the given LP
|
|
374
384
|
*
|
|
375
|
-
* @param signer
|
|
376
|
-
* @param amountData
|
|
385
|
+
* @param signer Source chain signer address initiating the swap
|
|
386
|
+
* @param amountData Token to swap
|
|
377
387
|
* @param invoiceCreateService Service for creating fixed amount invoices
|
|
378
|
-
* @param lp Intermediary
|
|
379
|
-
* @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay
|
|
380
|
-
*
|
|
381
|
-
* @param
|
|
382
|
-
* @param
|
|
388
|
+
* @param lp Intermediary (LPs) to get the quote from
|
|
389
|
+
* @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay, used to estimate
|
|
390
|
+
* network fees for an actual invoice
|
|
391
|
+
* @param options Optional additional quote options
|
|
392
|
+
* @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
|
|
393
|
+
* @param abortSignal Abort signal
|
|
383
394
|
* @param additionalParams Additional params to be sent to the intermediary
|
|
395
|
+
*
|
|
384
396
|
* @private
|
|
385
397
|
*/
|
|
386
398
|
private async getIntermediaryQuoteExactIn(
|
|
387
399
|
signer: string,
|
|
388
400
|
amountData: AmountData,
|
|
389
|
-
invoiceCreateService:
|
|
401
|
+
invoiceCreateService: LightningInvoiceCreateService,
|
|
390
402
|
lp: Intermediary,
|
|
391
403
|
dummyPr: string,
|
|
392
404
|
options: AllRequired<ToBTCLNOptions> & {comment?: string},
|
|
@@ -413,7 +425,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
413
425
|
maxFee: await options.maxFee,
|
|
414
426
|
expiryTimestamp: options.expiryTimestamp,
|
|
415
427
|
additionalParams
|
|
416
|
-
}, this.
|
|
428
|
+
}, this._options.postRequestTimeout, abortController.signal, retryCount>0 ? false : undefined);
|
|
417
429
|
|
|
418
430
|
return {
|
|
419
431
|
signDataPromise: this.preFetchSignData(signDataPrefetch),
|
|
@@ -440,14 +452,14 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
440
452
|
reqId: prepareResp.reqId,
|
|
441
453
|
feeRate: throwIfUndefined(preFetches.feeRatePromise),
|
|
442
454
|
additionalParams
|
|
443
|
-
}, this.
|
|
455
|
+
}, this._options.postRequestTimeout, abortController.signal, retryCount>0 ? false : undefined),
|
|
444
456
|
undefined, RequestError, abortController.signal
|
|
445
457
|
);
|
|
446
458
|
|
|
447
459
|
if(parsedInvoice.millisatoshis==null) throw new Error("Swap invoice doesn't have msat amount field!");
|
|
448
460
|
const amountOut: bigint = (BigInt(parsedInvoice.millisatoshis) + 999n) / 1000n;
|
|
449
461
|
const totalFee: bigint = resp.swapFee + resp.maxFee;
|
|
450
|
-
const data: T["Data"] = new this.
|
|
462
|
+
const data: T["Data"] = new this._swapDataDeserializer(resp.data);
|
|
451
463
|
data.setOfferer(signer);
|
|
452
464
|
|
|
453
465
|
await this.verifyReturnedData(signer, resp, parsedInvoice, amountData.token, lp, options, data, amountData.amount);
|
|
@@ -493,19 +505,21 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
493
505
|
}
|
|
494
506
|
|
|
495
507
|
/**
|
|
496
|
-
* Returns a newly created swap
|
|
508
|
+
* Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol via
|
|
509
|
+
* invoice creation service. This allows exactIn swaps by requesting the desired fixed amount lightning
|
|
510
|
+
* network invoice from the service.
|
|
497
511
|
*
|
|
498
|
-
* @param signer
|
|
499
|
-
* @param invoiceCreateServicePromise
|
|
500
|
-
* @param amountData
|
|
501
|
-
* @param lps
|
|
502
|
-
* @param options
|
|
503
|
-
* @param additionalParams
|
|
504
|
-
* @param abortSignal
|
|
512
|
+
* @param signer Source chain signer address initiating the swap
|
|
513
|
+
* @param invoiceCreateServicePromise Service to request destination lightning network invoices from
|
|
514
|
+
* @param amountData Amount, token and exact input/output data for to swap
|
|
515
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
516
|
+
* @param options Optional additional quote options
|
|
517
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
518
|
+
* @param abortSignal Abort signal
|
|
505
519
|
*/
|
|
506
520
|
async createViaInvoiceCreateService(
|
|
507
521
|
signer: string,
|
|
508
|
-
invoiceCreateServicePromise: Promise<
|
|
522
|
+
invoiceCreateServicePromise: Promise<LightningInvoiceCreateService>,
|
|
509
523
|
amountData: AmountData,
|
|
510
524
|
lps: Intermediary[],
|
|
511
525
|
options?: ToBTCLNOptions,
|
|
@@ -521,7 +535,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
521
535
|
const pricePreFetchPromise: Promise<bigint | undefined> = this.preFetchPrice(amountData, _abortController.signal);
|
|
522
536
|
const usdPricePrefetchPromise: Promise<number | undefined> = this.preFetchUsdPrice(_abortController.signal);
|
|
523
537
|
const feeRatePromise: Promise<string | undefined> = this.preFetchFeeRate(signer, amountData, undefined, _abortController);
|
|
524
|
-
const signDataPrefetchPromise: Promise<T["PreFetchVerification"] | undefined> | undefined = this.
|
|
538
|
+
const signDataPrefetchPromise: Promise<T["PreFetchVerification"] | undefined> | undefined = this._contract.preFetchBlockDataForSignatures==null ?
|
|
525
539
|
this.preFetchSignData(Promise.resolve(true)) :
|
|
526
540
|
undefined;
|
|
527
541
|
|
|
@@ -570,15 +584,17 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
570
584
|
}
|
|
571
585
|
|
|
572
586
|
/**
|
|
573
|
-
* Returns a newly created swap
|
|
587
|
+
* Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol. Pays to
|
|
588
|
+
* an LNURL-pay link. This allows exactIn swaps by requesting the desired fixed amount lightning
|
|
589
|
+
* network invoice from the LNURL service.
|
|
574
590
|
*
|
|
575
|
-
* @param signer
|
|
576
|
-
* @param lnurl
|
|
577
|
-
* @param amountData
|
|
578
|
-
* @param lps
|
|
579
|
-
* @param options
|
|
580
|
-
* @param additionalParams
|
|
581
|
-
* @param abortSignal
|
|
591
|
+
* @param signer Source chain signer address initiating the swap
|
|
592
|
+
* @param lnurl LNURL-pay link of the recipient
|
|
593
|
+
* @param amountData Amount, token and exact input/output data for to swap
|
|
594
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
595
|
+
* @param options Optional additional quote options
|
|
596
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
597
|
+
* @param abortSignal Abort signal
|
|
582
598
|
*/
|
|
583
599
|
async createViaLNURL(
|
|
584
600
|
signer: string,
|
|
@@ -607,7 +623,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
607
623
|
getInvoice: async (amountSats: number, abortSignal?: AbortSignal) => {
|
|
608
624
|
const {invoice, successAction} = await LNURL.useLNURLPay(
|
|
609
625
|
payRequest, BigInt(amountSats), options?.comment,
|
|
610
|
-
this.
|
|
626
|
+
this._options.getRequestTimeout, abortSignal
|
|
611
627
|
);
|
|
612
628
|
if(successAction!=null) successActions[invoice] = successAction;
|
|
613
629
|
return invoice;
|
|
@@ -634,18 +650,22 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
634
650
|
|
|
635
651
|
return quotes.map(value => ({
|
|
636
652
|
quote: value.quote.then(quote => {
|
|
637
|
-
|
|
653
|
+
let _successAction: LNURLPaySuccessAction | undefined;
|
|
638
654
|
const quoteAddress = quote.getOutputAddress();
|
|
639
655
|
if(quoteAddress!=null) {
|
|
640
656
|
const successAction = successActions[quoteAddress];
|
|
641
|
-
if(successAction!=null)
|
|
657
|
+
if(successAction!=null) _successAction = successAction;
|
|
642
658
|
}
|
|
659
|
+
quote._setLNURLData(resolved.url, _successAction);
|
|
643
660
|
return quote;
|
|
644
661
|
}),
|
|
645
662
|
intermediary: value.intermediary
|
|
646
663
|
}));
|
|
647
664
|
}
|
|
648
665
|
|
|
666
|
+
/**
|
|
667
|
+
* @inheritDoc
|
|
668
|
+
*/
|
|
649
669
|
async recoverFromSwapDataAndState(
|
|
650
670
|
init: {data: T["Data"], getInitTxId: () => Promise<string>, getTxBlock: () => Promise<{blockTime: number, blockHeight: number}>},
|
|
651
671
|
state: SwapCommitState,
|
|
@@ -660,7 +680,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
660
680
|
paymentHash = Buffer.from(sha256(Buffer.from(secret, "hex"))).toString("hex");
|
|
661
681
|
}
|
|
662
682
|
|
|
663
|
-
const
|
|
683
|
+
const swapInit: ToBTCLNSwapInit<T["Data"]> = {
|
|
664
684
|
pricingInfo: {
|
|
665
685
|
isValid: true,
|
|
666
686
|
satsBaseFee: 0n,
|
|
@@ -679,36 +699,16 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
|
|
|
679
699
|
networkFee: 0n,
|
|
680
700
|
networkFeeBtc: 0n,
|
|
681
701
|
confidence: 0,
|
|
682
|
-
pr: paymentHash,
|
|
702
|
+
pr: paymentHash ?? undefined,
|
|
683
703
|
exactIn: false
|
|
684
|
-
}
|
|
685
|
-
swap
|
|
704
|
+
};
|
|
705
|
+
const swap = new ToBTCLNSwap(this, swapInit);
|
|
706
|
+
swap._commitTxId = await init.getInitTxId();
|
|
686
707
|
const blockData = await init.getTxBlock();
|
|
687
708
|
swap.createdAt = blockData.blockTime * 1000;
|
|
688
709
|
swap._setInitiated();
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
case SwapCommitStateType.PAID:
|
|
692
|
-
secret ??= await state.getClaimResult();
|
|
693
|
-
await swap._setPaymentResult({secret}, false);
|
|
694
|
-
swap.claimTxId = await state.getClaimTxId();
|
|
695
|
-
swap.state = ToBTCSwapState.CLAIMED;
|
|
696
|
-
break;
|
|
697
|
-
case SwapCommitStateType.NOT_COMMITED:
|
|
698
|
-
case SwapCommitStateType.EXPIRED:
|
|
699
|
-
if(state.getRefundTxId==null) return null;
|
|
700
|
-
swap.refundTxId = await state.getRefundTxId();
|
|
701
|
-
swap.state = ToBTCSwapState.REFUNDED;
|
|
702
|
-
break;
|
|
703
|
-
case SwapCommitStateType.COMMITED:
|
|
704
|
-
swap.state = ToBTCSwapState.COMMITED;
|
|
705
|
-
//Try to fetch refund signature
|
|
706
|
-
if(lp!=null) await swap._sync(false, false, state);
|
|
707
|
-
break;
|
|
708
|
-
case SwapCommitStateType.REFUNDABLE:
|
|
709
|
-
swap.state = ToBTCSwapState.REFUNDABLE;
|
|
710
|
-
break;
|
|
711
|
-
}
|
|
710
|
+
swap._state = ToBTCSwapState.COMMITED;
|
|
711
|
+
await swap._sync(false, false, state);
|
|
712
712
|
await swap._save();
|
|
713
713
|
return swap;
|
|
714
714
|
}
|