@atomiqlabs/sdk 8.1.8 → 8.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/dist/bitcoin/coinselect2/utils.d.ts +6 -0
  2. package/dist/bitcoin/wallet/BitcoinWallet.d.ts +41 -5
  3. package/dist/bitcoin/wallet/BitcoinWallet.js +36 -1
  4. package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +52 -2
  5. package/dist/bitcoin/wallet/IBitcoinWallet.js +2 -1
  6. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +42 -7
  7. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +36 -1
  8. package/dist/enums/FeeType.d.ts +8 -1
  9. package/dist/enums/FeeType.js +8 -1
  10. package/dist/enums/SwapAmountType.d.ts +7 -0
  11. package/dist/enums/SwapAmountType.js +7 -0
  12. package/dist/enums/SwapDirection.d.ts +7 -0
  13. package/dist/enums/SwapDirection.js +7 -0
  14. package/dist/enums/SwapType.d.ts +62 -1
  15. package/dist/enums/SwapType.js +62 -1
  16. package/dist/errors/IntermediaryError.d.ts +4 -0
  17. package/dist/errors/IntermediaryError.js +1 -0
  18. package/dist/errors/RequestError.d.ts +15 -1
  19. package/dist/errors/RequestError.js +8 -0
  20. package/dist/errors/UserError.d.ts +1 -0
  21. package/dist/errors/UserError.js +1 -0
  22. package/dist/index.d.ts +5 -5
  23. package/dist/index.js +7 -6
  24. package/dist/intermediaries/Intermediary.d.ts +61 -14
  25. package/dist/intermediaries/Intermediary.js +38 -11
  26. package/dist/intermediaries/IntermediaryDiscovery.d.ts +62 -29
  27. package/dist/intermediaries/IntermediaryDiscovery.js +39 -24
  28. package/dist/prices/RedundantSwapPrice.d.ts +26 -5
  29. package/dist/prices/RedundantSwapPrice.js +22 -2
  30. package/dist/prices/SingleSwapPrice.d.ts +10 -7
  31. package/dist/prices/SingleSwapPrice.js +11 -8
  32. package/dist/prices/SwapPriceWithChain.d.ts +56 -19
  33. package/dist/prices/SwapPriceWithChain.js +62 -25
  34. package/dist/prices/abstract/IPriceProvider.d.ts +4 -4
  35. package/dist/prices/abstract/IPriceProvider.js +1 -1
  36. package/dist/prices/abstract/ISwapPrice.d.ts +95 -46
  37. package/dist/prices/abstract/ISwapPrice.js +104 -56
  38. package/dist/prices/providers/BinancePriceProvider.d.ts +8 -1
  39. package/dist/prices/providers/BinancePriceProvider.js +8 -1
  40. package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +7 -1
  41. package/dist/prices/providers/CoinGeckoPriceProvider.js +7 -1
  42. package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +7 -1
  43. package/dist/prices/providers/CoinPaprikaPriceProvider.js +7 -1
  44. package/dist/prices/providers/CustomPriceProvider.d.ts +12 -1
  45. package/dist/prices/providers/CustomPriceProvider.js +12 -1
  46. package/dist/prices/providers/KrakenPriceProvider.d.ts +10 -1
  47. package/dist/prices/providers/KrakenPriceProvider.js +10 -1
  48. package/dist/prices/providers/OKXPriceProvider.d.ts +7 -1
  49. package/dist/prices/providers/OKXPriceProvider.js +7 -1
  50. package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +3 -0
  51. package/dist/prices/providers/abstract/ExchangePriceProvider.js +3 -0
  52. package/dist/storage/IUnifiedStorage.d.ts +19 -7
  53. package/dist/storage/UnifiedSwapStorage.d.ts +33 -3
  54. package/dist/storage/UnifiedSwapStorage.js +29 -1
  55. package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +31 -7
  56. package/dist/storage-browser/IndexedDBUnifiedStorage.js +29 -6
  57. package/dist/storage-browser/LocalStorageManager.d.ts +25 -1
  58. package/dist/storage-browser/LocalStorageManager.js +25 -1
  59. package/dist/swapper/Swapper.d.ts +380 -226
  60. package/dist/swapper/Swapper.js +383 -349
  61. package/dist/swapper/SwapperFactory.d.ts +66 -18
  62. package/dist/swapper/SwapperFactory.js +24 -3
  63. package/dist/swapper/SwapperUtils.d.ts +75 -28
  64. package/dist/swapper/SwapperUtils.js +107 -60
  65. package/dist/swapper/SwapperWithChain.d.ts +286 -91
  66. package/dist/swapper/SwapperWithChain.js +218 -64
  67. package/dist/swapper/SwapperWithSigner.d.ts +229 -80
  68. package/dist/swapper/SwapperWithSigner.js +190 -44
  69. package/dist/swaps/IAddressSwap.d.ts +12 -3
  70. package/dist/swaps/IAddressSwap.js +3 -2
  71. package/dist/swaps/IBTCWalletSwap.d.ts +26 -8
  72. package/dist/swaps/IBTCWalletSwap.js +3 -2
  73. package/dist/swaps/IClaimableSwap.d.ts +38 -6
  74. package/dist/swaps/IClaimableSwap.js +3 -2
  75. package/dist/swaps/IClaimableSwapWrapper.d.ts +11 -1
  76. package/dist/swaps/IRefundableSwap.d.ts +31 -5
  77. package/dist/swaps/IRefundableSwap.js +3 -2
  78. package/dist/swaps/ISwap.d.ts +162 -24
  79. package/dist/swaps/ISwap.js +92 -35
  80. package/dist/swaps/ISwapWithGasDrop.d.ts +8 -2
  81. package/dist/swaps/ISwapWithGasDrop.js +2 -1
  82. package/dist/swaps/ISwapWrapper.d.ts +161 -52
  83. package/dist/swaps/ISwapWrapper.js +131 -73
  84. package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +51 -6
  85. package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +22 -12
  86. package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +65 -12
  87. package/dist/swaps/escrow_swaps/IEscrowSwap.js +38 -19
  88. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +39 -9
  89. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +30 -21
  90. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +31 -15
  91. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +33 -18
  92. package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +97 -28
  93. package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +91 -27
  94. package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +22 -9
  95. package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +24 -11
  96. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +278 -60
  97. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +519 -241
  98. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +77 -26
  99. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +132 -50
  100. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +313 -52
  101. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +544 -194
  102. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +87 -26
  103. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +147 -58
  104. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +222 -55
  105. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +462 -244
  106. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +77 -23
  107. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +116 -46
  108. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +195 -58
  109. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +324 -191
  110. package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +30 -5
  111. package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +44 -19
  112. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +61 -20
  113. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +75 -32
  114. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +76 -50
  115. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +106 -101
  116. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +37 -14
  117. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +66 -20
  118. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +46 -17
  119. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +82 -27
  120. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +350 -88
  121. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +482 -215
  122. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +76 -24
  123. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +247 -124
  124. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +148 -20
  125. package/dist/swaps/trusted/ln/LnForGasSwap.js +175 -45
  126. package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +29 -10
  127. package/dist/swaps/trusted/ln/LnForGasWrapper.js +30 -11
  128. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +202 -49
  129. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +232 -80
  130. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +34 -12
  131. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +33 -14
  132. package/dist/types/AmountData.d.ts +2 -1
  133. package/dist/types/CustomPriceFunction.d.ts +8 -2
  134. package/dist/types/PriceInfoType.d.ts +4 -4
  135. package/dist/types/PriceInfoType.js +3 -3
  136. package/dist/types/SwapExecutionAction.d.ts +85 -4
  137. package/dist/types/SwapWithSigner.d.ts +5 -2
  138. package/dist/types/SwapWithSigner.js +5 -2
  139. package/dist/types/Token.d.ts +11 -5
  140. package/dist/types/Token.js +6 -3
  141. package/dist/types/TokenAmount.d.ts +3 -0
  142. package/dist/types/TokenAmount.js +2 -0
  143. package/dist/types/fees/Fee.d.ts +3 -2
  144. package/dist/types/fees/FeeBreakdown.d.ts +3 -2
  145. package/dist/types/fees/PercentagePPM.d.ts +4 -2
  146. package/dist/types/fees/PercentagePPM.js +2 -1
  147. package/dist/types/lnurl/LNURLPay.d.ts +20 -12
  148. package/dist/types/lnurl/LNURLPay.js +8 -4
  149. package/dist/types/lnurl/LNURLWithdraw.d.ts +17 -10
  150. package/dist/types/lnurl/LNURLWithdraw.js +8 -4
  151. package/dist/types/wallets/LightningInvoiceCreateService.d.ts +24 -0
  152. package/dist/types/wallets/LightningInvoiceCreateService.js +15 -0
  153. package/dist/types/wallets/MinimalBitcoinWalletInterface.d.ts +3 -1
  154. package/dist/types/wallets/MinimalLightningNetworkWalletInterface.d.ts +4 -2
  155. package/dist/utils/BitcoinUtils.d.ts +1 -0
  156. package/dist/utils/BitcoinUtils.js +5 -1
  157. package/dist/utils/SwapUtils.d.ts +58 -1
  158. package/dist/utils/SwapUtils.js +55 -1
  159. package/dist/utils/TokenUtils.d.ts +10 -2
  160. package/dist/utils/TokenUtils.js +12 -4
  161. package/package.json +3 -3
  162. package/src/bitcoin/coinselect2/utils.ts +6 -0
  163. package/src/bitcoin/wallet/BitcoinWallet.ts +41 -5
  164. package/src/bitcoin/wallet/IBitcoinWallet.ts +57 -2
  165. package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +42 -6
  166. package/src/enums/FeeType.ts +8 -1
  167. package/src/enums/SwapAmountType.ts +7 -0
  168. package/src/enums/SwapDirection.ts +7 -0
  169. package/src/enums/SwapType.ts +62 -2
  170. package/src/errors/IntermediaryError.ts +4 -0
  171. package/src/errors/RequestError.ts +15 -1
  172. package/src/errors/UserError.ts +1 -0
  173. package/src/index.ts +12 -5
  174. package/src/intermediaries/Intermediary.ts +61 -14
  175. package/src/intermediaries/IntermediaryDiscovery.ts +69 -34
  176. package/src/prices/RedundantSwapPrice.ts +26 -6
  177. package/src/prices/SingleSwapPrice.ts +11 -8
  178. package/src/prices/SwapPriceWithChain.ts +63 -26
  179. package/src/prices/abstract/IPriceProvider.ts +4 -4
  180. package/src/prices/abstract/ISwapPrice.ts +115 -66
  181. package/src/prices/providers/BinancePriceProvider.ts +8 -1
  182. package/src/prices/providers/CoinGeckoPriceProvider.ts +7 -1
  183. package/src/prices/providers/CoinPaprikaPriceProvider.ts +7 -1
  184. package/src/prices/providers/CustomPriceProvider.ts +12 -1
  185. package/src/prices/providers/KrakenPriceProvider.ts +10 -1
  186. package/src/prices/providers/OKXPriceProvider.ts +7 -1
  187. package/src/prices/providers/abstract/ExchangePriceProvider.ts +3 -0
  188. package/src/storage/IUnifiedStorage.ts +19 -7
  189. package/src/storage/UnifiedSwapStorage.ts +33 -3
  190. package/src/storage-browser/IndexedDBUnifiedStorage.ts +31 -8
  191. package/src/storage-browser/LocalStorageManager.ts +25 -1
  192. package/src/swapper/Swapper.ts +599 -390
  193. package/src/swapper/SwapperFactory.ts +73 -24
  194. package/src/swapper/SwapperUtils.ts +107 -60
  195. package/src/swapper/SwapperWithChain.ts +320 -81
  196. package/src/swapper/SwapperWithSigner.ts +263 -56
  197. package/src/swaps/IAddressSwap.ts +13 -3
  198. package/src/swaps/IBTCWalletSwap.ts +26 -10
  199. package/src/swaps/IClaimableSwap.ts +41 -6
  200. package/src/swaps/IClaimableSwapWrapper.ts +11 -2
  201. package/src/swaps/IRefundableSwap.ts +34 -5
  202. package/src/swaps/ISwap.ts +224 -85
  203. package/src/swaps/ISwapWithGasDrop.ts +8 -2
  204. package/src/swaps/ISwapWrapper.ts +216 -98
  205. package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +64 -18
  206. package/src/swaps/escrow_swaps/IEscrowSwap.ts +83 -37
  207. package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +61 -30
  208. package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +37 -19
  209. package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +123 -50
  210. package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +24 -11
  211. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +562 -258
  212. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +156 -62
  213. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +592 -227
  214. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +177 -74
  215. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +483 -245
  216. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +141 -59
  217. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +350 -195
  218. package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +48 -23
  219. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +87 -40
  220. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +110 -110
  221. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +89 -34
  222. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +101 -31
  223. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +556 -259
  224. package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +292 -148
  225. package/src/swaps/trusted/ln/LnForGasSwap.ts +186 -47
  226. package/src/swaps/trusted/ln/LnForGasWrapper.ts +34 -15
  227. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +262 -88
  228. package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +41 -19
  229. package/src/types/AmountData.ts +2 -1
  230. package/src/types/CustomPriceFunction.ts +8 -2
  231. package/src/types/PriceInfoType.ts +4 -4
  232. package/src/types/SwapExecutionAction.ts +97 -5
  233. package/src/types/SwapWithSigner.ts +8 -4
  234. package/src/types/Token.ts +12 -5
  235. package/src/types/TokenAmount.ts +3 -0
  236. package/src/types/fees/Fee.ts +3 -2
  237. package/src/types/fees/FeeBreakdown.ts +3 -2
  238. package/src/types/fees/PercentagePPM.ts +4 -2
  239. package/src/types/lnurl/LNURLPay.ts +20 -12
  240. package/src/types/lnurl/LNURLWithdraw.ts +17 -10
  241. package/src/types/wallets/LightningInvoiceCreateService.ts +30 -0
  242. package/src/types/wallets/MinimalBitcoinWalletInterface.ts +3 -1
  243. package/src/types/wallets/MinimalLightningNetworkWalletInterface.ts +4 -2
  244. package/src/utils/BitcoinUtils.ts +5 -0
  245. package/src/utils/SwapUtils.ts +63 -1
  246. package/src/utils/TokenUtils.ts +12 -4
  247. package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +0 -68
  248. package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +0 -2
  249. package/dist/bitcoin/LightningNetworkApi.d.ts +0 -12
  250. package/dist/bitcoin/LightningNetworkApi.js +0 -2
  251. package/dist/bitcoin/mempool/MempoolApi.d.ts +0 -350
  252. package/dist/bitcoin/mempool/MempoolApi.js +0 -311
  253. package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +0 -44
  254. package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +0 -48
  255. package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +0 -119
  256. package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +0 -361
  257. package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +0 -22
  258. package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +0 -105
  259. package/dist/errors/PaymentAuthError.d.ts +0 -11
  260. package/dist/errors/PaymentAuthError.js +0 -23
  261. package/src/errors/PaymentAuthError.ts +0 -26
