@atomiqlabs/sdk 8.1.7 → 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.
Files changed (253) hide show
  1. package/dist/bitcoin/wallet/BitcoinWallet.d.ts +41 -5
  2. package/dist/bitcoin/wallet/BitcoinWallet.js +36 -1
  3. package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +52 -2
  4. package/dist/bitcoin/wallet/IBitcoinWallet.js +2 -1
  5. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +42 -7
  6. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +36 -1
  7. package/dist/enums/FeeType.d.ts +7 -0
  8. package/dist/enums/FeeType.js +7 -0
  9. package/dist/enums/SwapAmountType.d.ts +7 -0
  10. package/dist/enums/SwapAmountType.js +7 -0
  11. package/dist/enums/SwapDirection.d.ts +7 -0
  12. package/dist/enums/SwapDirection.js +7 -0
  13. package/dist/enums/SwapType.d.ts +62 -1
  14. package/dist/enums/SwapType.js +62 -1
  15. package/dist/errors/IntermediaryError.d.ts +4 -0
  16. package/dist/errors/IntermediaryError.js +1 -0
  17. package/dist/errors/RequestError.d.ts +15 -1
  18. package/dist/errors/RequestError.js +8 -0
  19. package/dist/errors/UserError.d.ts +1 -0
  20. package/dist/errors/UserError.js +1 -0
  21. package/dist/index.d.ts +4 -5
  22. package/dist/index.js +3 -4
  23. package/dist/intermediaries/Intermediary.d.ts +57 -10
  24. package/dist/intermediaries/Intermediary.js +37 -10
  25. package/dist/intermediaries/IntermediaryDiscovery.d.ts +55 -22
  26. package/dist/intermediaries/IntermediaryDiscovery.js +35 -22
  27. package/dist/prices/RedundantSwapPrice.d.ts +24 -3
  28. package/dist/prices/RedundantSwapPrice.js +21 -1
  29. package/dist/prices/SingleSwapPrice.d.ts +9 -6
  30. package/dist/prices/SingleSwapPrice.js +10 -7
  31. package/dist/prices/SwapPriceWithChain.d.ts +54 -16
  32. package/dist/prices/SwapPriceWithChain.js +58 -20
  33. package/dist/prices/abstract/ISwapPrice.d.ts +94 -45
  34. package/dist/prices/abstract/ISwapPrice.js +103 -55
  35. package/dist/prices/providers/BinancePriceProvider.d.ts +7 -0
  36. package/dist/prices/providers/BinancePriceProvider.js +7 -0
  37. package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +6 -0
  38. package/dist/prices/providers/CoinGeckoPriceProvider.js +6 -0
  39. package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +6 -0
  40. package/dist/prices/providers/CoinPaprikaPriceProvider.js +6 -0
  41. package/dist/prices/providers/CustomPriceProvider.d.ts +11 -0
  42. package/dist/prices/providers/CustomPriceProvider.js +11 -0
  43. package/dist/prices/providers/KrakenPriceProvider.d.ts +9 -0
  44. package/dist/prices/providers/KrakenPriceProvider.js +9 -0
  45. package/dist/prices/providers/OKXPriceProvider.d.ts +6 -0
  46. package/dist/prices/providers/OKXPriceProvider.js +6 -0
  47. package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +3 -0
  48. package/dist/prices/providers/abstract/ExchangePriceProvider.js +3 -0
  49. package/dist/storage/IUnifiedStorage.d.ts +19 -7
  50. package/dist/storage/UnifiedSwapStorage.d.ts +33 -3
  51. package/dist/storage/UnifiedSwapStorage.js +29 -1
  52. package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +31 -7
  53. package/dist/storage-browser/IndexedDBUnifiedStorage.js +29 -6
  54. package/dist/storage-browser/LocalStorageManager.d.ts +25 -1
  55. package/dist/storage-browser/LocalStorageManager.js +25 -1
  56. package/dist/swapper/Swapper.d.ts +303 -222
  57. package/dist/swapper/Swapper.js +376 -344
  58. package/dist/swapper/SwapperFactory.d.ts +41 -17
  59. package/dist/swapper/SwapperFactory.js +23 -2
  60. package/dist/swapper/SwapperUtils.d.ts +75 -28
  61. package/dist/swapper/SwapperUtils.js +107 -60
  62. package/dist/swapper/SwapperWithChain.d.ts +286 -91
  63. package/dist/swapper/SwapperWithChain.js +218 -64
  64. package/dist/swapper/SwapperWithSigner.d.ts +229 -80
  65. package/dist/swapper/SwapperWithSigner.js +190 -44
  66. package/dist/swaps/IAddressSwap.d.ts +10 -1
  67. package/dist/swaps/IAddressSwap.js +2 -1
  68. package/dist/swaps/IBTCWalletSwap.d.ts +24 -6
  69. package/dist/swaps/IBTCWalletSwap.js +2 -1
  70. package/dist/swaps/IClaimableSwap.d.ts +36 -4
  71. package/dist/swaps/IClaimableSwap.js +2 -1
  72. package/dist/swaps/IClaimableSwapWrapper.d.ts +11 -1
  73. package/dist/swaps/IRefundableSwap.d.ts +29 -3
  74. package/dist/swaps/IRefundableSwap.js +2 -1
  75. package/dist/swaps/ISwap.d.ts +159 -21
  76. package/dist/swaps/ISwap.js +90 -33
  77. package/dist/swaps/ISwapWithGasDrop.d.ts +6 -0
  78. package/dist/swaps/ISwapWithGasDrop.js +1 -0
  79. package/dist/swaps/ISwapWrapper.d.ts +157 -48
  80. package/dist/swaps/ISwapWrapper.js +130 -72
  81. package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +49 -6
  82. package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +22 -12
  83. package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +65 -12
  84. package/dist/swaps/escrow_swaps/IEscrowSwap.js +38 -19
  85. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +39 -9
  86. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +30 -21
  87. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +31 -15
  88. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +33 -18
  89. package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +94 -29
  90. package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +90 -27
  91. package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +22 -9
  92. package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +24 -11
  93. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +275 -58
  94. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +516 -239
  95. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +76 -25
  96. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +131 -49
  97. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +311 -51
  98. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +542 -193
  99. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +87 -26
  100. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +147 -58
  101. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +209 -53
  102. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +449 -242
  103. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +77 -23
  104. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +116 -46
  105. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +197 -56
  106. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +326 -189
  107. package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +30 -5
  108. package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +44 -19
  109. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +60 -19
  110. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +74 -31
  111. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +76 -50
  112. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +106 -101
  113. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +36 -13
  114. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +65 -19
  115. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +46 -17
  116. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +82 -27
  117. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +328 -92
  118. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +460 -219
  119. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +76 -24
  120. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +244 -124
  121. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +146 -18
  122. package/dist/swaps/trusted/ln/LnForGasSwap.js +173 -43
  123. package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +29 -10
  124. package/dist/swaps/trusted/ln/LnForGasWrapper.js +30 -11
  125. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +200 -47
  126. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +230 -78
  127. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +34 -12
  128. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +33 -14
  129. package/dist/types/AmountData.d.ts +2 -1
  130. package/dist/types/CustomPriceFunction.d.ts +7 -1
  131. package/dist/types/SwapExecutionAction.d.ts +74 -4
  132. package/dist/types/SwapWithSigner.d.ts +4 -1
  133. package/dist/types/SwapWithSigner.js +5 -2
  134. package/dist/types/Token.d.ts +11 -5
  135. package/dist/types/Token.js +6 -3
  136. package/dist/types/TokenAmount.d.ts +3 -0
  137. package/dist/types/TokenAmount.js +2 -0
  138. package/dist/types/fees/Fee.d.ts +2 -1
  139. package/dist/types/fees/FeeBreakdown.d.ts +2 -1
  140. package/dist/types/fees/PercentagePPM.d.ts +2 -0
  141. package/dist/types/fees/PercentagePPM.js +1 -0
  142. package/dist/types/lnurl/LNURLPay.d.ts +14 -6
  143. package/dist/types/lnurl/LNURLPay.js +6 -2
  144. package/dist/types/lnurl/LNURLWithdraw.d.ts +12 -5
  145. package/dist/types/lnurl/LNURLWithdraw.js +6 -2
  146. package/dist/types/wallets/LightningInvoiceCreateService.d.ts +20 -0
  147. package/dist/types/wallets/LightningInvoiceCreateService.js +15 -0
  148. package/dist/types/wallets/MinimalBitcoinWalletInterface.d.ts +3 -1
  149. package/dist/types/wallets/MinimalLightningNetworkWalletInterface.d.ts +3 -1
  150. package/dist/utils/BitcoinUtils.d.ts +1 -0
  151. package/dist/utils/BitcoinUtils.js +5 -1
  152. package/dist/utils/SwapUtils.d.ts +56 -1
  153. package/dist/utils/SwapUtils.js +53 -1
  154. package/dist/utils/TokenUtils.d.ts +10 -2
  155. package/dist/utils/TokenUtils.js +12 -4
  156. package/package.json +3 -3
  157. package/src/bitcoin/wallet/BitcoinWallet.ts +41 -5
  158. package/src/bitcoin/wallet/IBitcoinWallet.ts +57 -2
  159. package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +42 -6
  160. package/src/enums/FeeType.ts +7 -0
  161. package/src/enums/SwapAmountType.ts +7 -0
  162. package/src/enums/SwapDirection.ts +7 -0
  163. package/src/enums/SwapType.ts +62 -2
  164. package/src/errors/IntermediaryError.ts +4 -0
  165. package/src/errors/RequestError.ts +15 -1
  166. package/src/errors/UserError.ts +1 -0
  167. package/src/index.ts +6 -5
  168. package/src/intermediaries/Intermediary.ts +57 -10
  169. package/src/intermediaries/IntermediaryDiscovery.ts +60 -27
  170. package/src/prices/RedundantSwapPrice.ts +24 -4
  171. package/src/prices/SingleSwapPrice.ts +10 -7
  172. package/src/prices/SwapPriceWithChain.ts +59 -21
  173. package/src/prices/abstract/ISwapPrice.ts +114 -65
  174. package/src/prices/providers/BinancePriceProvider.ts +7 -0
  175. package/src/prices/providers/CoinGeckoPriceProvider.ts +6 -0
  176. package/src/prices/providers/CoinPaprikaPriceProvider.ts +6 -0
  177. package/src/prices/providers/CustomPriceProvider.ts +11 -0
  178. package/src/prices/providers/KrakenPriceProvider.ts +9 -0
  179. package/src/prices/providers/OKXPriceProvider.ts +6 -0
  180. package/src/prices/providers/abstract/ExchangePriceProvider.ts +3 -0
  181. package/src/storage/IUnifiedStorage.ts +19 -7
  182. package/src/storage/UnifiedSwapStorage.ts +33 -3
  183. package/src/storage-browser/IndexedDBUnifiedStorage.ts +31 -8
  184. package/src/storage-browser/LocalStorageManager.ts +25 -1
  185. package/src/swapper/Swapper.ts +513 -379
  186. package/src/swapper/SwapperFactory.ts +44 -21
  187. package/src/swapper/SwapperUtils.ts +107 -60
  188. package/src/swapper/SwapperWithChain.ts +320 -81
  189. package/src/swapper/SwapperWithSigner.ts +263 -56
  190. package/src/swaps/IAddressSwap.ts +11 -1
  191. package/src/swaps/IBTCWalletSwap.ts +24 -8
  192. package/src/swaps/IClaimableSwap.ts +39 -4
  193. package/src/swaps/IClaimableSwapWrapper.ts +11 -2
  194. package/src/swaps/IRefundableSwap.ts +32 -3
  195. package/src/swaps/ISwap.ts +221 -82
  196. package/src/swaps/ISwapWithGasDrop.ts +6 -0
  197. package/src/swaps/ISwapWrapper.ts +212 -94
  198. package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +62 -18
  199. package/src/swaps/escrow_swaps/IEscrowSwap.ts +83 -37
  200. package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +61 -30
  201. package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +37 -19
  202. package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +120 -51
  203. package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +24 -11
  204. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +559 -256
  205. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +155 -61
  206. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +590 -226
  207. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +177 -74
  208. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +470 -243
  209. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +141 -59
  210. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +352 -193
  211. package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +48 -23
  212. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +86 -39
  213. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +110 -110
  214. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +88 -33
  215. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +101 -31
  216. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +534 -263
  217. package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +289 -148
  218. package/src/swaps/trusted/ln/LnForGasSwap.ts +184 -45
  219. package/src/swaps/trusted/ln/LnForGasWrapper.ts +34 -15
  220. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +260 -86
  221. package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +41 -19
  222. package/src/types/AmountData.ts +2 -1
  223. package/src/types/CustomPriceFunction.ts +7 -1
  224. package/src/types/SwapExecutionAction.ts +84 -5
  225. package/src/types/SwapWithSigner.ts +7 -3
  226. package/src/types/Token.ts +12 -5
  227. package/src/types/TokenAmount.ts +3 -0
  228. package/src/types/fees/Fee.ts +2 -1
  229. package/src/types/fees/FeeBreakdown.ts +2 -1
  230. package/src/types/fees/PercentagePPM.ts +2 -0
  231. package/src/types/lnurl/LNURLPay.ts +14 -6
  232. package/src/types/lnurl/LNURLWithdraw.ts +12 -5
  233. package/src/types/wallets/LightningInvoiceCreateService.ts +26 -0
  234. package/src/types/wallets/MinimalBitcoinWalletInterface.ts +3 -1
  235. package/src/types/wallets/MinimalLightningNetworkWalletInterface.ts +3 -1
  236. package/src/utils/BitcoinUtils.ts +5 -0
  237. package/src/utils/SwapUtils.ts +61 -1
  238. package/src/utils/TokenUtils.ts +12 -4
  239. package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +0 -68
  240. package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +0 -2
  241. package/dist/bitcoin/LightningNetworkApi.d.ts +0 -12
  242. package/dist/bitcoin/LightningNetworkApi.js +0 -2
  243. package/dist/bitcoin/mempool/MempoolApi.d.ts +0 -350
  244. package/dist/bitcoin/mempool/MempoolApi.js +0 -311
  245. package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +0 -44
  246. package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +0 -48
  247. package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +0 -119
  248. package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +0 -361
  249. package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +0 -22
  250. package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +0 -105
  251. package/dist/errors/PaymentAuthError.d.ts +0 -11
  252. package/dist/errors/PaymentAuthError.js +0 -23
  253. package/src/errors/PaymentAuthError.ts +0 -26
