@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
@@ -18,11 +18,36 @@ export type OnchainForGasWrapperOptions = ISwapWrapperOptions & {
18
18
 
19
19
  export type OnchainForGasSwapTypeDefinition<T extends ChainType> = SwapTypeDefinition<T, OnchainForGasWrapper<T>, OnchainForGasSwap<T>>;
20
20
 
21
+ /**
22
+ * Trusted swap for Bitcoin -> Smart chains, to be used for minor amounts to get gas tokens on the
23
+ * destination chain, which is only needed for Solana, which still uses legacy swaps
24
+ *
25
+ * @category Swaps/Trusted Gas Swaps
26
+ */
21
27
  export class OnchainForGasWrapper<T extends ChainType> extends ISwapWrapper<T, OnchainForGasSwapTypeDefinition<T>, OnchainForGasWrapperOptions> {
22
- public readonly TYPE = SwapType.TRUSTED_FROM_BTC;
23
- public readonly swapDeserializer = OnchainForGasSwap;
28
+ public readonly TYPE: SwapType.TRUSTED_FROM_BTC = SwapType.TRUSTED_FROM_BTC;
29
+ /**
30
+ * @internal
31
+ */
32
+ readonly _swapDeserializer = OnchainForGasSwap;
33
+
34
+ /**
35
+ * @internal
36
+ */
37
+ readonly _pendingSwapStates = [OnchainForGasSwapState.PR_CREATED];
38
+ /**
39
+ * @internal
40
+ */
41
+ protected readonly tickSwapState = undefined;
42
+ /**
43
+ * @internal
44
+ */
45
+ protected processEvent = undefined;
24
46
 
25
- readonly btcRpc: BitcoinRpcWithAddressIndex<any>;
47
+ /**
48
+ * @internal
49
+ */
50
+ readonly _btcRpc: BitcoinRpcWithAddressIndex<any>;
26
51
 
27
52
  /**
28
53
  * @param chainIdentifier
@@ -47,30 +72,31 @@ export class OnchainForGasWrapper<T extends ChainType> extends ISwapWrapper<T, O
47
72
  events?: EventEmitter<{swapState: [ISwap]}>
48
73
  ) {
49
74
  super(chainIdentifier, unifiedStorage, unifiedChainEvents, chain, prices, tokens, options, events);
50
- this.btcRpc = btcRpc;
75
+ this._btcRpc = btcRpc;
51
76
  }
52
77
 
53
78
  /**
54
- * Returns a newly created swap, receiving 'amount' base units of gas token
79
+ * Returns a newly created trusted Bitcoin on-chain -> Smart chain swap, receiving
80
+ * the specified amount of native token on the destination chain.
55
81
  *
56
- * @param signer
57
- * @param amount Amount you wish to receive in base units
58
- * @param lpOrUrl Intermediary/Counterparty swap service Intermediary object or raw url
59
- * @param refundAddress Bitcoin address to receive refund on in case the counterparty cannot execute the swap
82
+ * @param recipient Address of the recipient on the smart chain destination chain
83
+ * @param amount Amount of native token to receive in base units
84
+ * @param lpOrUrl Intermediary (LP) to use for the swap
85
+ * @param refundAddress Bitcoin address to receive refund on in case the intermediary (LP) cannot execute the swap
60
86
  */
61
- async create(signer: string, amount: bigint, lpOrUrl: Intermediary | string, refundAddress?: string): Promise<OnchainForGasSwap<T>> {
87
+ async create(recipient: string, amount: bigint, lpOrUrl: Intermediary | string, refundAddress?: string): Promise<OnchainForGasSwap<T>> {
62
88
  if(!this.isInitialized) throw new Error("Not initialized, call init() first!");
63
89
 
64
90
  const lpUrl = typeof(lpOrUrl)==="string" ? lpOrUrl : lpOrUrl.url;
65
91
 
66
- const token = this.chain.getNativeCurrencyAddress();
92
+ const token = this._chain.getNativeCurrencyAddress();
67
93
 
68
94
  const resp = await TrustedIntermediaryAPI.initTrustedFromBTC(this.chainIdentifier, lpUrl, {
69
- address: signer,
95
+ address: recipient,
70
96
  amount,
71
97
  refundAddress,
72
98
  token
73
- }, this.options.getRequestTimeout);
99
+ }, this._options.getRequestTimeout);
74
100
 
75
101
  if(resp.total !== amount) throw new IntermediaryError("Invalid total returned");
76
102
 
@@ -79,7 +105,7 @@ export class OnchainForGasWrapper<T extends ChainType> extends ISwapWrapper<T, O
79
105
  {swapFeePPM: 10000, swapBaseFee: 10} :
80
106
  lpOrUrl.services[SwapType.TRUSTED_FROM_BTC],
81
107
  false, resp.amountSats,
82
- amount, this.chain.getNativeCurrencyAddress(), {}
108
+ amount, this._chain.getNativeCurrencyAddress(), {}
83
109
  );
84
110
 
85
111
  const quote = new OnchainForGasSwap(this, {
@@ -88,7 +114,7 @@ export class OnchainForGasWrapper<T extends ChainType> extends ISwapWrapper<T, O
88
114
  address: resp.btcAddress,
89
115
  inputAmount: resp.amountSats,
90
116
  outputAmount: resp.total,
91
- recipient: signer,
117
+ recipient,
92
118
  refundAddress,
93
119
  pricingInfo,
94
120
  url: lpUrl,
@@ -102,8 +128,4 @@ export class OnchainForGasWrapper<T extends ChainType> extends ISwapWrapper<T, O
102
128
  return quote;
103
129
  }
104
130
 
105
- public readonly pendingSwapStates = [OnchainForGasSwapState.PR_CREATED];
106
- public readonly tickSwapState = undefined;
107
- protected processEvent = undefined;
108
-
109
131
  }
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Simple amount definition for swap operations
2
+ * Amount, token and exact input object for initiating swap operations
3
+ *
3
4
  * @category Tokens
4
5
  */
5
6
  export type AmountData = {
@@ -1,5 +1,11 @@
1
1
  /**
2
- * Custom pricing callback function type
3
- * @category Pricing and LPs
2
+ * Custom pricing callback function type, fetches the USD price for the provided array
3
+ * of token tickers.
4
+ *
5
+ * @param tickers Tickers of the tokens to fetch USD price for
6
+ * @param abortSignal Abort signal
7
+ * @returns USD prices of the passed tickers in the order that they were passed
8
+ *
9
+ * @category Pricing
4
10
  */
5
11
  export type CustomPriceFunction = (tickers: string[], abortSignal?: AbortSignal) => Promise<number[]>;
@@ -2,7 +2,7 @@ import {toBigInt} from "../utils/Utils";
2
2
 
3
3
  /**
4
4
  * Pricing information for swap validation
5
- * @category Pricing and LPs
5
+ * @category Pricing
6
6
  */
7
7
  export type PriceInfoType = {
8
8
  isValid: boolean,
@@ -16,7 +16,7 @@ export type PriceInfoType = {
16
16
 
17
17
  /**
18
18
  * Type guard for PriceInfoType
19
- * @category Pricing and LPs
19
+ * @category Pricing
20
20
  */
21
21
  export function isPriceInfoType(obj: any): obj is PriceInfoType {
22
22
  return obj != null &&
@@ -31,7 +31,7 @@ export function isPriceInfoType(obj: any): obj is PriceInfoType {
31
31
 
32
32
  /**
33
33
  * Serializes PriceInfoType for storage
34
- * @category Pricing and LPs
34
+ * @category Pricing
35
35
  */
36
36
  export function serializePriceInfoType(obj: PriceInfoType | undefined): any {
37
37
  if (obj == null) return null;
@@ -48,7 +48,7 @@ export function serializePriceInfoType(obj: PriceInfoType | undefined): any {
48
48
 
49
49
  /**
50
50
  * Deserializes PriceInfoType from storage
51
- * @category Pricing and LPs
51
+ * @category Pricing
52
52
  */
53
53
  export function deserializePriceInfoType(obj: any): PriceInfoType | undefined {
54
54
  if (obj == null) return;
@@ -1,8 +1,100 @@
1
1
  import {ChainType} from "@atomiqlabs/base";
2
+ import {Transaction} from "@scure/btc-signer";
2
3
 
3
- export type SwapExecutionAction<T extends ChainType> = {
4
- name: "Payment" | "Commit" | "Claim",
4
+ /**
5
+ * Swap execution action requiring a payment of the provided bolt11 lightning network invoice
6
+ *
7
+ * @category Swap Actions
8
+ */
9
+ export type SwapExecutionActionLightning = {
10
+ name: "Payment",
5
11
  description: string,
6
- chain: "LIGHTNING" | "BITCOIN" | T["ChainId"],
7
- txs: any[]
8
- };
12
+ chain: "LIGHTNING",
13
+ txs: {
14
+ type: "BOLT11_PAYMENT_REQUEST",
15
+ address: string,
16
+ hyperlink: string
17
+ }[]
18
+ }
19
+
20
+ /**
21
+ * Swap execution action on on-chain Bitcoin, has following types:
22
+ * - `"ADDRESS"` - Destination bitcoin address and BTC amount to be sent
23
+ * - `"FUNDED_PSBT"` - A ready to sign PSBT with the inputs populated from the provided bitcoin wallet address
24
+ * - `"RAW_PSBT"` - Raw PSBT without the inputs, the implementor needs to add the input UTXOs before signing
25
+ * the transaction
26
+ *
27
+ * @category Swap Actions
28
+ */
29
+ export type SwapExecutionActionBitcoin<
30
+ T extends "ADDRESS" | "FUNDED_PSBT" | "RAW_PSBT" = "ADDRESS" | "FUNDED_PSBT" | "RAW_PSBT"
31
+ > = {
32
+ name: "Payment",
33
+ description: string,
34
+ chain: "BITCOIN",
35
+ txs: (T extends "ADDRESS" ? {
36
+ type: "ADDRESS",
37
+ amount: number,
38
+ address: string,
39
+ hyperlink: string
40
+ } : T extends "FUNDED_PSBT" ? {
41
+ type: "FUNDED_PSBT",
42
+ psbt: Transaction,
43
+ psbtHex: string,
44
+ psbtBase64: string,
45
+ signInputs: number[]
46
+ } : {
47
+ type: "RAW_PSBT",
48
+ psbt: Transaction,
49
+ psbtHex: string,
50
+ psbtBase64: string,
51
+ in1sequence: number
52
+ })[]
53
+ }
54
+
55
+ /**
56
+ * Swap execution action for committing (initiating) the escrow on the smart chain side
57
+ *
58
+ * @category Swap Actions
59
+ */
60
+ export type SwapExecutionActionCommit<T extends ChainType> = {
61
+ name: "Commit",
62
+ description: string,
63
+ chain: T["ChainId"],
64
+ txs: T["TX"][]
65
+ }
66
+
67
+ /**
68
+ * Swap execution action for claiming (settling) the swap on the smart chain side
69
+ *
70
+ * @category Swap Actions
71
+ */
72
+ export type SwapExecutionActionClaim<T extends ChainType> = {
73
+ name: "Claim",
74
+ description: string,
75
+ chain: T["ChainId"],
76
+ txs: T["TX"][]
77
+ }
78
+
79
+ /**
80
+ * Swap execution action for refunding the swap on the smart chain side after it fails
81
+ *
82
+ * @category Swap Actions
83
+ */
84
+ export type SwapExecutionActionRefund<T extends ChainType> = {
85
+ name: "Refund",
86
+ description: string,
87
+ chain: T["ChainId"],
88
+ txs: T["TX"][]
89
+ }
90
+
91
+ /**
92
+ * Swap execution action, a single step in the swapping process
93
+ *
94
+ * @category Swap Actions
95
+ */
96
+ export type SwapExecutionAction<T extends ChainType> = SwapExecutionActionLightning |
97
+ SwapExecutionActionBitcoin |
98
+ SwapExecutionActionCommit<T> |
99
+ SwapExecutionActionClaim<T> |
100
+ SwapExecutionActionRefund<T>;
@@ -3,10 +3,13 @@ import {ChainType} from "@atomiqlabs/base";
3
3
  import {IToBTCSwap} from "../swaps/escrow_swaps/tobtc/IToBTCSwap";
4
4
  import {IFromBTCSelfInitSwap} from "../swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap";
5
5
  import {FromBTCLNSwap} from "../swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap";
6
+ import {FromBTCLNAutoSwap} from "../swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap";
7
+ import {SpvFromBTCSwap} from "../swaps/spv_swaps/SpvFromBTCSwap";
6
8
 
7
9
  /**
8
- * Proxy type that auto-injects signer into swap methods
9
- * @category Swaps
10
+ * Proxy type that auto-injects a smart chain signer into swap methods
11
+ *
12
+ * @category Swaps/Base
10
13
  */
11
14
  export type SwapWithSigner<T extends ISwap> = {
12
15
  [K in keyof T]:
@@ -19,12 +22,13 @@ export type SwapWithSigner<T extends ISwap> = {
19
22
 
20
23
  /**
21
24
  * Wraps a swap with automatic signer injection for methods like commit, refund, and claim
25
+ *
22
26
  * @category Swaps
27
+ * @internal
23
28
  */
24
29
  export function wrapSwapWithSigner<C extends ChainType, T extends ISwap<C>>(swap: T, signer: C["Signer"]): SwapWithSigner<T> {
25
30
  return new Proxy(swap, {
26
31
  get: (target, prop, receiver) => {
27
- // Override the "sayGoodbye" method
28
32
  if (prop === "commit") {
29
33
  if(swap instanceof IToBTCSwap || swap instanceof IFromBTCSelfInitSwap) {
30
34
  return (abortSignal?: AbortSignal, skipChecks?: boolean) =>
@@ -38,7 +42,7 @@ export function wrapSwapWithSigner<C extends ChainType, T extends ISwap<C>>(swap
38
42
  }
39
43
  }
40
44
  if (prop === "claim") {
41
- if(swap instanceof IFromBTCSelfInitSwap) {
45
+ if(swap instanceof IFromBTCSelfInitSwap || swap instanceof FromBTCLNAutoSwap || swap instanceof SpvFromBTCSwap) {
42
46
  return (abortSignal?: AbortSignal) =>
43
47
  swap.claim(signer, abortSignal);
44
48
  }
@@ -1,5 +1,6 @@
1
1
  /**
2
- * Bitcoin token type (on-chain or lightning)
2
+ * Bitcoin token type (BTC on on-chain or lightning)
3
+ *
3
4
  * @category Tokens
4
5
  */
5
6
  export type BtcToken<L = boolean> = {
@@ -12,7 +13,8 @@ export type BtcToken<L = boolean> = {
12
13
  };
13
14
 
14
15
  /**
15
- * Type guard for BtcToken
16
+ * Type guard for {@link BtcToken} (token on the bitcoin network - lightning or on-chain)
17
+ *
16
18
  * @category Tokens
17
19
  */
18
20
  export function isBtcToken(obj: any): obj is BtcToken {
@@ -26,6 +28,7 @@ export function isBtcToken(obj: any): obj is BtcToken {
26
28
 
27
29
  /**
28
30
  * Predefined Bitcoin token constants
31
+ *
29
32
  * @category Tokens
30
33
  */
31
34
  export const BitcoinTokens: {
@@ -47,8 +50,10 @@ export const BitcoinTokens: {
47
50
  name: "Bitcoin (lightning L2)"
48
51
  }
49
52
  };
53
+
50
54
  /**
51
- * Smart Chain token type
55
+ * Token on the smart chain
56
+ *
52
57
  * @category Tokens
53
58
  */
54
59
  export type SCToken<ChainIdentifier extends string = string> = {
@@ -62,7 +67,7 @@ export type SCToken<ChainIdentifier extends string = string> = {
62
67
  }
63
68
 
64
69
  /**
65
- * Type guard for SCToken
70
+ * Type guard for {@link SCToken} (token on the smart chain)
66
71
  * @category Tokens
67
72
  */
68
73
  export function isSCToken(obj: any): obj is SCToken {
@@ -77,12 +82,14 @@ export function isSCToken(obj: any): obj is SCToken {
77
82
 
78
83
  /**
79
84
  * Union type for all token types (BTC or smart chain)
85
+ *
80
86
  * @category Tokens
81
87
  */
82
88
  export type Token<ChainIdentifier extends string = string> = BtcToken | SCToken<ChainIdentifier>;
83
89
 
84
90
  /**
85
- * Type guard for Token
91
+ * Type guard for an union {@link Token} type, encompassing all tokens (BTC or smart chain)
92
+ *
86
93
  * @category Tokens
87
94
  */
88
95
  export function isToken(obj: any): obj is Token {
@@ -5,6 +5,7 @@ import {toDecimal} from "../utils/Utils";
5
5
 
6
6
  /**
7
7
  * Represents a token amount along with its formatted values and USD valuation helpers
8
+ *
8
9
  * @category Tokens
9
10
  */
10
11
  export type TokenAmount<
@@ -68,7 +69,9 @@ export type TokenAmount<
68
69
 
69
70
  /**
70
71
  * Factory function to create a TokenAmount
72
+ *
71
73
  * @category Tokens
74
+ * @internal
72
75
  */
73
76
  export function toTokenAmount<
74
77
  ChainIdentifier extends string = string,
@@ -3,9 +3,10 @@ import {TokenAmount} from "../TokenAmount";
3
3
  import {Token} from "../Token";
4
4
 
5
5
  /**
6
- * Represents a fee in both source and destination tokens, as well as providing USD valuation helpers and
6
+ * Fee represented in both, source and destination tokens, as well as providing USD valuation helpers and
7
7
  * fee composition
8
- * @category Pricing and LPs
8
+ *
9
+ * @category Pricing
9
10
  */
10
11
  export type Fee<
11
12
  ChainIdentifier extends string = string,
@@ -2,8 +2,9 @@ import {FeeType} from "../../enums/FeeType";
2
2
  import {Fee} from "./Fee";
3
3
 
4
4
  /**
5
- * Breakdown of fees by type (swap fee vs network fee)
6
- * @category Pricing and LPs
5
+ * Breakdown of fees by type (swap fee, network fee, etc.)
6
+ *
7
+ * @category Pricing
7
8
  */
8
9
  export type FeeBreakdown<ChainIdentifier extends string = string> = {
9
10
  type: FeeType,
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * Parts-per-million fee representation with conversion helpers
3
- * @category Pricing and LPs
3
+ *
4
+ * @category Pricing
4
5
  */
5
6
  export type PercentagePPM = {
6
7
  ppm: bigint,
@@ -11,7 +12,8 @@ export type PercentagePPM = {
11
12
 
12
13
  /**
13
14
  * Converts parts-per-million to percentage representation
14
- * @category Pricing and LPs
15
+ *
16
+ * @category Pricing
15
17
  */
16
18
  export function ppmToPercentage(ppm: bigint): PercentagePPM {
17
19
  const percentage = Number(ppm) / 10_000;
@@ -1,6 +1,7 @@
1
1
  /**
2
- * LNURL-pay request parameters
3
- * @category Bitcoin
2
+ * Response of the LNURL-pay link
3
+ *
4
+ * @category Lightning
4
5
  */
5
6
  export type LNURLPayParams = {
6
7
  tag: "payRequest";
@@ -14,14 +15,16 @@ export type LNURLPayParams = {
14
15
  }
15
16
 
16
17
  /**
17
- * LNURL-pay parameters with URL
18
- * @category Bitcoin
18
+ * Response of the LNURL-pay link with the added original url
19
+ *
20
+ * @category Lightning
19
21
  */
20
22
  export type LNURLPayParamsWithUrl = LNURLPayParams & { url: string };
21
23
 
22
24
  /**
23
- * LNURL-pay specification
24
- * @category Bitcoin
25
+ * Parsed LNURL-pay specification
26
+ *
27
+ * @category Lightning
25
28
  */
26
29
  export type LNURLPay = {
27
30
  type: "pay",
@@ -35,16 +38,20 @@ export type LNURLPay = {
35
38
  }
36
39
 
37
40
  /**
38
- * Type guard for LNURL-pay parameters
39
- * @category Bitcoin
41
+ * Type guard for {@link LNURLPayParams}
42
+ *
43
+ * @category Lightning
44
+ * @internal
40
45
  */
41
46
  export function isLNURLPayParams(obj: any): obj is LNURLPayParams {
42
47
  return obj.tag === "payRequest";
43
48
  }
44
49
 
45
50
  /**
46
- * Type guard for LNURL-pay
47
- * @category Bitcoin
51
+ * Type guard for {@link LNURLPay}
52
+ *
53
+ * @category Lightning
54
+ * @internal
48
55
  */
49
56
  export function isLNURLPay(value: any): value is LNURLPay {
50
57
  return (
@@ -62,8 +69,9 @@ export function isLNURLPay(value: any): value is LNURLPay {
62
69
  }
63
70
 
64
71
  /**
65
- * Decoded LNURL-pay success action
66
- * @category Bitcoin
72
+ * Decoded LNURL-pay success action, revealed after a lightning payment is finished
73
+ *
74
+ * @category Lightning
67
75
  */
68
76
  export type LNURLDecodedSuccessAction = {
69
77
  description: string,
@@ -1,6 +1,7 @@
1
1
  /**
2
- * LNURL-withdraw request parameters
3
- * @category Bitcoin
2
+ * Response of the LNURL-withdraw link
3
+ *
4
+ * @category Lightning
4
5
  */
5
6
  export type LNURLWithdrawParams = {
6
7
  tag: "withdrawRequest";
@@ -15,14 +16,16 @@ export type LNURLWithdrawParams = {
15
16
  }
16
17
 
17
18
  /**
18
- * LNURL-withdraw parameters with URL
19
- * @category Bitcoin
19
+ * Response of the LNURL-withdraw link with the added original url
20
+ *
21
+ * @category Lightning
20
22
  */
21
23
  export type LNURLWithdrawParamsWithUrl = LNURLWithdrawParams & { url: string };
22
24
 
23
25
  /**
24
- * LNURL-withdraw specification
25
- * @category Bitcoin
26
+ * Parsed LNURL-withdraw specification
27
+ *
28
+ * @category Lightning
26
29
  */
27
30
  export type LNURLWithdraw = {
28
31
  type: "withdraw",
@@ -32,8 +35,10 @@ export type LNURLWithdraw = {
32
35
  }
33
36
 
34
37
  /**
35
- * Type guard for LNURL-withdraw
36
- * @category Bitcoin
38
+ * Type guard for {@link LNURLWithdraw}
39
+ *
40
+ * @category Lightning
41
+ * @internal
37
42
  */
38
43
  export function isLNURLWithdraw(value: any): value is LNURLWithdraw {
39
44
  return (
@@ -47,8 +52,10 @@ export function isLNURLWithdraw(value: any): value is LNURLWithdraw {
47
52
  }
48
53
 
49
54
  /**
50
- * Type guard for LNURL-withdraw parameters
51
- * @category Bitcoin
55
+ * Type guard for {@link LNURLWithdrawParams}
56
+ *
57
+ * @category Lightning
58
+ * @internal
52
59
  */
53
60
  export function isLNURLWithdrawParams(obj: any): obj is LNURLWithdrawParams {
54
61
  return obj.tag === "withdrawRequest";
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Invoice getter callback for the {@link LightningInvoiceCreateService}
3
+ *
4
+ * @category Lightning
5
+ */
6
+ export type LightningWalletCallback = (valueSats: number, abortSignal?: AbortSignal) => Promise<string>;
7
+ /**
8
+ * Service that creates on-demand fixed amount bolt11 lightning network invoices, optionally
9
+ * specifying minimum and maximum swappable sats amount. This used for exact input Smart chain ->
10
+ * Lightning swaps.
11
+ *
12
+ * @category Lightning
13
+ */
14
+ export type LightningInvoiceCreateService = {
15
+ getInvoice: LightningWalletCallback,
16
+ minMsats?: bigint,
17
+ maxMSats?: bigint
18
+ };
19
+
20
+ /**
21
+ * Type guard for {@link LightningInvoiceCreateService}
22
+ *
23
+ * @internal
24
+ */
25
+ export function isLightningInvoiceCreateService(obj: any): obj is LightningInvoiceCreateService {
26
+ return typeof (obj) === "object" &&
27
+ typeof (obj.getInvoice) === "function" &&
28
+ (obj.minMsats == null || typeof (obj.minMsats) === "bigint") &&
29
+ (obj.maxMSats == null || typeof (obj.maxMSats) === "bigint");
30
+ }
@@ -2,7 +2,8 @@ import {Transaction} from "@scure/btc-signer";
2
2
 
3
3
  /**
4
4
  * A type with minimum possible required data about a bitcoin wallet to be able to estimate fees and produce unsigned
5
- * PSBTs
5
+ * funded PSBTs with address's UTXOs
6
+ *
6
7
  * @category Bitcoin
7
8
  */
8
9
  export type MinimalBitcoinWalletInterface = {
@@ -12,6 +13,7 @@ export type MinimalBitcoinWalletInterface = {
12
13
 
13
14
  /**
14
15
  * A type with minimum possible required data about a bitcoin wallet to be able to estimate fees and sign PSBTs
16
+ *
15
17
  * @category Bitcoin
16
18
  */
17
19
  export type MinimalBitcoinWalletInterfaceWithSigner = MinimalBitcoinWalletInterface & {
@@ -1,6 +1,8 @@
1
1
  /**
2
- * A type with minimum possible required functionality to be usable with lightning network swaps
3
- * @category Bitcoin
2
+ * A type with minimum possible required functionality to be usable with lightning network swaps, i.e.
3
+ * a function to pay bolt11 lightning network invoices.
4
+ *
5
+ * @category Lightning
4
6
  */
5
7
  export type MinimalLightningNetworkWalletInterface = {
6
8
  payInvoice: (bolt11PaymentRequest: string) => Promise<string>
@@ -3,6 +3,11 @@ import {Buffer} from "buffer";
3
3
  import {Address, OutScript, Transaction} from "@scure/btc-signer";
4
4
  import {CoinselectAddressTypes} from "../bitcoin/coinselect2";
5
5
 
6
+
7
+ export function fromOutputScript(network: BTC_NETWORK, outputScriptHex: string): string {
8
+ return Address(network).encode(OutScript.decode(Buffer.from(outputScriptHex, "hex")));
9
+ }
10
+
6
11
  export function toOutputScript(network: BTC_NETWORK, address: string): Buffer {
7
12
  const outputScript = Address(network).decode(address);
8
13
  switch(outputScript.type) {