@@ -26,6 +26,11 @@ import {BtcToken, SCToken, Token} from "../types/Token";
26
26
  import {LNURLWithdraw} from "../types/lnurl/LNURLWithdraw";
27
27
  import {LNURLPay} from "../types/lnurl/LNURLPay";
28
28
  import {MempoolApi, MempoolBitcoinRpc} from "@atomiqlabs/btc-mempool";
29
+ import {Messenger} from "@atomiqlabs/base";
30
+ import {LightningInvoiceCreateService} from "../types/wallets/LightningInvoiceCreateService";
31
+ import {Intermediary} from "../intermediaries/Intermediary";
32
+ import {SpvFromBTCOptions} from "../swaps/spv_swaps/SpvFromBTCWrapper";
33
+ import {SwapTypeMapping} from "../utils/SwapUtils";
29
34
 
30
35
  /**
31
36
  * Chain and signer-specific wrapper for automatic signer injection into swap methods
@@ -33,28 +38,47 @@ import {MempoolApi, MempoolBitcoinRpc} from "@atomiqlabs/btc-mempool";
33
38
  */
34
39
  export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends ChainIds<T>> {
35
40
 
41
+ private readonly signer: T[ChainIdentifier]["Signer"];
42
+ /**
43
+ * Underlying single chain swapper instance
44
+ */
45
+ private readonly swapper: SwapperWithChain<T, ChainIdentifier>;
46
+
47
+ /**
48
+ * Smart chain identifier of this swapper with chain and signer
49
+ */
36
50
  readonly chainIdentifier: ChainIdentifier;
37
- readonly swapper: SwapperWithChain<T, ChainIdentifier>;
38
- readonly signer: T[ChainIdentifier]["Signer"];
39
51
 
52
+ /**
53
+ * Pricing API used by the SDK
54
+ */
40
55
  get prices(): SwapPriceWithChain<T, ChainIdentifier> {
41
56
  return this.swapper.prices;
42
57
  }
58
+ /**
59
+ * Intermediary discovery instance
60
+ */
43
61
  get intermediaryDiscovery(): IntermediaryDiscovery {
44
62
  return this.swapper.intermediaryDiscovery;
45
63
  }
46
- get mempoolApi(): MempoolApi {
47
- return this.swapper.mempoolApi;
48
- }
49
- get bitcoinRpc(): MempoolBitcoinRpc {
50
- return this.swapper.bitcoinRpc;
51
- }
52
- get bitcoinNetwork(): BTC_NETWORK {
53
- return this.swapper.bitcoinNetwork;
54
- }
64
+ /**
65
+ * Miscellaneous utility functions
66
+ */
55
67
  get Utils(): SwapperUtils<T> {
56
68
  return this.swapper.Utils;
57
69
  }
70
+ /**
71
+ * Helper information about various swap protocol and their features:
72
+ * - `requiresInputWallet`: Whether a swap requires a connected wallet on the input chain able to sign
73
+ * arbitrary transaction
74
+ * - `requiresOutputWallet`: Whether a swap requires a connected wallet on the output chain able to sign
75
+ * arbitrary transactions
76
+ * - `supportsGasDrop`: Whether a swap supports the "gas drop" feature, allowing to user to receive a small
77
+ * amount of native token as part of the swap when swapping to smart chains
78
+ *
79
+ * Uses a `Record` type here, use the {@link SwapProtocolInfo} import for a literal readonly type, with
80
+ * pre-filled exact values in the type.
81
+ */
58
82
  get SwapTypeInfo() {
59
83
  return this.swapper.SwapTypeInfo;
60
84
  }
@@ -65,6 +89,16 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
65
89
  this.chainIdentifier = swapper.chainIdentifier;
66
90
  }
