@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
@@ -1,5 +1,5 @@
1
1
  import {decode as bolt11Decode, PaymentRequestObject, TagsObject} from "@atomiqlabs/bolt11";
2
- import {ToBTCLNSwap} from "./ToBTCLNSwap";
2
+ import {ToBTCLNSwap, ToBTCLNSwapInit} from "./ToBTCLNSwap";
3
3
  import {IToBTCDefinition, IToBTCWrapper} from "../IToBTCWrapper";
4
4
  import {UserError} from "../../../../errors/UserError";
5
5
  import {ChainSwapType, ChainType, SwapCommitState, SwapCommitStateType} from "@atomiqlabs/base";
@@ -22,20 +22,7 @@ import {AmountData} from "../../../../types/AmountData";
22
22
  import {LNURLPayParamsWithUrl} from "../../../../types/lnurl/LNURLPay";
23
23
  import {tryWithRetries} from "../../../../utils/RetryUtils";
24
24
  import {AllOptional, AllRequired} from "../../../../utils/TypeUtils";
25
-
26
- export type LightningWalletCallback = (valueSats: number, abortSignal?: AbortSignal) => Promise<string>;
27
- export type InvoiceCreateService = {
28
- getInvoice: LightningWalletCallback,
29
- minMsats?: bigint,
30
- maxMSats?: bigint
31
- };
32
-
33
- export function isInvoiceCreateService(obj: any): obj is InvoiceCreateService {
34
- return typeof(obj)==="object" &&
35
- typeof(obj.getInvoice)==="function" &&
36
- (obj.minMsats==null || typeof(obj.minMsats)==="bigint") &&
37
- (obj.maxMSats==null || typeof(obj.maxMSats)==="bigint");
38
- }
25
+ import {LightningInvoiceCreateService} from "../../../../types/wallets/LightningInvoiceCreateService";
39
26
 
40
27
  export type ToBTCLNOptions = {
41
28
  expirySeconds?: number,
@@ -53,9 +40,17 @@ export type ToBTCLNWrapperOptions = ISwapWrapperOptions & {
53
40
 
54
41
  export type ToBTCLNDefinition<T extends ChainType> = IToBTCDefinition<T, ToBTCLNWrapper<T>, ToBTCLNSwap<T>>;
55
42
 
43
+ /**
44
+ * Escrow based (HTLC) swap for Smart chains -> Bitcoin lightning
45
+ *
46
+ * @category Swaps/Smart chain → Lightning
47
+ */
56
48
  export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCLNDefinition<T>, ToBTCLNWrapperOptions> {
57
- public readonly TYPE = SwapType.TO_BTCLN;
58
- public readonly swapDeserializer = ToBTCLNSwap;
49
+ public readonly TYPE: SwapType.TO_BTCLN = SwapType.TO_BTCLN;
50
+ /**
51
+ * @internal
52
+ */
53
+ readonly _swapDeserializer = ToBTCLNSwap;
59
54
 
60
55
  constructor(
61
56
  chainIdentifier: string,
@@ -81,9 +76,9 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
81
76
  }
82
77
 
83
78
  private toRequiredSwapOptions(amountData: AmountData, options?: ToBTCLNOptions, pricePreFetchPromise?: Promise<bigint | undefined>, abortSignal?: AbortSignal): AllRequired<ToBTCLNOptions> {
84
- const expirySeconds = options?.expirySeconds ?? this.options.paymentTimeoutSeconds;
85
- const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this.options.lightningBaseFee);
86
- const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this.options.lightningFeePPM);
79
+ const expirySeconds = options?.expirySeconds ?? this._options.paymentTimeoutSeconds;
80
+ const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this._options.lightningBaseFee);
81
+ const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this._options.lightningFeePPM);
87
82
 
88
83
  let maxFee: bigint | Promise<bigint>;
89
84
  if(options?.maxFee!=null) {
@@ -91,10 +86,10 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
91
86
  } else if(amountData.exactIn) {
92
87
  if(pricePreFetchPromise!=null) {
93
88
  maxFee = pricePreFetchPromise
94
- .then(val => this.prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal, val))
89
+ .then(val => this._prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal, val))
95
90
  .then(_maxBaseFee => this.calculateFeeForAmount(amountData.amount, _maxBaseFee, maxRoutingPPM))
