@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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
import { FromBTCLNSwap, FromBTCLNSwapState } from "./FromBTCLNSwap";
|
|
5
|
-
import { ChainType, ClaimEvent, InitializeEvent, LightningNetworkApi, RefundEvent } from "@atomiqlabs/base";
|
|
5
|
+
import { ChainType, ClaimEvent, InitializeEvent, LightningNetworkApi, RefundEvent, SwapCommitState } from "@atomiqlabs/base";
|
|
6
6
|
import { Intermediary } from "../../../../intermediaries/Intermediary";
|
|
7
7
|
import { Buffer } from "buffer";
|
|
8
8
|
import { SwapType } from "../../../../enums/SwapType";
|
|
@@ -28,13 +28,29 @@ export type FromBTCLNWrapperOptions = ISwapWrapperOptions & {
|
|
|
28
28
|
};
|
|
29
29
|
export type FromBTCLNDefinition<T extends ChainType> = IFromBTCLNDefinition<T, FromBTCLNWrapper<T>, FromBTCLNSwap<T>>;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
*
|
|
31
|
+
* Legacy escrow (HTLC) based swap for Bitcoin Lightning -> Smart chains, requires manual settlement
|
|
32
|
+
* of the swap on the destination network once the lightning network payment is received by the LP.
|
|
33
|
+
*
|
|
34
|
+
* @category Swaps/Legacy/Lightning → Smart chain
|
|
33
35
|
*/
|
|
34
36
|
export declare class FromBTCLNWrapper<T extends ChainType> extends IFromBTCLNWrapper<T, FromBTCLNDefinition<T>, FromBTCLNWrapperOptions> implements IClaimableSwapWrapper<FromBTCLNSwap<T>> {
|
|
35
|
-
readonly
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
readonly TYPE: SwapType.FROM_BTCLN;
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
protected readonly tickSwapState: FromBTCLNSwapState[];
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
readonly _pendingSwapStates: FromBTCLNSwapState[];
|
|
46
|
+
/**
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
readonly _claimableSwapStates: FromBTCLNSwapState[];
|
|
50
|
+
/**
|
|
51
|
+
* @internal
|
|
52
|
+
*/
|
|
53
|
+
readonly _swapDeserializer: typeof FromBTCLNSwap;
|
|
38
54
|
/**
|
|
39
55
|
* @param chainIdentifier
|
|
40
56
|
* @param unifiedStorage Storage interface for the current environment
|
|
@@ -51,10 +67,20 @@ export declare class FromBTCLNWrapper<T extends ChainType> extends IFromBTCLNWra
|
|
|
51
67
|
constructor(chainIdentifier: string, unifiedStorage: UnifiedSwapStorage<T>, unifiedChainEvents: UnifiedSwapEventListener<T>, chain: T["ChainInterface"], contract: T["Contract"], prices: ISwapPrice, tokens: WrapperCtorTokens, swapDataDeserializer: new (data: any) => T["Data"], lnApi: LightningNetworkApi, options?: AllOptional<FromBTCLNWrapperOptions>, events?: EventEmitter<{
|
|
52
68
|
swapState: [ISwap];
|
|
53
69
|
}>);
|
|
54
|
-
|
|
55
|
-
|
|
70
|
+
/**
|
|
71
|
+
* @inheritDoc
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
56
74
|
protected processEventInitialize(swap: FromBTCLNSwap<T>, event: InitializeEvent<T["Data"]>): Promise<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* @inheritDoc
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
57
79
|
protected processEventClaim(swap: FromBTCLNSwap<T>, event: ClaimEvent<T["Data"]>): Promise<boolean>;
|
|
80
|
+
/**
|
|
81
|
+
* @inheritDoc
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
58
84
|
protected processEventRefund(swap: FromBTCLNSwap<T>, event: RefundEvent<T["Data"]>): Promise<boolean>;
|
|
59
85
|
/**
|
|
60
86
|
* Verifies response returned from intermediary
|
|
@@ -65,22 +91,27 @@ export declare class FromBTCLNWrapper<T extends ChainType> extends IFromBTCLNWra
|
|
|
65
91
|
* @param options Options as passed to the swap creation function
|
|
66
92
|
* @param decodedPr Decoded bolt11 lightning network invoice
|
|
67
93
|
* @param paymentHash Expected payment hash of the bolt11 lightning network invoice
|
|
68
|
-
*
|
|
94
|
+
*
|
|
69
95
|
* @throws {IntermediaryError} in case the response is invalid
|
|
96
|
+
*
|
|
97
|
+
* @private
|
|
70
98
|
*/
|
|
71
99
|
private verifyReturnedData;
|
|
72
100
|
/**
|
|
73
|
-
* Returns a newly created swap
|
|
101
|
+
* Returns a newly created legacy Lightning -> Smart chain swap using the HTLC based escrow swap protocol,
|
|
102
|
+
* where the user needs to manually settle swap on the destination smart chain. The user has to pay
|
|
103
|
+
* a bolt11 invoice on the input lightning network side.
|
|
74
104
|
*
|
|
75
|
-
* @param
|
|
76
|
-
*
|
|
77
|
-
* @param
|
|
78
|
-
* @param
|
|
79
|
-
* @param
|
|
80
|
-
* @param
|
|
81
|
-
* @param
|
|
105
|
+
* @param recipient Smart chain signer's address on the destination chain, that will have to manually
|
|
106
|
+
* settle the swap.
|
|
107
|
+
* @param amountData Amount, token and exact input/output data for to swap
|
|
108
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
109
|
+
* @param options Optional additional quote options
|
|
110
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
111
|
+
* @param abortSignal Abort signal
|
|
112
|
+
* @param preFetches Optional pre-fetches for speeding up the quoting process (mainly used internally)
|
|
82
113
|
*/
|
|
83
|
-
create(
|
|
114
|
+
create(recipient: string, amountData: AmountData, lps: Intermediary[], options?: FromBTCLNOptions, additionalParams?: Record<string, any>, abortSignal?: AbortSignal, preFetches?: {
|
|
84
115
|
usdPricePrefetchPromise: Promise<number | undefined>;
|
|
85
116
|
pricePrefetchPromise?: Promise<bigint | undefined>;
|
|
86
117
|
feeRatePromise?: Promise<string | undefined>;
|
|
@@ -89,21 +120,41 @@ export declare class FromBTCLNWrapper<T extends ChainType> extends IFromBTCLNWra
|
|
|
89
120
|
intermediary: Intermediary;
|
|
90
121
|
}[];
|
|
91
122
|
/**
|
|
92
|
-
* Returns a newly created
|
|
123
|
+
* Returns a newly created legacy Lightning -> Smart chain swap using the HTLC based escrow swap protocol,
|
|
124
|
+
* where the user needs to manually settle swap on the destination smart chain. The swap is created
|
|
125
|
+
* with an LNURL-withdraw link which will be used to pay the generated bolt11 invoice automatically
|
|
126
|
+
* when {@link FromBTCLNSwap.waitForPayment} is called on the swap.
|
|
93
127
|
*
|
|
94
|
-
* @param
|
|
95
|
-
*
|
|
96
|
-
* @param
|
|
97
|
-
* @param
|
|
98
|
-
* @param
|
|
99
|
-
* @param
|
|
128
|
+
* @param recipient Smart chain signer's address on the destination chain, that will have to manually
|
|
129
|
+
* settle the swap.
|
|
130
|
+
* @param lnurl LNURL-withdraw link to pull the funds from
|
|
131
|
+
* @param amountData Amount, token and exact input/output data for to swap
|
|
132
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
133
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
134
|
+
* @param abortSignal Abort signal
|
|
100
135
|
*/
|
|
101
|
-
createViaLNURL(
|
|
136
|
+
createViaLNURL(recipient: string, lnurl: string | LNURLWithdrawParamsWithUrl, amountData: AmountData, lps: Intermediary[], additionalParams?: Record<string, any>, abortSignal?: AbortSignal): Promise<{
|
|
102
137
|
quote: Promise<FromBTCLNSwap<T>>;
|
|
103
138
|
intermediary: Intermediary;
|
|
104
139
|
}[]>;
|
|
140
|
+
/**
|
|
141
|
+
* @inheritDoc
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
105
144
|
protected _checkPastSwaps(pastSwaps: FromBTCLNSwap<T>[]): Promise<{
|
|
106
145
|
changedSwaps: FromBTCLNSwap<T>[];
|
|
107
146
|
removeSwaps: FromBTCLNSwap<T>[];
|
|
108
147
|
}>;
|
|
148
|
+
/**
|
|
149
|
+
* @inheritDoc
|
|
150
|
+
* @internal
|
|
151
|
+
*/
|
|
152
|
+
recoverFromSwapDataAndState(init: {
|
|
153
|
+
data: T["Data"];
|
|
154
|
+
getInitTxId: () => Promise<string>;
|
|
155
|
+
getTxBlock: () => Promise<{
|
|
156
|
+
blockTime: number;
|
|
157
|
+
blockHeight: number;
|
|
158
|
+
}>;
|
|
159
|
+
}, state: SwapCommitState, lp?: Intermediary): Promise<FromBTCLNSwap<T> | null>;
|
|
109
160
|
}
|
|
@@ -13,9 +13,12 @@ const IntermediaryAPI_1 = require("../../../../intermediaries/apis/IntermediaryA
|
|
|
13
13
|
const RequestError_1 = require("../../../../errors/RequestError");
|
|
14
14
|
const IFromBTCLNWrapper_1 = require("../IFromBTCLNWrapper");
|
|
15
15
|
const RetryUtils_1 = require("../../../../utils/RetryUtils");
|
|
16
|
+
const sha2_1 = require("@noble/hashes/sha2");
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
18
|
+
* Legacy escrow (HTLC) based swap for Bitcoin Lightning -> Smart chains, requires manual settlement
|
|
19
|
+
* of the swap on the destination network once the lightning network payment is received by the LP.
|
|
20
|
+
*
|
|
21
|
+
* @category Swaps/Legacy/Lightning → Smart chain
|
|
19
22
|
*/
|
|
20
23
|
class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
21
24
|
/**
|
|
@@ -37,39 +40,64 @@ class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
37
40
|
bitcoinBlocktime: options?.bitcoinBlocktime ?? 10 * 60,
|
|
38
41
|
unsafeSkipLnNodeCheck: options?.unsafeSkipLnNodeCheck ?? false
|
|
39
42
|
}, events);
|
|
40
|
-
this.claimableSwapStates = [FromBTCLNSwap_1.FromBTCLNSwapState.CLAIM_COMMITED];
|
|
41
43
|
this.TYPE = SwapType_1.SwapType.FROM_BTCLN;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
this.tickSwapState = [
|
|
44
48
|
FromBTCLNSwap_1.FromBTCLNSwapState.PR_CREATED,
|
|
45
|
-
FromBTCLNSwap_1.FromBTCLNSwapState.QUOTE_SOFT_EXPIRED,
|
|
46
49
|
FromBTCLNSwap_1.FromBTCLNSwapState.PR_PAID,
|
|
47
|
-
FromBTCLNSwap_1.FromBTCLNSwapState.CLAIM_COMMITED
|
|
48
|
-
FromBTCLNSwap_1.FromBTCLNSwapState.EXPIRED
|
|
50
|
+
FromBTCLNSwap_1.FromBTCLNSwapState.CLAIM_COMMITED
|
|
49
51
|
];
|
|
50
|
-
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
this._pendingSwapStates = [
|
|
51
56
|
FromBTCLNSwap_1.FromBTCLNSwapState.PR_CREATED,
|
|
57
|
+
FromBTCLNSwap_1.FromBTCLNSwapState.QUOTE_SOFT_EXPIRED,
|
|
52
58
|
FromBTCLNSwap_1.FromBTCLNSwapState.PR_PAID,
|
|
53
|
-
FromBTCLNSwap_1.FromBTCLNSwapState.CLAIM_COMMITED
|
|
59
|
+
FromBTCLNSwap_1.FromBTCLNSwapState.CLAIM_COMMITED,
|
|
60
|
+
FromBTCLNSwap_1.FromBTCLNSwapState.EXPIRED
|
|
54
61
|
];
|
|
62
|
+
/**
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
this._claimableSwapStates = [FromBTCLNSwap_1.FromBTCLNSwapState.CLAIM_COMMITED];
|
|
66
|
+
/**
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
this._swapDeserializer = FromBTCLNSwap_1.FromBTCLNSwap;
|
|
55
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* @inheritDoc
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
56
75
|
processEventInitialize(swap, event) {
|
|
57
|
-
if (swap.
|
|
58
|
-
swap.
|
|
76
|
+
if (swap._state === FromBTCLNSwap_1.FromBTCLNSwapState.PR_PAID || swap._state === FromBTCLNSwap_1.FromBTCLNSwapState.QUOTE_SOFT_EXPIRED) {
|
|
77
|
+
swap._state = FromBTCLNSwap_1.FromBTCLNSwapState.CLAIM_COMMITED;
|
|
59
78
|
return Promise.resolve(true);
|
|
60
79
|
}
|
|
61
80
|
return Promise.resolve(false);
|
|
62
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* @inheritDoc
|
|
84
|
+
* @internal
|
|
85
|
+
*/
|
|
63
86
|
processEventClaim(swap, event) {
|
|
64
|
-
if (swap.
|
|
65
|
-
swap.
|
|
87
|
+
if (swap._state !== FromBTCLNSwap_1.FromBTCLNSwapState.FAILED && swap._state !== FromBTCLNSwap_1.FromBTCLNSwapState.CLAIM_CLAIMED) {
|
|
88
|
+
swap._state = FromBTCLNSwap_1.FromBTCLNSwapState.CLAIM_CLAIMED;
|
|
89
|
+
swap._setSwapSecret(event.result);
|
|
66
90
|
return Promise.resolve(true);
|
|
67
91
|
}
|
|
68
92
|
return Promise.resolve(false);
|
|
69
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* @inheritDoc
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
70
98
|
processEventRefund(swap, event) {
|
|
71
|
-
if (swap.
|
|
72
|
-
swap.
|
|
99
|
+
if (swap._state !== FromBTCLNSwap_1.FromBTCLNSwapState.CLAIM_CLAIMED && swap._state !== FromBTCLNSwap_1.FromBTCLNSwapState.FAILED) {
|
|
100
|
+
swap._state = FromBTCLNSwap_1.FromBTCLNSwapState.FAILED;
|
|
73
101
|
return Promise.resolve(true);
|
|
74
102
|
}
|
|
75
103
|
return Promise.resolve(false);
|
|
@@ -83,8 +111,10 @@ class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
83
111
|
* @param options Options as passed to the swap creation function
|
|
84
112
|
* @param decodedPr Decoded bolt11 lightning network invoice
|
|
85
113
|
* @param paymentHash Expected payment hash of the bolt11 lightning network invoice
|
|
86
|
-
*
|
|
114
|
+
*
|
|
87
115
|
* @throws {IntermediaryError} in case the response is invalid
|
|
116
|
+
*
|
|
117
|
+
* @private
|
|
88
118
|
*/
|
|
89
119
|
verifyReturnedData(resp, amountData, lp, options, decodedPr, paymentHash) {
|
|
90
120
|
if (lp.getAddress(this.chainIdentifier) !== resp.intermediaryKey)
|
|
@@ -107,29 +137,32 @@ class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
107
137
|
}
|
|
108
138
|
}
|
|
109
139
|
/**
|
|
110
|
-
* Returns a newly created swap
|
|
140
|
+
* Returns a newly created legacy Lightning -> Smart chain swap using the HTLC based escrow swap protocol,
|
|
141
|
+
* where the user needs to manually settle swap on the destination smart chain. The user has to pay
|
|
142
|
+
* a bolt11 invoice on the input lightning network side.
|
|
111
143
|
*
|
|
112
|
-
* @param
|
|
113
|
-
*
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
116
|
-
* @param
|
|
117
|
-
* @param
|
|
118
|
-
* @param
|
|
144
|
+
* @param recipient Smart chain signer's address on the destination chain, that will have to manually
|
|
145
|
+
* settle the swap.
|
|
146
|
+
* @param amountData Amount, token and exact input/output data for to swap
|
|
147
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
148
|
+
* @param options Optional additional quote options
|
|
149
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
150
|
+
* @param abortSignal Abort signal
|
|
151
|
+
* @param preFetches Optional pre-fetches for speeding up the quoting process (mainly used internally)
|
|
119
152
|
*/
|
|
120
|
-
create(
|
|
153
|
+
create(recipient, amountData, lps, options, additionalParams, abortSignal, preFetches) {
|
|
121
154
|
if (options == null)
|
|
122
155
|
options = {};
|
|
123
|
-
options.unsafeSkipLnNodeCheck ??= this.
|
|
156
|
+
options.unsafeSkipLnNodeCheck ??= this._options.unsafeSkipLnNodeCheck;
|
|
124
157
|
if (options.descriptionHash != null && options.descriptionHash.length !== 32)
|
|
125
158
|
throw new UserError_1.UserError("Invalid description hash length");
|
|
126
159
|
const { secret, paymentHash } = this.getSecretAndHash();
|
|
127
|
-
const claimHash = this.
|
|
128
|
-
const nativeTokenAddress = this.
|
|
160
|
+
const claimHash = this._contract.getHashForHtlc(paymentHash);
|
|
161
|
+
const nativeTokenAddress = this._chain.getNativeCurrencyAddress();
|
|
129
162
|
const _abortController = (0, Utils_1.extendAbortController)(abortSignal);
|
|
130
163
|
const _preFetches = {
|
|
131
164
|
pricePrefetchPromise: preFetches?.pricePrefetchPromise ?? this.preFetchPrice(amountData, _abortController.signal),
|
|
132
|
-
feeRatePromise: preFetches?.feeRatePromise ?? this.preFetchFeeRate(
|
|
165
|
+
feeRatePromise: preFetches?.feeRatePromise ?? this.preFetchFeeRate(recipient, amountData, claimHash.toString("hex"), _abortController),
|
|
133
166
|
usdPricePrefetchPromise: preFetches?.usdPricePrefetchPromise ?? this.preFetchUsdPrice(_abortController.signal),
|
|
134
167
|
};
|
|
135
168
|
return lps.map(lp => {
|
|
@@ -144,13 +177,13 @@ class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
144
177
|
const { lnPublicKey, response } = IntermediaryAPI_1.IntermediaryAPI.initFromBTCLN(this.chainIdentifier, lp.url, nativeTokenAddress, {
|
|
145
178
|
paymentHash,
|
|
146
179
|
amount: amountData.amount,
|
|
147
|
-
claimer:
|
|
180
|
+
claimer: recipient,
|
|
148
181
|
token: amountData.token.toString(),
|
|
149
182
|
descriptionHash: options?.descriptionHash,
|
|
150
183
|
exactOut: !amountData.exactIn,
|
|
151
184
|
feeRate: (0, Utils_1.throwIfUndefined)(_preFetches.feeRatePromise),
|
|
152
185
|
additionalParams
|
|
153
|
-
}, this.
|
|
186
|
+
}, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined);
|
|
154
187
|
return {
|
|
155
188
|
lnCapacityPromise: options?.unsafeSkipLnNodeCheck ? null : this.preFetchLnCapacity(lnPublicKey),
|
|
156
189
|
resp: await response
|
|
@@ -176,7 +209,7 @@ class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
176
209
|
swapFee: resp.swapFee,
|
|
177
210
|
swapFeeBtc: resp.swapFee * amountIn / (resp.total - resp.swapFee),
|
|
178
211
|
feeRate: (await _preFetches.feeRatePromise),
|
|
179
|
-
initialSwapData: await this.
|
|
212
|
+
initialSwapData: await this._contract.createSwapData(base_1.ChainSwapType.HTLC, lp.getAddress(this.chainIdentifier), recipient, amountData.token, resp.total, claimHash.toString("hex"), this.getRandomSequence(), BigInt(Math.floor(Date.now() / 1000)), false, true, resp.securityDeposit, 0n, nativeTokenAddress),
|
|
180
213
|
pr: resp.pr,
|
|
181
214
|
secret: secret.toString("hex"),
|
|
182
215
|
exactIn: amountData.exactIn ?? true
|
|
@@ -193,26 +226,30 @@ class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
193
226
|
});
|
|
194
227
|
}
|
|
195
228
|
/**
|
|
196
|
-
* Returns a newly created
|
|
229
|
+
* Returns a newly created legacy Lightning -> Smart chain swap using the HTLC based escrow swap protocol,
|
|
230
|
+
* where the user needs to manually settle swap on the destination smart chain. The swap is created
|
|
231
|
+
* with an LNURL-withdraw link which will be used to pay the generated bolt11 invoice automatically
|
|
232
|
+
* when {@link FromBTCLNSwap.waitForPayment} is called on the swap.
|
|
197
233
|
*
|
|
198
|
-
* @param
|
|
199
|
-
*
|
|
200
|
-
* @param
|
|
201
|
-
* @param
|
|
202
|
-
* @param
|
|
203
|
-
* @param
|
|
234
|
+
* @param recipient Smart chain signer's address on the destination chain, that will have to manually
|
|
235
|
+
* settle the swap.
|
|
236
|
+
* @param lnurl LNURL-withdraw link to pull the funds from
|
|
237
|
+
* @param amountData Amount, token and exact input/output data for to swap
|
|
238
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
239
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
240
|
+
* @param abortSignal Abort signal
|
|
204
241
|
*/
|
|
205
|
-
async createViaLNURL(
|
|
242
|
+
async createViaLNURL(recipient, lnurl, amountData, lps, additionalParams, abortSignal) {
|
|
206
243
|
if (!this.isInitialized)
|
|
207
244
|
throw new Error("Not initialized, call init() first!");
|
|
208
245
|
const abortController = (0, Utils_1.extendAbortController)(abortSignal);
|
|
209
246
|
const preFetches = {
|
|
210
247
|
pricePrefetchPromise: this.preFetchPrice(amountData, abortController.signal),
|
|
211
248
|
usdPricePrefetchPromise: this.preFetchUsdPrice(abortController.signal),
|
|
212
|
-
feeRatePromise: this.preFetchFeeRate(
|
|
249
|
+
feeRatePromise: this.preFetchFeeRate(recipient, amountData, undefined, abortController)
|
|
213
250
|
};
|
|
214
251
|
try {
|
|
215
|
-
const exactOutAmountPromise = !amountData.exactIn ? preFetches.pricePrefetchPromise.then(price => this.
|
|
252
|
+
const exactOutAmountPromise = !amountData.exactIn ? preFetches.pricePrefetchPromise.then(price => this._prices.getToBtcSwapAmount(this.chainIdentifier, amountData.amount, amountData.token, abortController.signal, price)).catch(e => {
|
|
216
253
|
abortController.abort(e);
|
|
217
254
|
return undefined;
|
|
218
255
|
}) : undefined;
|
|
@@ -233,12 +270,10 @@ class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
233
270
|
if ((amount * 105n / 100n) > max)
|
|
234
271
|
throw new UserError_1.UserError("Amount more than LNURL-withdraw maximum");
|
|
235
272
|
}
|
|
236
|
-
return this.create(
|
|
273
|
+
return this.create(recipient, amountData, lps, undefined, additionalParams, abortSignal, preFetches).map(data => {
|
|
237
274
|
return {
|
|
238
275
|
quote: data.quote.then(quote => {
|
|
239
|
-
quote.
|
|
240
|
-
quote.lnurlK1 = withdrawRequest.k1;
|
|
241
|
-
quote.lnurlCallback = withdrawRequest.callback;
|
|
276
|
+
quote._setLNURLData(withdrawRequest.url, withdrawRequest.k1, withdrawRequest.callback);
|
|
242
277
|
const amountIn = quote.getInput().rawAmount;
|
|
243
278
|
if (amountIn < min)
|
|
244
279
|
throw new UserError_1.UserError("Amount less than LNURL-withdraw minimum");
|
|
@@ -255,6 +290,10 @@ class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
255
290
|
throw e;
|
|
256
291
|
}
|
|
257
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* @inheritDoc
|
|
295
|
+
* @internal
|
|
296
|
+
*/
|
|
258
297
|
async _checkPastSwaps(pastSwaps) {
|
|
259
298
|
const changedSwapSet = new Set();
|
|
260
299
|
const swapExpiredStatus = {};
|
|
@@ -275,13 +314,13 @@ class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
275
314
|
//Check expiry
|
|
276
315
|
swapExpiredStatus[pastSwap.getId()] = await pastSwap._verifyQuoteDefinitelyExpired();
|
|
277
316
|
}
|
|
278
|
-
if (pastSwap.
|
|
317
|
+
if (pastSwap._shouldFetchOnchainState()) {
|
|
279
318
|
//Add to swaps for which status should be checked
|
|
280
|
-
if (pastSwap.
|
|
319
|
+
if (pastSwap._data != null)
|
|
281
320
|
checkStatusSwaps.push(pastSwap);
|
|
282
321
|
}
|
|
283
322
|
}));
|
|
284
|
-
const swapStatuses = await this.
|
|
323
|
+
const swapStatuses = await this._contract.getCommitStatuses(checkStatusSwaps.map(val => ({ signer: val._getInitiator(), swapData: val._data })));
|
|
285
324
|
for (let pastSwap of checkStatusSwaps) {
|
|
286
325
|
const shouldSave = await pastSwap._sync(false, swapExpiredStatus[pastSwap.getId()], swapStatuses[pastSwap.getEscrowHash()], true);
|
|
287
326
|
if (shouldSave) {
|
|
@@ -303,5 +342,48 @@ class FromBTCLNWrapper extends IFromBTCLNWrapper_1.IFromBTCLNWrapper {
|
|
|
303
342
|
removeSwaps
|
|
304
343
|
};
|
|
305
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* @inheritDoc
|
|
347
|
+
* @internal
|
|
348
|
+
*/
|
|
349
|
+
async recoverFromSwapDataAndState(init, state, lp) {
|
|
350
|
+
const data = init.data;
|
|
351
|
+
let paymentHash = data.getHTLCHashHint();
|
|
352
|
+
let secret;
|
|
353
|
+
if (state.type === base_1.SwapCommitStateType.PAID) {
|
|
354
|
+
secret = await state.getClaimResult();
|
|
355
|
+
paymentHash = buffer_1.Buffer.from((0, sha2_1.sha256)(buffer_1.Buffer.from(secret, "hex"))).toString("hex");
|
|
356
|
+
}
|
|
357
|
+
const swapInit = {
|
|
358
|
+
pricingInfo: {
|
|
359
|
+
isValid: true,
|
|
360
|
+
satsBaseFee: 0n,
|
|
361
|
+
swapPriceUSatPerToken: 100000000000000n,
|
|
362
|
+
realPriceUSatPerToken: 100000000000000n,
|
|
363
|
+
differencePPM: 0n,
|
|
364
|
+
feePPM: 0n,
|
|
365
|
+
},
|
|
366
|
+
url: lp?.url,
|
|
367
|
+
expiry: 0,
|
|
368
|
+
swapFee: 0n,
|
|
369
|
+
swapFeeBtc: 0n,
|
|
370
|
+
feeRate: "",
|
|
371
|
+
signatureData: undefined,
|
|
372
|
+
initialSwapData: data,
|
|
373
|
+
data,
|
|
374
|
+
pr: paymentHash ?? undefined,
|
|
375
|
+
secret,
|
|
376
|
+
exactIn: false
|
|
377
|
+
};
|
|
378
|
+
const swap = new FromBTCLNSwap_1.FromBTCLNSwap(this, swapInit);
|
|
379
|
+
swap._commitTxId = await init.getInitTxId();
|
|
380
|
+
const blockData = await init.getTxBlock();
|
|
381
|
+
swap.createdAt = blockData.blockTime * 1000;
|
|
382
|
+
swap._setInitiated();
|
|
383
|
+
swap._state = FromBTCLNSwap_1.FromBTCLNSwapState.CLAIM_COMMITED;
|
|
384
|
+
await swap._sync(false, false, state);
|
|
385
|
+
await swap._save();
|
|
386
|
+
return swap;
|
|
387
|
+
}
|
|
306
388
|
}
|
|
307
389
|
exports.FromBTCLNWrapper = FromBTCLNWrapper;
|