67
91
 
92
+ /**
93
+ * Creates Smart chain -> Bitcoin ({@link SwapType.TO_BTC}) swap
94
+ *
95
+ * @param tokenAddress Token address to pay with
96
+ * @param address Recipient's bitcoin address
97
+ * @param amount Amount to send in token based units (if `exactIn=true`) or receive in satoshis (if `exactIn=false`)
98
+ * @param exactIn Whether to use exact in instead of exact out
99
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
100
+ * @param options Additional options for the swap
101
+ */
68
102
  createToBTCSwap(
69
103
  tokenAddress: string,
70
104
  address: string,
@@ -77,6 +111,15 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
77
111
  .then(swap => wrapSwapWithSigner(swap, this.signer));
78
112
  }
79
113
 
114
+ /**
115
+ * Creates Smart chain -> Bitcoin Lightning ({@link SwapType.TO_BTCLN}) swap
116
+ *
117
+ * @param tokenAddress Token address to pay with
118
+ * @param paymentRequest BOLT11 lightning network invoice to be paid (needs to have a fixed amount), and the swap
119
+ * amount is taken from this fixed amount, hence only exact output swaps are supported
120
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
121
+ * @param options Additional options for the swap
122
+ */
80
123
  createToBTCLNSwap(
81
124
  tokenAddress: string,
82
125
  paymentRequest: string,
@@ -87,6 +130,16 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
87
130
  .then(swap => wrapSwapWithSigner(swap, this.signer));
88
131
  }
