@atomiqlabs/sdk 8.1.8 → 8.3.1
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/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 +7 -0
- package/dist/enums/FeeType.js +7 -0
- 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 +4 -5
- package/dist/index.js +3 -4
- package/dist/intermediaries/Intermediary.d.ts +57 -10
- package/dist/intermediaries/Intermediary.js +37 -10
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +55 -22
- package/dist/intermediaries/IntermediaryDiscovery.js +35 -22
- package/dist/prices/RedundantSwapPrice.d.ts +24 -3
- package/dist/prices/RedundantSwapPrice.js +21 -1
- package/dist/prices/SingleSwapPrice.d.ts +9 -6
- package/dist/prices/SingleSwapPrice.js +10 -7
- package/dist/prices/SwapPriceWithChain.d.ts +54 -16
- package/dist/prices/SwapPriceWithChain.js +58 -20
- package/dist/prices/abstract/ISwapPrice.d.ts +94 -45
- package/dist/prices/abstract/ISwapPrice.js +103 -55
- package/dist/prices/providers/BinancePriceProvider.d.ts +7 -0
- package/dist/prices/providers/BinancePriceProvider.js +7 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +6 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.js +6 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +6 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.js +6 -0
- package/dist/prices/providers/CustomPriceProvider.d.ts +11 -0
- package/dist/prices/providers/CustomPriceProvider.js +11 -0
- package/dist/prices/providers/KrakenPriceProvider.d.ts +9 -0
- package/dist/prices/providers/KrakenPriceProvider.js +9 -0
- package/dist/prices/providers/OKXPriceProvider.d.ts +6 -0
- package/dist/prices/providers/OKXPriceProvider.js +6 -0
- 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 +302 -221
- package/dist/swapper/Swapper.js +376 -344
- package/dist/swapper/SwapperFactory.d.ts +41 -17
- package/dist/swapper/SwapperFactory.js +23 -2
- 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 +10 -1
- package/dist/swaps/IAddressSwap.js +2 -1
- package/dist/swaps/IBTCWalletSwap.d.ts +24 -6
- package/dist/swaps/IBTCWalletSwap.js +2 -1
- package/dist/swaps/IClaimableSwap.d.ts +36 -4
- package/dist/swaps/IClaimableSwap.js +2 -1
- package/dist/swaps/IClaimableSwapWrapper.d.ts +11 -1
- package/dist/swaps/IRefundableSwap.d.ts +29 -3
- package/dist/swaps/IRefundableSwap.js +2 -1
- package/dist/swaps/ISwap.d.ts +159 -21
- package/dist/swaps/ISwap.js +90 -33
- package/dist/swaps/ISwapWithGasDrop.d.ts +6 -0
- package/dist/swaps/ISwapWithGasDrop.js +1 -0
- package/dist/swaps/ISwapWrapper.d.ts +157 -48
- package/dist/swaps/ISwapWrapper.js +130 -72
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +49 -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 +94 -29
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +90 -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 +275 -58
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +516 -239
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +76 -25
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +131 -49
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +311 -51
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +542 -193
- 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 +209 -53
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +449 -242
- 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 +197 -56
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +326 -189
- 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 +60 -19
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +74 -31
- 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 +36 -13
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +65 -19
- 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 +328 -92
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +460 -219
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +76 -24
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +244 -124
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +146 -18
- package/dist/swaps/trusted/ln/LnForGasSwap.js +173 -43
- 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 +200 -47
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +230 -78
- 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 +7 -1
- package/dist/types/SwapExecutionAction.d.ts +74 -4
- package/dist/types/SwapWithSigner.d.ts +4 -1
- 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 +2 -1
- package/dist/types/fees/FeeBreakdown.d.ts +2 -1
- package/dist/types/fees/PercentagePPM.d.ts +2 -0
- package/dist/types/fees/PercentagePPM.js +1 -0
- package/dist/types/lnurl/LNURLPay.d.ts +14 -6
- package/dist/types/lnurl/LNURLPay.js +6 -2
- package/dist/types/lnurl/LNURLWithdraw.d.ts +12 -5
- package/dist/types/lnurl/LNURLWithdraw.js +6 -2
- package/dist/types/wallets/LightningInvoiceCreateService.d.ts +20 -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 +3 -1
- package/dist/utils/BitcoinUtils.d.ts +1 -0
- package/dist/utils/BitcoinUtils.js +5 -1
- package/dist/utils/SwapUtils.d.ts +56 -1
- package/dist/utils/SwapUtils.js +53 -1
- package/dist/utils/TokenUtils.d.ts +10 -2
- package/dist/utils/TokenUtils.js +12 -4
- package/package.json +3 -3
- 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 +7 -0
- 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 +6 -5
- package/src/intermediaries/Intermediary.ts +57 -10
- package/src/intermediaries/IntermediaryDiscovery.ts +60 -27
- package/src/prices/RedundantSwapPrice.ts +24 -4
- package/src/prices/SingleSwapPrice.ts +10 -7
- package/src/prices/SwapPriceWithChain.ts +59 -21
- package/src/prices/abstract/ISwapPrice.ts +114 -65
- package/src/prices/providers/BinancePriceProvider.ts +7 -0
- package/src/prices/providers/CoinGeckoPriceProvider.ts +6 -0
- package/src/prices/providers/CoinPaprikaPriceProvider.ts +6 -0
- package/src/prices/providers/CustomPriceProvider.ts +11 -0
- package/src/prices/providers/KrakenPriceProvider.ts +9 -0
- package/src/prices/providers/OKXPriceProvider.ts +6 -0
- 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 +512 -378
- package/src/swapper/SwapperFactory.ts +44 -21
- 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 +11 -1
- package/src/swaps/IBTCWalletSwap.ts +24 -8
- package/src/swaps/IClaimableSwap.ts +39 -4
- package/src/swaps/IClaimableSwapWrapper.ts +11 -2
- package/src/swaps/IRefundableSwap.ts +32 -3
- package/src/swaps/ISwap.ts +221 -82
- package/src/swaps/ISwapWithGasDrop.ts +6 -0
- package/src/swaps/ISwapWrapper.ts +212 -94
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +62 -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 +120 -51
- package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +24 -11
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +559 -256
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +155 -61
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +590 -226
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +177 -74
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +470 -243
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +141 -59
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +352 -193
- package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +48 -23
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +86 -39
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +110 -110
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +88 -33
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +101 -31
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +534 -263
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +289 -148
- package/src/swaps/trusted/ln/LnForGasSwap.ts +184 -45
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +34 -15
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +260 -86
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +41 -19
- package/src/types/AmountData.ts +2 -1
- package/src/types/CustomPriceFunction.ts +7 -1
- package/src/types/SwapExecutionAction.ts +84 -5
- package/src/types/SwapWithSigner.ts +7 -3
- package/src/types/Token.ts +12 -5
- package/src/types/TokenAmount.ts +3 -0
- package/src/types/fees/Fee.ts +2 -1
- package/src/types/fees/FeeBreakdown.ts +2 -1
- package/src/types/fees/PercentagePPM.ts +2 -0
- package/src/types/lnurl/LNURLPay.ts +14 -6
- package/src/types/lnurl/LNURLWithdraw.ts +12 -5
- package/src/types/wallets/LightningInvoiceCreateService.ts +26 -0
- package/src/types/wallets/MinimalBitcoinWalletInterface.ts +3 -1
- package/src/types/wallets/MinimalLightningNetworkWalletInterface.ts +3 -1
- package/src/utils/BitcoinUtils.ts +5 -0
- package/src/utils/SwapUtils.ts +61 -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
|
@@ -3,7 +3,8 @@ import {ISwap} from "./ISwap";
|
|
|
3
3
|
import {ISwapWrapper, SwapTypeDefinition} from "./ISwapWrapper";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Type guard to check if an object is an IRefundableSwap
|
|
6
|
+
* Type guard to check if an object is an {@link IRefundableSwap}
|
|
7
|
+
*
|
|
7
8
|
* @category Swaps
|
|
8
9
|
*/
|
|
9
10
|
export function isIRefundableSwap(obj: any): obj is IRefundableSwap {
|
|
@@ -13,7 +14,8 @@ export function isIRefundableSwap(obj: any): obj is IRefundableSwap {
|
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
|
-
* Interface for swaps that can be refunded
|
|
17
|
+
* Interface for swaps that can be refunded in case of failure
|
|
18
|
+
*
|
|
17
19
|
* @category Swaps
|
|
18
20
|
*/
|
|
19
21
|
export interface IRefundableSwap<
|
|
@@ -22,8 +24,35 @@ export interface IRefundableSwap<
|
|
|
22
24
|
S extends number = number
|
|
23
25
|
> extends ISwap<T, D, S> {
|
|
24
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Checks whether a swap is currently refundable
|
|
29
|
+
*/
|
|
25
30
|
isRefundable(): boolean;
|
|
26
|
-
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns transactions for refunding the swap if the swap is in refundable state, you can check so with
|
|
34
|
+
* {@link isRefundable}. After sending the transaction manually be sure to call the {@link waitTillRefunded}
|
|
35
|
+
* function to wait till the refund transaction is observed, processed by the SDK and state of the swap
|
|
36
|
+
* properly updated.
|
|
37
|
+
*
|
|
38
|
+
* @param _signer Address of the signer to create the refund transactions for
|
|
39
|
+
*/
|
|
40
|
+
txsRefund(_signer?: string): Promise<T["TX"][]>;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Refunds the swap if the swap is in refundable state, you can check so with {@link isRefundable}
|
|
44
|
+
*
|
|
45
|
+
* @param _signer Signer to sign the transactions with, must be the same as used in the initialization
|
|
46
|
+
* @param abortSignal Abort signal
|
|
47
|
+
*/
|
|
27
48
|
refund(_signer?: T["Signer"] | T["NativeSigner"], abortSignal?: AbortSignal): Promise<string>;
|
|
28
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Waits till a swap is refunded, should be called after sending the refund transactions manually to
|
|
52
|
+
* wait till the SDK processes the refund and updates the swap state accordingly
|
|
53
|
+
*
|
|
54
|
+
* @param abortSignal AbortSignal
|
|
55
|
+
*/
|
|
56
|
+
waitTillRefunded(abortSignal?: AbortSignal): Promise<void>;
|
|
57
|
+
|
|
29
58
|
}
|
package/src/swaps/ISwap.ts
CHANGED
|
@@ -15,6 +15,7 @@ import {isPriceInfoType, PriceInfoType} from "../types/PriceInfoType";
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Initialization data for creating a swap
|
|
18
|
+
*
|
|
18
19
|
* @category Swaps
|
|
19
20
|
*/
|
|
20
21
|
export type ISwapInit = {
|
|
@@ -28,6 +29,7 @@ export type ISwapInit = {
|
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Type guard to check if an object is an ISwapInit
|
|
32
|
+
*
|
|
31
33
|
* @category Swaps
|
|
32
34
|
*/
|
|
33
35
|
export function isISwapInit(obj: any): obj is ISwapInit {
|
|
@@ -43,6 +45,7 @@ export function isISwapInit(obj: any): obj is ISwapInit {
|
|
|
43
45
|
|
|
44
46
|
/**
|
|
45
47
|
* Base abstract class for all swap types
|
|
48
|
+
*
|
|
46
49
|
* @category Swaps
|
|
47
50
|
*/
|
|
48
51
|
export abstract class ISwap<
|
|
@@ -50,38 +53,95 @@ export abstract class ISwap<
|
|
|
50
53
|
D extends SwapTypeDefinition<T, ISwapWrapper<T, D>, ISwap<T, D, S>> = SwapTypeDefinition<T, ISwapWrapper<T, any>, ISwap<T, any, any>>,
|
|
51
54
|
S extends number = number
|
|
52
55
|
> {
|
|
56
|
+
/**
|
|
57
|
+
* Swap type
|
|
58
|
+
*/
|
|
53
59
|
protected readonly abstract TYPE: SwapType;
|
|
60
|
+
/**
|
|
61
|
+
* Swap logger
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
54
64
|
protected readonly abstract logger: LoggerType;
|
|
55
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Current newest defined version of the swap
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
56
69
|
protected readonly currentVersion: number = 1;
|
|
70
|
+
/**
|
|
71
|
+
* Wrapper instance holding this swap
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
57
74
|
protected readonly wrapper: D["Wrapper"];
|
|
58
75
|
|
|
59
|
-
readonly url?: string;
|
|
60
|
-
|
|
61
|
-
readonly chainIdentifier: T["ChainId"];
|
|
62
|
-
readonly exactIn: boolean;
|
|
63
|
-
createdAt: number;
|
|
64
76
|
|
|
77
|
+
/**
|
|
78
|
+
* The current version of the swap
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
65
81
|
protected version: number;
|
|
82
|
+
/**
|
|
83
|
+
* Whether a swap was initialized, a swap is considered initialize on first interaction with it, i.e.
|
|
84
|
+
* calling commit() on a Smart chain -> Bitcoin swaps, calling waitForPayment() or similar on the other
|
|
85
|
+
* direction. Not initiated swaps are not saved to the persistent storage by default (see
|
|
86
|
+
* {@link SwapperOptions.saveUninitializedSwaps})
|
|
87
|
+
* @internal
|
|
88
|
+
*/
|
|
66
89
|
protected initiated: boolean = false;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Expiration of the swap quote
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
protected expiry: number;
|
|
95
|
+
/**
|
|
96
|
+
* Pricing information of the swap
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
protected pricingInfo?: PriceInfoType;
|
|
100
|
+
/**
|
|
101
|
+
* Swap fee in the non-bitcoin token
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
72
104
|
protected swapFee: bigint;
|
|
105
|
+
/**
|
|
106
|
+
* Swap fee in bitcoin satoshis
|
|
107
|
+
* @internal
|
|
108
|
+
*/
|
|
73
109
|
protected swapFeeBtc: bigint;
|
|
74
110
|
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Swap state
|
|
114
|
+
* @internal
|
|
115
|
+
*/
|
|
116
|
+
_state: S = 0 as S;
|
|
75
117
|
/**
|
|
76
118
|
* Random nonce to differentiate the swap from others with the same identifier hash (i.e. when quoting the same swap
|
|
77
119
|
* from multiple LPs)
|
|
120
|
+
* @internal
|
|
78
121
|
*/
|
|
79
|
-
|
|
122
|
+
_randomNonce: string;
|
|
123
|
+
|
|
80
124
|
|
|
81
125
|
/**
|
|
82
|
-
* Event emitter emitting "swapState" event when swap's state changes
|
|
126
|
+
* Event emitter emitting `"swapState"` event when swap's state changes
|
|
83
127
|
*/
|
|
84
|
-
events: EventEmitter<{swapState: [D["Swap"]]}> = new EventEmitter();
|
|
128
|
+
readonly events: EventEmitter<{swapState: [D["Swap"]]}> = new EventEmitter();
|
|
129
|
+
/**
|
|
130
|
+
* URL of the intermediary (LP) used for this swap, already has the swap service specific path appended
|
|
131
|
+
*/
|
|
132
|
+
readonly url?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Smart chain identifier string corresponding to this swap
|
|
135
|
+
*/
|
|
136
|
+
readonly chainIdentifier: T["ChainId"];
|
|
137
|
+
/**
|
|
138
|
+
* Whether a swap is an exact input swap
|
|
139
|
+
*/
|
|
140
|
+
readonly exactIn: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* A UNIX milliseconds timestamps of when this swap was created
|
|
143
|
+
*/
|
|
144
|
+
createdAt: number;
|
|
85
145
|
|
|
86
146
|
protected constructor(wrapper: D["Wrapper"], obj: any);
|
|
87
147
|
protected constructor(wrapper: D["Wrapper"], swapInit: ISwapInit);
|
|
@@ -100,12 +160,12 @@ export abstract class ISwap<
|
|
|
100
160
|
this.exactIn = swapInitOrObj.exactIn;
|
|
101
161
|
this.version = this.currentVersion;
|
|
102
162
|
this.createdAt = Date.now();
|
|
103
|
-
this.
|
|
163
|
+
this._randomNonce = randomBytes(16).toString("hex");
|
|
104
164
|
} else {
|
|
105
165
|
this.expiry = swapInitOrObj.expiry;
|
|
106
166
|
this.url = swapInitOrObj.url;
|
|
107
167
|
|
|
108
|
-
this.
|
|
168
|
+
this._state = swapInitOrObj.state;
|
|
109
169
|
|
|
110
170
|
if(
|
|
111
171
|
swapInitOrObj._isValid!=null && swapInitOrObj._differencePPM!=null && swapInitOrObj._satsBaseFee!=null &&
|
|
@@ -130,7 +190,7 @@ export abstract class ISwap<
|
|
|
130
190
|
this.exactIn = swapInitOrObj.exactIn;
|
|
131
191
|
this.createdAt = swapInitOrObj.createdAt ?? swapInitOrObj.expiry;
|
|
132
192
|
|
|
133
|
-
this.
|
|
193
|
+
this._randomNonce = swapInitOrObj.randomNonce;
|
|
134
194
|
}
|
|
135
195
|
if(this.version!==this.currentVersion) {
|
|
136
196
|
this.upgradeVersion();
|
|
@@ -138,6 +198,11 @@ export abstract class ISwap<
|
|
|
138
198
|
if(this.initiated==null) this.initiated = true;
|
|
139
199
|
}
|
|
140
200
|
|
|
201
|
+
/**
|
|
202
|
+
* Called when swap is deserialized to potentially update the version of the data for the swap
|
|
203
|
+
*
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
141
206
|
protected abstract upgradeVersion(): void;
|
|
142
207
|
|
|
143
208
|
/**
|
|
@@ -145,14 +210,14 @@ export abstract class ISwap<
|
|
|
145
210
|
*
|
|
146
211
|
* @param targetState The state to wait for
|
|
147
212
|
* @param type Whether to wait for the state exactly or also to a state with a higher number
|
|
148
|
-
* @param abortSignal
|
|
149
|
-
* @
|
|
213
|
+
* @param abortSignal Abort signal
|
|
214
|
+
* @internal
|
|
150
215
|
*/
|
|
151
216
|
protected waitTillState(targetState: S, type: "eq" | "gte" | "neq" = "eq", abortSignal?: AbortSignal): Promise<void> {
|
|
152
217
|
return new Promise((resolve, reject) => {
|
|
153
218
|
let listener: (swap: D["Swap"]) => void;
|
|
154
219
|
listener = (swap) => {
|
|
155
|
-
if(type==="eq" ? swap.
|
|
220
|
+
if(type==="eq" ? swap._state===targetState : type==="gte" ? swap._state>=targetState : swap._state!=targetState) {
|
|
156
221
|
resolve();
|
|
157
222
|
this.events.removeListener("swapState", listener);
|
|
158
223
|
}
|
|
@@ -165,11 +230,21 @@ export abstract class ISwap<
|
|
|
165
230
|
});
|
|
166
231
|
}
|
|
167
232
|
|
|
168
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Returns a list of steps or transactions required to finish and settle the swap
|
|
235
|
+
*
|
|
236
|
+
* @param options Additional options for executing the swap
|
|
237
|
+
*/
|
|
238
|
+
public abstract txsExecute(options?: any): Promise<SwapExecutionAction<T>[]>;
|
|
169
239
|
|
|
170
240
|
//////////////////////////////
|
|
171
241
|
//// Pricing
|
|
172
242
|
|
|
243
|
+
/**
|
|
244
|
+
* This attempts to populate missing fields in the pricing info based on the swap amounts
|
|
245
|
+
*
|
|
246
|
+
* @internal
|
|
247
|
+
*/
|
|
173
248
|
protected tryRecomputeSwapPrice(): void {
|
|
174
249
|
if(this.pricingInfo==null) return;
|
|
175
250
|
if(this.pricingInfo.swapPriceUSatPerToken==null) {
|
|
@@ -178,7 +253,7 @@ export abstract class ISwap<
|
|
|
178
253
|
const output = this.getOutput();
|
|
179
254
|
if(input.isUnknown || output.isUnknown) return;
|
|
180
255
|
if(isSCToken(input.token) && this.getDirection()===SwapDirection.TO_BTC) {
|
|
181
|
-
this.pricingInfo = this.wrapper.
|
|
256
|
+
this.pricingInfo = this.wrapper._prices.recomputePriceInfoSend(
|
|
182
257
|
this.chainIdentifier,
|
|
183
258
|
output.rawAmount!,
|
|
184
259
|
this.pricingInfo.satsBaseFee,
|
|
@@ -188,7 +263,7 @@ export abstract class ISwap<
|
|
|
188
263
|
);
|
|
189
264
|
this.pricingInfo.realPriceUsdPerBitcoin = priceUsdPerBtc;
|
|
190
265
|
} else if(isSCToken(output.token) && this.getDirection()===SwapDirection.FROM_BTC) {
|
|
191
|
-
this.pricingInfo = this.wrapper.
|
|
266
|
+
this.pricingInfo = this.wrapper._prices.recomputePriceInfoReceive(
|
|
192
267
|
this.chainIdentifier,
|
|
193
268
|
input.rawAmount!,
|
|
194
269
|
this.pricingInfo.satsBaseFee,
|
|
@@ -202,9 +277,9 @@ export abstract class ISwap<
|
|
|
202
277
|
}
|
|
203
278
|
|
|
204
279
|
/**
|
|
205
|
-
* Re-fetches & revalidates the price data
|
|
280
|
+
* Re-fetches & revalidates the price data based on the current market prices
|
|
206
281
|
*/
|
|
207
|
-
async refreshPriceData(): Promise<void> {
|
|
282
|
+
public async refreshPriceData(): Promise<void> {
|
|
208
283
|
if(this.pricingInfo==null) return;
|
|
209
284
|
const priceUsdPerBtc = this.pricingInfo.realPriceUsdPerBitcoin;
|
|
210
285
|
const input = this.getInput();
|
|
@@ -212,7 +287,7 @@ export abstract class ISwap<
|
|
|
212
287
|
if(input.isUnknown || output.isUnknown) return;
|
|
213
288
|
|
|
214
289
|
if(isSCToken(input.token) && this.getDirection()===SwapDirection.TO_BTC) {
|
|
215
|
-
this.pricingInfo = await this.wrapper.
|
|
290
|
+
this.pricingInfo = await this.wrapper._prices.isValidAmountSend(
|
|
216
291
|
this.chainIdentifier,
|
|
217
292
|
output.rawAmount!,
|
|
218
293
|
this.pricingInfo.satsBaseFee,
|
|
@@ -222,7 +297,7 @@ export abstract class ISwap<
|
|
|
222
297
|
);
|
|
223
298
|
this.pricingInfo.realPriceUsdPerBitcoin = priceUsdPerBtc;
|
|
224
299
|
} else if(isSCToken(output.token) && this.getDirection()===SwapDirection.FROM_BTC) {
|
|
225
|
-
this.pricingInfo = await this.wrapper.
|
|
300
|
+
this.pricingInfo = await this.wrapper._prices.isValidAmountReceive(
|
|
226
301
|
this.chainIdentifier,
|
|
227
302
|
input.rawAmount!,
|
|
228
303
|
this.pricingInfo.satsBaseFee,
|
|
@@ -237,7 +312,7 @@ export abstract class ISwap<
|
|
|
237
312
|
/**
|
|
238
313
|
* Checks if the pricing for the swap is valid, according to max allowed price difference set in the ISwapPrice
|
|
239
314
|
*/
|
|
240
|
-
hasValidPrice(): boolean {
|
|
315
|
+
public hasValidPrice(): boolean {
|
|
241
316
|
if(this.pricingInfo==null) throw new Error("Pricing info not found, cannot check price validity!");
|
|
242
317
|
return this.pricingInfo.isValid;
|
|
243
318
|
}
|
|
@@ -245,7 +320,7 @@ export abstract class ISwap<
|
|
|
245
320
|
/**
|
|
246
321
|
* Returns pricing info about the swap
|
|
247
322
|
*/
|
|
248
|
-
getPriceInfo(): {
|
|
323
|
+
public getPriceInfo(): {
|
|
249
324
|
marketPrice?: number,
|
|
250
325
|
swapPrice: number,
|
|
251
326
|
difference: PercentagePPM
|
|
@@ -273,102 +348,142 @@ export abstract class ISwap<
|
|
|
273
348
|
//////////////////////////////
|
|
274
349
|
//// Getters & utils
|
|
275
350
|
|
|
276
|
-
abstract _getEscrowHash(): string | null;
|
|
277
|
-
|
|
278
351
|
/**
|
|
352
|
+
* Asserts a given signer is the initiator of this swap
|
|
353
|
+
*
|
|
279
354
|
* @param signer Signer to check with this swap's initiator
|
|
280
355
|
* @throws {Error} When signer's address doesn't match with the swap's initiator one
|
|
356
|
+
* @internal
|
|
281
357
|
*/
|
|
282
358
|
protected checkSigner(signer: T["Signer"] | string): void {
|
|
283
359
|
if((typeof(signer)==="string" ? signer : signer.getAddress())!==this._getInitiator()) throw new Error("Invalid signer provided!");
|
|
284
360
|
}
|
|
285
361
|
|
|
362
|
+
/**
|
|
363
|
+
* Returns an escrow hash of the swap
|
|
364
|
+
*
|
|
365
|
+
* @internal
|
|
366
|
+
*/
|
|
367
|
+
abstract _getEscrowHash(): string | null;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Checks if the swap's quote is expired for good (i.e. the swap strictly cannot be initiated anymore)
|
|
371
|
+
* @internal
|
|
372
|
+
*/
|
|
373
|
+
abstract _verifyQuoteDefinitelyExpired(): Promise<boolean>;
|
|
374
|
+
|
|
286
375
|
/**
|
|
287
376
|
* Checks if the swap's quote is still valid
|
|
377
|
+
* @internal
|
|
288
378
|
*/
|
|
289
|
-
abstract
|
|
379
|
+
abstract _verifyQuoteValid(): Promise<boolean>;
|
|
290
380
|
|
|
291
|
-
|
|
292
|
-
|
|
381
|
+
/**
|
|
382
|
+
* Returns the intiator address of the swap - address that created this swap
|
|
383
|
+
* @internal
|
|
384
|
+
*/
|
|
385
|
+
abstract _getInitiator(): string;
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Sets this swap as initiated
|
|
389
|
+
* @internal
|
|
390
|
+
*/
|
|
391
|
+
_setInitiated(): void {
|
|
392
|
+
this.initiated = true;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Returns source address of the swap
|
|
397
|
+
*/
|
|
398
|
+
public abstract getInputAddress(): string | null;
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Returns destination address of the swap
|
|
402
|
+
*/
|
|
403
|
+
public abstract getOutputAddress(): string | null;
|
|
293
404
|
|
|
294
|
-
|
|
295
|
-
|
|
405
|
+
/**
|
|
406
|
+
* Returns swap input transaction ID on the source chain
|
|
407
|
+
*/
|
|
408
|
+
public abstract getInputTxId(): string | null;
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Returns swap output transaction ID on the destination chain
|
|
412
|
+
*/
|
|
413
|
+
public abstract getOutputTxId(): string | null;
|
|
296
414
|
|
|
297
415
|
/**
|
|
298
|
-
* Returns the ID of the swap, as used in the storage
|
|
416
|
+
* Returns the ID of the swap, as used in the storage
|
|
299
417
|
*/
|
|
300
|
-
abstract getId(): string;
|
|
418
|
+
public abstract getId(): string;
|
|
301
419
|
|
|
302
420
|
/**
|
|
303
421
|
* Checks whether there is some action required from the user for this swap - can mean either refundable or claimable
|
|
304
422
|
*/
|
|
305
|
-
abstract requiresAction(): boolean;
|
|
423
|
+
public abstract requiresAction(): boolean;
|
|
306
424
|
|
|
307
425
|
/**
|
|
308
426
|
* Returns whether the swap is finished and in its terminal state (this can mean successful, refunded or failed)
|
|
309
427
|
*/
|
|
310
|
-
abstract isFinished(): boolean;
|
|
428
|
+
public abstract isFinished(): boolean;
|
|
311
429
|
|
|
312
430
|
/**
|
|
313
431
|
* Checks whether the swap's quote has definitely expired and cannot be committed anymore, we can remove such swap
|
|
314
432
|
*/
|
|
315
|
-
abstract isQuoteExpired(): boolean;
|
|
433
|
+
public abstract isQuoteExpired(): boolean;
|
|
316
434
|
|
|
317
435
|
/**
|
|
318
436
|
* Checks whether the swap's quote is soft expired (this means there is not enough time buffer for it to commit,
|
|
319
437
|
* but it still can happen)
|
|
320
438
|
*/
|
|
321
|
-
abstract isQuoteSoftExpired(): boolean;
|
|
439
|
+
public abstract isQuoteSoftExpired(): boolean;
|
|
322
440
|
|
|
323
441
|
/**
|
|
324
442
|
* Returns whether the swap finished successful
|
|
325
443
|
*/
|
|
326
|
-
abstract isSuccessful(): boolean;
|
|
444
|
+
public abstract isSuccessful(): boolean;
|
|
327
445
|
|
|
328
446
|
/**
|
|
329
447
|
* Returns whether the swap failed (e.g. was refunded)
|
|
330
448
|
*/
|
|
331
|
-
abstract isFailed(): boolean;
|
|
449
|
+
public abstract isFailed(): boolean;
|
|
332
450
|
|
|
333
451
|
/**
|
|
334
|
-
*
|
|
452
|
+
* Whether a swap was initialized, a swap is considered initialized on first interaction with it, i.e.
|
|
453
|
+
* calling commit() on a Smart chain -> Bitcoin swaps, calling waitForPayment() or similar on the other
|
|
454
|
+
* direction. Not initiated swaps are not saved to the persistent storage by default (see
|
|
455
|
+
* {@link SwapperOptions.saveUninitializedSwaps})
|
|
335
456
|
*/
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
isInitiated(): boolean {
|
|
457
|
+
public isInitiated(): boolean {
|
|
339
458
|
return this.initiated;
|
|
340
459
|
}
|
|
341
460
|
|
|
342
|
-
_setInitiated(): void {
|
|
343
|
-
this.initiated = true;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
461
|
/**
|
|
347
462
|
* Returns quote expiry in UNIX millis
|
|
348
463
|
*/
|
|
349
|
-
getQuoteExpiry(): number {
|
|
464
|
+
public getQuoteExpiry(): number {
|
|
350
465
|
return this.expiry;
|
|
351
466
|
}
|
|
352
467
|
|
|
353
468
|
/**
|
|
354
469
|
* Returns the type of the swap
|
|
355
470
|
*/
|
|
356
|
-
getType(): SwapType {
|
|
471
|
+
public getType(): SwapType {
|
|
357
472
|
return this.TYPE;
|
|
358
473
|
}
|
|
359
474
|
|
|
360
475
|
/**
|
|
361
476
|
* Returns the direction of the swap
|
|
362
477
|
*/
|
|
363
|
-
getDirection(): SwapDirection {
|
|
478
|
+
public getDirection(): SwapDirection {
|
|
364
479
|
return this.TYPE===SwapType.TO_BTC || this.TYPE===SwapType.TO_BTCLN ? SwapDirection.TO_BTC : SwapDirection.FROM_BTC;
|
|
365
480
|
}
|
|
366
481
|
|
|
367
482
|
/**
|
|
368
483
|
* Returns the current state of the swap
|
|
369
484
|
*/
|
|
370
|
-
getState(): S {
|
|
371
|
-
return this.
|
|
485
|
+
public getState(): S {
|
|
486
|
+
return this._state;
|
|
372
487
|
}
|
|
373
488
|
|
|
374
489
|
//////////////////////////////
|
|
@@ -377,44 +492,73 @@ export abstract class ISwap<
|
|
|
377
492
|
/**
|
|
378
493
|
* Returns output amount of the swap, user receives this much
|
|
379
494
|
*/
|
|
380
|
-
abstract getOutput(): TokenAmount;
|
|
495
|
+
public abstract getOutput(): TokenAmount;
|
|
381
496
|
|
|
382
497
|
/**
|
|
383
498
|
* Returns the output token of the swap
|
|
384
499
|
*/
|
|
385
|
-
abstract getOutputToken(): Token<T["ChainId"]>;
|
|
500
|
+
public abstract getOutputToken(): Token<T["ChainId"]>;
|
|
386
501
|
|
|
387
502
|
/**
|
|
388
503
|
* Returns input amount of the swap, user needs to pay this much
|
|
389
504
|
*/
|
|
390
|
-
abstract getInput(): TokenAmount;
|
|
505
|
+
public abstract getInput(): TokenAmount;
|
|
391
506
|
|
|
392
507
|
/**
|
|
393
508
|
* Returns the input token of the swap
|
|
394
509
|
*/
|
|
395
|
-
abstract getInputToken(): Token<T["ChainId"]>;
|
|
510
|
+
public abstract getInputToken(): Token<T["ChainId"]>;
|
|
396
511
|
|
|
397
512
|
/**
|
|
398
|
-
* Returns input amount
|
|
513
|
+
* Returns input amount of the swap without the fees (swap fee, network fee)
|
|
399
514
|
*/
|
|
400
|
-
abstract getInputWithoutFee(): TokenAmount;
|
|
515
|
+
public abstract getInputWithoutFee(): TokenAmount;
|
|
401
516
|
|
|
402
517
|
/**
|
|
403
518
|
* Returns total fee for the swap, the fee is represented in source currency & destination currency, but is
|
|
404
519
|
* paid only once
|
|
405
520
|
*/
|
|
406
|
-
abstract getFee(): Fee;
|
|
521
|
+
public abstract getFee(): Fee;
|
|
407
522
|
|
|
408
523
|
/**
|
|
409
524
|
* Returns the breakdown of all the fees paid
|
|
410
525
|
*/
|
|
411
|
-
abstract getFeeBreakdown(): FeeBreakdown<T["ChainId"]>;
|
|
526
|
+
public abstract getFeeBreakdown(): FeeBreakdown<T["ChainId"]>;
|
|
412
527
|
|
|
413
528
|
|
|
414
529
|
//////////////////////////////
|
|
415
530
|
//// Storage
|
|
416
531
|
|
|
417
|
-
|
|
532
|
+
/**
|
|
533
|
+
* Saves the swap data to the underlying storage, or removes it if it is in a quote expired state
|
|
534
|
+
*
|
|
535
|
+
* @internal
|
|
536
|
+
*/
|
|
537
|
+
_save(): Promise<void> {
|
|
538
|
+
if(this.isQuoteExpired()) {
|
|
539
|
+
return this.wrapper._removeSwapData(this);
|
|
540
|
+
} else {
|
|
541
|
+
return this.wrapper._saveSwapData(this);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Saves the swap data and also emits a swap state change
|
|
547
|
+
*
|
|
548
|
+
* @param state Optional state to set before the swap is saved an event emitted
|
|
549
|
+
*
|
|
550
|
+
* @internal
|
|
551
|
+
*/
|
|
552
|
+
async _saveAndEmit(state?: S): Promise<void> {
|
|
553
|
+
if(state!=null) this._state = state;
|
|
554
|
+
await this._save();
|
|
555
|
+
this._emitEvent();
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Serializes the swap to a JSON stringifiable representation (i.e. no bigints, buffers etc.)
|
|
560
|
+
*/
|
|
561
|
+
public serialize(): any {
|
|
418
562
|
if(this.pricingInfo==null) return {};
|
|
419
563
|
return {
|
|
420
564
|
id: this.getId(),
|
|
@@ -429,7 +573,7 @@ export abstract class ISwap<
|
|
|
429
573
|
_realPriceUSatPerToken: this.pricingInfo.realPriceUSatPerToken==null ? null :this.pricingInfo.realPriceUSatPerToken.toString(10),
|
|
430
574
|
_realPriceUsdPerBitcoin: this.pricingInfo.realPriceUsdPerBitcoin,
|
|
431
575
|
_swapPriceUSatPerToken: this.pricingInfo.swapPriceUSatPerToken==null ? null :this.pricingInfo.swapPriceUSatPerToken.toString(10),
|
|
432
|
-
state: this.
|
|
576
|
+
state: this._state,
|
|
433
577
|
url: this.url,
|
|
434
578
|
swapFee: this.swapFee==null ? null : this.swapFee.toString(10),
|
|
435
579
|
swapFeeBtc: this.swapFeeBtc==null ? null : this.swapFeeBtc.toString(10),
|
|
@@ -438,28 +582,19 @@ export abstract class ISwap<
|
|
|
438
582
|
initiated: this.initiated,
|
|
439
583
|
exactIn: this.exactIn,
|
|
440
584
|
createdAt: this.createdAt,
|
|
441
|
-
randomNonce: this.
|
|
585
|
+
randomNonce: this._randomNonce
|
|
442
586
|
}
|
|
443
587
|
}
|
|
444
588
|
|
|
445
|
-
_save(): Promise<void> {
|
|
446
|
-
if(this.isQuoteExpired()) {
|
|
447
|
-
return this.wrapper.removeSwapData(this);
|
|
448
|
-
} else {
|
|
449
|
-
return this.wrapper.saveSwapData(this);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
async _saveAndEmit(state?: S): Promise<void> {
|
|
454
|
-
if(state!=null) this.state = state;
|
|
455
|
-
await this._save();
|
|
456
|
-
this._emitEvent();
|
|
457
|
-
}
|
|
458
|
-
|
|
459
589
|
|
|
460
590
|
//////////////////////////////
|
|
461
591
|
//// Events
|
|
462
592
|
|
|
593
|
+
/**
|
|
594
|
+
* Emits a `swapState` event with the current swap
|
|
595
|
+
*
|
|
596
|
+
* @internal
|
|
597
|
+
*/
|
|
463
598
|
_emitEvent() {
|
|
464
599
|
this.wrapper.events.emit("swapState", this);
|
|
465
600
|
this.events.emit("swapState", this);
|
|
@@ -475,6 +610,8 @@ export abstract class ISwap<
|
|
|
475
610
|
* @param save whether to save the new swap state or not
|
|
476
611
|
*
|
|
477
612
|
* @returns {boolean} true if the swap changed, false if the swap hasn't changed
|
|
613
|
+
*
|
|
614
|
+
* @internal
|
|
478
615
|
*/
|
|
479
616
|
abstract _sync(save?: boolean): Promise<boolean>;
|
|
480
617
|
|
|
@@ -484,6 +621,8 @@ export abstract class ISwap<
|
|
|
484
621
|
* @param save whether to save the new swap state or not
|
|
485
622
|
*
|
|
486
623
|
* @returns {boolean} true if the swap changed, false if the swap hasn't changed
|
|
624
|
+
*
|
|
625
|
+
* @internal
|
|
487
626
|
*/
|
|
488
627
|
abstract _tick(save?: boolean): Promise<boolean>;
|
|
489
628
|
|
|
@@ -4,6 +4,7 @@ import {SCToken} from "../types/Token";
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Type guard to check if a swap has gas drop functionality
|
|
7
|
+
*
|
|
7
8
|
* @category Swaps
|
|
8
9
|
*/
|
|
9
10
|
export function isSwapWithGasDrop(swap: any): swap is ISwapWithGasDrop<any> {
|
|
@@ -12,8 +13,13 @@ export function isSwapWithGasDrop(swap: any): swap is ISwapWithGasDrop<any> {
|
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Interface for swaps with gas drop functionality
|
|
16
|
+
*
|
|
15
17
|
* @category Swaps
|
|
16
18
|
*/
|
|
17
19
|
export interface ISwapWithGasDrop<T extends ChainType> {
|
|
20
|
+
/**
|
|
21
|
+
* Returns the output of the "gas drop", additional native token received by the user on
|
|
22
|
+
* the destination chain
|
|
23
|
+
*/
|
|
18
24
|
getGasDropOutput(): TokenAmount<T["ChainId"], SCToken<T["ChainId"]>>;
|
|
19
25
|
}
|