@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
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {ParamDecoder} from "../ParamDecoder";
|
|
2
|
+
import {Buffer} from "buffer";
|
|
3
|
+
|
|
4
|
+
import {getLogger} from "../../../utils/Logger";
|
|
5
|
+
|
|
6
|
+
const logger = getLogger("ResponseParamDecoder: ");
|
|
7
|
+
|
|
8
|
+
export class ResponseParamDecoder extends ParamDecoder {
|
|
9
|
+
|
|
10
|
+
private readonly reader?: ReadableStreamDefaultReader<Uint8Array>;
|
|
11
|
+
private readonly abortSignal?: AbortSignal;
|
|
12
|
+
|
|
13
|
+
constructor(resp: Response, abortSignal?: AbortSignal) {
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
this.abortSignal = abortSignal;
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
//Read from stream
|
|
20
|
+
if(resp.body==null) throw new Error("Response has no body field!");
|
|
21
|
+
this.reader = resp.body.getReader();
|
|
22
|
+
this.readResponse();
|
|
23
|
+
} catch (e) {
|
|
24
|
+
//Read in one piece
|
|
25
|
+
resp.arrayBuffer().then(respBuffer => {
|
|
26
|
+
super.onData(Buffer.from(respBuffer));
|
|
27
|
+
super.onEnd();
|
|
28
|
+
}).catch(e => {
|
|
29
|
+
super.onError(e);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if(abortSignal!=null) abortSignal.addEventListener("abort", () => {
|
|
34
|
+
super.onError(abortSignal.reason);
|
|
35
|
+
if(this.reader!=null && !this.reader.closed) this.reader.cancel(abortSignal.reason);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Keeps reading the response until the reader closes
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
private async readResponse() {
|
|
44
|
+
if(this.reader==null) return;
|
|
45
|
+
while(true) {
|
|
46
|
+
const readResp = await this.reader.read().catch(e => {
|
|
47
|
+
logger.error("readResponse(): Error reading response: ",e);
|
|
48
|
+
return null;
|
|
49
|
+
});
|
|
50
|
+
if(this.abortSignal!=null && this.abortSignal.aborted) return;
|
|
51
|
+
if(readResp==null || readResp.done) {
|
|
52
|
+
super.onEnd();
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
super.onData(Buffer.from(readResp.value));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {ParamEncoder} from "../ParamEncoder";
|
|
2
|
+
import {Buffer} from "buffer";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export class StreamParamEncoder extends ParamEncoder {
|
|
6
|
+
|
|
7
|
+
private readonly stream: TransformStream<Buffer>;
|
|
8
|
+
private closed: boolean = false;
|
|
9
|
+
|
|
10
|
+
constructor() {
|
|
11
|
+
let stream = new TransformStream<Buffer>();
|
|
12
|
+
let writeStream = stream.writable.getWriter();
|
|
13
|
+
writeStream.closed.then(() => this.closed = true);
|
|
14
|
+
super(writeStream.write.bind(writeStream), () => {
|
|
15
|
+
if(this.closed) return Promise.resolve();
|
|
16
|
+
this.closed = true;
|
|
17
|
+
return writeStream.close();
|
|
18
|
+
});
|
|
19
|
+
this.stream = stream;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns the readable stream to be passed to the fetch API
|
|
24
|
+
*/
|
|
25
|
+
getReadableStream(): ReadableStream<Buffer> {
|
|
26
|
+
return this.stream.readable;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {isOptionalField, RequestSchema, RequestSchemaResultPromise, verifyField} from "../SchemaVerifier";
|
|
2
|
+
import {RequestError} from "../../../errors/RequestError";
|
|
3
|
+
import {extendAbortController, objectMap} from "../../../utils/Utils";
|
|
4
|
+
import {StreamParamEncoder} from "./StreamParamEncoder";
|
|
5
|
+
import {ResponseParamDecoder} from "./ResponseParamDecoder";
|
|
6
|
+
import {getLogger} from "../../../utils/Logger";
|
|
7
|
+
import {timeoutSignal} from "../../../utils/TimeoutUtils";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export type RequestBody = {
|
|
11
|
+
[key: string]: Promise<any> | any
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const logger = getLogger("StreamingFetch: ");
|
|
15
|
+
|
|
16
|
+
//https://developer.chrome.com/docs/capabilities/web-apis/fetch-streaming-requests#feature_detection
|
|
17
|
+
const supportsRequestStreams: boolean = (() => {
|
|
18
|
+
try {
|
|
19
|
+
let duplexAccessed = false;
|
|
20
|
+
|
|
21
|
+
const request = new Request('https://example.com/', {
|
|
22
|
+
body: new ReadableStream(),
|
|
23
|
+
method: 'POST',
|
|
24
|
+
get duplex() {
|
|
25
|
+
duplexAccessed = true;
|
|
26
|
+
return 'half';
|
|
27
|
+
},
|
|
28
|
+
} as any);
|
|
29
|
+
const hasContentType = request.headers.has('Content-Type');
|
|
30
|
+
|
|
31
|
+
return duplexAccessed && !hasContentType;
|
|
32
|
+
} catch (e) {
|
|
33
|
+
logger.error("supportsRequestStreams: Error checking environment support for HTTP request stream", e);
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
})();
|
|
37
|
+
|
|
38
|
+
logger.info("Environment supports request stream: "+supportsRequestStreams);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Sends a POST request to the specified URL in a streaming request/response mode
|
|
42
|
+
*
|
|
43
|
+
* @param url URL to send the request to
|
|
44
|
+
* @param body An object containing properties that should be sent to the server, can be Promise or any
|
|
45
|
+
* @param schema Schema of the response that should be received from the server
|
|
46
|
+
* @param timeout Timeout in millseconds for the request to succeed & all its response properties to resolve
|
|
47
|
+
* @param signal Abort signal
|
|
48
|
+
* @param streamRequest Whether the request should be streamed or not
|
|
49
|
+
* @throws {RequestError} When the response code is not 200
|
|
50
|
+
*/
|
|
51
|
+
export async function streamingFetchPromise<T extends RequestSchema>(
|
|
52
|
+
url: string,
|
|
53
|
+
body: RequestBody,
|
|
54
|
+
schema: T,
|
|
55
|
+
timeout?: number,
|
|
56
|
+
signal?: AbortSignal,
|
|
57
|
+
streamRequest?: boolean
|
|
58
|
+
): Promise<RequestSchemaResultPromise<T>> {
|
|
59
|
+
if(streamRequest==null) streamRequest = supportsRequestStreams;
|
|
60
|
+
if(timeout!=null) signal = timeoutSignal(timeout, new Error("Network request timed out"), signal);
|
|
61
|
+
|
|
62
|
+
const headers: Record<string, string> = {};
|
|
63
|
+
const init: RequestInit = {
|
|
64
|
+
method: "POST",
|
|
65
|
+
headers
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const startTime = Date.now();
|
|
69
|
+
|
|
70
|
+
const immediateValues: any = {};
|
|
71
|
+
const promises: Promise<any>[] = [];
|
|
72
|
+
|
|
73
|
+
if(!streamRequest) {
|
|
74
|
+
for(let key in body) {
|
|
75
|
+
if(body[key] instanceof Promise) {
|
|
76
|
+
promises.push(body[key].then((val: any) => {
|
|
77
|
+
immediateValues[key] = val;
|
|
78
|
+
}));
|
|
79
|
+
} else {
|
|
80
|
+
immediateValues[key] = body[key];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
await Promise.all(promises);
|
|
86
|
+
} catch (e: any) {
|
|
87
|
+
e._inputPromiseError = true;
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if(signal!=null) signal.throwIfAborted();
|
|
92
|
+
|
|
93
|
+
logger.debug(url+": Sending request ("+(Date.now()-startTime)+"ms) (non-streaming): ", immediateValues);
|
|
94
|
+
init.body = JSON.stringify(immediateValues);
|
|
95
|
+
headers['content-type'] = "application/json";
|
|
96
|
+
} else {
|
|
97
|
+
const outputStream = new StreamParamEncoder();
|
|
98
|
+
|
|
99
|
+
let hasPromiseInBody = false;
|
|
100
|
+
for(let key in body) {
|
|
101
|
+
if(body[key] instanceof Promise) {
|
|
102
|
+
promises.push(body[key].then((val: any) => {
|
|
103
|
+
logger.debug(url+": Send param ("+(Date.now()-startTime)+"ms) (streaming): ", {[key]: val});
|
|
104
|
+
return outputStream.writeParams({
|
|
105
|
+
[key]: val
|
|
106
|
+
});
|
|
107
|
+
}));
|
|
108
|
+
hasPromiseInBody = true;
|
|
109
|
+
} else {
|
|
110
|
+
immediateValues[key] = body[key];
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if(hasPromiseInBody) {
|
|
115
|
+
init.body = outputStream.getReadableStream();
|
|
116
|
+
headers['content-type'] = "application/x-multiple-json";
|
|
117
|
+
(init as any).duplex = "half";
|
|
118
|
+
|
|
119
|
+
logger.debug(url+": Sending request ("+(Date.now()-startTime)+"ms) (streaming): ", immediateValues);
|
|
120
|
+
promises.push(outputStream.writeParams(immediateValues));
|
|
121
|
+
|
|
122
|
+
const abortController = extendAbortController(signal);
|
|
123
|
+
signal = abortController.signal;
|
|
124
|
+
|
|
125
|
+
Promise.all(promises).then(() => outputStream.end()).catch(e => {
|
|
126
|
+
e._inputPromiseError = true;
|
|
127
|
+
abortController.abort(e);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
signal.addEventListener("abort", () => outputStream.end());
|
|
131
|
+
} else {
|
|
132
|
+
logger.debug(url+": Sending request ("+(Date.now()-startTime)+"ms) (non-streaming): ", immediateValues);
|
|
133
|
+
init.body = JSON.stringify(immediateValues);
|
|
134
|
+
headers['content-type'] = "application/json";
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if(signal!=null) init.signal = signal;
|
|
139
|
+
headers['accept'] = "application/x-multiple-json";
|
|
140
|
+
|
|
141
|
+
const resp = await fetch(url, init).catch(e => {
|
|
142
|
+
if(init.signal!=null && e.name==="AbortError") {
|
|
143
|
+
throw init.signal.reason;
|
|
144
|
+
} else {
|
|
145
|
+
if(e.message!=null) e.message += streamRequest ? " (streaming req)" : " (non streaming req)"
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
logger.debug(url+": Response status ("+(Date.now()-startTime)+"ms) "+(streamRequest ? "(streaming req)" : "(non streaming req)")+": ", resp.status);
|
|
151
|
+
|
|
152
|
+
if(resp.status!==200) {
|
|
153
|
+
let respTxt: string;
|
|
154
|
+
try {
|
|
155
|
+
respTxt = await resp.text();
|
|
156
|
+
} catch (e) {
|
|
157
|
+
throw new RequestError(resp.statusText, resp.status);
|
|
158
|
+
}
|
|
159
|
+
throw new RequestError(respTxt, resp.status);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if(resp.headers.get("content-type")!=="application/x-multiple-json") {
|
|
163
|
+
const respBody = await resp.json();
|
|
164
|
+
|
|
165
|
+
logger.debug(url+": Response read ("+(Date.now()-startTime)+"ms) (non streaming resp): ", respBody);
|
|
166
|
+
|
|
167
|
+
return objectMap(schema, (schemaValue, key) => {
|
|
168
|
+
const value = respBody[key];
|
|
169
|
+
|
|
170
|
+
const result = verifyField(schemaValue, value);
|
|
171
|
+
if(result===undefined) {
|
|
172
|
+
return Promise.reject(new Error("Invalid field value"));
|
|
173
|
+
} else {
|
|
174
|
+
return Promise.resolve(result);
|
|
175
|
+
}
|
|
176
|
+
}) as any;
|
|
177
|
+
} else {
|
|
178
|
+
const decoder = new ResponseParamDecoder(resp, init.signal ?? undefined);
|
|
179
|
+
|
|
180
|
+
return objectMap(schema, (schemaValue, key) => decoder.getParam(key).catch(e => {
|
|
181
|
+
if(isOptionalField(schemaValue)) return undefined;
|
|
182
|
+
throw e;
|
|
183
|
+
}).then(value => {
|
|
184
|
+
logger.debug(url+": Response frame read ("+(Date.now()-startTime)+"ms) (streaming resp): ", {[key]: value});
|
|
185
|
+
const result = verifyField(schemaValue, value);
|
|
186
|
+
if(result===undefined) {
|
|
187
|
+
return Promise.reject(new Error("Invalid field value"));
|
|
188
|
+
} else {
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
})) as any;
|
|
192
|
+
}
|
|
193
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,103 @@
|
|
|
1
1
|
export * from "@atomiqlabs/base";
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
export * from "./
|
|
5
|
-
|
|
2
|
+
|
|
3
|
+
export {MempoolApi} from "./bitcoin/mempool/MempoolApi";
|
|
4
|
+
export * from "./bitcoin/mempool/MempoolBitcoinRpc";
|
|
5
|
+
|
|
6
|
+
export * from "./bitcoin/wallet/BitcoinWallet";
|
|
7
|
+
export * from "./bitcoin/wallet/IBitcoinWallet";
|
|
8
|
+
export * from "./bitcoin/wallet/MinimalBitcoinWalletInterface";
|
|
9
|
+
export * from "./bitcoin/wallet/MinimalLightningNetworkWalletInterface";
|
|
10
|
+
export * from "./bitcoin/wallet/SingleAddressBitcoinWallet";
|
|
11
|
+
|
|
12
|
+
export * from "./enums/FeeType";
|
|
13
|
+
export * from "./enums/SwapAmountType";
|
|
14
|
+
export * from "./enums/SwapDirection";
|
|
15
|
+
export * from "./enums/SwapType";
|
|
16
|
+
|
|
17
|
+
export * from "./errors/IntermediaryError";
|
|
18
|
+
export * from "./errors/PaymentAuthError";
|
|
19
|
+
export * from "./errors/RequestError";
|
|
20
|
+
export * from "./errors/UserError";
|
|
21
|
+
|
|
22
|
+
export {Intermediary} from "./intermediaries/Intermediary";
|
|
23
|
+
export {IntermediaryDiscovery} from "./intermediaries/IntermediaryDiscovery";
|
|
24
|
+
|
|
25
|
+
export * from "./prices/abstract/ISwapPrice";
|
|
26
|
+
export {RedundantSwapPrice} from "./prices/RedundantSwapPrice";
|
|
27
|
+
export * from "./prices/SingleSwapPrice";
|
|
28
|
+
export * from "./prices/SwapPriceWithChain";
|
|
29
|
+
|
|
30
|
+
export {BinancePriceProvider} from "./prices/providers/BinancePriceProvider";
|
|
31
|
+
export {CoinGeckoPriceProvider} from "./prices/providers/CoinGeckoPriceProvider";
|
|
32
|
+
export {CoinPaprikaPriceProvider} from "./prices/providers/CoinPaprikaPriceProvider";
|
|
33
|
+
export {KrakenPriceProvider} from "./prices/providers/KrakenPriceProvider";
|
|
34
|
+
export {OKXPriceProvider} from "./prices/providers/OKXPriceProvider";
|
|
35
|
+
export {CustomPriceProvider} from "./prices/providers/CustomPriceProvider";
|
|
36
|
+
|
|
37
|
+
export * from "./storage/IUnifiedStorage";
|
|
38
|
+
export * from "./storage/UnifiedSwapStorage";
|
|
39
|
+
|
|
40
|
+
export {IndexedDBUnifiedStorage} from "./storage-browser/IndexedDBUnifiedStorage";
|
|
41
|
+
export * from "./storage-browser/LocalStorageManager";
|
|
42
|
+
|
|
43
|
+
export {Swapper} from "./swapper/Swapper";
|
|
44
|
+
export * from "./swapper/SwapperFactory";
|
|
45
|
+
export * from "./swapper/SwapperUtils";
|
|
46
|
+
export * from "./swapper/SwapperWithChain";
|
|
47
|
+
export * from "./swapper/SwapperWithSigner";
|
|
48
|
+
|
|
49
|
+
export {FromBTCLNSwap, FromBTCLNSwapState} from "./swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap";
|
|
50
|
+
export {FromBTCLNWrapper} from "./swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper";
|
|
51
|
+
export {FromBTCLNAutoSwap, FromBTCLNAutoSwapState} from "./swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap";
|
|
52
|
+
export {FromBTCLNAutoWrapper} from "./swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper";
|
|
53
|
+
export {FromBTCSwap, FromBTCSwapState} from "./swaps/escrow_swaps/frombtc/onchain/FromBTCSwap";
|
|
54
|
+
export {FromBTCWrapper} from "./swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper";
|
|
55
|
+
export {IFromBTCLNWrapper} from "./swaps/escrow_swaps/frombtc/IFromBTCLNWrapper";
|
|
56
|
+
export {IFromBTCSelfInitSwap} from "./swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap";
|
|
57
|
+
export {IFromBTCWrapper} from "./swaps/escrow_swaps/frombtc/IFromBTCWrapper";
|
|
58
|
+
|
|
59
|
+
export {ToBTCLNSwap} from "./swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap";
|
|
60
|
+
export {ToBTCLNWrapper} from "./swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper";
|
|
61
|
+
export {ToBTCSwap} from "./swaps/escrow_swaps/tobtc/onchain/ToBTCSwap";
|
|
62
|
+
export {ToBTCWrapper} from "./swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper";
|
|
63
|
+
export {IToBTCSwap, ToBTCSwapState} from "./swaps/escrow_swaps/tobtc/IToBTCSwap";
|
|
64
|
+
export {IToBTCWrapper} from "./swaps/escrow_swaps/tobtc/IToBTCWrapper";
|
|
65
|
+
|
|
66
|
+
export {IEscrowSelfInitSwap} from "./swaps/escrow_swaps/IEscrowSelfInitSwap";
|
|
67
|
+
export {IEscrowSwap} from "./swaps/escrow_swaps/IEscrowSwap";
|
|
68
|
+
export {IEscrowSwapWrapper} from "./swaps/escrow_swaps/IEscrowSwapWrapper";
|
|
69
|
+
|
|
70
|
+
export {SpvFromBTCSwap, SpvFromBTCSwapState} from "./swaps/spv_swaps/SpvFromBTCSwap";
|
|
71
|
+
export {SpvFromBTCWrapper} from "./swaps/spv_swaps/SpvFromBTCWrapper";
|
|
72
|
+
|
|
73
|
+
export {LnForGasSwap, LnForGasSwapState} from "./swaps/trusted/ln/LnForGasSwap";
|
|
74
|
+
export {LnForGasWrapper} from "./swaps/trusted/ln/LnForGasWrapper";
|
|
75
|
+
export {OnchainForGasSwap, OnchainForGasSwapState} from "./swaps/trusted/onchain/OnchainForGasSwap";
|
|
76
|
+
export {OnchainForGasWrapper} from "./swaps/trusted/onchain/OnchainForGasWrapper";
|
|
77
|
+
|
|
78
|
+
export * from "./swaps/IAddressSwap";
|
|
79
|
+
export * from "./swaps/IBTCWalletSwap";
|
|
80
|
+
export * from "./swaps/IClaimableSwap";
|
|
81
|
+
export * from "./swaps/IRefundableSwap";
|
|
82
|
+
export * from "./swaps/IAddressSwap";
|
|
83
|
+
export {ISwap} from "./swaps/ISwap";
|
|
84
|
+
export * from "./swaps/ISwapWithGasDrop";
|
|
85
|
+
export {ISwapWrapper} from "./swaps/ISwapWrapper";
|
|
86
|
+
|
|
87
|
+
export * from "./types/fees/Fee";
|
|
88
|
+
export * from "./types/fees/FeeBreakdown";
|
|
89
|
+
export * from "./types/fees/PercentagePPM";
|
|
90
|
+
|
|
91
|
+
export * from "./types/lnurl/LNURLPay";
|
|
92
|
+
export * from "./types/lnurl/LNURLWithdraw";
|
|
93
|
+
|
|
94
|
+
export * from "./types/AmountData";
|
|
95
|
+
export * from "./types/CustomPriceFunction";
|
|
96
|
+
export * from "./types/PriceInfoType";
|
|
97
|
+
export * from "./types/SwapExecutionAction";
|
|
98
|
+
export * from "./types/SwapWithSigner";
|
|
99
|
+
export * from "./types/Token";
|
|
100
|
+
export * from "./types/TokenAmount";
|
|
101
|
+
|
|
102
|
+
export * from "./utils/TokenUtils";
|
|
103
|
+
export * from "./utils/SwapUtils";
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
import {SwapType} from "../enums/SwapType";
|
|
2
|
+
import {SwapHandlerInfoType} from "./IntermediaryDiscovery";
|
|
3
|
+
import {ChainSwapType, SwapContract} from "@atomiqlabs/base";
|
|
4
|
+
import {LNNodeLiquidity} from "../bitcoin/LightningNetworkApi";
|
|
5
|
+
|
|
6
|
+
import {tryWithRetries} from "../utils/RetryUtils";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Services offered by an intermediary
|
|
10
|
+
* @category Pricing and LPs
|
|
11
|
+
*/
|
|
12
|
+
export type ServicesType = {
|
|
13
|
+
[key in SwapType]?: SwapHandlerInfoType
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Reputation data for an intermediary on a single chain
|
|
18
|
+
* @category Pricing and LPs
|
|
19
|
+
*/
|
|
20
|
+
export type SingleChainReputationType = {
|
|
21
|
+
[token: string]: {
|
|
22
|
+
[key in ChainSwapType]: {
|
|
23
|
+
successVolume: bigint,
|
|
24
|
+
successCount: bigint,
|
|
25
|
+
failVolume: bigint,
|
|
26
|
+
failCount: bigint,
|
|
27
|
+
coopCloseVolume: bigint,
|
|
28
|
+
coopCloseCount: bigint,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Smart chain liquidity data
|
|
35
|
+
* @category Pricing and LPs
|
|
36
|
+
*/
|
|
37
|
+
export type SCLiquidity = {
|
|
38
|
+
[token: string]: bigint
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Represents a liquidity provider/intermediary
|
|
43
|
+
* @category Pricing and LPs
|
|
44
|
+
*/
|
|
45
|
+
export class Intermediary {
|
|
46
|
+
|
|
47
|
+
readonly url: string;
|
|
48
|
+
readonly addresses: {[chainIdentifier: string]: string};
|
|
49
|
+
readonly services: ServicesType;
|
|
50
|
+
readonly swapBounds: {
|
|
51
|
+
[swapType in SwapType]?: {
|
|
52
|
+
[chainIdentifier: string]: {
|
|
53
|
+
[tokenAddress: string]: {
|
|
54
|
+
input: {
|
|
55
|
+
min?: bigint,
|
|
56
|
+
max?: bigint
|
|
57
|
+
},
|
|
58
|
+
output: {
|
|
59
|
+
min?: bigint,
|
|
60
|
+
max?: bigint
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
reputation: { [chainIdentifier: string]: SingleChainReputationType } = {};
|
|
67
|
+
liquidity: { [chainIdentifier: string]: SCLiquidity } = {};
|
|
68
|
+
lnData?: LNNodeLiquidity;
|
|
69
|
+
|
|
70
|
+
constructor(
|
|
71
|
+
url: string,
|
|
72
|
+
addresses: {[chainIdentifier: string]: string},
|
|
73
|
+
services: ServicesType,
|
|
74
|
+
reputation: { [chainIdentifier: string]: SingleChainReputationType } = {}
|
|
75
|
+
) {
|
|
76
|
+
this.url = url;
|
|
77
|
+
this.addresses = addresses;
|
|
78
|
+
this.services = services;
|
|
79
|
+
this.reputation = reputation;
|
|
80
|
+
|
|
81
|
+
this.swapBounds = {};
|
|
82
|
+
for(let _swapType in this.services) {
|
|
83
|
+
const swapType: SwapType = parseInt(_swapType);
|
|
84
|
+
const serviceInfo = this.services[swapType]!;
|
|
85
|
+
const btcBounds = {min: BigInt(serviceInfo.min), max: BigInt(serviceInfo.max)};
|
|
86
|
+
const isSend = swapType===SwapType.TO_BTC || swapType===SwapType.TO_BTCLN;
|
|
87
|
+
this.swapBounds[swapType] = {};
|
|
88
|
+
for(let chainIdentifier in serviceInfo.chainTokens) {
|
|
89
|
+
this.swapBounds[swapType]![chainIdentifier] = {};
|
|
90
|
+
for(let tokenAddress of serviceInfo.chainTokens[chainIdentifier]) {
|
|
91
|
+
this.swapBounds[swapType]![chainIdentifier][tokenAddress] = {
|
|
92
|
+
input: isSend ? {} : btcBounds,
|
|
93
|
+
output: !isSend ? {} : btcBounds,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
getSwapLimits(swapType: SwapType, chainId: string, tokenAddress: string): {input: {min?: bigint, max?: bigint}, output: {min?: bigint, max?: bigint}} | undefined {
|
|
101
|
+
return this.swapBounds[swapType]?.[chainId]?.[tokenAddress];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Returns tokens supported by the intermediary, optionally constrained to the specific swap types
|
|
106
|
+
*
|
|
107
|
+
* @param chainIdentifier
|
|
108
|
+
* @param swapTypesArr
|
|
109
|
+
* @private
|
|
110
|
+
*/
|
|
111
|
+
private getSupportedTokens(chainIdentifier: string, swapTypesArr: SwapType[] = [
|
|
112
|
+
SwapType.TO_BTC,
|
|
113
|
+
SwapType.TO_BTCLN,
|
|
114
|
+
SwapType.FROM_BTC,
|
|
115
|
+
SwapType.FROM_BTCLN,
|
|
116
|
+
SwapType.SPV_VAULT_FROM_BTC,
|
|
117
|
+
SwapType.FROM_BTCLN_AUTO
|
|
118
|
+
]): Set<string> {
|
|
119
|
+
const swapTypes = new Set(swapTypesArr);
|
|
120
|
+
let tokens: Set<string> = new Set<string>();
|
|
121
|
+
swapTypes.forEach((swapType) => {
|
|
122
|
+
const supportedTokens = this.services[swapType]?.chainTokens?.[chainIdentifier];
|
|
123
|
+
if(supportedTokens!=null) supportedTokens.forEach(token => tokens.add(token));
|
|
124
|
+
});
|
|
125
|
+
return tokens;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Fetches, returns and saves the reputation of the intermediary, either for all or just for a single token
|
|
130
|
+
*
|
|
131
|
+
* @param chainIdentifier
|
|
132
|
+
* @param swapContract
|
|
133
|
+
* @param tokens
|
|
134
|
+
* @param abortSignal
|
|
135
|
+
*/
|
|
136
|
+
async getReputation(
|
|
137
|
+
chainIdentifier: string,
|
|
138
|
+
swapContract: SwapContract<any>,
|
|
139
|
+
tokens?: string[],
|
|
140
|
+
abortSignal?: AbortSignal
|
|
141
|
+
): Promise<SingleChainReputationType> {
|
|
142
|
+
const checkReputationTokens: Set<string> = tokens==null ?
|
|
143
|
+
this.getSupportedTokens(chainIdentifier, [SwapType.TO_BTC, SwapType.TO_BTCLN]) :
|
|
144
|
+
new Set<string>(tokens);
|
|
145
|
+
|
|
146
|
+
const promises: Promise<void>[] = [];
|
|
147
|
+
const reputation: SingleChainReputationType = {};
|
|
148
|
+
for(let token of checkReputationTokens) {
|
|
149
|
+
promises.push(
|
|
150
|
+
tryWithRetries(() =>
|
|
151
|
+
swapContract.getIntermediaryReputation(this.getAddress(chainIdentifier), token),
|
|
152
|
+
undefined, undefined, abortSignal
|
|
153
|
+
).then(result => {
|
|
154
|
+
if(result!=null) reputation[token] = result;
|
|
155
|
+
})
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
await Promise.all(promises);
|
|
159
|
+
|
|
160
|
+
this.reputation ??= {};
|
|
161
|
+
this.reputation[chainIdentifier] ??= {};
|
|
162
|
+
for(let key in reputation) {
|
|
163
|
+
this.reputation[chainIdentifier][key] = reputation[key];
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return reputation;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Fetches, returns and saves the liquidity of the intermediaryfor a specific token
|
|
171
|
+
*
|
|
172
|
+
* @param chainIdentifier
|
|
173
|
+
* @param swapContract
|
|
174
|
+
* @param token
|
|
175
|
+
* @param abortSignal
|
|
176
|
+
*/
|
|
177
|
+
async getLiquidity(
|
|
178
|
+
chainIdentifier: string,
|
|
179
|
+
swapContract: SwapContract<any>,
|
|
180
|
+
token: string,
|
|
181
|
+
abortSignal?: AbortSignal
|
|
182
|
+
): Promise<bigint> {
|
|
183
|
+
const result = await tryWithRetries(
|
|
184
|
+
() => swapContract.getBalance(this.getAddress(chainIdentifier), token, true),
|
|
185
|
+
undefined, undefined, abortSignal
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
this.liquidity ??= {};
|
|
189
|
+
this.liquidity[chainIdentifier] ??= {};
|
|
190
|
+
this.liquidity[chainIdentifier][token] = result;
|
|
191
|
+
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
supportsChain(chainIdentifier: string): boolean {
|
|
196
|
+
if(this.addresses[chainIdentifier]==null) return false;
|
|
197
|
+
return this.getSupportedTokens(chainIdentifier).size!==0;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
getAddress(chainIdentifier: string) {
|
|
201
|
+
return this.addresses[chainIdentifier];
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
}
|