@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
@@ -1,15 +1,75 @@
1
-
2
1
  /**
3
- * Enum representing different types of swaps
2
+ * Enum representing different types of swap protocols used by atomiq.
3
+ *
4
4
  * @category Core
5
5
  */
6
6
  export enum SwapType {
7
+ /**
8
+ * Legacy escrow (PrTLC) based swap for Bitcoin -> Smart chains, requires manual initiation of the swap
9
+ * on the destination chain.
10
+ *
11
+ * Handled by {@link FromBTCWrapper} & {@link FromBTCSwap}.
12
+ *
13
+ * Legacy swaps are only used on Solana!
14
+ */
7
15
  FROM_BTC=0,
16
+ /**
17
+ * Legacy escrow (HTLC) based swap for Bitcoin Lightning -> Smart chains, requires manual settlement of the swap on the
18
+ * destination network once the lightning network payment is received by the LP
19
+ *
20
+ * Handled by {@link FromBTCLNWrapper} & {@link FromBTCLNSwap}.
21
+ *
22
+ * Legacy swaps are only used on Solana!
23
+ */
8
24
  FROM_BTCLN=1,
25
+ /**
26
+ * Escrow based (PrTLC) swap for Smart chains -> Bitcoin
27
+ *
28
+ * Handled by {@link ToBTCWrapper} & {@link ToBTCSwap}.
29
+ */
9
30
  TO_BTC=2,
31
+ /**
32
+ * Escrow based (HTLC) swap for Smart chains -> Bitcoin Lightning
33
+ *
34
+ * Handled by {@link ToBTCLNWrapper} & {@link ToBTCLNSwap}.
35
+ */
10
36
  TO_BTCLN=3,
37
+ /**
38
+ * Trusted swap for Bitcoin -> Smart chains, to be used for minor amounts to get gas tokens on the destination
39
+ * chain, which is only needed for Solana, which still uses legacy swaps and doesn't support newer
40
+ * {@link SPV_VAULT_FROM_BTC} & {@link FROM_BTCLN_AUTO} swaps.
41
+ *
42
+ * Handled by {@link OnchainForGasWrapper} & {@link OnchainForGasSwap}.
43
+ */
11
44
  TRUSTED_FROM_BTC=4,
45
+ /**
46
+ * Trusted swap for Bitcoin Lightning -> Smart chains, to be used for minor amounts to get gas tokens on the
47
+ * destination chain, which is only needed for Solana, which still uses legacy swaps and doesn't support newer
48
+ * {@link SPV_VAULT_FROM_BTC} & {@link FROM_BTCLN_AUTO} swaps.
49
+ *
50
+ * Handled by {@link LnForGasWrapper} & {@link LnForGasSwap}.
51
+ */
12
52
  TRUSTED_FROM_BTCLN=5,
53
+ /**
54
+ * New spv vault (UTXO-controlled vault) based swaps for Bitcoin -> Smart chain swaps not requiring any
55
+ * initiation on the destination chain, and with the added possibility for the user to receive a
56
+ * native token on the destination chain as part of the swap (a "gas drop" feature).
57
+ *
58
+ * Handled by {@link SpvFromBTCWrapper} & {@link SpvFromBTCSwap}.
59
+ *
60
+ * Used on all the supported chains except Solana!
61
+ */
13
62
  SPV_VAULT_FROM_BTC=6,
63
+ /**
64
+ * New escrow based (HTLC) swaps for Bitcoin Lightning -> Smart chain swaps not requiring manual
65
+ * settlement on the destination by the user, and instead letting the LP initiate the escrow,
66
+ * with the permissionless watchtower network managing the claiming of HTLC, with the swap secret
67
+ * broadcasted over Nostr. Also adds a possibility for the user to receive a native token on the
68
+ * destination chain as part of the swap (a "gas drop" feature).
69
+ *
70
+ * Handled by {@link FromBTCLNAutoWrapper} & {@link FromBTCLNAutoSwap}.
71
+ *
72
+ * Used on all the supported chains except Solana!
73
+ */
14
74
  FROM_BTCLN_AUTO=7
15
75
  }
@@ -1,9 +1,13 @@
1
1
  /**
2
2
  * An error or inconsistency in the intermediary's returned data, this will blacklist the intermediary
3
+ *
3
4
  * @category Errors
4
5
  */
