@atomiqlabs/sdk 8.1.7 → 8.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/dist/bitcoin/wallet/BitcoinWallet.d.ts +41 -5
  2. package/dist/bitcoin/wallet/BitcoinWallet.js +36 -1
  3. package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +52 -2
  4. package/dist/bitcoin/wallet/IBitcoinWallet.js +2 -1
  5. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +42 -7
  6. package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +36 -1
  7. package/dist/enums/FeeType.d.ts +7 -0
  8. package/dist/enums/FeeType.js +7 -0
  9. package/dist/enums/SwapAmountType.d.ts +7 -0
  10. package/dist/enums/SwapAmountType.js +7 -0
  11. package/dist/enums/SwapDirection.d.ts +7 -0
  12. package/dist/enums/SwapDirection.js +7 -0
  13. package/dist/enums/SwapType.d.ts +62 -1
  14. package/dist/enums/SwapType.js +62 -1
  15. package/dist/errors/IntermediaryError.d.ts +4 -0
  16. package/dist/errors/IntermediaryError.js +1 -0
  17. package/dist/errors/RequestError.d.ts +15 -1
  18. package/dist/errors/RequestError.js +8 -0
  19. package/dist/errors/UserError.d.ts +1 -0
  20. package/dist/errors/UserError.js +1 -0
  21. package/dist/index.d.ts +4 -5
  22. package/dist/index.js +3 -4
  23. package/dist/intermediaries/Intermediary.d.ts +57 -10
  24. package/dist/intermediaries/Intermediary.js +37 -10
  25. package/dist/intermediaries/IntermediaryDiscovery.d.ts +55 -22
  26. package/dist/intermediaries/IntermediaryDiscovery.js +35 -22
  27. package/dist/prices/RedundantSwapPrice.d.ts +24 -3
  28. package/dist/prices/RedundantSwapPrice.js +21 -1
  29. package/dist/prices/SingleSwapPrice.d.ts +9 -6
  30. package/dist/prices/SingleSwapPrice.js +10 -7
  31. package/dist/prices/SwapPriceWithChain.d.ts +54 -16
  32. package/dist/prices/SwapPriceWithChain.js +58 -20
  33. package/dist/prices/abstract/ISwapPrice.d.ts +94 -45
  34. package/dist/prices/abstract/ISwapPrice.js +103 -55
  35. package/dist/prices/providers/BinancePriceProvider.d.ts +7 -0
  36. package/dist/prices/providers/BinancePriceProvider.js +7 -0
  37. package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +6 -0
  38. package/dist/prices/providers/CoinGeckoPriceProvider.js +6 -0
  39. package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +6 -0
  40. package/dist/prices/providers/CoinPaprikaPriceProvider.js +6 -0
  41. package/dist/prices/providers/CustomPriceProvider.d.ts +11 -0
  42. package/dist/prices/providers/CustomPriceProvider.js +11 -0
  43. package/dist/prices/providers/KrakenPriceProvider.d.ts +9 -0
  44. package/dist/prices/providers/KrakenPriceProvider.js +9 -0
  45. package/dist/prices/providers/OKXPriceProvider.d.ts +6 -0
  46. package/dist/prices/providers/OKXPriceProvider.js +6 -0
  47. package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +3 -0
  48. package/dist/prices/providers/abstract/ExchangePriceProvider.js +3 -0
  49. package/dist/storage/IUnifiedStorage.d.ts +19 -7
  50. package/dist/storage/UnifiedSwapStorage.d.ts +33 -3
  51. package/dist/storage/UnifiedSwapStorage.js +29 -1
  52. package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +31 -7
  53. package/dist/storage-browser/IndexedDBUnifiedStorage.js +29 -6
  54. package/dist/storage-browser/LocalStorageManager.d.ts +25 -1
  55. package/dist/storage-browser/LocalStorageManager.js +25 -1
  56. package/dist/swapper/Swapper.d.ts +303 -222
  57. package/dist/swapper/Swapper.js +376 -344
  58. package/dist/swapper/SwapperFactory.d.ts +41 -17
  59. package/dist/swapper/SwapperFactory.js +23 -2
  60. package/dist/swapper/SwapperUtils.d.ts +75 -28
  61. package/dist/swapper/SwapperUtils.js +107 -60
  62. package/dist/swapper/SwapperWithChain.d.ts +286 -91
  63. package/dist/swapper/SwapperWithChain.js +218 -64
  64. package/dist/swapper/SwapperWithSigner.d.ts +229 -80
  65. package/dist/swapper/SwapperWithSigner.js +190 -44
  66. package/dist/swaps/IAddressSwap.d.ts +10 -1
  67. package/dist/swaps/IAddressSwap.js +2 -1
  68. package/dist/swaps/IBTCWalletSwap.d.ts +24 -6
  69. package/dist/swaps/IBTCWalletSwap.js +2 -1
  70. package/dist/swaps/IClaimableSwap.d.ts +36 -4
  71. package/dist/swaps/IClaimableSwap.js +2 -1
  72. package/dist/swaps/IClaimableSwapWrapper.d.ts +11 -1
  73. package/dist/swaps/IRefundableSwap.d.ts +29 -3
  74. package/dist/swaps/IRefundableSwap.js +2 -1
  75. package/dist/swaps/ISwap.d.ts +159 -21
  76. package/dist/swaps/ISwap.js +90 -33
  77. package/dist/swaps/ISwapWithGasDrop.d.ts +6 -0
  78. package/dist/swaps/ISwapWithGasDrop.js +1 -0
  79. package/dist/swaps/ISwapWrapper.d.ts +157 -48
  80. package/dist/swaps/ISwapWrapper.js +130 -72
  81. package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +49 -6
  82. package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +22 -12
  83. package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +65 -12
  84. package/dist/swaps/escrow_swaps/IEscrowSwap.js +38 -19
  85. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +39 -9
  86. package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +30 -21
  87. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +31 -15
  88. package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +33 -18
  89. package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +94 -29
  90. package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +90 -27
  91. package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +22 -9
  92. package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +24 -11
  93. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +275 -58
  94. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +516 -239
  95. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +76 -25
  96. package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +131 -49
  97. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +311 -51
  98. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +542 -193
  99. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +87 -26
  100. package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +147 -58
  101. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +209 -53
  102. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +449 -242
  103. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +77 -23
  104. package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +116 -46
  105. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +197 -56
  106. package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +326 -189
  107. package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +30 -5
  108. package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +44 -19
  109. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +60 -19
  110. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +74 -31
  111. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +76 -50
  112. package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +106 -101
  113. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +36 -13
  114. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +65 -19
  115. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +46 -17
  116. package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +82 -27
  117. package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +328 -92
  118. package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +460 -219
  119. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +76 -24
  120. package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +244 -124
  121. package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +146 -18
  122. package/dist/swaps/trusted/ln/LnForGasSwap.js +173 -43
  123. package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +29 -10
  124. package/dist/swaps/trusted/ln/LnForGasWrapper.js +30 -11
  125. package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +200 -47
  126. package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +230 -78
  127. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +34 -12
  128. package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +33 -14
  129. package/dist/types/AmountData.d.ts +2 -1
  130. package/dist/types/CustomPriceFunction.d.ts +7 -1
  131. package/dist/types/SwapExecutionAction.d.ts +74 -4
  132. package/dist/types/SwapWithSigner.d.ts +4 -1
  133. package/dist/types/SwapWithSigner.js +5 -2
  134. package/dist/types/Token.d.ts +11 -5
  135. package/dist/types/Token.js +6 -3
  136. package/dist/types/TokenAmount.d.ts +3 -0
  137. package/dist/types/TokenAmount.js +2 -0
  138. package/dist/types/fees/Fee.d.ts +2 -1
  139. package/dist/types/fees/FeeBreakdown.d.ts +2 -1
  140. package/dist/types/fees/PercentagePPM.d.ts +2 -0
  141. package/dist/types/fees/PercentagePPM.js +1 -0
  142. package/dist/types/lnurl/LNURLPay.d.ts +14 -6
  143. package/dist/types/lnurl/LNURLPay.js +6 -2
  144. package/dist/types/lnurl/LNURLWithdraw.d.ts +12 -5
  145. package/dist/types/lnurl/LNURLWithdraw.js +6 -2
  146. package/dist/types/wallets/LightningInvoiceCreateService.d.ts +20 -0
  147. package/dist/types/wallets/LightningInvoiceCreateService.js +15 -0
  148. package/dist/types/wallets/MinimalBitcoinWalletInterface.d.ts +3 -1
  149. package/dist/types/wallets/MinimalLightningNetworkWalletInterface.d.ts +3 -1
  150. package/dist/utils/BitcoinUtils.d.ts +1 -0
  151. package/dist/utils/BitcoinUtils.js +5 -1
  152. package/dist/utils/SwapUtils.d.ts +56 -1
  153. package/dist/utils/SwapUtils.js +53 -1
  154. package/dist/utils/TokenUtils.d.ts +10 -2
  155. package/dist/utils/TokenUtils.js +12 -4
  156. package/package.json +3 -3
  157. package/src/bitcoin/wallet/BitcoinWallet.ts +41 -5
  158. package/src/bitcoin/wallet/IBitcoinWallet.ts +57 -2
  159. package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +42 -6
  160. package/src/enums/FeeType.ts +7 -0
  161. package/src/enums/SwapAmountType.ts +7 -0
  162. package/src/enums/SwapDirection.ts +7 -0
  163. package/src/enums/SwapType.ts +62 -2
  164. package/src/errors/IntermediaryError.ts +4 -0
  165. package/src/errors/RequestError.ts +15 -1
  166. package/src/errors/UserError.ts +1 -0
  167. package/src/index.ts +6 -5
  168. package/src/intermediaries/Intermediary.ts +57 -10
  169. package/src/intermediaries/IntermediaryDiscovery.ts +60 -27
  170. package/src/prices/RedundantSwapPrice.ts +24 -4
  171. package/src/prices/SingleSwapPrice.ts +10 -7
  172. package/src/prices/SwapPriceWithChain.ts +59 -21
  173. package/src/prices/abstract/ISwapPrice.ts +114 -65
  174. package/src/prices/providers/BinancePriceProvider.ts +7 -0
  175. package/src/prices/providers/CoinGeckoPriceProvider.ts +6 -0
  176. package/src/prices/providers/CoinPaprikaPriceProvider.ts +6 -0
  177. package/src/prices/providers/CustomPriceProvider.ts +11 -0
  178. package/src/prices/providers/KrakenPriceProvider.ts +9 -0
  179. package/src/prices/providers/OKXPriceProvider.ts +6 -0
  180. package/src/prices/providers/abstract/ExchangePriceProvider.ts +3 -0
  181. package/src/storage/IUnifiedStorage.ts +19 -7
  182. package/src/storage/UnifiedSwapStorage.ts +33 -3
  183. package/src/storage-browser/IndexedDBUnifiedStorage.ts +31 -8
  184. package/src/storage-browser/LocalStorageManager.ts +25 -1
  185. package/src/swapper/Swapper.ts +513 -379
  186. package/src/swapper/SwapperFactory.ts +44 -21
  187. package/src/swapper/SwapperUtils.ts +107 -60
  188. package/src/swapper/SwapperWithChain.ts +320 -81
  189. package/src/swapper/SwapperWithSigner.ts +263 -56
  190. package/src/swaps/IAddressSwap.ts +11 -1
  191. package/src/swaps/IBTCWalletSwap.ts +24 -8
  192. package/src/swaps/IClaimableSwap.ts +39 -4
  193. package/src/swaps/IClaimableSwapWrapper.ts +11 -2
  194. package/src/swaps/IRefundableSwap.ts +32 -3
  195. package/src/swaps/ISwap.ts +221 -82
  196. package/src/swaps/ISwapWithGasDrop.ts +6 -0
  197. package/src/swaps/ISwapWrapper.ts +212 -94
  198. package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +62 -18
  199. package/src/swaps/escrow_swaps/IEscrowSwap.ts +83 -37
  200. package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +61 -30
  201. package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +37 -19
  202. package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +120 -51
  203. package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +24 -11
  204. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +559 -256
  205. package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +155 -61
  206. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +590 -226
  207. package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +177 -74
  208. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +470 -243
  209. package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +141 -59
  210. package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +352 -193
  211. package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +48 -23
  212. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +86 -39
  213. package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +110 -110
  214. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +88 -33
  215. package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +101 -31
  216. package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +534 -263
  217. package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +289 -148
  218. package/src/swaps/trusted/ln/LnForGasSwap.ts +184 -45
  219. package/src/swaps/trusted/ln/LnForGasWrapper.ts +34 -15
  220. package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +260 -86
  221. package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +41 -19
  222. package/src/types/AmountData.ts +2 -1
  223. package/src/types/CustomPriceFunction.ts +7 -1
  224. package/src/types/SwapExecutionAction.ts +84 -5
  225. package/src/types/SwapWithSigner.ts +7 -3
  226. package/src/types/Token.ts +12 -5
  227. package/src/types/TokenAmount.ts +3 -0
  228. package/src/types/fees/Fee.ts +2 -1
  229. package/src/types/fees/FeeBreakdown.ts +2 -1
  230. package/src/types/fees/PercentagePPM.ts +2 -0
  231. package/src/types/lnurl/LNURLPay.ts +14 -6
  232. package/src/types/lnurl/LNURLWithdraw.ts +12 -5
  233. package/src/types/wallets/LightningInvoiceCreateService.ts +26 -0
  234. package/src/types/wallets/MinimalBitcoinWalletInterface.ts +3 -1
  235. package/src/types/wallets/MinimalLightningNetworkWalletInterface.ts +3 -1
  236. package/src/utils/BitcoinUtils.ts +5 -0
  237. package/src/utils/SwapUtils.ts +61 -1
  238. package/src/utils/TokenUtils.ts +12 -4
  239. package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +0 -68
  240. package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +0 -2
  241. package/dist/bitcoin/LightningNetworkApi.d.ts +0 -12
  242. package/dist/bitcoin/LightningNetworkApi.js +0 -2
  243. package/dist/bitcoin/mempool/MempoolApi.d.ts +0 -350
  244. package/dist/bitcoin/mempool/MempoolApi.js +0 -311
  245. package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +0 -44
  246. package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +0 -48
  247. package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +0 -119
  248. package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +0 -361
  249. package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +0 -22
  250. package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +0 -105
  251. package/dist/errors/PaymentAuthError.d.ts +0 -11
  252. package/dist/errors/PaymentAuthError.js +0 -23
  253. package/src/errors/PaymentAuthError.ts +0 -26
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ToBTCSwapState = exports.IToBTCSwap = exports.isIToBTCSwapInit = void 0;
3
+ exports.IToBTCSwap = exports.ToBTCSwapState = exports.isIToBTCSwapInit = void 0;
4
4
  const base_1 = require("@atomiqlabs/base");