96
91
  } else {
97
- maxFee = this.prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal)
92
+ maxFee = this._prices.getFromBtcSwapAmount(this.chainIdentifier, maxRoutingBaseFee, amountData.token, abortSignal)
98
93
  .then(_maxBaseFee => this.calculateFeeForAmount(amountData.amount, _maxBaseFee, maxRoutingPPM))
99
94
  }
100
95
  } else {
@@ -110,14 +105,22 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
110
105
  }
111
106
  }
112
107
 
108
+ /**
109
+ * Verifies whether a given payment hash was already paid by checking the local
110
+ * storage of known swaps
111
+ *
112
+ * @param paymentHash Payment hash to check
113
+ *
114
+ * @private
115
+ */
113
116
  private async checkPaymentHashWasPaid(paymentHash: string) {
114
117
  const swaps = await this.unifiedStorage.query(
115
118
  [[{key: "type", value: this.TYPE}, {key: "paymentHash", value: paymentHash}]],
116
- (obj: any) => new this.swapDeserializer(this, obj)
119
+ (obj: any) => new this._swapDeserializer(this, obj)
117
120
  );
118
121
 
119
122
  for(let value of swaps) {
120
- if(value.state===ToBTCSwapState.CLAIMED || value.state===ToBTCSwapState.SOFT_CLAIMED)
123
+ if(value._state===ToBTCSwapState.CLAIMED || value._state===ToBTCSwapState.SOFT_CLAIMED)
121
124
  throw new UserError("Lightning invoice was already paid!");
122
125
  }
123
126
  }
@@ -128,12 +131,14 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
128
131
  * @param amount BTC amount of the swap in satoshis
129
132
  * @param overrideBaseFee Override wrapper's default base fee
130
133
  * @param overrideFeePPM Override wrapper's default PPM
131
- * @private
134
+ *
132
135
  * @returns Maximum lightning routing fee in sats
136
+ *
137
+ * @private
133
138
  */
134
139
  private calculateFeeForAmount(amount: bigint, overrideBaseFee?: bigint, overrideFeePPM?: bigint) : bigint {
135
- return BigInt(overrideBaseFee ?? this.options.lightningBaseFee)
136
- + (amount * BigInt(overrideFeePPM ?? this.options.lightningFeePPM) / 1000000n);
140
+ return BigInt(overrideBaseFee ?? this._options.lightningBaseFee)
141
+ + (amount * BigInt(overrideFeePPM ?? this._options.lightningFeePPM) / 1000000n);
137
142
  }
138
143
 
139
144
  /**
@@ -147,8 +152,10 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
147
152
  * @param options Swap options as passed to the swap create function
148
153
  * @param data Parsed swap data returned by the LP
149
154
  * @param requiredTotal Required total to be paid on the input (for exactIn swaps)
150
- * @private
155
+ *
151
156
  * @throws {IntermediaryError} In case the response is not valid
157
+ *
158
+ * @private
152
159
  */
153
160
  private async verifyReturnedData(
154
161
  signer: string,
@@ -166,7 +173,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
166
173
  throw new IntermediaryError("Invalid data returned - total amount");
167
174
 
168
175
  if(parsedPr.tagsObject.payment_hash==null) throw new Error("Swap invoice doesn't contain payment hash field!");
169
- const claimHash = this.contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
176
+ const claimHash = this._contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
170
177
 
171
178
  if(
172
179
  data.getAmount() !== resp.total ||
@@ -196,6 +203,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
196
203
  * @param abort Abort signal or controller, if AbortController is passed it is used as-is, when AbortSignal is passed
197
204
  * it is extended with extendAbortController and then used
198
205
  * @param additionalParams Additional params that should be sent to the LP
206
+ *
199
207
  * @private
200
208
  */
201
209
  private async getIntermediaryQuote(
@@ -229,7 +237,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
229
237
  token: amountData.token,
230
238
  feeRate: throwIfUndefined(preFetches.feeRatePromise),
231
239
  additionalParams
232
- }, this.options.postRequestTimeout, abortController.signal, retryCount>0 ? false : undefined);
240
+ }, this._options.postRequestTimeout, abortController.signal, retryCount>0 ? false : undefined);
233
241
 