89
132
 
133
+ /**
134
+ * Creates Smart chain -> Bitcoin Lightning ({@link SwapType.TO_BTCLN}) swap via LNURL-pay link
135
+ *
136
+ * @param tokenAddress Token address to pay with
137
+ * @param lnurlPay LNURL-pay link to use for the payment
138
+ * @param amount Amount to send in token based units (if `exactIn=true`) or receive in satoshis (if `exactIn=false`)
139
+ * @param exactIn Whether to do an exact in swap instead of exact out
140
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
141
+ * @param options Additional options for the swap
142
+ */
90
143
  createToBTCLNSwapViaLNURL(
91
144
  tokenAddress: string,
92
145
  lnurlPay: string | LNURLPay,
@@ -99,6 +152,57 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
99
152
  .then(swap => wrapSwapWithSigner(swap, this.signer));
100
153
  }
101
154
 
155
+ /**
156
+ * Creates Smart chain -> Bitcoin Lightning ({@link SwapType.TO_BTCLN}) swap via {@link LightningInvoiceCreateService}
157
+ *
158
+ * @param tokenAddress Token address to pay with
159
+ * @param service Invoice create service object which facilitates the creation of fixed amount LN invoices
160
+ * @param amount Amount to send in token based units (if `exactIn=true`) or receive in satoshis (if `exactIn=false`)
161
+ * @param exactIn Whether to do an exact in swap instead of exact out
162
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
163
+ * @param options Additional options for the swap
164
+ */
165
+ createToBTCLNSwapViaInvoiceCreateService(
166
+ tokenAddress: string,
167
+ service: LightningInvoiceCreateService,
168
+ amount: bigint,
169
+ exactIn?: boolean,
170
+ additionalParams?: Record<string, any>,
171
+ options?: ToBTCLNOptions
172
+ ): Promise<SwapWithSigner<ToBTCLNSwap<T[ChainIdentifier]>>> {
173
+ return this.swapper.createToBTCLNSwapViaInvoiceCreateService(this.signer.getAddress(), tokenAddress, service, amount, exactIn, additionalParams, options)
174
+ .then(swap => wrapSwapWithSigner(swap, this.signer));
175
+ }
176
+
177
+ /**
178
+ * Creates Bitcoin -> Smart chain ({@link SwapType.SPV_VAULT_FROM_BTC}) swap
179
+ *
180
+ * @param tokenAddress Token address to receive
181
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
182
+ * @param exactOut Whether to use a exact out instead of exact in
183
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
184
+ * @param options Additional options for the swap
185
+ */
186
+ createFromBTCSwapNew(
187
+ tokenAddress: string,
188
+ amount: bigint,
189
+ exactOut?: boolean,
190
+ additionalParams?: Record<string, any>,
191
+ options?: SpvFromBTCOptions
192
+ ): Promise<SwapWithSigner<SpvFromBTCSwap<T[ChainIdentifier]>>> {
193
+ return this.swapper.createFromBTCSwapNew(this.signer.getAddress(), tokenAddress, amount, exactOut, additionalParams, options)
194
+ .then(swap => wrapSwapWithSigner(swap, this.signer));
195
+ }
196
+
197
+ /**
198
+ * Creates LEGACY Bitcoin -> Smart chain ({@link SwapType.FROM_BTC}) swap
199
+ *
200
+ * @param tokenAddress Token address to receive
201
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
202
+ * @param exactOut Whether to use a exact out instead of exact in
203
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
204
+ * @param options Additional options for the swap
205
+ */
102
206
  createFromBTCSwap(
103
207
  tokenAddress: string,
104
208
  amount: bigint,
@@ -110,6 +214,15 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
110
214
  .then(swap => wrapSwapWithSigner(swap, this.signer));
111
215
  }
112
216
 