5
5
  const IntermediaryAPI_1 = require("../../../intermediaries/apis/IntermediaryAPI");
6
6
  const IntermediaryError_1 = require("../../../errors/IntermediaryError");
@@ -21,14 +21,66 @@ function isIToBTCSwapInit(obj) {
21
21
  (0, IEscrowSelfInitSwap_1.isIEscrowSelfInitSwapInit)(obj);
22
22
  }
23
23
  exports.isIToBTCSwapInit = isIToBTCSwapInit;
24
+ /**
25
+ * State enum for escrow-based Smart chain -> Bitcoin (on-chain & lightning) swaps
26
+ *
27
+ * @category Swaps
28
+ */
29
+ var ToBTCSwapState;
30
+ (function (ToBTCSwapState) {
31
+ /**
32
+ * Intermediary (LP) was unable to process the swap and the funds were refunded on the
33
+ * source chain
34
+ */
35
+ ToBTCSwapState[ToBTCSwapState["REFUNDED"] = -3] = "REFUNDED";
36
+ /**
37
+ * Swap has expired for good and there is no way how it can be executed anymore
38
+ */
39
+ ToBTCSwapState[ToBTCSwapState["QUOTE_EXPIRED"] = -2] = "QUOTE_EXPIRED";
40
+ /**
41
+ * A swap is almost expired, and it should be presented to the user as expired, though
42
+ * there is still a chance that it will be processed
43
+ */
44
+ ToBTCSwapState[ToBTCSwapState["QUOTE_SOFT_EXPIRED"] = -1] = "QUOTE_SOFT_EXPIRED";
45
+ /**
46
+ * Swap was created, use the {@link IToBTCSwap.commit} or {@link IToBTCSwap.txsCommit} to
47
+ * initiate it by creating the swap escrow on the source chain
48
+ */
49
+ ToBTCSwapState[ToBTCSwapState["CREATED"] = 0] = "CREATED";
50
+ /**
51
+ * Swap escrow was initiated (committed) on the source chain, the intermediary (LP) will
52
+ * now process the swap. You can wait till that happens with the {@link IToBTCSwap.waitForPayment}
53
+ * function.
54
+ */
55
+ ToBTCSwapState[ToBTCSwapState["COMMITED"] = 1] = "COMMITED";
56
+ /**
57
+ * The intermediary (LP) has processed the transaction and sent out the funds on the destination chain,
58
+ * but hasn't yet settled the escrow on the source chain.
59
+ */
60
+ ToBTCSwapState[ToBTCSwapState["SOFT_CLAIMED"] = 2] = "SOFT_CLAIMED";
61
+ /**
62
+ * Swap was successfully settled by the intermediary (LP) on the source chain
63
+ */
64
+ ToBTCSwapState[ToBTCSwapState["CLAIMED"] = 3] = "CLAIMED";
65
+ /**
66
+ * Intermediary (LP) was unable to process the swap and the swap escrow on the source chain
67
+ * is refundable, call {@link IToBTCSwap.refund} or {@link IToBTCSwap.txsRefund} to refund
68
+ */
69
+ ToBTCSwapState[ToBTCSwapState["REFUNDABLE"] = 4] = "REFUNDABLE";
70
+ })(ToBTCSwapState = exports.ToBTCSwapState || (exports.ToBTCSwapState = {}));
71
+ /**
72
+ * Base class for escrow-based Smart chain -> Bitcoin (on-chain & lightning) swaps
73
+ *
74
+ * @category Swaps
75
+ */
24
76
  class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