@@ -20,6 +20,7 @@ const utils_1 = require("@scure/btc-signer/utils");
20
20
  const UnifiedSwapStorage_1 = require("../storage/UnifiedSwapStorage");
21
21
  const UnifiedSwapEventListener_1 = require("../events/UnifiedSwapEventListener");
22
22
  const SpvFromBTCWrapper_1 = require("../swaps/spv_swaps/SpvFromBTCWrapper");
23
+ const SpvFromBTCSwap_1 = require("../swaps/spv_swaps/SpvFromBTCSwap");
23
24
  const SwapperUtils_1 = require("./SwapperUtils");
24
25
  const FromBTCLNAutoWrapper_1 = require("../swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper");
25
26
  const UserError_1 = require("../errors/UserError");
@@ -33,8 +34,11 @@ const LNURLWithdraw_1 = require("../types/lnurl/LNURLWithdraw");
33
34
  const LNURLPay_1 = require("../types/lnurl/LNURLPay");
34
35
  const RetryUtils_1 = require("../utils/RetryUtils");
35
36
  const btc_mempool_1 = require("@atomiqlabs/btc-mempool");
37
+ const IEscrowSwap_1 = require("../swaps/escrow_swaps/IEscrowSwap");
38
+ const LightningInvoiceCreateService_1 = require("../types/wallets/LightningInvoiceCreateService");
36
39
  /**
37
- * Core orchestrator for all swap operations with multi-chain support
40
+ * Core orchestrator for all atomiq swap operations
41
+ *
38
42
  * @category Core
39
43
  */