217
+ /**
218
+ * Creates LEGACY Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN}) swap
219
+ *
220
+ * @param tokenAddress Token address to receive
221
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
222
+ * @param exactOut Whether to use a exact out instead of exact in
223
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
224
+ * @param options Additional options for the swap
225
+ */
113
226
  createFromBTCLNSwap(
114
227
  tokenAddress: string,
115
228
  amount: bigint,
@@ -121,6 +234,16 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
121
234
  .then(swap => wrapSwapWithSigner(swap, this.signer));
122
235
  }
123
236
 
237
+ /**
238
+ * Creates LEGACY Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN}) swap, withdrawing from
239
+ * an LNURL-withdraw link
240
+ *
241
+ * @param tokenAddress Token address to receive
242
+ * @param lnurl LNURL-withdraw link to pull the funds from
243
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
244
+ * @param exactOut Whether to use a exact out instead of exact in
245
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
246
+ */
124
247
  createFromBTCLNSwapViaLNURL(
125
248
  tokenAddress: string,
126
249
  lnurl: string | LNURLWithdraw,
@@ -132,6 +255,15 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
132
255
  .then(swap => wrapSwapWithSigner(swap, this.signer));
133
256
  }
134
257
 
258
+ /**
259
+ * Creates Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN_AUTO}) swap
260
+ *
261
+ * @param tokenAddress Token address to receive
262
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
263
+ * @param exactOut Whether to use a exact out instead of exact in
264
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
265
+ * @param options Additional options for the swap
266
+ */
135
267
  createFromBTCLNSwapNew(
136
268
  tokenAddress: string,
137
269
  amount: bigint,
@@ -143,6 +275,17 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
143
275
  .then(swap => wrapSwapWithSigner(swap, this.signer));
144
276
  }
145
277
 
278
+ /**
279
+ * Creates Bitcoin Lightning -> Smart chain ({@link SwapType.FROM_BTCLN_AUTO}) swap, withdrawing from
280
+ * an LNURL-withdraw link
281
+ *
282
+ * @param tokenAddress Token address to receive
283
+ * @param lnurl LNURL-withdraw link to pull the funds from
284
+ * @param amount Amount to send in satoshis (if `exactOut=false`) or receive in token based units (if `exactOut=true`)
285
+ * @param exactOut Whether to use a exact out instead of exact in
286
+ * @param additionalParams Additional parameters sent to the LP when creating the swap
287
+ * @param options Additional options for the swap
288
+ */
146
289
  createFromBTCLNSwapNewViaLNURL(
147
290
  tokenAddress: string,
148
291
  lnurl: string | LNURLWithdraw,
@@ -155,19 +298,58 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
155
298
  .then(swap => wrapSwapWithSigner(swap, this.signer));
156
299
  }
157
300
 
