@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,940 @@
|
|
|
1
|
+
import {RequestError} from "../../errors/RequestError";
|
|
2
|
+
import {
|
|
3
|
+
FieldTypeEnum,
|
|
4
|
+
RequestSchemaResult,
|
|
5
|
+
verifySchema
|
|
6
|
+
} from "../../http/paramcoders/SchemaVerifier";
|
|
7
|
+
import {streamingFetchPromise} from "../../http/paramcoders/client/StreamingFetchPromise";
|
|
8
|
+
import {extendAbortController, randomBytes} from "../../utils/Utils";
|
|
9
|
+
import {httpGet, httpPost} from "../../http/HttpUtils";
|
|
10
|
+
import {tryWithRetries} from "../../utils/RetryUtils";
|
|
11
|
+
|
|
12
|
+
export type InfoHandlerResponse = {
|
|
13
|
+
envelope: string,
|
|
14
|
+
chains: {
|
|
15
|
+
[chainIdentifier: string]: {
|
|
16
|
+
address: string,
|
|
17
|
+
signature: string
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export enum RefundAuthorizationResponseCodes {
|
|
23
|
+
EXPIRED=20010,
|
|
24
|
+
REFUND_DATA=20000,
|
|
25
|
+
NOT_FOUND=20007,
|
|
26
|
+
PENDING=20008,
|
|
27
|
+
PAID=20006
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export enum PaymentAuthorizationResponseCodes {
|
|
31
|
+
AUTH_DATA=10000,
|
|
32
|
+
EXPIRED=10001,
|
|
33
|
+
PAID=10002,
|
|
34
|
+
PENDING=10003,
|
|
35
|
+
ALREADY_COMMITTED=10004
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export enum InvoiceStatusResponseCodes {
|
|
39
|
+
PAID=10000,
|
|
40
|
+
EXPIRED=10001,
|
|
41
|
+
SETTLED=10002,
|
|
42
|
+
PENDING=10003
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export type RefundAuthorizationResponse = {
|
|
46
|
+
code: RefundAuthorizationResponseCodes.PAID,
|
|
47
|
+
msg: string,
|
|
48
|
+
data: {
|
|
49
|
+
secret?: string,
|
|
50
|
+
txId?: string
|
|
51
|
+
}
|
|
52
|
+
} | {
|
|
53
|
+
code: RefundAuthorizationResponseCodes.REFUND_DATA,
|
|
54
|
+
msg: string,
|
|
55
|
+
data: {
|
|
56
|
+
address: string,
|
|
57
|
+
prefix: string,
|
|
58
|
+
timeout: string,
|
|
59
|
+
signature: string
|
|
60
|
+
}
|
|
61
|
+
} | {
|
|
62
|
+
code: Exclude<RefundAuthorizationResponseCodes, RefundAuthorizationResponseCodes.PAID | RefundAuthorizationResponseCodes.REFUND_DATA>,
|
|
63
|
+
msg: string
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type PaymentAuthorizationResponse = {
|
|
67
|
+
code: PaymentAuthorizationResponseCodes.AUTH_DATA,
|
|
68
|
+
msg: string,
|
|
69
|
+
data: {
|
|
70
|
+
address: string,
|
|
71
|
+
data: any,
|
|
72
|
+
nonce: number,
|
|
73
|
+
prefix: string,
|
|
74
|
+
timeout: string,
|
|
75
|
+
signature: string
|
|
76
|
+
}
|
|
77
|
+
} | {
|
|
78
|
+
code: Exclude<PaymentAuthorizationResponseCodes, PaymentAuthorizationResponseCodes.AUTH_DATA>,
|
|
79
|
+
msg: string
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export type InvoiceStatusResponse = {
|
|
83
|
+
code: Exclude<InvoiceStatusResponseCodes, InvoiceStatusResponseCodes.PAID>,
|
|
84
|
+
msg: string
|
|
85
|
+
} | {
|
|
86
|
+
code: InvoiceStatusResponseCodes.PAID,
|
|
87
|
+
msg: string,
|
|
88
|
+
data: {
|
|
89
|
+
data: any
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const SwapResponseSchema = {
|
|
94
|
+
data: FieldTypeEnum.Any,
|
|
95
|
+
|
|
96
|
+
prefix: FieldTypeEnum.String,
|
|
97
|
+
timeout: FieldTypeEnum.String,
|
|
98
|
+
signature: FieldTypeEnum.String
|
|
99
|
+
} as const;
|
|
100
|
+
|
|
101
|
+
export type SwapInit = {
|
|
102
|
+
token: string,
|
|
103
|
+
additionalParams?: { [name: string]: any }
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export type BaseFromBTCSwapInit = SwapInit & {
|
|
107
|
+
claimer: string,
|
|
108
|
+
amount: bigint,
|
|
109
|
+
exactOut: boolean,
|
|
110
|
+
feeRate: Promise<string>
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export type BaseToBTCSwapInit = SwapInit & {
|
|
114
|
+
offerer: string
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/////////////////////////
|
|
118
|
+
///// To BTC
|
|
119
|
+
|
|
120
|
+
const ToBTCResponseSchema = {
|
|
121
|
+
amount: FieldTypeEnum.BigInt,
|
|
122
|
+
address: FieldTypeEnum.String,
|
|
123
|
+
satsPervByte: FieldTypeEnum.BigInt,
|
|
124
|
+
networkFee: FieldTypeEnum.BigInt,
|
|
125
|
+
swapFee: FieldTypeEnum.BigInt,
|
|
126
|
+
totalFee: FieldTypeEnum.BigInt,
|
|
127
|
+
total: FieldTypeEnum.BigInt,
|
|
128
|
+
minRequiredExpiry: FieldTypeEnum.BigInt,
|
|
129
|
+
...SwapResponseSchema
|
|
130
|
+
} as const;
|
|
131
|
+
|
|
132
|
+
export type ToBTCResponseType = RequestSchemaResult<typeof ToBTCResponseSchema>;
|
|
133
|
+
|
|
134
|
+
export type ToBTCInit = BaseToBTCSwapInit & {
|
|
135
|
+
btcAddress: string,
|
|
136
|
+
exactIn: boolean,
|
|
137
|
+
amount: bigint,
|
|
138
|
+
confirmationTarget: number,
|
|
139
|
+
confirmations: number,
|
|
140
|
+
nonce: bigint,
|
|
141
|
+
feeRate: Promise<string>
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/////////////////////////
|
|
145
|
+
///// To BTCLN
|
|
146
|
+
|
|
147
|
+
const ToBTCLNResponseSchema = {
|
|
148
|
+
maxFee: FieldTypeEnum.BigInt,
|
|
149
|
+
swapFee: FieldTypeEnum.BigInt,
|
|
150
|
+
total: FieldTypeEnum.BigInt,
|
|
151
|
+
confidence: FieldTypeEnum.Number,
|
|
152
|
+
address: FieldTypeEnum.String,
|
|
153
|
+
|
|
154
|
+
routingFeeSats: FieldTypeEnum.BigInt,
|
|
155
|
+
...SwapResponseSchema
|
|
156
|
+
} as const;
|
|
157
|
+
|
|
158
|
+
export type ToBTCLNResponseType = RequestSchemaResult<typeof ToBTCLNResponseSchema>;
|
|
159
|
+
|
|
160
|
+
export type ToBTCLNInit = BaseToBTCSwapInit & {
|
|
161
|
+
pr: string,
|
|
162
|
+
maxFee: bigint,
|
|
163
|
+
expiryTimestamp: bigint,
|
|
164
|
+
feeRate: Promise<string>
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const ToBTCLNPrepareExactInSchema = {
|
|
168
|
+
amount: FieldTypeEnum.BigInt,
|
|
169
|
+
reqId: FieldTypeEnum.String
|
|
170
|
+
} as const;
|
|
171
|
+
|
|
172
|
+
export type ToBTCLNPrepareExactInResponseType = RequestSchemaResult<typeof ToBTCLNPrepareExactInSchema>;
|
|
173
|
+
|
|
174
|
+
export type ToBTCLNPrepareExactIn = BaseToBTCSwapInit & {
|
|
175
|
+
pr: string,
|
|
176
|
+
amount: bigint,
|
|
177
|
+
maxFee: bigint,
|
|
178
|
+
expiryTimestamp: bigint
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export type ToBTCLNInitExactIn = {
|
|
182
|
+
pr: string,
|
|
183
|
+
reqId: string,
|
|
184
|
+
feeRate: Promise<string>,
|
|
185
|
+
additionalParams?: { [name: string]: any }
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/////////////////////////
|
|
189
|
+
///// From BTC
|
|
190
|
+
|
|
191
|
+
const FromBTCResponseSchema = {
|
|
192
|
+
amount: FieldTypeEnum.BigInt,
|
|
193
|
+
btcAddress: FieldTypeEnum.String,
|
|
194
|
+
address: FieldTypeEnum.String,
|
|
195
|
+
swapFee: FieldTypeEnum.BigInt,
|
|
196
|
+
total: FieldTypeEnum.BigInt,
|
|
197
|
+
confirmations: FieldTypeEnum.Number,
|
|
198
|
+
...SwapResponseSchema
|
|
199
|
+
} as const;
|
|
200
|
+
|
|
201
|
+
export type FromBTCResponseType = RequestSchemaResult<typeof FromBTCResponseSchema>;
|
|
202
|
+
|
|
203
|
+
export type FromBTCInit = BaseFromBTCSwapInit & {
|
|
204
|
+
sequence: bigint,
|
|
205
|
+
claimerBounty: Promise<{
|
|
206
|
+
feePerBlock: bigint,
|
|
207
|
+
safetyFactor: number,
|
|
208
|
+
startTimestamp: bigint,
|
|
209
|
+
addBlock: number,
|
|
210
|
+
addFee: bigint
|
|
211
|
+
}>
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/////////////////////////
|
|
215
|
+
///// From BTCLN
|
|
216
|
+
|
|
217
|
+
const FromBTCLNResponseSchema = {
|
|
218
|
+
pr: FieldTypeEnum.String,
|
|
219
|
+
swapFee: FieldTypeEnum.BigInt,
|
|
220
|
+
total: FieldTypeEnum.BigInt,
|
|
221
|
+
intermediaryKey: FieldTypeEnum.String,
|
|
222
|
+
securityDeposit: FieldTypeEnum.BigInt
|
|
223
|
+
} as const;
|
|
224
|
+
|
|
225
|
+
export type FromBTCLNResponseType = RequestSchemaResult<typeof FromBTCLNResponseSchema>;
|
|
226
|
+
|
|
227
|
+
export type FromBTCLNInit = BaseFromBTCSwapInit & {
|
|
228
|
+
paymentHash: Buffer,
|
|
229
|
+
descriptionHash?: Buffer
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/////////////////////////
|
|
233
|
+
///// From BTCLN Auto
|
|
234
|
+
|
|
235
|
+
const FromBTCLNAutoResponseSchema = {
|
|
236
|
+
intermediaryKey: FieldTypeEnum.String,
|
|
237
|
+
pr: FieldTypeEnum.String,
|
|
238
|
+
|
|
239
|
+
btcAmountSwap: FieldTypeEnum.BigInt,
|
|
240
|
+
btcAmountGas: FieldTypeEnum.BigInt,
|
|
241
|
+
|
|
242
|
+
total: FieldTypeEnum.BigInt,
|
|
243
|
+
totalGas: FieldTypeEnum.BigInt,
|
|
244
|
+
|
|
245
|
+
totalFeeBtc: FieldTypeEnum.BigInt,
|
|
246
|
+
|
|
247
|
+
swapFeeBtc: FieldTypeEnum.BigInt,
|
|
248
|
+
swapFee: FieldTypeEnum.BigInt,
|
|
249
|
+
|
|
250
|
+
gasSwapFeeBtc: FieldTypeEnum.BigInt,
|
|
251
|
+
gasSwapFee: FieldTypeEnum.BigInt,
|
|
252
|
+
|
|
253
|
+
claimerBounty: FieldTypeEnum.BigInt
|
|
254
|
+
} as const;
|
|
255
|
+
|
|
256
|
+
export type FromBTCLNAutoResponseType = RequestSchemaResult<typeof FromBTCLNAutoResponseSchema>;
|
|
257
|
+
|
|
258
|
+
export type FromBTCLNAutoInit = Omit<BaseFromBTCSwapInit, "feeRate"> & {
|
|
259
|
+
paymentHash: Buffer,
|
|
260
|
+
gasToken: string,
|
|
261
|
+
descriptionHash?: Buffer,
|
|
262
|
+
gasAmount?: bigint,
|
|
263
|
+
claimerBounty?: Promise<bigint>
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/////////////////////////
|
|
267
|
+
///// Spv vault from BTC
|
|
268
|
+
|
|
269
|
+
const SpvFromBTCPrepareResponseSchema = {
|
|
270
|
+
quoteId: FieldTypeEnum.String,
|
|
271
|
+
expiry: FieldTypeEnum.Number,
|
|
272
|
+
|
|
273
|
+
address: FieldTypeEnum.String,
|
|
274
|
+
vaultId: FieldTypeEnum.BigInt,
|
|
275
|
+
|
|
276
|
+
vaultBtcAddress: FieldTypeEnum.String,
|
|
277
|
+
btcAddress: FieldTypeEnum.String,
|
|
278
|
+
btcUtxo: FieldTypeEnum.String,
|
|
279
|
+
btcFeeRate: FieldTypeEnum.Number,
|
|
280
|
+
|
|
281
|
+
btcAmount: FieldTypeEnum.BigInt,
|
|
282
|
+
btcAmountSwap: FieldTypeEnum.BigInt,
|
|
283
|
+
btcAmountGas: FieldTypeEnum.BigInt,
|
|
284
|
+
|
|
285
|
+
total: FieldTypeEnum.BigInt,
|
|
286
|
+
totalGas: FieldTypeEnum.BigInt,
|
|
287
|
+
|
|
288
|
+
totalFeeBtc: FieldTypeEnum.BigInt,
|
|
289
|
+
|
|
290
|
+
swapFeeBtc: FieldTypeEnum.BigInt,
|
|
291
|
+
swapFee: FieldTypeEnum.BigInt,
|
|
292
|
+
|
|
293
|
+
gasSwapFeeBtc: FieldTypeEnum.BigInt,
|
|
294
|
+
gasSwapFee: FieldTypeEnum.BigInt,
|
|
295
|
+
|
|
296
|
+
callerFeeShare: FieldTypeEnum.BigInt,
|
|
297
|
+
frontingFeeShare: FieldTypeEnum.BigInt,
|
|
298
|
+
executionFeeShare: FieldTypeEnum.BigInt
|
|
299
|
+
} as const;
|
|
300
|
+
|
|
301
|
+
export type SpvFromBTCPrepareResponseType = RequestSchemaResult<typeof SpvFromBTCPrepareResponseSchema>;
|
|
302
|
+
|
|
303
|
+
export type SpvFromBTCPrepare = SwapInit & {
|
|
304
|
+
address: string,
|
|
305
|
+
amount: bigint,
|
|
306
|
+
gasAmount: bigint,
|
|
307
|
+
gasToken: string,
|
|
308
|
+
exactOut: boolean,
|
|
309
|
+
callerFeeRate: Promise<bigint>,
|
|
310
|
+
frontingFeeRate: bigint
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
const SpvFromBTCInitResponseSchema = {
|
|
314
|
+
txId: FieldTypeEnum.String
|
|
315
|
+
} as const;
|
|
316
|
+
|
|
317
|
+
export type SpvFromBTCInitResponseType = RequestSchemaResult<typeof SpvFromBTCInitResponseSchema>;
|
|
318
|
+
|
|
319
|
+
export type SpvFromBTCInit = {
|
|
320
|
+
quoteId: string,
|
|
321
|
+
psbtHex: string
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
export class IntermediaryAPI {
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Returns the information about a specific intermediary
|
|
328
|
+
*
|
|
329
|
+
* @param baseUrl Base URL of the intermediary
|
|
330
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
331
|
+
* @param abortSignal
|
|
332
|
+
*
|
|
333
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
334
|
+
* @throws {Error} If the supplied nonce doesn't match the response
|
|
335
|
+
*/
|
|
336
|
+
static async getIntermediaryInfo(
|
|
337
|
+
baseUrl: string,
|
|
338
|
+
timeout?: number,
|
|
339
|
+
abortSignal?: AbortSignal
|
|
340
|
+
): Promise<InfoHandlerResponse> {
|
|
341
|
+
const nonce = randomBytes(32).toString("hex");
|
|
342
|
+
|
|
343
|
+
const abortController = extendAbortController(abortSignal);
|
|
344
|
+
|
|
345
|
+
//We don't know whether the node supports only POST or also has GET info support enabled
|
|
346
|
+
// here we try both, and abort when the first one returns (which should be GET)
|
|
347
|
+
const response = await Promise.any([
|
|
348
|
+
httpGet<InfoHandlerResponse>(baseUrl+"/info?nonce="+nonce, timeout, abortController.signal),
|
|
349
|
+
httpPost<InfoHandlerResponse>(baseUrl+"/info", {
|
|
350
|
+
nonce,
|
|
351
|
+
}, timeout, abortController.signal)
|
|
352
|
+
]);
|
|
353
|
+
abortController.abort();
|
|
354
|
+
|
|
355
|
+
const info = JSON.parse(response.envelope);
|
|
356
|
+
if(nonce!==info.nonce) throw new Error("Invalid response - nonce");
|
|
357
|
+
|
|
358
|
+
return response;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Returns the information about an outcome of the To BTC swap
|
|
363
|
+
*
|
|
364
|
+
* @param url URL of the intermediary
|
|
365
|
+
* @param paymentHash Payment hash of the swap
|
|
366
|
+
* @param sequence Swap's sequence number
|
|
367
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
368
|
+
* @param abortSignal
|
|
369
|
+
*
|
|
370
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
371
|
+
*/
|
|
372
|
+
static async getRefundAuthorization(
|
|
373
|
+
url: string,
|
|
374
|
+
paymentHash: string,
|
|
375
|
+
sequence: bigint,
|
|
376
|
+
timeout?: number,
|
|
377
|
+
abortSignal?: AbortSignal
|
|
378
|
+
): Promise<RefundAuthorizationResponse> {
|
|
379
|
+
return tryWithRetries(() => httpGet<RefundAuthorizationResponse>(
|
|
380
|
+
url + "/getRefundAuthorization"+
|
|
381
|
+
"?paymentHash=" + encodeURIComponent(paymentHash) +
|
|
382
|
+
"&sequence=" + encodeURIComponent(sequence.toString(10)),
|
|
383
|
+
timeout,
|
|
384
|
+
abortSignal
|
|
385
|
+
), undefined, RequestError, abortSignal);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Returns the information about the payment of the From BTCLN swaps
|
|
390
|
+
*
|
|
391
|
+
* @param url URL of the intermediary
|
|
392
|
+
* @param paymentHash Payment hash of the swap
|
|
393
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
394
|
+
* @param abortSignal
|
|
395
|
+
*
|
|
396
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
397
|
+
*/
|
|
398
|
+
static async getPaymentAuthorization(
|
|
399
|
+
url: string,
|
|
400
|
+
paymentHash: string,
|
|
401
|
+
timeout?: number,
|
|
402
|
+
abortSignal?: AbortSignal
|
|
403
|
+
): Promise<PaymentAuthorizationResponse> {
|
|
404
|
+
return tryWithRetries(() => httpGet<PaymentAuthorizationResponse>(
|
|
405
|
+
url+"/getInvoicePaymentAuth"+
|
|
406
|
+
"?paymentHash="+encodeURIComponent(paymentHash),
|
|
407
|
+
timeout,
|
|
408
|
+
abortSignal
|
|
409
|
+
), undefined, RequestError, abortSignal);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Returns the status of the payment of the From BTCLN swaps
|
|
414
|
+
*
|
|
415
|
+
* @param url URL of the intermediary
|
|
416
|
+
* @param paymentHash Payment hash of the swap
|
|
417
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
418
|
+
* @param abortSignal
|
|
419
|
+
*
|
|
420
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
421
|
+
*/
|
|
422
|
+
static async getInvoiceStatus(
|
|
423
|
+
url: string,
|
|
424
|
+
paymentHash: string,
|
|
425
|
+
timeout?: number,
|
|
426
|
+
abortSignal?: AbortSignal
|
|
427
|
+
): Promise<InvoiceStatusResponse> {
|
|
428
|
+
return tryWithRetries(() => httpGet<InvoiceStatusResponse>(
|
|
429
|
+
url+"/getInvoiceStatus"+
|
|
430
|
+
"?paymentHash="+encodeURIComponent(paymentHash),
|
|
431
|
+
timeout,
|
|
432
|
+
abortSignal
|
|
433
|
+
), undefined, RequestError, abortSignal);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Initiate To BTC swap with an intermediary
|
|
438
|
+
*
|
|
439
|
+
* @param chainIdentifier
|
|
440
|
+
* @param baseUrl Base URL of the intermediary
|
|
441
|
+
* @param init Swap initialization parameters
|
|
442
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
443
|
+
* @param abortSignal
|
|
444
|
+
* @param streamRequest Whether to force streaming (or not streaming) the request, default is autodetect
|
|
445
|
+
*
|
|
446
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
447
|
+
*/
|
|
448
|
+
static initToBTC(
|
|
449
|
+
chainIdentifier: string,
|
|
450
|
+
baseUrl: string,
|
|
451
|
+
init: ToBTCInit,
|
|
452
|
+
timeout?: number,
|
|
453
|
+
abortSignal?: AbortSignal,
|
|
454
|
+
streamRequest?: boolean
|
|
455
|
+
): {
|
|
456
|
+
signDataPrefetch: Promise<any>,
|
|
457
|
+
response: Promise<ToBTCResponseType>
|
|
458
|
+
} {
|
|
459
|
+
const responseBodyPromise = streamingFetchPromise(baseUrl+"/tobtc/payInvoice?chain="+encodeURIComponent(chainIdentifier), {
|
|
460
|
+
...init.additionalParams,
|
|
461
|
+
address: init.btcAddress,
|
|
462
|
+
amount: init.amount.toString(10),
|
|
463
|
+
exactIn: init.exactIn,
|
|
464
|
+
confirmationTarget: init.confirmationTarget,
|
|
465
|
+
confirmations: init.confirmations,
|
|
466
|
+
nonce: init.nonce.toString(10),
|
|
467
|
+
token: init.token,
|
|
468
|
+
offerer: init.offerer,
|
|
469
|
+
feeRate: init.feeRate
|
|
470
|
+
}, {
|
|
471
|
+
code: FieldTypeEnum.Number,
|
|
472
|
+
msg: FieldTypeEnum.String,
|
|
473
|
+
data: FieldTypeEnum.AnyOptional,
|
|
474
|
+
signDataPrefetch: FieldTypeEnum.AnyOptional
|
|
475
|
+
}, timeout, abortSignal, streamRequest);
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
signDataPrefetch: responseBodyPromise.then(responseBody => responseBody.signDataPrefetch),
|
|
479
|
+
response: responseBodyPromise.then((responseBody) => Promise.all([
|
|
480
|
+
responseBody.code,
|
|
481
|
+
responseBody.msg,
|
|
482
|
+
responseBody.data,
|
|
483
|
+
])).then(([code, msg, data]) => {
|
|
484
|
+
if(code!==20000) {
|
|
485
|
+
throw RequestError.parse(JSON.stringify({code, msg, data}), 400);
|
|
486
|
+
}
|
|
487
|
+
const result = verifySchema(data, ToBTCResponseSchema);
|
|
488
|
+
if(result==null) throw new RequestError("Cannot parse the response with the expected schema", 200);
|
|
489
|
+
return result;
|
|
490
|
+
})
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Initiate From BTC swap with an intermediary
|
|
496
|
+
*
|
|
497
|
+
* @param chainIdentifier
|
|
498
|
+
* @param baseUrl Base URL of the intermediary
|
|
499
|
+
* @param depositToken
|
|
500
|
+
* @param init Swap initialization parameters
|
|
501
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
502
|
+
* @param abortSignal
|
|
503
|
+
* @param streamRequest Whether to force streaming (or not streaming) the request, default is autodetect
|
|
504
|
+
*
|
|
505
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
506
|
+
*/
|
|
507
|
+
static initFromBTC(
|
|
508
|
+
chainIdentifier: string,
|
|
509
|
+
baseUrl: string,
|
|
510
|
+
depositToken: string,
|
|
511
|
+
init: FromBTCInit,
|
|
512
|
+
timeout?: number,
|
|
513
|
+
abortSignal?: AbortSignal,
|
|
514
|
+
streamRequest?: boolean
|
|
515
|
+
): {
|
|
516
|
+
signDataPrefetch: Promise<any>,
|
|
517
|
+
response: Promise<FromBTCResponseType>
|
|
518
|
+
} {
|
|
519
|
+
const responseBodyPromise = streamingFetchPromise(
|
|
520
|
+
baseUrl+"/frombtc/getAddress?chain="+encodeURIComponent(chainIdentifier)+"&depositToken="+encodeURIComponent(depositToken),
|
|
521
|
+
{
|
|
522
|
+
...init.additionalParams,
|
|
523
|
+
address: init.claimer,
|
|
524
|
+
amount: init.amount.toString(10),
|
|
525
|
+
token: init.token,
|
|
526
|
+
|
|
527
|
+
exactOut: init.exactOut,
|
|
528
|
+
sequence: init.sequence.toString(10),
|
|
529
|
+
|
|
530
|
+
claimerBounty: init.claimerBounty.then(claimerBounty => {
|
|
531
|
+
return {
|
|
532
|
+
feePerBlock: claimerBounty.feePerBlock.toString(10),
|
|
533
|
+
safetyFactor: claimerBounty.safetyFactor,
|
|
534
|
+
startTimestamp: claimerBounty.startTimestamp.toString(10),
|
|
535
|
+
addBlock: claimerBounty.addBlock,
|
|
536
|
+
addFee: claimerBounty.addFee.toString(10)
|
|
537
|
+
}
|
|
538
|
+
}),
|
|
539
|
+
feeRate: init.feeRate
|
|
540
|
+
},
|
|
541
|
+
{
|
|
542
|
+
code: FieldTypeEnum.Number,
|
|
543
|
+
msg: FieldTypeEnum.String,
|
|
544
|
+
data: FieldTypeEnum.AnyOptional,
|
|
545
|
+
signDataPrefetch: FieldTypeEnum.AnyOptional
|
|
546
|
+
},
|
|
547
|
+
timeout, abortSignal, streamRequest
|
|
548
|
+
);
|
|
549
|
+
|
|
550
|
+
return {
|
|
551
|
+
signDataPrefetch: responseBodyPromise.then(responseBody => responseBody.signDataPrefetch),
|
|
552
|
+
response: responseBodyPromise.then((responseBody) => Promise.all([
|
|
553
|
+
responseBody.code,
|
|
554
|
+
responseBody.msg,
|
|
555
|
+
responseBody.data,
|
|
556
|
+
])).then(([code, msg, data]) => {
|
|
557
|
+
if(code!==20000) {
|
|
558
|
+
throw RequestError.parse(JSON.stringify({code, msg, data}), 400);
|
|
559
|
+
}
|
|
560
|
+
const result = verifySchema(data, FromBTCResponseSchema);
|
|
561
|
+
if(result==null) throw new RequestError("Cannot parse the response with the expected schema", 200);
|
|
562
|
+
return result;
|
|
563
|
+
})
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Initiate From BTCLN swap with an intermediary
|
|
569
|
+
*
|
|
570
|
+
* @param chainIdentifier
|
|
571
|
+
* @param baseUrl Base URL of the intermediary
|
|
572
|
+
* @param depositToken
|
|
573
|
+
* @param init Swap initialization parameters
|
|
574
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
575
|
+
* @param abortSignal
|
|
576
|
+
* @param streamRequest Whether to force streaming (or not streaming) the request, default is autodetect
|
|
577
|
+
*
|
|
578
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
579
|
+
*/
|
|
580
|
+
static initFromBTCLN(
|
|
581
|
+
chainIdentifier: string,
|
|
582
|
+
baseUrl: string,
|
|
583
|
+
depositToken: string,
|
|
584
|
+
init: FromBTCLNInit,
|
|
585
|
+
timeout?: number,
|
|
586
|
+
abortSignal?: AbortSignal,
|
|
587
|
+
streamRequest?: boolean
|
|
588
|
+
): {
|
|
589
|
+
lnPublicKey: Promise<string | null>,
|
|
590
|
+
response: Promise<FromBTCLNResponseType>
|
|
591
|
+
} {
|
|
592
|
+
const responseBodyPromise = streamingFetchPromise(
|
|
593
|
+
baseUrl+"/frombtcln/createInvoice?chain="+encodeURIComponent(chainIdentifier)+"&depositToken="+encodeURIComponent(depositToken),
|
|
594
|
+
{
|
|
595
|
+
...init.additionalParams,
|
|
596
|
+
paymentHash: init.paymentHash.toString("hex"),
|
|
597
|
+
amount: init.amount.toString(),
|
|
598
|
+
address: init.claimer,
|
|
599
|
+
token: init.token,
|
|
600
|
+
descriptionHash: init.descriptionHash==null ? null : init.descriptionHash.toString("hex"),
|
|
601
|
+
exactOut: init.exactOut,
|
|
602
|
+
feeRate: init.feeRate
|
|
603
|
+
},
|
|
604
|
+
{
|
|
605
|
+
code: FieldTypeEnum.Number,
|
|
606
|
+
msg: FieldTypeEnum.String,
|
|
607
|
+
data: FieldTypeEnum.AnyOptional,
|
|
608
|
+
lnPublicKey: FieldTypeEnum.StringOptional
|
|
609
|
+
},
|
|
610
|
+
timeout, abortSignal, streamRequest
|
|
611
|
+
);
|
|
612
|
+
|
|
613
|
+
return {
|
|
614
|
+
lnPublicKey: responseBodyPromise.then(responseBody => responseBody.lnPublicKey),
|
|
615
|
+
response: responseBodyPromise.then((responseBody) => Promise.all([
|
|
616
|
+
responseBody.code,
|
|
617
|
+
responseBody.msg,
|
|
618
|
+
responseBody.data,
|
|
619
|
+
])).then(([code, msg, data]) => {
|
|
620
|
+
if(code!==20000) {
|
|
621
|
+
throw RequestError.parse(JSON.stringify({code, msg, data}), 400);
|
|
622
|
+
}
|
|
623
|
+
const result = verifySchema(data, FromBTCLNResponseSchema);
|
|
624
|
+
if(result==null) throw new RequestError("Cannot parse the response with the expected schema", 200);
|
|
625
|
+
return result;
|
|
626
|
+
})
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/**
|
|
631
|
+
* Initiate From BTCLN swap with auto-initilization by an intermediary
|
|
632
|
+
*
|
|
633
|
+
* @param chainIdentifier
|
|
634
|
+
* @param baseUrl Base URL of the intermediary
|
|
635
|
+
* @param init Swap initialization parameters
|
|
636
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
637
|
+
* @param abortSignal
|
|
638
|
+
* @param streamRequest Whether to force streaming (or not streaming) the request, default is autodetect
|
|
639
|
+
*
|
|
640
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
641
|
+
*/
|
|
642
|
+
static initFromBTCLNAuto(
|
|
643
|
+
chainIdentifier: string,
|
|
644
|
+
baseUrl: string,
|
|
645
|
+
init: FromBTCLNAutoInit,
|
|
646
|
+
timeout?: number,
|
|
647
|
+
abortSignal?: AbortSignal,
|
|
648
|
+
streamRequest?: boolean
|
|
649
|
+
): {
|
|
650
|
+
lnPublicKey: Promise<string | null>,
|
|
651
|
+
response: Promise<FromBTCLNAutoResponseType>
|
|
652
|
+
} {
|
|
653
|
+
const responseBodyPromise = streamingFetchPromise(
|
|
654
|
+
baseUrl+"/frombtcln_auto/createInvoice?chain="+encodeURIComponent(chainIdentifier),
|
|
655
|
+
{
|
|
656
|
+
...init.additionalParams,
|
|
657
|
+
paymentHash: init.paymentHash.toString("hex"),
|
|
658
|
+
amount: init.amount.toString(),
|
|
659
|
+
address: init.claimer,
|
|
660
|
+
token: init.token,
|
|
661
|
+
descriptionHash: init.descriptionHash==null ? null : init.descriptionHash.toString("hex"),
|
|
662
|
+
exactOut: init.exactOut,
|
|
663
|
+
gasToken: init.gasToken,
|
|
664
|
+
gasAmount: init.gasAmount?.toString(10) ?? "0",
|
|
665
|
+
claimerBounty: init.claimerBounty?.then(val => val.toString(10)) ?? "0"
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
code: FieldTypeEnum.Number,
|
|
669
|
+
msg: FieldTypeEnum.String,
|
|
670
|
+
data: FieldTypeEnum.AnyOptional,
|
|
671
|
+
lnPublicKey: FieldTypeEnum.StringOptional
|
|
672
|
+
},
|
|
673
|
+
timeout, abortSignal, streamRequest
|
|
674
|
+
);
|
|
675
|
+
|
|
676
|
+
return {
|
|
677
|
+
lnPublicKey: responseBodyPromise.then(responseBody => responseBody.lnPublicKey),
|
|
678
|
+
response: responseBodyPromise.then((responseBody) => Promise.all([
|
|
679
|
+
responseBody.code,
|
|
680
|
+
responseBody.msg,
|
|
681
|
+
responseBody.data,
|
|
682
|
+
])).then(([code, msg, data]) => {
|
|
683
|
+
if(code!==20000) {
|
|
684
|
+
throw RequestError.parse(JSON.stringify({code, msg, data}), 400);
|
|
685
|
+
}
|
|
686
|
+
const result = verifySchema(data, FromBTCLNAutoResponseSchema);
|
|
687
|
+
if(result==null) throw new RequestError("Cannot parse the response with the expected schema", 200);
|
|
688
|
+
return result;
|
|
689
|
+
})
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Initiate To BTCLN swap with an intermediary
|
|
695
|
+
*
|
|
696
|
+
* @param chainIdentifier
|
|
697
|
+
* @param baseUrl Base URL of the intermediary
|
|
698
|
+
* @param init Swap initialization parameters
|
|
699
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
700
|
+
* @param abortSignal
|
|
701
|
+
* @param streamRequest Whether to force streaming (or not streaming) the request, default is autodetect
|
|
702
|
+
*
|
|
703
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
704
|
+
*/
|
|
705
|
+
static initToBTCLN(
|
|
706
|
+
chainIdentifier: string,
|
|
707
|
+
baseUrl: string,
|
|
708
|
+
init: ToBTCLNInit,
|
|
709
|
+
timeout?: number,
|
|
710
|
+
abortSignal?: AbortSignal,
|
|
711
|
+
streamRequest?: boolean
|
|
712
|
+
): {
|
|
713
|
+
signDataPrefetch: Promise<any>,
|
|
714
|
+
response: Promise<ToBTCLNResponseType>
|
|
715
|
+
} {
|
|
716
|
+
const responseBodyPromise = streamingFetchPromise(baseUrl+"/tobtcln/payInvoice?chain="+encodeURIComponent(chainIdentifier), {
|
|
717
|
+
exactIn: false,
|
|
718
|
+
...init.additionalParams,
|
|
719
|
+
pr: init.pr,
|
|
720
|
+
maxFee: init.maxFee.toString(10),
|
|
721
|
+
expiryTimestamp: init.expiryTimestamp.toString(10),
|
|
722
|
+
token: init.token,
|
|
723
|
+
offerer: init.offerer,
|
|
724
|
+
feeRate: init.feeRate,
|
|
725
|
+
amount: null
|
|
726
|
+
}, {
|
|
727
|
+
code: FieldTypeEnum.Number,
|
|
728
|
+
msg: FieldTypeEnum.String,
|
|
729
|
+
data: FieldTypeEnum.AnyOptional,
|
|
730
|
+
signDataPrefetch: FieldTypeEnum.AnyOptional
|
|
731
|
+
}, timeout, abortSignal, streamRequest);
|
|
732
|
+
|
|
733
|
+
return {
|
|
734
|
+
signDataPrefetch: responseBodyPromise.then(responseBody => responseBody.signDataPrefetch),
|
|
735
|
+
response: responseBodyPromise.then((responseBody) => Promise.all([
|
|
736
|
+
responseBody.code,
|
|
737
|
+
responseBody.msg,
|
|
738
|
+
responseBody.data,
|
|
739
|
+
])).then(([code, msg, data]) => {
|
|
740
|
+
if(code!==20000) {
|
|
741
|
+
throw RequestError.parse(JSON.stringify({code, msg, data}), 400);
|
|
742
|
+
}
|
|
743
|
+
const result = verifySchema(data, ToBTCLNResponseSchema);
|
|
744
|
+
if(result==null) throw new RequestError("Cannot parse the response with the expected schema", 200);
|
|
745
|
+
return result;
|
|
746
|
+
})
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* Initiate To BTCLN exact in swap with an intermediary
|
|
752
|
+
*
|
|
753
|
+
* @param baseUrl Base URL of the intermediary
|
|
754
|
+
* @param init Swap initialization parameters
|
|
755
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
756
|
+
* @param abortSignal
|
|
757
|
+
* @param streamRequest Whether to force streaming (or not streaming) the request, default is autodetect
|
|
758
|
+
*
|
|
759
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
760
|
+
*/
|
|
761
|
+
static async initToBTCLNExactIn(
|
|
762
|
+
baseUrl: string,
|
|
763
|
+
init: ToBTCLNInitExactIn,
|
|
764
|
+
timeout?: number,
|
|
765
|
+
abortSignal?: AbortSignal,
|
|
766
|
+
streamRequest?: boolean
|
|
767
|
+
): Promise<ToBTCLNResponseType> {
|
|
768
|
+
const responseBody = await streamingFetchPromise(baseUrl+"/tobtcln/payInvoiceExactIn", {
|
|
769
|
+
...init.additionalParams,
|
|
770
|
+
pr: init.pr,
|
|
771
|
+
reqId: init.reqId,
|
|
772
|
+
feeRate: init.feeRate
|
|
773
|
+
}, {
|
|
774
|
+
code: FieldTypeEnum.Number,
|
|
775
|
+
msg: FieldTypeEnum.String,
|
|
776
|
+
data: FieldTypeEnum.AnyOptional
|
|
777
|
+
}, timeout, abortSignal, streamRequest);
|
|
778
|
+
|
|
779
|
+
const [code, msg, data] = await Promise.all([
|
|
780
|
+
responseBody.code,
|
|
781
|
+
responseBody.msg,
|
|
782
|
+
responseBody.data,
|
|
783
|
+
])
|
|
784
|
+
|
|
785
|
+
if(code!==20000) throw RequestError.parse(JSON.stringify({code, msg, data}), 400);
|
|
786
|
+
const result = verifySchema(data, ToBTCLNResponseSchema);
|
|
787
|
+
if(result==null) throw new RequestError("Cannot parse the response with the expected schema", 200);
|
|
788
|
+
return result;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Prepare To BTCLN exact in swap with an intermediary
|
|
793
|
+
*
|
|
794
|
+
* @param chainIdentifier
|
|
795
|
+
* @param baseUrl Base URL of the intermediary
|
|
796
|
+
* @param init Swap initialization parameters
|
|
797
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
798
|
+
* @param abortSignal
|
|
799
|
+
* @param streamRequest Whether to force streaming (or not streaming) the request, default is autodetect
|
|
800
|
+
*
|
|
801
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
802
|
+
*/
|
|
803
|
+
static prepareToBTCLNExactIn(
|
|
804
|
+
chainIdentifier: string,
|
|
805
|
+
baseUrl: string,
|
|
806
|
+
init: ToBTCLNPrepareExactIn,
|
|
807
|
+
timeout?: number,
|
|
808
|
+
abortSignal?: AbortSignal,
|
|
809
|
+
streamRequest?: boolean
|
|
810
|
+
): {
|
|
811
|
+
signDataPrefetch: Promise<any>,
|
|
812
|
+
response: Promise<ToBTCLNPrepareExactInResponseType>
|
|
813
|
+
} {
|
|
814
|
+
const responseBodyPromise = streamingFetchPromise(baseUrl+"/tobtcln/payInvoice?chain="+encodeURIComponent(chainIdentifier), {
|
|
815
|
+
exactIn: true,
|
|
816
|
+
...init.additionalParams,
|
|
817
|
+
pr: init.pr,
|
|
818
|
+
maxFee: init.maxFee.toString(10),
|
|
819
|
+
expiryTimestamp: init.expiryTimestamp.toString(10),
|
|
820
|
+
token: init.token,
|
|
821
|
+
offerer: init.offerer,
|
|
822
|
+
amount: init.amount.toString(10)
|
|
823
|
+
}, {
|
|
824
|
+
code: FieldTypeEnum.Number,
|
|
825
|
+
msg: FieldTypeEnum.String,
|
|
826
|
+
data: FieldTypeEnum.AnyOptional,
|
|
827
|
+
signDataPrefetch: FieldTypeEnum.AnyOptional
|
|
828
|
+
}, timeout, abortSignal, streamRequest);
|
|
829
|
+
|
|
830
|
+
return {
|
|
831
|
+
signDataPrefetch: responseBodyPromise.then(responseBody => responseBody.signDataPrefetch),
|
|
832
|
+
response: responseBodyPromise.then((responseBody) => Promise.all([
|
|
833
|
+
responseBody.code,
|
|
834
|
+
responseBody.msg,
|
|
835
|
+
responseBody.data,
|
|
836
|
+
])).then(([code, msg, data]) => {
|
|
837
|
+
if(code!==20000) {
|
|
838
|
+
throw RequestError.parse(JSON.stringify({code, msg, data}), 400);
|
|
839
|
+
}
|
|
840
|
+
const result = verifySchema(data, ToBTCLNPrepareExactInSchema);
|
|
841
|
+
if(result==null) throw new RequestError("Cannot parse the response with the expected schema", 200);
|
|
842
|
+
return result;
|
|
843
|
+
})
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Prepare From BTC swap via new spv vault swaps with an intermediary
|
|
849
|
+
*
|
|
850
|
+
* @param chainIdentifier
|
|
851
|
+
* @param baseUrl Base URL of the intermediary
|
|
852
|
+
* @param init Swap initialization parameters
|
|
853
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
854
|
+
* @param abortSignal
|
|
855
|
+
* @param streamRequest Whether to force streaming (or not streaming) the request, default is autodetect
|
|
856
|
+
*
|
|
857
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
858
|
+
*/
|
|
859
|
+
static prepareSpvFromBTC(
|
|
860
|
+
chainIdentifier: string,
|
|
861
|
+
baseUrl: string,
|
|
862
|
+
init: SpvFromBTCPrepare,
|
|
863
|
+
timeout?: number,
|
|
864
|
+
abortSignal?: AbortSignal,
|
|
865
|
+
streamRequest?: boolean
|
|
866
|
+
): Promise<SpvFromBTCPrepareResponseType> {
|
|
867
|
+
const responseBodyPromise = streamingFetchPromise(baseUrl+"/frombtc_spv/getQuote?chain="+encodeURIComponent(chainIdentifier), {
|
|
868
|
+
exactOut: init.exactOut,
|
|
869
|
+
...init.additionalParams,
|
|
870
|
+
address: init.address,
|
|
871
|
+
amount: init.amount.toString(10),
|
|
872
|
+
token: init.token,
|
|
873
|
+
gasAmount: init.gasAmount.toString(10),
|
|
874
|
+
gasToken: init.gasToken,
|
|
875
|
+
frontingFeeRate: init.frontingFeeRate.toString(10),
|
|
876
|
+
callerFeeRate: init.callerFeeRate.then(val => val.toString(10))
|
|
877
|
+
}, {
|
|
878
|
+
code: FieldTypeEnum.Number,
|
|
879
|
+
msg: FieldTypeEnum.String,
|
|
880
|
+
data: FieldTypeEnum.AnyOptional
|
|
881
|
+
}, timeout, abortSignal, streamRequest);
|
|
882
|
+
|
|
883
|
+
return responseBodyPromise.then((responseBody) => Promise.all([
|
|
884
|
+
responseBody.code,
|
|
885
|
+
responseBody.msg,
|
|
886
|
+
responseBody.data,
|
|
887
|
+
])).then(([code, msg, data]) => {
|
|
888
|
+
if(code!==20000) {
|
|
889
|
+
throw RequestError.parse(JSON.stringify({code, msg, data}), 400);
|
|
890
|
+
}
|
|
891
|
+
const result = verifySchema(data, SpvFromBTCPrepareResponseSchema);
|
|
892
|
+
if(result==null) throw new RequestError("Cannot parse the response with the expected schema", 200);
|
|
893
|
+
return result;
|
|
894
|
+
});
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* Prepare From BTC swap via new spv vault swaps with an intermediary
|
|
899
|
+
*
|
|
900
|
+
* @param chainIdentifier
|
|
901
|
+
* @param url
|
|
902
|
+
* @param init Swap initialization parameters
|
|
903
|
+
* @param timeout Timeout in milliseconds for the HTTP request
|
|
904
|
+
* @param abortSignal
|
|
905
|
+
* @param streamRequest Whether to force streaming (or not streaming) the request, default is autodetect
|
|
906
|
+
*
|
|
907
|
+
* @throws {RequestError} If non-200 http response code is returned
|
|
908
|
+
*/
|
|
909
|
+
static initSpvFromBTC(
|
|
910
|
+
chainIdentifier: string,
|
|
911
|
+
url: string,
|
|
912
|
+
init: SpvFromBTCInit,
|
|
913
|
+
timeout?: number,
|
|
914
|
+
abortSignal?: AbortSignal,
|
|
915
|
+
streamRequest?: boolean
|
|
916
|
+
): Promise<SpvFromBTCInitResponseType> {
|
|
917
|
+
const responseBodyPromise = streamingFetchPromise(url+"/postQuote?chain="+encodeURIComponent(chainIdentifier), {
|
|
918
|
+
quoteId: init.quoteId,
|
|
919
|
+
psbtHex: init.psbtHex
|
|
920
|
+
}, {
|
|
921
|
+
code: FieldTypeEnum.Number,
|
|
922
|
+
msg: FieldTypeEnum.String,
|
|
923
|
+
data: FieldTypeEnum.AnyOptional
|
|
924
|
+
}, timeout, abortSignal, streamRequest);
|
|
925
|
+
|
|
926
|
+
return responseBodyPromise.then((responseBody) => Promise.all([
|
|
927
|
+
responseBody.code,
|
|
928
|
+
responseBody.msg,
|
|
929
|
+
responseBody.data,
|
|
930
|
+
])).then(([code, msg, data]) => {
|
|
931
|
+
if(code!==20000) {
|
|
932
|
+
throw RequestError.parse(JSON.stringify({code, msg, data}), 400);
|
|
933
|
+
}
|
|
934
|
+
const result = verifySchema(data, SpvFromBTCInitResponseSchema);
|
|
935
|
+
if(result==null) throw new RequestError("Cannot parse the response with the expected schema", 200);
|
|
936
|
+
return result;
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
}
|