@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
@@ -13,13 +13,7 @@ import { ISwap } from "../../../ISwap";
13
13
  import { AmountData } from "../../../../types/AmountData";
14
14
  import { LNURLPayParamsWithUrl } from "../../../../types/lnurl/LNURLPay";
15
15
  import { AllOptional } from "../../../../utils/TypeUtils";
16
- export type LightningWalletCallback = (valueSats: number, abortSignal?: AbortSignal) => Promise<string>;
17
- export type InvoiceCreateService = {
18
- getInvoice: LightningWalletCallback;
19
- minMsats?: bigint;
20
- maxMSats?: bigint;
21
- };
22
- export declare function isInvoiceCreateService(obj: any): obj is InvoiceCreateService;
16
+ import { LightningInvoiceCreateService } from "../../../../types/wallets/LightningInvoiceCreateService";
23
17
  export type ToBTCLNOptions = {
24
18
  expirySeconds?: number;
25
19
  maxFee?: bigint | Promise<bigint>;
@@ -33,13 +27,29 @@ export type ToBTCLNWrapperOptions = ISwapWrapperOptions & {
33
27
  paymentTimeoutSeconds: number;
34
28
  };
35
29
  export type ToBTCLNDefinition<T extends ChainType> = IToBTCDefinition<T, ToBTCLNWrapper<T>, ToBTCLNSwap<T>>;
30
+ /**
31
+ * Escrow based (HTLC) swap for Smart chains -> Bitcoin lightning
32
+ *
33
+ * @category Swaps/Smart chain → Lightning
34
+ */
36
35
  export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCLNDefinition<T>, ToBTCLNWrapperOptions> {
37
- readonly TYPE = SwapType.TO_BTCLN;
38
- readonly swapDeserializer: typeof ToBTCLNSwap;
36
+ readonly TYPE: SwapType.TO_BTCLN;
37
+ /**
38
+ * @internal
39
+ */
40
+ readonly _swapDeserializer: typeof ToBTCLNSwap;
39
41
  constructor(chainIdentifier: string, unifiedStorage: UnifiedSwapStorage<T>, unifiedChainEvents: UnifiedSwapEventListener<T>, chain: T["ChainInterface"], contract: T["Contract"], prices: ISwapPrice, tokens: WrapperCtorTokens, swapDataDeserializer: new (data: any) => T["Data"], options?: AllOptional<ToBTCLNWrapperOptions>, events?: EventEmitter<{
40
42
  swapState: [ISwap];
41
43
  }>);
42
44
  private toRequiredSwapOptions;
45
+ /**
46
+ * Verifies whether a given payment hash was already paid by checking the local
47
+ * storage of known swaps
48
+ *
49
+ * @param paymentHash Payment hash to check
50
+ *
51
+ * @private
52
+ */
43
53
  private checkPaymentHashWasPaid;
44
54
  /**
45
55
  * Calculates maximum lightning network routing fee based on amount
@@ -47,8 +57,10 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
47
57
  * @param amount BTC amount of the swap in satoshis
48
58
  * @param overrideBaseFee Override wrapper's default base fee
49
59
  * @param overrideFeePPM Override wrapper's default PPM
50
- * @private
60
+ *
51
61
  * @returns Maximum lightning routing fee in sats
62
+ *
63
+ * @private
52
64
  */
53
65
  private calculateFeeForAmount;
54
66
  /**
@@ -62,8 +74,10 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
62
74
  * @param options Swap options as passed to the swap create function
63
75
  * @param data Parsed swap data returned by the LP
64
76
  * @param requiredTotal Required total to be paid on the input (for exactIn swaps)
65
- * @private
77
+ *
66
78
  * @throws {IntermediaryError} In case the response is not valid
79
+ *
80
+ * @private
67
81
  */
68
82
  private verifyReturnedData;
69
83
  /**
@@ -79,22 +93,24 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
79
93
  * @param abort Abort signal or controller, if AbortController is passed it is used as-is, when AbortSignal is passed
80
94
  * it is extended with extendAbortController and then used
81
95
  * @param additionalParams Additional params that should be sent to the LP
96
+ *
82
97
  * @private
83
98
  */
84
99
  private getIntermediaryQuote;
85
100
  /**
86
- * Returns a newly created swap, paying for 'bolt11PayRequest' - a bitcoin LN invoice
87
- *
88
- * @param signer Smartchain signer's address initiating the swap
89
- * @param bolt11PayRequest BOLT11 payment request (bitcoin lightning invoice) you wish to pay
90
- * @param amountData Amount of token & amount to swap
91
- * @param lps LPs (liquidity providers) to get the quotes from
92
- * @param options Quote options
93
- * @param additionalParams Additional parameters sent to the LP when creating the swap
94
- * @param abortSignal Abort signal for aborting the process
95
- * @param preFetches Existing pre-fetches for the swap (only used internally for LNURL swaps)
101
+ * Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol,
102
+ * the amount is parsed from the provided lightning network payment request (bolt11 invoice)
103
+ *
104
+ * @param signer Source chain signer address initiating the swap
105
+ * @param recipient BOLT11 payment request (bitcoin lightning invoice) you wish to pay
106
+ * @param amountData Token to swap
107
+ * @param lps An array of intermediaries (LPs) to get the quotes from
108
+ * @param options Optional additional quote options
109
+ * @param additionalParams Optional additional parameters sent to the LP when creating the swap
110
+ * @param abortSignal Abort signal
111
+ * @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
96
112
  */
97
- create(signer: string, bolt11PayRequest: string, amountData: Omit<AmountData, "amount">, lps: Intermediary[], options?: ToBTCLNOptions, additionalParams?: Record<string, any>, abortSignal?: AbortSignal, preFetches?: {
113
+ create(signer: string, recipient: string, amountData: Omit<AmountData, "amount">, lps: Intermediary[], options?: ToBTCLNOptions, additionalParams?: Record<string, any>, abortSignal?: AbortSignal, preFetches?: {
98
114
  feeRatePromise: Promise<string | undefined>;
99
115
  pricePreFetchPromise: Promise<bigint | undefined>;
100
116
  usdPricePrefetchPromise: Promise<number | undefined>;
@@ -107,51 +123,58 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
107
123
  * Parses and fetches lnurl pay params from the specified lnurl
108
124
  *
109
125
  * @param lnurl LNURL to be parsed and fetched
110
- * @param abortSignal
111
- * @private
126
+ * @param abortSignal Abort signal
112
127
  * @throws {UserError} if the LNURL is invalid or if it's not a LNURL-pay
128
+ *
129
+ * @private
113
130
  */
114
131
  private getLNURLPay;
115
132
  /**
116
133
  * Returns the quote/swap from the given LP
117
134
  *
118
- * @param signer Smartchain signer's address initiating the swap
119
- * @param amountData
135
+ * @param signer Source chain signer address initiating the swap
136
+ * @param amountData Token to swap
120
137
  * @param invoiceCreateService Service for creating fixed amount invoices
121
- * @param lp Intermediary
122
- * @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay
123
- * @param options Options as passed to the swap create function
124
- * @param preFetches
125
- * @param abortSignal
138
+ * @param lp Intermediary (LPs) to get the quote from
139
+ * @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay, used to estimate
140
+ * network fees for an actual invoice
141
+ * @param options Optional additional quote options
142
+ * @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
143
+ * @param abortSignal Abort signal
126
144
  * @param additionalParams Additional params to be sent to the intermediary
145
+ *
127
146
  * @private
128
147
  */
129
148
  private getIntermediaryQuoteExactIn;
130
149
  /**
131
- * Returns a newly created swap, allowing exactIn swaps with invoice creation service
132
- *
133
- * @param signer Smartchain signer's address initiating the swap
134
- * @param invoiceCreateServicePromise
135
- * @param amountData Amount of token & amount to swap
136
- * @param lps LPs (liquidity providers/intermediaries) to get the quotes from
137
- * @param options Quote options
138
- * @param additionalParams Additional parameters sent to the intermediary when creating the swap
139
- * @param abortSignal Abort signal for aborting the process
150
+ * Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol via
151
+ * invoice creation service. This allows exactIn swaps by requesting the desired fixed amount lightning
152
+ * network invoice from the service.
153
+ *
154
+ * @param signer Source chain signer address initiating the swap
155
+ * @param invoiceCreateServicePromise Service to request destination lightning network invoices from
156
+ * @param amountData Amount, token and exact input/output data for to swap
157
+ * @param lps An array of intermediaries (LPs) to get the quotes from
158
+ * @param options Optional additional quote options
159
+ * @param additionalParams Optional additional parameters sent to the LP when creating the swap
160
+ * @param abortSignal Abort signal
140
161
  */
141
- createViaInvoiceCreateService(signer: string, invoiceCreateServicePromise: Promise<InvoiceCreateService>, amountData: AmountData, lps: Intermediary[], options?: ToBTCLNOptions, additionalParams?: Record<string, any>, abortSignal?: AbortSignal): Promise<{
162
+ createViaInvoiceCreateService(signer: string, invoiceCreateServicePromise: Promise<LightningInvoiceCreateService>, amountData: AmountData, lps: Intermediary[], options?: ToBTCLNOptions, additionalParams?: Record<string, any>, abortSignal?: AbortSignal): Promise<{
142
163
  quote: Promise<ToBTCLNSwap<T>>;
143
164
  intermediary: Intermediary;
144
165
  }[]>;
145
166
  /**
146
- * Returns a newly created swap, paying for 'lnurl' - a lightning LNURL-pay
147
- *
148
- * @param signer Smartchain signer's address initiating the swap
149
- * @param lnurl LMURL-pay you wish to pay
150
- * @param amountData Amount of token & amount to swap
151
- * @param lps LPs (liquidity providers/intermediaries) to get the quotes from
152
- * @param options Quote options
153
- * @param additionalParams Additional parameters sent to the intermediary when creating the swap
154
- * @param abortSignal Abort signal for aborting the process
167
+ * Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol. Pays to
168
+ * an LNURL-pay link. This allows exactIn swaps by requesting the desired fixed amount lightning
169
+ * network invoice from the LNURL service.
170
+ *
171
+ * @param signer Source chain signer address initiating the swap
172
+ * @param lnurl LNURL-pay link of the recipient
173
+ * @param amountData Amount, token and exact input/output data for to swap
174
+ * @param lps An array of intermediaries (LPs) to get the quotes from
175
+ * @param options Optional additional quote options
176
+ * @param additionalParams Optional additional parameters sent to the LP when creating the swap
177
+ * @param abortSignal Abort signal
155
178
  */
156
179
  createViaLNURL(signer: string, lnurl: string | LNURLPayParamsWithUrl, amountData: AmountData, lps: Intermediary[], options?: ToBTCLNOptions & {
157
180
  comment?: string;
@@ -159,6 +182,9 @@ export declare class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T
159
182
  quote: Promise<ToBTCLNSwap<T>>;
160
183
  intermediary: Intermediary;
161
184
  }[]>;
185
+ /**
186
+ * @inheritDoc
187
+ */
162
188
  recoverFromSwapDataAndState(init: {
163
189
  data: T["Data"];
164
190
  getInitTxId: () => Promise<string>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToBTCLNWrapper = exports.isInvoiceCreateService = void 0;
3
+ exports.ToBTCLNWrapper = void 0;
4
4
  const bolt11_1 = require("@atomiqlabs/bolt11");
5
5
  const ToBTCLNSwap_1 = require("./ToBTCLNSwap");
6
6
  const IToBTCWrapper_1 = require("../IToBTCWrapper");
@@ -15,13 +15,11 @@ const LNURL_1 = require("../../../../lnurl/LNURL");
15
15
  const IToBTCSwap_1 = require("../IToBTCSwap");
16
16
  const sha2_1 = require("@noble/hashes/sha2");
17
17
  const RetryUtils_1 = require("../../../../utils/RetryUtils");
18
- function isInvoiceCreateService(obj) {
19
- return typeof (obj) === "object" &&
20
- typeof (obj.getInvoice) === "function" &&
21
- (obj.minMsats == null || typeof (obj.minMsats) === "bigint") &&
22
- (obj.maxMSats == null || typeof (obj.maxMSats) === "bigint");
23
- }
24
- exports.isInvoiceCreateService = isInvoiceCreateService;
18
+ /**
19
+ * Escrow based (HTLC) swap for Smart chains -> Bitcoin lightning
20
+ *
21
+ * @category Swaps/Smart chain Lightning
22
+ */
25
23
  class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
26
24
  constructor(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, contract, prices, tokens, swapDataDeserializer, options, events) {
27
25
  super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, contract, prices, tokens, swapDataDeserializer, {
@@ -30,12 +28,15 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
30
28
  lightningFeePPM: options?.lightningFeePPM ?? 2000
31
29
  }, events);
32
30
  this.TYPE = SwapType_1.SwapType.TO_BTCLN;
33
- this.swapDeserializer = ToBTCLNSwap_1.ToBTCLNSwap;
31
+ /**
32
+ * @internal
33
+ */
34
+ this._swapDeserializer = ToBTCLNSwap_1.ToBTCLNSwap;
34
35
  }
35
36
  toRequiredSwapOptions(amountData, options, pricePreFetchPromise, abortSignal) {
36
- const expirySeconds = options?.expirySeconds ?? this.options.paymentTimeoutSeconds;
37
- const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this.options.lightningBaseFee);
38
- const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this.options.lightningFeePPM);
37
+ const expirySeconds = options?.expirySeconds ?? this._options.paymentTimeoutSeconds;
38
+ const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this._options.lightningBaseFee);
39
+ const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this._options.lightningFeePPM);
39
40
  let maxFee;
40
41
  if (options?.maxFee != null) {
41
42
  maxFee = options.maxFee;
@@ -43,11 +44,11 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
43
44
  else if (amountData.exactIn) {
44
45
  if (pricePreFetchPromise != null) {
45
46
  maxFee = pricePreFetchPromise
46
- .then(val => this.prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal, val))
47
+ .then(val => this._prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal, val))
47
48
  .then(_maxBaseFee => this.calculateFeeForAmount(amountData.amount, _maxBaseFee, maxRoutingPPM));
48
49
  }
49
50
  else {
50
- maxFee = this.prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal)
51
+ maxFee = this._prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal)
51
52
  .then(_maxBaseFee => this.calculateFeeForAmount(amountData.amount, _maxBaseFee, maxRoutingPPM));
52
53
  }
53
54
  }
@@ -62,10 +63,18 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
62
63
  maxFee
63
64
  };
64
65
  }
66
+ /**
67
+ * Verifies whether a given payment hash was already paid by checking the local
68
+ * storage of known swaps
69
+ *
70
+ * @param paymentHash Payment hash to check
71
+ *
72
+ * @private
73
+ */
65
74
  async checkPaymentHashWasPaid(paymentHash) {
66
- const swaps = await this.unifiedStorage.query([[{ key: "type", value: this.TYPE }, { key: "paymentHash", value: paymentHash }]], (obj) => new this.swapDeserializer(this, obj));
75
+ const swaps = await this.unifiedStorage.query([[{ key: "type", value: this.TYPE }, { key: "paymentHash", value: paymentHash }]], (obj) => new this._swapDeserializer(this, obj));
67
76
  for (let value of swaps) {
68
- if (value.state === IToBTCSwap_1.ToBTCSwapState.CLAIMED || value.state === IToBTCSwap_1.ToBTCSwapState.SOFT_CLAIMED)
77
+ if (value._state === IToBTCSwap_1.ToBTCSwapState.CLAIMED || value._state === IToBTCSwap_1.ToBTCSwapState.SOFT_CLAIMED)
69
78
  throw new UserError_1.UserError("Lightning invoice was already paid!");
70
79
  }
71
80
  }
@@ -75,12 +84,14 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
75
84
  * @param amount BTC amount of the swap in satoshis
76
85
  * @param overrideBaseFee Override wrapper's default base fee
77
86
  * @param overrideFeePPM Override wrapper's default PPM
78
- * @private
87
+ *
79
88
  * @returns Maximum lightning routing fee in sats
89
+ *
90
+ * @private
80
91
  */
81
92
  calculateFeeForAmount(amount, overrideBaseFee, overrideFeePPM) {
82
- return BigInt(overrideBaseFee ?? this.options.lightningBaseFee)
83
- + (amount * BigInt(overrideFeePPM ?? this.options.lightningFeePPM) / 1000000n);
93
+ return BigInt(overrideBaseFee ?? this._options.lightningBaseFee)
94
+ + (amount * BigInt(overrideFeePPM ?? this._options.lightningFeePPM) / 1000000n);
84
95
  }
85
96
  /**
86
97
  * Verifies returned LP data
@@ -93,8 +104,10 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
93
104
  * @param options Swap options as passed to the swap create function
94
105
  * @param data Parsed swap data returned by the LP
95
106
  * @param requiredTotal Required total to be paid on the input (for exactIn swaps)
96
- * @private
107
+ *
97
108
  * @throws {IntermediaryError} In case the response is not valid
109
+ *
110
+ * @private
98
111
  */
99
112
  async verifyReturnedData(signer, resp, parsedPr, token, lp, options, data, requiredTotal) {
100
113
  if (resp.routingFeeSats > await options.maxFee)
@@ -103,7 +116,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
103
116
  throw new IntermediaryError_1.IntermediaryError("Invalid data returned - total amount");
104
117
  if (parsedPr.tagsObject.payment_hash == null)
105
118
  throw new Error("Swap invoice doesn't contain payment hash field!");
106
- const claimHash = this.contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
119
+ const claimHash = this._contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
107
120
  if (data.getAmount() !== resp.total ||
108
121
  !Buffer.from(data.getClaimHash(), "hex").equals(claimHash) ||
109
122
  data.getExpiry() !== options.expiryTimestamp ||
@@ -129,6 +142,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
129
142
  * @param abort Abort signal or controller, if AbortController is passed it is used as-is, when AbortSignal is passed
130
143
  * it is extended with extendAbortController and then used
131
144
  * @param additionalParams Additional params that should be sent to the LP
145
+ *
132
146
  * @private
133
147
  */
134
148
  async getIntermediaryQuote(signer, amountData, lp, pr, parsedPr, options, preFetches, abort, additionalParams) {
@@ -146,7 +160,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
146
160
  token: amountData.token,
147
161
  feeRate: (0, Utils_1.throwIfUndefined)(preFetches.feeRatePromise),
148
162
  additionalParams
149
- }, this.options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined);
163
+ }, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined);
150
164
  return {
151
165
  signDataPromise: preFetches.signDataPrefetchPromise ?? this.preFetchSignData(signDataPrefetch),
152
166
  resp: await response
@@ -156,7 +170,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
156
170
  throw new Error("Swap invoice doesn't have msat amount field!");
157
171
  const amountOut = (BigInt(parsedPr.millisatoshis) + 999n) / 1000n;
158
172
  const totalFee = resp.swapFee + resp.maxFee;
159
- const data = new this.swapDataDeserializer(resp.data);
173
+ const data = new this._swapDataDeserializer(resp.data);
160
174
  data.setOfferer(signer);
161
175
  await this.verifyReturnedData(signer, resp, parsedPr, amountData.token, lp, options, data);
162
176
  const [pricingInfo, signatureExpiry, reputation] = await Promise.all([
@@ -192,25 +206,26 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
192
206
  }
193
207
  }
194
208
  /**
195
- * Returns a newly created swap, paying for 'bolt11PayRequest' - a bitcoin LN invoice
209
+ * Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol,
210
+ * the amount is parsed from the provided lightning network payment request (bolt11 invoice)
196
211
  *
197
- * @param signer Smartchain signer's address initiating the swap
198
- * @param bolt11PayRequest BOLT11 payment request (bitcoin lightning invoice) you wish to pay
199
- * @param amountData Amount of token & amount to swap
200
- * @param lps LPs (liquidity providers) to get the quotes from
201
- * @param options Quote options
202
- * @param additionalParams Additional parameters sent to the LP when creating the swap
203
- * @param abortSignal Abort signal for aborting the process
204
- * @param preFetches Existing pre-fetches for the swap (only used internally for LNURL swaps)
212
+ * @param signer Source chain signer address initiating the swap
213
+ * @param recipient BOLT11 payment request (bitcoin lightning invoice) you wish to pay
214
+ * @param amountData Token to swap
215
+ * @param lps An array of intermediaries (LPs) to get the quotes from
216
+ * @param options Optional additional quote options
217
+ * @param additionalParams Optional additional parameters sent to the LP when creating the swap
218
+ * @param abortSignal Abort signal
219
+ * @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
205
220
  */
206
- async create(signer, bolt11PayRequest, amountData, lps, options, additionalParams, abortSignal, preFetches) {
207
- const parsedPr = (0, bolt11_1.decode)(bolt11PayRequest);
221
+ async create(signer, recipient, amountData, lps, options, additionalParams, abortSignal, preFetches) {
222
+ const parsedPr = (0, bolt11_1.decode)(recipient);
208
223
  if (parsedPr.millisatoshis == null)
209
224
  throw new UserError_1.UserError("Must be an invoice with amount");
210
225
  const amountOut = (BigInt(parsedPr.millisatoshis) + 999n) / 1000n;
211
- const expirySeconds = options?.expirySeconds ?? this.options.paymentTimeoutSeconds;
212
- const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this.options.lightningBaseFee);
213
- const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this.options.lightningFeePPM);
226
+ const expirySeconds = options?.expirySeconds ?? this._options.paymentTimeoutSeconds;
227
+ const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this._options.lightningBaseFee);
228
+ const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this._options.lightningFeePPM);
214
229
  const _options = {
215
230
  expirySeconds,
216
231
  expiryTimestamp: options?.expiryTimestamp ?? BigInt(Math.floor(Date.now() / 1000) + expirySeconds),
@@ -221,18 +236,18 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
221
236
  if (parsedPr.tagsObject.payment_hash == null)
222
237
  throw new Error("Provided lightning invoice doesn't contain payment hash field!");
223
238
  await this.checkPaymentHashWasPaid(parsedPr.tagsObject.payment_hash);
224
- const claimHash = this.contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
239
+ const claimHash = this._contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
225
240
  const _abortController = (0, Utils_1.extendAbortController)(abortSignal);
226
241
  const _preFetches = preFetches ?? {
227
242
  pricePreFetchPromise: this.preFetchPrice(amountData, _abortController.signal),
228
243
  feeRatePromise: this.preFetchFeeRate(signer, amountData, claimHash.toString("hex"), _abortController),
229
244
  usdPricePrefetchPromise: this.preFetchUsdPrice(_abortController.signal),
230
- signDataPrefetchPromise: this.contract.preFetchBlockDataForSignatures == null ? this.preFetchSignData(Promise.resolve(true)) : undefined
245
+ signDataPrefetchPromise: this._contract.preFetchBlockDataForSignatures == null ? this.preFetchSignData(Promise.resolve(true)) : undefined
231
246
  };
232
247
  return lps.map(lp => {
233
248
  return {
234
249
  intermediary: lp,
235
- quote: this.getIntermediaryQuote(signer, amountData, lp, bolt11PayRequest, parsedPr, _options, _preFetches, _abortController.signal, additionalParams)
250
+ quote: this.getIntermediaryQuote(signer, amountData, lp, recipient, parsedPr, _options, _preFetches, _abortController.signal, additionalParams)
236
251
  };
237
252
  });
238
253
  }
