@atomiqlabs/sdk 7.0.12 → 8.0.8
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
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { StorageObject, IStorageManager } from "@atomiqlabs/base";
|
|
2
|
-
/**
|
|
3
|
-
* StorageManager using local filesystem to persists data, creates a new file for every save object
|
|
4
|
-
*/
|
|
5
|
-
export declare class FileSystemStorageManager<T extends StorageObject> implements IStorageManager<T> {
|
|
6
|
-
private readonly directory;
|
|
7
|
-
data: {
|
|
8
|
-
[key: string]: T;
|
|
9
|
-
};
|
|
10
|
-
constructor(directory: string);
|
|
11
|
-
init(): Promise<void>;
|
|
12
|
-
saveData(hash: string, object: T): Promise<void>;
|
|
13
|
-
removeData(hash: string): Promise<void>;
|
|
14
|
-
loadData(type: new (data: any) => T): Promise<T[]>;
|
|
15
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FileSystemStorageManager = void 0;
|
|
4
|
-
const fs = require("fs/promises");
|
|
5
|
-
/**
|
|
6
|
-
* StorageManager using local filesystem to persists data, creates a new file for every save object
|
|
7
|
-
*/
|
|
8
|
-
class FileSystemStorageManager {
|
|
9
|
-
constructor(directory) {
|
|
10
|
-
this.data = {};
|
|
11
|
-
this.directory = directory;
|
|
12
|
-
}
|
|
13
|
-
async init() {
|
|
14
|
-
try {
|
|
15
|
-
await fs.mkdir(this.directory);
|
|
16
|
-
}
|
|
17
|
-
catch (e) { }
|
|
18
|
-
}
|
|
19
|
-
async saveData(hash, object) {
|
|
20
|
-
try {
|
|
21
|
-
await fs.mkdir(this.directory);
|
|
22
|
-
}
|
|
23
|
-
catch (e) { }
|
|
24
|
-
this.data[hash] = object;
|
|
25
|
-
const cpy = object.serialize();
|
|
26
|
-
await fs.writeFile(this.directory + "/" + hash + ".json", JSON.stringify(cpy));
|
|
27
|
-
}
|
|
28
|
-
async removeData(hash) {
|
|
29
|
-
const paymentHash = hash;
|
|
30
|
-
try {
|
|
31
|
-
if (this.data[paymentHash] != null)
|
|
32
|
-
delete this.data[paymentHash];
|
|
33
|
-
await fs.rm(this.directory + "/" + paymentHash + ".json");
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
console.error("FileSystemStorageManager: removeData(): Error: ", e);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
async loadData(type) {
|
|
40
|
-
let files;
|
|
41
|
-
try {
|
|
42
|
-
files = await fs.readdir(this.directory);
|
|
43
|
-
}
|
|
44
|
-
catch (e) {
|
|
45
|
-
console.error("FileSystemStorageManager: loadData(): Error: ", e);
|
|
46
|
-
return [];
|
|
47
|
-
}
|
|
48
|
-
const arr = [];
|
|
49
|
-
for (let file of files) {
|
|
50
|
-
const paymentHash = file.split(".")[0];
|
|
51
|
-
const result = await fs.readFile(this.directory + "/" + file);
|
|
52
|
-
const obj = JSON.parse(result.toString());
|
|
53
|
-
const parsed = new type(obj);
|
|
54
|
-
arr.push(parsed);
|
|
55
|
-
this.data[paymentHash] = parsed;
|
|
56
|
-
}
|
|
57
|
-
return arr;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.FileSystemStorageManager = FileSystemStorageManager;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./FileSystemStorageManager";
|
package/dist/fs-storage/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./FileSystemStorageManager"), exports);
|
package/src/SmartChainAssets.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SmartChainAssets = void 0;
|
|
4
|
-
exports.SmartChainAssets = {
|
|
5
|
-
WBTC: {
|
|
6
|
-
pricing: {
|
|
7
|
-
binancePair: "WBTCBTC",
|
|
8
|
-
okxPair: "WBTC-BTC",
|
|
9
|
-
coinGeckoCoinId: "wrapped-bitcoin",
|
|
10
|
-
coinPaprikaCoinId: "wbtc-wrapped-bitcoin",
|
|
11
|
-
krakenPair: "WBTCXBT"
|
|
12
|
-
},
|
|
13
|
-
name: "Wrapped BTC (WBTC)"
|
|
14
|
-
},
|
|
15
|
-
USDC: {
|
|
16
|
-
pricing: {
|
|
17
|
-
binancePair: "!BTCUSDC",
|
|
18
|
-
okxPair: "!BTC-USDC",
|
|
19
|
-
coinGeckoCoinId: "usd-coin",
|
|
20
|
-
coinPaprikaCoinId: "usdc-usd-coin",
|
|
21
|
-
krakenPair: "!XBTUSDC"
|
|
22
|
-
},
|
|
23
|
-
name: "USD Circle"
|
|
24
|
-
},
|
|
25
|
-
USDT: {
|
|
26
|
-
pricing: {
|
|
27
|
-
binancePair: "!BTCUSDT",
|
|
28
|
-
okxPair: "!BTC-USDT",
|
|
29
|
-
coinGeckoCoinId: "tether",
|
|
30
|
-
coinPaprikaCoinId: "usdt-tether",
|
|
31
|
-
krakenPair: "!XBTUSDT"
|
|
32
|
-
},
|
|
33
|
-
name: "Tether USD"
|
|
34
|
-
},
|
|
35
|
-
SOL: {
|
|
36
|
-
pricing: {
|
|
37
|
-
binancePair: "SOLBTC",
|
|
38
|
-
okxPair: "SOL-BTC",
|
|
39
|
-
coinGeckoCoinId: "solana",
|
|
40
|
-
coinPaprikaCoinId: "sol-solana",
|
|
41
|
-
krakenPair: "SOLXBT"
|
|
42
|
-
},
|
|
43
|
-
name: "Solana"
|
|
44
|
-
},
|
|
45
|
-
BONK: {
|
|
46
|
-
pricing: {
|
|
47
|
-
binancePair: "BONKUSDC;!BTCUSDC",
|
|
48
|
-
okxPair: "BONK-USDT;!BTC-USDT",
|
|
49
|
-
coinGeckoCoinId: "bonk",
|
|
50
|
-
coinPaprikaCoinId: "bonk-bonk",
|
|
51
|
-
krakenPair: "BONKUSD;!XXBTZUSD"
|
|
52
|
-
},
|
|
53
|
-
name: "Bonk"
|
|
54
|
-
},
|
|
55
|
-
ETH: {
|
|
56
|
-
pricing: {
|
|
57
|
-
binancePair: "ETHBTC",
|
|
58
|
-
okxPair: "ETH-BTC",
|
|
59
|
-
coinGeckoCoinId: "ethereum",
|
|
60
|
-
coinPaprikaCoinId: "eth-ethereum",
|
|
61
|
-
krakenPair: "XETHXXBT"
|
|
62
|
-
},
|
|
63
|
-
name: "Ether"
|
|
64
|
-
},
|
|
65
|
-
STRK: {
|
|
66
|
-
pricing: {
|
|
67
|
-
binancePair: "STRKUSDT;!BTCUSDT",
|
|
68
|
-
okxPair: "STRK-USDT;!BTC-USDT",
|
|
69
|
-
coinGeckoCoinId: "starknet",
|
|
70
|
-
coinPaprikaCoinId: "strk-starknet",
|
|
71
|
-
krakenPair: "STRKUSD;!XXBTZUSD"
|
|
72
|
-
},
|
|
73
|
-
name: "Starknet"
|
|
74
|
-
}
|
|
75
|
-
};
|
package/src/SwapperFactory.js
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var _a, _b, _c;
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.SwapperFactory = void 0;
|
|
16
|
-
var base_1 = require("@atomiqlabs/base");
|
|
17
|
-
var sdk_lib_1 = require("@atomiqlabs/sdk-lib");
|
|
18
|
-
var SmartChainAssets_1 = require("./SmartChainAssets");
|
|
19
|
-
var LocalStorageManager_1 = require("./storage/LocalStorageManager");
|
|
20
|
-
var registries = (_a = {},
|
|
21
|
-
_a[base_1.BitcoinNetwork.MAINNET] = "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry-mainnet.json?ref=main",
|
|
22
|
-
_a[base_1.BitcoinNetwork.TESTNET] = "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry.json?ref=main",
|
|
23
|
-
_a[base_1.BitcoinNetwork.TESTNET4] = "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry-testnet4.json?ref=main",
|
|
24
|
-
_a);
|
|
25
|
-
var trustedIntermediaries = (_b = {},
|
|
26
|
-
_b[base_1.BitcoinNetwork.MAINNET] = "https://node3.gethopa.com:34100",
|
|
27
|
-
_b[base_1.BitcoinNetwork.TESTNET] = "https://node3.gethopa.com:24100",
|
|
28
|
-
_b);
|
|
29
|
-
var mempoolUrls = (_c = {},
|
|
30
|
-
_c[base_1.BitcoinNetwork.MAINNET] = [
|
|
31
|
-
"https://mempool.space/api/",
|
|
32
|
-
"https://mempool.fra.mempool.space/api/",
|
|
33
|
-
"https://mempool.va1.mempool.space/api/",
|
|
34
|
-
"https://mempool.tk7.mempool.space/api/"
|
|
35
|
-
],
|
|
36
|
-
_c[base_1.BitcoinNetwork.TESTNET] = [
|
|
37
|
-
"https://mempool.space/testnet/api/",
|
|
38
|
-
"https://mempool.fra.mempool.space/testnet/api/",
|
|
39
|
-
"https://mempool.va1.mempool.space/testnet/api/",
|
|
40
|
-
"https://mempool.tk7.mempool.space/testnet/api/"
|
|
41
|
-
],
|
|
42
|
-
_c[base_1.BitcoinNetwork.TESTNET4] = [
|
|
43
|
-
"https://mempool.space/testnet4/api/",
|
|
44
|
-
"https://mempool.fra.mempool.space/testnet4/api/",
|
|
45
|
-
"https://mempool.va1.mempool.space/testnet4/api/",
|
|
46
|
-
"https://mempool.tk7.mempool.space/testnet4/api/"
|
|
47
|
-
],
|
|
48
|
-
_c);
|
|
49
|
-
var SwapperFactory = /** @class */ (function () {
|
|
50
|
-
function SwapperFactory(initializers) {
|
|
51
|
-
var _this = this;
|
|
52
|
-
this.initializers = initializers;
|
|
53
|
-
this.Tokens = {
|
|
54
|
-
BITCOIN: sdk_lib_1.BitcoinTokens
|
|
55
|
-
};
|
|
56
|
-
this.TokenResolver = {};
|
|
57
|
-
this.initializers = initializers;
|
|
58
|
-
initializers.forEach(function (initializer) {
|
|
59
|
-
var addressMap = {};
|
|
60
|
-
_this.Tokens[initializer.chainId] = {};
|
|
61
|
-
for (var ticker in initializer.tokens) {
|
|
62
|
-
var assetData = initializer.tokens[ticker];
|
|
63
|
-
_this.Tokens[initializer.chainId][ticker] = addressMap[assetData.address] = {
|
|
64
|
-
chain: "SC",
|
|
65
|
-
chainId: initializer.chainId,
|
|
66
|
-
address: assetData.address,
|
|
67
|
-
name: SmartChainAssets_1.SmartChainAssets[ticker].name,
|
|
68
|
-
decimals: assetData.decimals,
|
|
69
|
-
displayDecimals: assetData.displayDecimals,
|
|
70
|
-
ticker: ticker
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
_this.TokenResolver[initializer.chainId] = {
|
|
74
|
-
getToken: function (address) { return addressMap[address]; }
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
SwapperFactory.prototype.newSwapper = function (options) {
|
|
79
|
-
var _this = this;
|
|
80
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
81
|
-
(_a = options.bitcoinNetwork) !== null && _a !== void 0 ? _a : (options.bitcoinNetwork = base_1.BitcoinNetwork.MAINNET);
|
|
82
|
-
(_b = options.storagePrefix) !== null && _b !== void 0 ? _b : (options.storagePrefix = "atomiqsdk-" + options.bitcoinNetwork + "-");
|
|
83
|
-
(_c = options.defaultTrustedIntermediaryUrl) !== null && _c !== void 0 ? _c : (options.defaultTrustedIntermediaryUrl = trustedIntermediaries[options.bitcoinNetwork]);
|
|
84
|
-
(_d = options.registryUrl) !== null && _d !== void 0 ? _d : (options.registryUrl = registries[options.bitcoinNetwork]);
|
|
85
|
-
var b;
|
|
86
|
-
if (options.mempoolApi instanceof sdk_lib_1.MempoolApi)
|
|
87
|
-
var mempoolApi = (_e = options.mempoolApi) !== null && _e !== void 0 ? _e : new sdk_lib_1.MempoolApi(mempoolUrls[options.bitcoinNetwork]);
|
|
88
|
-
var bitcoinRpc = new sdk_lib_1.MempoolBitcoinRpc(mempoolApi);
|
|
89
|
-
var pricingAssets = [];
|
|
90
|
-
Object.keys(SmartChainAssets_1.SmartChainAssets).forEach(function (ticker) {
|
|
91
|
-
var chains = {};
|
|
92
|
-
for (var _i = 0, _a = _this.initializers; _i < _a.length; _i++) {
|
|
93
|
-
var _b = _a[_i], tokens = _b.tokens, chainId = _b.chainId;
|
|
94
|
-
if (tokens[ticker] != null)
|
|
95
|
-
chains[chainId] = tokens[ticker];
|
|
96
|
-
}
|
|
97
|
-
var assetData = SmartChainAssets_1.SmartChainAssets[ticker];
|
|
98
|
-
pricingAssets.push(__assign(__assign({}, assetData.pricing), { chains: chains, ticker: ticker, name: assetData.name }));
|
|
99
|
-
});
|
|
100
|
-
(_f = options.chainStorageCtor) !== null && _f !== void 0 ? _f : (options.chainStorageCtor = function (name) { return new LocalStorageManager_1.LocalStorageManager(name); });
|
|
101
|
-
var chains = {};
|
|
102
|
-
for (var _i = 0, _j = this.initializers; _i < _j.length; _i++) {
|
|
103
|
-
var _k = _j[_i], initializer = _k.initializer, chainId = _k.chainId;
|
|
104
|
-
if (options.chains[chainId] == null)
|
|
105
|
-
continue;
|
|
106
|
-
chains[chainId] = initializer(options.chains[chainId], bitcoinRpc, options.bitcoinNetwork, options.chainStorageCtor);
|
|
107
|
-
}
|
|
108
|
-
var swapPricing = options.getPriceFn != null ?
|
|
109
|
-
new sdk_lib_1.SingleSwapPrice((_g = options.pricingFeeDifferencePPM) !== null && _g !== void 0 ? _g : 10000n, new sdk_lib_1.CustomPriceProvider(pricingAssets.map(function (val) {
|
|
110
|
-
return {
|
|
111
|
-
coinId: val.ticker,
|
|
112
|
-
chains: val.chains
|
|
113
|
-
};
|
|
114
|
-
}), options.getPriceFn)) :
|
|
115
|
-
sdk_lib_1.RedundantSwapPrice.createFromTokenMap((_h = options.pricingFeeDifferencePPM) !== null && _h !== void 0 ? _h : 10000n, pricingAssets);
|
|
116
|
-
return new sdk_lib_1.Swapper(bitcoinRpc, chains, swapPricing, pricingAssets, options);
|
|
117
|
-
};
|
|
118
|
-
return SwapperFactory;
|
|
119
|
-
}());
|
|
120
|
-
exports.SwapperFactory = SwapperFactory;
|
package/src/Utils.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.timeoutSignal = exports.fromHumanReadableString = exports.toHumanReadableString = void 0;
|
|
4
|
-
var sdk_lib_1 = require("@atomiqlabs/sdk-lib");
|
|
5
|
-
function toHumanReadableString(amount, currencySpec) {
|
|
6
|
-
if (amount == null)
|
|
7
|
-
return null;
|
|
8
|
-
return (0, sdk_lib_1.toDecimal)(amount, currencySpec.decimals, undefined, currencySpec.displayDecimals);
|
|
9
|
-
}
|
|
10
|
-
exports.toHumanReadableString = toHumanReadableString;
|
|
11
|
-
function fromHumanReadableString(amount, currencySpec) {
|
|
12
|
-
if (amount === "" || amount == null)
|
|
13
|
-
return null;
|
|
14
|
-
return (0, sdk_lib_1.fromDecimal)(amount, currencySpec.decimals);
|
|
15
|
-
}
|
|
16
|
-
exports.fromHumanReadableString = fromHumanReadableString;
|
|
17
|
-
/**
|
|
18
|
-
* Returns an abort signal that aborts after a specified timeout in milliseconds
|
|
19
|
-
*
|
|
20
|
-
* @param timeout Milliseconds to wait
|
|
21
|
-
* @param abortReason Abort with this abort reason
|
|
22
|
-
* @param abortSignal Abort signal to extend
|
|
23
|
-
*/
|
|
24
|
-
function timeoutSignal(timeout, abortReason, abortSignal) {
|
|
25
|
-
if (timeout == null)
|
|
26
|
-
return abortSignal;
|
|
27
|
-
var abortController = new AbortController();
|
|
28
|
-
var timeoutHandle = setTimeout(function () { return abortController.abort(abortReason || new Error("Timed out")); }, timeout);
|
|
29
|
-
if (abortSignal != null) {
|
|
30
|
-
abortSignal.addEventListener("abort", function () {
|
|
31
|
-
clearTimeout(timeoutHandle);
|
|
32
|
-
abortController.abort(abortSignal.reason);
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return abortController.signal;
|
|
36
|
-
}
|
|
37
|
-
exports.timeoutSignal = timeoutSignal;
|
package/src/Utils.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {toDecimal, fromDecimal, Token} from "@atomiqlabs/sdk-lib";
|
|
2
|
-
|
|
3
|
-
export function toHumanReadableString(amount: bigint, currencySpec: Token): string {
|
|
4
|
-
if(amount==null) return null;
|
|
5
|
-
return toDecimal(amount, currencySpec.decimals, undefined, currencySpec.displayDecimals);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function fromHumanReadableString(amount: string, currencySpec: Token): bigint {
|
|
9
|
-
if(amount==="" || amount==null) return null;
|
|
10
|
-
return fromDecimal(amount, currencySpec.decimals);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Returns an abort signal that aborts after a specified timeout in milliseconds
|
|
15
|
-
*
|
|
16
|
-
* @param timeout Milliseconds to wait
|
|
17
|
-
* @param abortReason Abort with this abort reason
|
|
18
|
-
* @param abortSignal Abort signal to extend
|
|
19
|
-
*/
|
|
20
|
-
export function timeoutSignal(timeout: number, abortReason?: any, abortSignal?: AbortSignal): AbortSignal {
|
|
21
|
-
if(timeout==null) return abortSignal;
|
|
22
|
-
const abortController = new AbortController();
|
|
23
|
-
const timeoutHandle = setTimeout(() => abortController.abort(abortReason || new Error("Timed out")), timeout);
|
|
24
|
-
if(abortSignal!=null) {
|
|
25
|
-
abortSignal.addEventListener("abort", () => {
|
|
26
|
-
clearTimeout(timeoutHandle);
|
|
27
|
-
abortController.abort(abortSignal.reason);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
return abortController.signal;
|
|
31
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import {StorageObject, IStorageManager} from "@atomiqlabs/base";
|
|
2
|
-
import * as fs from "fs/promises";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* StorageManager using local filesystem to persists data, creates a new file for every save object
|
|
6
|
-
*/
|
|
7
|
-
export class FileSystemStorageManager<T extends StorageObject> implements IStorageManager<T> {
|
|
8
|
-
|
|
9
|
-
private readonly directory: string;
|
|
10
|
-
data: {
|
|
11
|
-
[key: string]: T
|
|
12
|
-
} = {};
|
|
13
|
-
|
|
14
|
-
constructor(directory: string) {
|
|
15
|
-
this.directory = directory;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async init(): Promise<void> {
|
|
19
|
-
try {
|
|
20
|
-
await fs.mkdir(this.directory);
|
|
21
|
-
} catch (e) {}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
async saveData(hash: string, object: T): Promise<void> {
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
await fs.mkdir(this.directory)
|
|
28
|
-
} catch (e) {}
|
|
29
|
-
|
|
30
|
-
this.data[hash] = object;
|
|
31
|
-
|
|
32
|
-
const cpy = object.serialize();
|
|
33
|
-
|
|
34
|
-
await fs.writeFile(this.directory+"/"+hash+".json", JSON.stringify(cpy));
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async removeData(hash: string): Promise<void> {
|
|
39
|
-
const paymentHash = hash;
|
|
40
|
-
try {
|
|
41
|
-
if(this.data[paymentHash]!=null) delete this.data[paymentHash];
|
|
42
|
-
await fs.rm(this.directory+"/"+paymentHash+".json");
|
|
43
|
-
} catch (e) {
|
|
44
|
-
console.error("FileSystemStorageManager: removeData(): Error: ", e);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async loadData(type: new(data: any) => T): Promise<T[]> {
|
|
49
|
-
let files;
|
|
50
|
-
try {
|
|
51
|
-
files = await fs.readdir(this.directory);
|
|
52
|
-
} catch (e) {
|
|
53
|
-
console.error("FileSystemStorageManager: loadData(): Error: ", e);
|
|
54
|
-
return [];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const arr = [];
|
|
58
|
-
|
|
59
|
-
for(let file of files) {
|
|
60
|
-
const paymentHash = file.split(".")[0];
|
|
61
|
-
const result = await fs.readFile(this.directory+"/"+file);
|
|
62
|
-
const obj = JSON.parse(result.toString());
|
|
63
|
-
const parsed = new type(obj);
|
|
64
|
-
arr.push(parsed);
|
|
65
|
-
this.data[paymentHash] = parsed;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return arr;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
}
|
package/src/fs-storage/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./FileSystemStorageManager";
|
package/src/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("@atomiqlabs/base"), exports);
|
|
18
|
-
__exportStar(require("@atomiqlabs/sdk-lib"), exports);
|
|
19
|
-
__exportStar(require("./SwapperFactory"), exports);
|
|
20
|
-
__exportStar(require("./Utils"), exports);
|
|
21
|
-
__exportStar(require("./storage/LocalStorageManager"), exports);
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LocalStorageManager = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* StorageManager using browser's local storage API
|
|
6
|
-
*/
|
|
7
|
-
var LocalStorageManager = /** @class */ (function () {
|
|
8
|
-
function LocalStorageManager(storageKey) {
|
|
9
|
-
this.rawData = null;
|
|
10
|
-
this.data = {};
|
|
11
|
-
this.storageKey = storageKey;
|
|
12
|
-
}
|
|
13
|
-
LocalStorageManager.prototype.init = function () {
|
|
14
|
-
var completedTxt = window.localStorage.getItem(this.storageKey);
|
|
15
|
-
if (completedTxt != null) {
|
|
16
|
-
this.rawData = JSON.parse(completedTxt);
|
|
17
|
-
if (this.rawData == null)
|
|
18
|
-
this.rawData = {};
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
this.rawData = {};
|
|
22
|
-
}
|
|
23
|
-
return Promise.resolve();
|
|
24
|
-
};
|
|
25
|
-
LocalStorageManager.prototype.saveData = function (hash, object) {
|
|
26
|
-
this.data[hash] = object;
|
|
27
|
-
this.rawData[hash] = object.serialize();
|
|
28
|
-
return this.save();
|
|
29
|
-
};
|
|
30
|
-
LocalStorageManager.prototype.saveDataArr = function (arr) {
|
|
31
|
-
var _this = this;
|
|
32
|
-
arr.forEach(function (e) {
|
|
33
|
-
_this.data[e.id] = e.object;
|
|
34
|
-
_this.rawData[e.id] = e.object.serialize();
|
|
35
|
-
});
|
|
36
|
-
return this.save();
|
|
37
|
-
};
|
|
38
|
-
LocalStorageManager.prototype.removeData = function (hash) {
|
|
39
|
-
if (this.rawData[hash] != null) {
|
|
40
|
-
if (this.data[hash] != null)
|
|
41
|
-
delete this.data[hash];
|
|
42
|
-
delete this.rawData[hash];
|
|
43
|
-
return this.save();
|
|
44
|
-
}
|
|
45
|
-
return Promise.resolve();
|
|
46
|
-
};
|
|
47
|
-
LocalStorageManager.prototype.removeDataArr = function (hashArr) {
|
|
48
|
-
var _this = this;
|
|
49
|
-
hashArr.forEach(function (hash) {
|
|
50
|
-
if (_this.rawData[hash] != null) {
|
|
51
|
-
if (_this.data[hash] != null)
|
|
52
|
-
delete _this.data[hash];
|
|
53
|
-
delete _this.rawData[hash];
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
return this.save();
|
|
57
|
-
};
|
|
58
|
-
LocalStorageManager.prototype.loadData = function (type) {
|
|
59
|
-
var _this = this;
|
|
60
|
-
return Promise.resolve(Object.keys(this.rawData).map(function (e) {
|
|
61
|
-
var deserialized = new type(_this.rawData[e]);
|
|
62
|
-
_this.data[e] = deserialized;
|
|
63
|
-
return deserialized;
|
|
64
|
-
}));
|
|
65
|
-
};
|
|
66
|
-
LocalStorageManager.prototype.save = function () {
|
|
67
|
-
window.localStorage.setItem(this.storageKey, JSON.stringify(this.rawData));
|
|
68
|
-
return Promise.resolve();
|
|
69
|
-
};
|
|
70
|
-
return LocalStorageManager;
|
|
71
|
-
}());
|
|
72
|
-
exports.LocalStorageManager = LocalStorageManager;
|