40
44
  class Swapper extends events_1.EventEmitter {
@@ -42,55 +46,26 @@ class Swapper extends events_1.EventEmitter {
42
46
  super();
43
47
  this.logger = (0, Logger_1.getLogger)(this.constructor.name + ": ");
44
48
  this.initialized = false;
45
- this.SwapTypeInfo = {
46
- [SwapType_1.SwapType.TO_BTC]: {
47
- requiresInputWallet: true,
48
- requiresOutputWallet: false,
49
- supportsGasDrop: false
50
- },
51
- [SwapType_1.SwapType.TO_BTCLN]: {
52
- requiresInputWallet: true,
53
- requiresOutputWallet: false,
54
- supportsGasDrop: false
55
- },
56
- [SwapType_1.SwapType.FROM_BTC]: {
57
- requiresInputWallet: false,
58
- requiresOutputWallet: true,
59
- supportsGasDrop: false
60
- },
61
- [SwapType_1.SwapType.FROM_BTCLN]: {
62
- requiresInputWallet: false,
63
- requiresOutputWallet: true,
64
- supportsGasDrop: false
65
- },
66
- [SwapType_1.SwapType.SPV_VAULT_FROM_BTC]: {
67
- requiresInputWallet: true,
68
- requiresOutputWallet: false,
69
- supportsGasDrop: true
70
- },
71
- [SwapType_1.SwapType.FROM_BTCLN_AUTO]: {
72
- requiresInputWallet: false,
73
- requiresOutputWallet: false,
74
- supportsGasDrop: true
75
- },
76
- [SwapType_1.SwapType.TRUSTED_FROM_BTC]: {
77
- requiresInputWallet: false,
78
- requiresOutputWallet: false,
79
- supportsGasDrop: false
80
- },
81
- [SwapType_1.SwapType.TRUSTED_FROM_BTCLN]: {
82
- requiresInputWallet: false,
83
- requiresOutputWallet: false,
84
- supportsGasDrop: false
85
- }
86
- };
49
+ /**
50
+ * Helper information about various swap protocol and their features:
51
+ * - `requiresInputWallet`: Whether a swap requires a connected wallet on the input chain able to sign
52
+ * arbitrary transaction
53
+ * - `requiresOutputWallet`: Whether a swap requires a connected wallet on the output chain able to sign
54
+ * arbitrary transactions
55
+ * - `supportsGasDrop`: Whether a swap supports the "gas drop" feature, allowing to user to receive a small
56
+ * amount of native token as part of the swap when swapping to smart chains
57
+ *
58
+ * Uses a `Record` type here, use the {@link SwapProtocolInfo} import for a literal readonly type, with
59
+ * pre-filled exact values in the type.
60
+ */
61
+ this.SwapTypeInfo = SwapUtils_1.SwapProtocolInfo;
87
62
  const storagePrefix = options?.storagePrefix ?? "atomiq-";
88
63
  options ??= {};
89
64
  options.bitcoinNetwork = options.bitcoinNetwork == null ? base_1.BitcoinNetwork.TESTNET : options.bitcoinNetwork;
90
65
  const swapStorage = options.swapStorage ??= (name) => new IndexedDBUnifiedStorage_1.IndexedDBUnifiedStorage(name);
91
66
  this.options = options;
92
- this._bitcoinNetwork = options.bitcoinNetwork;
93
- this.bitcoinNetwork = options.bitcoinNetwork === base_1.BitcoinNetwork.MAINNET ? utils_1.NETWORK :
67
+ this.bitcoinNetwork = options.bitcoinNetwork;
68
+ this._btcNetwork = options.bitcoinNetwork === base_1.BitcoinNetwork.MAINNET ? utils_1.NETWORK :
94
69
  (options.bitcoinNetwork === base_1.BitcoinNetwork.TESTNET || options.bitcoinNetwork === base_1.BitcoinNetwork.TESTNET4) ? utils_1.TEST_NETWORK : {
95
70
  bech32: 'bcrt',
96
71
  pubKeyHash: 111,
@@ -99,17 +74,16 @@ class Swapper extends events_1.EventEmitter {
99
74
  };
100
75
  this.Utils = new SwapperUtils_1.SwapperUtils(this);
101
76
  this.prices = pricing;
102
- this.bitcoinRpc = bitcoinRpc;
103
- this.mempoolApi = bitcoinRpc.api;
77
+ this._bitcoinRpc = bitcoinRpc;
104
78
  this.messenger = messenger;
105
- this.tokens = {};
106
- this.tokensByTicker = {};
79
+ this._tokens = {};
80
+ this._tokensByTicker = {};
107
81
  for (let tokenData of tokens) {
108
82
  for (let chainId in tokenData.chains) {
109
83
  const chainData = tokenData.chains[chainId];
110
- this.tokens[chainId] ??= {};
111
- this.tokensByTicker[chainId] ??= {};
112
- this.tokens[chainId][chainData.address] = this.tokensByTicker[chainId][tokenData.ticker] = {
84
+ this._tokens[chainId] ??= {};
85
+ this._tokensByTicker[chainId] ??= {};
86
+ this._tokens[chainId][chainData.address] = this._tokensByTicker[chainId][tokenData.ticker] = {
113
87
  chain: "SC",
114
88
  chainId,
115
89
  ticker: tokenData.ticker,
@@ -123,7 +97,7 @@ class Swapper extends events_1.EventEmitter {
123
97
  this.swapStateListener = (swap) => {
124
98
  this.emit("swapState", swap);
125
99
  };
126
- this.chains = (0, Utils_1.objectMap)(chainsData, (chainData, key) => {
100
+ this._chains = (0, Utils_1.objectMap)(chainsData, (chainData, key) => {
127
101
  const { swapContract, chainEvents, btcRelay, chainInterface, spvVaultContract, spvVaultWithdrawalDataConstructor } = chainData;
128
102
  const synchronizer = new btc_mempool_1.MempoolBtcRelaySynchronizer(btcRelay, bitcoinRpc);
129
103
  const storageHandler = swapStorage(storagePrefix + chainData.chainId);
@@ -134,20 +108,20 @@ class Swapper extends events_1.EventEmitter {
134
108
  getRequestTimeout: this.options.getRequestTimeout,
135
109
  postRequestTimeout: this.options.postRequestTimeout,
136
110
  });
137
- wrappers[SwapType_1.SwapType.TO_BTC] = new ToBTCWrapper_1.ToBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, tokens, chainData.swapDataConstructor, this.bitcoinRpc, {
111
+ wrappers[SwapType_1.SwapType.TO_BTC] = new ToBTCWrapper_1.ToBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, tokens, chainData.swapDataConstructor, this._bitcoinRpc, {
138
112
  getRequestTimeout: this.options.getRequestTimeout,
139
113
  postRequestTimeout: this.options.postRequestTimeout,
140
- bitcoinNetwork: this.bitcoinNetwork
114
+ bitcoinNetwork: this._btcNetwork
141
115
  });
142
116
  wrappers[SwapType_1.SwapType.FROM_BTCLN] = new FromBTCLNWrapper_1.FromBTCLNWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, tokens, chainData.swapDataConstructor, bitcoinRpc, {
143
117
  getRequestTimeout: this.options.getRequestTimeout,
144
118
  postRequestTimeout: this.options.postRequestTimeout,
145
- unsafeSkipLnNodeCheck: this._bitcoinNetwork === base_1.BitcoinNetwork.TESTNET4 || this._bitcoinNetwork === base_1.BitcoinNetwork.REGTEST
119
+ unsafeSkipLnNodeCheck: this.bitcoinNetwork === base_1.BitcoinNetwork.TESTNET4 || this.bitcoinNetwork === base_1.BitcoinNetwork.REGTEST
146
120
  });
147
- wrappers[SwapType_1.SwapType.FROM_BTC] = new FromBTCWrapper_1.FromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, tokens, chainData.swapDataConstructor, btcRelay, synchronizer, this.bitcoinRpc, {
121
+ wrappers[SwapType_1.SwapType.FROM_BTC] = new FromBTCWrapper_1.FromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, tokens, chainData.swapDataConstructor, btcRelay, synchronizer, this._bitcoinRpc, {
148
122
  getRequestTimeout: this.options.getRequestTimeout,
149
123
  postRequestTimeout: this.options.postRequestTimeout,
150
- bitcoinNetwork: this.bitcoinNetwork
124
+ bitcoinNetwork: this._btcNetwork
151
125
  });
152
126
  wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTCLN] = new LnForGasWrapper_1.LnForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, tokens, {
153
127
  getRequestTimeout: this.options.getRequestTimeout,
@@ -156,20 +130,20 @@ class Swapper extends events_1.EventEmitter {
156
130
  wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTC] = new OnchainForGasWrapper_1.OnchainForGasWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, pricing, tokens, bitcoinRpc, {
157
131
  getRequestTimeout: this.options.getRequestTimeout,
158
132
  postRequestTimeout: this.options.postRequestTimeout,
159
- bitcoinNetwork: this.bitcoinNetwork
133
+ bitcoinNetwork: this._btcNetwork
160
134
  });
161
135
  if (spvVaultContract != null) {
162
136
  wrappers[SwapType_1.SwapType.SPV_VAULT_FROM_BTC] = new SpvFromBTCWrapper_1.SpvFromBTCWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, spvVaultContract, pricing, tokens, spvVaultWithdrawalDataConstructor, btcRelay, synchronizer, bitcoinRpc, {
163
137
  getRequestTimeout: this.options.getRequestTimeout,
164
138
  postRequestTimeout: this.options.postRequestTimeout,
165
- bitcoinNetwork: this.bitcoinNetwork
139
+ bitcoinNetwork: this._btcNetwork
166
140
  });
167
141
  }
168
142
  if (swapContract.supportsInitWithoutClaimer) {
169
143
  wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO] = new FromBTCLNAutoWrapper_1.FromBTCLNAutoWrapper(key, unifiedSwapStorage, unifiedChainEvents, chainInterface, swapContract, pricing, tokens, chainData.swapDataConstructor, bitcoinRpc, this.messenger, {
170
144
  getRequestTimeout: this.options.getRequestTimeout,
171
145
  postRequestTimeout: this.options.postRequestTimeout,
172
- unsafeSkipLnNodeCheck: this._bitcoinNetwork === base_1.BitcoinNetwork.TESTNET4 || this._bitcoinNetwork === base_1.BitcoinNetwork.REGTEST
146
+ unsafeSkipLnNodeCheck: this.bitcoinNetwork === base_1.BitcoinNetwork.TESTNET4 || this.bitcoinNetwork === base_1.BitcoinNetwork.REGTEST
173
147
  });
174
148
  }
175
149
  Object.keys(wrappers).forEach(key => wrappers[key].events.on("swapState", this.swapStateListener));
@@ -177,7 +151,7 @@ class Swapper extends events_1.EventEmitter {
177
151
  const wrapper = wrappers[val.type];
178
152
  if (wrapper == null)
179
153
  return null;
180
- return new wrapper.swapDeserializer(wrapper, val);
154
+ return new wrapper._swapDeserializer(wrapper, val);
181
155
  };
182
156
  return {
183
157
  chainEvents,
@@ -241,17 +215,17 @@ class Swapper extends events_1.EventEmitter {
241
215
  await automaticClockDriftCorrectionPromise;
242
216
  }
243
217
  const chainPromises = [];
244
- for (let chainIdentifier in this.chains) {
218
+ for (let chainIdentifier in this._chains) {
245
219
  chainPromises.push((async () => {
246
- const { swapContract, unifiedChainEvents, unifiedSwapStorage, wrappers, reviver } = this.chains[chainIdentifier];
220
+ const { swapContract, unifiedChainEvents, unifiedSwapStorage, wrappers, reviver } = this._chains[chainIdentifier];
247
221
  await swapContract.start();
248
222
  this.logger.debug("init(): Intialized swap contract: " + chainIdentifier);
249
223
  await unifiedSwapStorage.init();
250
224
  if (unifiedSwapStorage.storage instanceof IndexedDBUnifiedStorage_1.IndexedDBUnifiedStorage) {
251
225
  //Try to migrate the data here
252
226
  const storagePrefix = chainIdentifier === "SOLANA" ?
253
- "SOLv4-" + this._bitcoinNetwork + "-Swaps-" :
254
- "atomiqsdk-" + this._bitcoinNetwork + chainIdentifier + "-Swaps-";
227
+ "SOLv4-" + this.bitcoinNetwork + "-Swaps-" :
228
+ "atomiqsdk-" + this.bitcoinNetwork + chainIdentifier + "-Swaps-";
255
229
  await unifiedSwapStorage.storage.tryMigrate([
256
230
  [storagePrefix + "FromBTC", SwapType_1.SwapType.FROM_BTC],
257
231
  [storagePrefix + "FromBTCLN", SwapType_1.SwapType.FROM_BTCLN],
@@ -259,9 +233,9 @@ class Swapper extends events_1.EventEmitter {
259
233
  [storagePrefix + "ToBTCLN", SwapType_1.SwapType.TO_BTCLN]
260
234
  ], (obj) => {
261
235
  const swap = reviver(obj);
262
- if (swap.randomNonce == null) {
236
+ if (swap._randomNonce == null) {
263
237
  const oldIdentifierHash = swap.getId();
264
- swap.randomNonce = (0, Utils_1.randomBytes)(16).toString("hex");
238
+ swap._randomNonce = (0, Utils_1.randomBytes)(16).toString("hex");
265
239
  const newIdentifierHash = swap.getId();
266
240
  this.logger.info("init(): Found older swap version without randomNonce, replacing, old hash: " + oldIdentifierHash +
267
241
  " new hash: " + newIdentifierHash);
@@ -309,8 +283,8 @@ class Swapper extends events_1.EventEmitter {
309
283
  async stop() {
310
284
  if (this.initPromise)
311
285
  await this.initPromise;
312
- for (let chainIdentifier in this.chains) {
313
- const { wrappers, unifiedChainEvents } = this.chains[chainIdentifier];
286
+ for (let chainIdentifier in this._chains) {
287
+ const { wrappers, unifiedChainEvents } = this._chains[chainIdentifier];
314
288
  for (let key in wrappers) {
315
289
  const wrapper = wrappers[key];
316
290
  wrapper.events.removeListener("swapState", this.swapStateListener);
@@ -336,7 +310,7 @@ class Swapper extends events_1.EventEmitter {
336
310
  async createSwap(chainIdentifier, create, amountData, swapType, maxWaitTimeMS = 2000) {
337
311
  if (!this.initialized)
338
312
  throw new Error("Swapper not initialized, init first with swapper.init()!");
339
- if (this.chains[chainIdentifier] == null)
313
+ if (this._chains[chainIdentifier] == null)
340
314
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
341
315
  let candidates;
342
316
  const inBtc = swapType === SwapType_1.SwapType.TO_BTCLN || swapType === SwapType_1.SwapType.TO_BTC ? !amountData.exactIn : amountData.exactIn;
@@ -374,7 +348,7 @@ class Swapper extends events_1.EventEmitter {
374
348
  }
375
349
  const abortController = new AbortController();
376
350
  this.logger.debug("createSwap() Swap candidates: ", candidates.map(lp => lp.url).join());
377
- const quotePromises = await create(candidates, abortController.signal, this.chains[chainIdentifier]);
351
+ const quotePromises = await create(candidates, abortController.signal, this._chains[chainIdentifier]);
378
352
  const promiseAll = new Promise((resolve, reject) => {
379
353
  let min;
380
354
  let max;
@@ -480,28 +454,28 @@ class Swapper extends events_1.EventEmitter {
480
454
  }
481
455
  }
482
456
  /**
483
- * Creates To BTC swap
457
+ * Creates Smart chain -> Bitcoin ({@link SwapType.TO_BTC}) swap
484
458
  *
485
- * @param chainIdentifier
486
- * @param signer
487
- * @param tokenAddress Token address to pay with
488
- * @param address Recipient's bitcoin address
489
- * @param amount Amount to send in satoshis (bitcoin's smallest denomination)
490
- * @param exactIn Whether to use exact in instead of exact out
491
- * @param additionalParams Additional parameters sent to the LP when creating the swap
492
- * @param options
459
+ * @param chainIdentifier Chain identifier string of the source smart chain
460
+ * @param signer Signer's address on the source chain
461
+ * @param tokenAddress Token address to pay with
462
+ * @param address Recipient's bitcoin address
463
+ * @param amount Amount to send in token based units (if `exactIn=true`) or receive in satoshis (if `exactIn=false`)
464
+ * @param exactIn Whether to use exact in instead of exact out
465
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
466
+ * @param options Additional options for the swap
493
467
  */
494
468
  createToBTCSwap(chainIdentifier, signer, tokenAddress, address, amount, exactIn = false, additionalParams = this.options.defaultAdditionalParameters, options) {
495
- if (this.chains[chainIdentifier] == null)
469
+ if (this._chains[chainIdentifier] == null)
496
470
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
497
471
  if (address.startsWith("bitcoin:")) {
498
472
  address = address.substring(8).split("?")[0];
499
473
  }
500
474
  if (!this.Utils.isValidBitcoinAddress(address))
501
475
  throw new Error("Invalid bitcoin address");
502
- if (!this.chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
476
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
503
477
  throw new Error("Invalid " + chainIdentifier + " address");
504
- signer = this.chains[chainIdentifier].chainInterface.normalizeAddress(signer);
478
+ signer = this._chains[chainIdentifier].chainInterface.normalizeAddress(signer);
505
479
  options ??= {};
506
480
  options.confirmationTarget ??= 3;
507
481
  options.confirmations ??= 2;
@@ -513,26 +487,27 @@ class Swapper extends events_1.EventEmitter {
513
487
  return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => Promise.resolve(chain.wrappers[SwapType_1.SwapType.TO_BTC].create(signer, address, amountData, candidates, options, additionalParams, abortSignal)), amountData, SwapType_1.SwapType.TO_BTC);
514
488
  }
515
489
  /**
516
- * Creates To BTCLN swap
490
+ * Creates Smart chain -> Bitcoin Lightning ({@link SwapType.TO_BTCLN}) swap
517
491
  *
518
- * @param chainIdentifier
519
- * @param signer
520
- * @param tokenAddress Token address to pay with
521
- * @param paymentRequest BOLT11 lightning network invoice to be paid (needs to have a fixed amount)
522
- * @param additionalParams Additional parameters sent to the LP when creating the swap
523
- * @param options
492
+ * @param chainIdentifier Chain identifier string of the source smart chain
493
+ * @param signer Signer's address on the source chain
494
+ * @param tokenAddress Token address to pay with
495
+ * @param paymentRequest BOLT11 lightning network invoice to be paid (needs to have a fixed amount), and the swap
496
+ * amount is taken from this fixed amount, hence only exact output swaps are supported
497
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
498
+ * @param options Additional options for the swap
524
499
  */
525
500
  async createToBTCLNSwap(chainIdentifier, signer, tokenAddress, paymentRequest, additionalParams = this.options.defaultAdditionalParameters, options) {
526
- if (this.chains[chainIdentifier] == null)
501
+ if (this._chains[chainIdentifier] == null)
527
502
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
528
503
  options ??= {};
529
504
  if (paymentRequest.startsWith("lightning:"))
530
505
  paymentRequest = paymentRequest.substring(10);
531
506
  if (!this.Utils.isValidLightningInvoice(paymentRequest))
532
507
  throw new Error("Invalid lightning network invoice");
533
- if (!this.chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
508
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
534
509
  throw new Error("Invalid " + chainIdentifier + " address");
535
- signer = this.chains[chainIdentifier].chainInterface.normalizeAddress(signer);
510
+ signer = this._chains[chainIdentifier].chainInterface.normalizeAddress(signer);
536
511
  const parsedPR = (0, bolt11_1.decode)(paymentRequest);
537
512
  if (parsedPR.millisatoshis == null)
538
513
  throw new Error("Invalid lightning network invoice, no msat value field!");
@@ -545,25 +520,25 @@ class Swapper extends events_1.EventEmitter {
545
520
  return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.TO_BTCLN].create(signer, paymentRequest, amountData, candidates, options, additionalParams, abortSignal), amountData, SwapType_1.SwapType.TO_BTCLN);
546
521
  }
547
522
  /**
548
- * Creates To BTCLN swap via LNURL-pay
523
+ * Creates Smart chain -> Bitcoin Lightning ({@link SwapType.TO_BTCLN}) swap via LNURL-pay link
549
524
  *
550
- * @param chainIdentifier
551
- * @param signer
552
- * @param tokenAddress Token address to pay with
553
- * @param lnurlPay LNURL-pay link to use for the payment
554
- * @param amount Amount to be paid in sats
555
- * @param exactIn Whether to do an exact in swap instead of exact out
556
- * @param additionalParams Additional parameters sent to the LP when creating the swap
557
- * @param options
525
+ * @param chainIdentifier Chain identifier string of the source smart chain
526
+ * @param signer Signer's address on the source chain
527
+ * @param tokenAddress Token address to pay with
528
+ * @param lnurlPay LNURL-pay link to use for the payment
529
+ * @param amount Amount to send in token based units (if `exactIn=true`) or receive in satoshis (if `exactIn=false`)
530
+ * @param exactIn Whether to do an exact in swap instead of exact out
531
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
532
+ * @param options Additional options for the swap
558
533
  */
559
534
  async createToBTCLNSwapViaLNURL(chainIdentifier, signer, tokenAddress, lnurlPay, amount, exactIn = false, additionalParams = this.options.defaultAdditionalParameters, options) {
560
- if (this.chains[chainIdentifier] == null)
535
+ if (this._chains[chainIdentifier] == null)
561
536
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
562
537
  if (typeof (lnurlPay) === "string" && !this.Utils.isValidLNURL(lnurlPay))
563
538
  throw new Error("Invalid LNURL-pay link");
564
- if (!this.chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
539
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
565
540
  throw new Error("Invalid " + chainIdentifier + " address");
566
- signer = this.chains[chainIdentifier].chainInterface.normalizeAddress(signer);
541
+ signer = this._chains[chainIdentifier].chainInterface.normalizeAddress(signer);
567
542
  const amountData = {
568
543
  amount,
569
544
  token: tokenAddress,
@@ -574,23 +549,23 @@ class Swapper extends events_1.EventEmitter {
574
549
  return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.TO_BTCLN].createViaLNURL(signer, typeof (lnurlPay) === "string" ? (lnurlPay.startsWith("lightning:") ? lnurlPay.substring(10) : lnurlPay) : lnurlPay.params, amountData, candidates, options, additionalParams, abortSignal), amountData, SwapType_1.SwapType.TO_BTCLN);
575
550
  }
576
551
  /**
577
- * Creates To BTCLN swap via InvoiceCreationService
552
+ * Creates Smart chain -> Bitcoin Lightning ({@link SwapType.TO_BTCLN}) swap via {@link LightningInvoiceCreateService}
578
553
  *
579
- * @param chainIdentifier
580
- * @param signer
581
- * @param tokenAddress Token address to pay with
582
- * @param service Invoice create service object which facilitates the creation of fixed amount LN invoices
583
- * @param amount Amount to be paid in sats
584
- * @param exactIn Whether to do an exact in swap instead of exact out
585
- * @param additionalParams Additional parameters sent to the LP when creating the swap
586
- * @param options
554
+ * @param chainIdentifier Chain identifier string of the source smart chain
555
+ * @param signer Signer's address on the source chain
556
+ * @param tokenAddress Token address to pay with
557
+ * @param service Invoice create service object which facilitates the creation of fixed amount LN invoices
558
+ * @param amount Amount to send in token based units (if `exactIn=true`) or receive in satoshis (if `exactIn=false`)
559
+ * @param exactIn Whether to do an exact in swap instead of exact out
560
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
561
+ * @param options Additional options for the swap
587
562
  */
588
563
  async createToBTCLNSwapViaInvoiceCreateService(chainIdentifier, signer, tokenAddress, service, amount, exactIn = false, additionalParams = this.options.defaultAdditionalParameters, options) {
589
- if (this.chains[chainIdentifier] == null)
564
+ if (this._chains[chainIdentifier] == null)
590
565
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
591
- if (!this.chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
566
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
592
567
  throw new Error("Invalid " + chainIdentifier + " address");
593
- signer = this.chains[chainIdentifier].chainInterface.normalizeAddress(signer);
568
+ signer = this._chains[chainIdentifier].chainInterface.normalizeAddress(signer);
594
569
  options ??= {};
595
570
  const amountData = {
596
571
  amount,
@@ -601,200 +576,202 @@ class Swapper extends events_1.EventEmitter {
601
576
  return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.TO_BTCLN].createViaInvoiceCreateService(signer, Promise.resolve(service), amountData, candidates, options, additionalParams, abortSignal), amountData, SwapType_1.SwapType.TO_BTCLN);
602
577
  }
603
578
  /**
604
- * Creates From BTC swap
579
+ * Creates Bitcoin -> Smart chain ({@link SwapType.SPV_VAULT_FROM_BTC}) swap
605
580
  *
606
- * @param chainIdentifier
607
- * @param signer
608
- * @param tokenAddress Token address to receive
609
- * @param amount Amount to receive, in satoshis (bitcoin's smallest denomination)
610
- * @param exactOut Whether to use a exact out instead of exact in
611
- * @param additionalParams Additional parameters sent to the LP when creating the swap
612
- * @param options
581
+ * @param chainIdentifier Chain identifier string of the destination smart chain
582
+ * @param recipient Recipient address on the destination chain
583
+ * @param tokenAddress Token address to receive
584
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
585
+ * @param exactOut Whether to use a exact out instead of exact in
586
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
587
+ * @param options Additional options for the swap
613
588
  */
614
- async createFromBTCSwapNew(chainIdentifier, signer, tokenAddress, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters, options) {
615
- if (this.chains[chainIdentifier] == null)
589
+ async createFromBTCSwapNew(chainIdentifier, recipient, tokenAddress, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters, options) {
590
+ if (this._chains[chainIdentifier] == null)
616
591
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
617
- if (!this.chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
592
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(recipient, true))
618
593
  throw new Error("Invalid " + chainIdentifier + " address");
619
- signer = this.chains[chainIdentifier].chainInterface.normalizeAddress(signer);
594
+ recipient = this._chains[chainIdentifier].chainInterface.normalizeAddress(recipient);
620
595
  const amountData = {
621
596
  amount,
622
597
  token: tokenAddress,
623
598
  exactIn: !exactOut
624
599
  };
625
- return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => Promise.resolve(chain.wrappers[SwapType_1.SwapType.SPV_VAULT_FROM_BTC].create(signer, amountData, candidates, options, additionalParams, abortSignal)), amountData, SwapType_1.SwapType.SPV_VAULT_FROM_BTC);
600
+ return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => Promise.resolve(chain.wrappers[SwapType_1.SwapType.SPV_VAULT_FROM_BTC].create(recipient, amountData, candidates, options, additionalParams, abortSignal)), amountData, SwapType_1.SwapType.SPV_VAULT_FROM_BTC);
626
601
  }
627
602
  /**
628
- * Creates From BTC swap
603
+ * Creates LEGACY Bitcoin -> Smart chain ({@link SwapType.FROM_BTC}) swap
629
604
  *
630
- * @param chainIdentifier
631
- * @param signer
632
- * @param tokenAddress Token address to receive
633
- * @param amount Amount to receive, in satoshis (bitcoin's smallest denomination)
634
- * @param exactOut Whether to use a exact out instead of exact in
635
- * @param additionalParams Additional parameters sent to the LP when creating the swap
636
- * @param options
605
+ * @param chainIdentifier Chain identifier string of the destination smart chain
606
+ * @param recipient Recipient address on the destination chain
607
+ * @param tokenAddress Token address to receive
608
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
609
+ * @param exactOut Whether to use a exact out instead of exact in
610
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
611
+ * @param options Additional options for the swap
637
612
  */
638
- async createFromBTCSwap(chainIdentifier, signer, tokenAddress, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters, options) {
639
- if (this.chains[chainIdentifier] == null)
613
+ async createFromBTCSwap(chainIdentifier, recipient, tokenAddress, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters, options) {
614
+ if (this._chains[chainIdentifier] == null)
640
615
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
641
- if (!this.chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
616
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(recipient, true))
642
617
  throw new Error("Invalid " + chainIdentifier + " address");
643
- signer = this.chains[chainIdentifier].chainInterface.normalizeAddress(signer);
618
+ recipient = this._chains[chainIdentifier].chainInterface.normalizeAddress(recipient);
644
619
  const amountData = {
645
620
  amount,
646
621
  token: tokenAddress,
647
622
  exactIn: !exactOut
648
623
  };
649
- return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => Promise.resolve(chain.wrappers[SwapType_1.SwapType.FROM_BTC].create(signer, amountData, candidates, options, additionalParams, abortSignal)), amountData, SwapType_1.SwapType.FROM_BTC);
624
+ return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => Promise.resolve(chain.wrappers[SwapType_1.SwapType.FROM_BTC].create(recipient, amountData, candidates, options, additionalParams, abortSignal)), amountData, SwapType_1.SwapType.FROM_BTC);
650
625
  }
651
626
  /**
652
- * Creates From BTCLN swap
627
+ * Creates LEGACY Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN}) swap
653
628
  *
654
- * @param chainIdentifier
655
- * @param signer
656
- * @param tokenAddress Token address to receive
657
- * @param amount Amount to receive, in satoshis (bitcoin's smallest denomination)
658
- * @param exactOut Whether to use exact out instead of exact in
659
- * @param additionalParams Additional parameters sent to the LP when creating the swap
660
- * @param options
629
+ * @param chainIdentifier Chain identifier string of the destination smart chain
630
+ * @param recipient Recipient address on the destination chain
631
+ * @param tokenAddress Token address to receive
632
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
633
+ * @param exactOut Whether to use a exact out instead of exact in
634
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
635
+ * @param options Additional options for the swap
661
636
  */
662
- async createFromBTCLNSwap(chainIdentifier, signer, tokenAddress, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters, options) {
663
- if (this.chains[chainIdentifier] == null)
637
+ async createFromBTCLNSwap(chainIdentifier, recipient, tokenAddress, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters, options) {
638
+ if (this._chains[chainIdentifier] == null)
664
639
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
665
- if (!this.chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
640
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(recipient, true))
666
641
  throw new Error("Invalid " + chainIdentifier + " address");
667
- signer = this.chains[chainIdentifier].chainInterface.normalizeAddress(signer);
642
+ recipient = this._chains[chainIdentifier].chainInterface.normalizeAddress(recipient);
668
643
  const amountData = {
669
644
  amount,
670
645
  token: tokenAddress,
671
646
  exactIn: !exactOut
672
647
  };
673
- return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => Promise.resolve(chain.wrappers[SwapType_1.SwapType.FROM_BTCLN].create(signer, amountData, candidates, options, additionalParams, abortSignal)), amountData, SwapType_1.SwapType.FROM_BTCLN);
648
+ return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => Promise.resolve(chain.wrappers[SwapType_1.SwapType.FROM_BTCLN].create(recipient, amountData, candidates, options, additionalParams, abortSignal)), amountData, SwapType_1.SwapType.FROM_BTCLN);
674
649
  }
675
650
  /**
676
- * Creates From BTCLN swap, withdrawing from LNURL-withdraw
651
+ * Creates LEGACY Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN}) swap, withdrawing from
652
+ * an LNURL-withdraw link
677
653
  *
678
- * @param chainIdentifier
679
- * @param signer
680
- * @param tokenAddress Token address to receive
681
- * @param lnurl LNURL-withdraw to pull the funds from
682
- * @param amount Amount to receive, in satoshis (bitcoin's smallest denomination)
683
- * @param exactOut Whether to use exact out instead of exact in
684
- * @param additionalParams Additional parameters sent to the LP when creating the swap
654
+ * @param chainIdentifier Chain identifier string of the destination smart chain
655
+ * @param recipient Recipient address on the destination chain
656
+ * @param tokenAddress Token address to receive
657
+ * @param lnurl LNURL-withdraw link to pull the funds from
658
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
659
+ * @param exactOut Whether to use a exact out instead of exact in
660
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
685
661
  */
686
- async createFromBTCLNSwapViaLNURL(chainIdentifier, signer, tokenAddress, lnurl, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters) {
687
- if (this.chains[chainIdentifier] == null)
662
+ async createFromBTCLNSwapViaLNURL(chainIdentifier, recipient, tokenAddress, lnurl, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters) {
663
+ if (this._chains[chainIdentifier] == null)
688
664
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
689
665
  if (typeof (lnurl) === "string" && !this.Utils.isValidLNURL(lnurl))
690
666
  throw new Error("Invalid LNURL-withdraw link");
691
- if (!this.chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
667
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(recipient, true))
692
668
  throw new Error("Invalid " + chainIdentifier + " address");
693
- signer = this.chains[chainIdentifier].chainInterface.normalizeAddress(signer);
669
+ recipient = this._chains[chainIdentifier].chainInterface.normalizeAddress(recipient);
694
670
  const amountData = {
695
671
  amount,
696
672
  token: tokenAddress,
697
673
  exactIn: !exactOut
698
674
  };
699
- return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.FROM_BTCLN].createViaLNURL(signer, typeof (lnurl) === "string" ? (lnurl.startsWith("lightning:") ? lnurl.substring(10) : lnurl) : lnurl.params, amountData, candidates, additionalParams, abortSignal), amountData, SwapType_1.SwapType.FROM_BTCLN);
675
+ return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.FROM_BTCLN].createViaLNURL(recipient, typeof (lnurl) === "string" ? (lnurl.startsWith("lightning:") ? lnurl.substring(10) : lnurl) : lnurl.params, amountData, candidates, additionalParams, abortSignal), amountData, SwapType_1.SwapType.FROM_BTCLN);
700
676
  }
701
677
  /**
702
- * Creates From BTCLN swap using new protocol
678
+ * Creates Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN_AUTO}) swap
703
679
  *
704
- * @param chainIdentifier
705
- * @param signer
706
- * @param tokenAddress Token address to receive
707
- * @param amount Amount to receive, in satoshis (bitcoin's smallest denomination)
708
- * @param exactOut Whether to use exact out instead of exact in
709
- * @param additionalParams Additional parameters sent to the LP when creating the swap
710
- * @param options
680
+ * @param chainIdentifier Chain identifier string of the destination smart chain
681
+ * @param recipient Recipient address on the destination chain
682
+ * @param tokenAddress Token address to receive
683
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
684
+ * @param exactOut Whether to use a exact out instead of exact in
685
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
686
+ * @param options Additional options for the swap
711
687
  */
712
- async createFromBTCLNSwapNew(chainIdentifier, signer, tokenAddress, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters, options) {
713
- if (this.chains[chainIdentifier] == null)
688
+ async createFromBTCLNSwapNew(chainIdentifier, recipient, tokenAddress, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters, options) {
689
+ if (this._chains[chainIdentifier] == null)
714
690
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
715
- if (!this.chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
691
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(recipient, true))
716
692
  throw new Error("Invalid " + chainIdentifier + " address");
717
- signer = this.chains[chainIdentifier].chainInterface.normalizeAddress(signer);
693
+ recipient = this._chains[chainIdentifier].chainInterface.normalizeAddress(recipient);
718
694
  const amountData = {
719
695
  amount,
720
696
  token: tokenAddress,
721
697
  exactIn: !exactOut
722
698
  };
723
- return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => Promise.resolve(chain.wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO].create(signer, amountData, candidates, options, additionalParams, abortSignal)), amountData, SwapType_1.SwapType.FROM_BTCLN_AUTO);
699
+ return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => Promise.resolve(chain.wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO].create(recipient, amountData, candidates, options, additionalParams, abortSignal)), amountData, SwapType_1.SwapType.FROM_BTCLN_AUTO);
724
700
  }
725
701
  /**
726
- * Creates From BTCLN swap using new protocol, withdrawing from LNURL-withdraw
702
+ * Creates Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN_AUTO}) swap, withdrawing from
703
+ * an LNURL-withdraw link
727
704
  *
728
- * @param chainIdentifier
729
- * @param signer
730
- * @param tokenAddress Token address to receive
731
- * @param lnurl LNURL-withdraw to pull the funds from
732
- * @param amount Amount to receive, in satoshis (bitcoin's smallest denomination)
733
- * @param exactOut Whether to use exact out instead of exact in
734
- * @param additionalParams Additional parameters sent to the LP when creating the swap
735
- * @param options
705
+ * @param chainIdentifier Chain identifier string of the destination smart chain
706
+ * @param recipient Recipient address on the destination chain
707
+ * @param tokenAddress Token address to receive
708
+ * @param lnurl LNURL-withdraw link to pull the funds from
709
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
710
+ * @param exactOut Whether to use a exact out instead of exact in
711
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
712
+ * @param options Additional options for the swap
736
713
  */
737
- async createFromBTCLNSwapNewViaLNURL(chainIdentifier, signer, tokenAddress, lnurl, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters, options) {
738
- if (this.chains[chainIdentifier] == null)
714
+ async createFromBTCLNSwapNewViaLNURL(chainIdentifier, recipient, tokenAddress, lnurl, amount, exactOut = false, additionalParams = this.options.defaultAdditionalParameters, options) {
715
+ if (this._chains[chainIdentifier] == null)
739
716
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
740
717
  if (typeof (lnurl) === "string" && !this.Utils.isValidLNURL(lnurl))
741
718
  throw new Error("Invalid LNURL-withdraw link");
742
- if (!this.chains[chainIdentifier].chainInterface.isValidAddress(signer, true))
719
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(recipient, true))
743
720
  throw new Error("Invalid " + chainIdentifier + " address");
744
- signer = this.chains[chainIdentifier].chainInterface.normalizeAddress(signer);
721
+ recipient = this._chains[chainIdentifier].chainInterface.normalizeAddress(recipient);
745
722
  const amountData = {
746
723
  amount,
747
724
  token: tokenAddress,
748
725
  exactIn: !exactOut
749
726
  };
750
- return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO].createViaLNURL(signer, typeof (lnurl) === "string" ? (lnurl.startsWith("lightning:") ? lnurl.substring(10) : lnurl) : lnurl.params, amountData, candidates, options, additionalParams, abortSignal), amountData, SwapType_1.SwapType.FROM_BTCLN_AUTO);
727
+ return this.createSwap(chainIdentifier, (candidates, abortSignal, chain) => chain.wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO].createViaLNURL(recipient, typeof (lnurl) === "string" ? (lnurl.startsWith("lightning:") ? lnurl.substring(10) : lnurl) : lnurl.params, amountData, candidates, options, additionalParams, abortSignal), amountData, SwapType_1.SwapType.FROM_BTCLN_AUTO);
751
728
  }
752
729
  /**
753
- * Creates trusted LN for Gas swap
730
+ * Creates a trusted Bitcoin Lightning -> Smart chain ({@link SwapType.TRUSTED_FROM_BTCLN}) gas swap
754
731
  *
755
- * @param chainId
756
- * @param signer
757
- * @param amount Amount of native token to receive, in base units
732
+ * @param chainIdentifier Chain identifier string of the destination smart chain
733
+ * @param recipient Recipient address on the destination chain
734
+ * @param amount Amount of native token to receive, in base units
758
735
  * @param trustedIntermediaryOrUrl URL or Intermediary object of the trusted intermediary to use, otherwise uses default
759
- * @throws {Error} If no trusted intermediary specified
736
+ * @throws {Error} If no trusted intermediary specified
760
737
  */
761
- createTrustedLNForGasSwap(chainId, signer, amount, trustedIntermediaryOrUrl) {
762
- if (this.chains[chainId] == null)
763
- throw new Error("Invalid chain identifier! Unknown chain: " + chainId);
764
- if (!this.chains[chainId].chainInterface.isValidAddress(signer, true))
765
- throw new Error("Invalid " + chainId + " address");
766
- signer = this.chains[chainId].chainInterface.normalizeAddress(signer);
738
+ createTrustedLNForGasSwap(chainIdentifier, recipient, amount, trustedIntermediaryOrUrl) {
739
+ if (this._chains[chainIdentifier] == null)
740
+ throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
741
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(recipient, true))
742
+ throw new Error("Invalid " + chainIdentifier + " address");
743
+ recipient = this._chains[chainIdentifier].chainInterface.normalizeAddress(recipient);
767
744
  const useUrl = trustedIntermediaryOrUrl ?? this.defaultTrustedIntermediary ?? this.options.defaultTrustedIntermediaryUrl;
768
745
  if (useUrl == null)
769
746
  throw new Error("No trusted intermediary specified!");
770
- return this.chains[chainId].wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTCLN].create(signer, amount, useUrl);
747
+ return this._chains[chainIdentifier].wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTCLN].create(recipient, amount, useUrl);
771
748
  }
772
749
  /**
773
- * Creates trusted BTC on-chain for Gas swap
750
+ * Creates a trusted Bitcoin -> Smart chain ({@link SwapType.TRUSTED_FROM_BTC}) gas swap
774
751
  *
775
- * @param chainId
776
- * @param signer
777
- * @param amount Amount of native token to receive, in base units
778
- * @param refundAddress Bitcoin refund address, in case the swap fails
779
- * @param trustedIntermediaryOrUrl URL or Intermediary object of the trusted intermediary to use, otherwise uses default
780
- * @throws {Error} If no trusted intermediary specified
752
+ * @param chainIdentifier Chain identifier string of the destination smart chain
753
+ * @param recipient Recipient address on the destination chain
754
+ * @param amount Amount of native token to receive, in base units
755
+ * @param refundAddress Bitcoin refund address, in case the swap fails the funds are refunded here
756
+ * @param trustedIntermediaryOrUrl URL or Intermediary object of the trusted intermediary to use, otherwise uses default
757
+ * @throws {Error} If no trusted intermediary specified
781
758
  */
782
- createTrustedOnchainForGasSwap(chainId, signer, amount, refundAddress, trustedIntermediaryOrUrl) {
783
- if (this.chains[chainId] == null)
784
- throw new Error("Invalid chain identifier! Unknown chain: " + chainId);
785
- if (!this.chains[chainId].chainInterface.isValidAddress(signer, true))
786
- throw new Error("Invalid " + chainId + " address");
787
- signer = this.chains[chainId].chainInterface.normalizeAddress(signer);
759
+ createTrustedOnchainForGasSwap(chainIdentifier, recipient, amount, refundAddress, trustedIntermediaryOrUrl) {
760
+ if (this._chains[chainIdentifier] == null)
761
+ throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
762
+ if (!this._chains[chainIdentifier].chainInterface.isValidAddress(recipient, true))
763
+ throw new Error("Invalid " + chainIdentifier + " address");
764
+ recipient = this._chains[chainIdentifier].chainInterface.normalizeAddress(recipient);
788
765
  const useUrl = trustedIntermediaryOrUrl ?? this.defaultTrustedIntermediary ?? this.options.defaultTrustedIntermediaryUrl;
789
766
  if (useUrl == null)
790
767
  throw new Error("No trusted intermediary specified!");
791
- return this.chains[chainId].wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTC].create(signer, amount, useUrl, refundAddress);
768
+ return this._chains[chainIdentifier].wrappers[SwapType_1.SwapType.TRUSTED_FROM_BTC].create(recipient, amount, useUrl, refundAddress);
792
769
  }
793
770
  /**
794
771
  * Creates a swap from srcToken to dstToken, of a specific token amount, either specifying input amount (exactIn=true)
795
772
  * or output amount (exactIn=false), NOTE: For regular -> BTC-LN (lightning) swaps the passed amount is ignored and
796
773
  * invoice's pre-set amount is used instead.
797
- * @deprecated Use swap() instead
774
+ * @deprecated Use {@link swap} instead
798
775
  *
799
776
  * @param signer Smartchain (Solana, Starknet, etc.) address of the user
800
777
  * @param srcToken Source token of the swap, user pays this token
@@ -813,9 +790,9 @@ class Swapper extends events_1.EventEmitter {
813
790
  }
814
791
  }
815
792
  /**
816
- * Creates a swap from srcToken to dstToken, of a specific token amount, either specifying input amount (exactIn=true)
817
- * or output amount (exactIn=false), NOTE: For regular SmartChain -> BTC-LN (lightning) swaps the passed amount is ignored and
818
- * invoice's pre-set amount is used instead, use LNURL-pay for dynamic amounts
793
+ * Creates a swap from srcToken to dstToken, of a specific token amount, either specifying input amount (if `exactIn=true`)
794
+ * or output amount (if `exactIn=false`), NOTE: For regular Smart chain -> BTC-LN (lightning) swaps the passed amount is ignored and
795
+ * invoice's pre-set amount is used instead, use LNURL-pay links for dynamic amounts
819
796
  *
820
797
  * @param _srcToken Source token of the swap, user pays this token
821
798
  * @param _dstToken Destination token of the swap, user receives this token
@@ -874,7 +851,7 @@ class Swapper extends events_1.EventEmitter {
874
851
  throw new Error("Amount cannot be null for to btcln swaps via LNURL-pay!");
875
852
  return this.createToBTCLNSwapViaLNURL(srcToken.chainId, src, srcToken.address, dst, amount, !!exactIn, undefined, options);
876
853
  }
877
- else if ((0, ToBTCLNWrapper_1.isInvoiceCreateService)(dst)) {
854
+ else if ((0, LightningInvoiceCreateService_1.isLightningInvoiceCreateService)(dst)) {
878
855
  if (amount == null)
879
856
  throw new Error("Amount cannot be null for to btcln swaps via InvoiceCreateService!");
880
857
  return this.createToBTCLNSwapViaInvoiceCreateService(srcToken.chainId, src, srcToken.address, dst, amount, !!exactIn, undefined, options);
@@ -907,28 +884,28 @@ class Swapper extends events_1.EventEmitter {
907
884
  if (signer != null)
908
885
  queryParams.push({ key: "initiator", value: signer });
909
886
  if (chainId == null) {
910
- const res = await Promise.all(Object.keys(this.chains).map((chainId) => {
911
- const { unifiedSwapStorage, reviver } = this.chains[chainId];
887
+ const res = await Promise.all(Object.keys(this._chains).map((chainId) => {
888
+ const { unifiedSwapStorage, reviver } = this._chains[chainId];
912
889
  return unifiedSwapStorage.query([queryParams], reviver);
913
890
  }));
914
891
  return res.flat();
915
892
  }
916
893
  else {
917
- const { unifiedSwapStorage, reviver } = this.chains[chainId];
894
+ const { unifiedSwapStorage, reviver } = this._chains[chainId];
918
895
  return await unifiedSwapStorage.query([queryParams], reviver);
919
896
  }
920
897
  }
921
898
  async getActionableSwaps(chainId, signer) {
922
899
  if (chainId == null) {
923
- const res = await Promise.all(Object.keys(this.chains).map((chainId) => {
924
- const { unifiedSwapStorage, reviver, wrappers } = this.chains[chainId];
900
+ const res = await Promise.all(Object.keys(this._chains).map((chainId) => {
901
+ const { unifiedSwapStorage, reviver, wrappers } = this._chains[chainId];
925
902
  const queryParams = [];
926
903
  for (let key in wrappers) {
927
904
  const wrapper = wrappers[key];
928
905
  const swapTypeQueryParams = [{ key: "type", value: wrapper.TYPE }];
929
906
  if (signer != null)
930
907
  swapTypeQueryParams.push({ key: "initiator", value: signer });
931
- swapTypeQueryParams.push({ key: "state", value: wrapper.pendingSwapStates });
908
+ swapTypeQueryParams.push({ key: "state", value: wrapper._pendingSwapStates });
932
909
  queryParams.push(swapTypeQueryParams);
933
910
  }
934
911
  return unifiedSwapStorage.query(queryParams, reviver);
@@ -936,14 +913,14 @@ class Swapper extends events_1.EventEmitter {
936
913
  return res.flat().filter(swap => swap.requiresAction());
937
914
  }
938
915
  else {
939
- const { unifiedSwapStorage, reviver, wrappers } = this.chains[chainId];
916
+ const { unifiedSwapStorage, reviver, wrappers } = this._chains[chainId];
940
917
  const queryParams = [];
941
918
  for (let key in wrappers) {
942
919
  const wrapper = wrappers[key];
943
920
  const swapTypeQueryParams = [{ key: "type", value: wrapper.TYPE }];
944
921
  if (signer != null)
945
922
  swapTypeQueryParams.push({ key: "initiator", value: signer });
946
- swapTypeQueryParams.push({ key: "state", value: wrapper.pendingSwapStates });
923
+ swapTypeQueryParams.push({ key: "state", value: wrapper._pendingSwapStates });
947
924
  queryParams.push(swapTypeQueryParams);
948
925
  }
949
926
  return (await unifiedSwapStorage.query(queryParams, reviver)).filter(swap => swap.requiresAction());
@@ -951,14 +928,14 @@ class Swapper extends events_1.EventEmitter {
951
928
  }
952
929
  async getRefundableSwaps(chainId, signer) {
953
930
  if (chainId == null) {
954
- const res = await Promise.all(Object.keys(this.chains).map((chainId) => {
955
- const { unifiedSwapStorage, reviver, wrappers } = this.chains[chainId];
931
+ const res = await Promise.all(Object.keys(this._chains).map((chainId) => {
932
+ const { unifiedSwapStorage, reviver, wrappers } = this._chains[chainId];
956
933
  const queryParams = [];
957
934
  for (let wrapper of [wrappers[SwapType_1.SwapType.TO_BTCLN], wrappers[SwapType_1.SwapType.TO_BTC]]) {
958
935
  const swapTypeQueryParams = [{ key: "type", value: wrapper.TYPE }];
959
936
  if (signer != null)
960
937
  swapTypeQueryParams.push({ key: "initiator", value: signer });
961
- swapTypeQueryParams.push({ key: "state", value: wrapper.refundableSwapStates });
938
+ swapTypeQueryParams.push({ key: "state", value: wrapper._refundableSwapStates });
962
939
  queryParams.push(swapTypeQueryParams);
963
940
  }
964
941
  return unifiedSwapStorage.query(queryParams, reviver);
@@ -966,13 +943,13 @@ class Swapper extends events_1.EventEmitter {
966
943
  return res.flat().filter(swap => swap.isRefundable());
967
944
  }
968
945
  else {
969
- const { unifiedSwapStorage, reviver, wrappers } = this.chains[chainId];
946
+ const { unifiedSwapStorage, reviver, wrappers } = this._chains[chainId];
970
947
  const queryParams = [];
971
948
  for (let wrapper of [wrappers[SwapType_1.SwapType.TO_BTCLN], wrappers[SwapType_1.SwapType.TO_BTC]]) {
972
949
  const swapTypeQueryParams = [{ key: "type", value: wrapper.TYPE }];
973
950
  if (signer != null)
974
951
  swapTypeQueryParams.push({ key: "initiator", value: signer });
975
- swapTypeQueryParams.push({ key: "state", value: wrapper.refundableSwapStates });
952
+ swapTypeQueryParams.push({ key: "state", value: wrapper._refundableSwapStates });
976
953
  queryParams.push(swapTypeQueryParams);
977
954
  }
978
955
  const result = await unifiedSwapStorage.query(queryParams, reviver);
@@ -981,8 +958,8 @@ class Swapper extends events_1.EventEmitter {
981
958
  }
982
959
  async getClaimableSwaps(chainId, signer) {
983
960
  if (chainId == null) {
984
- const res = await Promise.all(Object.keys(this.chains).map((chainId) => {
985
- const { unifiedSwapStorage, reviver, wrappers } = this.chains[chainId];
961
+ const res = await Promise.all(Object.keys(this._chains).map((chainId) => {
962
+ const { unifiedSwapStorage, reviver, wrappers } = this._chains[chainId];
986
963
  const queryParams = [];
987
964
  for (let wrapper of [wrappers[SwapType_1.SwapType.FROM_BTC], wrappers[SwapType_1.SwapType.FROM_BTCLN], wrappers[SwapType_1.SwapType.SPV_VAULT_FROM_BTC], wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO]]) {
988
965
  if (wrapper == null)
@@ -990,7 +967,7 @@ class Swapper extends events_1.EventEmitter {
990
967
  const swapTypeQueryParams = [{ key: "type", value: wrapper.TYPE }];
991
968
  if (signer != null)
992
969
  swapTypeQueryParams.push({ key: "initiator", value: signer });
993
- swapTypeQueryParams.push({ key: "state", value: wrapper.claimableSwapStates });
970
+ swapTypeQueryParams.push({ key: "state", value: wrapper._claimableSwapStates });
994
971
  queryParams.push(swapTypeQueryParams);
995
972
  }
996
973
  return unifiedSwapStorage.query(queryParams, reviver);
@@ -998,7 +975,7 @@ class Swapper extends events_1.EventEmitter {
998
975
  return res.flat().filter(swap => swap.isClaimable());
999
976
  }
1000
977
  else {
1001
- const { unifiedSwapStorage, reviver, wrappers } = this.chains[chainId];
978
+ const { unifiedSwapStorage, reviver, wrappers } = this._chains[chainId];
1002
979
  const queryParams = [];
1003
980
  for (let wrapper of [wrappers[SwapType_1.SwapType.FROM_BTC], wrappers[SwapType_1.SwapType.FROM_BTCLN], wrappers[SwapType_1.SwapType.SPV_VAULT_FROM_BTC], wrappers[SwapType_1.SwapType.FROM_BTCLN_AUTO]]) {
1004
981
  if (wrapper == null)
@@ -1006,7 +983,7 @@ class Swapper extends events_1.EventEmitter {
1006
983
  const swapTypeQueryParams = [{ key: "type", value: wrapper.TYPE }];
1007
984
  if (signer != null)
1008
985
  swapTypeQueryParams.push({ key: "initiator", value: signer });
1009
- swapTypeQueryParams.push({ key: "state", value: wrapper.claimableSwapStates });
986
+ swapTypeQueryParams.push({ key: "state", value: wrapper._claimableSwapStates });
1010
987
  queryParams.push(swapTypeQueryParams);
1011
988
  }
1012
989
  const result = await unifiedSwapStorage.query(queryParams, reviver);
@@ -1016,9 +993,9 @@ class Swapper extends events_1.EventEmitter {
1016
993
  async getSwapById(id, chainId, signer) {
1017
994
  //Check in pending swaps first
1018
995
  if (chainId != null) {
1019
- for (let key in this.chains[chainId].wrappers) {
1020
- const wrapper = this.chains[chainId].wrappers[key];
1021
- const result = wrapper.pendingSwaps.get(id)?.deref();
996
+ for (let key in this._chains[chainId].wrappers) {
997
+ const wrapper = this._chains[chainId].wrappers[key];
998
+ const result = wrapper._getPendingSwap(id);
1022
999
  if (result != null) {
1023
1000
  if (signer != null) {
1024
1001
  if (result._getInitiator() === signer)
@@ -1031,10 +1008,10 @@ class Swapper extends events_1.EventEmitter {
1031
1008
  }
1032
1009
  }
1033
1010
  else {
1034
- for (let chainId in this.chains) {
1035
- for (let key in this.chains[chainId].wrappers) {
1036
- const wrapper = this.chains[chainId].wrappers[key];
1037
- const result = wrapper.pendingSwaps.get(id)?.deref();
1011
+ for (let chainId in this._chains) {
1012
+ for (let key in this._chains[chainId].wrappers) {
1013
+ const wrapper = this._chains[chainId].wrappers[key];
1014
+ const result = wrapper._getPendingSwap(id);
1038
1015
  if (result != null) {
1039
1016
  if (signer != null) {
1040
1017
  if (result._getInitiator() === signer)
@@ -1052,24 +1029,24 @@ class Swapper extends events_1.EventEmitter {
1052
1029
  queryParams.push({ key: "initiator", value: signer });
1053
1030
  queryParams.push({ key: "id", value: id });
1054
1031
  if (chainId == null) {
1055
- const res = await Promise.all(Object.keys(this.chains).map((chainId) => {
1056
- const { unifiedSwapStorage, reviver } = this.chains[chainId];
1032
+ const res = await Promise.all(Object.keys(this._chains).map((chainId) => {
1033
+ const { unifiedSwapStorage, reviver } = this._chains[chainId];
1057
1034
  return unifiedSwapStorage.query([queryParams], reviver);
1058
1035
  }));
1059
1036
  return res.flat()[0];
1060
1037
  }
1061
1038
  else {
1062
- const { unifiedSwapStorage, reviver } = this.chains[chainId];
1039
+ const { unifiedSwapStorage, reviver } = this._chains[chainId];
1063
1040
  return (await unifiedSwapStorage.query([queryParams], reviver))[0];
1064
1041
  }
1065
1042
  }
1066
1043
  /**
1067
- * Returns the swap with a proper return type, or undefined, if not found, or has wrong type
1044
+ * Returns the swap with a proper return type, or `undefined` if not found or has wrong type
1068
1045
  *
1069
- * @param id
1070
- * @param chainId
1071
- * @param swapType
1072
- * @param signer
1046
+ * @param id An ID of the swap ({@link ISwap.getId})
1047
+ * @param chainId Chain identifier of the smart chain where the swap was initiated
1048
+ * @param swapType Type of the swap
1049
+ * @param signer An optional required smart chain signer address to fetch the swap for
1073
1050
  */
1074
1051
  async getTypedSwapById(id, chainId, swapType, signer) {
1075
1052
  let _swapType = swapType;
@@ -1077,10 +1054,10 @@ class Swapper extends events_1.EventEmitter {
1077
1054
  _swapType = SwapType_1.SwapType.SPV_VAULT_FROM_BTC;
1078
1055
  if (swapType === SwapType_1.SwapType.FROM_BTCLN && this.supportsSwapType(chainId, SwapType_1.SwapType.FROM_BTCLN_AUTO))
1079
1056
  _swapType = SwapType_1.SwapType.FROM_BTCLN_AUTO;
1080
- const wrapper = this.chains[chainId].wrappers[_swapType];
1057
+ const wrapper = this._chains[chainId].wrappers[_swapType];
1081
1058
  if (wrapper == null)
1082
1059
  return;
1083
- const result = wrapper.pendingSwaps.get(id)?.deref();
1060
+ const result = wrapper._getPendingSwap(id);
1084
1061
  if (result != null) {
1085
1062
  if (signer != null) {
1086
1063
  if (result._getInitiator() === signer)
@@ -1094,20 +1071,20 @@ class Swapper extends events_1.EventEmitter {
1094
1071
  if (signer != null)
1095
1072
  queryParams.push({ key: "initiator", value: signer });
1096
1073
  queryParams.push({ key: "id", value: id });
1097
- const { unifiedSwapStorage, reviver } = this.chains[chainId];
1074
+ const { unifiedSwapStorage, reviver } = this._chains[chainId];
1098
1075
  const swap = (await unifiedSwapStorage.query([queryParams], reviver))[0];
1099
1076
  if ((0, SwapUtils_1.isSwapType)(swap, swapType))
1100
1077
  return swap;
1101
1078
  }
1102
1079
  async syncSwapsForChain(chainId, signer) {
1103
- const { unifiedSwapStorage, reviver, wrappers } = this.chains[chainId];
1080
+ const { unifiedSwapStorage, reviver, wrappers } = this._chains[chainId];
1104
1081
  const queryParams = [];
1105
1082
  for (let key in wrappers) {
1106
1083
  const wrapper = wrappers[key];
1107
1084
  const swapTypeQueryParams = [{ key: "type", value: wrapper.TYPE }];
1108
1085
  if (signer != null)
1109
1086
  swapTypeQueryParams.push({ key: "initiator", value: signer });
1110
- swapTypeQueryParams.push({ key: "state", value: wrapper.pendingSwapStates });
1087
+ swapTypeQueryParams.push({ key: "state", value: wrapper._pendingSwapStates });
1111
1088
  queryParams.push(swapTypeQueryParams);
1112
1089
  }
1113
1090
  this.logger.debug("_syncSwaps(): Querying swaps swaps for chain " + chainId + "!");
@@ -1134,14 +1111,48 @@ class Swapper extends events_1.EventEmitter {
1134
1111
  removeSwaps.forEach(swap => swap._emitEvent());
1135
1112
  }
1136
1113
  /**
1137
- * Synchronizes swaps from chain, this is usually ran when SDK is initialized, deletes expired quotes
1114
+ * Deletes the swaps from the persistent storage backend. Note that some data (like lightning network
1115
+ * amounts and bolt11 invoices) are purely off-chain and can never be recovered later just from
1116
+ * on-chain data!
1138
1117
  *
1139
- * @param chainId
1140
- * @param signer
1118
+ * @param chainId Optional, to only delete swaps for this smart chain
1119
+ * @param signer Optional, to only delete swaps for this smart chain signer (`chainId` param must be
1120
+ * set to delete only signer's swaps)
1121
+ */
1122
+ async wipeStorage(chainId, signer) {
1123
+ if (chainId == null) {
1124
+ const swaps = await this.getAllSwaps();
1125
+ const chainSwaps = {};
1126
+ swaps.forEach(swap => (chainSwaps[swap.chainIdentifier] ??= []).push(swap));
1127
+ for (let chainId in chainSwaps) {
1128
+ const currentChainSwaps = chainSwaps[chainId];
1129
+ if (this._chains[chainId] == null) {
1130
+ this.logger.warn(`wipeStorage(): Attempted to remove ${currentChainSwaps.length} swaps on ${chainId}, but smart chain not known!`);
1131
+ continue;
1132
+ }
1133
+ await this._chains[chainId].unifiedSwapStorage.removeAll(currentChainSwaps);
1134
+ this.logger.debug(`wipeStorage(): Successfully removed ${currentChainSwaps.length} swaps on ${chainId}!`);
1135
+ }
1136
+ }
1137
+ else {
1138
+ if (this._chains[chainId] == null)
1139
+ throw new Error(`wipeStorage(): Smart chain with identifier ${chainId} not found!`);
1140
+ const swaps = await this.getAllSwaps(chainId, signer);
1141
+ await this._chains[chainId].unifiedSwapStorage.removeAll(swaps);
1142
+ this.logger.debug(`wipeStorage(): Successfully removed ${swaps.length} swaps on ${chainId}!`);
1143
+ }
1144
+ }
1145
+ /**
1146
+ * Synchronizes swaps from on-chain, this is ran automatically when SDK is initialized, hence
1147
+ * should only be ran manually when `dontCheckPastSwaps=true` is passed in the swapper options,
1148
+ * also deletes expired quotes
1149
+ *
1150
+ * @param chainId Optional chain identifier to only run swap sync for a single smart chain
1151
+ * @param signer Optional signer to only run swap sync for swaps initiated by this signer
1141
1152
  */
1142
1153
  async _syncSwaps(chainId, signer) {
1143
1154
  if (chainId == null) {
1144
- await Promise.all(Object.keys(this.chains).map((chainId) => {
1155
+ await Promise.all(Object.keys(this._chains).map((chainId) => {
1145
1156
  return this.syncSwapsForChain(chainId, signer);
1146
1157
  }));
1147
1158
  }
@@ -1150,18 +1161,27 @@ class Swapper extends events_1.EventEmitter {
1150
1161
  }
1151
1162
  }
1152
1163
  /**
1153
- * Attempts to recover partial swap data from on-chain historical data
1164
+ * Recovers swaps from on-chain historical data.
1165
+ *
1166
+ * Please note that the recovered swaps might not be complete (i.e. missing amounts or addresses), as some
1167
+ * of the swap data is purely off-chain and can never be recovered purely from on-chain data. This
1168
+ * functions tries to recover as much swap data as possible.
1154
1169
  *
1155
- * @param chainId
1156
- * @param signer
1157
- * @param startBlockheight
1170
+ * @param chainId Smart chain identifier string to recover the swaps from
1171
+ * @param signer Signer address to recover the swaps for
1172
+ * @param startBlockheight Optional starting blockheight for swap data recovery, will only check swaps
1173
+ * initiated after this blockheight
1158
1174
  */
1159
1175
  async recoverSwaps(chainId, signer, startBlockheight) {
1160
- const { swapContract, unifiedSwapStorage, reviver, wrappers } = this.chains[chainId];
1161
- if (swapContract.getHistoricalSwaps == null)
1176
+ const { spvVaultContract, swapContract, unifiedSwapStorage, reviver, wrappers } = this._chains[chainId];
1177
+ if (swapContract.getHistoricalSwaps == null ||
1178
+ (spvVaultContract != null && spvVaultContract.getHistoricalWithdrawalStates == null))
1162
1179
  throw new Error(`Historical swap recovery is not supported for ${chainId}`);
1163
- const { swaps } = await swapContract.getHistoricalSwaps(signer);
1180
+ const { swaps } = await swapContract.getHistoricalSwaps(signer, startBlockheight);
1181
+ const spvVaultData = await spvVaultContract?.getHistoricalWithdrawalStates(signer, startBlockheight);
1164
1182
  const escrowHashes = Object.keys(swaps);
1183
+ if (spvVaultData != null)
1184
+ Object.keys(spvVaultData.withdrawals).forEach(btcTxId => escrowHashes.push(btcTxId));
1165
1185
  this.logger.debug(`recoverSwaps(): Loaded on-chain data for ${escrowHashes.length} swaps`);
1166
1186
  this.logger.debug(`recoverSwaps(): Fetching if swap escrowHashes are known: ${escrowHashes.join(", ")}`);
1167
1187
  const knownSwapsArray = await unifiedSwapStorage.query([[{ key: "escrowHash", value: escrowHashes }]], reviver);
@@ -1176,16 +1196,21 @@ class Swapper extends events_1.EventEmitter {
1176
1196
  for (let escrowHash in swaps) {
1177
1197
  const { init, state } = swaps[escrowHash];
1178
1198
  const knownSwap = knownSwaps[escrowHash];
1179
- if (init == null) {
1180
- if (knownSwap == null)
1181
- this.logger.warn(`recoverSwaps(): Fetched ${escrowHash} swap state, but swap not found locally!`);
1182
- //TODO: Update the existing swaps here
1183
- this.logger.debug(`recoverSwaps(): Skipping ${escrowHash} swap: swap already known and in local storage!`);
1199
+ if (knownSwap == null) {
1200
+ if (init == null) {
1201
+ this.logger.warn(`recoverSwaps(escrow): Fetched ${escrowHash} swap state, but swap not found locally!`);
1202
+ continue;
1203
+ }
1204
+ }
1205
+ else if (knownSwap instanceof IEscrowSwap_1.IEscrowSwap) {
1206
+ this.logger.debug(`recoverSwaps(escrow): Forcibly updating ${escrowHash} swap: swap already known and in local storage!`);
1207
+ if (await knownSwap._forciblySetOnchainState(state)) {
1208
+ await knownSwap._save();
1209
+ }
1184
1210
  continue;
1185
1211
  }
1186
- if (knownSwap != null) {
1187
- //TODO: Update the existing swaps here
1188
- this.logger.debug(`recoverSwaps(): Skipping ${escrowHash} swap: swap already known and in local storage!`);
1212
+ else {
1213
+ this.logger.debug(`recoverSwaps(escrow): Skipping ${escrowHash} swap: swap already known and in local storage!`);
1189
1214
  continue;
1190
1215
  }
1191
1216
  const data = init.data;
@@ -1228,12 +1253,53 @@ class Swapper extends events_1.EventEmitter {
1228
1253
  }
1229
1254
  else {
1230
1255
  if (typeIdentified)
1231
- this.logger.debug(`recoverSwaps(): Swap data type correctly identified but swap returned is null for swap ${escrowHash}`);
1256
+ this.logger.debug(`recoverSwaps(escrow): Swap data type correctly identified but swap returned is null for swap ${escrowHash}`);
1257
+ }
1258
+ }
1259
+ if (spvVaultContract != null && spvVaultData != null) {
1260
+ const vaultsData = await spvVaultContract.getMultipleVaultData(Object.keys(spvVaultData.withdrawals)
1261
+ .map(btcTxId => ({
1262
+ owner: spvVaultData.withdrawals[btcTxId].owner,
1263
+ vaultId: spvVaultData.withdrawals[btcTxId].vaultId
1264
+ })));
1265
+ for (let btcTxId in spvVaultData.withdrawals) {
1266
+ const state = spvVaultData.withdrawals[btcTxId];
1267
+ const knownSwap = knownSwaps[btcTxId];
1268
+ if (knownSwap != null) {
1269
+ if (knownSwap instanceof SpvFromBTCSwap_1.SpvFromBTCSwap) {
1270
+ this.logger.debug(`recoverSwaps(spv_vault): Forcibly updating ${btcTxId} swap: swap already known and in local storage!`);
1271
+ //TODO: Forcibly set on-chain state to the swap
1272
+ // if(await knownSwap._forciblySetOnchainState(state)) {
1273
+ // await knownSwap._save();
1274
+ // }
1275
+ continue;
1276
+ }
1277
+ else {
1278
+ this.logger.debug(`recoverSwaps(spv_vault): Skipping ${btcTxId} swap: swap already known and in local storage!`);
1279
+ continue;
1280
+ }
1281
+ }
1282
+ const lp = this.intermediaryDiscovery.intermediaries.find(val => val.supportsChain(chainId) && state.owner.toLowerCase() === val.getAddress(chainId).toLowerCase());
1283
+ const swap = await wrappers[SwapType_1.SwapType.SPV_VAULT_FROM_BTC].recoverFromState(state, vaultsData[state.owner]?.[state.vaultId.toString(10)], lp);
1284
+ if (swap != null) {
1285
+ recoveredSwaps.push(swap);
1286
+ }
1287
+ else {
1288
+ this.logger.debug(`recoverSwaps(spv_vault): Swap data type correctly identified but swap returned is null for swap ${btcTxId}`);
1289
+ }
1232
1290
  }
1233
1291
  }
1234
1292
  this.logger.debug(`recoverSwaps(): Successfully recovered ${recoveredSwaps.length} swaps!`);
1235
1293
  return recoveredSwaps;
1236
1294
  }
1295
+ /**
1296
+ * Returns the {@link Token} object for a given token
1297
+ *
1298
+ * @param tickerOrAddress Token to return the object for, can use multiple formats:
1299
+ * - a) token ticker, such as `"BTC"`, `"SOL"`, etc.
1300
+ * - b) token ticker prefixed with smart chain identifier, such as `"SOLANA-SOL"`, `"SOLANA-USDC"`, etc.
1301
+ * - c) token address
1302
+ */
1237
1303
  getToken(tickerOrAddress) {
1238
1304
  //Btc tokens - BTC, BTCLN, BTC-LN
1239
1305
  if (tickerOrAddress === "BTC")
@@ -1243,23 +1309,23 @@ class Swapper extends events_1.EventEmitter {
1243
1309
  //Check if the ticker is in format <chainId>-<ticker>, i.e. SOLANA-USDC, STARKNET-WBTC
1244
1310
  if (tickerOrAddress.includes("-")) {
1245
1311
  const [chainId, ticker] = tickerOrAddress.split("-");
1246
- const token = this.tokensByTicker[chainId]?.[ticker];
1312
+ const token = this._tokensByTicker[chainId]?.[ticker];
1247
1313
  if (token == null)
1248
1314
  throw new UserError_1.UserError(`Not found ticker: ${ticker} for chainId: ${chainId}`);
1249
1315
  return token;
1250
1316
  }
1251
1317
  const possibleTokens = [];
1252
- for (let chainId in this.chains) {
1253
- const chain = this.chains[chainId];
1318
+ for (let chainId in this._chains) {
1319
+ const chain = this._chains[chainId];
1254
1320
  if (chain.chainInterface.isValidToken(tickerOrAddress)) {
1255
1321
  //Try to find in known token addresses
1256
- const token = this.tokens[chainId]?.[tickerOrAddress];
1322
+ const token = this._tokens[chainId]?.[tickerOrAddress];
1257
1323
  if (token != null)
1258
1324
  return token;
1259
1325
  }
1260
1326
  else {
1261
1327
  //Check in known tickers
1262
- const token = this.tokensByTicker[chainId]?.[tickerOrAddress];
1328
+ const token = this._tokensByTicker[chainId]?.[tickerOrAddress];
1263
1329
  if (token != null)
1264
1330
  possibleTokens.push(token);
1265
1331
  }
@@ -1274,28 +1340,34 @@ class Swapper extends events_1.EventEmitter {
1274
1340
  /**
1275
1341
  * Creates a child swapper instance with a given smart chain
1276
1342
  *
1277
- * @param chainIdentifier
1343
+ * @param chainIdentifier Smart chain identifier for the created child swapper instance
1278
1344
  */
1279
1345
  withChain(chainIdentifier) {
1280
- if (this.chains[chainIdentifier] == null)
1346
+ if (this._chains[chainIdentifier] == null)
1281
1347
  throw new Error("Invalid chain identifier! Unknown chain: " + chainIdentifier);
1282
1348
  return new SwapperWithChain_1.SwapperWithChain(this, chainIdentifier);
1283
1349
  }
1284
1350
  /**
1285
- * Returns supported smart chains
1351
+ * Returns an array of all the supported smart chains
1286
1352
  */
1287
1353
  getSmartChains() {
1288
- return Object.keys(this.chains);
1354
+ return Object.keys(this._chains);
1289
1355
  }
1290
1356
  /**
1291
1357
  * Returns whether the SDK supports a given swap type on a given chain based on currently known LPs
1292
1358
  *
1293
- * @param chainId
1294
- * @param swapType
1359
+ * @param chainId Smart chain identifier string
1360
+ * @param swapType Swap protocol type
1295
1361
  */
1296
1362
  supportsSwapType(chainId, swapType) {
1297
- return (this.chains[chainId]?.wrappers[swapType] != null);
1363
+ return (this._chains[chainId]?.wrappers[swapType] != null);
1298
1364
  }
1365
+ /**
1366
+ * Returns type of the swap based on input and output tokens specified
1367
+ *
1368
+ * @param srcToken Source token
1369
+ * @param dstToken Destination token
1370
+ */
1299
1371
  getSwapType(srcToken, dstToken) {
1300
1372
  if ((0, Token_1.isSCToken)(srcToken)) {
1301
1373
  if (!(0, Token_1.isBtcToken)(dstToken))
@@ -1332,8 +1404,8 @@ class Swapper extends events_1.EventEmitter {
1332
1404
  /**
1333
1405
  * Returns minimum/maximum limits for inputs and outputs for a swap between given tokens
1334
1406
  *
1335
- * @param srcToken
1336
- * @param dstToken
1407
+ * @param srcToken Source token
1408
+ * @param dstToken Destination token
1337
1409
  */
1338
1410
  getSwapLimits(srcToken, dstToken) {
1339
1411
  const swapType = this.getSwapType(srcToken, dstToken);
@@ -1365,7 +1437,7 @@ class Swapper extends events_1.EventEmitter {
1365
1437
  };
1366
1438
  }
1367
1439
  /**
1368
- * Returns supported tokens for a given direction
1440
+ * Returns an array of supported tokens either on the input or on the output of a swap
1369
1441
  *
1370
1442
  * @param input Whether to return input tokens or output tokens
1371
1443
  */
@@ -1421,7 +1493,7 @@ class Swapper extends events_1.EventEmitter {
1421
1493
  output.push(Token_1.BitcoinTokens.BTC);
1422
1494
  for (let chainId in tokens) {
1423
1495
  tokens[chainId].forEach(tokenAddress => {
1424
- const token = this.tokens?.[chainId]?.[tokenAddress];
1496
+ const token = this._tokens?.[chainId]?.[tokenAddress];
1425
1497
  if (token != null)
1426
1498
  output.push(token);
1427
1499
  });
@@ -1456,7 +1528,7 @@ class Swapper extends events_1.EventEmitter {
1456
1528
  const output = [];
1457
1529
  for (let chainId in tokens) {
1458
1530
  tokens[chainId].forEach(tokenAddress => {
1459
- const token = this.tokens?.[chainId]?.[tokenAddress];
1531
+ const token = this._tokens?.[chainId]?.[tokenAddress];
1460
1532
  if (token != null)
1461
1533
  output.push(token);
1462
1534
  });
@@ -1466,7 +1538,7 @@ class Swapper extends events_1.EventEmitter {
1466
1538
  /**
1467
1539
  * Returns the set of supported token addresses by all the intermediaries we know of offering a specific swapType service
1468
1540
  *
1469
- * @param chainIdentifier
1541
+ * @param chainIdentifier Chain identifier string
1470
1542
  * @param swapType Specific swap type for which to obtain supported tokens
1471
1543
  */
1472
1544
  getSupportedTokenAddresses(chainIdentifier, swapType) {
@@ -1527,45 +1599,5 @@ class Swapper extends events_1.EventEmitter {
1527
1599
  }
1528
1600
  }
1529
1601
  }
1530
- getSwapBounds(chainIdentifier) {
1531
- if (chainIdentifier == null) {
1532
- return this.intermediaryDiscovery.getMultichainSwapBounds();
1533
- }
1534
- else {
1535
- return this.intermediaryDiscovery.getSwapBounds(chainIdentifier);
1536
- }
1537
- }
1538
- /**
1539
- * Returns maximum possible swap amount
1540
- * @deprecated Use getSwapLimits() instead!
1541
- *
1542
- * @param chainIdentifier
1543
- * @param type Type of the swap
1544
- * @param token Token of the swap
1545
- */
1546
- getMaximum(chainIdentifier, type, token) {
1547
- if (this.intermediaryDiscovery != null) {
1548
- const max = this.intermediaryDiscovery.getSwapMaximum(chainIdentifier, type, token);
1549
- if (max != null)
1550
- return BigInt(max);
1551
- }
1552
- return 0n;
1553
- }
1554
- /**
1555
- * Returns minimum possible swap amount
1556
- * @deprecated Use getSwapLimits() instead!
1557
- *
1558
- * @param chainIdentifier
1559
- * @param type Type of swap
1560
- * @param token Token of the swap
1561
- */
1562
- getMinimum(chainIdentifier, type, token) {
1563
- if (this.intermediaryDiscovery != null) {
1564
- const min = this.intermediaryDiscovery.getSwapMinimum(chainIdentifier, type, token);
1565
- if (min != null)
1566
- return BigInt(min);
1567
- }
1568
- return 0n;
1569
- }
1570
1602
  }
1571
1603
  exports.Swapper = Swapper;