@@ -240,14 +255,15 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
240
255
  * Parses and fetches lnurl pay params from the specified lnurl
241
256
  *
242
257
  * @param lnurl LNURL to be parsed and fetched
243
- * @param abortSignal
244
- * @private
258
+ * @param abortSignal Abort signal
245
259
  * @throws {UserError} if the LNURL is invalid or if it's not a LNURL-pay
260
+ *
261
+ * @private
246
262
  */
247
263
  async getLNURLPay(lnurl, abortSignal) {
248
264
  if (typeof (lnurl) !== "string")
249
265
  return lnurl;
250
- const res = await LNURL_1.LNURL.getLNURL(lnurl, true, this.options.getRequestTimeout, abortSignal);
266
+ const res = await LNURL_1.LNURL.getLNURL(lnurl, true, this._options.getRequestTimeout, abortSignal);
251
267
  if (res == null)
252
268
  throw new UserError_1.UserError("Invalid LNURL");
253
269
  if (res.tag !== "payRequest")
@@ -257,15 +273,17 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
257
273
  /**
258
274
  * Returns the quote/swap from the given LP
259
275
  *
260
- * @param signer Smartchain signer's address initiating the swap
261
- * @param amountData
276
+ * @param signer Source chain signer address initiating the swap
277
+ * @param amountData Token to swap
262
278
  * @param invoiceCreateService Service for creating fixed amount invoices
263
- * @param lp Intermediary
264
- * @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay
265
- * @param options Options as passed to the swap create function
266
- * @param preFetches
267
- * @param abortSignal
279
+ * @param lp Intermediary (LPs) to get the quote from
280
+ * @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay, used to estimate
281
+ * network fees for an actual invoice
282
+ * @param options Optional additional quote options
283
+ * @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
284
+ * @param abortSignal Abort signal
268
285
  * @param additionalParams Additional params to be sent to the intermediary
286
+ *
269
287
  * @private
270
288
  */
271
289
  async getIntermediaryQuoteExactIn(signer, amountData, invoiceCreateService, lp, dummyPr, options, preFetches, abortSignal, additionalParams) {
@@ -283,7 +301,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
283
301
  maxFee: await options.maxFee,
284
302
  expiryTimestamp: options.expiryTimestamp,
285
303
  additionalParams
286
- }, this.options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined);
304
+ }, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined);
287
305
  return {
288
306
  signDataPromise: this.preFetchSignData(signDataPrefetch),
289
307
  prepareResp: await response
@@ -306,12 +324,12 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
306
324
  reqId: prepareResp.reqId,
307
325
  feeRate: (0, Utils_1.throwIfUndefined)(preFetches.feeRatePromise),
308
326
  additionalParams
309
- }, this.options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined), undefined, RequestError_1.RequestError, abortController.signal);
327
+ }, this._options.postRequestTimeout, abortController.signal, retryCount > 0 ? false : undefined), undefined, RequestError_1.RequestError, abortController.signal);
310
328
  if (parsedInvoice.millisatoshis == null)