25
77
  constructor(wrapper, initOrObject) {
26
78
  super(wrapper, initOrObject);
27
79
  if (isIToBTCSwapInit(initOrObject)) {
28
- this.state = ToBTCSwapState.CREATED;
80
+ this._state = ToBTCSwapState.CREATED;
29
81
  this.networkFee = initOrObject.networkFee;
30
82
  this.networkFeeBtc = initOrObject.networkFeeBtc;
31
- this.data = initOrObject.data;
83
+ this._data = initOrObject.data;
32
84
  this.signatureData = initOrObject.signatureData;
33
85
  }
34
86
  else {
@@ -36,37 +88,45 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
36
88
  this.networkFeeBtc = (0, Utils_1.toBigInt)(initOrObject.networkFeeBtc);
37
89
  }
38
90
  }
91
+ /**
92
+ * @inheritDoc
93
+ * @internal
94
+ */
39
95
  getSwapData() {
40
- return this.data;
96
+ return this._data;
41
97
  }
98
+ /**
99
+ * @inheritDoc
100
+ * @internal
101
+ */
42
102
  upgradeVersion() {
43
103
  if (this.version == null) {
44
- switch (this.state) {
104
+ switch (this._state) {
45
105
  case -2:
46
- this.state = ToBTCSwapState.REFUNDED;
106
+ this._state = ToBTCSwapState.REFUNDED;
47
107
  break;
48
108
  case -1:
49
- this.state = ToBTCSwapState.QUOTE_EXPIRED;
109
+ this._state = ToBTCSwapState.QUOTE_EXPIRED;
50
110
  break;
51
111
  case 0:
52
- this.state = ToBTCSwapState.CREATED;
112
+ this._state = ToBTCSwapState.CREATED;
53
113
  break;
54
114
  case 1:
55
- this.state = ToBTCSwapState.COMMITED;
115
+ this._state = ToBTCSwapState.COMMITED;
56
116
  break;
57
117
  case 2:
58
- this.state = ToBTCSwapState.CLAIMED;
118
+ this._state = ToBTCSwapState.CLAIMED;
59
119
  break;
60
120
  case 3:
61
- this.state = ToBTCSwapState.REFUNDABLE;
121
+ this._state = ToBTCSwapState.REFUNDABLE;
62
122
  break;
63
123
  }
64
124
  this.version = 1;
65
125
  }
66
126
  }
67
127
  /**
68
- * In case swapFee in BTC is not supplied it recalculates it based on swap price
69
- * @protected
128
+ * @inheritDoc
129
+ * @internal
70
130
  */
71
131
  tryRecomputeSwapPrice() {
72
132
  const output = this.getOutput();
@@ -82,91 +142,131 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
82
142
  }
83
143
  /**
84
144
  * Returns the payment hash identifier to be sent to the LP for getStatus and getRefund
85
- * @protected
145
+ * @internal
86
146
  */
87
147
  getLpIdentifier() {
88
148
  return this.getClaimHash();
89
149
  }
90
150
  //////////////////////////////
91
151
  //// Getters & utils
152
+ /**
153
+ * @inheritDoc
154
+ */
92
155
  getInputAddress() {
93
156
  return this._getInitiator();
94
157
  }
158
+ /**
159
+ * @inheritDoc
160
+ */
95
161
  getInputTxId() {
96
- return this.commitTxId ?? null;
162
+ return this._commitTxId ?? null;
97
163
  }
164
+ /**
165
+ * @inheritDoc
166
+ */
98
167
  requiresAction() {
99
168
  return this.isRefundable();
100
169
  }
101
170
  /**
102
- * Returns whether the swap is finished and in its terminal state (this can mean successful, refunded or failed)
171
+ * @inheritDoc
103
172
  */
104
173
  isFinished() {
105
- return this.state === ToBTCSwapState.CLAIMED || this.state === ToBTCSwapState.REFUNDED || this.state === ToBTCSwapState.QUOTE_EXPIRED;
174
+ return this._state === ToBTCSwapState.CLAIMED || this._state === ToBTCSwapState.REFUNDED || this._state === ToBTCSwapState.QUOTE_EXPIRED;
106
175
  }
176
+ /**
177
+ * @inheritDoc
178
+ */
107
179
  isRefundable() {
108
- return this.state === ToBTCSwapState.REFUNDABLE;
180
+ return this._state === ToBTCSwapState.REFUNDABLE;
109
181
  }
182
+ /**
183
+ * @inheritDoc
184
+ */
110
185
  isQuoteExpired() {
111
- return this.state === ToBTCSwapState.QUOTE_EXPIRED;
186
+ return this._state === ToBTCSwapState.QUOTE_EXPIRED;
112
187
  }
188
+ /**
189
+ * @inheritDoc
190
+ */
113
191
  isQuoteSoftExpired() {
114
- return this.state === ToBTCSwapState.QUOTE_EXPIRED || this.state === ToBTCSwapState.QUOTE_SOFT_EXPIRED;
192
+ return this._state === ToBTCSwapState.QUOTE_EXPIRED || this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED;
115
193
  }
194
+ /**
195
+ * @inheritDoc
196
+ */
116
197
  isSuccessful() {
117
- return this.state === ToBTCSwapState.CLAIMED;
198
+ return this._state === ToBTCSwapState.CLAIMED;
118
199
  }
200
+ /**
201
+ * @inheritDoc
202
+ */
119
203
  isFailed() {
120
- return this.state === ToBTCSwapState.REFUNDED;
204
+ return this._state === ToBTCSwapState.REFUNDED;
121
205
  }
206
+ /**
207
+ * @inheritDoc
208
+ * @internal
209
+ */
122
210
  _getInitiator() {
123
- return this.data.getOfferer();
211
+ return this._data.getOfferer();
124
212
  }
125
213
  //////////////////////////////
126
214
  //// Amounts & fees
215
+ /**
216
+ * Returns the swap fee charged by the intermediary (LP) on this swap
217
+ *
218
+ * @internal
219
+ */
127
220
  getSwapFee() {
128
221
  if (this.pricingInfo == null)
129
222
  throw new Error("No pricing info known, cannot estimate fee!");
130
223
  const feeWithoutBaseFee = this.swapFeeBtc - this.pricingInfo.satsBaseFee;
131
224
  const output = this.getOutput();
132
225
  const swapFeePPM = output.rawAmount == null ? 0n : feeWithoutBaseFee * 1000000n / output.rawAmount;
133
- const amountInDstToken = (0, TokenAmount_1.toTokenAmount)(this.swapFeeBtc, this.outputToken, this.wrapper.prices, this.pricingInfo);
226
+ const amountInDstToken = (0, TokenAmount_1.toTokenAmount)(this.swapFeeBtc, this.outputToken, this.wrapper._prices, this.pricingInfo);
134
227
  return {
135
- amountInSrcToken: (0, TokenAmount_1.toTokenAmount)(this.swapFee, this.wrapper.tokens[this.data.getToken()], this.wrapper.prices, this.pricingInfo),
228
+ amountInSrcToken: (0, TokenAmount_1.toTokenAmount)(this.swapFee, this.wrapper._tokens[this._data.getToken()], this.wrapper._prices, this.pricingInfo),
136
229
  amountInDstToken,
137
230
  currentUsdValue: amountInDstToken.currentUsdValue,
138
231
  usdValue: amountInDstToken.usdValue,
139
232
  pastUsdValue: amountInDstToken.pastUsdValue,
140
233
  composition: {
141
- base: (0, TokenAmount_1.toTokenAmount)(this.pricingInfo.satsBaseFee, this.outputToken, this.wrapper.prices, this.pricingInfo),
234
+ base: (0, TokenAmount_1.toTokenAmount)(this.pricingInfo.satsBaseFee, this.outputToken, this.wrapper._prices, this.pricingInfo),
142
235
  percentage: (0, PercentagePPM_1.ppmToPercentage)(swapFeePPM)
143
236
  }
144
237
  };
145
238
  }
146
239
  /**
147
- * Returns network fee for the swap, the fee is represented in source currency & destination currency, but is
148
- * paid only once
240
+ * Returns network fee for on the destination chain for the swap
241
+ *
242
+ * @internal
149
243
  */
150
244
  getNetworkFee() {
151
- const amountInDstToken = (0, TokenAmount_1.toTokenAmount)(this.networkFeeBtc, this.outputToken, this.wrapper.prices, this.pricingInfo);
245
+ const amountInDstToken = (0, TokenAmount_1.toTokenAmount)(this.networkFeeBtc, this.outputToken, this.wrapper._prices, this.pricingInfo);
152
246
  return {
153
- amountInSrcToken: (0, TokenAmount_1.toTokenAmount)(this.networkFee, this.wrapper.tokens[this.data.getToken()], this.wrapper.prices, this.pricingInfo),
247
+ amountInSrcToken: (0, TokenAmount_1.toTokenAmount)(this.networkFee, this.wrapper._tokens[this._data.getToken()], this.wrapper._prices, this.pricingInfo),
154
248
  amountInDstToken,
155
249
  currentUsdValue: amountInDstToken.currentUsdValue,
156
250
  usdValue: amountInDstToken.usdValue,
157
251
  pastUsdValue: amountInDstToken.pastUsdValue
158
252
  };
159
253
  }
254
+ /**
255
+ * @inheritDoc
256
+ */
160
257
  getFee() {
161
- const amountInDstToken = (0, TokenAmount_1.toTokenAmount)(this.swapFeeBtc + this.networkFeeBtc, this.outputToken, this.wrapper.prices, this.pricingInfo);
258
+ const amountInDstToken = (0, TokenAmount_1.toTokenAmount)(this.swapFeeBtc + this.networkFeeBtc, this.outputToken, this.wrapper._prices, this.pricingInfo);
162
259
  return {
163
- amountInSrcToken: (0, TokenAmount_1.toTokenAmount)(this.swapFee + this.networkFee, this.wrapper.tokens[this.data.getToken()], this.wrapper.prices, this.pricingInfo),
260
+ amountInSrcToken: (0, TokenAmount_1.toTokenAmount)(this.swapFee + this.networkFee, this.wrapper._tokens[this._data.getToken()], this.wrapper._prices, this.pricingInfo),
164
261
  amountInDstToken,
165
262
  currentUsdValue: amountInDstToken.currentUsdValue,
166
263
  usdValue: amountInDstToken.usdValue,
167
264
  pastUsdValue: amountInDstToken.pastUsdValue
168
265
  };
169
266
  }
267
+ /**
268
+ * @inheritDoc
269
+ */
170
270
  getFeeBreakdown() {
171
271
  return [
172
272
  {
@@ -179,44 +279,54 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
179
279
  }
180
280
  ];
181
281
  }
282
+ /**
283
+ * @inheritDoc
284
+ */
182
285
  getInputToken() {
183
- return this.wrapper.tokens[this.data.getToken()];
286
+ return this.wrapper._tokens[this._data.getToken()];
184
287
  }
288
+ /**
289
+ * @inheritDoc
290
+ */
185
291
  getInput() {
186
- return (0, TokenAmount_1.toTokenAmount)(this.data.getAmount(), this.wrapper.tokens[this.data.getToken()], this.wrapper.prices, this.pricingInfo);
292
+ return (0, TokenAmount_1.toTokenAmount)(this._data.getAmount(), this.wrapper._tokens[this._data.getToken()], this.wrapper._prices, this.pricingInfo);
187
293
  }
294
+ /**
295
+ * @inheritDoc
296
+ */
188
297
  getInputWithoutFee() {
189
- return (0, TokenAmount_1.toTokenAmount)(this.data.getAmount() - (this.swapFee + this.networkFee), this.wrapper.tokens[this.data.getToken()], this.wrapper.prices, this.pricingInfo);
298
+ return (0, TokenAmount_1.toTokenAmount)(this._data.getAmount() - (this.swapFee + this.networkFee), this.wrapper._tokens[this._data.getToken()], this.wrapper._prices, this.pricingInfo);
190
299
  }
191
300
  /**
192
- * Checks if the intiator/sender has enough balance to go through with the swap
301
+ * Checks if the initiator/sender on the source chain has enough balance to go through with the swap
193
302
  */
194
303
  async hasEnoughBalance() {
195
304
  const [balance, commitFee] = await Promise.all([
196
- this.wrapper.contract.getBalance(this._getInitiator(), this.data.getToken(), false),
197
- this.data.getToken() === this.wrapper.chain.getNativeCurrencyAddress() ? this.getCommitFee() : Promise.resolve(null)
305
+ this.wrapper._contract.getBalance(this._getInitiator(), this._data.getToken(), false),
306
+ this._data.getToken() === this.wrapper._chain.getNativeCurrencyAddress() ? this.getCommitFee() : Promise.resolve(null)
198
307
  ]);
199
- let required = this.data.getAmount();
308
+ let required = this._data.getAmount();
200
309
  if (commitFee != null)
201
310
  required = required + commitFee;
202
311
  return {
203
312
  enoughBalance: balance >= required,
204
- balance: (0, TokenAmount_1.toTokenAmount)(balance, this.wrapper.tokens[this.data.getToken()], this.wrapper.prices, this.pricingInfo),
205
- required: (0, TokenAmount_1.toTokenAmount)(required, this.wrapper.tokens[this.data.getToken()], this.wrapper.prices, this.pricingInfo)
313
+ balance: (0, TokenAmount_1.toTokenAmount)(balance, this.wrapper._tokens[this._data.getToken()], this.wrapper._prices, this.pricingInfo),
314
+ required: (0, TokenAmount_1.toTokenAmount)(required, this.wrapper._tokens[this._data.getToken()], this.wrapper._prices, this.pricingInfo)
206
315
  };
207
316
  }
208
317
  /**
209
- * Check if the initiator/sender has enough balance to cover the transaction fee for processing the swap
318
+ * Checks if the initiator/sender on the source chain has enough native token balance
319
+ * to cover the transaction fee of initiating the swap
210
320
  */
211
321
  async hasEnoughForTxFees() {
212
322
  const [balance, commitFee] = await Promise.all([
213
- this.wrapper.contract.getBalance(this._getInitiator(), this.wrapper.chain.getNativeCurrencyAddress(), false),
323
+ this.wrapper._contract.getBalance(this._getInitiator(), this.wrapper._chain.getNativeCurrencyAddress(), false),
214
324
  this.getCommitFee()
215
325
  ]);
216
326
  return {
217
327
  enoughBalance: balance >= commitFee,
218
- balance: (0, TokenAmount_1.toTokenAmount)(balance, this.wrapper.getNativeToken(), this.wrapper.prices),
219
- required: (0, TokenAmount_1.toTokenAmount)(commitFee, this.wrapper.getNativeToken(), this.wrapper.prices)
328
+ balance: (0, TokenAmount_1.toTokenAmount)(balance, this.wrapper._getNativeToken(), this.wrapper._prices),
329
+ required: (0, TokenAmount_1.toTokenAmount)(commitFee, this.wrapper._getNativeToken(), this.wrapper._prices)
220
330
  };
221
331
  }
222
332
  //////////////////////////////
@@ -229,26 +339,26 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
229
339
  * @param options Optional options for the swap like feeRate, AbortSignal, and timeouts/intervals
230
340
  *
231
341
  * @returns {boolean} Whether the swap was successfully processed by the LP, in case `false` is returned
232
- * the user can refund their funds back on the source chain by calling `swap.refund()`
342
+ * the user can refund their funds back on the source chain by calling {@link refund}
233
343
  */
234
344
  async execute(signer, callbacks, options) {
235
- if (this.state === ToBTCSwapState.QUOTE_EXPIRED || this.state === ToBTCSwapState.QUOTE_SOFT_EXPIRED)
345
+ if (this._state === ToBTCSwapState.QUOTE_EXPIRED || this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED)
236
346
  throw new Error("Quote expired");
237
- if (this.state === ToBTCSwapState.REFUNDED)
347
+ if (this._state === ToBTCSwapState.REFUNDED)
238
348
  throw new Error("Swap already refunded");
239
- if (this.state === ToBTCSwapState.REFUNDABLE)
349
+ if (this._state === ToBTCSwapState.REFUNDABLE)
240
350
  throw new Error("Swap refundable, refund with swap.refund()");
241
- if (this.state === ToBTCSwapState.SOFT_CLAIMED || this.state === ToBTCSwapState.CLAIMED)
351
+ if (this._state === ToBTCSwapState.SOFT_CLAIMED || this._state === ToBTCSwapState.CLAIMED)
242
352
  throw new Error("Swap already settled!");
243
- if (this.state === ToBTCSwapState.CREATED) {
353
+ if (this._state === ToBTCSwapState.CREATED) {
244
354
  const txId = await this.commit(signer, options?.abortSignal, false, callbacks?.onSourceTransactionSent);
245
355
  if (callbacks?.onSourceTransactionConfirmed != null)
246
356
  callbacks.onSourceTransactionConfirmed(txId);
247
357
  }
248
358
  // @ts-ignore
249
- if (this.state === ToBTCSwapState.CLAIMED || this.state === ToBTCSwapState.SOFT_CLAIMED)
359
+ if (this._state === ToBTCSwapState.CLAIMED || this._state === ToBTCSwapState.SOFT_CLAIMED)
250
360
  return true;
251
- if (this.state === ToBTCSwapState.COMMITED) {
361
+ if (this._state === ToBTCSwapState.COMMITED) {
252
362
  const success = await this.waitForPayment(options?.maxWaitTillSwapProcessedSeconds ?? 120, options?.paymentCheckIntervalSeconds, options?.abortSignal);
253
363
  if (success) {
254
364
  if (callbacks?.onSwapSettled != null)
@@ -261,8 +371,13 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
261
371
  }
262
372
  throw new Error("Unexpected state reached!");
263
373
  }
374
+ /**
375
+ * @inheritDoc
376
+ * @param options.skipChecks Skip checks like making sure init signature is still valid and swap wasn't commited yet
377
+ * (this is handled on swap creation, if you commit right after quoting, you can use `skipChecks=true`)
378
+ */
264
379
  async txsExecute(options) {
265
- if (this.state !== ToBTCSwapState.CREATED)
380
+ if (this._state !== ToBTCSwapState.CREATED)
266
381
  throw new Error("Invalid swap state, needs to be CREATED!");
267
382
  const txsCommit = await this.txsCommit(options?.skipChecks);
268
383
  return [
@@ -277,15 +392,16 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
277
392
  //////////////////////////////
278
393
  //// Commit
279
394
  /**
280
- * Returns transactions for committing the swap on-chain, initiating the swap
395
+ * After sending the transaction manually be sure to call the {@link waitTillCommited} function
396
+ * to wait till the initiation transaction is observed, processed by the SDK and state of the swap
397
+ * properly updated.
281
398
  *
282
- * @param skipChecks Skip checks like making sure init signature is still valid and swap wasn't commited yet
283
- * (this is handled on swap creation, if you commit right after quoting, you can use skipChecks=true)
399
+ * @inheritDoc
284
400
  *
285
401
  * @throws {Error} When in invalid state (not PR_CREATED)
286
402
  */
287
403
  async txsCommit(skipChecks) {
288
- if (this.state !== ToBTCSwapState.CREATED)
404
+ if (this._state !== ToBTCSwapState.CREATED)
289
405
  throw new Error("Must be in CREATED state!");
290
406
  if (this.signatureData == null)
291
407
  throw new Error("Init signature data not known, cannot commit!");
@@ -293,45 +409,39 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
293
409
  this.initiated = true;
294
410
  await this._saveAndEmit();
295
411
  }
296
- return await this.wrapper.contract.txsInit(this._getInitiator(), this.data, this.signatureData, skipChecks, this.feeRate).catch(e => Promise.reject(e instanceof base_1.SignatureVerificationError ? new Error("Request timed out") : e));
412
+ return await this.wrapper._contract.txsInit(this._getInitiator(), this._data, this.signatureData, skipChecks, this.feeRate).catch(e => Promise.reject(e instanceof base_1.SignatureVerificationError ? new Error("Request timed out") : e));
297
413
  }
298
414
  /**
299
- * Commits the swap on-chain, initiating the swap
415
+ * @inheritDoc
300
416
  *
301
- * @param _signer Signer to sign the transactions with, must be the same as used in the initialization
302
- * @param abortSignal Abort signal
303
- * @param skipChecks Skip checks like making sure init signature is still valid and swap wasn't commited yet
304
- * (this is handled on swap creation, if you commit right after quoting, you can skipChecks)`
305
- * @param onBeforeTxSent
306
417
  * @throws {Error} If invalid signer is provided that doesn't match the swap data
307
418
  */
308
419
  async commit(_signer, abortSignal, skipChecks, onBeforeTxSent) {
309
- const signer = (0, base_1.isAbstractSigner)(_signer) ? _signer : await this.wrapper.chain.wrapSigner(_signer);
420
+ const signer = (0, base_1.isAbstractSigner)(_signer) ? _signer : await this.wrapper._chain.wrapSigner(_signer);
310
421
  this.checkSigner(signer);
311
422
  const txs = await this.txsCommit(skipChecks);
312
423
  let txCount = 0;
313
- const result = await this.wrapper.chain.sendAndConfirm(signer, txs, true, abortSignal, false, (txId, rawTx) => {
424
+ const result = await this.wrapper._chain.sendAndConfirm(signer, txs, true, abortSignal, false, (txId, rawTx) => {
314
425
  txCount++;
315
426
  if (onBeforeTxSent != null && txCount === txs.length)
316
427
  onBeforeTxSent(txId);
317
428
  return Promise.resolve();
318
429
  });
319
- this.commitTxId = result[result.length - 1];
320
- if (this.state === ToBTCSwapState.CREATED || this.state === ToBTCSwapState.QUOTE_SOFT_EXPIRED || this.state === ToBTCSwapState.QUOTE_EXPIRED) {
430
+ this._commitTxId = result[result.length - 1];
431
+ if (this._state === ToBTCSwapState.CREATED || this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED || this._state === ToBTCSwapState.QUOTE_EXPIRED) {
321
432
  await this._saveAndEmit(ToBTCSwapState.COMMITED);
322
433
  }
323
- return this.commitTxId;
434
+ return this._commitTxId;
324
435
  }
325
436
  /**
326
- * Waits till a swap is committed, should be called after sending the commit transactions manually
437
+ * @inheritDoc
327
438
  *
328
- * @param abortSignal AbortSignal
329
- * @throws {Error} If swap is not in the correct state (must be CREATED)
439
+ * @throws {Error} If swap is not in the correct state (must be {@link ToBTCSwapState.CREATED})
330
440
  */
331
441
  async waitTillCommited(abortSignal) {
332
- if (this.state === ToBTCSwapState.COMMITED || this.state === ToBTCSwapState.CLAIMED)
442
+ if (this._state === ToBTCSwapState.COMMITED || this._state === ToBTCSwapState.CLAIMED)
333
443
  return Promise.resolve();
334
- if (this.state !== ToBTCSwapState.CREATED && this.state !== ToBTCSwapState.QUOTE_SOFT_EXPIRED)
444
+ if (this._state !== ToBTCSwapState.CREATED && this._state !== ToBTCSwapState.QUOTE_SOFT_EXPIRED)
335
445
  throw new Error("Invalid state (not CREATED)");
336
446
  const abortController = (0, Utils_1.extendAbortController)(abortSignal);
337
447
  let result;
@@ -352,28 +462,35 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
352
462
  this.logger.debug("waitTillCommited(): Resolved from watchdog - commited");
353
463
  if (result === false) {
354
464
  this.logger.debug("waitTillCommited(): Resolved from watchdog - signature expiry");
355
- if (this.state === ToBTCSwapState.QUOTE_SOFT_EXPIRED || this.state === ToBTCSwapState.CREATED) {
465
+ if (this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED || this._state === ToBTCSwapState.CREATED) {
356
466
  await this._saveAndEmit(ToBTCSwapState.QUOTE_EXPIRED);
357
467
  }
358
468
  throw new Error("Quote expired while waiting for transaction confirmation!");
359
469
  }
360
- if (this.state === ToBTCSwapState.QUOTE_SOFT_EXPIRED || this.state === ToBTCSwapState.CREATED || this.state === ToBTCSwapState.QUOTE_EXPIRED) {
470
+ if (this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED || this._state === ToBTCSwapState.CREATED || this._state === ToBTCSwapState.QUOTE_EXPIRED) {
361
471
  await this._saveAndEmit(ToBTCSwapState.COMMITED);
362
472
  }
363
473
  }
364
474
  //////////////////////////////
365
475
  //// Payment
476
+ /**
477
+ * Waits till the swap is processed by the intermediary (LP)
478
+ *
479
+ * @param checkIntervalSeconds How often to poll the intermediary for status (5 seconds default)
480
+ * @param abortSignal Abort signal
481
+ * @internal
482
+ */
366
483
  async waitTillIntermediarySwapProcessed(checkIntervalSeconds, abortSignal) {
367
484
  if (this.url == null)
368
485
  throw new Error("LP URL not specified!");
369
486
  checkIntervalSeconds ??= 5;
370
487
  let resp = { code: IntermediaryAPI_1.RefundAuthorizationResponseCodes.PENDING, msg: "" };
371
488
  while (!abortSignal?.aborted && (resp.code === IntermediaryAPI_1.RefundAuthorizationResponseCodes.PENDING || resp.code === IntermediaryAPI_1.RefundAuthorizationResponseCodes.NOT_FOUND)) {
372
- resp = await IntermediaryAPI_1.IntermediaryAPI.getRefundAuthorization(this.url, this.getLpIdentifier(), this.data.getSequence());
489
+ resp = await IntermediaryAPI_1.IntermediaryAPI.getRefundAuthorization(this.url, this.getLpIdentifier(), this._data.getSequence());
373
490
  if (resp.code === IntermediaryAPI_1.RefundAuthorizationResponseCodes.PAID) {
374
491
  const validResponse = await this._setPaymentResult(resp.data, true);
375
492
  if (validResponse) {
376
- if (this.state === ToBTCSwapState.COMMITED || this.state === ToBTCSwapState.REFUNDABLE) {
493
+ if (this._state === ToBTCSwapState.COMMITED || this._state === ToBTCSwapState.REFUNDABLE) {
377
494
  await this._saveAndEmit(ToBTCSwapState.SOFT_CLAIMED);
378
495
  }
379
496
  }
@@ -393,28 +510,29 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
393
510
  * refund.
394
511
  *
395
512
  * @param save whether to save the data
396
- * @returns true if swap is processed, false if the swap is still ongoing
397
- * @private
513
+ * @returns `true` if swap is processed, `false` if the swap is still ongoing
514
+ *
515
+ * @internal
398
516
  */
399
517
  async checkIntermediarySwapProcessed(save = true) {
400
- if (this.state === ToBTCSwapState.CREATED || this.state == ToBTCSwapState.QUOTE_EXPIRED || this.url == null)
518
+ if (this._state === ToBTCSwapState.CREATED || this._state == ToBTCSwapState.QUOTE_EXPIRED || this.url == null)
401
519
  return false;
402
520
  if (this.isFinished() || this.isRefundable())
403
521
  return true;
404
522
  //Check if that maybe already concluded according to the LP
405
- const resp = await IntermediaryAPI_1.IntermediaryAPI.getRefundAuthorization(this.url, this.getLpIdentifier(), this.data.getSequence());
523
+ const resp = await IntermediaryAPI_1.IntermediaryAPI.getRefundAuthorization(this.url, this.getLpIdentifier(), this._data.getSequence());
406
524
  switch (resp.code) {
407
525
  case IntermediaryAPI_1.RefundAuthorizationResponseCodes.PAID:
408
526
  const processed = await this._setPaymentResult(resp.data, true);
409
527
  if (processed) {
410
- this.state = ToBTCSwapState.SOFT_CLAIMED;
528
+ this._state = ToBTCSwapState.SOFT_CLAIMED;
411
529
  if (save)
412
530
  await this._saveAndEmit();
413
531
  }
414
532
  return processed;
415
533
  case IntermediaryAPI_1.RefundAuthorizationResponseCodes.REFUND_DATA:
416
- await this.wrapper.contract.isValidRefundAuthorization(this.data, resp.data);
417
- this.state = ToBTCSwapState.REFUNDABLE;
534
+ await this.wrapper._contract.isValidRefundAuthorization(this._data, resp.data);
535
+ this._state = ToBTCSwapState.REFUNDABLE;
418
536
  if (save)
419
537
  await this._saveAndEmit();
420
538
  return true;
@@ -423,23 +541,24 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
423
541
  }
424
542
  }
425
543
  /**
426
- * A blocking promise resolving when swap was concluded by the intermediary,
544
+ * A blocking promise resolving when swap was concluded by the intermediary (LP),
427
545
  * rejecting in case of failure
428
546
  *
429
547
  * @param maxWaitTimeSeconds Maximum time in seconds to wait for the swap to be settled, an error is thrown if the
430
548
  * swap is taking too long to claim
431
- * @param checkIntervalSeconds How often to poll the intermediary for answer
432
- * @param abortSignal Abort signal
433
- * @returns {Promise<boolean>} Was the payment successful? If not we can refund.
549
+ * @param checkIntervalSeconds How often to poll the intermediary for answer
550
+ * @param abortSignal Abort signal
551
+ * @returns `true` if swap was successful, `false` if swap failed and we can refund
552
+ *
434
553
  * @throws {IntermediaryError} If a swap is determined expired by the intermediary, but it is actually still valid
435
554
  * @throws {SignatureVerificationError} If the swap should be cooperatively refundable but the intermediary returned
436
555
  * invalid refund signature
437
- * @throws {Error} When swap expires or if the swap has invalid state (must be COMMITED)
556
+ * @throws {Error} When swap expires or if the swap has invalid state (must be {@link ToBTCSwapState.COMMITED})
438
557
  */
439
558
  async waitForPayment(maxWaitTimeSeconds, checkIntervalSeconds, abortSignal) {
440
- if (this.state === ToBTCSwapState.CLAIMED)
559
+ if (this._state === ToBTCSwapState.CLAIMED)
441
560
  return Promise.resolve(true);
442
- if (this.state !== ToBTCSwapState.COMMITED && this.state !== ToBTCSwapState.SOFT_CLAIMED)
561
+ if (this._state !== ToBTCSwapState.COMMITED && this._state !== ToBTCSwapState.SOFT_CLAIMED)
443
562
  throw new Error("Invalid state (not COMMITED)");
444
563
  const abortController = (0, Utils_1.extendAbortController)(abortSignal);
445
564
  let timedOut = false;
@@ -462,12 +581,12 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
462
581
  abortController.abort();
463
582
  if (timedOut) {
464
583
  throw new Error("Timed out while waiting for LP to process the swap, the LP might be unresponsive or offline!" +
465
- ` Please check later or wait till ${new Date(Number(this.data.getExpiry()) * 1000).toLocaleString()} to refund unilaterally!`);
584
+ ` Please check later or wait till ${new Date(Number(this._data.getExpiry()) * 1000).toLocaleString()} to refund unilaterally!`);
466
585
  }
467
586
  throw e;
468
587
  }
469
588
  if (typeof result !== "object") {
470
- if (this.state === ToBTCSwapState.REFUNDABLE)
589
+ if (this._state === ToBTCSwapState.REFUNDABLE)
471
590
  throw new Error("Swap expired");
472
591
  this.logger.debug("waitTillRefunded(): Resolved from state change");
473
592
  return true;
@@ -478,15 +597,15 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
478
597
  return true;
479
598
  case IntermediaryAPI_1.RefundAuthorizationResponseCodes.REFUND_DATA:
480
599
  const resultData = result.data;
481
- await this.wrapper.contract.isValidRefundAuthorization(this.data, resultData);
600
+ await this.wrapper._contract.isValidRefundAuthorization(this._data, resultData);
482
601
  await this._saveAndEmit(ToBTCSwapState.REFUNDABLE);
483
602
  return false;
484
603
  case IntermediaryAPI_1.RefundAuthorizationResponseCodes.EXPIRED:
485
- if (await this.wrapper.contract.isExpired(this._getInitiator(), this.data))
604
+ if (await this.wrapper._contract.isExpired(this._getInitiator(), this._data))
486
605
  throw new Error("Swap expired");
487
606
  throw new IntermediaryError_1.IntermediaryError("Swap expired");
488
607
  case IntermediaryAPI_1.RefundAuthorizationResponseCodes.NOT_FOUND:
489
- if (this.state === ToBTCSwapState.CLAIMED)
608
+ if (this._state === ToBTCSwapState.CLAIMED)
490
609
  return true;
491
610
  throw new Error("LP swap not found");
492
611
  }
@@ -497,11 +616,12 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
497
616
  /**
498
617
  * Get the estimated smart chain transaction fee of the refund transaction
499
618
  */
500
- getRefundFee() {
501
- return this.wrapper.contract.getRefundFee(this._getInitiator(), this.data);
619
+ async getRefundNetworkFee() {
620
+ const swapContract = this.wrapper._contract;
621
+ return (0, TokenAmount_1.toTokenAmount)(await swapContract.getRefundFee(this._getInitiator(), this._data), this.wrapper._getNativeToken(), this.wrapper._prices);
502
622
  }
503
623
  /**
504
- * Returns transactions for refunding the swap if the swap is in refundable state, you can check so with isRefundable()
624
+ * @inheritDoc
505
625
  *
506
626
  * @throws {IntermediaryError} If intermediary returns invalid response in case cooperative refund should be used
507
627
  * @throws {SignatureVerificationError} If intermediary returned invalid cooperative refund signature
@@ -511,46 +631,46 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
511
631
  if (!this.isRefundable())
512
632
  throw new Error("Must be in REFUNDABLE state or expired!");
513
633
  signer ??= this._getInitiator();
514
- if (await this.wrapper.contract.isExpired(this._getInitiator(), this.data)) {
515
- return await this.wrapper.contract.txsRefund(signer, this.data, true, true);
634
+ if (await this.wrapper._contract.isExpired(this._getInitiator(), this._data)) {
635
+ return await this.wrapper._contract.txsRefund(signer, this._data, true, true);
516
636
  }
517
637
  else {
518
638
  if (this.url == null)
519
639
  throw new Error("LP URL not known, cannot get cooperative refund message, wait till expiry to refund!");
520
- const res = await IntermediaryAPI_1.IntermediaryAPI.getRefundAuthorization(this.url, this.getLpIdentifier(), this.data.getSequence());
640
+ const res = await IntermediaryAPI_1.IntermediaryAPI.getRefundAuthorization(this.url, this.getLpIdentifier(), this._data.getSequence());
521
641
  if (res.code === IntermediaryAPI_1.RefundAuthorizationResponseCodes.REFUND_DATA) {
522
- return await this.wrapper.contract.txsRefundWithAuthorization(signer, this.data, res.data, true, true);
642
+ return await this.wrapper._contract.txsRefundWithAuthorization(signer, this._data, res.data, true, true);
523
643
  }
524
644
  throw new IntermediaryError_1.IntermediaryError("Invalid intermediary cooperative message returned");
525
645
  }
526
646
  }
527
647
  /**
528
- * Refunds the swap if the swap is in refundable state, you can check so with isRefundable()
648
+ * @inheritDoc
529
649
  *
530
- * @param _signer Signer to sign the transactions with, must be the same as used in the initialization
531
- * @param abortSignal Abort signal
532
650
  * @throws {Error} If invalid signer is provided that doesn't match the swap data
533
651
  */
534
652
  async refund(_signer, abortSignal) {
535
- const signer = (0, base_1.isAbstractSigner)(_signer) ? _signer : await this.wrapper.chain.wrapSigner(_signer);
536
- const result = await this.wrapper.chain.sendAndConfirm(signer, await this.txsRefund(signer.getAddress()), true, abortSignal);
537
- this.refundTxId = result[0];
538
- if (this.state === ToBTCSwapState.COMMITED || this.state === ToBTCSwapState.REFUNDABLE || this.state === ToBTCSwapState.SOFT_CLAIMED) {
653
+ const signer = (0, base_1.isAbstractSigner)(_signer) ? _signer : await this.wrapper._chain.wrapSigner(_signer);
654
+ const result = await this.wrapper._chain.sendAndConfirm(signer, await this.txsRefund(signer.getAddress()), true, abortSignal);
655
+ this._refundTxId = result[0];
656
+ if (this._state === ToBTCSwapState.COMMITED || this._state === ToBTCSwapState.REFUNDABLE || this._state === ToBTCSwapState.SOFT_CLAIMED) {
539
657
  await this._saveAndEmit(ToBTCSwapState.REFUNDED);
540
658
  }
541
659
  return result[0];
542
660
  }
543
661
  /**
544
- * Waits till a swap is refunded, should be called after sending the refund transactions manually
662
+ * @inheritDoc
545
663
  *
546
- * @param abortSignal AbortSignal
547
- * @throws {Error} When swap is not in a valid state (must be COMMITED)
664
+ * @throws {Error} When swap is not in a valid state (must be {@link ToBTCSwapState.COMMITED} or
665
+ * {@link ToBTCSwapState.REFUNDABLE})
548
666
  * @throws {Error} If we tried to refund but claimer was able to claim first
549
667
  */
550
668
  async waitTillRefunded(abortSignal) {
551
- if (this.state === ToBTCSwapState.REFUNDED)
669
+ if (this._state === ToBTCSwapState.REFUNDED)
552
670
  return Promise.resolve();
553
- if (this.state !== ToBTCSwapState.COMMITED && this.state !== ToBTCSwapState.SOFT_CLAIMED)
671
+ if (this._state !== ToBTCSwapState.COMMITED &&
672
+ this._state !== ToBTCSwapState.SOFT_CLAIMED &&
673
+ this._state !== ToBTCSwapState.REFUNDABLE)
554
674
  throw new Error("Invalid state (not COMMITED)");
555
675
  const abortController = new AbortController();
556
676
  if (abortSignal != null)
@@ -571,19 +691,22 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
571
691
  }
572
692
  this.logger.debug("waitTillRefunded(): Resolved from watchdog");
573
693
  if (res?.type === base_1.SwapCommitStateType.PAID) {
574
- if (this.claimTxId == null)
575
- this.claimTxId = await res.getClaimTxId();
694
+ if (this._claimTxId == null)
695
+ this._claimTxId = await res.getClaimTxId();
576
696
  await this._saveAndEmit(ToBTCSwapState.CLAIMED);
577
697
  throw new Error("Tried to refund swap, but claimer claimed it in the meantime!");
578
698
  }
579
699
  if (res?.type === base_1.SwapCommitStateType.NOT_COMMITED) {
580
- if (this.refundTxId == null && res.getRefundTxId != null)
581
- this.refundTxId = await res.getRefundTxId();
700
+ if (this._refundTxId == null && res.getRefundTxId != null)
701
+ this._refundTxId = await res.getRefundTxId();
582
702
  await this._saveAndEmit(ToBTCSwapState.REFUNDED);
583
703
  }
584
704
  }
585
705
  //////////////////////////////
586
706
  //// Storage
707
+ /**
708
+ * @inheritDoc
709
+ */
587
710
  serialize() {
588
711
  const obj = super.serialize();
589
712
  return {
@@ -601,75 +724,53 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
601
724
  * @private
602
725
  */
603
726
  async syncStateFromChain(quoteDefinitelyExpired, commitStatus) {
604
- if (this.state === ToBTCSwapState.CREATED ||
605
- this.state === ToBTCSwapState.QUOTE_SOFT_EXPIRED ||
606
- this.state === ToBTCSwapState.COMMITED ||
607
- this.state === ToBTCSwapState.SOFT_CLAIMED ||
608
- this.state === ToBTCSwapState.REFUNDABLE) {
727
+ if (this._state === ToBTCSwapState.CREATED ||
728
+ this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED ||
729
+ this._state === ToBTCSwapState.COMMITED ||
730
+ this._state === ToBTCSwapState.SOFT_CLAIMED ||
731
+ this._state === ToBTCSwapState.REFUNDABLE) {
609
732
  let quoteExpired = false;
610
- if (this.state === ToBTCSwapState.CREATED || this.state === ToBTCSwapState.QUOTE_SOFT_EXPIRED) {
733
+ if (this._state === ToBTCSwapState.CREATED || this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED) {
611
734
  //Check if quote is still valid
612
735
  quoteExpired = quoteDefinitelyExpired ?? await this._verifyQuoteDefinitelyExpired();
613
736
  }
614
- commitStatus ??= await this.wrapper.contract.getCommitStatus(this._getInitiator(), this.data);
615
- switch (commitStatus?.type) {
616
- case base_1.SwapCommitStateType.PAID:
617
- if (this.claimTxId == null && commitStatus.getClaimTxId)
618
- this.claimTxId = await commitStatus.getClaimTxId();
619
- const eventResult = await commitStatus.getClaimResult();
620
- try {
621
- await this._setPaymentResult({ secret: eventResult, txId: Buffer.from(eventResult, "hex").reverse().toString("hex") });
622
- }
623
- catch (e) {
624
- this.logger.error(`Failed to set payment result ${eventResult} on the swap!`);
625
- }
626
- this.state = ToBTCSwapState.CLAIMED;
627
- return true;
628
- case base_1.SwapCommitStateType.REFUNDABLE:
629
- this.state = ToBTCSwapState.REFUNDABLE;
630
- return true;
631
- case base_1.SwapCommitStateType.EXPIRED:
632
- if (this.refundTxId == null && commitStatus.getRefundTxId)
633
- this.refundTxId = await commitStatus.getRefundTxId();
634
- this.state = ToBTCSwapState.QUOTE_EXPIRED;
635
- return true;
636
- case base_1.SwapCommitStateType.NOT_COMMITED:
637
- if (this.refundTxId == null && commitStatus.getRefundTxId)
638
- this.refundTxId = await commitStatus.getRefundTxId();
639
- if (this.state === ToBTCSwapState.COMMITED || this.state === ToBTCSwapState.REFUNDABLE) {
640
- this.state = ToBTCSwapState.REFUNDED;
641
- return true;
642
- }
643
- break;
644
- case base_1.SwapCommitStateType.COMMITED:
645
- if (this.state !== ToBTCSwapState.COMMITED && this.state !== ToBTCSwapState.REFUNDABLE) {
646
- this.state = ToBTCSwapState.COMMITED;
647
- return true;
648
- }
649
- break;
650
- }
651
- if ((this.state === ToBTCSwapState.CREATED || this.state === ToBTCSwapState.QUOTE_SOFT_EXPIRED)) {
737
+ commitStatus ??= await this.wrapper._contract.getCommitStatus(this._getInitiator(), this._data);
738
+ if (commitStatus != null && await this._forciblySetOnchainState(commitStatus))
739
+ return true;
740
+ if ((this._state === ToBTCSwapState.CREATED || this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED)) {
652
741
  if (quoteExpired) {
653
- this.state = ToBTCSwapState.QUOTE_EXPIRED;
742
+ this._state = ToBTCSwapState.QUOTE_EXPIRED;
654
743
  return true;
655
744
  }
656
745
  }
657
746
  }
658
747
  return false;
659
748
  }
660
- _shouldFetchCommitStatus() {
661
- return this.state === ToBTCSwapState.CREATED ||
662
- this.state === ToBTCSwapState.QUOTE_SOFT_EXPIRED ||
663
- this.state === ToBTCSwapState.COMMITED ||
664
- this.state === ToBTCSwapState.SOFT_CLAIMED ||
665
- this.state === ToBTCSwapState.REFUNDABLE;
749
+ /**
750
+ * @inheritDoc
751
+ * @internal
752
+ */
753
+ _shouldFetchOnchainState() {
754
+ return this._state === ToBTCSwapState.CREATED ||
755
+ this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED ||
756
+ this._state === ToBTCSwapState.COMMITED ||
757
+ this._state === ToBTCSwapState.SOFT_CLAIMED ||
758
+ this._state === ToBTCSwapState.REFUNDABLE;
666
759
  }
760
+ /**
761
+ * @inheritDoc
762
+ * @internal
763
+ */
667
764
  _shouldFetchExpiryStatus() {
668
- return this.state === ToBTCSwapState.CREATED || this.state === ToBTCSwapState.QUOTE_SOFT_EXPIRED;
765
+ return this._state === ToBTCSwapState.CREATED || this._state === ToBTCSwapState.QUOTE_SOFT_EXPIRED;
669
766
  }
767
+ /**
768
+ * @inheritDoc
769
+ * @internal
770
+ */
670
771
  async _sync(save, quoteDefinitelyExpired, commitStatus) {
671
772
  let changed = await this.syncStateFromChain(quoteDefinitelyExpired, commitStatus);
672
- if (this.state === ToBTCSwapState.COMMITED || this.state === ToBTCSwapState.SOFT_CLAIMED) {
773
+ if (this._state === ToBTCSwapState.COMMITED || this._state === ToBTCSwapState.SOFT_CLAIMED) {
673
774
  //Check if that maybe already concluded
674
775
  try {
675
776
  if (await this.checkIntermediarySwapProcessed(false))
@@ -683,11 +784,58 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
683
784
  await this._saveAndEmit();
684
785
  return changed;
685
786
  }
787
+ /**
788
+ * @inheritDoc
789
+ * @internal
790
+ */
791
+ async _forciblySetOnchainState(commitStatus) {
792
+ switch (commitStatus.type) {
793
+ case base_1.SwapCommitStateType.PAID:
794
+ if (this._claimTxId == null && commitStatus.getClaimTxId)
795
+ this._claimTxId = await commitStatus.getClaimTxId();
796
+ const eventResult = await commitStatus.getClaimResult();
797
+ try {
798
+ await this._setPaymentResult({ secret: eventResult, txId: Buffer.from(eventResult, "hex").reverse().toString("hex") });
799
+ }
800
+ catch (e) {
801
+ this.logger.error(`Failed to set payment result ${eventResult} on the swap!`);
802
+ }
803
+ this._state = ToBTCSwapState.CLAIMED;
804
+ return true;
805
+ case base_1.SwapCommitStateType.REFUNDABLE:
806
+ this._state = ToBTCSwapState.REFUNDABLE;
807
+ return true;
808
+ case base_1.SwapCommitStateType.EXPIRED:
809
+ if (this._refundTxId == null && commitStatus.getRefundTxId)
810
+ this._refundTxId = await commitStatus.getRefundTxId();
811
+ this._state = this._refundTxId == null ? ToBTCSwapState.QUOTE_EXPIRED : ToBTCSwapState.REFUNDED;
812
+ return true;
813
+ case base_1.SwapCommitStateType.NOT_COMMITED:
814
+ if (this._refundTxId == null && commitStatus.getRefundTxId)
815
+ this._refundTxId = await commitStatus.getRefundTxId();
816
+ if (this._refundTxId != null) {
817
+ this._state = ToBTCSwapState.REFUNDED;
818
+ return true;
819
+ }
820
+ break;
821
+ case base_1.SwapCommitStateType.COMMITED:
822
+ if (this._state !== ToBTCSwapState.COMMITED && this._state !== ToBTCSwapState.REFUNDABLE && this._state !== ToBTCSwapState.SOFT_CLAIMED) {
823
+ this._state = ToBTCSwapState.COMMITED;
824
+ return true;
825
+ }
826
+ break;
827
+ }
828
+ return false;
829
+ }
830
+ /**
831
+ * @inheritDoc
832
+ * @internal
833
+ */
686
834
  async _tick(save) {
687
- switch (this.state) {
835
+ switch (this._state) {
688
836
  case ToBTCSwapState.CREATED:
689
837
  if (this.expiry < Date.now()) {
690
- this.state = ToBTCSwapState.QUOTE_SOFT_EXPIRED;
838
+ this._state = ToBTCSwapState.QUOTE_SOFT_EXPIRED;
691
839
  if (save)
692
840
  await this._saveAndEmit();
693
841
  return true;
@@ -695,9 +843,9 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
695
843
  break;
696
844
  case ToBTCSwapState.COMMITED:
697
845
  case ToBTCSwapState.SOFT_CLAIMED:
698
- const expired = await this.wrapper.contract.isExpired(this._getInitiator(), this.data);
846
+ const expired = await this.wrapper._contract.isExpired(this._getInitiator(), this._data);
699
847
  if (expired) {
700
- this.state = ToBTCSwapState.REFUNDABLE;
848
+ this._state = ToBTCSwapState.REFUNDABLE;
701
849
  if (save)
702
850
  await this._saveAndEmit();
703
851
  return true;
@@ -708,14 +856,3 @@ class IToBTCSwap extends IEscrowSelfInitSwap_1.IEscrowSelfInitSwap {
708
856
  }
709
857
  }
710
858
  exports.IToBTCSwap = IToBTCSwap;
711
- var ToBTCSwapState;
712
- (function (ToBTCSwapState) {
713
- ToBTCSwapState[ToBTCSwapState["REFUNDED"] = -3] = "REFUNDED";
714
- ToBTCSwapState[ToBTCSwapState["QUOTE_EXPIRED"] = -2] = "QUOTE_EXPIRED";
715
- ToBTCSwapState[ToBTCSwapState["QUOTE_SOFT_EXPIRED"] = -1] = "QUOTE_SOFT_EXPIRED";
716
- ToBTCSwapState[ToBTCSwapState["CREATED"] = 0] = "CREATED";
717
- ToBTCSwapState[ToBTCSwapState["COMMITED"] = 1] = "COMMITED";
718
- ToBTCSwapState[ToBTCSwapState["SOFT_CLAIMED"] = 2] = "SOFT_CLAIMED";
719
- ToBTCSwapState[ToBTCSwapState["CLAIMED"] = 3] = "CLAIMED";
720
- ToBTCSwapState[ToBTCSwapState["REFUNDABLE"] = 4] = "REFUNDABLE";
721
- })(ToBTCSwapState = exports.ToBTCSwapState || (exports.ToBTCSwapState = {}));