@atomiqlabs/sdk 7.0.12 → 8.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -29
- package/dist/SmartChainAssets.d.ts +11 -3
- package/dist/SmartChainAssets.js +7 -3
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +68 -0
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +2 -0
- package/dist/bitcoin/LightningNetworkApi.d.ts +12 -0
- package/dist/bitcoin/LightningNetworkApi.js +2 -0
- package/dist/bitcoin/coinselect2/accumulative.d.ts +6 -0
- package/dist/bitcoin/coinselect2/accumulative.js +52 -0
- package/dist/bitcoin/coinselect2/blackjack.d.ts +6 -0
- package/dist/bitcoin/coinselect2/blackjack.js +38 -0
- package/dist/bitcoin/coinselect2/index.d.ts +19 -0
- package/dist/bitcoin/coinselect2/index.js +69 -0
- package/dist/bitcoin/coinselect2/utils.d.ts +71 -0
- package/dist/bitcoin/coinselect2/utils.js +123 -0
- package/dist/bitcoin/mempool/MempoolApi.d.ts +350 -0
- package/dist/bitcoin/mempool/MempoolApi.js +311 -0
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +44 -0
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +48 -0
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +119 -0
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +361 -0
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +22 -0
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +105 -0
- package/dist/bitcoin/wallet/BitcoinWallet.d.ts +93 -0
- package/dist/bitcoin/wallet/BitcoinWallet.js +273 -0
- package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +28 -0
- package/dist/bitcoin/wallet/IBitcoinWallet.js +20 -0
- package/dist/bitcoin/wallet/MinimalBitcoinWalletInterface.d.ts +21 -0
- package/dist/bitcoin/wallet/MinimalBitcoinWalletInterface.js +2 -0
- package/dist/bitcoin/wallet/MinimalLightningNetworkWalletInterface.d.ts +7 -0
- package/dist/bitcoin/wallet/MinimalLightningNetworkWalletInterface.js +2 -0
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +40 -0
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +86 -0
- package/dist/enums/FeeType.d.ts +8 -0
- package/dist/enums/FeeType.js +12 -0
- package/dist/enums/SwapAmountType.d.ts +8 -0
- package/dist/enums/SwapAmountType.js +12 -0
- package/dist/enums/SwapDirection.d.ts +8 -0
- package/dist/enums/SwapDirection.js +12 -0
- package/dist/enums/SwapType.d.ts +14 -0
- package/dist/enums/SwapType.js +18 -0
- package/dist/errors/IntermediaryError.d.ts +9 -0
- package/dist/errors/IntermediaryError.js +26 -0
- package/dist/errors/PaymentAuthError.d.ts +11 -0
- package/dist/errors/PaymentAuthError.js +23 -0
- package/dist/errors/RequestError.d.ts +18 -0
- package/dist/errors/RequestError.js +46 -0
- package/dist/errors/UserError.d.ts +7 -0
- package/dist/errors/UserError.js +15 -0
- package/dist/events/UnifiedSwapEventListener.d.ts +23 -0
- package/dist/events/UnifiedSwapEventListener.js +130 -0
- package/dist/http/HttpUtils.d.ts +27 -0
- package/dist/http/HttpUtils.js +91 -0
- package/dist/http/paramcoders/IParamReader.d.ts +8 -0
- package/dist/http/paramcoders/IParamReader.js +2 -0
- package/dist/http/paramcoders/ParamDecoder.d.ts +44 -0
- package/dist/http/paramcoders/ParamDecoder.js +132 -0
- package/dist/http/paramcoders/ParamEncoder.d.ts +20 -0
- package/dist/http/paramcoders/ParamEncoder.js +31 -0
- package/dist/http/paramcoders/SchemaVerifier.d.ts +26 -0
- package/dist/http/paramcoders/SchemaVerifier.js +145 -0
- package/dist/http/paramcoders/client/ResponseParamDecoder.d.ts +11 -0
- package/dist/http/paramcoders/client/ResponseParamDecoder.js +57 -0
- package/dist/http/paramcoders/client/StreamParamEncoder.d.ts +13 -0
- package/dist/http/paramcoders/client/StreamParamEncoder.js +26 -0
- package/dist/http/paramcoders/client/StreamingFetchPromise.d.ts +16 -0
- package/dist/http/paramcoders/client/StreamingFetchPromise.js +174 -0
- package/dist/index.d.ts +82 -4
- package/dist/index.js +128 -4
- package/dist/intermediaries/Intermediary.d.ts +111 -0
- package/dist/intermediaries/Intermediary.js +115 -0
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +166 -0
- package/dist/intermediaries/IntermediaryDiscovery.js +390 -0
- package/dist/intermediaries/apis/IntermediaryAPI.d.ts +436 -0
- package/dist/intermediaries/apis/IntermediaryAPI.js +600 -0
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.d.ts +154 -0
- package/dist/intermediaries/apis/TrustedIntermediaryAPI.js +136 -0
- package/dist/lnurl/LNURL.d.ts +102 -0
- package/dist/lnurl/LNURL.js +321 -0
- package/dist/prices/RedundantSwapPrice.d.ts +89 -0
- package/dist/prices/RedundantSwapPrice.js +202 -0
- package/dist/prices/SingleSwapPrice.d.ts +31 -0
- package/dist/prices/SingleSwapPrice.js +41 -0
- package/dist/prices/SwapPriceWithChain.d.ts +70 -0
- package/dist/prices/SwapPriceWithChain.js +91 -0
- package/dist/prices/abstract/ICachedSwapPrice.d.ts +28 -0
- package/dist/prices/abstract/ICachedSwapPrice.js +62 -0
- package/dist/prices/abstract/IPriceProvider.d.ts +81 -0
- package/dist/prices/abstract/IPriceProvider.js +74 -0
- package/dist/prices/abstract/ISwapPrice.d.ts +117 -0
- package/dist/prices/abstract/ISwapPrice.js +219 -0
- package/dist/prices/providers/BinancePriceProvider.d.ts +16 -0
- package/dist/prices/providers/BinancePriceProvider.js +23 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +17 -0
- package/dist/prices/providers/CoinGeckoPriceProvider.js +23 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +19 -0
- package/dist/prices/providers/CoinPaprikaPriceProvider.js +23 -0
- package/dist/prices/providers/CustomPriceProvider.d.ts +13 -0
- package/dist/prices/providers/CustomPriceProvider.js +24 -0
- package/dist/prices/providers/KrakenPriceProvider.d.ts +29 -0
- package/dist/prices/providers/KrakenPriceProvider.js +36 -0
- package/dist/prices/providers/OKXPriceProvider.d.ts +28 -0
- package/dist/prices/providers/OKXPriceProvider.js +23 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +14 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.js +18 -0
- package/dist/prices/providers/abstract/HttpPriceProvider.d.ts +7 -0
- package/dist/prices/providers/abstract/HttpPriceProvider.js +12 -0
- package/dist/storage/IUnifiedStorage.d.ts +73 -0
- package/dist/storage/IUnifiedStorage.js +2 -0
- package/dist/storage/UnifiedSwapStorage.d.ts +82 -0
- package/dist/storage/UnifiedSwapStorage.js +83 -0
- package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +39 -0
- package/dist/storage-browser/IndexedDBUnifiedStorage.js +275 -0
- package/dist/{storage → storage-browser}/LocalStorageManager.d.ts +1 -0
- package/dist/{storage → storage-browser}/LocalStorageManager.js +2 -1
- package/dist/swapper/Swapper.d.ts +533 -0
- package/dist/swapper/Swapper.js +1566 -0
- package/dist/swapper/SwapperFactory.d.ts +87 -0
- package/dist/{SwapperFactory.js → swapper/SwapperFactory.js} +37 -19
- package/dist/swapper/SwapperUtils.d.ts +153 -0
- package/dist/swapper/SwapperUtils.js +420 -0
- package/dist/swapper/SwapperWithChain.d.ts +214 -0
- package/dist/swapper/SwapperWithChain.js +315 -0
- package/dist/swapper/SwapperWithSigner.d.ts +178 -0
- package/dist/swapper/SwapperWithSigner.js +172 -0
- package/dist/swaps/IAddressSwap.d.ts +13 -0
- package/dist/swaps/IAddressSwap.js +13 -0
- package/dist/swaps/IBTCWalletSwap.d.ts +55 -0
- package/dist/swaps/IBTCWalletSwap.js +17 -0
- package/dist/swaps/IClaimableSwap.d.ts +17 -0
- package/dist/swaps/IClaimableSwap.js +14 -0
- package/dist/swaps/IClaimableSwapWrapper.d.ts +5 -0
- package/dist/swaps/IClaimableSwapWrapper.js +2 -0
- package/dist/swaps/IRefundableSwap.d.ts +17 -0
- package/dist/swaps/IRefundableSwap.js +13 -0
- package/dist/swaps/ISwap.d.ts +207 -0
- package/dist/swaps/ISwap.js +264 -0
- package/dist/swaps/ISwapWithGasDrop.d.ts +15 -0
- package/dist/swaps/ISwapWithGasDrop.js +11 -0
- package/dist/swaps/ISwapWrapper.d.ts +153 -0
- package/dist/swaps/ISwapWrapper.js +227 -0
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +53 -0
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +116 -0
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +70 -0
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +132 -0
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +85 -0
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +122 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +86 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +115 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +93 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +121 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +45 -0
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +65 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +263 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +933 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +110 -0
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +307 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +236 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +898 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +125 -0
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +393 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +245 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +841 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +120 -0
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +294 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +228 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +721 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +37 -0
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +93 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +86 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +213 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +170 -0
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +520 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +50 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +109 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +93 -0
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +217 -0
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +315 -0
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +1098 -0
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +125 -0
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +631 -0
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +107 -0
- package/dist/swaps/trusted/ln/LnForGasSwap.js +343 -0
- package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +21 -0
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +62 -0
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +164 -0
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +520 -0
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +48 -0
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +74 -0
- package/dist/types/AmountData.d.ts +9 -0
- package/dist/types/AmountData.js +2 -0
- package/dist/types/CustomPriceFunction.d.ts +5 -0
- package/dist/types/CustomPriceFunction.js +2 -0
- package/dist/types/PriceInfoType.d.ts +28 -0
- package/dist/types/PriceInfoType.js +57 -0
- package/dist/types/SwapExecutionAction.d.ts +7 -0
- package/dist/types/SwapExecutionAction.js +2 -0
- package/dist/types/SwapWithSigner.d.ts +14 -0
- package/dist/types/SwapWithSigner.js +40 -0
- package/dist/types/Token.d.ts +53 -0
- package/dist/types/Token.js +58 -0
- package/dist/types/TokenAmount.d.ts +57 -0
- package/dist/types/TokenAmount.js +47 -0
- package/dist/types/fees/Fee.d.ts +49 -0
- package/dist/types/fees/Fee.js +2 -0
- package/dist/types/fees/FeeBreakdown.d.ts +10 -0
- package/dist/types/fees/FeeBreakdown.js +2 -0
- package/dist/types/fees/PercentagePPM.d.ts +15 -0
- package/dist/types/fees/PercentagePPM.js +17 -0
- package/dist/types/lnurl/LNURLPay.d.ts +54 -0
- package/dist/types/lnurl/LNURLPay.js +28 -0
- package/dist/types/lnurl/LNURLWithdraw.d.ts +42 -0
- package/dist/types/lnurl/LNURLWithdraw.js +24 -0
- package/dist/utils/AutomaticClockDriftCorrection.d.ts +1 -0
- package/dist/utils/AutomaticClockDriftCorrection.js +70 -0
- package/dist/utils/BitcoinUtils.d.ts +13 -0
- package/dist/utils/BitcoinUtils.js +98 -0
- package/dist/utils/BitcoinWalletUtils.d.ts +7 -0
- package/dist/utils/BitcoinWalletUtils.js +14 -0
- package/dist/utils/Logger.d.ts +7 -0
- package/dist/utils/Logger.js +12 -0
- package/dist/utils/RetryUtils.d.ts +21 -0
- package/dist/utils/RetryUtils.js +66 -0
- package/dist/utils/SwapUtils.d.ts +31 -0
- package/dist/utils/SwapUtils.js +18 -0
- package/dist/{Utils.d.ts → utils/TimeoutUtils.d.ts} +9 -3
- package/dist/utils/TimeoutUtils.js +55 -0
- package/dist/utils/TokenUtils.d.ts +11 -0
- package/dist/utils/TokenUtils.js +29 -0
- package/dist/utils/TypeUtils.d.ts +7 -0
- package/dist/utils/TypeUtils.js +2 -0
- package/dist/utils/Utils.d.ts +57 -0
- package/dist/utils/Utils.js +178 -0
- package/package.json +14 -6
- package/src/SmartChainAssets.ts +11 -3
- package/src/bitcoin/BitcoinRpcWithAddressIndex.ts +87 -0
- package/src/bitcoin/LightningNetworkApi.ts +16 -0
- package/src/bitcoin/coinselect2/accumulative.ts +68 -0
- package/src/bitcoin/coinselect2/blackjack.ts +49 -0
- package/src/bitcoin/coinselect2/index.ts +92 -0
- package/src/bitcoin/coinselect2/utils.ts +189 -0
- package/src/bitcoin/mempool/MempoolApi.ts +554 -0
- package/src/bitcoin/mempool/MempoolBitcoinBlock.ts +88 -0
- package/src/bitcoin/mempool/MempoolBitcoinRpc.ts +437 -0
- package/src/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.ts +134 -0
- package/src/bitcoin/wallet/BitcoinWallet.ts +375 -0
- package/src/bitcoin/wallet/IBitcoinWallet.ts +44 -0
- package/src/bitcoin/wallet/MinimalBitcoinWalletInterface.ts +19 -0
- package/src/bitcoin/wallet/MinimalLightningNetworkWalletInterface.ts +7 -0
- package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +108 -0
- package/src/enums/FeeType.ts +9 -0
- package/src/enums/SwapAmountType.ts +9 -0
- package/src/enums/SwapDirection.ts +9 -0
- package/src/enums/SwapType.ts +15 -0
- package/src/errors/IntermediaryError.ts +24 -0
- package/src/errors/PaymentAuthError.ts +26 -0
- package/src/errors/RequestError.ts +51 -0
- package/src/errors/UserError.ts +14 -0
- package/src/events/UnifiedSwapEventListener.ts +171 -0
- package/src/http/HttpUtils.ts +92 -0
- package/src/http/paramcoders/IParamReader.ts +10 -0
- package/src/http/paramcoders/ParamDecoder.ts +142 -0
- package/src/http/paramcoders/ParamEncoder.ts +37 -0
- package/src/http/paramcoders/SchemaVerifier.ts +153 -0
- package/src/http/paramcoders/client/ResponseParamDecoder.ts +58 -0
- package/src/http/paramcoders/client/StreamParamEncoder.ts +29 -0
- package/src/http/paramcoders/client/StreamingFetchPromise.ts +193 -0
- package/src/index.ts +102 -4
- package/src/intermediaries/Intermediary.ts +204 -0
- package/src/intermediaries/IntermediaryDiscovery.ts +485 -0
- package/src/intermediaries/apis/IntermediaryAPI.ts +940 -0
- package/src/intermediaries/apis/TrustedIntermediaryAPI.ts +257 -0
- package/src/lnurl/LNURL.ts +403 -0
- package/src/prices/RedundantSwapPrice.ts +245 -0
- package/src/prices/SingleSwapPrice.ts +47 -0
- package/src/prices/SwapPriceWithChain.ts +157 -0
- package/src/prices/abstract/ICachedSwapPrice.ts +86 -0
- package/src/prices/abstract/IPriceProvider.ts +128 -0
- package/src/prices/abstract/ISwapPrice.ts +328 -0
- package/src/prices/providers/BinancePriceProvider.ts +41 -0
- package/src/prices/providers/CoinGeckoPriceProvider.ts +40 -0
- package/src/prices/providers/CoinPaprikaPriceProvider.ts +44 -0
- package/src/prices/providers/CustomPriceProvider.ts +29 -0
- package/src/prices/providers/KrakenPriceProvider.ts +74 -0
- package/src/prices/providers/OKXPriceProvider.ts +53 -0
- package/src/prices/providers/abstract/ExchangePriceProvider.ts +29 -0
- package/src/prices/providers/abstract/HttpPriceProvider.ts +15 -0
- package/src/storage/IUnifiedStorage.ts +83 -0
- package/src/storage/UnifiedSwapStorage.ts +104 -0
- package/src/storage-browser/IndexedDBUnifiedStorage.ts +328 -0
- package/src/{storage → storage-browser}/LocalStorageManager.ts +2 -1
- package/src/swapper/Swapper.ts +2107 -0
- package/src/{SwapperFactory.ts → swapper/SwapperFactory.ts} +113 -72
- package/src/swapper/SwapperUtils.ts +510 -0
- package/src/swapper/SwapperWithChain.ts +464 -0
- package/src/swapper/SwapperWithSigner.ts +300 -0
- package/src/swaps/IAddressSwap.ts +20 -0
- package/src/swaps/IBTCWalletSwap.ts +77 -0
- package/src/swaps/IClaimableSwap.ts +30 -0
- package/src/swaps/IClaimableSwapWrapper.ts +9 -0
- package/src/swaps/IRefundableSwap.ts +29 -0
- package/src/swaps/ISwap.ts +490 -0
- package/src/swaps/ISwapWithGasDrop.ts +19 -0
- package/src/swaps/ISwapWrapper.ts +344 -0
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +168 -0
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +197 -0
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +210 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +150 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +219 -0
- package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +84 -0
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +1082 -0
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +429 -0
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +1078 -0
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +549 -0
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +974 -0
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +443 -0
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +860 -0
- package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +104 -0
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +256 -0
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +716 -0
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +151 -0
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +299 -0
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +1394 -0
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +796 -0
- package/src/swaps/trusted/ln/LnForGasSwap.ts +402 -0
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +70 -0
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +633 -0
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +110 -0
- package/src/types/AmountData.ts +9 -0
- package/src/types/CustomPriceFunction.ts +5 -0
- package/src/types/PriceInfoType.ts +67 -0
- package/src/types/SwapExecutionAction.ts +8 -0
- package/src/types/SwapWithSigner.ts +57 -0
- package/src/types/Token.ts +90 -0
- package/src/types/TokenAmount.ts +110 -0
- package/src/types/fees/Fee.ts +55 -0
- package/src/types/fees/FeeBreakdown.ts +11 -0
- package/src/types/fees/PercentagePPM.ts +24 -0
- package/src/types/lnurl/LNURLPay.ts +72 -0
- package/src/types/lnurl/LNURLWithdraw.ts +55 -0
- package/src/utils/AutomaticClockDriftCorrection.ts +71 -0
- package/src/utils/BitcoinUtils.ts +86 -0
- package/src/utils/BitcoinWalletUtils.ts +16 -0
- package/src/utils/Logger.ts +15 -0
- package/src/utils/RetryUtils.ts +71 -0
- package/src/utils/SwapUtils.ts +38 -0
- package/src/utils/TimeoutUtils.ts +50 -0
- package/src/utils/TokenUtils.ts +25 -0
- package/src/utils/TypeUtils.ts +9 -0
- package/src/utils/Utils.ts +182 -0
- package/dist/SwapperFactory.d.ts +0 -52
- package/dist/Utils.js +0 -37
- package/dist/fs-storage/FileSystemStorageManager.d.ts +0 -15
- package/dist/fs-storage/FileSystemStorageManager.js +0 -60
- package/dist/fs-storage/index.d.ts +0 -1
- package/dist/fs-storage/index.js +0 -17
- package/src/SmartChainAssets.js +0 -75
- package/src/SwapperFactory.js +0 -120
- package/src/Utils.js +0 -37
- package/src/Utils.ts +0 -31
- package/src/fs-storage/FileSystemStorageManager.ts +0 -71
- package/src/fs-storage/index.ts +0 -1
- package/src/index.js +0 -21
- package/src/storage/LocalStorageManager.js +0 -72
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ISwapPrice = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Abstract base class for swap pricing implementations
|
|
6
|
+
* @category Pricing and LPs
|
|
7
|
+
*/
|
|
8
|
+
class ISwapPrice {
|
|
9
|
+
constructor(maxAllowedFeeDifferencePPM) {
|
|
10
|
+
this.maxAllowedFeeDifferencePPM = maxAllowedFeeDifferencePPM;
|
|
11
|
+
}
|
|
12
|
+
getDecimalsThrowing(chainIdentifier, token) {
|
|
13
|
+
const decimals = this.getDecimals(chainIdentifier, token);
|
|
14
|
+
if (decimals == null)
|
|
15
|
+
throw new Error(`Cannot get decimal count for token ${chainIdentifier}:${token}!`);
|
|
16
|
+
return decimals;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Recomputes pricing info without fetching the current price
|
|
20
|
+
*
|
|
21
|
+
* @param chainIdentifier
|
|
22
|
+
* @param amountSats
|
|
23
|
+
* @param satsBaseFee
|
|
24
|
+
* @param feePPM
|
|
25
|
+
* @param paidToken
|
|
26
|
+
* @param token
|
|
27
|
+
*/
|
|
28
|
+
recomputePriceInfoSend(chainIdentifier, amountSats, satsBaseFee, feePPM, paidToken, token) {
|
|
29
|
+
const totalSats = (amountSats * (1000000n + feePPM) / 1000000n)
|
|
30
|
+
+ satsBaseFee;
|
|
31
|
+
const totalUSats = totalSats * 1000000n;
|
|
32
|
+
const swapPriceUSatPerToken = totalUSats * (10n ** BigInt(this.getDecimalsThrowing(chainIdentifier, token))) / paidToken;
|
|
33
|
+
return {
|
|
34
|
+
isValid: true,
|
|
35
|
+
differencePPM: 0n,
|
|
36
|
+
satsBaseFee,
|
|
37
|
+
feePPM,
|
|
38
|
+
realPriceUSatPerToken: this.shouldIgnore(chainIdentifier, token) ? undefined : swapPriceUSatPerToken,
|
|
39
|
+
swapPriceUSatPerToken
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Checks whether the swap amounts are valid given the current market rate for a given pair
|
|
44
|
+
*
|
|
45
|
+
* @param chainIdentifier
|
|
46
|
+
* @param amountSats Amount of sats (BTC) to be received from the swap
|
|
47
|
+
* @param satsBaseFee Base fee in sats (BTC) as reported by the intermediary
|
|
48
|
+
* @param feePPM PPM fee rate as reported by the intermediary
|
|
49
|
+
* @param paidToken Amount of token to be paid to the swap
|
|
50
|
+
* @param token
|
|
51
|
+
* @param abortSignal
|
|
52
|
+
* @param preFetchedPrice Already pre-fetched price
|
|
53
|
+
*/
|
|
54
|
+
async isValidAmountSend(chainIdentifier, amountSats, satsBaseFee, feePPM, paidToken, token, abortSignal, preFetchedPrice) {
|
|
55
|
+
const totalSats = (amountSats * (1000000n + feePPM) / 1000000n)
|
|
56
|
+
+ satsBaseFee;
|
|
57
|
+
const totalUSats = totalSats * 1000000n;
|
|
58
|
+
const swapPriceUSatPerToken = totalUSats * (10n ** BigInt(this.getDecimalsThrowing(chainIdentifier, token))) / paidToken;
|
|
59
|
+
if (this.shouldIgnore(chainIdentifier, token))
|
|
60
|
+
return {
|
|
61
|
+
isValid: true,
|
|
62
|
+
differencePPM: 0n,
|
|
63
|
+
satsBaseFee,
|
|
64
|
+
feePPM,
|
|
65
|
+
realPriceUSatPerToken: undefined,
|
|
66
|
+
swapPriceUSatPerToken
|
|
67
|
+
};
|
|
68
|
+
const calculatedAmtInToken = await this.getFromBtcSwapAmount(chainIdentifier, totalSats, token, abortSignal, preFetchedPrice);
|
|
69
|
+
const realPriceUSatPerToken = totalUSats * (10n ** BigInt(this.getDecimalsThrowing(chainIdentifier, token))) / calculatedAmtInToken;
|
|
70
|
+
const difference = paidToken - calculatedAmtInToken; //Will be >0 if we need to pay more than we should've
|
|
71
|
+
const differencePPM = difference * 1000000n / calculatedAmtInToken;
|
|
72
|
+
return {
|
|
73
|
+
isValid: differencePPM <= this.maxAllowedFeeDifferencePPM,
|
|
74
|
+
differencePPM,
|
|
75
|
+
satsBaseFee,
|
|
76
|
+
feePPM,
|
|
77
|
+
realPriceUSatPerToken,
|
|
78
|
+
swapPriceUSatPerToken
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Recomputes pricing info without fetching the current price
|
|
83
|
+
*
|
|
84
|
+
* @param chainIdentifier
|
|
85
|
+
* @param amountSats
|
|
86
|
+
* @param satsBaseFee
|
|
87
|
+
* @param feePPM
|
|
88
|
+
* @param receiveToken
|
|
89
|
+
* @param token
|
|
90
|
+
*/
|
|
91
|
+
recomputePriceInfoReceive(chainIdentifier, amountSats, satsBaseFee, feePPM, receiveToken, token) {
|
|
92
|
+
const totalSats = (amountSats * (1000000n - feePPM) / 1000000n)
|
|
93
|
+
- satsBaseFee;
|
|
94
|
+
const totalUSats = totalSats * 1000000n;
|
|
95
|
+
const swapPriceUSatPerToken = totalUSats * (10n ** BigInt(this.getDecimalsThrowing(chainIdentifier, token))) / receiveToken;
|
|
96
|
+
return {
|
|
97
|
+
isValid: true,
|
|
98
|
+
differencePPM: 0n,
|
|
99
|
+
satsBaseFee,
|
|
100
|
+
feePPM,
|
|
101
|
+
realPriceUSatPerToken: this.shouldIgnore(chainIdentifier, token) ? undefined : swapPriceUSatPerToken,
|
|
102
|
+
swapPriceUSatPerToken
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Checks whether the swap amounts are valid given the current market rate for a given pair
|
|
107
|
+
*
|
|
108
|
+
* @param chainIdentifier
|
|
109
|
+
* @param amountSats Amount of sats (BTC) to be paid to the swap
|
|
110
|
+
* @param satsBaseFee Base fee in sats (BTC) as reported by the intermediary
|
|
111
|
+
* @param feePPM PPM fee rate as reported by the intermediary
|
|
112
|
+
* @param receiveToken Amount of token to be received from the swap
|
|
113
|
+
* @param token
|
|
114
|
+
* @param abortSignal
|
|
115
|
+
* @param preFetchedPrice Already pre-fetched price
|
|
116
|
+
*/
|
|
117
|
+
async isValidAmountReceive(chainIdentifier, amountSats, satsBaseFee, feePPM, receiveToken, token, abortSignal, preFetchedPrice) {
|
|
118
|
+
const totalSats = (amountSats * (1000000n - feePPM) / 1000000n)
|
|
119
|
+
- satsBaseFee;
|
|
120
|
+
const totalUSats = totalSats * 1000000n;
|
|
121
|
+
const swapPriceUSatPerToken = totalUSats * (10n ** BigInt(this.getDecimalsThrowing(chainIdentifier, token))) / receiveToken;
|
|
122
|
+
if (this.shouldIgnore(chainIdentifier, token))
|
|
123
|
+
return {
|
|
124
|
+
isValid: true,
|
|
125
|
+
differencePPM: 0n,
|
|
126
|
+
satsBaseFee,
|
|
127
|
+
feePPM,
|
|
128
|
+
realPriceUSatPerToken: undefined,
|
|
129
|
+
swapPriceUSatPerToken
|
|
130
|
+
};
|
|
131
|
+
const calculatedAmtInToken = await this.getFromBtcSwapAmount(chainIdentifier, totalSats, token, abortSignal, preFetchedPrice);
|
|
132
|
+
const realPriceUSatPerToken = totalUSats * (10n ** BigInt(this.getDecimalsThrowing(chainIdentifier, token))) / calculatedAmtInToken;
|
|
133
|
+
const difference = calculatedAmtInToken - receiveToken; //Will be >0 if we receive less than we should've
|
|
134
|
+
const differencePPM = difference * 100000n / calculatedAmtInToken;
|
|
135
|
+
return {
|
|
136
|
+
isValid: differencePPM <= this.maxAllowedFeeDifferencePPM,
|
|
137
|
+
differencePPM,
|
|
138
|
+
satsBaseFee,
|
|
139
|
+
feePPM,
|
|
140
|
+
realPriceUSatPerToken,
|
|
141
|
+
swapPriceUSatPerToken
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
preFetchPrice(chainIdentifier, token, abortSignal) {
|
|
145
|
+
return this.getPrice(chainIdentifier, token, abortSignal);
|
|
146
|
+
}
|
|
147
|
+
preFetchUsdPrice(abortSignal) {
|
|
148
|
+
return this.getUsdPrice(abortSignal);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Returns amount of {toToken} that are equivalent to {fromAmount} satoshis
|
|
152
|
+
*
|
|
153
|
+
* @param chainIdentifier
|
|
154
|
+
* @param fromAmount Amount of satoshis
|
|
155
|
+
* @param toToken Token
|
|
156
|
+
* @param abortSignal
|
|
157
|
+
* @param preFetchedPrice
|
|
158
|
+
* @throws {Error} when token is not found
|
|
159
|
+
*/
|
|
160
|
+
async getFromBtcSwapAmount(chainIdentifier, fromAmount, toToken, abortSignal, preFetchedPrice) {
|
|
161
|
+
if (this.getDecimals(chainIdentifier, toToken.toString()) == null)
|
|
162
|
+
throw new Error("Token not found!");
|
|
163
|
+
const price = preFetchedPrice || await this.getPrice(chainIdentifier, toToken, abortSignal);
|
|
164
|
+
return fromAmount
|
|
165
|
+
* (10n ** BigInt(this.getDecimalsThrowing(chainIdentifier, toToken.toString())))
|
|
166
|
+
* (1000000n) //To usat
|
|
167
|
+
/ (price);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Returns amount of satoshis that are equivalent to {fromAmount} of {fromToken}
|
|
171
|
+
*
|
|
172
|
+
* @param chainIdentifier
|
|
173
|
+
* @param fromAmount Amount of the token
|
|
174
|
+
* @param fromToken Token
|
|
175
|
+
* @param abortSignal
|
|
176
|
+
* @param preFetchedPrice Pre-fetched swap price if available
|
|
177
|
+
* @throws {Error} when token is not found
|
|
178
|
+
*/
|
|
179
|
+
async getToBtcSwapAmount(chainIdentifier, fromAmount, fromToken, abortSignal, preFetchedPrice) {
|
|
180
|
+
if (this.getDecimals(chainIdentifier, fromToken.toString()) == null)
|
|
181
|
+
throw new Error("Token not found");
|
|
182
|
+
const price = preFetchedPrice || await this.getPrice(chainIdentifier, fromToken, abortSignal);
|
|
183
|
+
return fromAmount
|
|
184
|
+
* price
|
|
185
|
+
/ 1000000n
|
|
186
|
+
/ (10n ** BigInt(this.getDecimalsThrowing(chainIdentifier, fromToken.toString())));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Returns whether the token should be ignored and pricing for it not calculated
|
|
190
|
+
* @param chainIdentifier
|
|
191
|
+
* @param tokenAddress
|
|
192
|
+
* @throws {Error} if token is not found
|
|
193
|
+
*/
|
|
194
|
+
shouldIgnore(chainIdentifier, tokenAddress) {
|
|
195
|
+
const coin = this.getDecimals(chainIdentifier, tokenAddress.toString());
|
|
196
|
+
if (coin == null)
|
|
197
|
+
throw new Error("Token not found");
|
|
198
|
+
return coin === -1;
|
|
199
|
+
}
|
|
200
|
+
async getBtcUsdValue(btcSats, abortSignal, preFetchedPrice) {
|
|
201
|
+
return Number(btcSats) * (preFetchedPrice || await this.getUsdPrice(abortSignal));
|
|
202
|
+
}
|
|
203
|
+
async getTokenUsdValue(chainId, tokenAmount, token, abortSignal, preFetchedPrice) {
|
|
204
|
+
const [btcAmount, usdPrice] = await Promise.all([
|
|
205
|
+
this.getToBtcSwapAmount(chainId, tokenAmount, token, abortSignal),
|
|
206
|
+
preFetchedPrice == null ? this.preFetchUsdPrice(abortSignal) : Promise.resolve(preFetchedPrice)
|
|
207
|
+
]);
|
|
208
|
+
return Number(btcAmount) * usdPrice;
|
|
209
|
+
}
|
|
210
|
+
getUsdValue(amount, token, abortSignal, preFetchedUsdPrice) {
|
|
211
|
+
if (token.chain === "BTC") {
|
|
212
|
+
return this.getBtcUsdValue(amount, abortSignal, preFetchedUsdPrice);
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
return this.getTokenUsdValue(token.chainId, amount, token.address, abortSignal, preFetchedUsdPrice);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
exports.ISwapPrice = ISwapPrice;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CtorCoinTypes } from "../abstract/IPriceProvider";
|
|
2
|
+
import { ExchangePriceProvider } from "./abstract/ExchangePriceProvider";
|
|
3
|
+
import { MultiChain } from "../../swapper/Swapper";
|
|
4
|
+
export type BinanceResponse = {
|
|
5
|
+
symbol: string;
|
|
6
|
+
price: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Price provider using Binance exchange API
|
|
10
|
+
* @category Pricing and LPs
|
|
11
|
+
*/
|
|
12
|
+
export declare class BinancePriceProvider<T extends MultiChain> extends ExchangePriceProvider<T> {
|
|
13
|
+
constructor(coinsMap: CtorCoinTypes<T>, url?: string, httpRequestTimeout?: number);
|
|
14
|
+
protected fetchPair(pair: string, abortSignal?: AbortSignal): Promise<number>;
|
|
15
|
+
protected fetchUsdPrice(abortSignal?: AbortSignal): Promise<number>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BinancePriceProvider = void 0;
|
|
4
|
+
const ExchangePriceProvider_1 = require("./abstract/ExchangePriceProvider");
|
|
5
|
+
const HttpUtils_1 = require("../../http/HttpUtils");
|
|
6
|
+
/**
|
|
7
|
+
* Price provider using Binance exchange API
|
|
8
|
+
* @category Pricing and LPs
|
|
9
|
+
*/
|
|
10
|
+
class BinancePriceProvider extends ExchangePriceProvider_1.ExchangePriceProvider {
|
|
11
|
+
constructor(coinsMap, url = "https://api.binance.com/api/v3", httpRequestTimeout) {
|
|
12
|
+
super(coinsMap, url, httpRequestTimeout);
|
|
13
|
+
}
|
|
14
|
+
async fetchPair(pair, abortSignal) {
|
|
15
|
+
const response = await (0, HttpUtils_1.httpGet)(this.url + "/ticker/price?symbol=" + pair, this.httpRequestTimeout, abortSignal);
|
|
16
|
+
return parseFloat(response.price);
|
|
17
|
+
}
|
|
18
|
+
async fetchUsdPrice(abortSignal) {
|
|
19
|
+
const response = await (0, HttpUtils_1.httpGet)(this.url + "/ticker/price?symbol=BTCUSDC", this.httpRequestTimeout, abortSignal);
|
|
20
|
+
return parseFloat(response.price) / 100000000;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.BinancePriceProvider = BinancePriceProvider;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CoinType, CtorCoinTypes } from "../abstract/IPriceProvider";
|
|
2
|
+
import { HttpPriceProvider } from "./abstract/HttpPriceProvider";
|
|
3
|
+
import { MultiChain } from "../../swapper/Swapper";
|
|
4
|
+
export type CoinGeckoResponse<Currency extends string> = {
|
|
5
|
+
[coinId: string]: {
|
|
6
|
+
[c in Currency]: number;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Price provider using CoinGecko API
|
|
11
|
+
* @category Pricing and LPs
|
|
12
|
+
*/
|
|
13
|
+
export declare class CoinGeckoPriceProvider<T extends MultiChain> extends HttpPriceProvider<T> {
|
|
14
|
+
constructor(coinsMap: CtorCoinTypes<T>, url?: string, httpRequestTimeout?: number);
|
|
15
|
+
protected fetchPrice(token: CoinType, abortSignal?: AbortSignal): Promise<bigint>;
|
|
16
|
+
protected fetchUsdPrice(abortSignal?: AbortSignal): Promise<number>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoinGeckoPriceProvider = void 0;
|
|
4
|
+
const HttpPriceProvider_1 = require("./abstract/HttpPriceProvider");
|
|
5
|
+
const HttpUtils_1 = require("../../http/HttpUtils");
|
|
6
|
+
/**
|
|
7
|
+
* Price provider using CoinGecko API
|
|
8
|
+
* @category Pricing and LPs
|
|
9
|
+
*/
|
|
10
|
+
class CoinGeckoPriceProvider extends HttpPriceProvider_1.HttpPriceProvider {
|
|
11
|
+
constructor(coinsMap, url = "https://api.coingecko.com/api/v3", httpRequestTimeout) {
|
|
12
|
+
super(coinsMap, url, httpRequestTimeout);
|
|
13
|
+
}
|
|
14
|
+
async fetchPrice(token, abortSignal) {
|
|
15
|
+
let response = await (0, HttpUtils_1.httpGet)(this.url + "/simple/price?ids=" + token.coinId + "&vs_currencies=sats&precision=6", this.httpRequestTimeout, abortSignal);
|
|
16
|
+
return BigInt(response[token.coinId].sats * 1000000);
|
|
17
|
+
}
|
|
18
|
+
async fetchUsdPrice(abortSignal) {
|
|
19
|
+
let response = await (0, HttpUtils_1.httpGet)(this.url + "/simple/price?ids=bitcoin&vs_currencies=usd&precision=9", this.httpRequestTimeout, abortSignal);
|
|
20
|
+
return response["bitcoin"].usd / 100000000;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.CoinGeckoPriceProvider = CoinGeckoPriceProvider;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CoinType, CtorCoinTypes } from "../abstract/IPriceProvider";
|
|
2
|
+
import { HttpPriceProvider } from "./abstract/HttpPriceProvider";
|
|
3
|
+
import { MultiChain } from "../../swapper/Swapper";
|
|
4
|
+
export type CoinPaprikaResponse<Currency extends string> = {
|
|
5
|
+
quotes: {
|
|
6
|
+
[curr in Currency]: {
|
|
7
|
+
price: number;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Price provider using CoinPaprika API
|
|
13
|
+
* @category Pricing and LPs
|
|
14
|
+
*/
|
|
15
|
+
export declare class CoinPaprikaPriceProvider<T extends MultiChain> extends HttpPriceProvider<T> {
|
|
16
|
+
constructor(coinsMap: CtorCoinTypes<T>, url?: string, httpRequestTimeout?: number);
|
|
17
|
+
fetchPrice(token: CoinType, abortSignal?: AbortSignal): Promise<bigint>;
|
|
18
|
+
protected fetchUsdPrice(abortSignal?: AbortSignal): Promise<number>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CoinPaprikaPriceProvider = void 0;
|
|
4
|
+
const HttpPriceProvider_1 = require("./abstract/HttpPriceProvider");
|
|
5
|
+
const HttpUtils_1 = require("../../http/HttpUtils");
|
|
6
|
+
/**
|
|
7
|
+
* Price provider using CoinPaprika API
|
|
8
|
+
* @category Pricing and LPs
|
|
9
|
+
*/
|
|
10
|
+
class CoinPaprikaPriceProvider extends HttpPriceProvider_1.HttpPriceProvider {
|
|
11
|
+
constructor(coinsMap, url = "https://api.coinpaprika.com/v1", httpRequestTimeout) {
|
|
12
|
+
super(coinsMap, url, httpRequestTimeout);
|
|
13
|
+
}
|
|
14
|
+
async fetchPrice(token, abortSignal) {
|
|
15
|
+
const response = await (0, HttpUtils_1.httpGet)(this.url + "/tickers/" + token.coinId + "?quotes=BTC", this.httpRequestTimeout, abortSignal);
|
|
16
|
+
return BigInt(Math.floor(response.quotes.BTC.price * 100000000000000));
|
|
17
|
+
}
|
|
18
|
+
async fetchUsdPrice(abortSignal) {
|
|
19
|
+
const response = await (0, HttpUtils_1.httpGet)(this.url + "/tickers/btc-bitcoin?quotes=USD", this.httpRequestTimeout, abortSignal);
|
|
20
|
+
return response.quotes.USD.price / 100000000;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.CoinPaprikaPriceProvider = CoinPaprikaPriceProvider;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CoinType, CtorCoinTypes, IPriceProvider } from "../abstract/IPriceProvider";
|
|
2
|
+
import { MultiChain } from "../../swapper/Swapper";
|
|
3
|
+
import { CustomPriceFunction } from "../../types/CustomPriceFunction";
|
|
4
|
+
/**
|
|
5
|
+
* Price provider using custom pricing function
|
|
6
|
+
* @category Pricing and LPs
|
|
7
|
+
*/
|
|
8
|
+
export declare class CustomPriceProvider<T extends MultiChain> extends IPriceProvider<T> {
|
|
9
|
+
readonly getUsdPriceFn: CustomPriceFunction;
|
|
10
|
+
constructor(coinsMap: CtorCoinTypes<T>, getUsdPriceFn: CustomPriceFunction);
|
|
11
|
+
protected fetchPrice(token: CoinType, abortSignal?: AbortSignal): Promise<bigint>;
|
|
12
|
+
protected fetchUsdPrice(abortSignal?: AbortSignal): Promise<number>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomPriceProvider = void 0;
|
|
4
|
+
const IPriceProvider_1 = require("../abstract/IPriceProvider");
|
|
5
|
+
/**
|
|
6
|
+
* Price provider using custom pricing function
|
|
7
|
+
* @category Pricing and LPs
|
|
8
|
+
*/
|
|
9
|
+
class CustomPriceProvider extends IPriceProvider_1.IPriceProvider {
|
|
10
|
+
constructor(coinsMap, getUsdPriceFn) {
|
|
11
|
+
super(coinsMap);
|
|
12
|
+
this.getUsdPriceFn = getUsdPriceFn;
|
|
13
|
+
}
|
|
14
|
+
async fetchPrice(token, abortSignal) {
|
|
15
|
+
const [btcPrice, tokenPrice] = await this.getUsdPriceFn(["BTC", token.coinId], abortSignal);
|
|
16
|
+
const priceInBtc = tokenPrice / btcPrice;
|
|
17
|
+
return BigInt(Math.floor(priceInBtc * 100000000 * 1000000));
|
|
18
|
+
}
|
|
19
|
+
async fetchUsdPrice(abortSignal) {
|
|
20
|
+
const [btcPrice] = await this.getUsdPriceFn(["BTC"], abortSignal);
|
|
21
|
+
return btcPrice / 100000000;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.CustomPriceProvider = CustomPriceProvider;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CoinType, CtorCoinTypes } from "../abstract/IPriceProvider";
|
|
2
|
+
import { ExchangePriceProvider } from "./abstract/ExchangePriceProvider";
|
|
3
|
+
import { MultiChain } from "../../swapper/Swapper";
|
|
4
|
+
export type KrakenResponse = {
|
|
5
|
+
error: string[];
|
|
6
|
+
result: {
|
|
7
|
+
[ticker: string]: {
|
|
8
|
+
a: [string, string, string];
|
|
9
|
+
b: [string, string, string];
|
|
10
|
+
c: [string, string];
|
|
11
|
+
v: [string, string];
|
|
12
|
+
p: [string, string];
|
|
13
|
+
t: [number, number];
|
|
14
|
+
l: [string, string];
|
|
15
|
+
h: [string, string];
|
|
16
|
+
o: string;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Price provider using Kraken exchange API
|
|
22
|
+
* @category Pricing and LPs
|
|
23
|
+
*/
|
|
24
|
+
export declare class KrakenPriceProvider<T extends MultiChain> extends ExchangePriceProvider<T> {
|
|
25
|
+
constructor(coinsMap: CtorCoinTypes<T>, url?: string, httpRequestTimeout?: number);
|
|
26
|
+
protected fetchPair(pair: string, abortSignal?: AbortSignal): Promise<number>;
|
|
27
|
+
protected fetchUsdPrice(abortSignal?: AbortSignal): Promise<number>;
|
|
28
|
+
protected fetchPrice(token: CoinType, abortSignal?: AbortSignal): Promise<bigint>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KrakenPriceProvider = void 0;
|
|
4
|
+
const ExchangePriceProvider_1 = require("./abstract/ExchangePriceProvider");
|
|
5
|
+
const HttpUtils_1 = require("../../http/HttpUtils");
|
|
6
|
+
/**
|
|
7
|
+
* Price provider using Kraken exchange API
|
|
8
|
+
* @category Pricing and LPs
|
|
9
|
+
*/
|
|
10
|
+
class KrakenPriceProvider extends ExchangePriceProvider_1.ExchangePriceProvider {
|
|
11
|
+
constructor(coinsMap, url = "https://api.kraken.com/0", httpRequestTimeout) {
|
|
12
|
+
super(coinsMap, url, httpRequestTimeout);
|
|
13
|
+
}
|
|
14
|
+
async fetchPair(pair, abortSignal) {
|
|
15
|
+
const response = await (0, HttpUtils_1.httpGet)(this.url + "/public/Ticker?pair=" + pair, this.httpRequestTimeout, abortSignal);
|
|
16
|
+
return parseFloat(response.result[pair].c[0]);
|
|
17
|
+
}
|
|
18
|
+
async fetchUsdPrice(abortSignal) {
|
|
19
|
+
const response = await (0, HttpUtils_1.httpGet)(this.url + "/public/Ticker?pair=XBTUSDC", this.httpRequestTimeout, abortSignal);
|
|
20
|
+
return parseFloat(response.result["XBTUSDC"].c[0]) / 100000000;
|
|
21
|
+
}
|
|
22
|
+
async fetchPrice(token, abortSignal) {
|
|
23
|
+
const pairs = token.coinId.split(";");
|
|
24
|
+
const response = await (0, HttpUtils_1.httpGet)(this.url + "/public/Ticker?pair=" + pairs.map(val => val.startsWith("!") ? val.substring(1) : val).join(","), this.httpRequestTimeout, abortSignal);
|
|
25
|
+
const prices = pairs.map(pair => {
|
|
26
|
+
let invert = pair.startsWith("!");
|
|
27
|
+
if (invert)
|
|
28
|
+
pair = pair.substring(1);
|
|
29
|
+
const value = parseFloat(response.result[pair].c[0]);
|
|
30
|
+
return invert ? 1 / value : value;
|
|
31
|
+
});
|
|
32
|
+
const price = prices.reduce((previousValue, currentValue) => previousValue * currentValue, 1);
|
|
33
|
+
return BigInt(Math.floor(price * 100000000000000));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.KrakenPriceProvider = KrakenPriceProvider;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { CtorCoinTypes } from "../abstract/IPriceProvider";
|
|
2
|
+
import { ExchangePriceProvider } from "./abstract/ExchangePriceProvider";
|
|
3
|
+
import { MultiChain } from "../../swapper/Swapper";
|
|
4
|
+
export type OKXResponse = {
|
|
5
|
+
code: string;
|
|
6
|
+
msg: string;
|
|
7
|
+
data: [
|
|
8
|
+
{
|
|
9
|
+
instId: string;
|
|
10
|
+
idxPx: string;
|
|
11
|
+
high24h: string;
|
|
12
|
+
sodUtc0: string;
|
|
13
|
+
open24h: string;
|
|
14
|
+
low24h: string;
|
|
15
|
+
sodUtc8: string;
|
|
16
|
+
ts: string;
|
|
17
|
+
}
|
|
18
|
+
];
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Price provider using OKX exchange API
|
|
22
|
+
* @category Pricing and LPs
|
|
23
|
+
*/
|
|
24
|
+
export declare class OKXPriceProvider<T extends MultiChain> extends ExchangePriceProvider<T> {
|
|
25
|
+
constructor(coinsMap: CtorCoinTypes<T>, url?: string, httpRequestTimeout?: number);
|
|
26
|
+
fetchPair(pair: string, abortSignal?: AbortSignal): Promise<number>;
|
|
27
|
+
protected fetchUsdPrice(abortSignal?: AbortSignal): Promise<number>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OKXPriceProvider = void 0;
|
|
4
|
+
const ExchangePriceProvider_1 = require("./abstract/ExchangePriceProvider");
|
|
5
|
+
const HttpUtils_1 = require("../../http/HttpUtils");
|
|
6
|
+
/**
|
|
7
|
+
* Price provider using OKX exchange API
|
|
8
|
+
* @category Pricing and LPs
|
|
9
|
+
*/
|
|
10
|
+
class OKXPriceProvider extends ExchangePriceProvider_1.ExchangePriceProvider {
|
|
11
|
+
constructor(coinsMap, url = "https://www.okx.com/api/v5", httpRequestTimeout) {
|
|
12
|
+
super(coinsMap, url, httpRequestTimeout);
|
|
13
|
+
}
|
|
14
|
+
async fetchPair(pair, abortSignal) {
|
|
15
|
+
const response = await (0, HttpUtils_1.httpGet)(this.url + "/market/index-tickers?instId=" + pair, this.httpRequestTimeout, abortSignal);
|
|
16
|
+
return parseFloat(response.data[0].idxPx);
|
|
17
|
+
}
|
|
18
|
+
async fetchUsdPrice(abortSignal) {
|
|
19
|
+
const response = await (0, HttpUtils_1.httpGet)(this.url + "/market/index-tickers?instId=BTC-USD", this.httpRequestTimeout, abortSignal);
|
|
20
|
+
return parseFloat(response.data[0].idxPx) / 100000000;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.OKXPriceProvider = OKXPriceProvider;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { HttpPriceProvider } from "./HttpPriceProvider";
|
|
2
|
+
import { CoinType } from "../../abstract/IPriceProvider";
|
|
3
|
+
import { MultiChain } from "../../../swapper/Swapper";
|
|
4
|
+
export declare abstract class ExchangePriceProvider<T extends MultiChain> extends HttpPriceProvider<T> {
|
|
5
|
+
/**
|
|
6
|
+
* Fetches the price on the specific exchange pair
|
|
7
|
+
*
|
|
8
|
+
* @param pair
|
|
9
|
+
* @param abortSignal
|
|
10
|
+
* @protected
|
|
11
|
+
*/
|
|
12
|
+
protected abstract fetchPair(pair: string, abortSignal?: AbortSignal): Promise<number>;
|
|
13
|
+
protected fetchPrice(token: CoinType, abortSignal?: AbortSignal): Promise<bigint>;
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ExchangePriceProvider = void 0;
|
|
4
|
+
const HttpPriceProvider_1 = require("./HttpPriceProvider");
|
|
5
|
+
class ExchangePriceProvider extends HttpPriceProvider_1.HttpPriceProvider {
|
|
6
|
+
async fetchPrice(token, abortSignal) {
|
|
7
|
+
const pairs = token.coinId.split(";");
|
|
8
|
+
const prices = await Promise.all(pairs.map(pair => {
|
|
9
|
+
let invert = pair.startsWith("!");
|
|
10
|
+
if (invert)
|
|
11
|
+
pair = pair.substring(1);
|
|
12
|
+
return this.fetchPair(pair, abortSignal).then(value => invert ? 1 / value : value);
|
|
13
|
+
}));
|
|
14
|
+
const price = prices.reduce((previousValue, currentValue) => previousValue * currentValue, 1);
|
|
15
|
+
return BigInt(Math.floor(price * 100000000000000));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ExchangePriceProvider = ExchangePriceProvider;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CtorCoinTypes, IPriceProvider } from "../../abstract/IPriceProvider";
|
|
2
|
+
import { MultiChain } from "../../../swapper/Swapper";
|
|
3
|
+
export declare abstract class HttpPriceProvider<T extends MultiChain> extends IPriceProvider<T> {
|
|
4
|
+
url: string;
|
|
5
|
+
httpRequestTimeout?: number;
|
|
6
|
+
protected constructor(coinsMap: CtorCoinTypes<T>, url: string, httpRequestTimeout?: number);
|
|
7
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpPriceProvider = void 0;
|
|
4
|
+
const IPriceProvider_1 = require("../../abstract/IPriceProvider");
|
|
5
|
+
class HttpPriceProvider extends IPriceProvider_1.IPriceProvider {
|
|
6
|
+
constructor(coinsMap, url, httpRequestTimeout) {
|
|
7
|
+
super(coinsMap);
|
|
8
|
+
this.url = url;
|
|
9
|
+
this.httpRequestTimeout = httpRequestTimeout;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.HttpPriceProvider = HttpPriceProvider;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query parameters for storage operations
|
|
3
|
+
* @category Storage
|
|
4
|
+
*/
|
|
5
|
+
export type QueryParams = {
|
|
6
|
+
key: string;
|
|
7
|
+
value: any | any[];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Base type for stored objects
|
|
11
|
+
* @category Storage
|
|
12
|
+
*/
|
|
13
|
+
export type UnifiedStoredObject = {
|
|
14
|
+
id: string;
|
|
15
|
+
} & any;
|
|
16
|
+
/**
|
|
17
|
+
* Defines simple indexes (for queries that use a single key)
|
|
18
|
+
* @category Storage
|
|
19
|
+
*/
|
|
20
|
+
export type UnifiedStorageIndexes = readonly {
|
|
21
|
+
key: string;
|
|
22
|
+
type: "number" | "string" | "boolean";
|
|
23
|
+
unique: boolean;
|
|
24
|
+
nullable: boolean;
|
|
25
|
+
}[];
|
|
26
|
+
/**
|
|
27
|
+
* Defines composite indexes (for queries that use multiple keys)
|
|
28
|
+
* @category Storage
|
|
29
|
+
*/
|
|
30
|
+
export type UnifiedStorageCompositeIndexes = readonly {
|
|
31
|
+
keys: readonly string[];
|
|
32
|
+
unique: boolean;
|
|
33
|
+
}[];
|
|
34
|
+
/**
|
|
35
|
+
* Interface for unified storage implementations
|
|
36
|
+
* @category Storage
|
|
37
|
+
*/
|
|
38
|
+
export interface IUnifiedStorage<I extends UnifiedStorageIndexes, C extends UnifiedStorageCompositeIndexes> {
|
|
39
|
+
/**
|
|
40
|
+
* Initializes the storage with given indexes and composite indexes
|
|
41
|
+
* @param indexes
|
|
42
|
+
* @param compositeIndexes
|
|
43
|
+
*/
|
|
44
|
+
init(indexes: I, compositeIndexes: C): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Params are specified in the following way:
|
|
47
|
+
* - [[condition1, condition2]] - returns all rows where condition1 AND condition2 is met
|
|
48
|
+
* - [[condition1], [condition2]] - returns all rows where condition1 OR condition2 is met
|
|
49
|
+
* - [[condition1, condition2], [condition3]] - returns all rows where (condition1 AND condition2) OR condition3 is met
|
|
50
|
+
* @param params
|
|
51
|
+
*/
|
|
52
|
+
query(params: Array<Array<QueryParams>>): Promise<Array<UnifiedStoredObject>>;
|
|
53
|
+
/**
|
|
54
|
+
* Saves an object to storage, updating indexes as needed
|
|
55
|
+
* @param value - Object to save (must have an id property)
|
|
56
|
+
*/
|
|
57
|
+
save(value: UnifiedStoredObject): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Saves multiple objects to storage in a batch operation
|
|
60
|
+
* @param value - Array of objects to save
|
|
61
|
+
*/
|
|
62
|
+
saveAll(value: UnifiedStoredObject[]): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Removes an object from storage
|
|
65
|
+
* @param value - Object to remove (must have an id property)
|
|
66
|
+
*/
|
|
67
|
+
remove(value: UnifiedStoredObject): Promise<void>;
|
|
68
|
+
/**
|
|
69
|
+
* Removes multiple objects from storage in a batch operation
|
|
70
|
+
* @param value - Array of objects to remove
|
|
71
|
+
*/
|
|
72
|
+
removeAll(value: UnifiedStoredObject[]): Promise<void>;
|
|
73
|
+
}
|