311
329
  throw new Error("Swap invoice doesn't have msat amount field!");
312
330
  const amountOut = (BigInt(parsedInvoice.millisatoshis) + 999n) / 1000n;
313
331
  const totalFee = resp.swapFee + resp.maxFee;
314
- const data = new this.swapDataDeserializer(resp.data);
332
+ const data = new this._swapDataDeserializer(resp.data);
315
333
  data.setOfferer(signer);
316
334
  await this.verifyReturnedData(signer, resp, parsedInvoice, amountData.token, lp, options, data, amountData.amount);
317
335
  const [pricingInfo, signatureExpiry, reputation] = await Promise.all([
@@ -347,15 +365,17 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
347
365
  }
348
366
  }
349
367
  /**
350
- * Returns a newly created swap, allowing exactIn swaps with invoice creation service
368
+ * Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol via
369
+ * invoice creation service. This allows exactIn swaps by requesting the desired fixed amount lightning
370
+ * network invoice from the service.
351
371
  *
352
- * @param signer Smartchain signer's address initiating the swap
353
- * @param invoiceCreateServicePromise
354
- * @param amountData Amount of token & amount to swap
355
- * @param lps LPs (liquidity providers/intermediaries) to get the quotes from
356
- * @param options Quote options
357
- * @param additionalParams Additional parameters sent to the intermediary when creating the swap
358
- * @param abortSignal Abort signal for aborting the process
372
+ * @param signer Source chain signer address initiating the swap
373
+ * @param invoiceCreateServicePromise Service to request destination lightning network invoices from
374
+ * @param amountData Amount, token and exact input/output data for to swap
375
+ * @param lps An array of intermediaries (LPs) to get the quotes from
376
+ * @param options Optional additional quote options
377
+ * @param additionalParams Optional additional parameters sent to the LP when creating the swap
378
+ * @param abortSignal Abort signal
359
379
  */
