@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,390 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IntermediaryDiscovery = exports.SwapHandlerType = void 0;
|
|
4
|
+
const Intermediary_1 = require("./Intermediary");
|
|
5
|
+
const SwapType_1 = require("../enums/SwapType");
|
|
6
|
+
const events_1 = require("events");
|
|
7
|
+
const buffer_1 = require("buffer");
|
|
8
|
+
const Utils_1 = require("../utils/Utils");
|
|
9
|
+
const IntermediaryAPI_1 = require("./apis/IntermediaryAPI");
|
|
10
|
+
const Logger_1 = require("../utils/Logger");
|
|
11
|
+
const HttpUtils_1 = require("../http/HttpUtils");
|
|
12
|
+
const RetryUtils_1 = require("../utils/RetryUtils");
|
|
13
|
+
/**
|
|
14
|
+
* Swap handler type enum for intermediary communication
|
|
15
|
+
* @category Pricing and LPs
|
|
16
|
+
*/
|
|
17
|
+
var SwapHandlerType;
|
|
18
|
+
(function (SwapHandlerType) {
|
|
19
|
+
SwapHandlerType["TO_BTC"] = "TO_BTC";
|
|
20
|
+
SwapHandlerType["FROM_BTC"] = "FROM_BTC";
|
|
21
|
+
SwapHandlerType["TO_BTCLN"] = "TO_BTCLN";
|
|
22
|
+
SwapHandlerType["FROM_BTCLN"] = "FROM_BTCLN";
|
|
23
|
+
SwapHandlerType["FROM_BTC_TRUSTED"] = "FROM_BTC_TRUSTED";
|
|
24
|
+
SwapHandlerType["FROM_BTCLN_TRUSTED"] = "FROM_BTCLN_TRUSTED";
|
|
25
|
+
SwapHandlerType["FROM_BTC_SPV"] = "FROM_BTC_SPV";
|
|
26
|
+
SwapHandlerType["FROM_BTCLN_AUTO"] = "FROM_BTCLN_AUTO";
|
|
27
|
+
})(SwapHandlerType = exports.SwapHandlerType || (exports.SwapHandlerType = {}));
|
|
28
|
+
/**
|
|
29
|
+
* Converts SwapHandlerType (represented as string & used in REST API communication with intermediaries) to regular
|
|
30
|
+
* SwapType
|
|
31
|
+
*
|
|
32
|
+
* @param swapHandlerType
|
|
33
|
+
*/
|
|
34
|
+
function swapHandlerTypeToSwapType(swapHandlerType) {
|
|
35
|
+
switch (swapHandlerType) {
|
|
36
|
+
case SwapHandlerType.FROM_BTC:
|
|
37
|
+
return SwapType_1.SwapType.FROM_BTC;
|
|
38
|
+
case SwapHandlerType.TO_BTC:
|
|
39
|
+
return SwapType_1.SwapType.TO_BTC;
|
|
40
|
+
case SwapHandlerType.FROM_BTCLN:
|
|
41
|
+
return SwapType_1.SwapType.FROM_BTCLN;
|
|
42
|
+
case SwapHandlerType.TO_BTCLN:
|
|
43
|
+
return SwapType_1.SwapType.TO_BTCLN;
|
|
44
|
+
case SwapHandlerType.FROM_BTC_TRUSTED:
|
|
45
|
+
return SwapType_1.SwapType.TRUSTED_FROM_BTC;
|
|
46
|
+
case SwapHandlerType.FROM_BTCLN_TRUSTED:
|
|
47
|
+
return SwapType_1.SwapType.TRUSTED_FROM_BTCLN;
|
|
48
|
+
case SwapHandlerType.FROM_BTC_SPV:
|
|
49
|
+
return SwapType_1.SwapType.SPV_VAULT_FROM_BTC;
|
|
50
|
+
case SwapHandlerType.FROM_BTCLN_AUTO:
|
|
51
|
+
return SwapType_1.SwapType.FROM_BTCLN_AUTO;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A default intermediary comparator, only takes to announced fee into consideration
|
|
56
|
+
*
|
|
57
|
+
* @param swapType
|
|
58
|
+
* @param tokenAddress
|
|
59
|
+
* @param swapAmount
|
|
60
|
+
*/
|
|
61
|
+
function getIntermediaryComparator(swapType, tokenAddress, swapAmount) {
|
|
62
|
+
if (swapType === SwapType_1.SwapType.TO_BTC) {
|
|
63
|
+
//TODO: Also take reputation into account
|
|
64
|
+
}
|
|
65
|
+
return (a, b) => {
|
|
66
|
+
const aService = a.services[swapType];
|
|
67
|
+
const bService = b.services[swapType];
|
|
68
|
+
if (aService == null && bService == null)
|
|
69
|
+
return 0;
|
|
70
|
+
if (aService == null)
|
|
71
|
+
return 1;
|
|
72
|
+
if (bService == null)
|
|
73
|
+
return -1;
|
|
74
|
+
if (swapAmount == null) {
|
|
75
|
+
return aService.swapFeePPM - bService.swapFeePPM;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const feeA = BigInt(aService.swapBaseFee) + (swapAmount * BigInt(aService.swapFeePPM) / 1000000n);
|
|
79
|
+
const feeB = BigInt(bService.swapBaseFee) + (swapAmount * BigInt(bService.swapFeePPM) / 1000000n);
|
|
80
|
+
return feeA - feeB > 0n ? 1 : feeA === feeB ? 0 : -1;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const logger = (0, Logger_1.getLogger)("IntermediaryDiscovery: ");
|
|
85
|
+
const REGISTRY_URL = "https://api.github.com/repos/adambor/SolLightning-registry/contents/registry.json?ref=main";
|
|
86
|
+
//To allow for legacy responses from not-yet updated LPs
|
|
87
|
+
const DEFAULT_CHAIN = "SOLANA";
|
|
88
|
+
/**
|
|
89
|
+
* Discovery service for available liquidity providers/intermediaries
|
|
90
|
+
* @category Pricing and LPs
|
|
91
|
+
*/
|
|
92
|
+
class IntermediaryDiscovery extends events_1.EventEmitter {
|
|
93
|
+
constructor(swapContracts, registryUrl = REGISTRY_URL, nodeUrls, httpRequestTimeout, maxWaitForOthersTimeout) {
|
|
94
|
+
super();
|
|
95
|
+
this.intermediaries = [];
|
|
96
|
+
this.swapContracts = swapContracts;
|
|
97
|
+
this.registryUrl = registryUrl;
|
|
98
|
+
this.overrideNodeUrls = nodeUrls;
|
|
99
|
+
this.httpRequestTimeout = httpRequestTimeout;
|
|
100
|
+
this.maxWaitForOthersTimeout = maxWaitForOthersTimeout;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Fetches the URLs of swap intermediaries from registry or from a pre-defined array of node urls
|
|
104
|
+
*
|
|
105
|
+
* @param abortSignal
|
|
106
|
+
*/
|
|
107
|
+
async getIntermediaryUrls(abortSignal) {
|
|
108
|
+
if (this.overrideNodeUrls != null && this.overrideNodeUrls.length > 0) {
|
|
109
|
+
return this.overrideNodeUrls;
|
|
110
|
+
}
|
|
111
|
+
const response = await (0, RetryUtils_1.tryWithRetries)(() => (0, HttpUtils_1.httpGet)(this.registryUrl, this.httpRequestTimeout, abortSignal), { maxRetries: 3, delay: 100, exponential: true });
|
|
112
|
+
const content = response.content.replace(new RegExp("\\n", "g"), "");
|
|
113
|
+
return JSON.parse(buffer_1.Buffer.from(content, "base64").toString());
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Returns data as reported by a specific node (as identified by its URL). This function is specifically made
|
|
117
|
+
* in a way, that in case the abortSignal fires AFTER the LP response was received (and during signature checking),
|
|
118
|
+
* it proceeds with the addresses it was able to verify already. Hence after calling abort, this function is guaranteed
|
|
119
|
+
* to either reject or resolve instantly.
|
|
120
|
+
*
|
|
121
|
+
* @param url
|
|
122
|
+
* @param abortSignal
|
|
123
|
+
*/
|
|
124
|
+
async getNodeInfo(url, abortSignal) {
|
|
125
|
+
const response = await (0, RetryUtils_1.tryWithRetries)(() => IntermediaryAPI_1.IntermediaryAPI.getIntermediaryInfo(url, this.httpRequestTimeout, abortSignal), { maxRetries: 3, delay: 100, exponential: true }, undefined, abortSignal);
|
|
126
|
+
abortSignal?.throwIfAborted();
|
|
127
|
+
const promises = [];
|
|
128
|
+
const addresses = {};
|
|
129
|
+
for (let chain in response.chains) {
|
|
130
|
+
if (this.swapContracts[chain] != null) {
|
|
131
|
+
promises.push((async () => {
|
|
132
|
+
const { signature, address } = response.chains[chain];
|
|
133
|
+
try {
|
|
134
|
+
await this.swapContracts[chain].isValidDataSignature(buffer_1.Buffer.from(response.envelope), signature, address);
|
|
135
|
+
addresses[chain] = address;
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
logger.warn("Failed to verify " + chain + " signature for intermediary: " + url);
|
|
139
|
+
}
|
|
140
|
+
})());
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (abortSignal != null) {
|
|
144
|
+
await Promise.race([
|
|
145
|
+
Promise.all(promises),
|
|
146
|
+
new Promise(resolve => abortSignal.addEventListener("abort", resolve))
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
await Promise.all(promises);
|
|
151
|
+
}
|
|
152
|
+
//Handle legacy responses
|
|
153
|
+
const info = JSON.parse(response.envelope);
|
|
154
|
+
for (let swapType in info.services) {
|
|
155
|
+
const serviceData = info.services[swapType];
|
|
156
|
+
if (serviceData.chainTokens == null)
|
|
157
|
+
serviceData.chainTokens = {
|
|
158
|
+
[DEFAULT_CHAIN]: serviceData.tokens
|
|
159
|
+
};
|
|
160
|
+
for (let chain in serviceData.chainTokens) {
|
|
161
|
+
if (addresses[chain] == null)
|
|
162
|
+
delete serviceData.chainTokens[chain];
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
addresses,
|
|
167
|
+
info
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Inherits abort signal logic from `getNodeInfo()`, check those function docs to better understand
|
|
172
|
+
*
|
|
173
|
+
* @param url
|
|
174
|
+
* @param abortSignal
|
|
175
|
+
* @private
|
|
176
|
+
*/
|
|
177
|
+
async loadIntermediary(url, abortSignal) {
|
|
178
|
+
try {
|
|
179
|
+
const nodeInfo = await this.getNodeInfo(url, abortSignal);
|
|
180
|
+
const services = {};
|
|
181
|
+
for (let key in nodeInfo.info.services) {
|
|
182
|
+
services[swapHandlerTypeToSwapType(key)] = nodeInfo.info.services[key];
|
|
183
|
+
}
|
|
184
|
+
return new Intermediary_1.Intermediary(url, nodeInfo.addresses, services);
|
|
185
|
+
}
|
|
186
|
+
catch (e) {
|
|
187
|
+
logger.warn("fetchIntermediaries(): Error contacting intermediary " + url + ": ", e);
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Returns the intermediary at the provided URL, either from the already fetched list of LPs or fetches the data on-demand
|
|
193
|
+
*
|
|
194
|
+
* @param url
|
|
195
|
+
* @param abortSignal
|
|
196
|
+
*/
|
|
197
|
+
getIntermediary(url, abortSignal) {
|
|
198
|
+
const foundLp = this.intermediaries.find(lp => lp.url === url);
|
|
199
|
+
if (foundLp != null)
|
|
200
|
+
return Promise.resolve(foundLp);
|
|
201
|
+
return this.loadIntermediary(url, abortSignal);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Reloads the saves a list of intermediaries
|
|
205
|
+
* @param abortSignal
|
|
206
|
+
*/
|
|
207
|
+
async reloadIntermediaries(abortSignal) {
|
|
208
|
+
//Get LP urls
|
|
209
|
+
const urls = await this.getIntermediaryUrls(abortSignal);
|
|
210
|
+
logger.debug("reloadIntermediaries(): Pinging intermediaries: ", urls.join());
|
|
211
|
+
const abortController = (0, Utils_1.extendAbortController)(abortSignal);
|
|
212
|
+
let timer;
|
|
213
|
+
const intermediaries = await Promise.all(urls.map(url => this.loadIntermediary(url, abortController.signal).then(lp => {
|
|
214
|
+
if (lp != null && timer == null)
|
|
215
|
+
timer = setTimeout(() => {
|
|
216
|
+
//Trigger abort through the abort controller, such that all underlying promises resolve instantly
|
|
217
|
+
abortController.abort();
|
|
218
|
+
}, this.maxWaitForOthersTimeout ?? 5 * 1000);
|
|
219
|
+
return lp;
|
|
220
|
+
})));
|
|
221
|
+
if (timer != null)
|
|
222
|
+
clearTimeout(timer);
|
|
223
|
+
const activeNodes = intermediaries.filter(intermediary => intermediary != null);
|
|
224
|
+
if (activeNodes.length === 0)
|
|
225
|
+
logger.error("reloadIntermediaries(): No online intermediary found! Swaps might not be possible!");
|
|
226
|
+
this.intermediaries = activeNodes;
|
|
227
|
+
this.emit("added", activeNodes);
|
|
228
|
+
logger.info("reloadIntermediaries(): Using active intermediaries: ", activeNodes.map(lp => lp.url).join());
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Initializes the discovery by fetching/reloading intermediaries
|
|
232
|
+
*
|
|
233
|
+
* @param abortSignal
|
|
234
|
+
*/
|
|
235
|
+
init(abortSignal) {
|
|
236
|
+
logger.info("init(): Initializing with registryUrl: " + this.registryUrl + " intermediary array: " + (this.overrideNodeUrls || []).join());
|
|
237
|
+
return this.reloadIntermediaries(abortSignal);
|
|
238
|
+
}
|
|
239
|
+
getMultichainSwapBounds() {
|
|
240
|
+
const bounds = {};
|
|
241
|
+
this.intermediaries.forEach(intermediary => {
|
|
242
|
+
for (let _swapType in intermediary.services) {
|
|
243
|
+
const swapType = parseInt(_swapType);
|
|
244
|
+
const swapService = intermediary.services[swapType];
|
|
245
|
+
const multichainBounds = (bounds[swapType] ??= {});
|
|
246
|
+
for (let chainId in swapService.chainTokens) {
|
|
247
|
+
multichainBounds[chainId] ??= {};
|
|
248
|
+
const tokenBounds = multichainBounds[chainId];
|
|
249
|
+
for (let token of swapService.chainTokens[chainId]) {
|
|
250
|
+
const tokenMinMax = tokenBounds[token];
|
|
251
|
+
if (tokenMinMax == null) {
|
|
252
|
+
tokenBounds[token] = {
|
|
253
|
+
min: BigInt(swapService.min),
|
|
254
|
+
max: BigInt(swapService.max)
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
tokenMinMax.min = (0, Utils_1.bigIntMin)(tokenMinMax.min, BigInt(swapService.min));
|
|
259
|
+
tokenMinMax.max = (0, Utils_1.bigIntMax)(tokenMinMax.max, BigInt(swapService.max));
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return bounds;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Returns aggregate swap bounds (in sats - BTC) as indicated by the intermediaries
|
|
269
|
+
*/
|
|
270
|
+
getSwapBounds(chainIdentifier) {
|
|
271
|
+
const bounds = {};
|
|
272
|
+
this.intermediaries.forEach(intermediary => {
|
|
273
|
+
for (let _swapType in intermediary.services) {
|
|
274
|
+
const swapType = parseInt(_swapType);
|
|
275
|
+
const swapService = intermediary.services[swapType];
|
|
276
|
+
const tokenBounds = (bounds[swapType] ??= {});
|
|
277
|
+
if (swapService.chainTokens != null && swapService.chainTokens[chainIdentifier] != null) {
|
|
278
|
+
for (let token of swapService.chainTokens[chainIdentifier]) {
|
|
279
|
+
const tokenMinMax = tokenBounds[token];
|
|
280
|
+
if (tokenMinMax == null) {
|
|
281
|
+
tokenBounds[token] = {
|
|
282
|
+
min: BigInt(swapService.min),
|
|
283
|
+
max: BigInt(swapService.max)
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
tokenMinMax.min = (0, Utils_1.bigIntMin)(tokenMinMax.min, BigInt(swapService.min));
|
|
288
|
+
tokenMinMax.max = (0, Utils_1.bigIntMax)(tokenMinMax.max, BigInt(swapService.max));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
return bounds;
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Returns the aggregate swap minimum (in sats - BTC) for a specific swap type & token
|
|
298
|
+
* as indicated by the intermediaries
|
|
299
|
+
*
|
|
300
|
+
* @param chainIdentifier
|
|
301
|
+
* @param swapType
|
|
302
|
+
* @param token
|
|
303
|
+
*/
|
|
304
|
+
getSwapMinimum(chainIdentifier, swapType, token) {
|
|
305
|
+
const tokenStr = token.toString();
|
|
306
|
+
return this.intermediaries.reduce((prevMin, intermediary) => {
|
|
307
|
+
const swapService = intermediary.services[swapType];
|
|
308
|
+
if (swapService == null)
|
|
309
|
+
return prevMin;
|
|
310
|
+
const chainTokens = swapService.chainTokens?.[chainIdentifier];
|
|
311
|
+
if (chainTokens == null)
|
|
312
|
+
return prevMin;
|
|
313
|
+
if (!chainTokens.includes(tokenStr))
|
|
314
|
+
return prevMin;
|
|
315
|
+
return prevMin == null ? swapService.min : Math.min(prevMin, swapService.min);
|
|
316
|
+
}, null);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Returns the aggregate swap maximum (in sats - BTC) for a specific swap type & token
|
|
320
|
+
* as indicated by the intermediaries
|
|
321
|
+
*
|
|
322
|
+
* @param chainIdentifier
|
|
323
|
+
* @param swapType
|
|
324
|
+
* @param token
|
|
325
|
+
*/
|
|
326
|
+
getSwapMaximum(chainIdentifier, swapType, token) {
|
|
327
|
+
const tokenStr = token.toString();
|
|
328
|
+
return this.intermediaries.reduce((prevMax, intermediary) => {
|
|
329
|
+
const swapService = intermediary.services[swapType];
|
|
330
|
+
if (swapService == null)
|
|
331
|
+
return prevMax;
|
|
332
|
+
const chainTokens = swapService.chainTokens?.[chainIdentifier];
|
|
333
|
+
if (chainTokens == null)
|
|
334
|
+
return prevMax;
|
|
335
|
+
if (!chainTokens.includes(tokenStr))
|
|
336
|
+
return prevMax;
|
|
337
|
+
return prevMax == null ? swapService.max : Math.max(prevMax, swapService.max);
|
|
338
|
+
}, null);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Returns swap candidates for a specific swap type & token address
|
|
342
|
+
*
|
|
343
|
+
* @param chainIdentifier
|
|
344
|
+
* @param swapType
|
|
345
|
+
* @param tokenAddress
|
|
346
|
+
* @param amount Amount to be swapped in sats - BTC
|
|
347
|
+
* @param count How many intermediaries to return at most
|
|
348
|
+
*/
|
|
349
|
+
getSwapCandidates(chainIdentifier, swapType, tokenAddress, amount, count) {
|
|
350
|
+
const candidates = this.intermediaries.filter(e => {
|
|
351
|
+
const swapService = e.services[swapType];
|
|
352
|
+
if (swapService == null)
|
|
353
|
+
return false;
|
|
354
|
+
if (amount != null && amount < BigInt(swapService.min))
|
|
355
|
+
return false;
|
|
356
|
+
if (amount != null && amount > BigInt(swapService.max))
|
|
357
|
+
return false;
|
|
358
|
+
if (swapService.chainTokens == null)
|
|
359
|
+
return false;
|
|
360
|
+
if (swapService.chainTokens[chainIdentifier] == null)
|
|
361
|
+
return false;
|
|
362
|
+
if (!swapService.chainTokens[chainIdentifier].includes(tokenAddress.toString()))
|
|
363
|
+
return false;
|
|
364
|
+
return true;
|
|
365
|
+
});
|
|
366
|
+
candidates.sort(getIntermediaryComparator(swapType, tokenAddress, amount));
|
|
367
|
+
if (count == null) {
|
|
368
|
+
return candidates;
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
return candidates.slice(0, count);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Removes a specific intermediary from the list of active intermediaries (used for blacklisting)
|
|
376
|
+
*
|
|
377
|
+
* @param intermediary
|
|
378
|
+
*/
|
|
379
|
+
removeIntermediary(intermediary) {
|
|
380
|
+
const index = this.intermediaries.indexOf(intermediary);
|
|
381
|
+
if (index >= 0) {
|
|
382
|
+
logger.info("removeIntermediary(): Removing intermediary: " + intermediary.url);
|
|
383
|
+
this.intermediaries.splice(index, 1);
|
|
384
|
+
this.emit("removed", [intermediary]);
|
|
385
|
+
return true;
|
|
386
|
+
}
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
exports.IntermediaryDiscovery = IntermediaryDiscovery;
|