@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,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LNURL-pay request parameters
|
|
3
|
+
* @category Bitcoin
|
|
4
|
+
*/
|
|
5
|
+
export type LNURLPayParams = {
|
|
6
|
+
tag: "payRequest";
|
|
7
|
+
callback: string;
|
|
8
|
+
domain: string;
|
|
9
|
+
minSendable: number;
|
|
10
|
+
maxSendable: number;
|
|
11
|
+
metadata: string;
|
|
12
|
+
decodedMetadata: string[][];
|
|
13
|
+
commentAllowed: number;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* LNURL-pay parameters with URL
|
|
17
|
+
* @category Bitcoin
|
|
18
|
+
*/
|
|
19
|
+
export type LNURLPayParamsWithUrl = LNURLPayParams & {
|
|
20
|
+
url: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* LNURL-pay specification
|
|
24
|
+
* @category Bitcoin
|
|
25
|
+
*/
|
|
26
|
+
export type LNURLPay = {
|
|
27
|
+
type: "pay";
|
|
28
|
+
min: bigint;
|
|
29
|
+
max: bigint;
|
|
30
|
+
commentMaxLength: number;
|
|
31
|
+
shortDescription?: string;
|
|
32
|
+
longDescription?: string;
|
|
33
|
+
icon?: string;
|
|
34
|
+
params: LNURLPayParamsWithUrl;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Type guard for LNURL-pay parameters
|
|
38
|
+
* @category Bitcoin
|
|
39
|
+
*/
|
|
40
|
+
export declare function isLNURLPayParams(obj: any): obj is LNURLPayParams;
|
|
41
|
+
/**
|
|
42
|
+
* Type guard for LNURL-pay
|
|
43
|
+
* @category Bitcoin
|
|
44
|
+
*/
|
|
45
|
+
export declare function isLNURLPay(value: any): value is LNURLPay;
|
|
46
|
+
/**
|
|
47
|
+
* Decoded LNURL-pay success action
|
|
48
|
+
* @category Bitcoin
|
|
49
|
+
*/
|
|
50
|
+
export type LNURLDecodedSuccessAction = {
|
|
51
|
+
description: string;
|
|
52
|
+
text?: string;
|
|
53
|
+
url?: string;
|
|
54
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLNURLPay = exports.isLNURLPayParams = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Type guard for LNURL-pay parameters
|
|
6
|
+
* @category Bitcoin
|
|
7
|
+
*/
|
|
8
|
+
function isLNURLPayParams(obj) {
|
|
9
|
+
return obj.tag === "payRequest";
|
|
10
|
+
}
|
|
11
|
+
exports.isLNURLPayParams = isLNURLPayParams;
|
|
12
|
+
/**
|
|
13
|
+
* Type guard for LNURL-pay
|
|
14
|
+
* @category Bitcoin
|
|
15
|
+
*/
|
|
16
|
+
function isLNURLPay(value) {
|
|
17
|
+
return (typeof value === "object" &&
|
|
18
|
+
value != null &&
|
|
19
|
+
value.type === "pay" &&
|
|
20
|
+
typeof (value.min) === "bigint" &&
|
|
21
|
+
typeof (value.max) === "bigint" &&
|
|
22
|
+
typeof value.commentMaxLength === "number" &&
|
|
23
|
+
(value.shortDescription === undefined || typeof value.shortDescription === "string") &&
|
|
24
|
+
(value.longDescription === undefined || typeof value.longDescription === "string") &&
|
|
25
|
+
(value.icon === undefined || typeof value.icon === "string") &&
|
|
26
|
+
isLNURLPayParams(value.params));
|
|
27
|
+
}
|
|
28
|
+
exports.isLNURLPay = isLNURLPay;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LNURL-withdraw request parameters
|
|
3
|
+
* @category Bitcoin
|
|
4
|
+
*/
|
|
5
|
+
export type LNURLWithdrawParams = {
|
|
6
|
+
tag: "withdrawRequest";
|
|
7
|
+
k1: string;
|
|
8
|
+
callback: string;
|
|
9
|
+
domain: string;
|
|
10
|
+
minWithdrawable: number;
|
|
11
|
+
maxWithdrawable: number;
|
|
12
|
+
defaultDescription: string;
|
|
13
|
+
balanceCheck?: string;
|
|
14
|
+
payLink?: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* LNURL-withdraw parameters with URL
|
|
18
|
+
* @category Bitcoin
|
|
19
|
+
*/
|
|
20
|
+
export type LNURLWithdrawParamsWithUrl = LNURLWithdrawParams & {
|
|
21
|
+
url: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* LNURL-withdraw specification
|
|
25
|
+
* @category Bitcoin
|
|
26
|
+
*/
|
|
27
|
+
export type LNURLWithdraw = {
|
|
28
|
+
type: "withdraw";
|
|
29
|
+
min: bigint;
|
|
30
|
+
max: bigint;
|
|
31
|
+
params: LNURLWithdrawParamsWithUrl;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Type guard for LNURL-withdraw
|
|
35
|
+
* @category Bitcoin
|
|
36
|
+
*/
|
|
37
|
+
export declare function isLNURLWithdraw(value: any): value is LNURLWithdraw;
|
|
38
|
+
/**
|
|
39
|
+
* Type guard for LNURL-withdraw parameters
|
|
40
|
+
* @category Bitcoin
|
|
41
|
+
*/
|
|
42
|
+
export declare function isLNURLWithdrawParams(obj: any): obj is LNURLWithdrawParams;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isLNURLWithdrawParams = exports.isLNURLWithdraw = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Type guard for LNURL-withdraw
|
|
6
|
+
* @category Bitcoin
|
|
7
|
+
*/
|
|
8
|
+
function isLNURLWithdraw(value) {
|
|
9
|
+
return (typeof value === "object" &&
|
|
10
|
+
value != null &&
|
|
11
|
+
value.type === "withdraw" &&
|
|
12
|
+
typeof (value.min) === "bigint" &&
|
|
13
|
+
typeof (value.max) === "bigint" &&
|
|
14
|
+
isLNURLWithdrawParams(value.params));
|
|
15
|
+
}
|
|
16
|
+
exports.isLNURLWithdraw = isLNURLWithdraw;
|
|
17
|
+
/**
|
|
18
|
+
* Type guard for LNURL-withdraw parameters
|
|
19
|
+
* @category Bitcoin
|
|
20
|
+
*/
|
|
21
|
+
function isLNURLWithdrawParams(obj) {
|
|
22
|
+
return obj.tag === "withdrawRequest";
|
|
23
|
+
}
|
|
24
|
+
exports.isLNURLWithdrawParams = isLNURLWithdrawParams;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function correctClock(): Promise<void>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.correctClock = void 0;
|
|
4
|
+
const TimeoutUtils_1 = require("./TimeoutUtils");
|
|
5
|
+
const headerUrls = ["https://api.atomiq.exchange/"];
|
|
6
|
+
async function getHeaderTimestamp(url) {
|
|
7
|
+
const timeStart = performance.now();
|
|
8
|
+
const resp = await fetch(url, { method: "HEAD", signal: (0, TimeoutUtils_1.timeoutSignal)(3000) });
|
|
9
|
+
const timeDelta = performance.now() - timeStart;
|
|
10
|
+
const dateHeaderValue = resp.headers.get("Date");
|
|
11
|
+
if (dateHeaderValue == null)
|
|
12
|
+
throw new Error("Date header not returned!");
|
|
13
|
+
return { delta: timeDelta, timestamp: new Date(dateHeaderValue).getTime() };
|
|
14
|
+
}
|
|
15
|
+
async function getBinanceTimestamp() {
|
|
16
|
+
const timeStart = performance.now();
|
|
17
|
+
const resp = await fetch("https://api.binance.com/api/v3/time", { signal: (0, TimeoutUtils_1.timeoutSignal)(3000) });
|
|
18
|
+
const timeDelta = performance.now() - timeStart;
|
|
19
|
+
const obj = await resp.json();
|
|
20
|
+
if (obj == null || obj.serverTime == null)
|
|
21
|
+
throw new Error("Timestamp not returned!");
|
|
22
|
+
return { delta: timeDelta, timestamp: Math.floor(obj.serverTime) };
|
|
23
|
+
}
|
|
24
|
+
async function getOKXTimestamp() {
|
|
25
|
+
const timeStart = performance.now();
|
|
26
|
+
const resp = await fetch("https://www.okx.com/api/v5/public/time", { signal: (0, TimeoutUtils_1.timeoutSignal)(3000) });
|
|
27
|
+
const timeDelta = performance.now() - timeStart;
|
|
28
|
+
const obj = await resp.json();
|
|
29
|
+
if (obj == null || obj.data == null || obj.data[0] == null || obj.data[0].ts == null)
|
|
30
|
+
throw new Error("Timestamp not returned!");
|
|
31
|
+
return { delta: timeDelta, timestamp: Math.floor(obj.data[0].ts) };
|
|
32
|
+
}
|
|
33
|
+
async function getAisenseApiTimestamp() {
|
|
34
|
+
const timeStart = performance.now();
|
|
35
|
+
const resp = await fetch("https://aisenseapi.com/services/v1/timestamp", { signal: (0, TimeoutUtils_1.timeoutSignal)(3000) });
|
|
36
|
+
const timeDelta = performance.now() - timeStart;
|
|
37
|
+
const obj = await resp.json();
|
|
38
|
+
if (obj == null || obj.timestamp == null)
|
|
39
|
+
throw new Error("Timestamp not returned!");
|
|
40
|
+
return { delta: timeDelta, timestamp: Math.floor(obj.timestamp * 1000) };
|
|
41
|
+
}
|
|
42
|
+
async function correctClock() {
|
|
43
|
+
const dateNow = Date._now ?? Date.now;
|
|
44
|
+
const dateStart = performance.now();
|
|
45
|
+
try {
|
|
46
|
+
let result = await Promise.any([
|
|
47
|
+
...headerUrls.map(url => getHeaderTimestamp(url)),
|
|
48
|
+
getAisenseApiTimestamp(),
|
|
49
|
+
getBinanceTimestamp(),
|
|
50
|
+
getOKXTimestamp()
|
|
51
|
+
]);
|
|
52
|
+
const desiredTime = result.timestamp - (result.delta / 2);
|
|
53
|
+
if (Math.abs(Date.now() - desiredTime) < 2000) {
|
|
54
|
+
console.log("AutomaticClockDriftCorrection: correctClock(): Time drift too small, not adjusting!");
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const timeDrift = dateStart - desiredTime;
|
|
58
|
+
console.log(`AutomaticClockDriftCorrection: correctClock(): Time correction perf.now: ${dateStart}, server: ${desiredTime}, time diff: ${timeDrift}`);
|
|
59
|
+
Date._now = dateNow;
|
|
60
|
+
Date.now = () => {
|
|
61
|
+
return Math.floor(performance.now() - timeDrift);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
if (e instanceof AggregateError)
|
|
66
|
+
e.message = "Cannot sync time! All servers responded negatively!";
|
|
67
|
+
throw e;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.correctClock = correctClock;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { BTC_NETWORK } from "@scure/btc-signer/utils";
|
|
4
|
+
import { Buffer } from "buffer";
|
|
5
|
+
import { Transaction } from "@scure/btc-signer";
|
|
6
|
+
import { CoinselectAddressTypes } from "../bitcoin/coinselect2";
|
|
7
|
+
export declare function toOutputScript(network: BTC_NETWORK, address: string): Buffer;
|
|
8
|
+
export declare function toCoinselectAddressType(outputScript: Uint8Array): CoinselectAddressTypes;
|
|
9
|
+
/**
|
|
10
|
+
* General parsers for PSBTs, can parse hex or base64 encoded PSBTs
|
|
11
|
+
* @param _psbt
|
|
12
|
+
*/
|
|
13
|
+
export declare function parsePsbtTransaction(_psbt: Transaction | string): Transaction;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parsePsbtTransaction = exports.toCoinselectAddressType = exports.toOutputScript = void 0;
|
|
4
|
+
const utils_1 = require("@scure/btc-signer/utils");
|
|
5
|
+
const buffer_1 = require("buffer");
|
|
6
|
+
const btc_signer_1 = require("@scure/btc-signer");
|
|
7
|
+
function toOutputScript(network, address) {
|
|
8
|
+
const outputScript = (0, btc_signer_1.Address)(network).decode(address);
|
|
9
|
+
switch (outputScript.type) {
|
|
10
|
+
case "pkh":
|
|
11
|
+
case "sh":
|
|
12
|
+
case "wpkh":
|
|
13
|
+
case "wsh":
|
|
14
|
+
return buffer_1.Buffer.from(btc_signer_1.OutScript.encode({
|
|
15
|
+
type: outputScript.type,
|
|
16
|
+
hash: outputScript.hash
|
|
17
|
+
}));
|
|
18
|
+
case "tr":
|
|
19
|
+
try {
|
|
20
|
+
return buffer_1.Buffer.from(btc_signer_1.OutScript.encode({
|
|
21
|
+
type: "tr",
|
|
22
|
+
pubkey: outputScript.pubkey
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
let msg = "";
|
|
27
|
+
if (e.name != null)
|
|
28
|
+
msg += ": " + e.name;
|
|
29
|
+
if (e.message != null)
|
|
30
|
+
msg += ": " + e.message;
|
|
31
|
+
if (typeof (e) === "string")
|
|
32
|
+
msg += ": " + e;
|
|
33
|
+
msg += ", isBytes: " + (0, utils_1.isBytes)(outputScript.pubkey);
|
|
34
|
+
try {
|
|
35
|
+
(0, utils_1.validatePubkey)(outputScript.pubkey, utils_1.PubT.schnorr);
|
|
36
|
+
msg += ", validatePubkey: success";
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
msg += ", validatePubkeyError: ";
|
|
40
|
+
if (e.name != null)
|
|
41
|
+
msg += ": " + e.name;
|
|
42
|
+
if (e.message != null)
|
|
43
|
+
msg += ": " + e.message;
|
|
44
|
+
if (typeof (e) === "string")
|
|
45
|
+
msg += ": " + e;
|
|
46
|
+
}
|
|
47
|
+
throw new Error(msg);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
throw new Error(`Unrecognized output script type: ${outputScript.type}`);
|
|
51
|
+
}
|
|
52
|
+
exports.toOutputScript = toOutputScript;
|
|
53
|
+
function toCoinselectAddressType(outputScript) {
|
|
54
|
+
const data = btc_signer_1.OutScript.decode(outputScript);
|
|
55
|
+
switch (data.type) {
|
|
56
|
+
case "pkh":
|
|
57
|
+
return "p2pkh";
|
|
58
|
+
case "sh":
|
|
59
|
+
return "p2sh-p2wpkh";
|
|
60
|
+
case "wpkh":
|
|
61
|
+
return "p2wpkh";
|
|
62
|
+
case "wsh":
|
|
63
|
+
return "p2wsh";
|
|
64
|
+
case "tr":
|
|
65
|
+
return "p2tr";
|
|
66
|
+
}
|
|
67
|
+
throw new Error("Unrecognized address type!");
|
|
68
|
+
}
|
|
69
|
+
exports.toCoinselectAddressType = toCoinselectAddressType;
|
|
70
|
+
/**
|
|
71
|
+
* General parsers for PSBTs, can parse hex or base64 encoded PSBTs
|
|
72
|
+
* @param _psbt
|
|
73
|
+
*/
|
|
74
|
+
function parsePsbtTransaction(_psbt) {
|
|
75
|
+
if (typeof (_psbt) === "string") {
|
|
76
|
+
let rawPsbt;
|
|
77
|
+
if (/^(?:[0-9a-fA-F]{2})+$/.test(_psbt)) {
|
|
78
|
+
//Hex
|
|
79
|
+
rawPsbt = buffer_1.Buffer.from(_psbt, "hex");
|
|
80
|
+
}
|
|
81
|
+
else if (/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(_psbt)) {
|
|
82
|
+
//Base64
|
|
83
|
+
rawPsbt = buffer_1.Buffer.from(_psbt, "base64");
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
throw new Error("Provided psbt string not base64 nor hex encoded!");
|
|
87
|
+
}
|
|
88
|
+
return btc_signer_1.Transaction.fromPSBT(rawPsbt, {
|
|
89
|
+
allowUnknownOutputs: true,
|
|
90
|
+
allowUnknownInputs: true,
|
|
91
|
+
allowLegacyWitnessUtxo: true,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return _psbt;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
exports.parsePsbtTransaction = parsePsbtTransaction;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { IBitcoinWallet } from "../bitcoin/wallet/IBitcoinWallet";
|
|
2
|
+
import { BitcoinRpcWithAddressIndex } from "../bitcoin/BitcoinRpcWithAddressIndex";
|
|
3
|
+
import { BTC_NETWORK } from "@scure/btc-signer/utils";
|
|
4
|
+
export declare function toBitcoinWallet(_bitcoinWallet: IBitcoinWallet | {
|
|
5
|
+
address: string;
|
|
6
|
+
publicKey: string;
|
|
7
|
+
}, btcRpc: BitcoinRpcWithAddressIndex<any>, bitcoinNetwork: BTC_NETWORK): IBitcoinWallet;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toBitcoinWallet = void 0;
|
|
4
|
+
const IBitcoinWallet_1 = require("../bitcoin/wallet/IBitcoinWallet");
|
|
5
|
+
const SingleAddressBitcoinWallet_1 = require("../bitcoin/wallet/SingleAddressBitcoinWallet");
|
|
6
|
+
function toBitcoinWallet(_bitcoinWallet, btcRpc, bitcoinNetwork) {
|
|
7
|
+
if ((0, IBitcoinWallet_1.isIBitcoinWallet)(_bitcoinWallet)) {
|
|
8
|
+
return _bitcoinWallet;
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return new SingleAddressBitcoinWallet_1.SingleAddressBitcoinWallet(btcRpc, bitcoinNetwork, _bitcoinWallet);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.toBitcoinWallet = toBitcoinWallet;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type LoggerType = {
|
|
2
|
+
debug: (msg: string, ...args: any[]) => void;
|
|
3
|
+
info: (msg: string, ...args: any[]) => void;
|
|
4
|
+
warn: (msg: string, ...args: any[]) => void;
|
|
5
|
+
error: (msg: string, ...args: any[]) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare function getLogger(prefix: string): LoggerType;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLogger = void 0;
|
|
4
|
+
function getLogger(prefix) {
|
|
5
|
+
return {
|
|
6
|
+
debug: (msg, ...args) => global.atomiqLogLevel >= 3 && console.debug(prefix + msg, ...args),
|
|
7
|
+
info: (msg, ...args) => global.atomiqLogLevel >= 2 && console.info(prefix + msg, ...args),
|
|
8
|
+
warn: (msg, ...args) => (global.atomiqLogLevel == null || global.atomiqLogLevel >= 1) && console.warn(prefix + msg, ...args),
|
|
9
|
+
error: (msg, ...args) => (global.atomiqLogLevel == null || global.atomiqLogLevel >= 0) && console.error(prefix + msg, ...args)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
exports.getLogger = getLogger;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type Constructor<T = any> = new (...args: any[]) => T;
|
|
2
|
+
/**
|
|
3
|
+
* Runs the passed function multiple times if it fails
|
|
4
|
+
*
|
|
5
|
+
* @param func A callback for executing the action
|
|
6
|
+
* @param func.retryCount Count of the current retry, starting from 0 for original request and increasing
|
|
7
|
+
* @param retryPolicy Retry policy
|
|
8
|
+
* @param retryPolicy.maxRetries How many retries to attempt in total
|
|
9
|
+
* @param retryPolicy.delay How long should the delay be
|
|
10
|
+
* @param retryPolicy.exponential Whether to use exponentially increasing delays
|
|
11
|
+
* @param errorAllowed A callback for determining whether a given error is allowed, and we should therefore not retry
|
|
12
|
+
* @param abortSignal
|
|
13
|
+
* @returns Result of the action executing callback
|
|
14
|
+
* @category Utilities
|
|
15
|
+
*/
|
|
16
|
+
export declare function tryWithRetries<T>(func: (retryCount: number) => Promise<T>, retryPolicy?: {
|
|
17
|
+
maxRetries?: number;
|
|
18
|
+
delay?: number;
|
|
19
|
+
exponential?: boolean;
|
|
20
|
+
}, errorAllowed?: ((e: any) => boolean) | Constructor<Error> | Constructor<Error>[], abortSignal?: AbortSignal): Promise<T>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tryWithRetries = void 0;
|
|
4
|
+
const TimeoutUtils_1 = require("./TimeoutUtils");
|
|
5
|
+
const Logger_1 = require("./Logger");
|
|
6
|
+
const logger = (0, Logger_1.getLogger)("RetryUtils: ");
|
|
7
|
+
function isConstructor(fn) {
|
|
8
|
+
return (typeof fn === 'function' &&
|
|
9
|
+
fn.prototype != null &&
|
|
10
|
+
fn.prototype.constructor === fn);
|
|
11
|
+
}
|
|
12
|
+
function isConstructorArray(fnArr) {
|
|
13
|
+
return Array.isArray(fnArr) && fnArr.every(isConstructor);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Checks whether the passed error is allowed to pass through
|
|
17
|
+
*
|
|
18
|
+
* @param e Error in question
|
|
19
|
+
* @param errorAllowed Allowed errors as defined as a callback function, specific error type, or an array of error types
|
|
20
|
+
*/
|
|
21
|
+
function checkError(e, errorAllowed) {
|
|
22
|
+
if (isConstructorArray(errorAllowed))
|
|
23
|
+
return errorAllowed.find(error => e instanceof error) != null;
|
|
24
|
+
if (isConstructor(errorAllowed))
|
|
25
|
+
return e instanceof errorAllowed;
|
|
26
|
+
return errorAllowed(e);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Runs the passed function multiple times if it fails
|
|
30
|
+
*
|
|
31
|
+
* @param func A callback for executing the action
|
|
32
|
+
* @param func.retryCount Count of the current retry, starting from 0 for original request and increasing
|
|
33
|
+
* @param retryPolicy Retry policy
|
|
34
|
+
* @param retryPolicy.maxRetries How many retries to attempt in total
|
|
35
|
+
* @param retryPolicy.delay How long should the delay be
|
|
36
|
+
* @param retryPolicy.exponential Whether to use exponentially increasing delays
|
|
37
|
+
* @param errorAllowed A callback for determining whether a given error is allowed, and we should therefore not retry
|
|
38
|
+
* @param abortSignal
|
|
39
|
+
* @returns Result of the action executing callback
|
|
40
|
+
* @category Utilities
|
|
41
|
+
*/
|
|
42
|
+
async function tryWithRetries(func, retryPolicy, errorAllowed, abortSignal) {
|
|
43
|
+
retryPolicy = retryPolicy || {};
|
|
44
|
+
retryPolicy.maxRetries = retryPolicy.maxRetries || 5;
|
|
45
|
+
retryPolicy.delay = retryPolicy.delay || 500;
|
|
46
|
+
retryPolicy.exponential = retryPolicy.exponential == null ? true : retryPolicy.exponential;
|
|
47
|
+
let err = null;
|
|
48
|
+
for (let i = 0; i < retryPolicy.maxRetries; i++) {
|
|
49
|
+
try {
|
|
50
|
+
return await func(i);
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
if (errorAllowed != null && checkError(e, errorAllowed))
|
|
54
|
+
throw e;
|
|
55
|
+
err = e;
|
|
56
|
+
logger.warn("tryWithRetries(): Error on try number: " + i, e);
|
|
57
|
+
}
|
|
58
|
+
if (abortSignal != null && abortSignal.aborted)
|
|
59
|
+
throw (abortSignal.reason || new Error("Aborted"));
|
|
60
|
+
if (i !== retryPolicy.maxRetries - 1) {
|
|
61
|
+
await (0, TimeoutUtils_1.timeoutPromise)(retryPolicy.exponential ? retryPolicy.delay * Math.pow(2, i) : retryPolicy.delay, abortSignal);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
exports.tryWithRetries = tryWithRetries;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ChainType } from "@atomiqlabs/base";
|
|
2
|
+
import { SwapType } from "../enums/SwapType";
|
|
3
|
+
import { SupportsSwapType } from "../swapper/Swapper";
|
|
4
|
+
import { SpvFromBTCSwap } from "../swaps/spv_swaps/SpvFromBTCSwap";
|
|
5
|
+
import { FromBTCSwap } from "../swaps/escrow_swaps/frombtc/onchain/FromBTCSwap";
|
|
6
|
+
import { FromBTCLNSwap } from "../swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap";
|
|
7
|
+
import { ToBTCSwap } from "../swaps/escrow_swaps/tobtc/onchain/ToBTCSwap";
|
|
8
|
+
import { FromBTCLNAutoSwap } from "../swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap";
|
|
9
|
+
import { ToBTCLNSwap } from "../swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap";
|
|
10
|
+
import { OnchainForGasSwap } from "../swaps/trusted/onchain/OnchainForGasSwap";
|
|
11
|
+
import { LnForGasSwap } from "../swaps/trusted/ln/LnForGasSwap";
|
|
12
|
+
import { ISwap } from "../swaps/ISwap";
|
|
13
|
+
/**
|
|
14
|
+
* Type mapping from SwapType enum to specific swap class implementations
|
|
15
|
+
* @category Utilities
|
|
16
|
+
*/
|
|
17
|
+
export type SwapTypeMapping<T extends ChainType> = {
|
|
18
|
+
[SwapType.FROM_BTC]: SupportsSwapType<T, SwapType.SPV_VAULT_FROM_BTC> extends true ? SpvFromBTCSwap<T> : FromBTCSwap<T>;
|
|
19
|
+
[SwapType.FROM_BTCLN]: SupportsSwapType<T, SwapType.FROM_BTCLN_AUTO> extends true ? FromBTCLNAutoSwap<T> : FromBTCLNSwap<T>;
|
|
20
|
+
[SwapType.TO_BTC]: ToBTCSwap<T>;
|
|
21
|
+
[SwapType.TO_BTCLN]: ToBTCLNSwap<T>;
|
|
22
|
+
[SwapType.TRUSTED_FROM_BTC]: OnchainForGasSwap<T>;
|
|
23
|
+
[SwapType.TRUSTED_FROM_BTCLN]: LnForGasSwap<T>;
|
|
24
|
+
[SwapType.SPV_VAULT_FROM_BTC]: SpvFromBTCSwap<T>;
|
|
25
|
+
[SwapType.FROM_BTCLN_AUTO]: FromBTCLNAutoSwap<T>;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Type guard to check if a swap is of a specific swap type
|
|
29
|
+
* @category Utilities
|
|
30
|
+
*/
|
|
31
|
+
export declare function isSwapType<T extends ChainType, S extends SwapType>(swap: ISwap<T>, swapType: S): swap is SwapTypeMapping<T>[S];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isSwapType = void 0;
|
|
4
|
+
const SwapType_1 = require("../enums/SwapType");
|
|
5
|
+
/**
|
|
6
|
+
* Type guard to check if a swap is of a specific swap type
|
|
7
|
+
* @category Utilities
|
|
8
|
+
*/
|
|
9
|
+
function isSwapType(swap, swapType) {
|
|
10
|
+
if (swap == null)
|
|
11
|
+
return false;
|
|
12
|
+
if (swap.getType() === SwapType_1.SwapType.SPV_VAULT_FROM_BTC && swapType === SwapType_1.SwapType.FROM_BTC)
|
|
13
|
+
return true;
|
|
14
|
+
if (swap.getType() === SwapType_1.SwapType.FROM_BTCLN_AUTO && swapType === SwapType_1.SwapType.FROM_BTCLN)
|
|
15
|
+
return true;
|
|
16
|
+
return swap.getType() === swapType;
|
|
17
|
+
}
|
|
18
|
+
exports.isSwapType = isSwapType;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Returns a promise that resolves after given amount seconds
|
|
3
|
+
*
|
|
4
|
+
* @param timeout how many milliseconds to wait for
|
|
5
|
+
* @param abortSignal
|
|
6
|
+
* @category Utilities
|
|
7
|
+
*/
|
|
8
|
+
export declare function timeoutPromise(timeout: number, abortSignal?: AbortSignal): Promise<void>;
|
|
4
9
|
/**
|
|
5
10
|
* Returns an abort signal that aborts after a specified timeout in milliseconds
|
|
6
11
|
*
|
|
7
12
|
* @param timeout Milliseconds to wait
|
|
8
13
|
* @param abortReason Abort with this abort reason
|
|
9
14
|
* @param abortSignal Abort signal to extend
|
|
15
|
+
* @category Utilities
|
|
10
16
|
*/
|
|
11
17
|
export declare function timeoutSignal(timeout: number, abortReason?: any, abortSignal?: AbortSignal): AbortSignal;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.timeoutSignal = exports.timeoutPromise = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Returns a promise that resolves after given amount seconds
|
|
6
|
+
*
|
|
7
|
+
* @param timeout how many milliseconds to wait for
|
|
8
|
+
* @param abortSignal
|
|
9
|
+
* @category Utilities
|
|
10
|
+
*/
|
|
11
|
+
function timeoutPromise(timeout, abortSignal) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
if (abortSignal != null && abortSignal.aborted) {
|
|
14
|
+
reject(abortSignal.reason);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
let abortSignalListener;
|
|
18
|
+
let timeoutHandle = setTimeout(() => {
|
|
19
|
+
if (abortSignalListener != null && abortSignal != null)
|
|
20
|
+
abortSignal.removeEventListener("abort", abortSignalListener);
|
|
21
|
+
resolve();
|
|
22
|
+
}, timeout);
|
|
23
|
+
if (abortSignal != null) {
|
|
24
|
+
abortSignal.addEventListener("abort", abortSignalListener = () => {
|
|
25
|
+
if (timeoutHandle != null)
|
|
26
|
+
clearTimeout(timeoutHandle);
|
|
27
|
+
timeoutHandle = null;
|
|
28
|
+
reject(abortSignal.reason);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.timeoutPromise = timeoutPromise;
|
|
34
|
+
/**
|
|
35
|
+
* Returns an abort signal that aborts after a specified timeout in milliseconds
|
|
36
|
+
*
|
|
37
|
+
* @param timeout Milliseconds to wait
|
|
38
|
+
* @param abortReason Abort with this abort reason
|
|
39
|
+
* @param abortSignal Abort signal to extend
|
|
40
|
+
* @category Utilities
|
|
41
|
+
*/
|
|
42
|
+
function timeoutSignal(timeout, abortReason, abortSignal) {
|
|
43
|
+
if (timeout == null)
|
|
44
|
+
throw new Error("Timeout seconds cannot be null!");
|
|
45
|
+
const abortController = new AbortController();
|
|
46
|
+
const timeoutHandle = setTimeout(() => abortController.abort(abortReason || new Error("Timed out")), timeout);
|
|
47
|
+
if (abortSignal != null) {
|
|
48
|
+
abortSignal.addEventListener("abort", () => {
|
|
49
|
+
clearTimeout(timeoutHandle);
|
|
50
|
+
abortController.abort(abortSignal.reason);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return abortController.signal;
|
|
54
|
+
}
|
|
55
|
+
exports.timeoutSignal = timeoutSignal;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Token } from "../types/Token";
|
|
2
|
+
/**
|
|
3
|
+
* Converts a raw bigint amount to a human-readable string with decimals
|
|
4
|
+
* @category Utilities
|
|
5
|
+
*/
|
|
6
|
+
export declare function toHumanReadableString(amount: bigint, currencySpec: Token): string;
|
|
7
|
+
/**
|
|
8
|
+
* Parses a human-readable decimal string to a raw bigint amount
|
|
9
|
+
* @category Utilities
|
|
10
|
+
*/
|
|
11
|
+
export declare function fromHumanReadableString(amount: string, currencySpec: Token): bigint | null;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromHumanReadableString = exports.toHumanReadableString = void 0;
|
|
4
|
+
const Utils_1 = require("./Utils");
|
|
5
|
+
/**
|
|
6
|
+
* Converts a raw bigint amount to a human-readable string with decimals
|
|
7
|
+
* @category Utilities
|
|
8
|
+
*/
|
|
9
|
+
function toHumanReadableString(amount, currencySpec) {
|
|
10
|
+
if (amount == null)
|
|
11
|
+
return "";
|
|
12
|
+
return (0, Utils_1.toDecimal)(amount, currencySpec.decimals, undefined, currencySpec.displayDecimals);
|
|
13
|
+
}
|
|
14
|
+
exports.toHumanReadableString = toHumanReadableString;
|
|
15
|
+
/**
|
|
16
|
+
* Parses a human-readable decimal string to a raw bigint amount
|
|
17
|
+
* @category Utilities
|
|
18
|
+
*/
|
|
19
|
+
function fromHumanReadableString(amount, currencySpec) {
|
|
20
|
+
if (amount === "" || amount == null)
|
|
21
|
+
return null;
|
|
22
|
+
try {
|
|
23
|
+
return (0, Utils_1.fromDecimal)(amount, currencySpec.decimals);
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.fromHumanReadableString = fromHumanReadableString;
|