360
380
  async createViaInvoiceCreateService(signer, invoiceCreateServicePromise, amountData, lps, options, additionalParams, abortSignal) {
361
381
  if (!this.isInitialized)
@@ -364,7 +384,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
364
384
  const pricePreFetchPromise = this.preFetchPrice(amountData, _abortController.signal);
365
385
  const usdPricePrefetchPromise = this.preFetchUsdPrice(_abortController.signal);
366
386
  const feeRatePromise = this.preFetchFeeRate(signer, amountData, undefined, _abortController);
367
- const signDataPrefetchPromise = this.contract.preFetchBlockDataForSignatures == null ?
387
+ const signDataPrefetchPromise = this._contract.preFetchBlockDataForSignatures == null ?
368
388
  this.preFetchSignData(Promise.resolve(true)) :
369
389
  undefined;
370
390
  const _options = this.toRequiredSwapOptions(amountData, options, pricePreFetchPromise, _abortController.signal);
@@ -407,15 +427,17 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
407
427
  }
408
428
  }
409
429
  /**
410
- * Returns a newly created swap, paying for 'lnurl' - a lightning LNURL-pay
430
+ * Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol. Pays to
431
+ * an LNURL-pay link. This allows exactIn swaps by requesting the desired fixed amount lightning
432
+ * network invoice from the LNURL service.
411
433
  *
412
- * @param signer Smartchain signer's address initiating the swap
413
- * @param lnurl LMURL-pay you wish to pay
414
- * @param amountData Amount of token & amount to swap
415
- * @param lps LPs (liquidity providers/intermediaries) to get the quotes from
416
- * @param options Quote options
417
- * @param additionalParams Additional parameters sent to the intermediary when creating the swap
418
- * @param abortSignal Abort signal for aborting the process
434
+ * @param signer Source chain signer address initiating the swap
435
+ * @param lnurl LNURL-pay link of the recipient
436
+ * @param amountData Amount, token and exact input/output data for to swap
437
+ * @param lps An array of intermediaries (LPs) to get the quotes from
438
+ * @param options Optional additional quote options
439
+ * @param additionalParams Optional additional parameters sent to the LP when creating the swap
440
+ * @param abortSignal Abort signal
419
441
  */