234
242
  return {
235
243
  signDataPromise: preFetches.signDataPrefetchPromise ?? this.preFetchSignData(signDataPrefetch),
@@ -240,7 +248,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
240
248
  if(parsedPr.millisatoshis==null) throw new Error("Swap invoice doesn't have msat amount field!");
241
249
  const amountOut: bigint = (BigInt(parsedPr.millisatoshis) + 999n) / 1000n;
242
250
  const totalFee: bigint = resp.swapFee + resp.maxFee;
243
- const data: T["Data"] = new this.swapDataDeserializer(resp.data);
251
+ const data: T["Data"] = new this._swapDataDeserializer(resp.data);
244
252
  data.setOfferer(signer);
245
253
 
246
254
  await this.verifyReturnedData(signer, resp, parsedPr, amountData.token, lp, options, data);
@@ -286,20 +294,21 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
286
294
  }
287
295
 
288
296
  /**
289
- * Returns a newly created swap, paying for 'bolt11PayRequest' - a bitcoin LN invoice
297
+ * Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol,
298
+ * the amount is parsed from the provided lightning network payment request (bolt11 invoice)
290
299
  *
291
- * @param signer Smartchain signer's address initiating the swap
292
- * @param bolt11PayRequest BOLT11 payment request (bitcoin lightning invoice) you wish to pay
293
- * @param amountData Amount of token & amount to swap
294
- * @param lps LPs (liquidity providers) to get the quotes from
295
- * @param options Quote options
296
- * @param additionalParams Additional parameters sent to the LP when creating the swap
297
- * @param abortSignal Abort signal for aborting the process
298
- * @param preFetches Existing pre-fetches for the swap (only used internally for LNURL swaps)
300
+ * @param signer Source chain signer address initiating the swap
301
+ * @param recipient BOLT11 payment request (bitcoin lightning invoice) you wish to pay
302
+ * @param amountData Token to swap
303
+ * @param lps An array of intermediaries (LPs) to get the quotes from
304
+ * @param options Optional additional quote options
305
+ * @param additionalParams Optional additional parameters sent to the LP when creating the swap
306
+ * @param abortSignal Abort signal
307
+ * @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
299
308
  */
300
309
  async create(
301
310
  signer: string,
302
- bolt11PayRequest: string,
311
+ recipient: string,
303
312
  amountData: Omit<AmountData, "amount">,
304
313
  lps: Intermediary[],
305
314
  options?: ToBTCLNOptions,
@@ -315,13 +324,13 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
315
324
  quote: Promise<ToBTCLNSwap<T>>,
316
325
  intermediary: Intermediary
317
326
  }[]> {
318
- const parsedPr = bolt11Decode(bolt11PayRequest);
327
+ const parsedPr = bolt11Decode(recipient);
319
328
  if(parsedPr.millisatoshis==null) throw new UserError("Must be an invoice with amount");
320
329
  const amountOut: bigint = (BigInt(parsedPr.millisatoshis) + 999n) / 1000n;
321
330
 
322
- const expirySeconds = options?.expirySeconds ?? this.options.paymentTimeoutSeconds;
323
- const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this.options.lightningBaseFee);
324
- const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this.options.lightningFeePPM);
331
+ const expirySeconds = options?.expirySeconds ?? this._options.paymentTimeoutSeconds;
332
+ const maxRoutingBaseFee = options?.maxRoutingBaseFee ?? BigInt(this._options.lightningBaseFee);
333
+ const maxRoutingPPM = options?.maxRoutingPPM ?? BigInt(this._options.lightningFeePPM);
325
334
 
326
335
  const _options: AllRequired<ToBTCLNOptions> = {
327
336
  expirySeconds,
@@ -334,20 +343,20 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
334
343
  if(parsedPr.tagsObject.payment_hash==null) throw new Error("Provided lightning invoice doesn't contain payment hash field!");
335
344
  await this.checkPaymentHashWasPaid(parsedPr.tagsObject.payment_hash);
336
345
 
337
- const claimHash = this.contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
346
+ const claimHash = this._contract.getHashForHtlc(Buffer.from(parsedPr.tagsObject.payment_hash, "hex"));
338
347
 
339
348
  const _abortController = extendAbortController(abortSignal);
340
349
  const _preFetches = preFetches ?? {
341
350
  pricePreFetchPromise: this.preFetchPrice(amountData, _abortController.signal),
342
351
  feeRatePromise: this.preFetchFeeRate(signer, amountData, claimHash.toString("hex"), _abortController),
343
352
  usdPricePrefetchPromise: this.preFetchUsdPrice(_abortController.signal),
344
- signDataPrefetchPromise: this.contract.preFetchBlockDataForSignatures==null ? this.preFetchSignData(Promise.resolve(true)) : undefined
353
+ signDataPrefetchPromise: this._contract.preFetchBlockDataForSignatures==null ? this.preFetchSignData(Promise.resolve(true)) : undefined
345
354
  };
346
355
 
347
356
  return lps.map(lp => {
348
357
  return {
349
358
  intermediary: lp,
350
- quote: this.getIntermediaryQuote(signer, amountData, lp, bolt11PayRequest, parsedPr, _options, _preFetches, _abortController.signal, additionalParams)
359
+ quote: this.getIntermediaryQuote(signer, amountData, lp, recipient, parsedPr, _options, _preFetches, _abortController.signal, additionalParams)
351
360
  }
352
361
  });
353
362
  }