5
6
  export class IntermediaryError extends Error {
6
7
 
8
+ /**
9
+ * Whether the error is recoverable and intermediary (LP) shouldn't be blacklisted for it
10
+ */
7
11
  recoverable: boolean;
8
12
  originalStack?: string;
9
13
 
@@ -1,6 +1,7 @@
1
1
 
2
2
  /**
3
3
  * An error returned by the intermediary in a http response
4
+ *
4
5
  * @category Errors
5
6
  */
6
7
  export class RequestError extends Error {
@@ -18,7 +19,13 @@ export class RequestError extends Error {
18
19
  this.httpCode = httpCode;
19
20
  }
20
21
 
21
- static parse(msg: string, httpCode: number): RequestError {
22
+ /**
23
+ * Parses a message + a response code returned by the intermediary (LP) as an error
24
+ *
25
+ * @param msg Raw response
26
+ * @param httpCode HTTP response status code
27
+ */
28
+ static parse(msg: string, httpCode: number): RequestError | OutOfBoundsError {
22
29
  try {
23
30
  const parsed = JSON.parse(msg);
24
31
  msg = parsed.msg;
@@ -34,11 +41,18 @@ export class RequestError extends Error {
34
41
 
35
42
  /**
36
43
  * An error indicating out of bounds (amount too high or too low) on swap initialization
44
+ *
37
45
  * @category Errors
38
46
  */
39
47
  export class OutOfBoundsError extends RequestError {
40
48
 
49
+ /**
50
+ * Swap minimum in base units of the token in which the quote was requested
51
+ */
41
52
  min: bigint;
53
+ /**
54
+ * Swap maximum in base units of the token in which the quote was requested
55
+ */
42
56
  max: bigint;
43
57
 
44
58
  constructor(msg: string, httpCode: number, min: bigint, max: bigint) {
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * An error on the user side, such as invalid address provided
3
+ *
3
4
  * @category Errors
4
5
  */
5
6
  export class UserError extends Error {
package/src/index.ts CHANGED
@@ -20,7 +20,8 @@ export {
20
20
  IStorageManager,
21
21
  StorageObject,
22
22
  SwapContract,
23
- SwapData
23
+ SwapData,
24
+ AbstractSigner
24
25
  } from "@atomiqlabs/base";
25
26
 
26
27
  export {
@@ -31,8 +32,6 @@ export {
31
32
 
32
33
  export * from "./bitcoin/wallet/BitcoinWallet";
33
34
  export * from "./bitcoin/wallet/IBitcoinWallet";
34
- export * from "./types/wallets/MinimalBitcoinWalletInterface";
35
- export * from "./types/wallets/MinimalLightningNetworkWalletInterface";
36
35
  export * from "./bitcoin/wallet/SingleAddressBitcoinWallet";
37
36
 
38
37
  export {CoinselectAddressTypes} from "./bitcoin/coinselect2";
@@ -43,7 +42,6 @@ export * from "./enums/SwapDirection";
43
42
  export * from "./enums/SwapType";
44
43
 
45
44
  export * from "./errors/IntermediaryError";
46
- export * from "./errors/PaymentAuthError";
47
45
  export * from "./errors/RequestError";
48
46
  export * from "./errors/UserError";
49
47
 
@@ -119,9 +117,12 @@ export * from "./types/fees/PercentagePPM";
119
117
  export * from "./types/lnurl/LNURLPay";
120
118
  export * from "./types/lnurl/LNURLWithdraw";
121
119
 
120
+ export * from "./types/wallets/MinimalBitcoinWalletInterface";
121
+ export * from "./types/wallets/MinimalLightningNetworkWalletInterface";
122
+ export * from "./types/wallets/LightningInvoiceCreateService";
123
+
122
124
  export * from "./types/AmountData";
123
125
  export * from "./types/CustomPriceFunction";
124
- export * from "./types/PriceInfoType";
125
126
  export * from "./types/SwapExecutionAction";
126
127
  export * from "./types/SwapWithSigner";
127
128
  export * from "./types/Token";
@@ -6,6 +6,7 @@ import {tryWithRetries} from "../utils/RetryUtils";
6
6
 
7
7
  /**
8
8
  * Services offered by an intermediary
9
+ *
9
10
  * @category Pricing and LPs
10
11
  */
11
12
  export type ServicesType = {
@@ -14,6 +15,7 @@ export type ServicesType = {
14
15
 
15
16
  /**
16
17
  * Reputation data for an intermediary on a single chain
18
+ *
17
19
  * @category Pricing and LPs
18
20
  */
19
21
  export type SingleChainReputationType = {
@@ -31,6 +33,7 @@ export type SingleChainReputationType = {
31
33
 
32
34
  /**
33
35
  * Smart chain liquidity data
36
+ *
34
37
  * @category Pricing and LPs
35
38
  */
36
39
  export type SCLiquidity = {
@@ -38,14 +41,27 @@ export type SCLiquidity = {
38
41
  };
39
42
 
40
43
  /**
41
- * Represents a liquidity provider/intermediary
44
+ * Represents an intermediary (liquidity provider)
45
+ *
42
46
  * @category Pricing and LPs
43
47
  */
44
48
  export class Intermediary {
45
49
 
50
+ /**
51
+ * Base URL where the intermediary is listening for HTTP requests
52
+ */
46
53
  readonly url: string;
54
+ /**
55
+ * Addresses of the intermediary on smart chains, used for checking the provided signatures
56
+ */
47
57
  readonly addresses: {[chainIdentifier: string]: string};
58
+ /**
59
+ * Swap protocol services offered by the intermediary
60
+ */
48
61
  readonly services: ServicesType;
62
+ /**
63
+ * Input/output swap bounds for various swap protocols offered by the intermediary
64
+ */
49
65
  readonly swapBounds: {
50
66
  [swapType in SwapType]?: {
51
67
  [chainIdentifier: string]: {
@@ -62,8 +78,21 @@ export class Intermediary {
62
78
  }
63
79
  }
64
80
  }
81
+ /**
82
+ * Reputation of the intermediary on different smart chains, this is only fetched
83
+ * on-demand when creating a swap where reputation is checked
84
+ */
65
85
  reputation: { [chainIdentifier: string]: SingleChainReputationType } = {};
86
+ /**
87
+ * Liquidity of the intermediary across different smart chains, this is only fetched
88
+ * on-demand when creating a swap where intermediary's liquidity is checked
89
+ */
66
90
  liquidity: { [chainIdentifier: string]: SCLiquidity } = {};
91
+ /**
92
+ * Data about a lightning network node used by this intermediary, if it offers lightning
93
+ * network swaps, this is only fetched on-demand when creating a Bitcoin Lightning -> Smart chain
94
+ * swap through the intermediary (which necessitates checking intermediary's channel capacities)
95
+ */
67
96
  lnData?: LNNodeLiquidity;
68
97
 
69
98
  constructor(
@@ -96,6 +125,13 @@ export class Intermediary {
96
125
  }
97
126
  }
98
127
 
128
+ /**
129
+ * Returns the input/output swap limit for given swap type, chain and token
130
+ *
131
+ * @param swapType Swap protocol service to check
132
+ * @param chainId Chain identifier of the smart chain to check
133
+ * @param tokenAddress Address of the token to check
134
+ */
99
135
  getSwapLimits(swapType: SwapType, chainId: string, tokenAddress: string): {input: {min?: bigint, max?: bigint}, output: {min?: bigint, max?: bigint}} | undefined {
100
136
  return this.swapBounds[swapType]?.[chainId]?.[tokenAddress];
101
137
  }
@@ -103,8 +139,8 @@ export class Intermediary {
103
139
  /**
104
140
  * Returns tokens supported by the intermediary, optionally constrained to the specific swap types
105
141
  *
106
- * @param chainIdentifier
107
- * @param swapTypesArr
142
+ * @param chainIdentifier Chain identifier of the smart chain to check
143
+ * @param swapTypesArr An array of swap type services to check
108
144
  * @private
109
145
  */
110
146
  private getSupportedTokens(chainIdentifier: string, swapTypesArr: SwapType[] = [
@@ -127,9 +163,10 @@ export class Intermediary {
127
163
  /**
128
164
  * Fetches, returns and saves the reputation of the intermediary, either for all or just for a single token
129
165
  *
130
- * @param chainIdentifier
131
- * @param swapContract
132
- * @param tokens
166
+ * @param chainIdentifier Chain identifier of the chain on which to fetch the reputation
167
+ * @param swapContract Swap contract for the requested smart chain
168
+ * @param tokens An optional array of tokens to fetch the data for (by default it uses all tokens supported
169
+ * by the intermediary)
133
170
  * @param abortSignal
134
171
  */
135
172
  async getReputation(
@@ -166,11 +203,11 @@ export class Intermediary {
166
203
  }
167
204
 
168
205
  /**
169
- * Fetches, returns and saves the liquidity of the intermediaryfor a specific token
206
+ * Fetches, returns and saves the liquidity of the intermediary for a specific token
170
207
  *
171
- * @param chainIdentifier
172
- * @param swapContract
173
- * @param token
208
+ * @param chainIdentifier Chain identifier of the chain on which to fetch the reputation
209
+ * @param swapContract Swap contract for the requested smart chain
210
+ * @param token Token address of the token to fetch the liquidity for
174
211
  * @param abortSignal
175
212
  */
176
213
  async getLiquidity(
@@ -191,11 +228,21 @@ export class Intermediary {
191
228
  return result;
192
229
  }
193
230
 
231
+ /**
232
+ * Checks whether the intermediary supports swaps of any tokens on the smart chain
233
+ *
234
+ * @param chainIdentifier Chain identifier of the smart chain
235
+ */
194
236
  supportsChain(chainIdentifier: string): boolean {
195
237
  if(this.addresses[chainIdentifier]==null) return false;
196
238
  return this.getSupportedTokens(chainIdentifier).size!==0;
197
239
  }
198
240
 
241
+ /**
242
+ * Returns intermediary's address on a given smart chain
243
+ *
244
+ * @param chainIdentifier Chain identifier of the smart chain
245
+ */
199
246
  getAddress(chainIdentifier: string) {
200
247
  return this.addresses[chainIdentifier];
201
248
  }
@@ -1,6 +1,6 @@
1
1
  import {Intermediary, ServicesType} from "./Intermediary";
2
2
  import {SwapType} from "../enums/SwapType";
3
- import {SignatureVerificationError, SwapContract} from "@atomiqlabs/base";
3
+ import {SwapContract} from "@atomiqlabs/base";
4
4
  import {EventEmitter} from "events";
5
5
  import {Buffer} from "buffer";
6
6
  import {bigIntMax, bigIntMin, extendAbortController} from "../utils/Utils";
@@ -10,7 +10,8 @@ import {httpGet} from "../http/HttpUtils";
10
10
  import {tryWithRetries} from "../utils/RetryUtils";
11
11
 
12
12
  /**
13
- * Swap handler type enum for intermediary communication
13
+ * Swap handler type mapping for intermediary communication
14
+ *
14
15
  * @category Pricing and LPs
15
16
  */
16
17
  export enum SwapHandlerType {
@@ -26,6 +27,7 @@ export enum SwapHandlerType {
26
27
 
27
28
  /**
28
29
  * Swap handler information type
30
+ *
29
31
  * @category Pricing and LPs
30
32
  */
31
33
  export type SwapHandlerInfoType = {
@@ -47,6 +49,7 @@ type InfoHandlerResponseEnvelope = {
47
49
 
48
50
  /**
49
51
  * Token bounds (min/max) for swaps
52
+ *
50
53
  * @category Pricing and LPs
51
54
  */
52
55
  export type TokenBounds = {
@@ -57,7 +60,8 @@ export type TokenBounds = {
57
60
  }
58
61
 
59
62
  /**
60
- * Multi-chain token bounds
63
+ * Multi-chain token bounds (min/max) for swaps
64
+ *
61
65
  * @category Pricing and LPs
62
66
  */
63
67
  export type MultichainTokenBounds = {
@@ -65,7 +69,8 @@ export type MultichainTokenBounds = {
65
69
  }
66
70
 
67
71
  /**
68
- * Swap bounds by type
72
+ * Swap bounds by swap protocol type
73
+ *
69
74
  * @category Pricing and LPs
70
75
  */
71
76
  export type SwapBounds = {
@@ -74,6 +79,7 @@ export type SwapBounds = {
74
79
 
75
80
  /**
76
81
  * Multi-chain swap bounds
82
+ *
77
83
  * @category Pricing and LPs
78
84
  */
79
85
  export type MultichainSwapBounds = {
@@ -82,7 +88,7 @@ export type MultichainSwapBounds = {
82
88
 
83
89
  /**
84
90
  * Converts SwapHandlerType (represented as string & used in REST API communication with intermediaries) to regular
85
- * SwapType
91
+ * {@link SwapType}
86
92
  *
87
93
  * @param swapHandlerType
88
94
  */
@@ -108,7 +114,7 @@ function swapHandlerTypeToSwapType(swapHandlerType: SwapHandlerType): SwapType {
108
114
  }
109
115
 
110
116
  /**
111
- * A default intermediary comparator, only takes to announced fee into consideration
117
+ * A default intermediary comparator, only takes the announced fee into consideration
112
118
  *
113
119
  * @param swapType
114
120
  * @param tokenAddress
@@ -147,22 +153,41 @@ const REGISTRY_URL = "https://api.github.com/repos/adambor/SolLightning-registry
147
153
  const DEFAULT_CHAIN = "SOLANA";
148
154
 
149
155
  /**
150
- * Discovery service for available liquidity providers/intermediaries
156
+ * Discovery service for available intermediaries (liquidity providers)
157
+ *
151
158
  * @category Pricing and LPs
152
159
  */
153
160
  export class IntermediaryDiscovery extends EventEmitter {
154
161
 
162
+ /**
163
+ * A current list of active intermediaries
164
+ */
155
165
  intermediaries: Intermediary[] = [];
156
166
 
167
+ /**
168
+ * Swap contracts for checking intermediary signatures
169
+ */
157
170
  swapContracts: {[key: string]: SwapContract};
171
+ /**
172
+ * Registry URL used as a source for the list of intermediaries, this should be a link to a
173
+ * github-hosted JSON file
174
+ */
158
175
  registryUrl: string;
159
176
 
177
+ /**
178
+ * Timeout for the HTTP handshake (/info) requests sent to the intermediaries
179
+ */
160
180
  httpRequestTimeout?: number;
161
181
  /**
162
- * Maximum time (in millis) to wait for other LP's responses after the first one was founds
182
+ * Maximum time (in millis) to wait for other intermediary's responses after the first one was founds
163
183
  */
164
184
  maxWaitForOthersTimeout?: number;
165
185
 
186
+ /**
187
+ * The intermediary URLs passed in the constructor, to be used instead of querying the registry
188
+ *
189
+ * @private
190
+ */
166
191
  private overrideNodeUrls?: string[];
167
192
 
168
193
  constructor(
@@ -283,9 +308,13 @@ export class IntermediaryDiscovery extends EventEmitter {
283
308
  }
284
309
 
285
310
  /**
286
- * Returns the intermediary at the provided URL, either from the already fetched list of LPs or fetches the data on-demand
311
+ * Returns the intermediary at the provided URL, either from the already fetched list of LPs
312
+ * or fetches the data on-demand, by sending the handshake HTTP request (/info) to the LP.
287
313
  *
288
- * @param url
314
+ * Doesn't save the fetched intermediary to the list of intermediaries if it isn't already
315
+ * part of the known intermediaries
316
+ *
317
+ * @param url Base URL of the intermediary, which accepts HTTP requests
289
318
  * @param abortSignal
290
319
  */
291
320
  getIntermediary(url: string, abortSignal?: AbortSignal): Promise<Intermediary | null> {
@@ -296,6 +325,7 @@ export class IntermediaryDiscovery extends EventEmitter {
296
325
 
297
326
  /**
298
327
  * Reloads the saves a list of intermediaries
328
+ *
299
329
  * @param abortSignal
300
330
  */
301
331
  async reloadIntermediaries(abortSignal?: AbortSignal): Promise<void> {
@@ -334,6 +364,9 @@ export class IntermediaryDiscovery extends EventEmitter {
334
364
  return this.reloadIntermediaries(abortSignal);
335
365
  }
336
366
 
367
+ /**
368
+ * Returns known swap bounds (in satoshis - BTC) by aggregating values from all known intermediaries
369
+ */
337
370
  getMultichainSwapBounds(): MultichainSwapBounds {
338
371
  const bounds: MultichainSwapBounds = {};
339
372
 
@@ -366,7 +399,7 @@ export class IntermediaryDiscovery extends EventEmitter {
366
399
  }
367
400
 
368
401
  /**
369
- * Returns aggregate swap bounds (in sats - BTC) as indicated by the intermediaries
402
+ * Returns aggregate swap bounds (in satoshis - BTC) as indicated by the intermediaries
370
403
  */
371
404
  getSwapBounds(chainIdentifier: string): SwapBounds {
372
405
  const bounds: SwapBounds = {};
@@ -397,15 +430,15 @@ export class IntermediaryDiscovery extends EventEmitter {
397
430
  }
398
431
 
399
432
  /**
400
- * Returns the aggregate swap minimum (in sats - BTC) for a specific swap type & token
433
+ * Returns the aggregate swap minimum (in satoshis - BTC) for a specific swap type & token
401
434
  * as indicated by the intermediaries
402
435
  *
403
- * @param chainIdentifier
404
- * @param swapType
405
- * @param token
436
+ * @param chainIdentifier Chain identifier of the smart chain
437
+ * @param swapType Swap protocol type
438
+ * @param tokenAddress Token address
406
439
  */
407
- getSwapMinimum(chainIdentifier: string, swapType: SwapType, token: any): number | null {
408
- const tokenStr = token.toString();
440
+ getSwapMinimum(chainIdentifier: string, swapType: SwapType, tokenAddress: string): number | null {
441
+ const tokenStr = tokenAddress.toString();
409
442
  return this.intermediaries.reduce<number | null>((prevMin: number | null, intermediary: Intermediary) => {
410
443
  const swapService = intermediary.services[swapType];
411
444
  if(swapService==null) return prevMin;
@@ -417,15 +450,15 @@ export class IntermediaryDiscovery extends EventEmitter {
417
450
  }
418
451
 
419
452
  /**
420
- * Returns the aggregate swap maximum (in sats - BTC) for a specific swap type & token
453
+ * Returns the aggregate swap maximum (in satoshis - BTC) for a specific swap type & token
421
454
  * as indicated by the intermediaries
422
455
  *
423
- * @param chainIdentifier
424
- * @param swapType
425
- * @param token
456
+ * @param chainIdentifier Chain identifier of the smart chain
457
+ * @param swapType Swap protocol type
458
+ * @param tokenAddress Token address
426
459
  */
427
- getSwapMaximum(chainIdentifier: string, swapType: SwapType, token: any): number | null {
428
- const tokenStr = token.toString();
460
+ getSwapMaximum(chainIdentifier: string, swapType: SwapType, tokenAddress: string): number | null {
461
+ const tokenStr = tokenAddress.toString();
429
462
  return this.intermediaries.reduce<number | null>((prevMax: number | null, intermediary: Intermediary) => {
430
463
  const swapService = intermediary.services[swapType];
431
464
  if(swapService==null) return prevMax;
@@ -439,13 +472,13 @@ export class IntermediaryDiscovery extends EventEmitter {
439
472
  /**
440
473
  * Returns swap candidates for a specific swap type & token address
441
474
  *
442
- * @param chainIdentifier
443
- * @param swapType
444
- * @param tokenAddress
475
+ * @param chainIdentifier Chain identifier of the smart chain
476
+ * @param swapType Swap protocol type
477
+ * @param tokenAddress Token address
445
478
  * @param amount Amount to be swapped in sats - BTC
446
479
  * @param count How many intermediaries to return at most
447
480
  */
448
- getSwapCandidates(chainIdentifier: string, swapType: SwapType, tokenAddress: any, amount?: bigint, count?: number): Intermediary[] {
481
+ getSwapCandidates(chainIdentifier: string, swapType: SwapType, tokenAddress: string, amount?: bigint, count?: number): Intermediary[] {
449
482
  const candidates = this.intermediaries.filter(e => {
450
483
  const swapService = e.services[swapType];
451
484
  if(swapService==null) return false;
@@ -13,6 +13,7 @@ import {tryWithRetries} from "../utils/RetryUtils";
13
13
 
14
14
  /**
15
15
  * Asset configuration for redundant swap pricing
16
+ *
16
17
  * @category Pricing and LPs
17
18
  */
18
19
  export type RedundantSwapPriceAssets<T extends MultiChain> = {
@@ -49,10 +50,20 @@ const logger = getLogger("RedundantSwapPrice: ");
49
50
  /**
50
51
  * Swap price API using multiple price sources, handles errors on the APIs and automatically switches between them, such
51
52
  * that there always is a functional API
53
+ *
52
54
  * @category Pricing and LPs
53
55
  */
54
56
  export class RedundantSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T> {
55
57
 
58
+ /**
59
+ * Creates a new {@link RedundantSwapPrice} instance from an asset list and other data, using all
60
+ * the available price providers: {@link BinancePriceProvider}, {@link OKXPriceProvider},
61
+ * {@link CoinGeckoPriceProvider}, {@link CoinPaprikaPriceProvider}, {@link KrakenPriceProvider}
62
+ *
63
+ * @param maxAllowedFeeDiffPPM Maximum allowed price difference between returned swap prices & market prices
64
+ * @param assets Specifications of the assets
65
+ * @param cacheTimeout Timeout of the internal cache holding prices
66
+ */
56
67
  static createFromTokenMap<T extends MultiChain>(maxAllowedFeeDiffPPM: bigint, assets: RedundantSwapPriceAssets<T>, cacheTimeout?: number): RedundantSwapPrice<T> {
57
68
  const priceApis = [
58
69
  new BinancePriceProvider(assets.map(coinData => {
@@ -90,8 +101,8 @@ export class RedundantSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T
90
101
  return new RedundantSwapPrice(maxAllowedFeeDiffPPM, assets, priceApis, cacheTimeout);
91
102
  }
92
103
 
93
- coinsDecimals: CoinDecimals<T> = {};
94
- priceApis: {
104
+ protected coinsDecimals: CoinDecimals<T> = {};
105
+ protected priceApis: {
95
106
  priceApi: IPriceProvider<T>,
96
107
  operational?: boolean
97
108
  }[];
@@ -174,7 +185,7 @@ export class RedundantSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T
174
185
  * @param chainIdentifier
175
186
  * @param token
176
187
  * @param abortSignal
177
- * @private
188
+ * @protected
178
189
  */
179
190
  protected fetchPrice<C extends ChainIds<T>>(chainIdentifier: C, token: string, abortSignal?: AbortSignal): Promise<bigint> {
180
191
  return tryWithRetries(async () => {
@@ -193,12 +204,14 @@ export class RedundantSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T
193
204
  }, undefined, RequestError, abortSignal);
194
205
  }
195
206
 
207
+ /**
208
+ * @inheritDoc
209
+ */
196
210
  protected getDecimals<C extends ChainIds<T>>(chainIdentifier: C, token: string): number | null {
197
211
  if(this.coinsDecimals[chainIdentifier]==null) return null;
198
212
  return this.coinsDecimals[chainIdentifier]?.[token.toString()] ?? null;
199
213
  }
200
214
 
201
-
202
215
  /**
203
216
  * Fetches BTC price in USD in parallel from multiple maybe operational price APIs
204
217
  *
@@ -228,6 +241,13 @@ export class RedundantSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T
228
241
  }
229
242
  }
230
243
 
244
+ /**
245
+ * Fetches the USD prices, first tries to use the operational price API (if any) and if that fails it falls back
246
+ * to using maybe operational price APIs
247
+ *
248
+ * @param abortSignal
249
+ * @protected
250
+ */
231
251
  protected fetchUsdPrice(abortSignal?: AbortSignal): Promise<number> {
232
252
  return tryWithRetries(() => {
233
253
  const operationalPriceApi = this.getOperationalPriceApi();
@@ -3,7 +3,8 @@ import {ICachedSwapPrice} from "./abstract/ICachedSwapPrice";
3
3
  import {ChainIds, MultiChain} from "../swapper/Swapper";
4
4
 
5
5
  /**
6
- * Swap price API using single price source
6
+ * Swap price API using a single price source
7
+ *
7
8
  * @category Pricing and LPs
8
9
  */
9
10
  export class SingleSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T> {
@@ -29,17 +30,19 @@ export class SingleSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T> {
29
30
  }
30
31
 
31
32
  /**
32
- * Returns the decimal places of the specified token, or -1 if token should be ignored, returns null if
33
- * token is not found
34
- *
35
- * @param chainIdentifier
36
- * @param token
37
- * @protected
33
+ * @inheritDoc
38
34
  */
39
35
  protected getDecimals<C extends ChainIds<T>>(chainIdentifier: C, token: string): number | null {
40
36
  return this.priceProvider.getDecimals(chainIdentifier, token.toString());
41
37
  }
42
38
 
39
+ /**
40
+ * Fetches BTC price in USD
41
+ *
42
+ * @param abortSignal
43
+ * @protected
44
+ * @returns token price in uSats (micro sats)
45
+ */
43
46
  protected fetchUsdPrice(abortSignal?: AbortSignal): Promise<number> {
44
47
  return this.priceProvider.getUsdPrice(abortSignal);
45
48
  }