@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
|
@@ -13,13 +13,7 @@ import { ISwap } from "../../../ISwap";
|
|
|
13
13
|
import { AmountData } from "../../../../types/AmountData";
|
|
14
14
|
import { LNURLPayParamsWithUrl } from "../../../../types/lnurl/LNURLPay";
|
|
15
15
|
import { AllOptional } from "../../../../utils/TypeUtils";
|
|
16
|
-
|
|
17
|
-
export type InvoiceCreateService = {
|
|
18
|
-
getInvoice: LightningWalletCallback;
|
|
19
|
-
minMsats?: bigint;
|
|
20
|
-
maxMSats?: bigint;
|
|
21
|
-
};
|
|
22
|
-
export declare function isInvoiceCreateService(obj: any): obj is InvoiceCreateService;
|
|
16
|
+
import { LightningInvoiceCreateService } from "../../../../types/wallets/LightningInvoiceCreateService";
|
|
23
17
|
export type ToBTCLNOptions = {
|
|
24
18
|
expirySeconds?: number;
|
|
25
19
|
maxFee?: bigint | Promise<bigint>;
|
|
@@ -33,13 +27,29 @@ export type ToBTCLNWrapperOptions = ISwapWrapperOptions & {
|
|
|
33
27
|
paymentTimeoutSeconds: number;
|
|
34
28
|
};
|
|
35
29
|
export type ToBTCLNDefinition<T extends ChainType> = IToBTCDefinition<T, ToBTCLNWrapper<T>, ToBTCLNSwap<T>>;
|
|
30
|
+
/**
|
|
31
|
+
* Escrow based (HTLC) swap for Smart chains -> Bitcoin lightning
|
|
32
|
+
*
|
|
33
|
+
* @category Swaps/Smart chain → Lightning
|
|
34
|
+
*/
|
|
36
35
|
export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCLNDefinition<T>, ToBTCLNWrapperOptions> {
|
|
37
|
-
readonly TYPE
|
|
38
|
-
|
|
36
|
+
readonly TYPE: SwapType.TO_BTCLN;
|
|
37
|
+
/**
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
readonly _swapDeserializer: typeof ToBTCLNSwap;
|
|
39
41
|
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"], options?: AllOptional<ToBTCLNWrapperOptions>, events?: EventEmitter<{
|
|
40
42
|
swapState: [ISwap];
|
|
41
43
|
}>);
|
|
42
44
|
private toRequiredSwapOptions;
|
|
45
|
+
/**
|
|
46
|
+
* Verifies whether a given payment hash was already paid by checking the local
|
|
47
|
+
* storage of known swaps
|
|
48
|
+
*
|
|
49
|
+
* @param paymentHash Payment hash to check
|
|
50
|
+
*
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
43
53
|
private checkPaymentHashWasPaid;
|
|
44
54
|
/**
|
|
45
55
|
* Calculates maximum lightning network routing fee based on amount
|
|
@@ -47,8 +57,10 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
|
|
|
47
57
|
* @param amount BTC amount of the swap in satoshis
|
|
48
58
|
* @param overrideBaseFee Override wrapper's default base fee
|
|
49
59
|
* @param overrideFeePPM Override wrapper's default PPM
|
|
50
|
-
*
|
|
60
|
+
*
|
|
51
61
|
* @returns Maximum lightning routing fee in sats
|
|
62
|
+
*
|
|
63
|
+
* @private
|
|
52
64
|
*/
|
|
53
65
|
private calculateFeeForAmount;
|
|
54
66
|
/**
|
|
@@ -62,8 +74,10 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
|
|
|
62
74
|
* @param options Swap options as passed to the swap create function
|
|
63
75
|
* @param data Parsed swap data returned by the LP
|
|
64
76
|
* @param requiredTotal Required total to be paid on the input (for exactIn swaps)
|
|
65
|
-
*
|
|
77
|
+
*
|
|
66
78
|
* @throws {IntermediaryError} In case the response is not valid
|
|
79
|
+
*
|
|
80
|
+
* @private
|
|
67
81
|
*/
|
|
68
82
|
private verifyReturnedData;
|
|
69
83
|
/**
|
|
@@ -79,22 +93,24 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
|
|
|
79
93
|
* @param abort Abort signal or controller, if AbortController is passed it is used as-is, when AbortSignal is passed
|
|
80
94
|
* it is extended with extendAbortController and then used
|
|
81
95
|
* @param additionalParams Additional params that should be sent to the LP
|
|
96
|
+
*
|
|
82
97
|
* @private
|
|
83
98
|
*/
|
|
84
99
|
private getIntermediaryQuote;
|
|
85
100
|
/**
|
|
86
|
-
* Returns a newly created swap
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* @param
|
|
90
|
-
* @param
|
|
91
|
-
* @param
|
|
92
|
-
* @param
|
|
93
|
-
* @param
|
|
94
|
-
* @param
|
|
95
|
-
* @param
|
|
101
|
+
* Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol,
|
|
102
|
+
* the amount is parsed from the provided lightning network payment request (bolt11 invoice)
|
|
103
|
+
*
|
|
104
|
+
* @param signer Source chain signer address initiating the swap
|
|
105
|
+
* @param recipient BOLT11 payment request (bitcoin lightning invoice) you wish to pay
|
|
106
|
+
* @param amountData Token to swap
|
|
107
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
108
|
+
* @param options Optional additional quote options
|
|
109
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
110
|
+
* @param abortSignal Abort signal
|
|
111
|
+
* @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
|
|
96
112
|
*/
|
|
97
|
-
create(signer: string,
|
|
113
|
+
create(signer: string, recipient: string, amountData: Omit<AmountData, "amount">, lps: Intermediary[], options?: ToBTCLNOptions, additionalParams?: Record<string, any>, abortSignal?: AbortSignal, preFetches?: {
|
|
98
114
|
feeRatePromise: Promise<string | undefined>;
|
|
99
115
|
pricePreFetchPromise: Promise<bigint | undefined>;
|
|
100
116
|
usdPricePrefetchPromise: Promise<number | undefined>;
|
|
@@ -107,51 +123,58 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
|
|
|
107
123
|
* Parses and fetches lnurl pay params from the specified lnurl
|
|
108
124
|
*
|
|
109
125
|
* @param lnurl LNURL to be parsed and fetched
|
|
110
|
-
* @param abortSignal
|
|
111
|
-
* @private
|
|
126
|
+
* @param abortSignal Abort signal
|
|
112
127
|
* @throws {UserError} if the LNURL is invalid or if it's not a LNURL-pay
|
|
128
|
+
*
|
|
129
|
+
* @private
|
|
113
130
|
*/
|
|
114
131
|
private getLNURLPay;
|
|
115
132
|
/**
|
|
116
133
|
* Returns the quote/swap from the given LP
|
|
117
134
|
*
|
|
118
|
-
* @param signer
|
|
119
|
-
* @param amountData
|
|
135
|
+
* @param signer Source chain signer address initiating the swap
|
|
136
|
+
* @param amountData Token to swap
|
|
120
137
|
* @param invoiceCreateService Service for creating fixed amount invoices
|
|
121
|
-
* @param lp Intermediary
|
|
122
|
-
* @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay
|
|
123
|
-
*
|
|
124
|
-
* @param
|
|
125
|
-
* @param
|
|
138
|
+
* @param lp Intermediary (LPs) to get the quote from
|
|
139
|
+
* @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay, used to estimate
|
|
140
|
+
* network fees for an actual invoice
|
|
141
|
+
* @param options Optional additional quote options
|
|
142
|
+
* @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
|
|
143
|
+
* @param abortSignal Abort signal
|
|
126
144
|
* @param additionalParams Additional params to be sent to the intermediary
|
|
145
|
+
*
|
|
127
146
|
* @private
|
|
128
147
|
*/
|
|
129
148
|
private getIntermediaryQuoteExactIn;
|
|
130
149
|
/**
|
|
131
|
-
* Returns a newly created swap
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* @param
|
|
136
|
-
* @param
|
|
137
|
-
* @param
|
|
138
|
-
* @param
|
|
139
|
-
* @param
|
|
150
|
+
* Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol via
|
|
151
|
+
* invoice creation service. This allows exactIn swaps by requesting the desired fixed amount lightning
|
|
152
|
+
* network invoice from the service.
|
|
153
|
+
*
|
|
154
|
+
* @param signer Source chain signer address initiating the swap
|
|
155
|
+
* @param invoiceCreateServicePromise Service to request destination lightning network invoices from
|
|
156
|
+
* @param amountData Amount, token and exact input/output data for to swap
|
|
157
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
158
|
+
* @param options Optional additional quote options
|
|
159
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
160
|
+
* @param abortSignal Abort signal
|
|
140
161
|
*/
|
|
141
|
-
createViaInvoiceCreateService(signer: string, invoiceCreateServicePromise: Promise<
|
|
162
|
+
createViaInvoiceCreateService(signer: string, invoiceCreateServicePromise: Promise<LightningInvoiceCreateService>, amountData: AmountData, lps: Intermediary[], options?: ToBTCLNOptions, additionalParams?: Record<string, any>, abortSignal?: AbortSignal): Promise<{
|
|
142
163
|
quote: Promise<ToBTCLNSwap<T>>;
|
|
143
164
|
intermediary: Intermediary;
|
|
144
165
|
}[]>;
|
|
145
166
|
/**
|
|
146
|
-
* Returns a newly created swap
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* @param
|
|
151
|
-
* @param
|
|
152
|
-
* @param
|
|
153
|
-
* @param
|
|
154
|
-
* @param
|
|
167
|
+
* Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol. Pays to
|
|
168
|
+
* an LNURL-pay link. This allows exactIn swaps by requesting the desired fixed amount lightning
|
|
169
|
+
* network invoice from the LNURL service.
|
|
170
|
+
*
|
|
171
|
+
* @param signer Source chain signer address initiating the swap
|
|
172
|
+
* @param lnurl LNURL-pay link of the recipient
|
|
173
|
+
* @param amountData Amount, token and exact input/output data for to swap
|
|
174
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
175
|
+
* @param options Optional additional quote options
|
|
176
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
177
|
+
* @param abortSignal Abort signal
|
|
155
178
|
*/
|
|
156
179
|
createViaLNURL(signer: string, lnurl: string | LNURLPayParamsWithUrl, amountData: AmountData, lps: Intermediary[], options?: ToBTCLNOptions & {
|
|
157
180
|
comment?: string;
|
|
@@ -159,6 +182,9 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
|
|
|
159
182
|
quote: Promise<ToBTCLNSwap<T>>;
|
|
160
183
|
intermediary: Intermediary;
|
|
161
184
|
}[]>;
|
|
185
|
+
/**
|
|
186
|
+
* @inheritDoc
|
|
187
|
+
*/
|
|
162
188
|
recoverFromSwapDataAndState(init: {
|
|
163
189
|
data: T["Data"];
|
|
164
190
|
getInitTxId: () => Promise<string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ToBTCLNWrapper =
|
|
3
|
+
exports.ToBTCLNWrapper = void 0;
|
|
4
4
|
const bolt11_1 = require("@atomiqlabs/bolt11");
|
|
5
5
|
const ToBTCLNSwap_1 = require("./ToBTCLNSwap");
|
|
6
6
|
const IToBTCWrapper_1 = require("../IToBTCWrapper");
|
|
@@ -15,13 +15,11 @@ const LNURL_1 = require("../../../../lnurl/LNURL");
|
|
|
15
15
|
const IToBTCSwap_1 = require("../IToBTCSwap");
|
|
16
16
|
const sha2_1 = require("@noble/hashes/sha2");
|
|
17
17
|
const RetryUtils_1 = require("../../../../utils/RetryUtils");
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
exports.isInvoiceCreateService = isInvoiceCreateService;
|
|
18
|
+
/**
|
|
19
|
+
* Escrow based (HTLC) swap for Smart chains -> Bitcoin lightning
|
|
20
|
+
*
|
|
21
|
+
* @category Swaps/Smart chain → Lightning
|
|
22
|
+
*/
|
|
25
23
|
class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
26
24
|
constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, contract, prices, tokens, swapDataDeserializer, options, events) {
|
|
27
25
|
super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, contract, prices, tokens, swapDataDeserializer, {
|
|
@@ -30,12 +28,15 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
30
28
|
lightningFeePPM: options?.lightningFeePPM ?? 2000
|
|
31
29
|
}, events);
|
|
32
30
|
this.TYPE = SwapType_1.SwapType.TO_BTCLN;
|
|
33
|
-
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
this._swapDeserializer = ToBTCLNSwap_1.ToBTCLNSwap;
|
|
34
35
|
}
|
|
35
36
|
toRequiredSwapOptions(amountData, options, pricePreFetchPromise, abortSignal) {
|
|
36
|
-
const expirySeconds = options?.expirySeconds ?? this.
|
|
37
|
-
const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this.
|
|
38
|
-
const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this.
|
|
37
|
+
const expirySeconds = options?.expirySeconds ?? this._options.paymentTimeoutSeconds;
|
|
38
|
+
const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this._options.lightningBaseFee);
|
|
39
|
+
const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this._options.lightningFeePPM);
|
|
39
40
|
let maxFee;
|
|
40
41
|
if (options?.maxFee != null) {
|
|
41
42
|
maxFee = options.maxFee;
|
|
@@ -43,11 +44,11 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
43
44
|
else if (amountData.exactIn) {
|
|
44
45
|
if (pricePreFetchPromise != null) {
|
|
45
46
|
maxFee = pricePreFetchPromise
|
|
46
|
-
.then(val => this.
|
|
47
|
+
.then(val => this._prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal, val))
|
|
47
48
|
.then(_maxBaseFee => this.calculateFeeForAmount(amountData.amount, _maxBaseFee, maxRoutingPPM));
|
|
48
49
|
}
|
|
49
50
|
else {
|
|
50
|
-
maxFee = this.
|
|
51
|
+
maxFee = this._prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal)
|
|
51
52
|
.then(_maxBaseFee => this.calculateFeeForAmount(amountData.amount, _maxBaseFee, maxRoutingPPM));
|
|
52
53
|
}
|
|
53
54
|
}
|
|
@@ -62,10 +63,18 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
62
63
|
maxFee
|
|
63
64
|
};
|
|
64
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Verifies whether a given payment hash was already paid by checking the local
|
|
68
|
+
* storage of known swaps
|
|
69
|
+
*
|
|
70
|
+
* @param paymentHash Payment hash to check
|
|
71
|
+
*
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
65
74
|
async checkPaymentHashWasPaid(paymentHash) {
|
|
66
|
-
const swaps = await this.unifiedStorage.query([[{ key: "type", value: this.TYPE }, { key: "paymentHash", value: paymentHash }]], (obj) => new this.
|
|
75
|
+
const swaps = await this.unifiedStorage.query([[{ key: "type", value: this.TYPE }, { key: "paymentHash", value: paymentHash }]], (obj) => new this._swapDeserializer(this, obj));
|
|
67
76
|
for (let value of swaps) {
|
|
68
|
-
if (value.
|
|
77
|
+
if (value._state === IToBTCSwap_1.ToBTCSwapState.CLAIMED || value._state === IToBTCSwap_1.ToBTCSwapState.SOFT_CLAIMED)
|
|
69
78
|
throw new UserError_1.UserError("Lightning invoice was already paid!");
|
|
70
79
|
}
|
|
71
80
|
}
|
|
@@ -75,12 +84,14 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
75
84
|
* @param amount BTC amount of the swap in satoshis
|
|
76
85
|
* @param overrideBaseFee Override wrapper's default base fee
|
|
77
86
|
* @param overrideFeePPM Override wrapper's default PPM
|
|
78
|
-
*
|
|
87
|
+
*
|
|
79
88
|
* @returns Maximum lightning routing fee in sats
|
|
89
|
+
*
|
|
90
|
+
* @private
|
|
80
91
|
*/
|
|
81
92
|
calculateFeeForAmount(amount, overrideBaseFee, overrideFeePPM) {
|
|
82
|
-
return BigInt(overrideBaseFee ?? this.
|
|
83
|
-
+ (amount * BigInt(overrideFeePPM ?? this.
|
|
93
|
+
return BigInt(overrideBaseFee ?? this._options.lightningBaseFee)
|
|
94
|
+
+ (amount * BigInt(overrideFeePPM ?? this._options.lightningFeePPM) / 1000000n);
|
|
84
95
|
}
|
|
85
96
|
/**
|
|
86
97
|
* Verifies returned LP data
|
|
@@ -93,8 +104,10 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
93
104
|
* @param options Swap options as passed to the swap create function
|
|
94
105
|
* @param data Parsed swap data returned by the LP
|
|
95
106
|
* @param requiredTotal Required total to be paid on the input (for exactIn swaps)
|
|
96
|
-
*
|
|
107
|
+
*
|
|
97
108
|
* @throws {IntermediaryError} In case the response is not valid
|
|
109
|
+
*
|
|
110
|
+
* @private
|
|
98
111
|
*/
|
|
99
112
|
async verifyReturnedData(signer, resp, parsedPr, token, lp, options, data, requiredTotal) {
|
|
100
113
|
if (resp.routingFeeSats > await options.maxFee)
|
|
@@ -103,7 +116,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
103
116
|
throw new IntermediaryError_1.IntermediaryError("Invalid data returned - total amount");
|
|
104
117
|
if (parsedPr.tagsObject.payment_hash == null)
|
|
105
118
|
throw new Error("Swap invoice doesn't contain payment hash field!");
|
|
106
|
-
const claimHash = this.
|
|
119
|
+
const claimHash = this._contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
|
|
107
120
|
if (data.getAmount() !== resp.total ||
|
|
108
121
|
!Buffer.from(data.getClaimHash(), "hex").equals(claimHash) ||
|
|
109
122
|
data.getExpiry() !== options.expiryTimestamp ||
|
|
@@ -129,6 +142,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
129
142
|
* @param abort Abort signal or controller, if AbortController is passed it is used as-is, when AbortSignal is passed
|
|
130
143
|
* it is extended with extendAbortController and then used
|
|
131
144
|
* @param additionalParams Additional params that should be sent to the LP
|
|
145
|
+
*
|
|
132
146
|
* @private
|
|
133
147
|
*/
|
|
134
148
|
async getIntermediaryQuote(signer, amountData, lp, pr, parsedPr, options, preFetches, abort, additionalParams) {
|
|
@@ -146,7 +160,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
146
160
|
token: amountData.token,
|
|
147
161
|
feeRate: (0, Utils_1.throwIfUndefined)(preFetches.feeRatePromise),
|
|
148
162
|
additionalParams
|
|
149
|
-
}, this.
|
|
163
|
+
}, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined);
|
|
150
164
|
return {
|
|
151
165
|
signDataPromise: preFetches.signDataPrefetchPromise ?? this.preFetchSignData(signDataPrefetch),
|
|
152
166
|
resp: await response
|
|
@@ -156,7 +170,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
156
170
|
throw new Error("Swap invoice doesn't have msat amount field!");
|
|
157
171
|
const amountOut = (BigInt(parsedPr.millisatoshis) + 999n) / 1000n;
|
|
158
172
|
const totalFee = resp.swapFee + resp.maxFee;
|
|
159
|
-
const data = new this.
|
|
173
|
+
const data = new this._swapDataDeserializer(resp.data);
|
|
160
174
|
data.setOfferer(signer);
|
|
161
175
|
await this.verifyReturnedData(signer, resp, parsedPr, amountData.token, lp, options, data);
|
|
162
176
|
const [pricingInfo, signatureExpiry, reputation] = await Promise.all([
|
|
@@ -192,25 +206,26 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
192
206
|
}
|
|
193
207
|
}
|
|
194
208
|
/**
|
|
195
|
-
* Returns a newly created swap
|
|
209
|
+
* Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol,
|
|
210
|
+
* the amount is parsed from the provided lightning network payment request (bolt11 invoice)
|
|
196
211
|
*
|
|
197
|
-
* @param signer
|
|
198
|
-
* @param
|
|
199
|
-
* @param amountData
|
|
200
|
-
* @param lps
|
|
201
|
-
* @param options
|
|
202
|
-
* @param additionalParams
|
|
203
|
-
* @param abortSignal
|
|
204
|
-
* @param preFetches
|
|
212
|
+
* @param signer Source chain signer address initiating the swap
|
|
213
|
+
* @param recipient BOLT11 payment request (bitcoin lightning invoice) you wish to pay
|
|
214
|
+
* @param amountData Token to swap
|
|
215
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
216
|
+
* @param options Optional additional quote options
|
|
217
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
218
|
+
* @param abortSignal Abort signal
|
|
219
|
+
* @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
|
|
205
220
|
*/
|
|
206
|
-
async create(signer,
|
|
207
|
-
const parsedPr = (0, bolt11_1.decode)(
|
|
221
|
+
async create(signer, recipient, amountData, lps, options, additionalParams, abortSignal, preFetches) {
|
|
222
|
+
const parsedPr = (0, bolt11_1.decode)(recipient);
|
|
208
223
|
if (parsedPr.millisatoshis == null)
|
|
209
224
|
throw new UserError_1.UserError("Must be an invoice with amount");
|
|
210
225
|
const amountOut = (BigInt(parsedPr.millisatoshis) + 999n) / 1000n;
|
|
211
|
-
const expirySeconds = options?.expirySeconds ?? this.
|
|
212
|
-
const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this.
|
|
213
|
-
const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this.
|
|
226
|
+
const expirySeconds = options?.expirySeconds ?? this._options.paymentTimeoutSeconds;
|
|
227
|
+
const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this._options.lightningBaseFee);
|
|
228
|
+
const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this._options.lightningFeePPM);
|
|
214
229
|
const _options = {
|
|
215
230
|
expirySeconds,
|
|
216
231
|
expiryTimestamp: options?.expiryTimestamp ?? BigInt(Math.floor(Date.now() / 1000) + expirySeconds),
|
|
@@ -221,18 +236,18 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
221
236
|
if (parsedPr.tagsObject.payment_hash == null)
|
|
222
237
|
throw new Error("Provided lightning invoice doesn't contain payment hash field!");
|
|
223
238
|
await this.checkPaymentHashWasPaid(parsedPr.tagsObject.payment_hash);
|
|
224
|
-
const claimHash = this.
|
|
239
|
+
const claimHash = this._contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
|
|
225
240
|
const _abortController = (0, Utils_1.extendAbortController)(abortSignal);
|
|
226
241
|
const _preFetches = preFetches ?? {
|
|
227
242
|
pricePreFetchPromise: this.preFetchPrice(amountData, _abortController.signal),
|
|
228
243
|
feeRatePromise: this.preFetchFeeRate(signer, amountData, claimHash.toString("hex"), _abortController),
|
|
229
244
|
usdPricePrefetchPromise: this.preFetchUsdPrice(_abortController.signal),
|
|
230
|
-
signDataPrefetchPromise: this.
|
|
245
|
+
signDataPrefetchPromise: this._contract.preFetchBlockDataForSignatures == null ? this.preFetchSignData(Promise.resolve(true)) : undefined
|
|
231
246
|
};
|
|
232
247
|
return lps.map(lp => {
|
|
233
248
|
return {
|
|
234
249
|
intermediary: lp,
|
|
235
|
-
quote: this.getIntermediaryQuote(signer, amountData, lp,
|
|
250
|
+
quote: this.getIntermediaryQuote(signer, amountData, lp, recipient, parsedPr, _options, _preFetches, _abortController.signal, additionalParams)
|
|
236
251
|
};
|
|
237
252
|
});
|
|
238
253
|
}
|
|
@@ -240,14 +255,15 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
240
255
|
* Parses and fetches lnurl pay params from the specified lnurl
|
|
241
256
|
*
|
|
242
257
|
* @param lnurl LNURL to be parsed and fetched
|
|
243
|
-
* @param abortSignal
|
|
244
|
-
* @private
|
|
258
|
+
* @param abortSignal Abort signal
|
|
245
259
|
* @throws {UserError} if the LNURL is invalid or if it's not a LNURL-pay
|
|
260
|
+
*
|
|
261
|
+
* @private
|
|
246
262
|
*/
|
|
247
263
|
async getLNURLPay(lnurl, abortSignal) {
|
|
248
264
|
if (typeof (lnurl) !== "string")
|
|
249
265
|
return lnurl;
|
|
250
|
-
const res = await LNURL_1.LNURL.getLNURL(lnurl, true, this.
|
|
266
|
+
const res = await LNURL_1.LNURL.getLNURL(lnurl, true, this._options.getRequestTimeout, abortSignal);
|
|
251
267
|
if (res == null)
|
|
252
268
|
throw new UserError_1.UserError("Invalid LNURL");
|
|
253
269
|
if (res.tag !== "payRequest")
|
|
@@ -257,15 +273,17 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
257
273
|
/**
|
|
258
274
|
* Returns the quote/swap from the given LP
|
|
259
275
|
*
|
|
260
|
-
* @param signer
|
|
261
|
-
* @param amountData
|
|
276
|
+
* @param signer Source chain signer address initiating the swap
|
|
277
|
+
* @param amountData Token to swap
|
|
262
278
|
* @param invoiceCreateService Service for creating fixed amount invoices
|
|
263
|
-
* @param lp Intermediary
|
|
264
|
-
* @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay
|
|
265
|
-
*
|
|
266
|
-
* @param
|
|
267
|
-
* @param
|
|
279
|
+
* @param lp Intermediary (LPs) to get the quote from
|
|
280
|
+
* @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay, used to estimate
|
|
281
|
+
* network fees for an actual invoice
|
|
282
|
+
* @param options Optional additional quote options
|
|
283
|
+
* @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
|
|
284
|
+
* @param abortSignal Abort signal
|
|
268
285
|
* @param additionalParams Additional params to be sent to the intermediary
|
|
286
|
+
*
|
|
269
287
|
* @private
|
|
270
288
|
*/
|
|
271
289
|
async getIntermediaryQuoteExactIn(signer, amountData, invoiceCreateService, lp, dummyPr, options, preFetches, abortSignal, additionalParams) {
|
|
@@ -283,7 +301,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
283
301
|
maxFee: await options.maxFee,
|
|
284
302
|
expiryTimestamp: options.expiryTimestamp,
|
|
285
303
|
additionalParams
|
|
286
|
-
}, this.
|
|
304
|
+
}, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined);
|
|
287
305
|
return {
|
|
288
306
|
signDataPromise: this.preFetchSignData(signDataPrefetch),
|
|
289
307
|
prepareResp: await response
|
|
@@ -306,12 +324,12 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
306
324
|
reqId: prepareResp.reqId,
|
|
307
325
|
feeRate: (0, Utils_1.throwIfUndefined)(preFetches.feeRatePromise),
|
|
308
326
|
additionalParams
|
|
309
|
-
}, this.
|
|
327
|
+
}, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined), undefined, RequestError_1.RequestError, abortController.signal);
|
|
310
328
|
if (parsedInvoice.millisatoshis == null)
|
|
311
329
|
throw new Error("Swap invoice doesn't have msat amount field!");
|
|
312
330
|
const amountOut = (BigInt(parsedInvoice.millisatoshis) + 999n) / 1000n;
|
|
313
331
|
const totalFee = resp.swapFee + resp.maxFee;
|
|
314
|
-
const data = new this.
|
|
332
|
+
const data = new this._swapDataDeserializer(resp.data);
|
|
315
333
|
data.setOfferer(signer);
|
|
316
334
|
await this.verifyReturnedData(signer, resp, parsedInvoice, amountData.token, lp, options, data, amountData.amount);
|
|
317
335
|
const [pricingInfo, signatureExpiry, reputation] = await Promise.all([
|
|
@@ -347,15 +365,17 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
347
365
|
}
|
|
348
366
|
}
|
|
349
367
|
/**
|
|
350
|
-
* Returns a newly created swap
|
|
368
|
+
* Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol via
|
|
369
|
+
* invoice creation service. This allows exactIn swaps by requesting the desired fixed amount lightning
|
|
370
|
+
* network invoice from the service.
|
|
351
371
|
*
|
|
352
|
-
* @param signer
|
|
353
|
-
* @param invoiceCreateServicePromise
|
|
354
|
-
* @param amountData
|
|
355
|
-
* @param lps
|
|
356
|
-
* @param options
|
|
357
|
-
* @param additionalParams
|
|
358
|
-
* @param abortSignal
|
|
372
|
+
* @param signer Source chain signer address initiating the swap
|
|
373
|
+
* @param invoiceCreateServicePromise Service to request destination lightning network invoices from
|
|
374
|
+
* @param amountData Amount, token and exact input/output data for to swap
|
|
375
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
376
|
+
* @param options Optional additional quote options
|
|
377
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
378
|
+
* @param abortSignal Abort signal
|
|
359
379
|
*/
|
|
360
380
|
async createViaInvoiceCreateService(signer, invoiceCreateServicePromise, amountData, lps, options, additionalParams, abortSignal) {
|
|
361
381
|
if (!this.isInitialized)
|
|
@@ -364,7 +384,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
364
384
|
const pricePreFetchPromise = this.preFetchPrice(amountData, _abortController.signal);
|
|
365
385
|
const usdPricePrefetchPromise = this.preFetchUsdPrice(_abortController.signal);
|
|
366
386
|
const feeRatePromise = this.preFetchFeeRate(signer, amountData, undefined, _abortController);
|
|
367
|
-
const signDataPrefetchPromise = this.
|
|
387
|
+
const signDataPrefetchPromise = this._contract.preFetchBlockDataForSignatures == null ?
|
|
368
388
|
this.preFetchSignData(Promise.resolve(true)) :
|
|
369
389
|
undefined;
|
|
370
390
|
const _options = this.toRequiredSwapOptions(amountData, options, pricePreFetchPromise, _abortController.signal);
|
|
@@ -407,15 +427,17 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
407
427
|
}
|
|
408
428
|
}
|
|
409
429
|
/**
|
|
410
|
-
* Returns a newly created swap
|
|
430
|
+
* Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol. Pays to
|
|
431
|
+
* an LNURL-pay link. This allows exactIn swaps by requesting the desired fixed amount lightning
|
|
432
|
+
* network invoice from the LNURL service.
|
|
411
433
|
*
|
|
412
|
-
* @param signer
|
|
413
|
-
* @param lnurl
|
|
414
|
-
* @param amountData
|
|
415
|
-
* @param lps
|
|
416
|
-
* @param options
|
|
417
|
-
* @param additionalParams
|
|
418
|
-
* @param abortSignal
|
|
434
|
+
* @param signer Source chain signer address initiating the swap
|
|
435
|
+
* @param lnurl LNURL-pay link of the recipient
|
|
436
|
+
* @param amountData Amount, token and exact input/output data for to swap
|
|
437
|
+
* @param lps An array of intermediaries (LPs) to get the quotes from
|
|
438
|
+
* @param options Optional additional quote options
|
|
439
|
+
* @param additionalParams Optional additional parameters sent to the LP when creating the swap
|
|
440
|
+
* @param abortSignal Abort signal
|
|
419
441
|
*/
|
|
420
442
|
async createViaLNURL(signer, lnurl, amountData, lps, options, additionalParams, abortSignal) {
|
|
421
443
|
let successActions = {};
|
|
@@ -427,7 +449,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
427
449
|
throw new UserError_1.UserError("Comment not allowed or too long");
|
|
428
450
|
return {
|
|
429
451
|
getInvoice: async (amountSats, abortSignal) => {
|
|
430
|
-
const { invoice, successAction } = await LNURL_1.LNURL.useLNURLPay(payRequest, BigInt(amountSats), options?.comment, this.
|
|
452
|
+
const { invoice, successAction } = await LNURL_1.LNURL.useLNURLPay(payRequest, BigInt(amountSats), options?.comment, this._options.getRequestTimeout, abortSignal);
|
|
431
453
|
if (successAction != null)
|
|
432
454
|
successActions[invoice] = successAction;
|
|
433
455
|
return invoice;
|
|
@@ -443,18 +465,22 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
443
465
|
_abortController.signal.throwIfAborted();
|
|
444
466
|
return quotes.map(value => ({
|
|
445
467
|
quote: value.quote.then(quote => {
|
|
446
|
-
|
|
468
|
+
let _successAction;
|
|
447
469
|
const quoteAddress = quote.getOutputAddress();
|
|
448
470
|
if (quoteAddress != null) {
|
|
449
471
|
const successAction = successActions[quoteAddress];
|
|
450
472
|
if (successAction != null)
|
|
451
|
-
|
|
473
|
+
_successAction = successAction;
|
|
452
474
|
}
|
|
475
|
+
quote._setLNURLData(resolved.url, _successAction);
|
|
453
476
|
return quote;
|
|
454
477
|
}),
|
|
455
478
|
intermediary: value.intermediary
|
|
456
479
|
}));
|
|
457
480
|
}
|
|
481
|
+
/**
|
|
482
|
+
* @inheritDoc
|
|
483
|
+
*/
|
|
458
484
|
async recoverFromSwapDataAndState(init, state, lp) {
|
|
459
485
|
const data = init.data;
|
|
460
486
|
let paymentHash = data.getHTLCHashHint();
|
|
@@ -463,7 +489,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
463
489
|
secret = await state.getClaimResult();
|
|
464
490
|
paymentHash = Buffer.from((0, sha2_1.sha256)(Buffer.from(secret, "hex"))).toString("hex");
|
|
465
491
|
}
|
|
466
|
-
const
|
|
492
|
+
const swapInit = {
|
|
467
493
|
pricingInfo: {
|
|
468
494
|
isValid: true,
|
|
469
495
|
satsBaseFee: 0n,
|
|
@@ -482,37 +508,16 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
|
|
|
482
508
|
networkFee: 0n,
|
|
483
509
|
networkFeeBtc: 0n,
|
|
484
510
|
confidence: 0,
|
|
485
|
-
pr: paymentHash,
|
|
511
|
+
pr: paymentHash ?? undefined,
|
|
486
512
|
exactIn: false
|
|
487
|
-
}
|
|
488
|
-
swap
|
|
513
|
+
};
|
|
514
|
+
const swap = new ToBTCLNSwap_1.ToBTCLNSwap(this, swapInit);
|
|
515
|
+
swap._commitTxId = await init.getInitTxId();
|
|
489
516
|
const blockData = await init.getTxBlock();
|
|
490
517
|
swap.createdAt = blockData.blockTime * 1000;
|
|
491
518
|
swap._setInitiated();
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
secret ??= await state.getClaimResult();
|
|
495
|
-
await swap._setPaymentResult({ secret }, false);
|
|
496
|
-
swap.claimTxId = await state.getClaimTxId();
|
|
497
|
-
swap.state = IToBTCSwap_1.ToBTCSwapState.CLAIMED;
|
|
498
|
-
break;
|
|
499
|
-
case base_1.SwapCommitStateType.NOT_COMMITED:
|
|
500
|
-
case base_1.SwapCommitStateType.EXPIRED:
|
|
501
|
-
if (state.getRefundTxId == null)
|
|
502
|
-
return null;
|
|
503
|
-
swap.refundTxId = await state.getRefundTxId();
|
|
504
|
-
swap.state = IToBTCSwap_1.ToBTCSwapState.REFUNDED;
|
|
505
|
-
break;
|
|
506
|
-
case base_1.SwapCommitStateType.COMMITED:
|
|
507
|
-
swap.state = IToBTCSwap_1.ToBTCSwapState.COMMITED;
|
|
508
|
-
//Try to fetch refund signature
|
|
509
|
-
if (lp != null)
|
|
510
|
-
await swap._sync(false, false, state);
|
|
511
|
-
break;
|
|
512
|
-
case base_1.SwapCommitStateType.REFUNDABLE:
|
|
513
|
-
swap.state = IToBTCSwap_1.ToBTCSwapState.REFUNDABLE;
|
|
514
|
-
break;
|
|
515
|
-
}
|
|
519
|
+
swap._state = IToBTCSwap_1.ToBTCSwapState.COMMITED;
|
|
520
|
+
await swap._sync(false, false, state);
|
|
516
521
|
await swap._save();
|
|
517
522
|
return swap;
|
|
518
523
|
}
|