@atomiqlabs/sdk 7.0.12 → 8.0.7
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.
- package/README.md +45 -29
- package/dist/SmartChainAssets.d.ts +11 -3
- package/dist/SmartChainAssets.js +7 -3
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +68 -0
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +2 -0
- package/dist/bitcoin/LightningNetworkApi.d.ts +12 -0
- package/dist/bitcoin/LightningNetworkApi.js +2 -0
- package/dist/bitcoin/coinselect2/accumulative.d.ts +6 -0
- package/dist/bitcoin/coinselect2/accumulative.js +52 -0
- package/dist/bitcoin/coinselect2/blackjack.d.ts +6 -0
- package/dist/bitcoin/coinselect2/blackjack.js +38 -0
- package/dist/bitcoin/coinselect2/index.d.ts +19 -0
- package/dist/bitcoin/coinselect2/index.js +69 -0
- package/dist/bitcoin/coinselect2/utils.d.ts +71 -0
- package/dist/bitcoin/coinselect2/utils.js +123 -0
- package/dist/bitcoin/mempool/MempoolApi.d.ts +350 -0
- package/dist/bitcoin/mempool/MempoolApi.js +311 -0
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +44 -0
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +48 -0
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +119 -0
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +361 -0
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +22 -0
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +105 -0
- package/dist/bitcoin/wallet/BitcoinWallet.d.ts +93 -0
- package/dist/bitcoin/wallet/BitcoinWallet.js +273 -0
- package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +28 -0
- package/dist/bitcoin/wallet/IBitcoinWallet.js +20 -0
- package/dist/bitcoin/wallet/MinimalBitcoinWalletInterface.d.ts +21 -0
- package/dist/bitcoin/wallet/MinimalBitcoinWalletInterface.js +2 -0
- package/dist/bitcoin/wallet/MinimalLightningNetworkWalletInterface.d.ts +7 -0
- package/dist/bitcoin/wallet/MinimalLightningNetworkWalletInterface.js +2 -0
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +40 -0
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +86 -0
- package/dist/enums/FeeType.d.ts +8 -0
- package/dist/enums/FeeType.js +12 -0
- package/dist/enums/SwapAmountType.d.ts +8 -0
- package/dist/enums/SwapAmountType.js +12 -0
- package/dist/enums/SwapDirection.d.ts +8 -0
- package/dist/enums/SwapDirection.js +12 -0
- package/dist/enums/SwapType.d.ts +14 -0
- package/dist/enums/SwapType.js +18 -0
- package/dist/errors/IntermediaryError.d.ts +9 -0
- package/dist/errors/IntermediaryError.js +26 -0
- package/dist/errors/PaymentAuthError.d.ts +11 -0
- package/dist/errors/PaymentAuthError.js +23 -0
- package/dist/errors/RequestError.d.ts +18 -0
- package/dist/errors/RequestError.js +46 -0
- package/dist/errors/UserError.d.ts +7 -0
- package/dist/errors/UserError.js +15 -0
- package/dist/events/UnifiedSwapEventListener.d.ts +23 -0
- package/dist/events/UnifiedSwapEventListener.js +130 -0
- package/dist/http/HttpUtils.d.ts +27 -0
- package/dist/http/HttpUtils.js +91 -0
- package/dist/http/paramcoders/IParamReader.d.ts +8 -0
- package/dist/http/paramcoders/IParamReader.js +2 -0
- package/dist/http/paramcoders/ParamDecoder.d.ts +44 -0
- package/dist/http/paramcoders/ParamDecoder.js +132 -0
- package/dist/http/paramcoders/ParamEncoder.d.ts +20 -0
- package/dist/http/paramcoders/ParamEncoder.js +31 -0
- package/dist/http/paramcoders/SchemaVerifier.d.ts +26 -0
- package/dist/http/paramcoders/SchemaVerifier.js +145 -0
- package/dist/http/paramcoders/client/ResponseParamDecoder.d.ts +11 -0
- package/dist/http/paramcoders/client/ResponseParamDecoder.js +57 -0
- package/dist/http/paramcoders/client/StreamParamEncoder.d.ts +13 -0
- package/dist/http/paramcoders/client/StreamParamEncoder.js +26 -0
- package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +16 -0
- package/dist/http/paramcoders/client/StreamingFetchPromise.js +174 -0
- package/dist/index.d.ts +82 -4
- package/dist/index.js +128 -4
- package/dist/intermediaries/Intermediary.d.ts +111 -0
- package/dist/intermediaries/Intermediary.js +115 -0
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +166 -0
- package/dist/intermediaries/IntermediaryDiscovery.js +390 -0
- package/dist/intermediaries/apis/IntermediaryAPI.d.ts +436 -0
- package/dist/intermediaries/apis/IntermediaryAPI.js +600 -0
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.d.ts +154 -0
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.js +136 -0
- package/dist/lnurl/LNURL.d.ts +102 -0
- package/dist/lnurl/LNURL.js +321 -0
- package/dist/prices/RedundantSwapPrice.d.ts +89 -0
- package/dist/prices/RedundantSwapPrice.js +202 -0
- package/dist/prices/SingleSwapPrice.d.ts +31 -0
- package/dist/prices/SingleSwapPrice.js +41 -0
- package/dist/prices/SwapPriceWithChain.d.ts +70 -0
- package/dist/prices/SwapPriceWithChain.js +91 -0
- package/dist/prices/abstract/ICachedSwapPrice.d.ts +28 -0
- package/dist/prices/abstract/ICachedSwapPrice.js +62 -0
- package/dist/prices/abstract/IPriceProvider.d.ts +81 -0
- package/dist/prices/abstract/IPriceProvider.js +74 -0
- package/dist/prices/abstract/ISwapPrice.d.ts +117 -0
- package/dist/prices/abstract/ISwapPrice.js +219 -0
- package/dist/prices/providers/BinancePriceProvider.d.ts +16 -0
- package/dist/prices/providers/BinancePriceProvider.js +23 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +17 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.js +23 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +19 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.js +23 -0
- package/dist/prices/providers/CustomPriceProvider.d.ts +13 -0
- package/dist/prices/providers/CustomPriceProvider.js +24 -0
- package/dist/prices/providers/KrakenPriceProvider.d.ts +29 -0
- package/dist/prices/providers/KrakenPriceProvider.js +36 -0
- package/dist/prices/providers/OKXPriceProvider.d.ts +28 -0
- package/dist/prices/providers/OKXPriceProvider.js +23 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +14 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.js +18 -0
- package/dist/prices/providers/abstract/HttpPriceProvider.d.ts +7 -0
- package/dist/prices/providers/abstract/HttpPriceProvider.js +12 -0
- package/dist/storage/IUnifiedStorage.d.ts +73 -0
- package/dist/storage/IUnifiedStorage.js +2 -0
- package/dist/storage/UnifiedSwapStorage.d.ts +82 -0
- package/dist/storage/UnifiedSwapStorage.js +83 -0
- package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +39 -0
- package/dist/storage-browser/IndexedDBUnifiedStorage.js +275 -0
- package/dist/{storage → storage-browser}/LocalStorageManager.d.ts +1 -0
- package/dist/{storage → storage-browser}/LocalStorageManager.js +2 -1
- package/dist/swapper/Swapper.d.ts +533 -0
- package/dist/swapper/Swapper.js +1566 -0
- package/dist/swapper/SwapperFactory.d.ts +87 -0
- package/dist/{SwapperFactory.js → swapper/SwapperFactory.js} +37 -19
- package/dist/swapper/SwapperUtils.d.ts +153 -0
- package/dist/swapper/SwapperUtils.js +420 -0
- package/dist/swapper/SwapperWithChain.d.ts +214 -0
- package/dist/swapper/SwapperWithChain.js +315 -0
- package/dist/swapper/SwapperWithSigner.d.ts +178 -0
- package/dist/swapper/SwapperWithSigner.js +172 -0
- package/dist/swaps/IAddressSwap.d.ts +13 -0
- package/dist/swaps/IAddressSwap.js +13 -0
- package/dist/swaps/IBTCWalletSwap.d.ts +55 -0
- package/dist/swaps/IBTCWalletSwap.js +17 -0
- package/dist/swaps/IClaimableSwap.d.ts +17 -0
- package/dist/swaps/IClaimableSwap.js +14 -0
- package/dist/swaps/IClaimableSwapWrapper.d.ts +5 -0
- package/dist/swaps/IClaimableSwapWrapper.js +2 -0
- package/dist/swaps/IRefundableSwap.d.ts +17 -0
- package/dist/swaps/IRefundableSwap.js +13 -0
- package/dist/swaps/ISwap.d.ts +207 -0
- package/dist/swaps/ISwap.js +264 -0
- package/dist/swaps/ISwapWithGasDrop.d.ts +15 -0
- package/dist/swaps/ISwapWithGasDrop.js +11 -0
- package/dist/swaps/ISwapWrapper.d.ts +153 -0
- package/dist/swaps/ISwapWrapper.js +227 -0
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +53 -0
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +116 -0
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +70 -0
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +132 -0
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +85 -0
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +122 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +86 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +115 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +93 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +121 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +45 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +65 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +263 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +933 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +110 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +307 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +236 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +898 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +125 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +393 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +245 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +841 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +120 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +294 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +228 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +721 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +37 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +93 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +86 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +213 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +170 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +520 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +50 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +109 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +93 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +217 -0
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +315 -0
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +1098 -0
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +125 -0
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +631 -0
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +107 -0
- package/dist/swaps/trusted/ln/LnForGasSwap.js +343 -0
- package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +21 -0
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +62 -0
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +164 -0
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +520 -0
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +48 -0
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +74 -0
- package/dist/types/AmountData.d.ts +9 -0
- package/dist/types/AmountData.js +2 -0
- package/dist/types/CustomPriceFunction.d.ts +5 -0
- package/dist/types/CustomPriceFunction.js +2 -0
- package/dist/types/PriceInfoType.d.ts +28 -0
- package/dist/types/PriceInfoType.js +57 -0
- package/dist/types/SwapExecutionAction.d.ts +7 -0
- package/dist/types/SwapExecutionAction.js +2 -0
- package/dist/types/SwapWithSigner.d.ts +14 -0
- package/dist/types/SwapWithSigner.js +40 -0
- package/dist/types/Token.d.ts +53 -0
- package/dist/types/Token.js +58 -0
- package/dist/types/TokenAmount.d.ts +57 -0
- package/dist/types/TokenAmount.js +47 -0
- package/dist/types/fees/Fee.d.ts +49 -0
- package/dist/types/fees/Fee.js +2 -0
- package/dist/types/fees/FeeBreakdown.d.ts +10 -0
- package/dist/types/fees/FeeBreakdown.js +2 -0
- package/dist/types/fees/PercentagePPM.d.ts +15 -0
- package/dist/types/fees/PercentagePPM.js +17 -0
- package/dist/types/lnurl/LNURLPay.d.ts +54 -0
- package/dist/types/lnurl/LNURLPay.js +28 -0
- package/dist/types/lnurl/LNURLWithdraw.d.ts +42 -0
- package/dist/types/lnurl/LNURLWithdraw.js +24 -0
- package/dist/utils/AutomaticClockDriftCorrection.d.ts +1 -0
- package/dist/utils/AutomaticClockDriftCorrection.js +70 -0
- package/dist/utils/BitcoinUtils.d.ts +13 -0
- package/dist/utils/BitcoinUtils.js +98 -0
- package/dist/utils/BitcoinWalletUtils.d.ts +7 -0
- package/dist/utils/BitcoinWalletUtils.js +14 -0
- package/dist/utils/Logger.d.ts +7 -0
- package/dist/utils/Logger.js +12 -0
- package/dist/utils/RetryUtils.d.ts +21 -0
- package/dist/utils/RetryUtils.js +66 -0
- package/dist/utils/SwapUtils.d.ts +31 -0
- package/dist/utils/SwapUtils.js +18 -0
- package/dist/{Utils.d.ts → utils/TimeoutUtils.d.ts} +9 -3
- package/dist/utils/TimeoutUtils.js +55 -0
- package/dist/utils/TokenUtils.d.ts +11 -0
- package/dist/utils/TokenUtils.js +29 -0
- package/dist/utils/TypeUtils.d.ts +7 -0
- package/dist/utils/TypeUtils.js +2 -0
- package/dist/utils/Utils.d.ts +57 -0
- package/dist/utils/Utils.js +178 -0
- package/package.json +14 -6
- package/src/SmartChainAssets.ts +11 -3
- package/src/bitcoin/BitcoinRpcWithAddressIndex.ts +87 -0
- package/src/bitcoin/LightningNetworkApi.ts +16 -0
- package/src/bitcoin/coinselect2/accumulative.ts +68 -0
- package/src/bitcoin/coinselect2/blackjack.ts +49 -0
- package/src/bitcoin/coinselect2/index.ts +92 -0
- package/src/bitcoin/coinselect2/utils.ts +189 -0
- package/src/bitcoin/mempool/MempoolApi.ts +554 -0
- package/src/bitcoin/mempool/MempoolBitcoinBlock.ts +88 -0
- package/src/bitcoin/mempool/MempoolBitcoinRpc.ts +437 -0
- package/src/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.ts +134 -0
- package/src/bitcoin/wallet/BitcoinWallet.ts +375 -0
- package/src/bitcoin/wallet/IBitcoinWallet.ts +44 -0
- package/src/bitcoin/wallet/MinimalBitcoinWalletInterface.ts +19 -0
- package/src/bitcoin/wallet/MinimalLightningNetworkWalletInterface.ts +7 -0
- package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +108 -0
- package/src/enums/FeeType.ts +9 -0
- package/src/enums/SwapAmountType.ts +9 -0
- package/src/enums/SwapDirection.ts +9 -0
- package/src/enums/SwapType.ts +15 -0
- package/src/errors/IntermediaryError.ts +24 -0
- package/src/errors/PaymentAuthError.ts +26 -0
- package/src/errors/RequestError.ts +51 -0
- package/src/errors/UserError.ts +14 -0
- package/src/events/UnifiedSwapEventListener.ts +171 -0
- package/src/http/HttpUtils.ts +92 -0
- package/src/http/paramcoders/IParamReader.ts +10 -0
- package/src/http/paramcoders/ParamDecoder.ts +142 -0
- package/src/http/paramcoders/ParamEncoder.ts +37 -0
- package/src/http/paramcoders/SchemaVerifier.ts +153 -0
- package/src/http/paramcoders/client/ResponseParamDecoder.ts +58 -0
- package/src/http/paramcoders/client/StreamParamEncoder.ts +29 -0
- package/src/http/paramcoders/client/StreamingFetchPromise.ts +193 -0
- package/src/index.ts +102 -4
- package/src/intermediaries/Intermediary.ts +204 -0
- package/src/intermediaries/IntermediaryDiscovery.ts +485 -0
- package/src/intermediaries/apis/IntermediaryAPI.ts +940 -0
- package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +257 -0
- package/src/lnurl/LNURL.ts +403 -0
- package/src/prices/RedundantSwapPrice.ts +245 -0
- package/src/prices/SingleSwapPrice.ts +47 -0
- package/src/prices/SwapPriceWithChain.ts +157 -0
- package/src/prices/abstract/ICachedSwapPrice.ts +86 -0
- package/src/prices/abstract/IPriceProvider.ts +128 -0
- package/src/prices/abstract/ISwapPrice.ts +328 -0
- package/src/prices/providers/BinancePriceProvider.ts +41 -0
- package/src/prices/providers/CoinGeckoPriceProvider.ts +40 -0
- package/src/prices/providers/CoinPaprikaPriceProvider.ts +44 -0
- package/src/prices/providers/CustomPriceProvider.ts +29 -0
- package/src/prices/providers/KrakenPriceProvider.ts +74 -0
- package/src/prices/providers/OKXPriceProvider.ts +53 -0
- package/src/prices/providers/abstract/ExchangePriceProvider.ts +29 -0
- package/src/prices/providers/abstract/HttpPriceProvider.ts +15 -0
- package/src/storage/IUnifiedStorage.ts +83 -0
- package/src/storage/UnifiedSwapStorage.ts +104 -0
- package/src/storage-browser/IndexedDBUnifiedStorage.ts +328 -0
- package/src/{storage → storage-browser}/LocalStorageManager.ts +2 -1
- package/src/swapper/Swapper.ts +2107 -0
- package/src/{SwapperFactory.ts → swapper/SwapperFactory.ts} +113 -72
- package/src/swapper/SwapperUtils.ts +510 -0
- package/src/swapper/SwapperWithChain.ts +464 -0
- package/src/swapper/SwapperWithSigner.ts +300 -0
- package/src/swaps/IAddressSwap.ts +20 -0
- package/src/swaps/IBTCWalletSwap.ts +77 -0
- package/src/swaps/IClaimableSwap.ts +30 -0
- package/src/swaps/IClaimableSwapWrapper.ts +9 -0
- package/src/swaps/IRefundableSwap.ts +29 -0
- package/src/swaps/ISwap.ts +490 -0
- package/src/swaps/ISwapWithGasDrop.ts +19 -0
- package/src/swaps/ISwapWrapper.ts +344 -0
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +168 -0
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +197 -0
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +210 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +150 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +219 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +84 -0
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +1082 -0
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +429 -0
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +1078 -0
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +549 -0
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +974 -0
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +443 -0
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +860 -0
- package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +104 -0
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +256 -0
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +716 -0
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +151 -0
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +299 -0
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +1394 -0
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +796 -0
- package/src/swaps/trusted/ln/LnForGasSwap.ts +402 -0
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +70 -0
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +633 -0
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +110 -0
- package/src/types/AmountData.ts +9 -0
- package/src/types/CustomPriceFunction.ts +5 -0
- package/src/types/PriceInfoType.ts +67 -0
- package/src/types/SwapExecutionAction.ts +8 -0
- package/src/types/SwapWithSigner.ts +57 -0
- package/src/types/Token.ts +90 -0
- package/src/types/TokenAmount.ts +110 -0
- package/src/types/fees/Fee.ts +55 -0
- package/src/types/fees/FeeBreakdown.ts +11 -0
- package/src/types/fees/PercentagePPM.ts +24 -0
- package/src/types/lnurl/LNURLPay.ts +72 -0
- package/src/types/lnurl/LNURLWithdraw.ts +55 -0
- package/src/utils/AutomaticClockDriftCorrection.ts +71 -0
- package/src/utils/BitcoinUtils.ts +86 -0
- package/src/utils/BitcoinWalletUtils.ts +16 -0
- package/src/utils/Logger.ts +15 -0
- package/src/utils/RetryUtils.ts +71 -0
- package/src/utils/SwapUtils.ts +38 -0
- package/src/utils/TimeoutUtils.ts +50 -0
- package/src/utils/TokenUtils.ts +25 -0
- package/src/utils/TypeUtils.ts +9 -0
- package/src/utils/Utils.ts +182 -0
- package/dist/SwapperFactory.d.ts +0 -52
- package/dist/Utils.js +0 -37
- package/dist/fs-storage/FileSystemStorageManager.d.ts +0 -15
- package/dist/fs-storage/FileSystemStorageManager.js +0 -60
- package/dist/fs-storage/index.d.ts +0 -1
- package/dist/fs-storage/index.js +0 -17
- package/src/SmartChainAssets.js +0 -75
- package/src/SwapperFactory.js +0 -120
- package/src/Utils.js +0 -37
- package/src/Utils.ts +0 -31
- package/src/fs-storage/FileSystemStorageManager.ts +0 -71
- package/src/fs-storage/index.ts +0 -1
- package/src/index.js +0 -21
- package/src/storage/LocalStorageManager.js +0 -72
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {ToBTCDefinition, ToBTCWrapper} from "./ToBTCWrapper";
|
|
2
|
+
import {isIToBTCSwapInit, IToBTCSwap, IToBTCSwapInit} from "../IToBTCSwap";
|
|
3
|
+
import {SwapType} from "../../../../enums/SwapType";
|
|
4
|
+
import {ChainType, SwapData} from "@atomiqlabs/base";
|
|
5
|
+
import {Buffer} from "buffer";
|
|
6
|
+
import {IntermediaryError} from "../../../../errors/IntermediaryError";
|
|
7
|
+
import {toBigInt} from "../../../../utils/Utils";
|
|
8
|
+
import {TokenAmount, toTokenAmount} from "../../../../types/TokenAmount";
|
|
9
|
+
import {BitcoinTokens, BtcToken} from "../../../../types/Token";
|
|
10
|
+
import {getLogger, LoggerType} from "../../../../utils/Logger";
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export type ToBTCSwapInit<T extends SwapData> = IToBTCSwapInit<T> & {
|
|
14
|
+
address: string;
|
|
15
|
+
amount: bigint;
|
|
16
|
+
confirmationTarget: number;
|
|
17
|
+
satsPerVByte: number;
|
|
18
|
+
requiredConfirmations: number;
|
|
19
|
+
nonce: bigint;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function isToBTCSwapInit<T extends SwapData>(obj: any): obj is ToBTCSwapInit<T> {
|
|
23
|
+
return typeof (obj.address) === "string" &&
|
|
24
|
+
typeof(obj.amount) === "bigint" &&
|
|
25
|
+
typeof (obj.confirmationTarget) === "number" &&
|
|
26
|
+
typeof (obj.satsPerVByte) === "number" &&
|
|
27
|
+
typeof (obj.requiredConfirmations) === "number" &&
|
|
28
|
+
typeof (obj.nonce) === "bigint" &&
|
|
29
|
+
isIToBTCSwapInit<T>(obj);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Smart Chain to on-chain BTC swap
|
|
34
|
+
* @category Swaps
|
|
35
|
+
*/
|
|
36
|
+
export class ToBTCSwap<T extends ChainType = ChainType> extends IToBTCSwap<T, ToBTCDefinition<T>> {
|
|
37
|
+
protected readonly outputToken: BtcToken<false> = BitcoinTokens.BTC;
|
|
38
|
+
protected readonly TYPE = SwapType.TO_BTC;
|
|
39
|
+
protected readonly logger: LoggerType;
|
|
40
|
+
|
|
41
|
+
private readonly address: string;
|
|
42
|
+
private readonly amount: bigint;
|
|
43
|
+
private readonly confirmationTarget: number;
|
|
44
|
+
private readonly satsPerVByte: number;
|
|
45
|
+
|
|
46
|
+
private readonly requiredConfirmations: number;
|
|
47
|
+
private readonly nonce: bigint;
|
|
48
|
+
|
|
49
|
+
private txId?: string;
|
|
50
|
+
|
|
51
|
+
constructor(wrapper: ToBTCWrapper<T>, serializedObject: any);
|
|
52
|
+
constructor(wrapper: ToBTCWrapper<T>, init: ToBTCSwapInit<T["Data"]>);
|
|
53
|
+
constructor(
|
|
54
|
+
wrapper: ToBTCWrapper<T>,
|
|
55
|
+
initOrObject: ToBTCSwapInit<T["Data"]> | any
|
|
56
|
+
) {
|
|
57
|
+
if(isToBTCSwapInit(initOrObject) && initOrObject.url!=null) initOrObject.url += "/tobtc";
|
|
58
|
+
super(wrapper, initOrObject);
|
|
59
|
+
if(isToBTCSwapInit(initOrObject)) {
|
|
60
|
+
this.address = initOrObject.address;
|
|
61
|
+
this.amount = initOrObject.amount;
|
|
62
|
+
this.confirmationTarget = initOrObject.confirmationTarget;
|
|
63
|
+
this.satsPerVByte = initOrObject.satsPerVByte;
|
|
64
|
+
this.requiredConfirmations = initOrObject.requiredConfirmations;
|
|
65
|
+
this.nonce = initOrObject.nonce;
|
|
66
|
+
} else {
|
|
67
|
+
this.address = initOrObject.address;
|
|
68
|
+
this.amount = BigInt(initOrObject.amount);
|
|
69
|
+
this.confirmationTarget = initOrObject.confirmationTarget;
|
|
70
|
+
this.satsPerVByte = initOrObject.satsPerVByte;
|
|
71
|
+
this.txId = initOrObject.txId;
|
|
72
|
+
|
|
73
|
+
this.requiredConfirmations = initOrObject.requiredConfirmations ?? this.data.getConfirmationsHint();
|
|
74
|
+
this.nonce = toBigInt(initOrObject.nonce) ?? this.data.getNonceHint();
|
|
75
|
+
}
|
|
76
|
+
this.logger = getLogger("ToBTC("+this.getIdentifierHashString()+"): ");
|
|
77
|
+
this.tryRecomputeSwapPrice();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
async _setPaymentResult(result: { secret?: string; txId?: string }, check: boolean = false): Promise<boolean> {
|
|
81
|
+
if(result==null) return false;
|
|
82
|
+
if(result.txId==null) throw new IntermediaryError("No btc txId returned!");
|
|
83
|
+
if(check) {
|
|
84
|
+
const btcTx = await this.wrapper.btcRpc.getTransaction(result.txId);
|
|
85
|
+
if(btcTx==null) return false;
|
|
86
|
+
|
|
87
|
+
const foundVout = btcTx.outs.find(vout => this.data.getClaimHash()===this.wrapper.contract.getHashForOnchain(
|
|
88
|
+
Buffer.from(vout.scriptPubKey.hex, "hex"),
|
|
89
|
+
BigInt(vout.value),
|
|
90
|
+
this.requiredConfirmations,
|
|
91
|
+
this.nonce
|
|
92
|
+
).toString("hex"));
|
|
93
|
+
|
|
94
|
+
if(foundVout==null) throw new IntermediaryError("Invalid btc txId returned");
|
|
95
|
+
}
|
|
96
|
+
this.txId = result.txId;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
//////////////////////////////
|
|
102
|
+
//// Amounts & fees
|
|
103
|
+
|
|
104
|
+
getOutputToken(): BtcToken<false> {
|
|
105
|
+
return BitcoinTokens.BTC;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
getOutput(): TokenAmount<T["ChainId"], BtcToken<false>> {
|
|
109
|
+
return toTokenAmount(this.amount, this.outputToken, this.wrapper.prices, this.pricingInfo);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
//////////////////////////////
|
|
114
|
+
//// Getters & utils
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Returns the bitcoin address where the BTC will be sent to
|
|
118
|
+
*/
|
|
119
|
+
getOutputAddress(): string {
|
|
120
|
+
return this.address;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
getOutputTxId(): string | null {
|
|
124
|
+
return this.txId ?? null;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Returns fee rate of the bitcoin transaction in sats/vB
|
|
129
|
+
*/
|
|
130
|
+
getBitcoinFeeRate(): number {
|
|
131
|
+
return this.satsPerVByte;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
//////////////////////////////
|
|
136
|
+
//// Storage
|
|
137
|
+
|
|
138
|
+
serialize(): any {
|
|
139
|
+
return {
|
|
140
|
+
...super.serialize(),
|
|
141
|
+
address: this.address,
|
|
142
|
+
amount: this.amount.toString(10),
|
|
143
|
+
confirmationTarget: this.confirmationTarget,
|
|
144
|
+
satsPerVByte: this.satsPerVByte,
|
|
145
|
+
nonce: this.nonce==null ? null : this.nonce.toString(10),
|
|
146
|
+
requiredConfirmations: this.requiredConfirmations,
|
|
147
|
+
txId: this.txId
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import {ToBTCSwap, ToBTCSwapInit} from "./ToBTCSwap";
|
|
2
|
+
import {IToBTCDefinition, IToBTCWrapper} from "../IToBTCWrapper";
|
|
3
|
+
import {BigIntBufferUtils, BitcoinRpc, ChainSwapType, ChainType} from "@atomiqlabs/base";
|
|
4
|
+
import {Intermediary, SingleChainReputationType} from "../../../../intermediaries/Intermediary";
|
|
5
|
+
import {ISwapPrice} from "../../../../prices/abstract/ISwapPrice";
|
|
6
|
+
import {EventEmitter} from "events";
|
|
7
|
+
import {ISwapWrapperOptions, WrapperCtorTokens} from "../../../ISwapWrapper";
|
|
8
|
+
import {Buffer} from "buffer";
|
|
9
|
+
import {UserError} from "../../../../errors/UserError";
|
|
10
|
+
import {IntermediaryError} from "../../../../errors/IntermediaryError";
|
|
11
|
+
import {SwapType} from "../../../../enums/SwapType";
|
|
12
|
+
import {extendAbortController, randomBytes, throwIfUndefined} from "../../../../utils/Utils";
|
|
13
|
+
import {toOutputScript} from "../../../../utils/BitcoinUtils";
|
|
14
|
+
import {IntermediaryAPI, ToBTCResponseType} from "../../../../intermediaries/apis/IntermediaryAPI";
|
|
15
|
+
import {RequestError} from "../../../../errors/RequestError";
|
|
16
|
+
import {BTC_NETWORK, TEST_NETWORK} from "@scure/btc-signer/utils";
|
|
17
|
+
import {UnifiedSwapEventListener} from "../../../../events/UnifiedSwapEventListener";
|
|
18
|
+
import {UnifiedSwapStorage} from "../../../../storage/UnifiedSwapStorage";
|
|
19
|
+
import {ISwap} from "../../../ISwap";
|
|
20
|
+
import {AmountData} from "../../../../types/AmountData";
|
|
21
|
+
import {tryWithRetries} from "../../../../utils/RetryUtils";
|
|
22
|
+
import {AllOptional, AllRequired} from "../../../../utils/TypeUtils";
|
|
23
|
+
|
|
24
|
+
export type ToBTCOptions = {
|
|
25
|
+
confirmationTarget?: number,
|
|
26
|
+
confirmations?: number
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export type ToBTCWrapperOptions = ISwapWrapperOptions & {
|
|
30
|
+
safetyFactor: number,
|
|
31
|
+
maxConfirmations: number,
|
|
32
|
+
bitcoinNetwork: BTC_NETWORK,
|
|
33
|
+
|
|
34
|
+
bitcoinBlocktime: number,
|
|
35
|
+
|
|
36
|
+
maxExpectedOnchainSendSafetyFactor: number,
|
|
37
|
+
maxExpectedOnchainSendGracePeriodBlocks: number,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type ToBTCDefinition<T extends ChainType> = IToBTCDefinition<T, ToBTCWrapper<T>, ToBTCSwap<T>>;
|
|
41
|
+
|
|
42
|
+
export class ToBTCWrapper<T extends ChainType> extends IToBTCWrapper<T, ToBTCDefinition<T>, ToBTCWrapperOptions> {
|
|
43
|
+
public readonly TYPE = SwapType.TO_BTC;
|
|
44
|
+
public readonly swapDeserializer = ToBTCSwap;
|
|
45
|
+
|
|
46
|
+
readonly btcRpc: BitcoinRpc<any>;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @param chainIdentifier
|
|
50
|
+
* @param unifiedStorage Storage interface for the current environment
|
|
51
|
+
* @param unifiedChainEvents Smart chain on-chain event listener
|
|
52
|
+
* @param chain
|
|
53
|
+
* @param contract Chain specific swap contract
|
|
54
|
+
* @param prices Swap pricing handler
|
|
55
|
+
* @param tokens
|
|
56
|
+
* @param swapDataDeserializer Deserializer for chain specific SwapData
|
|
57
|
+
* @param btcRpc Bitcoin RPC api
|
|
58
|
+
* @param options
|
|
59
|
+
* @param events Instance to use for emitting events
|
|
60
|
+
*/
|
|
61
|
+
constructor(
|
|
62
|
+
chainIdentifier: string,
|
|
63
|
+
unifiedStorage: UnifiedSwapStorage<T>,
|
|
64
|
+
unifiedChainEvents: UnifiedSwapEventListener<T>,
|
|
65
|
+
chain: T["ChainInterface"],
|
|
66
|
+
contract: T["Contract"],
|
|
67
|
+
prices: ISwapPrice,
|
|
68
|
+
tokens: WrapperCtorTokens,
|
|
69
|
+
swapDataDeserializer: new (data: any) => T["Data"],
|
|
70
|
+
btcRpc: BitcoinRpc<any>,
|
|
71
|
+
options?: AllOptional<ToBTCWrapperOptions>,
|
|
72
|
+
events?: EventEmitter<{swapState: [ISwap]}>
|
|
73
|
+
) {
|
|
74
|
+
super(
|
|
75
|
+
chainIdentifier, unifiedStorage, unifiedChainEvents, chain, contract, prices, tokens, swapDataDeserializer,
|
|
76
|
+
{
|
|
77
|
+
bitcoinNetwork: options?.bitcoinNetwork ?? TEST_NETWORK,
|
|
78
|
+
safetyFactor: options?.safetyFactor ?? 2,
|
|
79
|
+
maxConfirmations: options?.maxConfirmations ?? 6,
|
|
80
|
+
bitcoinBlocktime: options?.bitcoinBlocktime ?? (60*10),
|
|
81
|
+
maxExpectedOnchainSendSafetyFactor: options?.maxExpectedOnchainSendSafetyFactor ?? 4,
|
|
82
|
+
maxExpectedOnchainSendGracePeriodBlocks: options?.maxExpectedOnchainSendGracePeriodBlocks ?? 12,
|
|
83
|
+
},
|
|
84
|
+
events
|
|
85
|
+
);
|
|
86
|
+
this.btcRpc = btcRpc;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Returns randomly generated random escrow nonce to be used for to BTC on-chain swaps
|
|
91
|
+
* @private
|
|
92
|
+
* @returns Escrow nonce
|
|
93
|
+
*/
|
|
94
|
+
private getRandomNonce(): bigint {
|
|
95
|
+
const firstPart = BigInt(Math.floor((Date.now()/1000)) - 700000000);
|
|
96
|
+
|
|
97
|
+
return (firstPart << 24n) | BigIntBufferUtils.fromBuffer(randomBytes(3));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Converts bitcoin address to its corresponding output script
|
|
102
|
+
*
|
|
103
|
+
* @param addr Bitcoin address to get the output script for
|
|
104
|
+
* @private
|
|
105
|
+
* @returns Output script as Buffer
|
|
106
|
+
* @throws {UserError} if invalid address is specified
|
|
107
|
+
*/
|
|
108
|
+
private btcAddressToOutputScript(addr: string): Buffer {
|
|
109
|
+
try {
|
|
110
|
+
return toOutputScript(this.options.bitcoinNetwork, addr);
|
|
111
|
+
} catch (e) {
|
|
112
|
+
throw new UserError("Invalid address specified");
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Verifies returned LP data
|
|
118
|
+
*
|
|
119
|
+
* @param signer
|
|
120
|
+
* @param resp LP's response
|
|
121
|
+
* @param amountData
|
|
122
|
+
* @param lp
|
|
123
|
+
* @param options Options as passed to the swap create function
|
|
124
|
+
* @param data LP's returned parsed swap data
|
|
125
|
+
* @param hash Payment hash of the swap
|
|
126
|
+
* @private
|
|
127
|
+
* @throws {IntermediaryError} if returned data are not correct
|
|
128
|
+
*/
|
|
129
|
+
private verifyReturnedData(
|
|
130
|
+
signer: string,
|
|
131
|
+
resp: ToBTCResponseType,
|
|
132
|
+
amountData: AmountData,
|
|
133
|
+
lp: Intermediary,
|
|
134
|
+
options: AllRequired<ToBTCOptions>,
|
|
135
|
+
data: T["Data"],
|
|
136
|
+
hash: string
|
|
137
|
+
): void {
|
|
138
|
+
if(resp.totalFee !== (resp.swapFee + resp.networkFee)) throw new IntermediaryError("Invalid totalFee returned");
|
|
139
|
+
|
|
140
|
+
if(amountData.exactIn) {
|
|
141
|
+
if(resp.total !== amountData.amount) throw new IntermediaryError("Invalid total returned");
|
|
142
|
+
} else {
|
|
143
|
+
if(resp.amount !== amountData.amount) throw new IntermediaryError("Invalid amount returned");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const maxAllowedBlockDelta: bigint = BigInt(
|
|
147
|
+
options.confirmations +
|
|
148
|
+
options.confirmationTarget +
|
|
149
|
+
this.options.maxExpectedOnchainSendGracePeriodBlocks
|
|
150
|
+
);
|
|
151
|
+
const maxAllowedExpiryDelta: bigint = maxAllowedBlockDelta
|
|
152
|
+
* BigInt(this.options.maxExpectedOnchainSendSafetyFactor)
|
|
153
|
+
* BigInt(this.options.bitcoinBlocktime);
|
|
154
|
+
const currentTimestamp: bigint = BigInt(Math.floor(Date.now()/1000));
|
|
155
|
+
const maxAllowedExpiryTimestamp: bigint = currentTimestamp + maxAllowedExpiryDelta;
|
|
156
|
+
|
|
157
|
+
if(data.getExpiry() > maxAllowedExpiryTimestamp) {
|
|
158
|
+
throw new IntermediaryError("Expiry time returned too high!");
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if(
|
|
162
|
+
data.getAmount() !== resp.total ||
|
|
163
|
+
data.getClaimHash()!==hash ||
|
|
164
|
+
data.getType()!==ChainSwapType.CHAIN_NONCED ||
|
|
165
|
+
!data.isPayIn() ||
|
|
166
|
+
!data.isToken(amountData.token) ||
|
|
167
|
+
!data.isClaimer(lp.getAddress(this.chainIdentifier)) ||
|
|
168
|
+
!data.isOfferer(signer) ||
|
|
169
|
+
data.getTotalDeposit() !== 0n
|
|
170
|
+
) {
|
|
171
|
+
throw new IntermediaryError("Invalid data returned");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Returns quotes fetched from LPs, paying to an 'address' - a bitcoin address
|
|
177
|
+
*
|
|
178
|
+
* @param signer Smart-chain signer address initiating the swap
|
|
179
|
+
* @param address Bitcoin on-chain address you wish to pay to
|
|
180
|
+
* @param amountData Amount of token & amount to swap
|
|
181
|
+
* @param lps LPs (liquidity providers) to get the quotes from
|
|
182
|
+
* @param options Quote options
|
|
183
|
+
* @param additionalParams Additional parameters sent to the LP when creating the swap
|
|
184
|
+
* @param abortSignal Abort signal for aborting the process
|
|
185
|
+
*/
|
|
186
|
+
create(
|
|
187
|
+
signer: string,
|
|
188
|
+
address: string,
|
|
189
|
+
amountData: AmountData,
|
|
190
|
+
lps: Intermediary[],
|
|
191
|
+
options?: ToBTCOptions,
|
|
192
|
+
additionalParams?: Record<string, any>,
|
|
193
|
+
abortSignal?: AbortSignal
|
|
194
|
+
): {
|
|
195
|
+
quote: Promise<ToBTCSwap<T>>,
|
|
196
|
+
intermediary: Intermediary
|
|
197
|
+
}[] {
|
|
198
|
+
if(!this.isInitialized) throw new Error("Not initialized, call init() first!");
|
|
199
|
+
const _options: AllRequired<ToBTCOptions> = {
|
|
200
|
+
confirmationTarget: options?.confirmationTarget ?? 3,
|
|
201
|
+
confirmations: options?.confirmations ?? 2
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
const nonce: bigint = this.getRandomNonce();
|
|
205
|
+
const outputScript: Buffer = this.btcAddressToOutputScript(address);
|
|
206
|
+
const _hash: string | undefined = !amountData.exactIn ?
|
|
207
|
+
this.contract.getHashForOnchain(outputScript, amountData.amount, _options.confirmations, nonce).toString("hex") :
|
|
208
|
+
undefined;
|
|
209
|
+
|
|
210
|
+
const _abortController = extendAbortController(abortSignal);
|
|
211
|
+
const pricePreFetchPromise: Promise<bigint | undefined> = this.preFetchPrice(amountData, _abortController.signal);
|
|
212
|
+
const usdPricePrefetchPromise: Promise<number | undefined> = this.preFetchUsdPrice(_abortController.signal);
|
|
213
|
+
const feeRatePromise: Promise<string | undefined> = this.preFetchFeeRate(signer, amountData, _hash, _abortController);
|
|
214
|
+
const _signDataPromise: Promise<T["PreFetchVerification"] | undefined> | undefined = this.contract.preFetchBlockDataForSignatures==null ?
|
|
215
|
+
this.preFetchSignData(Promise.resolve(true)) :
|
|
216
|
+
undefined;
|
|
217
|
+
|
|
218
|
+
return lps.map(lp => {
|
|
219
|
+
return {
|
|
220
|
+
intermediary: lp,
|
|
221
|
+
quote: (async () => {
|
|
222
|
+
if(lp.services[SwapType.TO_BTC]==null) throw new Error("LP service for processing to btc swaps not found!");
|
|
223
|
+
|
|
224
|
+
const abortController = extendAbortController(_abortController.signal);
|
|
225
|
+
const reputationPromise: Promise<SingleChainReputationType | undefined> = this.preFetchIntermediaryReputation(amountData, lp, abortController);
|
|
226
|
+
|
|
227
|
+
try {
|
|
228
|
+
const {signDataPromise, resp} = await tryWithRetries(async(retryCount) => {
|
|
229
|
+
const {signDataPrefetch, response} = IntermediaryAPI.initToBTC(this.chainIdentifier, lp.url, {
|
|
230
|
+
btcAddress: address,
|
|
231
|
+
amount: amountData.amount,
|
|
232
|
+
confirmationTarget: _options.confirmationTarget,
|
|
233
|
+
confirmations: _options.confirmations,
|
|
234
|
+
nonce: nonce,
|
|
235
|
+
token: amountData.token,
|
|
236
|
+
offerer: signer,
|
|
237
|
+
exactIn: amountData.exactIn,
|
|
238
|
+
feeRate: throwIfUndefined(feeRatePromise),
|
|
239
|
+
additionalParams
|
|
240
|
+
}, this.options.postRequestTimeout, abortController.signal, retryCount>0 ? false : undefined);
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
signDataPromise: _signDataPromise ?? this.preFetchSignData(signDataPrefetch),
|
|
244
|
+
resp: await response
|
|
245
|
+
};
|
|
246
|
+
}, undefined, RequestError, abortController.signal);
|
|
247
|
+
|
|
248
|
+
let hash: string = _hash ?? this.contract.getHashForOnchain(outputScript, resp.amount, _options.confirmations, nonce).toString("hex");
|
|
249
|
+
|
|
250
|
+
const data: T["Data"] = new this.swapDataDeserializer(resp.data);
|
|
251
|
+
data.setOfferer(signer);
|
|
252
|
+
|
|
253
|
+
this.verifyReturnedData(signer, resp, amountData, lp, _options, data, hash);
|
|
254
|
+
const [pricingInfo, signatureExpiry, reputation] = await Promise.all([
|
|
255
|
+
this.verifyReturnedPrice(
|
|
256
|
+
lp.services[SwapType.TO_BTC], true, resp.amount, data.getAmount(),
|
|
257
|
+
amountData.token, resp, pricePreFetchPromise, usdPricePrefetchPromise, abortController.signal
|
|
258
|
+
),
|
|
259
|
+
this.verifyReturnedSignature(signer, data, resp, feeRatePromise, signDataPromise, abortController.signal),
|
|
260
|
+
reputationPromise
|
|
261
|
+
]);
|
|
262
|
+
abortController.signal.throwIfAborted();
|
|
263
|
+
|
|
264
|
+
if(reputation!=null) lp.reputation[amountData.token.toString()] = reputation;
|
|
265
|
+
|
|
266
|
+
const inputWithoutFees = data.getAmount() - resp.swapFee - resp.networkFee;
|
|
267
|
+
const swapFeeBtc = resp.swapFee * resp.amount / inputWithoutFees;
|
|
268
|
+
const networkFeeBtc = resp.networkFee * resp.amount / inputWithoutFees
|
|
269
|
+
|
|
270
|
+
const quote = new ToBTCSwap<T>(this, {
|
|
271
|
+
pricingInfo,
|
|
272
|
+
url: lp.url,
|
|
273
|
+
expiry: signatureExpiry,
|
|
274
|
+
swapFee: resp.swapFee,
|
|
275
|
+
swapFeeBtc,
|
|
276
|
+
feeRate: (await feeRatePromise)!,
|
|
277
|
+
signatureData: resp,
|
|
278
|
+
data,
|
|
279
|
+
networkFee: resp.networkFee,
|
|
280
|
+
networkFeeBtc,
|
|
281
|
+
address,
|
|
282
|
+
amount: resp.amount,
|
|
283
|
+
confirmationTarget: _options.confirmationTarget,
|
|
284
|
+
satsPerVByte: Number(resp.satsPervByte),
|
|
285
|
+
exactIn: amountData.exactIn,
|
|
286
|
+
requiredConfirmations: _options.confirmations,
|
|
287
|
+
nonce
|
|
288
|
+
} as ToBTCSwapInit<T["Data"]>);
|
|
289
|
+
await quote._save();
|
|
290
|
+
return quote;
|
|
291
|
+
} catch (e) {
|
|
292
|
+
abortController.abort(e);
|
|
293
|
+
throw e;
|
|
294
|
+
}
|
|
295
|
+
})()
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
}
|