@@ -356,14 +365,15 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
356
365
  * Parses and fetches lnurl pay params from the specified lnurl
357
366
  *
358
367
  * @param lnurl LNURL to be parsed and fetched
359
- * @param abortSignal
360
- * @private
368
+ * @param abortSignal Abort signal
361
369
  * @throws {UserError} if the LNURL is invalid or if it's not a LNURL-pay
370
+ *
371
+ * @private
362
372
  */
363
373
  private async getLNURLPay(lnurl: string | LNURLPayParamsWithUrl, abortSignal: AbortSignal): Promise<LNURLPayParamsWithUrl> {
364
374
  if(typeof(lnurl)!=="string") return lnurl;
365
375
 
366
- const res = await LNURL.getLNURL(lnurl, true, this.options.getRequestTimeout, abortSignal);
376
+ const res = await LNURL.getLNURL(lnurl, true, this._options.getRequestTimeout, abortSignal);
367
377
  if(res==null) throw new UserError("Invalid LNURL");
368
378
  if(res.tag!=="payRequest") throw new UserError("Not a LNURL-pay");
369
379
  return res;
@@ -372,21 +382,23 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
372
382
  /**
373
383
  * Returns the quote/swap from the given LP
374
384
  *
375
- * @param signer Smartchain signer's address initiating the swap
376
- * @param amountData
385
+ * @param signer Source chain signer address initiating the swap
386
+ * @param amountData Token to swap
377
387
  * @param invoiceCreateService Service for creating fixed amount invoices
378
- * @param lp Intermediary
379
- * @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay
380
- * @param options Options as passed to the swap create function
381
- * @param preFetches
382
- * @param abortSignal
388
+ * @param lp Intermediary (LPs) to get the quote from
389
+ * @param dummyPr Dummy minimum value bolt11 lightning invoice returned from the LNURL-pay, used to estimate
390
+ * network fees for an actual invoice
391
+ * @param options Optional additional quote options
392
+ * @param preFetches Optional existing pre-fetch promises for the swap (only used internally for LNURL swaps)
393
+ * @param abortSignal Abort signal
383
394
  * @param additionalParams Additional params to be sent to the intermediary
395
+ *
384
396
  * @private
385
397
  */
386
398
  private async getIntermediaryQuoteExactIn(
387
399
  signer: string,
388
400
  amountData: AmountData,
389
- invoiceCreateService: InvoiceCreateService,
401
+ invoiceCreateService: LightningInvoiceCreateService,
390
402
  lp: Intermediary,
391
403
  dummyPr: string,
392
404
  options: AllRequired<ToBTCLNOptions> & {comment?: string},
@@ -413,7 +425,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
413
425
  maxFee: await options.maxFee,
414
426
  expiryTimestamp: options.expiryTimestamp,
415
427
  additionalParams
416
- }, this.options.postRequestTimeout, abortController.signal, retryCount>0 ? false : undefined);
428
+ }, this._options.postRequestTimeout, abortController.signal, retryCount>0 ? false : undefined);
417
429
 
418
430
  return {
419
431
  signDataPromise: this.preFetchSignData(signDataPrefetch),
@@ -440,14 +452,14 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
440
452
  reqId: prepareResp.reqId,
441
453
  feeRate: throwIfUndefined(preFetches.feeRatePromise),
442
454
  additionalParams
443
- }, this.options.postRequestTimeout, abortController.signal, retryCount>0 ? false : undefined),
455
+ }, this._options.postRequestTimeout, abortController.signal, retryCount>0 ? false : undefined),
444
456
  undefined, RequestError, abortController.signal