158
- createTrustedLNForGasSwap(amount: bigint, trustedIntermediaryUrl?: string): Promise<LnForGasSwap<T[ChainIdentifier]>> {
159
- return this.swapper.createTrustedLNForGasSwap(this.signer.getAddress(), amount, trustedIntermediaryUrl);
301
+ /**
302
+ * Creates a trusted Bitcoin Lightning -> Smart chain ({@link SwapType.TRUSTED_FROM_BTCLN}) gas swap
303
+ *
304
+ * @param amount Amount of native token to receive, in base units
305
+ * @param trustedIntermediaryOrUrl URL or Intermediary object of the trusted intermediary to use, otherwise uses default
306
+ * @throws {Error} If no trusted intermediary specified
307
+ */
308
+ createTrustedLNForGasSwap(amount: bigint, trustedIntermediaryOrUrl?: Intermediary | string): Promise<LnForGasSwap<T[ChainIdentifier]>> {
309
+ return this.swapper.createTrustedLNForGasSwap(this.signer.getAddress(), amount, trustedIntermediaryOrUrl);
160
310
  }
161
311
 
162
- createTrustedOnchainForGasSwap(amount: bigint, refundAddress?: string, trustedIntermediaryUrl?: string): Promise<OnchainForGasSwap<T[ChainIdentifier]>> {
163
- return this.swapper.createTrustedOnchainForGasSwap(this.signer.getAddress(), amount, refundAddress, trustedIntermediaryUrl);
312
+ /**
313
+ * Creates a trusted Bitcoin -> Smart chain ({@link SwapType.TRUSTED_FROM_BTC}) gas swap
314
+ *
315
+ * @param amount Amount of native token to receive, in base units
316
+ * @param refundAddress Bitcoin refund address, in case the swap fails the funds are refunded here
317
+ * @param trustedIntermediaryOrUrl URL or Intermediary object of the trusted intermediary to use, otherwise uses default
318
+ * @throws {Error} If no trusted intermediary specified
319
+ */
320
+ createTrustedOnchainForGasSwap(amount: bigint, refundAddress?: string, trustedIntermediaryOrUrl?: Intermediary | string): Promise<OnchainForGasSwap<T[ChainIdentifier]>> {
321
+ return this.swapper.createTrustedOnchainForGasSwap(this.signer.getAddress(), amount, refundAddress, trustedIntermediaryOrUrl);
164
322
  }
165
323
 
324
+ /**
325
+ * @internal
326
+ */
166
327
  create(srcToken: BtcToken<true>, dstToken: SCToken<ChainIdentifier>, amount: bigint, exactIn: boolean, lnurlWithdraw?: string | LNURLWithdraw): Promise<(SupportsSwapType<T[ChainIdentifier], SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoSwap<T[ChainIdentifier]> : FromBTCLNSwap<T[ChainIdentifier]>)>;
328
+ /**
329
+ * @internal
330
+ */
167
331
  create(srcToken: BtcToken<false>, dstToken: SCToken<ChainIdentifier>, amount: bigint, exactIn: boolean): Promise<(SupportsSwapType<T[ChainIdentifier], SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCSwap<T[ChainIdentifier]> : FromBTCSwap<T[ChainIdentifier]>)>;
332
+ /**
333
+ * @internal
334
+ */
168
335
  create(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<false>, amount: bigint, exactIn: boolean, address: string): Promise<ToBTCSwap<T[ChainIdentifier]>>;
336
+ /**
337
+ * @internal
338
+ */
169
339
  create(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount: bigint, exactIn: boolean, lnurlPay: string | LNURLPay): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
170
- create(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount: undefined, exactIn: false, lightningInvoice: string): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
340
+ /**
341
+ * Creates a swap from srcToken to dstToken, of a specific token amount, either specifying input amount (exactIn=true)
342
+ * or output amount (exactIn=false), NOTE: For regular -> BTC-LN (lightning) swaps the passed amount is ignored and
343
+ * invoice's pre-set amount is used instead.
344
+ *
345
+ * @param srcToken Source token of the swap, user pays this token
346
+ * @param dstToken Destination token of the swap, user receives this token
347
+ * @param amount Amount of the swap
348
+ * @param exactIn Whether the amount specified is an input amount (exactIn=true) or an output amount (exactIn=false)
349
+ * @param addressLnurlLightningInvoice Bitcoin on-chain address, lightning invoice, LNURL-pay to pay or
350
+ * LNURL-withdrawal to withdraw money from
351
+ */
352
+ create(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>, amount: undefined, exactIn: false, addressLnurlLightningInvoice: string): Promise<ToBTCLNSwap<T[ChainIdentifier]>>;
171
353
  /**
172
354
  * Creates a swap from srcToken to dstToken, of a specific token amount, either specifying input amount (exactIn=true)
173
355
  * or output amount (exactIn=false), NOTE: For regular -> BTC-LN (lightning) swaps the passed amount is ignored and
@@ -213,6 +395,16 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
213
395
  return this.swapper.getSwapById(id, this.signer.getAddress());
214
396
  }
215
397
 
398
+ /**
399
+ * Returns the swap with a proper return type, or `undefined` if not found or has wrong type
400
+ *
401
+ * @param id An ID of the swap ({@link ISwap.getId})
402
+ * @param swapType Type of the swap
403
+ */
404
+ async getTypedSwapById<S extends SwapType>(id: string, swapType: S): Promise<SwapTypeMapping<T[ChainIdentifier]>[S] | undefined> {
405
+ return this.swapper.getTypedSwapById<S>(id, swapType, this.signer.getAddress());
406
+ }
407
+
216
408
  /**
217
409
  * Synchronizes swaps from chain, this is usually ran when SDK is initialized, deletes expired quotes
218
410
  */
@@ -220,6 +412,37 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
220
412
  return this.swapper._syncSwaps(this.signer.getAddress());
221
413
  }
222
414
 
415
+ /**
416
+ * Recovers swaps from on-chain historical data.
417
+ *
418
+ * Please note that the recovered swaps might not be complete (i.e. missing amounts or addresses), as some
419
+ * of the swap data is purely off-chain and can never be recovered purely from on-chain data. This
420
+ * functions tries to recover as much swap data as possible.
421
+ *
422
+ * @param startBlockheight Optional starting blockheight for swap data recovery, will only check swaps
423
+ * initiated after this blockheight
424
+ */
425
+ async recoverSwaps(startBlockheight?: number): Promise<ISwap<T[ChainIdentifier]>[]> {
426
+ return this.swapper.recoverSwaps(this.signer.getAddress(), startBlockheight);
427
+ }
428
+
429
+ /**
430
+ * Returns the {@link Token} object for a given token
431
+ *
432
+ * @param tickerOrAddress Token to return the object for, can use multiple formats:
433
+ * - a) token ticker, such as `"BTC"`, `"SOL"`, etc.
434
+ * - b) token ticker prefixed with smart chain identifier, such as `"SOLANA-SOL"`, `"SOLANA-USDC"`, etc.
435
+ * - c) token address
436
+ */
437
+ getToken(tickerOrAddress: string): Token<ChainIdentifier> {
438
+ return this.swapper.getToken(tickerOrAddress);
439
+ }
440
+
441
+ /**
442
+ * Returns whether the SDK supports a given swap type on this chain based on currently known LPs
443
+ *
444
+ * @param swapType Swap protocol type
445
+ */
223
446
  supportsSwapType<
224
447
  Type extends SwapType
225
448
  >(swapType: Type): SupportsSwapType<T[ChainIdentifier], Type> {
@@ -227,16 +450,34 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
227
450
  }
228
451
 
229
452
  /**
230
- * Returns type of the swap based on input and output tokens specified
231
- *
232
- * @param srcToken
233
- * @param dstToken
453
+ * @internal
234
454
  */
235
455
  getSwapType(srcToken: BtcToken<true>, dstToken: SCToken<ChainIdentifier>): (SupportsSwapType<T[ChainIdentifier], SwapType.FROM_BTCLN_AUTO> extends true ? SwapType.FROM_BTCLN_AUTO : SwapType.FROM_BTCLN);
456
+ /**
457
+ * @internal
458
+ */
236
459
  getSwapType(srcToken: BtcToken<false>, dstToken: SCToken<ChainIdentifier>): (SupportsSwapType<T[ChainIdentifier], SwapType.SPV_VAULT_FROM_BTC> extends true ? SwapType.SPV_VAULT_FROM_BTC : SwapType.FROM_BTC);
460
+ /**
461
+ * @internal
462
+ */
237
463
  getSwapType(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<false>): SwapType.TO_BTC;
464
+ /**
465
+ * @internal
466
+ */
238
467
  getSwapType(srcToken: SCToken<ChainIdentifier>, dstToken: BtcToken<true>): SwapType.TO_BTCLN;
468
+ /**
469
+ * Returns type of the swap based on input and output tokens specified
470
+ *
471
+ * @param srcToken Source token
472
+ * @param dstToken Destination token
473
+ */
239
474
  getSwapType(srcToken: Token<ChainIdentifier>, dstToken: Token<ChainIdentifier>): SwapType.FROM_BTCLN_AUTO | SwapType.FROM_BTCLN | SwapType.SPV_VAULT_FROM_BTC | SwapType.FROM_BTC | SwapType.TO_BTC | SwapType.TO_BTCLN;
475
+ /**
476
+ * Returns type of the swap based on input and output tokens specified
477
+ *
478
+ * @param srcToken Source token
479
+ * @param dstToken Destination token
480
+ */
240
481
  getSwapType(srcToken: Token<ChainIdentifier>, dstToken: Token<ChainIdentifier>): SwapType.FROM_BTCLN_AUTO | SwapType.FROM_BTCLN | SwapType.SPV_VAULT_FROM_BTC | SwapType.FROM_BTC | SwapType.TO_BTC | SwapType.TO_BTCLN {
241
482
  return this.swapper.getSwapType(srcToken, dstToken);
242
483
  }
@@ -244,8 +485,8 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
244
485
  /**
245
486
  * Returns minimum/maximum limits for inputs and outputs for a swap between given tokens
246
487
  *
247
- * @param srcToken
248
- * @param dstToken
488
+ * @param srcToken Source token
489
+ * @param dstToken Destination token
249
490
  */
250
491
  getSwapLimits<A extends Token<ChainIdentifier>, B extends Token<ChainIdentifier>>(srcToken: A, dstToken: B): {
251
492
  input: {min: TokenAmount<string, A>, max?: TokenAmount<string, A>},
@@ -262,38 +503,4 @@ export class SwapperWithSigner<T extends MultiChain, ChainIdentifier extends Cha
262
503
  return this.swapper.getSwapCounterTokens(token, input);
263
504
  }
264
505
 
265
-
266
- ///////////////////////////////////
267
- /// Deprecated
268
-
269
- /**
270
- * Returns swap bounds (minimums & maximums) for different swap types & tokens
271
- * @deprecated Use getSwapLimits() instead!
272
- */
273
- getSwapBounds(): SwapBounds {
274
- return this.swapper.getSwapBounds();
275
- }
276
-
277
- /**
278
- * Returns maximum possible swap amount
279
- * @deprecated Use getSwapLimits() instead!
280
- *
281
- * @param type Type of the swap
282
- * @param token Token of the swap
283
- */
284
- getMaximum(type: SwapType, token: string): bigint {
285
- return this.swapper.getMaximum(type, token);
286
- }
287
-
288
- /**
289
- * Returns minimum possible swap amount
290
- * @deprecated Use getSwapLimits() instead!
291
- *
292
- * @param type Type of swap
293
- * @param token Token of the swap
294
- */
295
- getMinimum(type: SwapType, token: string): bigint {
296
- return this.swapper.getMinimum(type, token);
297
- }
298
-
299
506
  }