420
442
  async createViaLNURL(signer, lnurl, amountData, lps, options, additionalParams, abortSignal) {
421
443
  let successActions = {};
@@ -427,7 +449,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
427
449
  throw new UserError_1.UserError("Comment not allowed or too long");
428
450
  return {
429
451
  getInvoice: async (amountSats, abortSignal) => {
430
- const { invoice, successAction } = await LNURL_1.LNURL.useLNURLPay(payRequest, BigInt(amountSats), options?.comment, this.options.getRequestTimeout, abortSignal);
452
+ const { invoice, successAction } = await LNURL_1.LNURL.useLNURLPay(payRequest, BigInt(amountSats), options?.comment, this._options.getRequestTimeout, abortSignal);
431
453
  if (successAction != null)
432
454
  successActions[invoice] = successAction;
433
455
  return invoice;
@@ -443,18 +465,22 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
443
465
  _abortController.signal.throwIfAborted();
444
466
  return quotes.map(value => ({
445
467
  quote: value.quote.then(quote => {
446
- quote.lnurl = resolved.url;
468
+ let _successAction;
447
469
  const quoteAddress = quote.getOutputAddress();
448
470
  if (quoteAddress != null) {
449
471
  const successAction = successActions[quoteAddress];
450
472
  if (successAction != null)
451
- quote.successAction = successAction;
473
+ _successAction = successAction;
452
474
  }
475
+ quote._setLNURLData(resolved.url, _successAction);
453
476
  return quote;
454
477
  }),
455
478
  intermediary: value.intermediary
456
479
  }));
457
480
  }
481
+ /**
482
+ * @inheritDoc
483
+ */
458
484
  async recoverFromSwapDataAndState(init, state, lp) {
459
485
  const data = init.data;
460
486
  let paymentHash = data.getHTLCHashHint();
@@ -463,7 +489,7 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
463
489
  secret = await state.getClaimResult();
464
490
  paymentHash = Buffer.from((0, sha2_1.sha256)(Buffer.from(secret, "hex"))).toString("hex");
465
491
  }
466
- const swap = new ToBTCLNSwap_1.ToBTCLNSwap(this, {
492
+ const swapInit = {
467
493
  pricingInfo: {
468
494
  isValid: true,
469
495
  satsBaseFee: 0n,
@@ -482,37 +508,16 @@ class ToBTCLNWrapper extends IToBTCWrapper_1.IToBTCWrapper {
482
508
  networkFee: 0n,
483
509
  networkFeeBtc: 0n,
484
510
  confidence: 0,
485
- pr: paymentHash,
511
+ pr: paymentHash ?? undefined,
486
512
  exactIn: false
487
- });
488
- swap.commitTxId = await init.getInitTxId();
513
+ };
514
+ const swap = new ToBTCLNSwap_1.ToBTCLNSwap(this, swapInit);
515
+ swap._commitTxId = await init.getInitTxId();
489
516
  const blockData = await init.getTxBlock();
490
517
  swap.createdAt = blockData.blockTime * 1000;
491
518
  swap._setInitiated();
492
- switch (state.type) {
493
- case base_1.SwapCommitStateType.PAID:
494
- secret ??= await state.getClaimResult();
495
- await swap._setPaymentResult({ secret }, false);
496
- swap.claimTxId = await state.getClaimTxId();
497
- swap.state = IToBTCSwap_1.ToBTCSwapState.CLAIMED;
498
- break;
499
- case base_1.SwapCommitStateType.NOT_COMMITED:
500
- case base_1.SwapCommitStateType.EXPIRED:
501
- if (state.getRefundTxId == null)
502
- return null;
503
- swap.refundTxId = await state.getRefundTxId();
504
- swap.state = IToBTCSwap_1.ToBTCSwapState.REFUNDED;
505
- break;
506
- case base_1.SwapCommitStateType.COMMITED:
507
- swap.state = IToBTCSwap_1.ToBTCSwapState.COMMITED;
508
- //Try to fetch refund signature
509
- if (lp != null)
510
- await swap._sync(false, false, state);
511
- break;
512
- case base_1.SwapCommitStateType.REFUNDABLE:
513
- swap.state = IToBTCSwap_1.ToBTCSwapState.REFUNDABLE;
514
- break;
515
- }
519
+ swap._state = IToBTCSwap_1.ToBTCSwapState.COMMITED;
520
+ await swap._sync(false, false, state);
516
521
  await swap._save();
517
522
  return swap;
518
523
  }