445
457
  );
446
458
 
447
459
  if(parsedInvoice.millisatoshis==null) throw new Error("Swap invoice doesn't have msat amount field!");
448
460
  const amountOut: bigint = (BigInt(parsedInvoice.millisatoshis) + 999n) / 1000n;
449
461
  const totalFee: bigint = resp.swapFee + resp.maxFee;
450
- const data: T["Data"] = new this.swapDataDeserializer(resp.data);
462
+ const data: T["Data"] = new this._swapDataDeserializer(resp.data);
451
463
  data.setOfferer(signer);
452
464
 
453
465
  await this.verifyReturnedData(signer, resp, parsedInvoice, amountData.token, lp, options, data, amountData.amount);
@@ -493,19 +505,21 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
493
505
  }
494
506
 
495
507
  /**
496
- * Returns a newly created swap, allowing exactIn swaps with invoice creation service
508
+ * Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol via
509
+ * invoice creation service. This allows exactIn swaps by requesting the desired fixed amount lightning
510
+ * network invoice from the service.
497
511
  *
498
- * @param signer Smartchain signer's address initiating the swap
499
- * @param invoiceCreateServicePromise
500
- * @param amountData Amount of token & amount to swap
501
- * @param lps LPs (liquidity providers/intermediaries) to get the quotes from
502
- * @param options Quote options
503
- * @param additionalParams Additional parameters sent to the intermediary when creating the swap
504
- * @param abortSignal Abort signal for aborting the process
512
+ * @param signer Source chain signer address initiating the swap
513
+ * @param invoiceCreateServicePromise Service to request destination lightning network invoices from
514
+ * @param amountData Amount, token and exact input/output data for to swap
515
+ * @param lps An array of intermediaries (LPs) to get the quotes from
516
+ * @param options Optional additional quote options
517
+ * @param additionalParams Optional additional parameters sent to the LP when creating the swap
518
+ * @param abortSignal Abort signal
505
519
  */
506
520
  async createViaInvoiceCreateService(
507
521
  signer: string,
508
- invoiceCreateServicePromise: Promise<InvoiceCreateService>,
522
+ invoiceCreateServicePromise: Promise<LightningInvoiceCreateService>,
509
523
  amountData: AmountData,
510
524
  lps: Intermediary[],
511
525
  options?: ToBTCLNOptions,
@@ -521,7 +535,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
521
535
  const pricePreFetchPromise: Promise<bigint | undefined> = this.preFetchPrice(amountData, _abortController.signal);
522
536
  const usdPricePrefetchPromise: Promise<number | undefined> = this.preFetchUsdPrice(_abortController.signal);
523
537
  const feeRatePromise: Promise<string | undefined> = this.preFetchFeeRate(signer, amountData, undefined, _abortController);
524
- const signDataPrefetchPromise: Promise<T["PreFetchVerification"] | undefined> | undefined = this.contract.preFetchBlockDataForSignatures==null ?
538
+ const signDataPrefetchPromise: Promise<T["PreFetchVerification"] | undefined> | undefined = this._contract.preFetchBlockDataForSignatures==null ?
525
539
  this.preFetchSignData(Promise.resolve(true)) :
526
540
  undefined;
527
541
 
@@ -570,15 +584,17 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
570
584
  }
571
585
 
572
586
  /**
573
- * Returns a newly created swap, paying for 'lnurl' - a lightning LNURL-pay
587
+ * Returns a newly created Smart chain -> Lightning swap using the HTLC based escrow swap protocol. Pays to
588
+ * an LNURL-pay link. This allows exactIn swaps by requesting the desired fixed amount lightning
589
+ * network invoice from the LNURL service.
574
590
  *
575
- * @param signer Smartchain signer's address initiating the swap
576
- * @param lnurl LMURL-pay you wish to pay
577
- * @param amountData Amount of token & amount to swap
578
- * @param lps LPs (liquidity providers/intermediaries) to get the quotes from
579
- * @param options Quote options
580
- * @param additionalParams Additional parameters sent to the intermediary when creating the swap
581
- * @param abortSignal Abort signal for aborting the process
591
+ * @param signer Source chain signer address initiating the swap
592
+ * @param lnurl LNURL-pay link of the recipient
593
+ * @param amountData Amount, token and exact input/output data for to swap
594
+ * @param lps An array of intermediaries (LPs) to get the quotes from
595
+ * @param options Optional additional quote options
596
+ * @param additionalParams Optional additional parameters sent to the LP when creating the swap
597
+ * @param abortSignal Abort signal
582
598
  */