@@ -1,6 +1,7 @@
1
1
  /**
2
- * Type guard to check if an object is an IAddressSwap
3
- * @category Swaps
2
+ * Type guard to check if an object is an {@link IAddressSwap}
3
+ *
4
+ * @category Swaps/Types
4
5
  */
5
6
  export function isIAddressSwap(obj: any): obj is IAddressSwap {
6
7
  return obj!=null &&
@@ -10,11 +11,20 @@ export function isIAddressSwap(obj: any): obj is IAddressSwap {
10
11
 
11
12
  /**
12
13
  * Interface for swaps which require a user to send funds to a specific address
13
- * @category Swaps
14
+ *
15
+ * @category Swaps/Types
14
16
  */
15
17
  export interface IAddressSwap {
16
18
 
19
+ /**
20
+ * An address to which the user needs to send funds on the source chain
21
+ */
17
22
  getAddress(): string;
23
+
24
+ /**
25
+ * A hyperlink representation of the address + amount that the user needs to sends on the source chain.
26
+ * This is suitable to be displayed in a form of QR code.
27
+ */
18
28
  getHyperlink(): string;
19
29
 
20
30
  }
@@ -8,8 +8,9 @@ import {TokenAmount} from "../types/TokenAmount";
8
8
  import {BtcToken} from "../types/Token";
9
9
 
10
10
  /**
11
- * Type guard to check if an object is an IBTCWalletSwap
12
- * @category Swaps
11
+ * Type guard to check if an object is an {@link IBTCWalletSwap}
12
+ *
13
+ * @category Swaps/Types
13
14
  */
14
15
  export function isIBTCWalletSwap(obj: any): obj is IBTCWalletSwap {
15
16
  return obj!=null &&
@@ -23,17 +24,18 @@ export function isIBTCWalletSwap(obj: any): obj is IBTCWalletSwap {
23
24
 
24
25
  /**
25
26
  * Interface for swaps requiring Bitcoin wallet interaction
26
- * @category Swaps
27
+ *
28
+ * @category Swaps/Types
27
29
  */
28
30
  export interface IBTCWalletSwap {
29
31
 
30
32
  /**
31
33
  * Returns the PSBT that is already funded with wallet's UTXOs (runs a coin-selection algorithm to choose UTXOs to use),
32
34
  * also returns inputs indices that need to be signed by the wallet before submitting the PSBT back to the SDK with
33
- * `swap.submitPsbt()`
35
+ * {@link submitPsbt}
34
36
  *
35
37
  * @param _bitcoinWallet Sender's bitcoin wallet
36
- * @param feeRate Optional fee rate for the transaction, needs to be at least as big as {minimumBtcFeeRate} field
38
+ * @param feeRate Optional fee rate in sats/vB for the transaction
37
39
  * @param additionalOutputs additional outputs to add to the PSBT - can be used to collect fees from users
38
40
  */
39
41
  getFundedPsbt(
@@ -45,26 +47,36 @@ export interface IBTCWalletSwap {
45
47
  /**
46
48
  * Submits a PSBT signed by the wallet back to the SDK
47
49
  *
48
- * @param psbt A psbt - either a Transaction object or a hex or base64 encoded PSBT string
50
+ * @param psbt A PSBT, either a Transaction object or a hex or base64 encoded PSBT string
49
51
  */
50
52
  submitPsbt(psbt: Transaction | string): Promise<string>;
51
53
 
52
-
54
+ /**
55
+ * Estimates a bitcoin on-chain fee paid for the bitcoin swap transaction
56
+ *
57
+ * @param wallet Sender's bitcoin wallet
58
+ * @param feeRate Optional fee rate in sats/vB for the transaction
59
+ */
53
60
  estimateBitcoinFee(wallet: IBitcoinWallet | MinimalBitcoinWalletInterface, feeRate?: number): Promise<TokenAmount<any, BtcToken<false>> | null>;
54
61
 
55
-
62
+ /**
63
+ * Sends a swap bitcoin transaction via the passed bitcoin wallet
64
+ *
65
+ * @param wallet Sender's bitcoin wallet
66
+ * @param feeRate Optional fee rate in sats/vB for the transaction
67
+ */
56
68
  sendBitcoinTransaction(
57
69
  wallet: IBitcoinWallet | MinimalBitcoinWalletInterfaceWithSigner,
58
70
  feeRate?: number
59
71
  ): Promise<string>;
60
72
 
61
73
  /**
62
- * Waits till the bitcoin transaction confirms
74
+ * Waits till the bitcoin transaction gets the required number of confirmations
63
75
  *
64
76
  * @param updateCallback Callback called when txId is found, and also called with subsequent confirmations
65
77
  * @param checkIntervalSeconds How often to check the bitcoin transaction
66
78
  * @param abortSignal Abort signal
67
- * @throws {Error} if in invalid state (must be CLAIM_COMMITED)
79
+ * @throws {Error} if in invalid state
68
80
  */
69
81
  waitForBitcoinTransaction(
70
82
  updateCallback?: (txId?: string, confirmations?: number, targetConfirmations?: number, txEtaMs?: number) => void,
@@ -72,6 +84,10 @@ export interface IBTCWalletSwap {
72
84
  abortSignal?: AbortSignal,
73
85
  ): Promise<string>;
74
86
 
87
+ /**
88
+ * Returns the number of confirmations required for the bitcoin transaction for this swap
89
+ * to complete and settle
90
+ */
75
91
  getRequiredConfirmationsCount(): number;
76
92
 
77
93
  }
@@ -3,8 +3,9 @@ import {ISwap} from "./ISwap";
3
3
  import {ISwapWrapper, SwapTypeDefinition} from "./ISwapWrapper";
4
4
 
5
5
  /**
6
- * Type guard to check if an object is an IClaimableSwap
7
- * @category Swaps
6
+ * Type guard to check if an object is an {@link IClaimableSwap}
7
+ *
8
+ * @category Swaps/Types
8
9
  */
9
10
  export function isIClaimableSwap(obj: any): obj is IClaimableSwap {
10
11
  return obj!=null &&
@@ -14,8 +15,10 @@ export function isIClaimableSwap(obj: any): obj is IClaimableSwap {
14
15
  }
15
16
 
16
17
  /**
17
- * Interface for swaps that can be claimed
18
- * @category Swaps
18
+ * Interface for swaps that can end up in a claimable state, requiring the user to claim the
19
+ * assets on the destination chain.
20
+ *
21
+ * @category Swaps/Types
19
22
  */
20
23
  export interface IClaimableSwap<
21
24
  T extends ChainType = ChainType,
@@ -23,8 +26,40 @@ export interface IClaimableSwap<
23
26
  S extends number = number
24
27
  > extends ISwap<T, D, S> {
25
28
 
29
+ /**
30
+ * Checks whether a swap currently requires a manual claiming (settlement)
31
+ */
26
32
  isClaimable(): boolean;
27
- txsClaim(_signer?: T["Signer"] | T["NativeSigner"]): Promise<T["TX"][]>;
28
- claim(_signer?: T["Signer"] | T["NativeSigner"], abortSignal?: AbortSignal): Promise<string>;
33
+
34
+ /**
35
+ * Returns transactions for settling (claiming) the swap if the swap requires manual settlement, you can check
36
+ * so with {@link isClaimable}. After sending the transaction manually be sure to call the {@link waitTillClaimed}
37
+ * function to wait till the claim transaction is observed, processed by the SDK and state of the swap
38
+ * properly updated.
39
+ *
40
+ * @param _signer Address of the signer to create the settlement (claim) transactions for
41
+ */
42
+ txsClaim(_signer?: string | T["Signer"] | T["NativeSigner"]): Promise<T["TX"][]>;
43
+
44
+ /**
45
+ * Settles the swap by claiming the funds on the destination chain if the swap requires manual settlement,
46
+ * you can check so with {@link isClaimable}
47
+ *
48
+ * @param _signer Signer to use for signing the settlement transactions
49
+ * @param abortSignal Abort signal
50
+ * @param onBeforeTxSent Optional callback triggered before the claim transaction is broadcasted
51
+ */
52
+ claim(_signer?: T["Signer"] | T["NativeSigner"], abortSignal?: AbortSignal, onBeforeTxSent?: (txId: string) => void): Promise<string>;
53
+
54
+ /**
55
+ * Waits till the swap is successfully settled (claimed), should be called after sending the claim (settlement)
56
+ * transactions manually to wait till the SDK processes the settlement and updates the swap state accordingly
57
+ *
58
+ * @param maxWaitTimeSeconds Maximum time in seconds to wait for the swap to be settled
59
+ * @param abortSignal AbortSignal
60
+ *
61
+ * @returns {boolean} whether the swap was claimed in time or not
62
+ */
63
+ waitTillClaimed(maxWaitTimeSeconds?: number, abortSignal?: AbortSignal): Promise<boolean>;
29
64
 
30
65
  }
@@ -1,9 +1,18 @@
1
1
  import {ISwap} from "./ISwap";
2
2
  import {IClaimableSwap} from "./IClaimableSwap";
3
3
 
4
-
4
+ /**
5
+ * Interface for a swap wrapper for swaps that can end up in a claimable state, requiring the user to claim the
6
+ * assets on the destination chain.
7
+ *
8
+ * @category Swaps/Abstract
9
+ */
5
10
  export interface IClaimableSwapWrapper<T extends ISwap & IClaimableSwap = ISwap & IClaimableSwap> {
6
11
 
7
- claimableSwapStates: T["state"][];
12
+ /**
13
+ * A list of swap states when the swap is potentially claimable
14
+ * @internal
15
+ */
16
+ _claimableSwapStates: T["_state"][];
8
17
 
9
18
  }