@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,6 @@ import {decode as bolt11Decode} from "@atomiqlabs/bolt11";
|
|
|
2
2
|
import {SwapType} from "../../../enums/SwapType";
|
|
3
3
|
import {ChainType} from "@atomiqlabs/base";
|
|
4
4
|
import {LnForGasSwapTypeDefinition, LnForGasWrapper} from "./LnForGasWrapper";
|
|
5
|
-
import {PaymentAuthError} from "../../../errors/PaymentAuthError";
|
|
6
5
|
import {toBigInt} from "../../../utils/Utils";
|
|
7
6
|
import {isISwapInit, ISwap, ISwapInit} from "../../ISwap";
|
|
8
7
|
import {InvoiceStatusResponseCodes, TrustedIntermediaryAPI} from "../../../intermediaries/apis/TrustedIntermediaryAPI";
|
|
@@ -14,16 +13,33 @@ import {TokenAmount, toTokenAmount} from "../../../types/TokenAmount";
|
|
|
14
13
|
import {BitcoinTokens, BtcToken, SCToken} from "../../../types/Token";
|
|
15
14
|
import {getLogger, LoggerType} from "../../../utils/Logger";
|
|
16
15
|
import {timeoutPromise} from "../../../utils/TimeoutUtils";
|
|
16
|
+
import {SwapExecutionActionLightning} from "../../../types/SwapExecutionAction";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* State enum for trusted Lightning gas swaps
|
|
20
|
-
*
|
|
20
|
+
*
|
|
21
|
+
* @category Swaps/Trusted Gas Swaps
|
|
21
22
|
*/
|
|
22
23
|
export enum LnForGasSwapState {
|
|
24
|
+
/**
|
|
25
|
+
* The swap quote expired without user sending in the lightning network payment
|
|
26
|
+
*/
|
|
23
27
|
EXPIRED = -2,
|
|
28
|
+
/**
|
|
29
|
+
* The swap has failed after the intermediary already received a lightning network payment on the source
|
|
30
|
+
*/
|
|
24
31
|
FAILED = -1,
|
|
32
|
+
/**
|
|
33
|
+
* Swap was created
|
|
34
|
+
*/
|
|
25
35
|
PR_CREATED = 0,
|
|
36
|
+
/**
|
|
37
|
+
* User paid the lightning network invoice on the source
|
|
38
|
+
*/
|
|
26
39
|
PR_PAID = 1,
|
|
40
|
+
/**
|
|
41
|
+
* The swap is finished after the intermediary sent funds on the destination chain
|
|
42
|
+
*/
|
|
27
43
|
FINISHED = 2
|
|
28
44
|
}
|
|
29
45
|
|
|
@@ -43,12 +59,20 @@ export function isLnForGasSwapInit(obj: any): obj is LnForGasSwapInit {
|
|
|
43
59
|
}
|
|
44
60
|
|
|
45
61
|
/**
|
|
46
|
-
* Trusted Lightning
|
|
47
|
-
*
|
|
62
|
+
* Trusted swap for Bitcoin Lightning -> Smart chains, to be used for minor amounts to get gas tokens on
|
|
63
|
+
* the destination chain, which is only needed for Solana, which still uses legacy swaps
|
|
64
|
+
*
|
|
65
|
+
* @category Swaps/Trusted Gas Swaps
|
|
48
66
|
*/
|
|
49
67
|
export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnForGasSwapTypeDefinition<T>, LnForGasSwapState> implements IAddressSwap {
|
|
68
|
+
protected readonly TYPE: SwapType.TRUSTED_FROM_BTCLN = SwapType.TRUSTED_FROM_BTCLN;
|
|
69
|
+
/**
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
50
72
|
protected readonly currentVersion: number = 2;
|
|
51
|
-
|
|
73
|
+
/**
|
|
74
|
+
* @internal
|
|
75
|
+
*/
|
|
52
76
|
protected readonly logger: LoggerType;
|
|
53
77
|
|
|
54
78
|
//State: PR_CREATED
|
|
@@ -58,7 +82,11 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
58
82
|
private readonly token: string;
|
|
59
83
|
|
|
60
84
|
//State: FINISHED
|
|
61
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Destination transaction ID on the smart chain side
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
private scTxId?: string;
|
|
62
90
|
|
|
63
91
|
constructor(wrapper: LnForGasWrapper<T>, init: LnForGasSwapInit);
|
|
64
92
|
constructor(wrapper: LnForGasWrapper<T>, obj: any);
|
|
@@ -73,7 +101,7 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
73
101
|
this.outputAmount = initOrObj.outputAmount;
|
|
74
102
|
this.recipient = initOrObj.recipient;
|
|
75
103
|
this.token = initOrObj.token;
|
|
76
|
-
this.
|
|
104
|
+
this._state = LnForGasSwapState.PR_CREATED;
|
|
77
105
|
} else {
|
|
78
106
|
this.pr = initOrObj.pr;
|
|
79
107
|
this.outputAmount = toBigInt(initOrObj.outputAmount);
|
|
@@ -89,9 +117,13 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
89
117
|
this.logger = getLogger("LnForGas("+this.getId()+"): ");
|
|
90
118
|
}
|
|
91
119
|
|
|
120
|
+
/**
|
|
121
|
+
* @inheritDoc
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
92
124
|
protected upgradeVersion() {
|
|
93
125
|
if(this.version == 1) {
|
|
94
|
-
if(this.
|
|
126
|
+
if(this._state===1) this._state = LnForGasSwapState.FINISHED;
|
|
95
127
|
this.version = 2;
|
|
96
128
|
}
|
|
97
129
|
if(this.version == null) {
|
|
@@ -101,8 +133,8 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
101
133
|
}
|
|
102
134
|
|
|
103
135
|
/**
|
|
104
|
-
*
|
|
105
|
-
* @
|
|
136
|
+
* @inheritDoc
|
|
137
|
+
* @internal
|
|
106
138
|
*/
|
|
107
139
|
protected tryRecomputeSwapPrice() {
|
|
108
140
|
if(this.swapFeeBtc==null && this.swapFee!=null) {
|
|
@@ -115,26 +147,45 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
115
147
|
//////////////////////////////
|
|
116
148
|
//// Getters & utils
|
|
117
149
|
|
|
150
|
+
/**
|
|
151
|
+
* @inheritDoc
|
|
152
|
+
* @internal
|
|
153
|
+
*/
|
|
118
154
|
_getEscrowHash(): string {
|
|
119
155
|
return this.getId();
|
|
120
156
|
}
|
|
121
157
|
|
|
158
|
+
/**
|
|
159
|
+
* @inheritDoc
|
|
160
|
+
*/
|
|
122
161
|
getOutputAddress(): string | null {
|
|
123
162
|
return this.recipient;
|
|
124
163
|
}
|
|
125
164
|
|
|
165
|
+
/**
|
|
166
|
+
* @inheritDoc
|
|
167
|
+
*/
|
|
126
168
|
getInputAddress(): string | null {
|
|
127
169
|
return this.pr;
|
|
128
170
|
}
|
|
129
171
|
|
|
172
|
+
/**
|
|
173
|
+
* @inheritDoc
|
|
174
|
+
*/
|
|
130
175
|
getInputTxId(): string | null {
|
|
131
176
|
return this.getId();
|
|
132
177
|
}
|
|
133
178
|
|
|
179
|
+
/**
|
|
180
|
+
* @inheritDoc
|
|
181
|
+
*/
|
|
134
182
|
getOutputTxId(): string | null {
|
|
135
183
|
return this.scTxId ?? null;
|
|
136
184
|
}
|
|
137
185
|
|
|
186
|
+
/**
|
|
187
|
+
* @inheritDoc
|
|
188
|
+
*/
|
|
138
189
|
getId(): string {
|
|
139
190
|
if(this.pr==null) throw new Error("No payment request assigned to this swap!");
|
|
140
191
|
const decodedPR = bolt11Decode(this.pr);
|
|
@@ -156,64 +207,115 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
156
207
|
return "lightning:"+this.pr.toUpperCase();
|
|
157
208
|
}
|
|
158
209
|
|
|
210
|
+
/**
|
|
211
|
+
* @inheritDoc
|
|
212
|
+
*/
|
|
159
213
|
requiresAction(): boolean {
|
|
160
214
|
return false;
|
|
161
215
|
}
|
|
162
216
|
|
|
217
|
+
/**
|
|
218
|
+
* @inheritDoc
|
|
219
|
+
*/
|
|
163
220
|
isFinished(): boolean {
|
|
164
|
-
return this.
|
|
221
|
+
return this._state===LnForGasSwapState.FINISHED || this._state===LnForGasSwapState.FAILED || this._state===LnForGasSwapState.EXPIRED;
|
|
165
222
|
}
|
|
166
223
|
|
|
224
|
+
/**
|
|
225
|
+
* @inheritDoc
|
|
226
|
+
*/
|
|
167
227
|
isQuoteExpired(): boolean {
|
|
168
|
-
return this.
|
|
228
|
+
return this._state===LnForGasSwapState.EXPIRED;
|
|
169
229
|
}
|
|
170
230
|
|
|
231
|
+
/**
|
|
232
|
+
* @inheritDoc
|
|
233
|
+
*/
|
|
171
234
|
isQuoteSoftExpired(): boolean {
|
|
172
235
|
return this.expiry<Date.now();
|
|
173
236
|
}
|
|
174
237
|
|
|
238
|
+
/**
|
|
239
|
+
* @inheritDoc
|
|
240
|
+
*/
|
|
175
241
|
isFailed(): boolean {
|
|
176
|
-
return this.
|
|
242
|
+
return this._state===LnForGasSwapState.FAILED;
|
|
177
243
|
}
|
|
178
244
|
|
|
245
|
+
/**
|
|
246
|
+
* @inheritDoc
|
|
247
|
+
*/
|
|
179
248
|
isSuccessful(): boolean {
|
|
180
|
-
return this.
|
|
249
|
+
return this._state===LnForGasSwapState.FINISHED;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* @inheritDoc
|
|
254
|
+
* @internal
|
|
255
|
+
*/
|
|
256
|
+
_verifyQuoteDefinitelyExpired(): Promise<boolean> {
|
|
257
|
+
return Promise.resolve(this.expiry<Date.now());
|
|
181
258
|
}
|
|
182
259
|
|
|
183
|
-
|
|
260
|
+
/**
|
|
261
|
+
* @inheritDoc
|
|
262
|
+
* @internal
|
|
263
|
+
*/
|
|
264
|
+
_verifyQuoteValid(): Promise<boolean> {
|
|
184
265
|
return Promise.resolve(this.expiry>Date.now());
|
|
185
266
|
}
|
|
186
267
|
|
|
187
268
|
//////////////////////////////
|
|
188
269
|
//// Amounts & fees
|
|
189
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Returns an output amount in base units without a swap fee included, hence this value
|
|
273
|
+
* is larger than the actual output amount
|
|
274
|
+
*
|
|
275
|
+
* @internal
|
|
276
|
+
*/
|
|
190
277
|
protected getOutAmountWithoutFee(): bigint {
|
|
191
278
|
return this.outputAmount + (this.swapFee ?? 0n);
|
|
192
279
|
}
|
|
193
280
|
|
|
281
|
+
/**
|
|
282
|
+
* @inheritDoc
|
|
283
|
+
*/
|
|
194
284
|
getOutputToken(): SCToken<T["ChainId"]> {
|
|
195
|
-
return this.wrapper.
|
|
285
|
+
return this.wrapper._tokens[this.wrapper._chain.getNativeCurrencyAddress()];
|
|
196
286
|
}
|
|
197
287
|
|
|
288
|
+
/**
|
|
289
|
+
* @inheritDoc
|
|
290
|
+
*/
|
|
198
291
|
getOutput(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>, true> {
|
|
199
292
|
return toTokenAmount(
|
|
200
|
-
this.outputAmount, this.wrapper.
|
|
201
|
-
this.wrapper.
|
|
293
|
+
this.outputAmount, this.wrapper._tokens[this.wrapper._chain.getNativeCurrencyAddress()],
|
|
294
|
+
this.wrapper._prices, this.pricingInfo
|
|
202
295
|
);
|
|
203
296
|
}
|
|
204
297
|
|
|
298
|
+
/**
|
|
299
|
+
* @inheritDoc
|
|
300
|
+
*/
|
|
205
301
|
getInputToken(): BtcToken<true> {
|
|
206
302
|
return BitcoinTokens.BTCLN;
|
|
207
303
|
}
|
|
208
304
|
|
|
305
|
+
/**
|
|
306
|
+
* @inheritDoc
|
|
307
|
+
*/
|
|
209
308
|
getInput(): TokenAmount<T["ChainId"], BtcToken<true>, true> {
|
|
210
309
|
const parsed = bolt11Decode(this.pr);
|
|
211
310
|
const msats = parsed.millisatoshis;
|
|
212
311
|
if(msats==null) throw new Error("Swap lightning invoice has no msat amount field!");
|
|
213
312
|
const amount = (BigInt(msats) + 999n) / 1000n;
|
|
214
|
-
return toTokenAmount(amount, BitcoinTokens.BTCLN, this.wrapper.
|
|
313
|
+
return toTokenAmount(amount, BitcoinTokens.BTCLN, this.wrapper._prices, this.pricingInfo);
|
|
215
314
|
}
|
|
216
315
|
|
|
316
|
+
/**
|
|
317
|
+
* @inheritDoc
|
|
318
|
+
*/
|
|
217
319
|
getInputWithoutFee(): TokenAmount<T["ChainId"], BtcToken<true>, true> {
|
|
218
320
|
const parsed = bolt11Decode(this.pr);
|
|
219
321
|
const msats = parsed.millisatoshis;
|
|
@@ -221,33 +323,44 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
221
323
|
const amount = (BigInt(msats) + 999n) / 1000n;
|
|
222
324
|
return toTokenAmount(
|
|
223
325
|
amount - (this.swapFeeBtc ?? 0n), BitcoinTokens.BTCLN,
|
|
224
|
-
this.wrapper.
|
|
326
|
+
this.wrapper._prices, this.pricingInfo
|
|
225
327
|
);
|
|
226
328
|
}
|
|
227
329
|
|
|
330
|
+
/**
|
|
331
|
+
* Returns the swap fee charged by the intermediary (LP) on this swap
|
|
332
|
+
*
|
|
333
|
+
* @internal
|
|
334
|
+
*/
|
|
228
335
|
protected getSwapFee(): Fee<T["ChainId"], BtcToken<true>, SCToken<T["ChainId"]>> {
|
|
229
336
|
if(this.pricingInfo==null) throw new Error("No pricing info known, cannot estimate swap fee!");
|
|
230
337
|
const feeWithoutBaseFee = this.swapFeeBtc==null ? 0n : this.swapFeeBtc - this.pricingInfo.satsBaseFee;
|
|
231
338
|
const swapFeePPM = feeWithoutBaseFee * 1000000n / this.getInputWithoutFee().rawAmount;
|
|
232
339
|
|
|
233
|
-
const amountInSrcToken = toTokenAmount(this.swapFeeBtc ?? 0n, BitcoinTokens.BTCLN, this.wrapper.
|
|
340
|
+
const amountInSrcToken = toTokenAmount(this.swapFeeBtc ?? 0n, BitcoinTokens.BTCLN, this.wrapper._prices, this.pricingInfo);
|
|
234
341
|
return {
|
|
235
342
|
amountInSrcToken,
|
|
236
|
-
amountInDstToken: toTokenAmount(this.swapFee ?? 0n, this.wrapper.
|
|
343
|
+
amountInDstToken: toTokenAmount(this.swapFee ?? 0n, this.wrapper._tokens[this.wrapper._chain.getNativeCurrencyAddress()], this.wrapper._prices, this.pricingInfo),
|
|
237
344
|
currentUsdValue: amountInSrcToken.currentUsdValue,
|
|
238
345
|
usdValue: amountInSrcToken.usdValue,
|
|
239
346
|
pastUsdValue: amountInSrcToken.pastUsdValue,
|
|
240
347
|
composition: {
|
|
241
|
-
base: toTokenAmount(this.pricingInfo.satsBaseFee, BitcoinTokens.BTCLN, this.wrapper.
|
|
348
|
+
base: toTokenAmount(this.pricingInfo.satsBaseFee, BitcoinTokens.BTCLN, this.wrapper._prices, this.pricingInfo),
|
|
242
349
|
percentage: ppmToPercentage(swapFeePPM)
|
|
243
350
|
}
|
|
244
351
|
};
|
|
245
352
|
}
|
|
246
353
|
|
|
354
|
+
/**
|
|
355
|
+
* @inheritDoc
|
|
356
|
+
*/
|
|
247
357
|
getFee(): Fee<T["ChainId"], BtcToken<true>, SCToken<T["ChainId"]>> {
|
|
248
358
|
return this.getSwapFee();
|
|
249
359
|
}
|
|
250
360
|
|
|
361
|
+
/**
|
|
362
|
+
* @inheritDoc
|
|
363
|
+
*/
|
|
251
364
|
getFeeBreakdown(): [{type: FeeType.SWAP, fee: Fee<T["ChainId"], BtcToken<true>, SCToken<T["ChainId"]>>}] {
|
|
252
365
|
return [{
|
|
253
366
|
type: FeeType.SWAP,
|
|
@@ -259,9 +372,12 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
259
372
|
//////////////////////////////
|
|
260
373
|
//// Payment
|
|
261
374
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
375
|
+
/**
|
|
376
|
+
* @inheritDoc
|
|
377
|
+
*/
|
|
378
|
+
async txsExecute(): Promise<[SwapExecutionActionLightning]> {
|
|
379
|
+
if(this._state===LnForGasSwapState.PR_CREATED) {
|
|
380
|
+
if (!await this._verifyQuoteValid()) throw new Error("Quote already expired or close to expiry!");
|
|
265
381
|
return [
|
|
266
382
|
{
|
|
267
383
|
name: "Payment" as const,
|
|
@@ -269,6 +385,7 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
269
385
|
chain: "LIGHTNING",
|
|
270
386
|
txs: [
|
|
271
387
|
{
|
|
388
|
+
type: "BOLT11_PAYMENT_REQUEST",
|
|
272
389
|
address: this.pr,
|
|
273
390
|
hyperlink: this.getHyperlink()
|
|
274
391
|
}
|
|
@@ -280,9 +397,17 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
280
397
|
throw new Error("Invalid swap state to obtain execution txns, required PR_CREATED");
|
|
281
398
|
}
|
|
282
399
|
|
|
400
|
+
/**
|
|
401
|
+
* Queries the intermediary (LP) node for the state of the swap
|
|
402
|
+
*
|
|
403
|
+
* @param save Whether the save the result or not
|
|
404
|
+
*
|
|
405
|
+
* @returns Whether the swap was successful as `boolean` or `null` if the swap is still pending
|
|
406
|
+
* @internal
|
|
407
|
+
*/
|
|
283
408
|
protected async checkInvoicePaid(save: boolean = true): Promise<boolean | null> {
|
|
284
|
-
if(this.
|
|
285
|
-
if(this.
|
|
409
|
+
if(this._state===LnForGasSwapState.FAILED || this._state===LnForGasSwapState.EXPIRED) return false;
|
|
410
|
+
if(this._state===LnForGasSwapState.FINISHED) return true;
|
|
286
411
|
if(this.url==null) return false;
|
|
287
412
|
|
|
288
413
|
const decodedPR = bolt11Decode(this.pr);
|
|
@@ -290,72 +415,71 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
290
415
|
if(paymentHash==null) throw new Error("Invalid swap invoice, payment hash not found!");
|
|
291
416
|
|
|
292
417
|
const response = await TrustedIntermediaryAPI.getInvoiceStatus(
|
|
293
|
-
this.url, paymentHash, this.wrapper.
|
|
418
|
+
this.url, paymentHash, this.wrapper._options.getRequestTimeout
|
|
294
419
|
);
|
|
295
420
|
this.logger.debug("checkInvoicePaid(): LP response: ", response);
|
|
296
421
|
switch(response.code) {
|
|
297
422
|
case InvoiceStatusResponseCodes.PAID:
|
|
298
423
|
this.scTxId = response.data.txId;
|
|
299
|
-
const txStatus = await this.wrapper.
|
|
424
|
+
const txStatus = await this.wrapper._chain.getTxIdStatus(this.scTxId);
|
|
300
425
|
if(txStatus==="success") {
|
|
301
|
-
this.
|
|
426
|
+
this._state = LnForGasSwapState.FINISHED;
|
|
302
427
|
if(save) await this._saveAndEmit();
|
|
303
428
|
return true;
|
|
304
429
|
}
|
|
305
430
|
return null;
|
|
306
431
|
case InvoiceStatusResponseCodes.EXPIRED:
|
|
307
|
-
if(this.
|
|
308
|
-
this.
|
|
432
|
+
if(this._state===LnForGasSwapState.PR_CREATED) {
|
|
433
|
+
this._state = LnForGasSwapState.EXPIRED;
|
|
309
434
|
} else {
|
|
310
|
-
this.
|
|
435
|
+
this._state = LnForGasSwapState.FAILED;
|
|
311
436
|
}
|
|
312
437
|
if(save) await this._saveAndEmit();
|
|
313
438
|
return false;
|
|
314
439
|
case InvoiceStatusResponseCodes.TX_SENT:
|
|
315
440
|
this.scTxId = response.data.txId;
|
|
316
|
-
if(this.
|
|
317
|
-
this.
|
|
441
|
+
if(this._state===LnForGasSwapState.PR_CREATED) {
|
|
442
|
+
this._state = LnForGasSwapState.PR_PAID;
|
|
318
443
|
if(save) await this._saveAndEmit();
|
|
319
444
|
}
|
|
320
445
|
return null;
|
|
321
446
|
case InvoiceStatusResponseCodes.PENDING:
|
|
322
|
-
if(this.
|
|
323
|
-
this.
|
|
447
|
+
if(this._state===LnForGasSwapState.PR_CREATED) {
|
|
448
|
+
this._state = LnForGasSwapState.PR_PAID;
|
|
324
449
|
if(save) await this._saveAndEmit();
|
|
325
450
|
}
|
|
326
451
|
return null;
|
|
327
452
|
case InvoiceStatusResponseCodes.AWAIT_PAYMENT:
|
|
328
453
|
return null;
|
|
329
454
|
default:
|
|
330
|
-
this.
|
|
455
|
+
this._state = LnForGasSwapState.FAILED;
|
|
331
456
|
if(save) await this._saveAndEmit();
|
|
332
457
|
return false;
|
|
333
458
|
}
|
|
334
459
|
}
|
|
335
460
|
|
|
336
461
|
/**
|
|
337
|
-
* A blocking promise resolving when payment was received by the intermediary and client can continue
|
|
338
|
-
*
|
|
462
|
+
* A blocking promise resolving when payment was received by the intermediary and client can continue,
|
|
463
|
+
* rejecting in case of failure. The swap must be in {@link LnForGasSwapState.PR_CREATED} state!
|
|
339
464
|
*
|
|
340
465
|
* @param checkIntervalSeconds How often to poll the intermediary for answer (default 5 seconds)
|
|
341
466
|
* @param abortSignal Abort signal
|
|
342
|
-
* @throws {PaymentAuthError} If swap expired or failed
|
|
343
467
|
* @throws {Error} When in invalid state (not PR_CREATED)
|
|
344
468
|
*/
|
|
345
469
|
async waitForPayment(checkIntervalSeconds?: number, abortSignal?: AbortSignal): Promise<boolean> {
|
|
346
|
-
if(this.
|
|
470
|
+
if(this._state!==LnForGasSwapState.PR_CREATED) throw new Error("Must be in PR_CREATED state!");
|
|
347
471
|
|
|
348
472
|
if(!this.initiated) {
|
|
349
473
|
this.initiated = true;
|
|
350
474
|
await this._saveAndEmit();
|
|
351
475
|
}
|
|
352
476
|
|
|
353
|
-
while(!abortSignal?.aborted && (this.
|
|
477
|
+
while(!abortSignal?.aborted && (this._state===LnForGasSwapState.PR_CREATED || this._state===LnForGasSwapState.PR_PAID)) {
|
|
354
478
|
await this.checkInvoicePaid(true);
|
|
355
|
-
if(this.
|
|
479
|
+
if(this._state===LnForGasSwapState.PR_CREATED || this._state===LnForGasSwapState.PR_PAID) await timeoutPromise((checkIntervalSeconds ?? 5)*1000, abortSignal);
|
|
356
480
|
}
|
|
357
481
|
|
|
358
|
-
if(this.isFailed()) throw new
|
|
482
|
+
if(this.isFailed()) throw new Error("Swap failed");
|
|
359
483
|
return !this.isQuoteExpired();
|
|
360
484
|
|
|
361
485
|
}
|
|
@@ -364,6 +488,9 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
364
488
|
//////////////////////////////
|
|
365
489
|
//// Storage
|
|
366
490
|
|
|
491
|
+
/**
|
|
492
|
+
* @inheritDoc
|
|
493
|
+
*/
|
|
367
494
|
serialize(): any{
|
|
368
495
|
return {
|
|
369
496
|
...super.serialize(),
|
|
@@ -375,6 +502,10 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
375
502
|
};
|
|
376
503
|
}
|
|
377
504
|
|
|
505
|
+
/**
|
|
506
|
+
* @inheritDoc
|
|
507
|
+
* @internal
|
|
508
|
+
*/
|
|
378
509
|
_getInitiator(): string {
|
|
379
510
|
return this.recipient;
|
|
380
511
|
}
|
|
@@ -383,8 +514,12 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
383
514
|
//////////////////////////////
|
|
384
515
|
//// Swap ticks & sync
|
|
385
516
|
|
|
517
|
+
/**
|
|
518
|
+
* @inheritDoc
|
|
519
|
+
* @internal
|
|
520
|
+
*/
|
|
386
521
|
async _sync(save?: boolean): Promise<boolean> {
|
|
387
|
-
if(this.
|
|
522
|
+
if(this._state===LnForGasSwapState.PR_CREATED) {
|
|
388
523
|
//Check if it's maybe already paid
|
|
389
524
|
const res = await this.checkInvoicePaid(false);
|
|
390
525
|
if(res!==null) {
|
|
@@ -395,6 +530,10 @@ export class LnForGasSwap<T extends ChainType = ChainType> extends ISwap<T, LnFo
|
|
|
395
530
|
return false;
|
|
396
531
|
}
|
|
397
532
|
|
|
533
|
+
/**
|
|
534
|
+
* @inheritDoc
|
|
535
|
+
* @internal
|
|
536
|
+
*/
|
|
398
537
|
_tick(save?: boolean): Promise<boolean> {
|
|
399
538
|
return Promise.resolve(false);
|
|
400
539
|
}
|
|
@@ -9,29 +9,52 @@ import {SwapType} from "../../../enums/SwapType";
|
|
|
9
9
|
|
|
10
10
|
export type LnForGasSwapTypeDefinition<T extends ChainType> = SwapTypeDefinition<T, LnForGasWrapper<T>, LnForGasSwap<T>>;
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Trusted swap for Bitcoin Lightning -> Smart chains, to be used for minor amounts to get gas tokens on
|
|
14
|
+
* the destination chain, which is only needed for Solana, which still uses legacy swaps
|
|
15
|
+
*
|
|
16
|
+
* @category Swaps/Trusted Gas Swaps
|
|
17
|
+
*/
|
|
12
18
|
export class LnForGasWrapper<T extends ChainType> extends ISwapWrapper<T, LnForGasSwapTypeDefinition<T>> {
|
|
13
|
-
public TYPE = SwapType.TRUSTED_FROM_BTCLN;
|
|
14
|
-
|
|
19
|
+
public TYPE: SwapType.TRUSTED_FROM_BTCLN = SwapType.TRUSTED_FROM_BTCLN;
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
public readonly _swapDeserializer = LnForGasSwap;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
readonly _pendingSwapStates = [LnForGasSwapState.PR_CREATED];
|
|
29
|
+
/**
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
protected readonly tickSwapState = undefined;
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
protected processEvent = undefined;
|
|
15
37
|
|
|
16
38
|
/**
|
|
17
|
-
* Returns a newly created
|
|
39
|
+
* Returns a newly created trusted Lightning network -> Smart chain swap, receiving
|
|
40
|
+
* the specified amount of native token on the destination chain.
|
|
18
41
|
*
|
|
19
|
-
* @param
|
|
20
|
-
* @param amount
|
|
21
|
-
* @param lpOrUrl
|
|
42
|
+
* @param recipient Address of the recipient on the smart chain destination chain
|
|
43
|
+
* @param amount Amount of native token to receive in base units
|
|
44
|
+
* @param lpOrUrl Intermediary (LP) to use for the swap
|
|
22
45
|
*/
|
|
23
|
-
async create(
|
|
46
|
+
async create(recipient: string, amount: bigint, lpOrUrl: Intermediary | string): Promise<LnForGasSwap<T>> {
|
|
24
47
|
if(!this.isInitialized) throw new Error("Not initialized, call init() first!");
|
|
25
48
|
|
|
26
49
|
const lpUrl = typeof(lpOrUrl)==="string" ? lpOrUrl : lpOrUrl.url;
|
|
27
50
|
|
|
28
|
-
const token = this.
|
|
51
|
+
const token = this._chain.getNativeCurrencyAddress();
|
|
29
52
|
|
|
30
53
|
const resp = await TrustedIntermediaryAPI.initTrustedFromBTCLN(this.chainIdentifier, lpUrl, {
|
|
31
|
-
address:
|
|
54
|
+
address: recipient,
|
|
32
55
|
amount,
|
|
33
56
|
token
|
|
34
|
-
}, this.
|
|
57
|
+
}, this._options.getRequestTimeout);
|
|
35
58
|
|
|
36
59
|
const decodedPr = bolt11Decode(resp.pr);
|
|
37
60
|
if(decodedPr.millisatoshis==null) throw new Error("Invalid payment request returned, no msat amount value!");
|
|
@@ -51,7 +74,7 @@ export class LnForGasWrapper<T extends ChainType> extends ISwapWrapper<T, LnForG
|
|
|
51
74
|
const quoteInit: LnForGasSwapInit = {
|
|
52
75
|
pr: resp.pr,
|
|
53
76
|
outputAmount: resp.total,
|
|
54
|
-
recipient
|
|
77
|
+
recipient,
|
|
55
78
|
pricingInfo,
|
|
56
79
|
url: lpUrl,
|
|
57
80
|
expiry: decodedPr.timeExpireDate*1000,
|
|
@@ -65,8 +88,4 @@ export class LnForGasWrapper<T extends ChainType> extends ISwapWrapper<T, LnForG
|
|
|
65
88
|
return quote;
|
|
66
89
|
}
|
|
67
90
|
|
|
68
|
-
public readonly pendingSwapStates = [LnForGasSwapState.PR_CREATED];
|
|
69
|
-
public readonly tickSwapState = undefined;
|
|
70
|
-
protected processEvent = undefined;
|
|
71
|
-
|
|
72
91
|
}
|