583
599
  async createViaLNURL(
584
600
  signer: string,
@@ -607,7 +623,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
607
623
  getInvoice: async (amountSats: number, abortSignal?: AbortSignal) => {
608
624
  const {invoice, successAction} = await LNURL.useLNURLPay(
609
625
  payRequest, BigInt(amountSats), options?.comment,
610
- this.options.getRequestTimeout, abortSignal
626
+ this._options.getRequestTimeout, abortSignal
611
627
  );
612
628
  if(successAction!=null) successActions[invoice] = successAction;
613
629
  return invoice;
@@ -634,18 +650,22 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
634
650
 
635
651
  return quotes.map(value => ({
636
652
  quote: value.quote.then(quote => {
637
- quote.lnurl = resolved.url;
653
+ let _successAction: LNURLPaySuccessAction | undefined;
638
654
  const quoteAddress = quote.getOutputAddress();
639
655
  if(quoteAddress!=null) {
640
656
  const successAction = successActions[quoteAddress];
641
- if(successAction!=null) quote.successAction = successAction;
657
+ if(successAction!=null) _successAction = successAction;
642
658
  }
659
+ quote._setLNURLData(resolved.url, _successAction);
643
660
  return quote;
644
661
  }),
645
662
  intermediary: value.intermediary
646
663
  }));
647
664
  }
648
665
 
666
+ /**
667
+ * @inheritDoc
668
+ */
649
669
  async recoverFromSwapDataAndState(
650
670
  init: {data: T["Data"], getInitTxId: () => Promise<string>, getTxBlock: () => Promise<{blockTime: number, blockHeight: number}>},
651
671
  state: SwapCommitState,
@@ -660,7 +680,7 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
660
680
  paymentHash = Buffer.from(sha256(Buffer.from(secret, "hex"))).toString("hex");
661
681
  }
662
682
 
663
- const swap = new ToBTCLNSwap(this, {
683
+ const swapInit: ToBTCLNSwapInit<T["Data"]> = {
664
684
  pricingInfo: {
665
685
  isValid: true,
666
686
  satsBaseFee: 0n,
@@ -679,36 +699,16 @@ export class ToBTCLNWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCL
679
699
  networkFee: 0n,
680
700
  networkFeeBtc: 0n,
681
701
  confidence: 0,
682
- pr: paymentHash,
702
+ pr: paymentHash ?? undefined,
683
703
  exactIn: false
684
- } as IToBTCSwapInit<T["Data"]>);
685
- swap.commitTxId = await init.getInitTxId();
704
+ };
705
+ const swap = new ToBTCLNSwap(this, swapInit);
706
+ swap._commitTxId = await init.getInitTxId();
686
707
  const blockData = await init.getTxBlock();
687
708
  swap.createdAt = blockData.blockTime * 1000;
688
709
  swap._setInitiated();
689
-
690
- switch(state.type) {
691
- case SwapCommitStateType.PAID:
692
- secret ??= await state.getClaimResult();
693
- await swap._setPaymentResult({secret}, false);
694
- swap.claimTxId = await state.getClaimTxId();
695
- swap.state = ToBTCSwapState.CLAIMED;
696
- break;
697
- case SwapCommitStateType.NOT_COMMITED:
698
- case SwapCommitStateType.EXPIRED:
699
- if(state.getRefundTxId==null) return null;
700
- swap.refundTxId = await state.getRefundTxId();
701
- swap.state = ToBTCSwapState.REFUNDED;
702
- break;
703
- case SwapCommitStateType.COMMITED:
704
- swap.state = ToBTCSwapState.COMMITED;
705
- //Try to fetch refund signature
706
- if(lp!=null) await swap._sync(false, false, state);
707
- break;
708
- case SwapCommitStateType.REFUNDABLE:
709
- swap.state = ToBTCSwapState.REFUNDABLE;
710
- break;
711
- }
710
+ swap._state = ToBTCSwapState.COMMITED;
711
+ await swap._sync(false, false, state);
712
712
  await swap._save();
713
713
  return swap;
714
714
  }