@atomiqlabs/sdk 8.6.6 → 8.6.7
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/SmartChainAssets.d.ts +181 -181
- package/dist/SmartChainAssets.js +181 -181
- package/dist/bitcoin/coinselect2/accumulative.d.ts +6 -6
- package/dist/bitcoin/coinselect2/accumulative.js +52 -51
- package/dist/bitcoin/coinselect2/blackjack.d.ts +6 -6
- package/dist/bitcoin/coinselect2/blackjack.js +38 -37
- package/dist/bitcoin/coinselect2/index.d.ts +19 -17
- package/dist/bitcoin/coinselect2/index.js +69 -69
- package/dist/bitcoin/coinselect2/utils.d.ts +77 -75
- package/dist/bitcoin/coinselect2/utils.js +123 -123
- package/dist/bitcoin/wallet/BitcoinWallet.d.ts +130 -128
- package/dist/bitcoin/wallet/BitcoinWallet.js +322 -322
- package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +78 -78
- package/dist/bitcoin/wallet/IBitcoinWallet.js +21 -20
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +101 -99
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +176 -176
- package/dist/enums/FeeType.d.ts +15 -15
- package/dist/enums/FeeType.js +19 -19
- package/dist/enums/SwapAmountType.d.ts +15 -15
- package/dist/enums/SwapAmountType.js +19 -19
- package/dist/enums/SwapDirection.d.ts +15 -15
- package/dist/enums/SwapDirection.js +19 -19
- package/dist/enums/SwapSide.d.ts +15 -15
- package/dist/enums/SwapSide.js +19 -19
- package/dist/enums/SwapType.d.ts +75 -75
- package/dist/enums/SwapType.js +79 -79
- package/dist/errors/IntermediaryError.d.ts +13 -13
- package/dist/errors/IntermediaryError.js +27 -27
- package/dist/errors/RequestError.d.ts +32 -32
- package/dist/errors/RequestError.js +54 -54
- package/dist/errors/UserError.d.ts +8 -8
- package/dist/errors/UserError.js +16 -16
- package/dist/events/UnifiedSwapEventListener.d.ts +23 -23
- package/dist/events/UnifiedSwapEventListener.js +130 -130
- package/dist/http/HttpUtils.d.ts +27 -27
- package/dist/http/HttpUtils.js +91 -90
- package/dist/http/paramcoders/IParamReader.d.ts +8 -8
- package/dist/http/paramcoders/IParamReader.js +2 -2
- package/dist/http/paramcoders/ParamDecoder.d.ts +44 -42
- package/dist/http/paramcoders/ParamDecoder.js +137 -137
- package/dist/http/paramcoders/ParamEncoder.d.ts +20 -18
- package/dist/http/paramcoders/ParamEncoder.js +36 -36
- package/dist/http/paramcoders/SchemaVerifier.d.ts +26 -26
- package/dist/http/paramcoders/SchemaVerifier.js +145 -145
- package/dist/http/paramcoders/client/ResponseParamDecoder.d.ts +11 -11
- package/dist/http/paramcoders/client/ResponseParamDecoder.js +57 -57
- package/dist/http/paramcoders/client/StreamParamEncoder.d.ts +13 -11
- package/dist/http/paramcoders/client/StreamParamEncoder.js +26 -26
- package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +16 -16
- package/dist/http/paramcoders/client/StreamingFetchPromise.js +174 -173
- package/dist/index.d.ts +85 -85
- package/dist/index.js +158 -158
- package/dist/intermediaries/Intermediary.d.ts +157 -157
- package/dist/intermediaries/Intermediary.js +142 -142
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +199 -198
- package/dist/intermediaries/IntermediaryDiscovery.js +406 -406
- package/dist/intermediaries/apis/IntermediaryAPI.d.ts +439 -437
- package/dist/intermediaries/apis/IntermediaryAPI.js +603 -603
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.d.ts +155 -155
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.js +137 -137
- package/dist/lnurl/LNURL.d.ts +102 -102
- package/dist/lnurl/LNURL.js +321 -321
- package/dist/prices/RedundantSwapPrice.d.ts +110 -110
- package/dist/prices/RedundantSwapPrice.js +222 -222
- package/dist/prices/SingleSwapPrice.d.ts +34 -34
- package/dist/prices/SingleSwapPrice.js +44 -44
- package/dist/prices/SwapPriceWithChain.d.ts +107 -107
- package/dist/prices/SwapPriceWithChain.js +128 -128
- package/dist/prices/abstract/ICachedSwapPrice.d.ts +28 -28
- package/dist/prices/abstract/ICachedSwapPrice.js +62 -62
- package/dist/prices/abstract/IPriceProvider.d.ts +81 -81
- package/dist/prices/abstract/IPriceProvider.js +74 -74
- package/dist/prices/abstract/ISwapPrice.d.ts +168 -168
- package/dist/prices/abstract/ISwapPrice.js +279 -279
- package/dist/prices/providers/BinancePriceProvider.d.ts +23 -23
- package/dist/prices/providers/BinancePriceProvider.js +30 -30
- package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +23 -23
- package/dist/prices/providers/CoinGeckoPriceProvider.js +29 -29
- package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +25 -25
- package/dist/prices/providers/CoinPaprikaPriceProvider.js +29 -29
- package/dist/prices/providers/CustomPriceProvider.d.ts +24 -24
- package/dist/prices/providers/CustomPriceProvider.js +35 -35
- package/dist/prices/providers/KrakenPriceProvider.d.ts +38 -38
- package/dist/prices/providers/KrakenPriceProvider.js +45 -45
- package/dist/prices/providers/OKXPriceProvider.d.ts +34 -34
- package/dist/prices/providers/OKXPriceProvider.js +29 -29
- package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +17 -17
- package/dist/prices/providers/abstract/ExchangePriceProvider.js +21 -21
- package/dist/prices/providers/abstract/HttpPriceProvider.d.ts +7 -7
- package/dist/prices/providers/abstract/HttpPriceProvider.js +12 -12
- package/dist/storage/IUnifiedStorage.d.ts +85 -85
- package/dist/storage/IUnifiedStorage.js +2 -2
- package/dist/storage/UnifiedSwapStorage.d.ts +114 -114
- package/dist/storage/UnifiedSwapStorage.js +116 -116
- package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +63 -63
- package/dist/storage-browser/IndexedDBUnifiedStorage.js +298 -298
- package/dist/storage-browser/LocalStorageManager.d.ts +49 -49
- package/dist/storage-browser/LocalStorageManager.js +93 -93
- package/dist/swapper/Swapper.d.ts +687 -686
- package/dist/swapper/Swapper.js +1603 -1603
- package/dist/swapper/SwapperFactory.d.ts +135 -135
- package/dist/swapper/SwapperFactory.js +162 -162
- package/dist/swapper/SwapperUtils.d.ts +200 -200
- package/dist/swapper/SwapperUtils.js +467 -467
- package/dist/swapper/SwapperWithChain.d.ts +404 -404
- package/dist/swapper/SwapperWithChain.js +469 -469
- package/dist/swapper/SwapperWithSigner.d.ts +322 -322
- package/dist/swapper/SwapperWithSigner.js +318 -318
- package/dist/swaps/IAddressSwap.d.ts +22 -22
- package/dist/swaps/IAddressSwap.js +14 -13
- package/dist/swaps/IBTCWalletSwap.d.ts +73 -73
- package/dist/swaps/IBTCWalletSwap.js +18 -17
- package/dist/swaps/IClaimableSwap.d.ts +49 -49
- package/dist/swaps/IClaimableSwap.js +15 -14
- package/dist/swaps/IClaimableSwapWrapper.d.ts +15 -15
- package/dist/swaps/IClaimableSwapWrapper.js +2 -2
- package/dist/swaps/IRefundableSwap.d.ts +43 -43
- package/dist/swaps/IRefundableSwap.js +14 -13
- package/dist/swaps/ISwap.d.ts +387 -386
- package/dist/swaps/ISwap.js +346 -346
- package/dist/swaps/ISwapWithGasDrop.d.ts +21 -21
- package/dist/swaps/ISwapWithGasDrop.js +12 -11
- package/dist/swaps/ISwapWrapper.d.ts +285 -283
- package/dist/swaps/ISwapWrapper.js +353 -353
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +98 -98
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +126 -126
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +135 -133
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +169 -169
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +115 -114
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +134 -134
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +101 -98
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +130 -130
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +162 -162
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +190 -190
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +58 -58
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +78 -78
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +531 -529
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +1285 -1285
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +184 -181
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +418 -418
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +583 -581
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +1371 -1371
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +228 -225
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +506 -506
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +458 -458
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +1126 -1126
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +191 -190
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +378 -378
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +403 -403
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +924 -924
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +62 -62
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +112 -112
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +127 -125
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +256 -256
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +242 -241
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +520 -520
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +73 -73
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +155 -155
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +128 -127
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +278 -278
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +630 -630
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +1443 -1443
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +214 -213
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +756 -756
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +261 -261
- package/dist/swaps/trusted/ln/LnForGasSwap.js +511 -511
- package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +40 -40
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +82 -82
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +342 -342
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +715 -715
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +69 -68
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +92 -92
- package/dist/types/AmountData.d.ts +10 -10
- package/dist/types/AmountData.js +2 -2
- package/dist/types/CustomPriceFunction.d.ts +11 -11
- package/dist/types/CustomPriceFunction.js +2 -2
- package/dist/types/PriceInfoType.d.ts +28 -28
- package/dist/types/PriceInfoType.js +57 -56
- package/dist/types/SwapExecutionAction.d.ts +88 -88
- package/dist/types/SwapExecutionAction.js +2 -2
- package/dist/types/SwapStateInfo.d.ts +5 -5
- package/dist/types/SwapStateInfo.js +2 -2
- package/dist/types/SwapWithSigner.d.ts +17 -17
- package/dist/types/SwapWithSigner.js +43 -42
- package/dist/types/Token.d.ts +99 -99
- package/dist/types/Token.js +76 -76
- package/dist/types/TokenAmount.d.ts +69 -69
- package/dist/types/TokenAmount.js +60 -59
- package/dist/types/fees/Fee.d.ts +50 -50
- package/dist/types/fees/Fee.js +2 -2
- package/dist/types/fees/FeeBreakdown.d.ts +11 -11
- package/dist/types/fees/FeeBreakdown.js +2 -2
- package/dist/types/fees/PercentagePPM.d.ts +17 -17
- package/dist/types/fees/PercentagePPM.js +18 -17
- package/dist/types/lnurl/LNURLPay.d.ts +61 -61
- package/dist/types/lnurl/LNURLPay.js +31 -30
- package/dist/types/lnurl/LNURLWithdraw.d.ts +48 -48
- package/dist/types/lnurl/LNURLWithdraw.js +27 -26
- package/dist/types/wallets/LightningInvoiceCreateService.d.ts +24 -24
- package/dist/types/wallets/LightningInvoiceCreateService.js +15 -14
- package/dist/types/wallets/MinimalBitcoinWalletInterface.d.ts +23 -23
- package/dist/types/wallets/MinimalBitcoinWalletInterface.js +2 -2
- package/dist/types/wallets/MinimalLightningNetworkWalletInterface.d.ts +9 -9
- package/dist/types/wallets/MinimalLightningNetworkWalletInterface.js +2 -2
- package/dist/utils/AutomaticClockDriftCorrection.d.ts +1 -1
- package/dist/utils/AutomaticClockDriftCorrection.js +70 -69
- package/dist/utils/BitcoinUtils.d.ts +14 -12
- package/dist/utils/BitcoinUtils.js +102 -101
- package/dist/utils/BitcoinWalletUtils.d.ts +7 -7
- package/dist/utils/BitcoinWalletUtils.js +14 -13
- package/dist/utils/Logger.d.ts +7 -7
- package/dist/utils/Logger.js +12 -11
- package/dist/utils/RetryUtils.d.ts +22 -22
- package/dist/utils/RetryUtils.js +67 -66
- package/dist/utils/SwapUtils.d.ts +88 -88
- package/dist/utils/SwapUtils.js +72 -72
- package/dist/utils/TimeoutUtils.d.ts +17 -17
- package/dist/utils/TimeoutUtils.js +55 -54
- package/dist/utils/TokenUtils.d.ts +19 -19
- package/dist/utils/TokenUtils.js +37 -36
- package/dist/utils/TypeUtils.d.ts +7 -7
- package/dist/utils/TypeUtils.js +2 -2
- package/dist/utils/Utils.d.ts +58 -56
- package/dist/utils/Utils.js +194 -193
- package/package.json +1 -1
|
@@ -1,686 +1,687 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
import {
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import {
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
*
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
*
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
*
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
*
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
[SwapType.
|
|
153
|
-
[SwapType.
|
|
154
|
-
[SwapType.
|
|
155
|
-
[SwapType.
|
|
156
|
-
[SwapType.
|
|
157
|
-
[SwapType.
|
|
158
|
-
[SwapType.
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
*
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
*
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
private readonly
|
|
199
|
-
private
|
|
200
|
-
private
|
|
201
|
-
private readonly
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
*
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
*
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
*
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
*
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
*
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
private
|
|
257
|
-
private
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* @param
|
|
271
|
-
* @param
|
|
272
|
-
* @param
|
|
273
|
-
* @param
|
|
274
|
-
* @
|
|
275
|
-
* @
|
|
276
|
-
* @throws {Error}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* @param
|
|
284
|
-
* @param
|
|
285
|
-
* @param address
|
|
286
|
-
* @param
|
|
287
|
-
* @param
|
|
288
|
-
* @param
|
|
289
|
-
* @param
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
* @param
|
|
297
|
-
* @param
|
|
298
|
-
* @param
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
* @param
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
* @param
|
|
309
|
-
* @param
|
|
310
|
-
* @param
|
|
311
|
-
* @param
|
|
312
|
-
* @param
|
|
313
|
-
* @param
|
|
314
|
-
* @param
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* @param
|
|
324
|
-
* @param
|
|
325
|
-
* @param
|
|
326
|
-
* @param
|
|
327
|
-
* @param
|
|
328
|
-
* @param
|
|
329
|
-
* @param
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
* @param
|
|
337
|
-
* @param
|
|
338
|
-
* @param
|
|
339
|
-
* @param
|
|
340
|
-
* @param
|
|
341
|
-
* @param
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
*
|
|
347
|
-
*
|
|
348
|
-
* @param
|
|
349
|
-
* @param
|
|
350
|
-
* @param
|
|
351
|
-
* @param
|
|
352
|
-
* @param
|
|
353
|
-
* @param
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
* @param
|
|
361
|
-
* @param
|
|
362
|
-
* @param
|
|
363
|
-
* @param
|
|
364
|
-
* @param
|
|
365
|
-
* @param
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* @param
|
|
374
|
-
* @param
|
|
375
|
-
* @param
|
|
376
|
-
* @param
|
|
377
|
-
* @param
|
|
378
|
-
* @param
|
|
379
|
-
* @param
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
* @param
|
|
387
|
-
* @param
|
|
388
|
-
* @param
|
|
389
|
-
* @param
|
|
390
|
-
* @param
|
|
391
|
-
* @param
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
*
|
|
397
|
-
*
|
|
398
|
-
*
|
|
399
|
-
* @param
|
|
400
|
-
* @param
|
|
401
|
-
* @param
|
|
402
|
-
* @param
|
|
403
|
-
* @param
|
|
404
|
-
* @param
|
|
405
|
-
* @param
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
* @param
|
|
413
|
-
* @param
|
|
414
|
-
* @param
|
|
415
|
-
* @
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
* @param
|
|
423
|
-
* @param
|
|
424
|
-
* @param
|
|
425
|
-
* @param
|
|
426
|
-
* @
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
* @param
|
|
457
|
-
* @param
|
|
458
|
-
* @param
|
|
459
|
-
* @param
|
|
460
|
-
* @param
|
|
461
|
-
*
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
*
|
|
489
|
-
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
* @param
|
|
493
|
-
* @param
|
|
494
|
-
* @param
|
|
495
|
-
* @param
|
|
496
|
-
* @param
|
|
497
|
-
* @param
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
* @param
|
|
547
|
-
* @param
|
|
548
|
-
* @param
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
* @param
|
|
559
|
-
*
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
* @param
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
*
|
|
574
|
-
*
|
|
575
|
-
*
|
|
576
|
-
*
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
* @param
|
|
580
|
-
* @param
|
|
581
|
-
*
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
getToken(ticker: "
|
|
586
|
-
getToken
|
|
587
|
-
getToken(
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
*
|
|
591
|
-
*
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
*
|
|
601
|
-
*
|
|
602
|
-
* @param
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
* @param
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
*
|
|
631
|
-
*
|
|
632
|
-
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
*
|
|
638
|
-
*
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
*
|
|
648
|
-
*
|
|
649
|
-
* @param
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
*
|
|
664
|
-
*
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
*
|
|
670
|
-
*
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
* @param
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
*
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ISwapPrice } from "../prices/abstract/ISwapPrice";
|
|
3
|
+
import { BitcoinNetwork, BitcoinRpcWithAddressIndex, BtcBlock, BtcRelay, ChainData, ChainType, LightningNetworkApi, Messenger, RelaySynchronizer } from "@atomiqlabs/base";
|
|
4
|
+
import { ToBTCLNOptions, ToBTCLNWrapper } from "../swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper";
|
|
5
|
+
import { ToBTCOptions, ToBTCWrapper } from "../swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper";
|
|
6
|
+
import { FromBTCLNOptions, FromBTCLNWrapper } from "../swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper";
|
|
7
|
+
import { FromBTCOptions, FromBTCWrapper } from "../swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper";
|
|
8
|
+
import { IntermediaryDiscovery } from "../intermediaries/IntermediaryDiscovery";
|
|
9
|
+
import { ISwap } from "../swaps/ISwap";
|
|
10
|
+
import { SwapType } from "../enums/SwapType";
|
|
11
|
+
import { FromBTCLNSwap } from "../swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap";
|
|
12
|
+
import { FromBTCSwap } from "../swaps/escrow_swaps/frombtc/onchain/FromBTCSwap";
|
|
13
|
+
import { ToBTCLNSwap } from "../swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap";
|
|
14
|
+
import { ToBTCSwap } from "../swaps/escrow_swaps/tobtc/onchain/ToBTCSwap";
|
|
15
|
+
import { LnForGasWrapper } from "../swaps/trusted/ln/LnForGasWrapper";
|
|
16
|
+
import { LnForGasSwap } from "../swaps/trusted/ln/LnForGasSwap";
|
|
17
|
+
import { EventEmitter } from "events";
|
|
18
|
+
import { Intermediary } from "../intermediaries/Intermediary";
|
|
19
|
+
import { SwapperWithChain } from "./SwapperWithChain";
|
|
20
|
+
import { OnchainForGasSwap } from "../swaps/trusted/onchain/OnchainForGasSwap";
|
|
21
|
+
import { OnchainForGasWrapper } from "../swaps/trusted/onchain/OnchainForGasWrapper";
|
|
22
|
+
import { BTC_NETWORK } from "@scure/btc-signer/utils";
|
|
23
|
+
import { IUnifiedStorage } from "../storage/IUnifiedStorage";
|
|
24
|
+
import { UnifiedSwapStorage, UnifiedSwapStorageCompositeIndexes, UnifiedSwapStorageIndexes } from "../storage/UnifiedSwapStorage";
|
|
25
|
+
import { UnifiedSwapEventListener } from "../events/UnifiedSwapEventListener";
|
|
26
|
+
import { IToBTCSwap } from "../swaps/escrow_swaps/tobtc/IToBTCSwap";
|
|
27
|
+
import { SpvFromBTCOptions, SpvFromBTCWrapper } from "../swaps/spv_swaps/SpvFromBTCWrapper";
|
|
28
|
+
import { SpvFromBTCSwap } from "../swaps/spv_swaps/SpvFromBTCSwap";
|
|
29
|
+
import { SwapperUtils } from "./SwapperUtils";
|
|
30
|
+
import { FromBTCLNAutoOptions, FromBTCLNAutoWrapper } from "../swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper";
|
|
31
|
+
import { FromBTCLNAutoSwap } from "../swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap";
|
|
32
|
+
import { SwapAmountType } from "../enums/SwapAmountType";
|
|
33
|
+
import { IClaimableSwap } from "../swaps/IClaimableSwap";
|
|
34
|
+
import { SwapTypeMapping } from "../utils/SwapUtils";
|
|
35
|
+
import { TokenAmount } from "../types/TokenAmount";
|
|
36
|
+
import { BtcToken, SCToken, Token } from "../types/Token";
|
|
37
|
+
import { LNURLWithdraw } from "../types/lnurl/LNURLWithdraw";
|
|
38
|
+
import { LNURLPay } from "../types/lnurl/LNURLPay";
|
|
39
|
+
import { NotNever } from "../utils/TypeUtils";
|
|
40
|
+
import { LightningInvoiceCreateService } from "../types/wallets/LightningInvoiceCreateService";
|
|
41
|
+
import { SwapSide } from "../enums/SwapSide";
|
|
42
|
+
/**
|
|
43
|
+
* Configuration options for the Swapper
|
|
44
|
+
* @category Core
|
|
45
|
+
*/
|
|
46
|
+
export type SwapperOptions = {
|
|
47
|
+
/**
|
|
48
|
+
* Manual override for the intermediary (LP) URLs for the SDK to use, by default these are fetched automatically
|
|
49
|
+
* from the registry
|
|
50
|
+
*/
|
|
51
|
+
intermediaryUrl?: string | string[];
|
|
52
|
+
/**
|
|
53
|
+
* Registry URL for where to look for active intermediary (LP) endpoint URLs
|
|
54
|
+
*/
|
|
55
|
+
registryUrl?: string;
|
|
56
|
+
/**
|
|
57
|
+
* Bitcoin network to use for the swaps,
|
|
58
|
+
*/
|
|
59
|
+
bitcoinNetwork?: BitcoinNetwork;
|
|
60
|
+
/**
|
|
61
|
+
* Timeout (in milliseconds) for HTTP GET requests done by the SDK
|
|
62
|
+
*/
|
|
63
|
+
getRequestTimeout?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Timeout (in milliseconds) for HTTP POST requests done by the SDK
|
|
66
|
+
*/
|
|
67
|
+
postRequestTimeout?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Additional parameters to be sent to the intermediaries (LPs), when requesting quotes from them
|
|
70
|
+
*/
|
|
71
|
+
defaultAdditionalParameters?: {
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Optional name prefix to use when creating a swap storage, you can use this to create separate storage
|
|
76
|
+
* instances that don't overlap.
|
|
77
|
+
*/
|
|
78
|
+
storagePrefix?: string;
|
|
79
|
+
/**
|
|
80
|
+
* Sets the default intermediary (LP) to use for the trusted gas swaps, if not set the SDK uses a default one
|
|
81
|
+
*/
|
|
82
|
+
defaultTrustedIntermediaryUrl?: string;
|
|
83
|
+
/**
|
|
84
|
+
* A function callback to retrieve a specific named storage container for swap persistency. If not present, the
|
|
85
|
+
* default IndexedDB storage adapter is used. When you use the SDK in non-browser based environments you need to
|
|
86
|
+
* provide this callback such that the SDK is able to use a custom storage adapter.
|
|
87
|
+
*
|
|
88
|
+
* @param storageName Name of the container to retrieve
|
|
89
|
+
*/
|
|
90
|
+
swapStorage?: (storageName: string) => IUnifiedStorage<UnifiedSwapStorageIndexes, UnifiedSwapStorageCompositeIndexes>;
|
|
91
|
+
/**
|
|
92
|
+
* By setting this flag, the swapper doesn't schedule automatic tick timers. To make sure the swap states are
|
|
93
|
+
* properly updated (e.g. the expired swaps properly move to the expired state), you should call the
|
|
94
|
+
* {@link Swapper._syncSwaps} function periodically. This flag should be set when you run an environment that
|
|
95
|
+
* doesn't support long-running timers - e.g. serverless environments like Azure Function Apps or AWS Lambda
|
|
96
|
+
*/
|
|
97
|
+
noTimers?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* By setting this flag, the swapper doesn't subscribe to on-chain events. To make sure the swap states are
|
|
100
|
+
* properly updated you should call the {@link Swapper._syncSwaps} function periodically. This flag should be
|
|
101
|
+
* set when you run an environment that doesn't support long-running timers and websocket connections - e.g.
|
|
102
|
+
* serverless environments like Azure Function Apps or AWS Lambda
|
|
103
|
+
*/
|
|
104
|
+
noEvents?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* By setting this flag, the swap objects will not be cached in the SDK and instead will always be loaded from
|
|
107
|
+
* the persistent storage. By default, the SDK uses a `WeakRef` mapping of swaps, to ensure that when the same
|
|
108
|
+
* swap is loaded concurrently, it returns the same object reference to both, making the changes on the object
|
|
109
|
+
* atomic. This flag should be set to `true` when running in an environment where multiple instances of the SDK
|
|
110
|
+
* access the same swap database - e.g. serverless environments like Azure Function Apps or AWS Lambda
|
|
111
|
+
*/
|
|
112
|
+
noSwapCache?: boolean;
|
|
113
|
+
/**
|
|
114
|
+
* Skip checking past swaps when the swapper is initiated with {@link Swapper.init}, you can call the
|
|
115
|
+
* {@link Swapper._syncSwaps} function later, to check the swaps. By default, the SDK checks the state
|
|
116
|
+
* of all the known swaps during init.
|
|
117
|
+
*/
|
|
118
|
+
dontCheckPastSwaps?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Skip fetching the LPs when the swapper is initiated with {@link Swapper.init}, this means the list of available
|
|
121
|
+
* tokens and swap limits won't be available immediately. LPs will be fetched automatically later, when a swap
|
|
122
|
+
* is requested
|
|
123
|
+
*/
|
|
124
|
+
dontFetchLPs?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Defaults to `true`, this means every swap regardless of it being initiated (i.e. when `commit()`, `execute()` or
|
|
127
|
+
* `waitTillPayment` is called) is saved to the persistent storage. This is a reasonable default for when you
|
|
128
|
+
* want to only create a swap, and then later on retrieve it with the `swapper.getSwapById()` function.
|
|
129
|
+
*
|
|
130
|
+
* Setting this to `false` means the SDK only saves and persists swaps that are considered initiated, i.e. when
|
|
131
|
+
* `commit()`, `execute()` or `waitTillPayment` is called (or their respective txs... prefixed variations). This
|
|
132
|
+
* might save calls to the persistent storage for swaps that are never initiated. This is useful in e.g.
|
|
133
|
+
* frontend implementations where the frontend holds the swap object reference until it is initiated anyway, not
|
|
134
|
+
* necessitating the saving of the swap data to the persistent storage until it is actually initiated.
|
|
135
|
+
*/
|
|
136
|
+
saveUninitializedSwaps?: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Automatically checks system time on initialize, if the system time drifts too far from the actual time
|
|
139
|
+
* (as checked from multiple server sources) it adjusts the `Date.now()` function to return proper actual time.
|
|
140
|
+
*/
|
|
141
|
+
automaticClockDriftCorrection?: boolean;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Type representing multiple blockchain configurations
|
|
145
|
+
* @category Core
|
|
146
|
+
*/
|
|
147
|
+
export type MultiChain = {
|
|
148
|
+
[chainIdentifier in string]: ChainType;
|
|
149
|
+
};
|
|
150
|
+
type ChainSpecificData<T extends ChainType> = {
|
|
151
|
+
wrappers: {
|
|
152
|
+
[SwapType.TO_BTCLN]: ToBTCLNWrapper<T>;
|
|
153
|
+
[SwapType.TO_BTC]: ToBTCWrapper<T>;
|
|
154
|
+
[SwapType.FROM_BTCLN]: FromBTCLNWrapper<T>;
|
|
155
|
+
[SwapType.FROM_BTC]: FromBTCWrapper<T>;
|
|
156
|
+
[SwapType.TRUSTED_FROM_BTCLN]: LnForGasWrapper<T>;
|
|
157
|
+
[SwapType.TRUSTED_FROM_BTC]: OnchainForGasWrapper<T>;
|
|
158
|
+
[SwapType.SPV_VAULT_FROM_BTC]: SpvFromBTCWrapper<T>;
|
|
159
|
+
[SwapType.FROM_BTCLN_AUTO]: FromBTCLNAutoWrapper<T>;
|
|
160
|
+
};
|
|
161
|
+
chainEvents: T["Events"];
|
|
162
|
+
swapContract: T["Contract"];
|
|
163
|
+
spvVaultContract: T["SpvVaultContract"];
|
|
164
|
+
chainInterface: T["ChainInterface"];
|
|
165
|
+
btcRelay: BtcRelay<any, T["TX"], BtcBlock, T["Signer"]>;
|
|
166
|
+
synchronizer: RelaySynchronizer<any, T["TX"], BtcBlock>;
|
|
167
|
+
unifiedChainEvents: UnifiedSwapEventListener<T>;
|
|
168
|
+
unifiedSwapStorage: UnifiedSwapStorage<T>;
|
|
169
|
+
reviver: (val: any) => ISwap<T>;
|
|
170
|
+
};
|
|
171
|
+
type MultiChainData<T extends MultiChain> = {
|
|
172
|
+
[chainIdentifier in keyof T]: ChainSpecificData<T[chainIdentifier]>;
|
|
173
|
+
};
|
|
174
|
+
type CtorMultiChainData<T extends MultiChain> = {
|
|
175
|
+
[chainIdentifier in keyof T]: ChainData<T[chainIdentifier]>;
|
|
176
|
+
};
|
|
177
|
+
/**
|
|
178
|
+
* Type extracting chain identifiers from a MultiChain type
|
|
179
|
+
* @category Core
|
|
180
|
+
*/
|
|
181
|
+
export type ChainIds<T extends MultiChain> = keyof T & string;
|
|
182
|
+
/**
|
|
183
|
+
* Type helper to check if a chain supports a specific swap type
|
|
184
|
+
* @category Core
|
|
185
|
+
*/
|
|
186
|
+
export type SupportsSwapType<C extends ChainType, Type extends SwapType> = Type extends SwapType.SPV_VAULT_FROM_BTC ? NotNever<C["SpvVaultContract"]> : Type extends (SwapType.TRUSTED_FROM_BTCLN | SwapType.TRUSTED_FROM_BTC) ? true : Type extends SwapType.FROM_BTCLN_AUTO ? (C["Contract"]["supportsInitWithoutClaimer"] extends true ? true : false) : NotNever<C["Contract"]>;
|
|
187
|
+
/**
|
|
188
|
+
* Core orchestrator for all atomiq swap operations
|
|
189
|
+
*
|
|
190
|
+
* @category Core
|
|
191
|
+
*/
|
|
192
|
+
export declare class Swapper<T extends MultiChain> extends EventEmitter<{
|
|
193
|
+
lpsRemoved: [Intermediary[]];
|
|
194
|
+
lpsAdded: [Intermediary[]];
|
|
195
|
+
swapState: [ISwap];
|
|
196
|
+
swapLimitsChanged: [];
|
|
197
|
+
}> {
|
|
198
|
+
private readonly logger;
|
|
199
|
+
private readonly swapStateListener;
|
|
200
|
+
private defaultTrustedIntermediary?;
|
|
201
|
+
private readonly bitcoinNetwork;
|
|
202
|
+
private readonly options;
|
|
203
|
+
/**
|
|
204
|
+
* Data propagation layer used for broadcasting messages to watchtowers
|
|
205
|
+
*/
|
|
206
|
+
private readonly messenger;
|
|
207
|
+
/**
|
|
208
|
+
* A dictionary of smart chains used by the SDK
|
|
209
|
+
* @internal
|
|
210
|
+
*/
|
|
211
|
+
readonly _chains: MultiChainData<T>;
|
|
212
|
+
/**
|
|
213
|
+
* Bitcoin RPC for fetching bitcoin chain data
|
|
214
|
+
* @internal
|
|
215
|
+
*/
|
|
216
|
+
readonly _bitcoinRpc: BitcoinRpcWithAddressIndex<any>;
|
|
217
|
+
/**
|
|
218
|
+
* Bitcoin network specification
|
|
219
|
+
* @internal
|
|
220
|
+
*/
|
|
221
|
+
readonly _btcNetwork: BTC_NETWORK;
|
|
222
|
+
/**
|
|
223
|
+
* Token data indexed by chain identifier and token addresses
|
|
224
|
+
* @internal
|
|
225
|
+
*/
|
|
226
|
+
readonly _tokens: {
|
|
227
|
+
[chainId: string]: {
|
|
228
|
+
[tokenAddress: string]: SCToken;
|
|
229
|
+
};
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Token data indexed by chain identifier and token tickers
|
|
233
|
+
* @internal
|
|
234
|
+
*/
|
|
235
|
+
readonly _tokensByTicker: {
|
|
236
|
+
[chainId: string]: {
|
|
237
|
+
[tokenTicker: string]: SCToken;
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Pricing API used by the SDK
|
|
242
|
+
*/
|
|
243
|
+
readonly prices: ISwapPrice<T>;
|
|
244
|
+
/**
|
|
245
|
+
* Intermediary discovery instance
|
|
246
|
+
*/
|
|
247
|
+
readonly intermediaryDiscovery: IntermediaryDiscovery;
|
|
248
|
+
/**
|
|
249
|
+
* Miscellaneous utility functions
|
|
250
|
+
*/
|
|
251
|
+
readonly Utils: SwapperUtils<T>;
|
|
252
|
+
/**
|
|
253
|
+
* @internal
|
|
254
|
+
*/
|
|
255
|
+
constructor(bitcoinRpc: BitcoinRpcWithAddressIndex<any>, lightningApi: LightningNetworkApi, bitcoinSynchronizer: (btcRelay: BtcRelay<any, any, any>) => RelaySynchronizer<any, any, any>, chainsData: CtorMultiChainData<T>, pricing: ISwapPrice<T>, tokens: SCToken[], messenger: Messenger, options?: SwapperOptions);
|
|
256
|
+
private _init;
|
|
257
|
+
private initPromise?;
|
|
258
|
+
private initialized;
|
|
259
|
+
/**
|
|
260
|
+
* Initializes the swap storage and loads existing swaps, needs to be called before any other action
|
|
261
|
+
*/
|
|
262
|
+
init(): Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Stops listening for onchain events and closes this Swapper instance
|
|
265
|
+
*/
|
|
266
|
+
stop(): Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Creates swap & handles intermediary, quote selection
|
|
269
|
+
*
|
|
270
|
+
* @param chainIdentifier
|
|
271
|
+
* @param create Callback to create the
|
|
272
|
+
* @param amountData Amount data as passed to the function
|
|
273
|
+
* @param swapType Swap type of the execution
|
|
274
|
+
* @param maxWaitTimeMS Maximum waiting time after the first intermediary returns the quote
|
|
275
|
+
* @private
|
|
276
|
+
* @throws {Error} when no intermediary was found
|
|
277
|
+
* @throws {Error} if the chain with the provided identifier cannot be found
|
|
278
|
+
*/
|
|
279
|
+
private createSwap;
|
|
280
|
+
/**
|
|
281
|
+
* Creates Smart chain -> Bitcoin ({@link SwapType.TO_BTC}) swap
|
|
282
|
+
*
|
|
283
|
+
* @param chainIdentifier Chain identifier string of the source smart chain
|
|
284
|
+
* @param signer Signer's address on the source chain
|
|
285
|
+
* @param tokenAddress Token address to pay with
|
|
286
|
+
* @param address Recipient's bitcoin address
|
|
287
|
+
* @param amount Amount to send in token based units (if `exactIn=true`) or receive in satoshis (if `exactIn=false`)
|
|
288
|
+
* @param exactIn Whether to use exact in instead of exact out
|
|
289
|
+
* @param additionalParams Additional parameters sent to the LP when creating the swap
|
|
290
|
+
* @param options Additional options for the swap
|
|
291
|
+
*/
|
|
292
|
+
createToBTCSwap<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, signer: string, tokenAddress: string, address: string, amount: bigint, exactIn?: boolean, additionalParams?: Record<string, any> | undefined, options?: ToBTCOptions): Promise<ToBTCSwap<T[ChainIdentifier]>>;
|
|
293
|
+
/**
|
|
294
|
+
* Creates Smart chain -> Bitcoin Lightning ({@link SwapType.TO_BTCLN}) swap
|
|
295
|
+
*
|
|
296
|
+
* @param chainIdentifier Chain identifier string of the source smart chain
|
|
297
|
+
* @param signer Signer's address on the source chain
|
|
298
|
+
* @param tokenAddress Token address to pay with
|
|
299
|
+
* @param paymentRequest BOLT11 lightning network invoice to be paid (needs to have a fixed amount), and the swap
|
|
300
|
+
* amount is taken from this fixed amount, hence only exact output swaps are supported
|
|
301
|
+
* @param additionalParams Additional parameters sent to the LP when creating the swap
|
|
302
|
+
* @param options Additional options for the swap
|
|
303
|
+
*/
|
|
304
|
+
createToBTCLNSwap<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, signer: string, tokenAddress: string, paymentRequest: string, additionalParams?: Record<string, any> | undefined, options?: ToBTCLNOptions): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
|
|
305
|
+
/**
|
|
306
|
+
* Creates Smart chain -> Bitcoin Lightning ({@link SwapType.TO_BTCLN}) swap via LNURL-pay link
|
|
307
|
+
*
|
|
308
|
+
* @param chainIdentifier Chain identifier string of the source smart chain
|
|
309
|
+
* @param signer Signer's address on the source chain
|
|
310
|
+
* @param tokenAddress Token address to pay with
|
|
311
|
+
* @param lnurlPay LNURL-pay link to use for the payment
|
|
312
|
+
* @param amount Amount to send in token based units (if `exactIn=true`) or receive in satoshis (if `exactIn=false`)
|
|
313
|
+
* @param exactIn Whether to do an exact in swap instead of exact out
|
|
314
|
+
* @param additionalParams Additional parameters sent to the LP when creating the swap
|
|
315
|
+
* @param options Additional options for the swap
|
|
316
|
+
*/
|
|
317
|
+
createToBTCLNSwapViaLNURL<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, signer: string, tokenAddress: string, lnurlPay: string | LNURLPay, amount: bigint, exactIn?: boolean, additionalParams?: Record<string, any> | undefined, options?: ToBTCLNOptions & {
|
|
318
|
+
comment?: string;
|
|
319
|
+
}): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
|
|
320
|
+
/**
|
|
321
|
+
* Creates Smart chain -> Bitcoin Lightning ({@link SwapType.TO_BTCLN}) swap via {@link LightningInvoiceCreateService}
|
|
322
|
+
*
|
|
323
|
+
* @param chainIdentifier Chain identifier string of the source smart chain
|
|
324
|
+
* @param signer Signer's address on the source chain
|
|
325
|
+
* @param tokenAddress Token address to pay with
|
|
326
|
+
* @param service Invoice create service object which facilitates the creation of fixed amount LN invoices
|
|
327
|
+
* @param amount Amount to send in token based units (if `exactIn=true`) or receive in satoshis (if `exactIn=false`)
|
|
328
|
+
* @param exactIn Whether to do an exact in swap instead of exact out
|
|
329
|
+
* @param additionalParams Additional parameters sent to the LP when creating the swap
|
|
330
|
+
* @param options Additional options for the swap
|
|
331
|
+
*/
|
|
332
|
+
createToBTCLNSwapViaInvoiceCreateService<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, signer: string, tokenAddress: string, service: LightningInvoiceCreateService, amount: bigint, exactIn?: boolean, additionalParams?: Record<string, any> | undefined, options?: ToBTCLNOptions): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
|
|
333
|
+
/**
|
|
334
|
+
* Creates Bitcoin -> Smart chain ({@link SwapType.SPV_VAULT_FROM_BTC}) swap
|
|
335
|
+
*
|
|
336
|
+
* @param chainIdentifier Chain identifier string of the destination smart chain
|
|
337
|
+
* @param recipient Recipient address on the destination chain
|
|
338
|
+
* @param tokenAddress Token address to receive
|
|
339
|
+
* @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
|
|
340
|
+
* @param exactOut Whether to use a exact out instead of exact in
|
|
341
|
+
* @param additionalParams Additional parameters sent to the LP when creating the swap
|
|
342
|
+
* @param options Additional options for the swap
|
|
343
|
+
*/
|
|
344
|
+
createFromBTCSwapNew<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, recipient: string, tokenAddress: string, amount: bigint, exactOut?: boolean, additionalParams?: Record<string, any> | undefined, options?: SpvFromBTCOptions): Promise<SpvFromBTCSwap<T[ChainIdentifier]>>;
|
|
345
|
+
/**
|
|
346
|
+
* Creates LEGACY Bitcoin -> Smart chain ({@link SwapType.FROM_BTC}) swap
|
|
347
|
+
*
|
|
348
|
+
* @param chainIdentifier Chain identifier string of the destination smart chain
|
|
349
|
+
* @param recipient Recipient address on the destination chain
|
|
350
|
+
* @param tokenAddress Token address to receive
|
|
351
|
+
* @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
|
|
352
|
+
* @param exactOut Whether to use a exact out instead of exact in
|
|
353
|
+
* @param additionalParams Additional parameters sent to the LP when creating the swap
|
|
354
|
+
* @param options Additional options for the swap
|
|
355
|
+
*/
|
|
356
|
+
createFromBTCSwap<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, recipient: string, tokenAddress: string, amount: bigint, exactOut?: boolean, additionalParams?: Record<string, any> | undefined, options?: FromBTCOptions): Promise<FromBTCSwap<T[ChainIdentifier]>>;
|
|
357
|
+
/**
|
|
358
|
+
* Creates LEGACY Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN}) swap
|
|
359
|
+
*
|
|
360
|
+
* @param chainIdentifier Chain identifier string of the destination smart chain
|
|
361
|
+
* @param recipient Recipient address on the destination chain
|
|
362
|
+
* @param tokenAddress Token address to receive
|
|
363
|
+
* @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
|
|
364
|
+
* @param exactOut Whether to use a exact out instead of exact in
|
|
365
|
+
* @param additionalParams Additional parameters sent to the LP when creating the swap
|
|
366
|
+
* @param options Additional options for the swap
|
|
367
|
+
*/
|
|
368
|
+
createFromBTCLNSwap<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, recipient: string, tokenAddress: string, amount: bigint, exactOut?: boolean, additionalParams?: Record<string, any> | undefined, options?: FromBTCLNOptions): Promise<FromBTCLNSwap<T[ChainIdentifier]>>;
|
|
369
|
+
/**
|
|
370
|
+
* Creates LEGACY Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN}) swap, withdrawing from
|
|
371
|
+
* an LNURL-withdraw link
|
|
372
|
+
*
|
|
373
|
+
* @param chainIdentifier Chain identifier string of the destination smart chain
|
|
374
|
+
* @param recipient Recipient address on the destination chain
|
|
375
|
+
* @param tokenAddress Token address to receive
|
|
376
|
+
* @param lnurl LNURL-withdraw link to pull the funds from
|
|
377
|
+
* @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
|
|
378
|
+
* @param exactOut Whether to use a exact out instead of exact in
|
|
379
|
+
* @param additionalParams Additional parameters sent to the LP when creating the swap
|
|
380
|
+
* @param options Additional options for the swap
|
|
381
|
+
*/
|
|
382
|
+
createFromBTCLNSwapViaLNURL<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, recipient: string, tokenAddress: string, lnurl: string | LNURLWithdraw, amount: bigint, exactOut?: boolean, additionalParams?: Record<string, any> | undefined, options?: FromBTCLNOptions): Promise<FromBTCLNSwap<T[ChainIdentifier]>>;
|
|
383
|
+
/**
|
|
384
|
+
* Creates Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN_AUTO}) swap
|
|
385
|
+
*
|
|
386
|
+
* @param chainIdentifier Chain identifier string of the destination smart chain
|
|
387
|
+
* @param recipient Recipient address on the destination chain
|
|
388
|
+
* @param tokenAddress Token address to receive
|
|
389
|
+
* @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
|
|
390
|
+
* @param exactOut Whether to use a exact out instead of exact in
|
|
391
|
+
* @param additionalParams Additional parameters sent to the LP when creating the swap
|
|
392
|
+
* @param options Additional options for the swap
|
|
393
|
+
*/
|
|
394
|
+
createFromBTCLNSwapNew<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, recipient: string, tokenAddress: string, amount: bigint, exactOut?: boolean, additionalParams?: Record<string, any> | undefined, options?: FromBTCLNAutoOptions): Promise<FromBTCLNAutoSwap<T[ChainIdentifier]>>;
|
|
395
|
+
/**
|
|
396
|
+
* Creates Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN_AUTO}) swap, withdrawing from
|
|
397
|
+
* an LNURL-withdraw link
|
|
398
|
+
*
|
|
399
|
+
* @param chainIdentifier Chain identifier string of the destination smart chain
|
|
400
|
+
* @param recipient Recipient address on the destination chain
|
|
401
|
+
* @param tokenAddress Token address to receive
|
|
402
|
+
* @param lnurl LNURL-withdraw link to pull the funds from
|
|
403
|
+
* @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
|
|
404
|
+
* @param exactOut Whether to use a exact out instead of exact in
|
|
405
|
+
* @param additionalParams Additional parameters sent to the LP when creating the swap
|
|
406
|
+
* @param options Additional options for the swap
|
|
407
|
+
*/
|
|
408
|
+
createFromBTCLNSwapNewViaLNURL<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier, recipient: string, tokenAddress: string, lnurl: string | LNURLWithdraw, amount: bigint, exactOut?: boolean, additionalParams?: Record<string, any> | undefined, options?: FromBTCLNAutoOptions): Promise<FromBTCLNAutoSwap<T[ChainIdentifier]>>;
|
|
409
|
+
/**
|
|
410
|
+
* Creates a trusted Bitcoin Lightning -> Smart chain ({@link SwapType.TRUSTED_FROM_BTCLN}) gas swap
|
|
411
|
+
*
|
|
412
|
+
* @param chainIdentifier Chain identifier string of the destination smart chain
|
|
413
|
+
* @param recipient Recipient address on the destination chain
|
|
414
|
+
* @param amount Amount of native token to receive, in base units
|
|
415
|
+
* @param trustedIntermediaryOrUrl URL or Intermediary object of the trusted intermediary to use, otherwise uses default
|
|
416
|
+
* @throws {Error} If no trusted intermediary specified
|
|
417
|
+
*/
|
|
418
|
+
createTrustedLNForGasSwap<C extends ChainIds<T>>(chainIdentifier: C, recipient: string, amount: bigint, trustedIntermediaryOrUrl?: Intermediary | string): Promise<LnForGasSwap<T[C]>>;
|
|
419
|
+
/**
|
|
420
|
+
* Creates a trusted Bitcoin -> Smart chain ({@link SwapType.TRUSTED_FROM_BTC}) gas swap
|
|
421
|
+
*
|
|
422
|
+
* @param chainIdentifier Chain identifier string of the destination smart chain
|
|
423
|
+
* @param recipient Recipient address on the destination chain
|
|
424
|
+
* @param amount Amount of native token to receive, in base units
|
|
425
|
+
* @param refundAddress Bitcoin refund address, in case the swap fails the funds are refunded here
|
|
426
|
+
* @param trustedIntermediaryOrUrl URL or Intermediary object of the trusted intermediary to use, otherwise uses default
|
|
427
|
+
* @throws {Error} If no trusted intermediary specified
|
|
428
|
+
*/
|
|
429
|
+
createTrustedOnchainForGasSwap<C extends ChainIds<T>>(chainIdentifier: C, recipient: string, amount: bigint, refundAddress?: string, trustedIntermediaryOrUrl?: Intermediary | string): Promise<OnchainForGasSwap<T[C]>>;
|
|
430
|
+
/**
|
|
431
|
+
* @internal
|
|
432
|
+
*/
|
|
433
|
+
create<C extends ChainIds<T>>(signer: string, srcToken: BtcToken<true>, dstToken: SCToken<C>, amount: bigint, exactIn: boolean, lnurlWithdraw?: string | LNURLWithdraw): Promise<(SupportsSwapType<T[C], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoSwap<T[C]> : FromBTCLNSwap<T[C]>)>;
|
|
434
|
+
/**
|
|
435
|
+
* @internal
|
|
436
|
+
*/
|
|
437
|
+
create<C extends ChainIds<T>>(signer: string, srcToken: BtcToken<false>, dstToken: SCToken<C>, amount: bigint, exactIn: boolean): Promise<(SupportsSwapType<T[C], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCSwap<T[C]> : FromBTCSwap<T[C]>)>;
|
|
438
|
+
/**
|
|
439
|
+
* @internal
|
|
440
|
+
*/
|
|
441
|
+
create<C extends ChainIds<T>>(signer: string, srcToken: SCToken<C>, dstToken: BtcToken<false>, amount: bigint, exactIn: boolean, address: string): Promise<ToBTCSwap<T[C]>>;
|
|
442
|
+
/**
|
|
443
|
+
* @internal
|
|
444
|
+
*/
|
|
445
|
+
create<C extends ChainIds<T>>(signer: string, srcToken: SCToken<C>, dstToken: BtcToken<true>, amount: bigint, exactIn: boolean, lnurlPay: string | LNURLPay): Promise<ToBTCLNSwap<T[C]>>;
|
|
446
|
+
/**
|
|
447
|
+
* @internal
|
|
448
|
+
*/
|
|
449
|
+
create<C extends ChainIds<T>>(signer: string, srcToken: SCToken<C>, dstToken: BtcToken<true>, amount: undefined, exactIn: false, lightningInvoice: string): Promise<ToBTCLNSwap<T[C]>>;
|
|
450
|
+
/**
|
|
451
|
+
* Creates a swap from srcToken to dstToken, of a specific token amount, either specifying input amount (exactIn=true)
|
|
452
|
+
* or output amount (exactIn=false), NOTE: For regular -> BTC-LN (lightning) swaps the passed amount is ignored and
|
|
453
|
+
* invoice's pre-set amount is used instead.
|
|
454
|
+
* @deprecated Use {@link swap} instead
|
|
455
|
+
*
|
|
456
|
+
* @param signer Smartchain (Solana, Starknet, etc.) address of the user
|
|
457
|
+
* @param srcToken Source token of the swap, user pays this token
|
|
458
|
+
* @param dstToken Destination token of the swap, user receives this token
|
|
459
|
+
* @param amount Amount of the swap
|
|
460
|
+
* @param exactIn Whether the amount specified is an input amount (exactIn=true) or an output amount (exactIn=false)
|
|
461
|
+
* @param addressLnurlLightningInvoice Bitcoin on-chain address, lightning invoice, LNURL-pay to pay or
|
|
462
|
+
* LNURL-withdrawal to withdraw money from
|
|
463
|
+
*/
|
|
464
|
+
create<C extends ChainIds<T>>(signer: string, srcToken: Token<C>, dstToken: Token<C>, amount: bigint | undefined, exactIn: boolean, addressLnurlLightningInvoice?: string | LNURLWithdraw | LNURLPay): Promise<ISwap<T[C]>>;
|
|
465
|
+
/**
|
|
466
|
+
* @internal
|
|
467
|
+
*/
|
|
468
|
+
swap<C extends ChainIds<T>>(srcToken: BtcToken<true> | "BTCLN" | "BTC-LN" | "LIGHTNING-BTC", dstToken: SCToken<C> | string, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string | LNURLWithdraw, dstSmartchainWallet: string, options?: (SupportsSwapType<T[C], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoOptions : FromBTCLNOptions)): Promise<(SupportsSwapType<T[C], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoSwap<T[C]> : FromBTCLNSwap<T[C]>)>;
|
|
469
|
+
/**
|
|
470
|
+
* @internal
|
|
471
|
+
*/
|
|
472
|
+
swap<C extends ChainIds<T>>(srcToken: BtcToken<false> | "BTC" | "BITCOIN-BTC", dstToken: SCToken<C> | string, amount: bigint | string, exactIn: boolean | SwapAmountType, src: undefined | string, dstSmartchainWallet: string, options?: (SupportsSwapType<T[C], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCOptions : FromBTCOptions)): Promise<(SupportsSwapType<T[C], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCSwap<T[C]> : FromBTCSwap<T[C]>)>;
|
|
473
|
+
/**
|
|
474
|
+
* @internal
|
|
475
|
+
*/
|
|
476
|
+
swap<C extends ChainIds<T>>(srcToken: SCToken<C> | string, dstToken: BtcToken<false> | "BTC" | "BITCOIN-BTC", amount: bigint | string, exactIn: boolean | SwapAmountType, src: string, dstAddress: string, options?: ToBTCOptions): Promise<ToBTCSwap<T[C]>>;
|
|
477
|
+
/**
|
|
478
|
+
* @internal
|
|
479
|
+
*/
|
|
480
|
+
swap<C extends ChainIds<T>>(srcToken: SCToken<C> | string, dstToken: BtcToken<true> | "BTCLN" | "BTC-LN" | "LIGHTNING-BTC", amount: bigint | string, exactIn: boolean | SwapAmountType, src: string, dstLnurlPayOrInvoiceCreateService: string | LNURLPay | LightningInvoiceCreateService, options?: ToBTCLNOptions & {
|
|
481
|
+
comment?: string;
|
|
482
|
+
}): Promise<ToBTCLNSwap<T[C]>>;
|
|
483
|
+
/**
|
|
484
|
+
* @internal
|
|
485
|
+
*/
|
|
486
|
+
swap<C extends ChainIds<T>>(srcToken: SCToken<C> | string, dstToken: BtcToken<true> | "BTCLN" | "BTC-LN" | "LIGHTNING-BTC", amount: undefined, exactIn: false | SwapAmountType.EXACT_OUT, src: string, dstLightningInvoice: string, options?: ToBTCLNOptions): Promise<ToBTCLNSwap<T[C]>>;
|
|
487
|
+
/**
|
|
488
|
+
* Creates a swap from srcToken to dstToken, of a specific token amount, either specifying input amount (if `exactIn=true`)
|
|
489
|
+
* or output amount (if `exactIn=false`), NOTE: For regular Smart chain -> BTC-LN (lightning) swaps the passed amount is ignored and
|
|
490
|
+
* invoice's pre-set amount is used instead, use LNURL-pay links for dynamic amounts
|
|
491
|
+
*
|
|
492
|
+
* @param srcToken Source token of the swap, user pays this token
|
|
493
|
+
* @param dstToken Destination token of the swap, user receives this token
|
|
494
|
+
* @param amount Amount of the swap either in base units as {bigint} or in human readable format (with decimals) as {string}
|
|
495
|
+
* @param exactIn Whether the amount specified is an input amount (exactIn=true) or an output amount (exactIn=false)
|
|
496
|
+
* @param src Source wallet/lnurl-withdraw of the swap
|
|
497
|
+
* @param dst Destination smart chain address, bitcoin on-chain address, lightning invoice, LNURL-pay
|
|
498
|
+
* @param options Options for the swap
|
|
499
|
+
*/
|
|
500
|
+
swap<C extends ChainIds<T>>(srcToken: Token<C> | string, dstToken: Token<C> | string, amount: bigint | string | undefined, exactIn: boolean | SwapAmountType, src: undefined | string | LNURLWithdraw, dst: string | LNURLPay | LightningInvoiceCreateService, options?: FromBTCLNOptions | SpvFromBTCOptions | FromBTCOptions | ToBTCOptions | (ToBTCLNOptions & {
|
|
501
|
+
comment?: string;
|
|
502
|
+
}) | FromBTCLNAutoOptions): Promise<ISwap<T[C]>>;
|
|
503
|
+
/**
|
|
504
|
+
* Returns all swaps
|
|
505
|
+
*/
|
|
506
|
+
getAllSwaps(): Promise<ISwap[]>;
|
|
507
|
+
/**
|
|
508
|
+
* Returns all swaps for the specific chain, and optionally also for a specific signer's address
|
|
509
|
+
*/
|
|
510
|
+
getAllSwaps<C extends ChainIds<T>>(chainId: C, signer?: string): Promise<ISwap<T[C]>[]>;
|
|
511
|
+
/**
|
|
512
|
+
* Returns all swaps where an action is required (either claim or refund)
|
|
513
|
+
*/
|
|
514
|
+
getActionableSwaps(): Promise<ISwap[]>;
|
|
515
|
+
/**
|
|
516
|
+
* Returns swaps where an action is required (either claim or refund) for the specific chain, and optionally also for a specific signer's address
|
|
517
|
+
*/
|
|
518
|
+
getActionableSwaps<C extends ChainIds<T>>(chainId: C, signer?: string): Promise<ISwap<T[C]>[]>;
|
|
519
|
+
/**
|
|
520
|
+
* Returns all swaps that are refundable
|
|
521
|
+
*/
|
|
522
|
+
getRefundableSwaps(): Promise<IToBTCSwap[]>;
|
|
523
|
+
/**
|
|
524
|
+
* Returns swaps which are refundable for the specific chain, and optionally also for a specific signer's address
|
|
525
|
+
*/
|
|
526
|
+
getRefundableSwaps<C extends ChainIds<T>>(chainId: C, signer?: string): Promise<IToBTCSwap<T[C]>[]>;
|
|
527
|
+
/**
|
|
528
|
+
* Returns all swaps that are manually claimable
|
|
529
|
+
*/
|
|
530
|
+
getClaimableSwaps(): Promise<IClaimableSwap[]>;
|
|
531
|
+
/**
|
|
532
|
+
* Returns all swaps that are manually claimable for the specific chain, and optionally also for a specific signer's address
|
|
533
|
+
*/
|
|
534
|
+
getClaimableSwaps<C extends ChainIds<T>>(chainId: C, signer?: string): Promise<IClaimableSwap<T[C]>[]>;
|
|
535
|
+
/**
|
|
536
|
+
* Returns swap with a specific id (identifier)
|
|
537
|
+
*/
|
|
538
|
+
getSwapById(id: string): Promise<ISwap>;
|
|
539
|
+
/**
|
|
540
|
+
* Returns swap with a specific id (identifier) on a specific chain and optionally with a signer
|
|
541
|
+
*/
|
|
542
|
+
getSwapById<C extends ChainIds<T>>(id: string, chainId: C, signer?: string): Promise<ISwap<T[C]>>;
|
|
543
|
+
/**
|
|
544
|
+
* Returns the swap with a proper return type, or `undefined` if not found or has wrong type
|
|
545
|
+
*
|
|
546
|
+
* @param id An ID of the swap ({@link ISwap.getId})
|
|
547
|
+
* @param chainId Chain identifier of the smart chain where the swap was initiated
|
|
548
|
+
* @param swapType Type of the swap
|
|
549
|
+
* @param signer An optional required smart chain signer address to fetch the swap for
|
|
550
|
+
*/
|
|
551
|
+
getTypedSwapById<C extends ChainIds<T>, S extends SwapType>(id: string, chainId: C, swapType: S, signer?: string): Promise<SwapTypeMapping<T[C]>[S] | undefined>;
|
|
552
|
+
private syncSwapsForChain;
|
|
553
|
+
/**
|
|
554
|
+
* Deletes the swaps from the persistent storage backend. Note that some data (like lightning network
|
|
555
|
+
* amounts and bolt11 invoices) are purely off-chain and can never be recovered later just from
|
|
556
|
+
* on-chain data!
|
|
557
|
+
*
|
|
558
|
+
* @param chainId Optional, to only delete swaps for this smart chain
|
|
559
|
+
* @param signer Optional, to only delete swaps for this smart chain signer (`chainId` param must be
|
|
560
|
+
* set to delete only signer's swaps)
|
|
561
|
+
*/
|
|
562
|
+
wipeStorage<C extends ChainIds<T>>(chainId?: C, signer?: string): Promise<void>;
|
|
563
|
+
/**
|
|
564
|
+
* Synchronizes swaps from on-chain, this is ran automatically when SDK is initialized, hence
|
|
565
|
+
* should only be ran manually when `dontCheckPastSwaps=true` is passed in the swapper options,
|
|
566
|
+
* also deletes expired quotes
|
|
567
|
+
*
|
|
568
|
+
* @param chainId Optional chain identifier to only run swap sync for a single smart chain
|
|
569
|
+
* @param signer Optional signer to only run swap sync for swaps initiated by this signer
|
|
570
|
+
*/
|
|
571
|
+
_syncSwaps<C extends ChainIds<T>>(chainId?: C, signer?: string): Promise<void>;
|
|
572
|
+
/**
|
|
573
|
+
* Recovers swaps from on-chain historical data.
|
|
574
|
+
*
|
|
575
|
+
* Please note that the recovered swaps might not be complete (i.e. missing amounts or addresses), as some
|
|
576
|
+
* of the swap data is purely off-chain and can never be recovered purely from on-chain data. This
|
|
577
|
+
* functions tries to recover as much swap data as possible.
|
|
578
|
+
*
|
|
579
|
+
* @param chainId Smart chain identifier string to recover the swaps from
|
|
580
|
+
* @param signer Signer address to recover the swaps for
|
|
581
|
+
* @param startBlockheight Optional starting blockheight for swap data recovery, will only check swaps
|
|
582
|
+
* initiated after this blockheight
|
|
583
|
+
*/
|
|
584
|
+
recoverSwaps<C extends ChainIds<T>>(chainId: C, signer: string, startBlockheight?: number): Promise<ISwap<T[C]>[]>;
|
|
585
|
+
getToken(ticker: "BTC" | "BITCOIN-BTC"): BtcToken<false>;
|
|
586
|
+
getToken(ticker: "BTCLN" | "BTC-LN" | "LIGHTNING-BTC"): BtcToken<true>;
|
|
587
|
+
getToken<ChainIdentifier extends ChainIds<T>>(ticker: `${ChainIdentifier}-${string}`): SCToken<ChainIdentifier>;
|
|
588
|
+
getToken(tickerOrAddress: string): Token<ChainIds<T>>;
|
|
589
|
+
/**
|
|
590
|
+
* Creates a child swapper instance with a given smart chain
|
|
591
|
+
*
|
|
592
|
+
* @param chainIdentifier Smart chain identifier for the created child swapper instance
|
|
593
|
+
*/
|
|
594
|
+
withChain<ChainIdentifier extends ChainIds<T>>(chainIdentifier: ChainIdentifier): SwapperWithChain<T, ChainIdentifier>;
|
|
595
|
+
/**
|
|
596
|
+
* Returns an array of all the supported smart chains
|
|
597
|
+
*/
|
|
598
|
+
getSmartChains(): ChainIds<T>[];
|
|
599
|
+
/**
|
|
600
|
+
* Returns whether the SDK supports a given swap type on a given chain based on currently known LPs
|
|
601
|
+
*
|
|
602
|
+
* @param chainId Smart chain identifier string
|
|
603
|
+
* @param swapType Swap protocol type
|
|
604
|
+
*/
|
|
605
|
+
supportsSwapType<ChainIdentifier extends ChainIds<T>, Type extends SwapType>(chainId: ChainIdentifier, swapType: Type): SupportsSwapType<T[ChainIdentifier], Type>;
|
|
606
|
+
/**
|
|
607
|
+
* @internal
|
|
608
|
+
*/
|
|
609
|
+
getSwapType<C extends ChainIds<T>>(srcToken: BtcToken<true>, dstToken: SCToken<C>): (SupportsSwapType<T[C], SwapType.FROM_BTCLN_AUTO> extends true ? SwapType.FROM_BTCLN_AUTO : SwapType.FROM_BTCLN);
|
|
610
|
+
/**
|
|
611
|
+
* @internal
|
|
612
|
+
*/
|
|
613
|
+
getSwapType<C extends ChainIds<T>>(srcToken: BtcToken<false>, dstToken: SCToken<C>): (SupportsSwapType<T[C], SwapType.SPV_VAULT_FROM_BTC> extends true ? SwapType.SPV_VAULT_FROM_BTC : SwapType.FROM_BTC);
|
|
614
|
+
/**
|
|
615
|
+
* @internal
|
|
616
|
+
*/
|
|
617
|
+
getSwapType<C extends ChainIds<T>>(srcToken: SCToken<C>, dstToken: BtcToken<false>): SwapType.TO_BTC;
|
|
618
|
+
/**
|
|
619
|
+
* @internal
|
|
620
|
+
*/
|
|
621
|
+
getSwapType<C extends ChainIds<T>>(srcToken: SCToken<C>, dstToken: BtcToken<true>): SwapType.TO_BTCLN;
|
|
622
|
+
/**
|
|
623
|
+
* Returns type of the swap based on input and output tokens specified
|
|
624
|
+
*
|
|
625
|
+
* @param srcToken Source token
|
|
626
|
+
* @param dstToken Destination token
|
|
627
|
+
*/
|
|
628
|
+
getSwapType<C extends ChainIds<T>>(srcToken: Token<C>, dstToken: Token<C>): SwapType.FROM_BTCLN_AUTO | SwapType.FROM_BTCLN | SwapType.SPV_VAULT_FROM_BTC | SwapType.FROM_BTC | SwapType.TO_BTC | SwapType.TO_BTCLN;
|
|
629
|
+
/**
|
|
630
|
+
* Helper information about various swap protocol and their features:
|
|
631
|
+
* - `requiresInputWallet`: Whether a swap requires a connected wallet on the input chain able to sign
|
|
632
|
+
* arbitrary transaction
|
|
633
|
+
* - `requiresOutputWallet`: Whether a swap requires a connected wallet on the output chain able to sign
|
|
634
|
+
* arbitrary transactions
|
|
635
|
+
* - `supportsGasDrop`: Whether a swap supports the "gas drop" feature, allowing to user to receive a small
|
|
636
|
+
* amount of native token as part of the swap when swapping to smart chains
|
|
637
|
+
*
|
|
638
|
+
* Uses a `Record` type here, use the {@link SwapProtocolInfo} import for a literal readonly type, with
|
|
639
|
+
* pre-filled exact values in the type.
|
|
640
|
+
*/
|
|
641
|
+
readonly SwapTypeInfo: Record<SwapType, {
|
|
642
|
+
requiresInputWallet: boolean;
|
|
643
|
+
requiresOutputWallet: boolean;
|
|
644
|
+
supportsGasDrop: boolean;
|
|
645
|
+
}>;
|
|
646
|
+
/**
|
|
647
|
+
* Returns minimum/maximum limits for inputs and outputs for a swap between given tokens
|
|
648
|
+
*
|
|
649
|
+
* @param srcToken Source token
|
|
650
|
+
* @param dstToken Destination token
|
|
651
|
+
*/
|
|
652
|
+
getSwapLimits<C extends ChainIds<T>, A extends Token<C>, B extends Token<C>>(srcToken: A, dstToken: B): {
|
|
653
|
+
input: {
|
|
654
|
+
min: TokenAmount<A>;
|
|
655
|
+
max?: TokenAmount<A>;
|
|
656
|
+
};
|
|
657
|
+
output: {
|
|
658
|
+
min: TokenAmount<B>;
|
|
659
|
+
max?: TokenAmount<B>;
|
|
660
|
+
};
|
|
661
|
+
};
|
|
662
|
+
/**
|
|
663
|
+
* Returns an array of supported tokens either on the input or on the output of a swap
|
|
664
|
+
*
|
|
665
|
+
* @param input Whether to return input tokens or output tokens
|
|
666
|
+
*/
|
|
667
|
+
getSupportedTokens(input: SwapSide | boolean): Token[];
|
|
668
|
+
/**
|
|
669
|
+
* Returns a set of supported tokens by all the intermediaries offering a specific swap service
|
|
670
|
+
*
|
|
671
|
+
* @param _swapType Swap service type to check supported tokens for
|
|
672
|
+
*/
|
|
673
|
+
private getSupportedTokensForSwapType;
|
|
674
|
+
/**
|
|
675
|
+
* Returns the set of supported token addresses by all the intermediaries we know of offering a specific swapType service
|
|
676
|
+
*
|
|
677
|
+
* @param chainIdentifier Chain identifier string
|
|
678
|
+
* @param swapType Specific swap type for which to obtain supported tokens
|
|
679
|
+
*/
|
|
680
|
+
private getSupportedTokenAddresses;
|
|
681
|
+
/**
|
|
682
|
+
* Returns tokens that you can swap to (if input=true) from a given token,
|
|
683
|
+
* or tokens that you can swap from (if input=false) to a given token
|
|
684
|
+
*/
|
|
685
|
+
getSwapCounterTokens(token: Token, input: SwapSide | boolean): Token[];
|
|
686
|
+
}
|
|
687
|
+
export {};
|