@atomiqlabs/sdk 8.1.8 → 8.3.5
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/dist/bitcoin/coinselect2/utils.d.ts +6 -0
- package/dist/bitcoin/wallet/BitcoinWallet.d.ts +41 -5
- package/dist/bitcoin/wallet/BitcoinWallet.js +36 -1
- package/dist/bitcoin/wallet/IBitcoinWallet.d.ts +52 -2
- package/dist/bitcoin/wallet/IBitcoinWallet.js +2 -1
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.d.ts +42 -7
- package/dist/bitcoin/wallet/SingleAddressBitcoinWallet.js +36 -1
- package/dist/enums/FeeType.d.ts +8 -1
- package/dist/enums/FeeType.js +8 -1
- package/dist/enums/SwapAmountType.d.ts +7 -0
- package/dist/enums/SwapAmountType.js +7 -0
- package/dist/enums/SwapDirection.d.ts +7 -0
- package/dist/enums/SwapDirection.js +7 -0
- package/dist/enums/SwapType.d.ts +62 -1
- package/dist/enums/SwapType.js +62 -1
- package/dist/errors/IntermediaryError.d.ts +4 -0
- package/dist/errors/IntermediaryError.js +1 -0
- package/dist/errors/RequestError.d.ts +15 -1
- package/dist/errors/RequestError.js +8 -0
- package/dist/errors/UserError.d.ts +1 -0
- package/dist/errors/UserError.js +1 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +7 -6
- package/dist/intermediaries/Intermediary.d.ts +61 -14
- package/dist/intermediaries/Intermediary.js +38 -11
- package/dist/intermediaries/IntermediaryDiscovery.d.ts +62 -29
- package/dist/intermediaries/IntermediaryDiscovery.js +39 -24
- package/dist/prices/RedundantSwapPrice.d.ts +26 -5
- package/dist/prices/RedundantSwapPrice.js +22 -2
- package/dist/prices/SingleSwapPrice.d.ts +10 -7
- package/dist/prices/SingleSwapPrice.js +11 -8
- package/dist/prices/SwapPriceWithChain.d.ts +56 -19
- package/dist/prices/SwapPriceWithChain.js +62 -25
- package/dist/prices/abstract/IPriceProvider.d.ts +4 -4
- package/dist/prices/abstract/IPriceProvider.js +1 -1
- package/dist/prices/abstract/ISwapPrice.d.ts +95 -46
- package/dist/prices/abstract/ISwapPrice.js +104 -56
- package/dist/prices/providers/BinancePriceProvider.d.ts +8 -1
- package/dist/prices/providers/BinancePriceProvider.js +8 -1
- package/dist/prices/providers/CoinGeckoPriceProvider.d.ts +7 -1
- package/dist/prices/providers/CoinGeckoPriceProvider.js +7 -1
- package/dist/prices/providers/CoinPaprikaPriceProvider.d.ts +7 -1
- package/dist/prices/providers/CoinPaprikaPriceProvider.js +7 -1
- package/dist/prices/providers/CustomPriceProvider.d.ts +12 -1
- package/dist/prices/providers/CustomPriceProvider.js +12 -1
- package/dist/prices/providers/KrakenPriceProvider.d.ts +10 -1
- package/dist/prices/providers/KrakenPriceProvider.js +10 -1
- package/dist/prices/providers/OKXPriceProvider.d.ts +7 -1
- package/dist/prices/providers/OKXPriceProvider.js +7 -1
- package/dist/prices/providers/abstract/ExchangePriceProvider.d.ts +3 -0
- package/dist/prices/providers/abstract/ExchangePriceProvider.js +3 -0
- package/dist/storage/IUnifiedStorage.d.ts +19 -7
- package/dist/storage/UnifiedSwapStorage.d.ts +33 -3
- package/dist/storage/UnifiedSwapStorage.js +29 -1
- package/dist/storage-browser/IndexedDBUnifiedStorage.d.ts +31 -7
- package/dist/storage-browser/IndexedDBUnifiedStorage.js +29 -6
- package/dist/storage-browser/LocalStorageManager.d.ts +25 -1
- package/dist/storage-browser/LocalStorageManager.js +25 -1
- package/dist/swapper/Swapper.d.ts +380 -226
- package/dist/swapper/Swapper.js +383 -349
- package/dist/swapper/SwapperFactory.d.ts +66 -18
- package/dist/swapper/SwapperFactory.js +24 -3
- package/dist/swapper/SwapperUtils.d.ts +75 -28
- package/dist/swapper/SwapperUtils.js +107 -60
- package/dist/swapper/SwapperWithChain.d.ts +286 -91
- package/dist/swapper/SwapperWithChain.js +218 -64
- package/dist/swapper/SwapperWithSigner.d.ts +229 -80
- package/dist/swapper/SwapperWithSigner.js +190 -44
- package/dist/swaps/IAddressSwap.d.ts +12 -3
- package/dist/swaps/IAddressSwap.js +3 -2
- package/dist/swaps/IBTCWalletSwap.d.ts +26 -8
- package/dist/swaps/IBTCWalletSwap.js +3 -2
- package/dist/swaps/IClaimableSwap.d.ts +38 -6
- package/dist/swaps/IClaimableSwap.js +3 -2
- package/dist/swaps/IClaimableSwapWrapper.d.ts +11 -1
- package/dist/swaps/IRefundableSwap.d.ts +31 -5
- package/dist/swaps/IRefundableSwap.js +3 -2
- package/dist/swaps/ISwap.d.ts +162 -24
- package/dist/swaps/ISwap.js +92 -35
- package/dist/swaps/ISwapWithGasDrop.d.ts +8 -2
- package/dist/swaps/ISwapWithGasDrop.js +2 -1
- package/dist/swaps/ISwapWrapper.d.ts +161 -52
- package/dist/swaps/ISwapWrapper.js +131 -73
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.d.ts +51 -6
- package/dist/swaps/escrow_swaps/IEscrowSelfInitSwap.js +22 -12
- package/dist/swaps/escrow_swaps/IEscrowSwap.d.ts +65 -12
- package/dist/swaps/escrow_swaps/IEscrowSwap.js +38 -19
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.d.ts +39 -9
- package/dist/swaps/escrow_swaps/IEscrowSwapWrapper.js +30 -21
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.d.ts +31 -15
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.js +33 -18
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.d.ts +97 -28
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.js +91 -27
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.d.ts +22 -9
- package/dist/swaps/escrow_swaps/frombtc/IFromBTCWrapper.js +24 -11
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.d.ts +278 -60
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.js +519 -241
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.d.ts +77 -26
- package/dist/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.js +132 -50
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.d.ts +313 -52
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.js +544 -194
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.d.ts +87 -26
- package/dist/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.js +147 -58
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.d.ts +222 -55
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.js +462 -244
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.d.ts +77 -23
- package/dist/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.js +116 -46
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.d.ts +195 -58
- package/dist/swaps/escrow_swaps/tobtc/IToBTCSwap.js +324 -191
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.d.ts +30 -5
- package/dist/swaps/escrow_swaps/tobtc/IToBTCWrapper.js +44 -19
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.d.ts +61 -20
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.js +75 -32
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.d.ts +76 -50
- package/dist/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.js +106 -101
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.d.ts +37 -14
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.js +66 -20
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.d.ts +46 -17
- package/dist/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.js +82 -27
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.d.ts +350 -88
- package/dist/swaps/spv_swaps/SpvFromBTCSwap.js +482 -215
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.d.ts +76 -24
- package/dist/swaps/spv_swaps/SpvFromBTCWrapper.js +247 -124
- package/dist/swaps/trusted/ln/LnForGasSwap.d.ts +148 -20
- package/dist/swaps/trusted/ln/LnForGasSwap.js +175 -45
- package/dist/swaps/trusted/ln/LnForGasWrapper.d.ts +29 -10
- package/dist/swaps/trusted/ln/LnForGasWrapper.js +30 -11
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.d.ts +202 -49
- package/dist/swaps/trusted/onchain/OnchainForGasSwap.js +232 -80
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.d.ts +34 -12
- package/dist/swaps/trusted/onchain/OnchainForGasWrapper.js +33 -14
- package/dist/types/AmountData.d.ts +2 -1
- package/dist/types/CustomPriceFunction.d.ts +8 -2
- package/dist/types/PriceInfoType.d.ts +4 -4
- package/dist/types/PriceInfoType.js +3 -3
- package/dist/types/SwapExecutionAction.d.ts +85 -4
- package/dist/types/SwapWithSigner.d.ts +5 -2
- package/dist/types/SwapWithSigner.js +5 -2
- package/dist/types/Token.d.ts +11 -5
- package/dist/types/Token.js +6 -3
- package/dist/types/TokenAmount.d.ts +3 -0
- package/dist/types/TokenAmount.js +2 -0
- package/dist/types/fees/Fee.d.ts +3 -2
- package/dist/types/fees/FeeBreakdown.d.ts +3 -2
- package/dist/types/fees/PercentagePPM.d.ts +4 -2
- package/dist/types/fees/PercentagePPM.js +2 -1
- package/dist/types/lnurl/LNURLPay.d.ts +20 -12
- package/dist/types/lnurl/LNURLPay.js +8 -4
- package/dist/types/lnurl/LNURLWithdraw.d.ts +17 -10
- package/dist/types/lnurl/LNURLWithdraw.js +8 -4
- package/dist/types/wallets/LightningInvoiceCreateService.d.ts +24 -0
- package/dist/types/wallets/LightningInvoiceCreateService.js +15 -0
- package/dist/types/wallets/MinimalBitcoinWalletInterface.d.ts +3 -1
- package/dist/types/wallets/MinimalLightningNetworkWalletInterface.d.ts +4 -2
- package/dist/utils/BitcoinUtils.d.ts +1 -0
- package/dist/utils/BitcoinUtils.js +5 -1
- package/dist/utils/SwapUtils.d.ts +58 -1
- package/dist/utils/SwapUtils.js +55 -1
- package/dist/utils/TokenUtils.d.ts +10 -2
- package/dist/utils/TokenUtils.js +12 -4
- package/package.json +3 -3
- package/src/bitcoin/coinselect2/utils.ts +6 -0
- package/src/bitcoin/wallet/BitcoinWallet.ts +41 -5
- package/src/bitcoin/wallet/IBitcoinWallet.ts +57 -2
- package/src/bitcoin/wallet/SingleAddressBitcoinWallet.ts +42 -6
- package/src/enums/FeeType.ts +8 -1
- package/src/enums/SwapAmountType.ts +7 -0
- package/src/enums/SwapDirection.ts +7 -0
- package/src/enums/SwapType.ts +62 -2
- package/src/errors/IntermediaryError.ts +4 -0
- package/src/errors/RequestError.ts +15 -1
- package/src/errors/UserError.ts +1 -0
- package/src/index.ts +12 -5
- package/src/intermediaries/Intermediary.ts +61 -14
- package/src/intermediaries/IntermediaryDiscovery.ts +69 -34
- package/src/prices/RedundantSwapPrice.ts +26 -6
- package/src/prices/SingleSwapPrice.ts +11 -8
- package/src/prices/SwapPriceWithChain.ts +63 -26
- package/src/prices/abstract/IPriceProvider.ts +4 -4
- package/src/prices/abstract/ISwapPrice.ts +115 -66
- package/src/prices/providers/BinancePriceProvider.ts +8 -1
- package/src/prices/providers/CoinGeckoPriceProvider.ts +7 -1
- package/src/prices/providers/CoinPaprikaPriceProvider.ts +7 -1
- package/src/prices/providers/CustomPriceProvider.ts +12 -1
- package/src/prices/providers/KrakenPriceProvider.ts +10 -1
- package/src/prices/providers/OKXPriceProvider.ts +7 -1
- package/src/prices/providers/abstract/ExchangePriceProvider.ts +3 -0
- package/src/storage/IUnifiedStorage.ts +19 -7
- package/src/storage/UnifiedSwapStorage.ts +33 -3
- package/src/storage-browser/IndexedDBUnifiedStorage.ts +31 -8
- package/src/storage-browser/LocalStorageManager.ts +25 -1
- package/src/swapper/Swapper.ts +599 -390
- package/src/swapper/SwapperFactory.ts +73 -24
- package/src/swapper/SwapperUtils.ts +107 -60
- package/src/swapper/SwapperWithChain.ts +320 -81
- package/src/swapper/SwapperWithSigner.ts +263 -56
- package/src/swaps/IAddressSwap.ts +13 -3
- package/src/swaps/IBTCWalletSwap.ts +26 -10
- package/src/swaps/IClaimableSwap.ts +41 -6
- package/src/swaps/IClaimableSwapWrapper.ts +11 -2
- package/src/swaps/IRefundableSwap.ts +34 -5
- package/src/swaps/ISwap.ts +224 -85
- package/src/swaps/ISwapWithGasDrop.ts +8 -2
- package/src/swaps/ISwapWrapper.ts +216 -98
- package/src/swaps/escrow_swaps/IEscrowSelfInitSwap.ts +64 -18
- package/src/swaps/escrow_swaps/IEscrowSwap.ts +83 -37
- package/src/swaps/escrow_swaps/IEscrowSwapWrapper.ts +61 -30
- package/src/swaps/escrow_swaps/frombtc/IFromBTCLNWrapper.ts +37 -19
- package/src/swaps/escrow_swaps/frombtc/IFromBTCSelfInitSwap.ts +123 -50
- package/src/swaps/escrow_swaps/frombtc/IFromBTCWrapper.ts +24 -11
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNSwap.ts +562 -258
- package/src/swaps/escrow_swaps/frombtc/ln/FromBTCLNWrapper.ts +156 -62
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoSwap.ts +592 -227
- package/src/swaps/escrow_swaps/frombtc/ln_auto/FromBTCLNAutoWrapper.ts +177 -74
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCSwap.ts +483 -245
- package/src/swaps/escrow_swaps/frombtc/onchain/FromBTCWrapper.ts +141 -59
- package/src/swaps/escrow_swaps/tobtc/IToBTCSwap.ts +350 -195
- package/src/swaps/escrow_swaps/tobtc/IToBTCWrapper.ts +48 -23
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNSwap.ts +87 -40
- package/src/swaps/escrow_swaps/tobtc/ln/ToBTCLNWrapper.ts +110 -110
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCSwap.ts +89 -34
- package/src/swaps/escrow_swaps/tobtc/onchain/ToBTCWrapper.ts +101 -31
- package/src/swaps/spv_swaps/SpvFromBTCSwap.ts +556 -259
- package/src/swaps/spv_swaps/SpvFromBTCWrapper.ts +292 -148
- package/src/swaps/trusted/ln/LnForGasSwap.ts +186 -47
- package/src/swaps/trusted/ln/LnForGasWrapper.ts +34 -15
- package/src/swaps/trusted/onchain/OnchainForGasSwap.ts +262 -88
- package/src/swaps/trusted/onchain/OnchainForGasWrapper.ts +41 -19
- package/src/types/AmountData.ts +2 -1
- package/src/types/CustomPriceFunction.ts +8 -2
- package/src/types/PriceInfoType.ts +4 -4
- package/src/types/SwapExecutionAction.ts +97 -5
- package/src/types/SwapWithSigner.ts +8 -4
- package/src/types/Token.ts +12 -5
- package/src/types/TokenAmount.ts +3 -0
- package/src/types/fees/Fee.ts +3 -2
- package/src/types/fees/FeeBreakdown.ts +3 -2
- package/src/types/fees/PercentagePPM.ts +4 -2
- package/src/types/lnurl/LNURLPay.ts +20 -12
- package/src/types/lnurl/LNURLWithdraw.ts +17 -10
- package/src/types/wallets/LightningInvoiceCreateService.ts +30 -0
- package/src/types/wallets/MinimalBitcoinWalletInterface.ts +3 -1
- package/src/types/wallets/MinimalLightningNetworkWalletInterface.ts +4 -2
- package/src/utils/BitcoinUtils.ts +5 -0
- package/src/utils/SwapUtils.ts +63 -1
- package/src/utils/TokenUtils.ts +12 -4
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.d.ts +0 -68
- package/dist/bitcoin/BitcoinRpcWithAddressIndex.js +0 -2
- package/dist/bitcoin/LightningNetworkApi.d.ts +0 -12
- package/dist/bitcoin/LightningNetworkApi.js +0 -2
- package/dist/bitcoin/mempool/MempoolApi.d.ts +0 -350
- package/dist/bitcoin/mempool/MempoolApi.js +0 -311
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.d.ts +0 -44
- package/dist/bitcoin/mempool/MempoolBitcoinBlock.js +0 -48
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.d.ts +0 -119
- package/dist/bitcoin/mempool/MempoolBitcoinRpc.js +0 -361
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.d.ts +0 -22
- package/dist/bitcoin/mempool/synchronizer/MempoolBtcRelaySynchronizer.js +0 -105
- package/dist/errors/PaymentAuthError.d.ts +0 -11
- package/dist/errors/PaymentAuthError.js +0 -23
- package/src/errors/PaymentAuthError.ts +0 -26
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {Intermediary, ServicesType} from "./Intermediary";
|
|
2
2
|
import {SwapType} from "../enums/SwapType";
|
|
3
|
-
import {
|
|
3
|
+
import {SwapContract} from "@atomiqlabs/base";
|
|
4
4
|
import {EventEmitter} from "events";
|
|
5
5
|
import {Buffer} from "buffer";
|
|
6
6
|
import {bigIntMax, bigIntMin, extendAbortController} from "../utils/Utils";
|
|
@@ -10,8 +10,9 @@ import {httpGet} from "../http/HttpUtils";
|
|
|
10
10
|
import {tryWithRetries} from "../utils/RetryUtils";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* Swap handler type
|
|
14
|
-
*
|
|
13
|
+
* Swap handler type mapping for intermediary communication
|
|
14
|
+
*
|
|
15
|
+
* @category LPs
|
|
15
16
|
*/
|
|
16
17
|
export enum SwapHandlerType {
|
|
17
18
|
TO_BTC = "TO_BTC",
|
|
@@ -26,7 +27,8 @@ export enum SwapHandlerType {
|
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Swap handler information type
|
|
29
|
-
*
|
|
30
|
+
*
|
|
31
|
+
* @category LPs
|
|
30
32
|
*/
|
|
31
33
|
export type SwapHandlerInfoType = {
|
|
32
34
|
swapFeePPM: number,
|
|
@@ -47,7 +49,8 @@ type InfoHandlerResponseEnvelope = {
|
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
51
|
* Token bounds (min/max) for swaps
|
|
50
|
-
*
|
|
52
|
+
*
|
|
53
|
+
* @category LPs
|
|
51
54
|
*/
|
|
52
55
|
export type TokenBounds = {
|
|
53
56
|
[token: string]: {
|
|
@@ -57,16 +60,18 @@ export type TokenBounds = {
|
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
/**
|
|
60
|
-
* Multi-chain token bounds
|
|
61
|
-
*
|
|
63
|
+
* Multi-chain token bounds (min/max) for swaps
|
|
64
|
+
*
|
|
65
|
+
* @category LPs
|
|
62
66
|
*/
|
|
63
67
|
export type MultichainTokenBounds = {
|
|
64
68
|
[chainId: string]: TokenBounds
|
|
65
69
|
}
|
|
66
70
|
|
|
67
71
|
/**
|
|
68
|
-
* Swap bounds by type
|
|
69
|
-
*
|
|
72
|
+
* Swap bounds by swap protocol type
|
|
73
|
+
*
|
|
74
|
+
* @category LPs
|
|
70
75
|
*/
|
|
71
76
|
export type SwapBounds = {
|
|
72
77
|
[key in SwapType]?: TokenBounds
|
|
@@ -74,7 +79,8 @@ export type SwapBounds = {
|
|
|
74
79
|
|
|
75
80
|
/**
|
|
76
81
|
* Multi-chain swap bounds
|
|
77
|
-
*
|
|
82
|
+
*
|
|
83
|
+
* @category LPs
|
|
78
84
|
*/
|
|
79
85
|
export type MultichainSwapBounds = {
|
|
80
86
|
[key in SwapType]?: MultichainTokenBounds
|
|
@@ -82,7 +88,7 @@ export type MultichainSwapBounds = {
|
|
|
82
88
|
|
|
83
89
|
/**
|
|
84
90
|
* Converts SwapHandlerType (represented as string & used in REST API communication with intermediaries) to regular
|
|
85
|
-
* SwapType
|
|
91
|
+
* {@link SwapType}
|
|
86
92
|
*
|
|
87
93
|
* @param swapHandlerType
|
|
88
94
|
*/
|
|
@@ -104,11 +110,13 @@ function swapHandlerTypeToSwapType(swapHandlerType: SwapHandlerType): SwapType {
|
|
|
104
110
|
return SwapType.SPV_VAULT_FROM_BTC;
|
|
105
111
|
case SwapHandlerType.FROM_BTCLN_AUTO:
|
|
106
112
|
return SwapType.FROM_BTCLN_AUTO;
|
|
113
|
+
default:
|
|
114
|
+
return SwapType.TRUSTED_FROM_BTCLN;
|
|
107
115
|
}
|
|
108
116
|
}
|
|
109
117
|
|
|
110
118
|
/**
|
|
111
|
-
* A default intermediary comparator, only takes
|
|
119
|
+
* A default intermediary comparator, only takes the announced fee into consideration
|
|
112
120
|
*
|
|
113
121
|
* @param swapType
|
|
114
122
|
* @param tokenAddress
|
|
@@ -147,22 +155,41 @@ const REGISTRY_URL = "https://api.github.com/repos/adambor/SolLightning-registry
|
|
|
147
155
|
const DEFAULT_CHAIN = "SOLANA";
|
|
148
156
|
|
|
149
157
|
/**
|
|
150
|
-
* Discovery service for available liquidity providers
|
|
151
|
-
*
|
|
158
|
+
* Discovery service for available intermediaries (liquidity providers)
|
|
159
|
+
*
|
|
160
|
+
* @category LPs
|
|
152
161
|
*/
|
|
153
162
|
export class IntermediaryDiscovery extends EventEmitter {
|
|
154
163
|
|
|
164
|
+
/**
|
|
165
|
+
* A current list of active intermediaries
|
|
166
|
+
*/
|
|
155
167
|
intermediaries: Intermediary[] = [];
|
|
156
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Swap contracts for checking intermediary signatures
|
|
171
|
+
*/
|
|
157
172
|
swapContracts: {[key: string]: SwapContract};
|
|
173
|
+
/**
|
|
174
|
+
* Registry URL used as a source for the list of intermediaries, this should be a link to a
|
|
175
|
+
* github-hosted JSON file
|
|
176
|
+
*/
|
|
158
177
|
registryUrl: string;
|
|
159
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Timeout for the HTTP handshake (/info) requests sent to the intermediaries
|
|
181
|
+
*/
|
|
160
182
|
httpRequestTimeout?: number;
|
|
161
183
|
/**
|
|
162
|
-
* Maximum time (in millis) to wait for other
|
|
184
|
+
* Maximum time (in millis) to wait for other intermediary's responses after the first one was founds
|
|
163
185
|
*/
|
|
164
186
|
maxWaitForOthersTimeout?: number;
|
|
165
187
|
|
|
188
|
+
/**
|
|
189
|
+
* The intermediary URLs passed in the constructor, to be used instead of querying the registry
|
|
190
|
+
*
|
|
191
|
+
* @private
|
|
192
|
+
*/
|
|
166
193
|
private overrideNodeUrls?: string[];
|
|
167
194
|
|
|
168
195
|
constructor(
|
|
@@ -283,9 +310,13 @@ export class IntermediaryDiscovery extends EventEmitter {
|
|
|
283
310
|
}
|
|
284
311
|
|
|
285
312
|
/**
|
|
286
|
-
* Returns the intermediary at the provided URL, either from the already fetched list of LPs
|
|
313
|
+
* Returns the intermediary at the provided URL, either from the already fetched list of LPs
|
|
314
|
+
* or fetches the data on-demand, by sending the handshake HTTP request (/info) to the LP.
|
|
287
315
|
*
|
|
288
|
-
*
|
|
316
|
+
* Doesn't save the fetched intermediary to the list of intermediaries if it isn't already
|
|
317
|
+
* part of the known intermediaries
|
|
318
|
+
*
|
|
319
|
+
* @param url Base URL of the intermediary, which accepts HTTP requests
|
|
289
320
|
* @param abortSignal
|
|
290
321
|
*/
|
|
291
322
|
getIntermediary(url: string, abortSignal?: AbortSignal): Promise<Intermediary | null> {
|
|
@@ -296,6 +327,7 @@ export class IntermediaryDiscovery extends EventEmitter {
|
|
|
296
327
|
|
|
297
328
|
/**
|
|
298
329
|
* Reloads the saves a list of intermediaries
|
|
330
|
+
*
|
|
299
331
|
* @param abortSignal
|
|
300
332
|
*/
|
|
301
333
|
async reloadIntermediaries(abortSignal?: AbortSignal): Promise<void> {
|
|
@@ -334,6 +366,9 @@ export class IntermediaryDiscovery extends EventEmitter {
|
|
|
334
366
|
return this.reloadIntermediaries(abortSignal);
|
|
335
367
|
}
|
|
336
368
|
|
|
369
|
+
/**
|
|
370
|
+
* Returns known swap bounds (in satoshis - BTC) by aggregating values from all known intermediaries
|
|
371
|
+
*/
|
|
337
372
|
getMultichainSwapBounds(): MultichainSwapBounds {
|
|
338
373
|
const bounds: MultichainSwapBounds = {};
|
|
339
374
|
|
|
@@ -366,7 +401,7 @@ export class IntermediaryDiscovery extends EventEmitter {
|
|
|
366
401
|
}
|
|
367
402
|
|
|
368
403
|
/**
|
|
369
|
-
* Returns aggregate swap bounds (in
|
|
404
|
+
* Returns aggregate swap bounds (in satoshis - BTC) as indicated by the intermediaries
|
|
370
405
|
*/
|
|
371
406
|
getSwapBounds(chainIdentifier: string): SwapBounds {
|
|
372
407
|
const bounds: SwapBounds = {};
|
|
@@ -397,15 +432,15 @@ export class IntermediaryDiscovery extends EventEmitter {
|
|
|
397
432
|
}
|
|
398
433
|
|
|
399
434
|
/**
|
|
400
|
-
* Returns the aggregate swap minimum (in
|
|
435
|
+
* Returns the aggregate swap minimum (in satoshis - BTC) for a specific swap type & token
|
|
401
436
|
* as indicated by the intermediaries
|
|
402
437
|
*
|
|
403
|
-
* @param chainIdentifier
|
|
404
|
-
* @param swapType
|
|
405
|
-
* @param
|
|
438
|
+
* @param chainIdentifier Chain identifier of the smart chain
|
|
439
|
+
* @param swapType Swap protocol type
|
|
440
|
+
* @param tokenAddress Token address
|
|
406
441
|
*/
|
|
407
|
-
getSwapMinimum(chainIdentifier: string, swapType: SwapType,
|
|
408
|
-
const tokenStr =
|
|
442
|
+
getSwapMinimum(chainIdentifier: string, swapType: SwapType, tokenAddress: string): number | null {
|
|
443
|
+
const tokenStr = tokenAddress.toString();
|
|
409
444
|
return this.intermediaries.reduce<number | null>((prevMin: number | null, intermediary: Intermediary) => {
|
|
410
445
|
const swapService = intermediary.services[swapType];
|
|
411
446
|
if(swapService==null) return prevMin;
|
|
@@ -417,15 +452,15 @@ export class IntermediaryDiscovery extends EventEmitter {
|
|
|
417
452
|
}
|
|
418
453
|
|
|
419
454
|
/**
|
|
420
|
-
* Returns the aggregate swap maximum (in
|
|
455
|
+
* Returns the aggregate swap maximum (in satoshis - BTC) for a specific swap type & token
|
|
421
456
|
* as indicated by the intermediaries
|
|
422
457
|
*
|
|
423
|
-
* @param chainIdentifier
|
|
424
|
-
* @param swapType
|
|
425
|
-
* @param
|
|
458
|
+
* @param chainIdentifier Chain identifier of the smart chain
|
|
459
|
+
* @param swapType Swap protocol type
|
|
460
|
+
* @param tokenAddress Token address
|
|
426
461
|
*/
|
|
427
|
-
getSwapMaximum(chainIdentifier: string, swapType: SwapType,
|
|
428
|
-
const tokenStr =
|
|
462
|
+
getSwapMaximum(chainIdentifier: string, swapType: SwapType, tokenAddress: string): number | null {
|
|
463
|
+
const tokenStr = tokenAddress.toString();
|
|
429
464
|
return this.intermediaries.reduce<number | null>((prevMax: number | null, intermediary: Intermediary) => {
|
|
430
465
|
const swapService = intermediary.services[swapType];
|
|
431
466
|
if(swapService==null) return prevMax;
|
|
@@ -439,13 +474,13 @@ export class IntermediaryDiscovery extends EventEmitter {
|
|
|
439
474
|
/**
|
|
440
475
|
* Returns swap candidates for a specific swap type & token address
|
|
441
476
|
*
|
|
442
|
-
* @param chainIdentifier
|
|
443
|
-
* @param swapType
|
|
444
|
-
* @param tokenAddress
|
|
477
|
+
* @param chainIdentifier Chain identifier of the smart chain
|
|
478
|
+
* @param swapType Swap protocol type
|
|
479
|
+
* @param tokenAddress Token address
|
|
445
480
|
* @param amount Amount to be swapped in sats - BTC
|
|
446
481
|
* @param count How many intermediaries to return at most
|
|
447
482
|
*/
|
|
448
|
-
getSwapCandidates(chainIdentifier: string, swapType: SwapType, tokenAddress:
|
|
483
|
+
getSwapCandidates(chainIdentifier: string, swapType: SwapType, tokenAddress: string, amount?: bigint, count?: number): Intermediary[] {
|
|
449
484
|
const candidates = this.intermediaries.filter(e => {
|
|
450
485
|
const swapService = e.services[swapType];
|
|
451
486
|
if(swapService==null) return false;
|
|
@@ -13,7 +13,8 @@ import {tryWithRetries} from "../utils/RetryUtils";
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Asset configuration for redundant swap pricing
|
|
16
|
-
*
|
|
16
|
+
*
|
|
17
|
+
* @category Pricing
|
|
17
18
|
*/
|
|
18
19
|
export type RedundantSwapPriceAssets<T extends MultiChain> = {
|
|
19
20
|
binancePair?: string,
|
|
@@ -49,10 +50,20 @@ const logger = getLogger("RedundantSwapPrice: ");
|
|
|
49
50
|
/**
|
|
50
51
|
* Swap price API using multiple price sources, handles errors on the APIs and automatically switches between them, such
|
|
51
52
|
* that there always is a functional API
|
|
52
|
-
*
|
|
53
|
+
*
|
|
54
|
+
* @category Pricing
|
|
53
55
|
*/
|
|
54
56
|
export class RedundantSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T> {
|
|
55
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new {@link RedundantSwapPrice} instance from an asset list and other data, using all
|
|
60
|
+
* the available price providers: {@link BinancePriceProvider}, {@link OKXPriceProvider},
|
|
61
|
+
* {@link CoinGeckoPriceProvider}, {@link CoinPaprikaPriceProvider}, {@link KrakenPriceProvider}
|
|
62
|
+
*
|
|
63
|
+
* @param maxAllowedFeeDiffPPM Maximum allowed price difference between returned swap prices & market prices
|
|
64
|
+
* @param assets Specifications of the assets
|
|
65
|
+
* @param cacheTimeout Timeout of the internal cache holding prices
|
|
66
|
+
*/
|
|
56
67
|
static createFromTokenMap<T extends MultiChain>(maxAllowedFeeDiffPPM: bigint, assets: RedundantSwapPriceAssets<T>, cacheTimeout?: number): RedundantSwapPrice<T> {
|
|
57
68
|
const priceApis = [
|
|
58
69
|
new BinancePriceProvider(assets.map(coinData => {
|
|
@@ -90,8 +101,8 @@ export class RedundantSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T
|
|
|
90
101
|
return new RedundantSwapPrice(maxAllowedFeeDiffPPM, assets, priceApis, cacheTimeout);
|
|
91
102
|
}
|
|
92
103
|
|
|
93
|
-
coinsDecimals: CoinDecimals<T> = {};
|
|
94
|
-
priceApis: {
|
|
104
|
+
protected coinsDecimals: CoinDecimals<T> = {};
|
|
105
|
+
protected priceApis: {
|
|
95
106
|
priceApi: IPriceProvider<T>,
|
|
96
107
|
operational?: boolean
|
|
97
108
|
}[];
|
|
@@ -174,7 +185,7 @@ export class RedundantSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T
|
|
|
174
185
|
* @param chainIdentifier
|
|
175
186
|
* @param token
|
|
176
187
|
* @param abortSignal
|
|
177
|
-
* @
|
|
188
|
+
* @protected
|
|
178
189
|
*/
|
|
179
190
|
protected fetchPrice<C extends ChainIds<T>>(chainIdentifier: C, token: string, abortSignal?: AbortSignal): Promise<bigint> {
|
|
180
191
|
return tryWithRetries(async () => {
|
|
@@ -193,12 +204,14 @@ export class RedundantSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T
|
|
|
193
204
|
}, undefined, RequestError, abortSignal);
|
|
194
205
|
}
|
|
195
206
|
|
|
207
|
+
/**
|
|
208
|
+
* @inheritDoc
|
|
209
|
+
*/
|
|
196
210
|
protected getDecimals<C extends ChainIds<T>>(chainIdentifier: C, token: string): number | null {
|
|
197
211
|
if(this.coinsDecimals[chainIdentifier]==null) return null;
|
|
198
212
|
return this.coinsDecimals[chainIdentifier]?.[token.toString()] ?? null;
|
|
199
213
|
}
|
|
200
214
|
|
|
201
|
-
|
|
202
215
|
/**
|
|
203
216
|
* Fetches BTC price in USD in parallel from multiple maybe operational price APIs
|
|
204
217
|
*
|
|
@@ -228,6 +241,13 @@ export class RedundantSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T
|
|
|
228
241
|
}
|
|
229
242
|
}
|
|
230
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Fetches the USD prices, first tries to use the operational price API (if any) and if that fails it falls back
|
|
246
|
+
* to using maybe operational price APIs
|
|
247
|
+
*
|
|
248
|
+
* @param abortSignal
|
|
249
|
+
* @protected
|
|
250
|
+
*/
|
|
231
251
|
protected fetchUsdPrice(abortSignal?: AbortSignal): Promise<number> {
|
|
232
252
|
return tryWithRetries(() => {
|
|
233
253
|
const operationalPriceApi = this.getOperationalPriceApi();
|
|
@@ -3,8 +3,9 @@ import {ICachedSwapPrice} from "./abstract/ICachedSwapPrice";
|
|
|
3
3
|
import {ChainIds, MultiChain} from "../swapper/Swapper";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Swap price API using single price source
|
|
7
|
-
*
|
|
6
|
+
* Swap price API using a single price source
|
|
7
|
+
*
|
|
8
|
+
* @category Pricing
|
|
8
9
|
*/
|
|
9
10
|
export class SingleSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T> {
|
|
10
11
|
|
|
@@ -29,17 +30,19 @@ export class SingleSwapPrice<T extends MultiChain> extends ICachedSwapPrice<T> {
|
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
|
-
*
|
|
33
|
-
* token is not found
|
|
34
|
-
*
|
|
35
|
-
* @param chainIdentifier
|
|
36
|
-
* @param token
|
|
37
|
-
* @protected
|
|
33
|
+
* @inheritDoc
|
|
38
34
|
*/
|
|
39
35
|
protected getDecimals<C extends ChainIds<T>>(chainIdentifier: C, token: string): number | null {
|
|
40
36
|
return this.priceProvider.getDecimals(chainIdentifier, token.toString());
|
|
41
37
|
}
|
|
42
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Fetches BTC price in USD
|
|
41
|
+
*
|
|
42
|
+
* @param abortSignal
|
|
43
|
+
* @protected
|
|
44
|
+
* @returns token price in uSats (micro sats)
|
|
45
|
+
*/
|
|
43
46
|
protected fetchUsdPrice(abortSignal?: AbortSignal): Promise<number> {
|
|
44
47
|
return this.priceProvider.getUsdPrice(abortSignal);
|
|
45
48
|
}
|
|
@@ -6,7 +6,8 @@ import {PriceInfoType} from "../types/PriceInfoType";
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Chain-specific wrapper for swap pricing
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
|
+
* @category Pricing
|
|
10
11
|
*/
|
|
11
12
|
export class SwapPriceWithChain<T extends MultiChain, ChainIdentifier extends ChainIds<T>> {
|
|
12
13
|
|
|
@@ -27,21 +28,21 @@ export class SwapPriceWithChain<T extends MultiChain, ChainIdentifier extends Ch
|
|
|
27
28
|
* @param satsBaseFee Base fee in sats (BTC) as reported by the intermediary
|
|
28
29
|
* @param feePPM PPM fee rate as reported by the intermediary
|
|
29
30
|
* @param paidToken Amount of token to be paid to the swap
|
|
30
|
-
* @param
|
|
31
|
-
* @param abortSignal
|
|
32
|
-
* @param preFetchedPrice
|
|
31
|
+
* @param tokenAddress Token address to be paid
|
|
32
|
+
* @param abortSignal Abort signal
|
|
33
|
+
* @param preFetchedPrice An optional price pre-fetched with {@link preFetchPrice}
|
|
33
34
|
*/
|
|
34
35
|
public async isValidAmountSend(
|
|
35
36
|
amountSats: bigint,
|
|
36
37
|
satsBaseFee: bigint,
|
|
37
38
|
feePPM: bigint,
|
|
38
39
|
paidToken: bigint,
|
|
39
|
-
|
|
40
|
+
tokenAddress: string,
|
|
40
41
|
abortSignal?: AbortSignal,
|
|
41
42
|
preFetchedPrice?: bigint
|
|
42
43
|
): Promise<PriceInfoType> {
|
|
43
44
|
return this.swapPrice.isValidAmountSend<ChainIdentifier>(
|
|
44
|
-
this.chainIdentifier, amountSats, satsBaseFee, feePPM, paidToken,
|
|
45
|
+
this.chainIdentifier, amountSats, satsBaseFee, feePPM, paidToken, tokenAddress, abortSignal, preFetchedPrice
|
|
45
46
|
);
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -52,39 +53,52 @@ export class SwapPriceWithChain<T extends MultiChain, ChainIdentifier extends Ch
|
|
|
52
53
|
* @param satsBaseFee Base fee in sats (BTC) as reported by the intermediary
|
|
53
54
|
* @param feePPM PPM fee rate as reported by the intermediary
|
|
54
55
|
* @param receiveToken Amount of token to be received from the swap
|
|
55
|
-
* @param
|
|
56
|
-
* @param abortSignal
|
|
57
|
-
* @param preFetchedPrice
|
|
56
|
+
* @param tokenAddress Token address to be received
|
|
57
|
+
* @param abortSignal Abort signal
|
|
58
|
+
* @param preFetchedPrice An optional price pre-fetched with {@link preFetchPrice}
|
|
58
59
|
*/
|
|
59
60
|
public async isValidAmountReceive(
|
|
60
61
|
amountSats: bigint,
|
|
61
62
|
satsBaseFee: bigint,
|
|
62
63
|
feePPM: bigint,
|
|
63
64
|
receiveToken: bigint,
|
|
64
|
-
|
|
65
|
+
tokenAddress: string,
|
|
65
66
|
abortSignal?: AbortSignal,
|
|
66
67
|
preFetchedPrice?: bigint
|
|
67
68
|
): Promise<PriceInfoType> {
|
|
68
69
|
return this.swapPrice.isValidAmountReceive<ChainIdentifier>(
|
|
69
|
-
this.chainIdentifier, amountSats, satsBaseFee, feePPM, receiveToken,
|
|
70
|
+
this.chainIdentifier, amountSats, satsBaseFee, feePPM, receiveToken, tokenAddress, abortSignal, preFetchedPrice
|
|
70
71
|
);
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Pre-fetches the pricing data for a given token, such that further calls to {@link isValidAmountReceive} or
|
|
76
|
+
* {@link isValidAmountSend} are quicker and don't need to wait for the price fetch
|
|
77
|
+
*
|
|
78
|
+
* @param tokenAddress Token address
|
|
79
|
+
* @param abortSignal Abort signal
|
|
80
|
+
*/
|
|
81
|
+
public preFetchPrice(tokenAddress: string, abortSignal?: AbortSignal): Promise<bigint> {
|
|
82
|
+
return this.swapPrice.preFetchPrice<ChainIdentifier>(this.chainIdentifier, tokenAddress, abortSignal);
|
|
75
83
|
}
|
|
76
84
|
|
|
85
|
+
/**
|
|
86
|
+
* Pre-fetches the Bitcoin USD price data, such that further calls to {@link getBtcUsdValue},
|
|
87
|
+
* {@link getTokenUsdValue} or {@link getUsdValue} are quicker and don't need to wait for the price fetch
|
|
88
|
+
*
|
|
89
|
+
* @param abortSignal
|
|
90
|
+
*/
|
|
77
91
|
public preFetchUsdPrice(abortSignal?: AbortSignal): Promise<number> {
|
|
78
92
|
return this.swapPrice.preFetchUsdPrice(abortSignal);
|
|
79
93
|
}
|
|
80
94
|
|
|
81
95
|
/**
|
|
82
|
-
* Returns amount of
|
|
96
|
+
* Returns amount of `toToken` that is equivalent to `fromAmount` satoshis
|
|
83
97
|
*
|
|
84
|
-
* @param fromAmount
|
|
85
|
-
* @param toToken
|
|
98
|
+
* @param fromAmount Amount of satoshis
|
|
99
|
+
* @param toToken Token address
|
|
86
100
|
* @param abortSignal
|
|
87
|
-
* @param preFetchedPrice
|
|
101
|
+
* @param preFetchedPrice An optional price pre-fetched with {@link preFetchPrice}
|
|
88
102
|
* @throws {Error} when token is not found
|
|
89
103
|
*/
|
|
90
104
|
public async getFromBtcSwapAmount(
|
|
@@ -99,12 +113,12 @@ export class SwapPriceWithChain<T extends MultiChain, ChainIdentifier extends Ch
|
|
|
99
113
|
}
|
|
100
114
|
|
|
101
115
|
/**
|
|
102
|
-
* Returns amount of satoshis that are equivalent to
|
|
116
|
+
* Returns amount of satoshis that are equivalent to `fromAmount` of `fromToken`
|
|
103
117
|
*
|
|
104
118
|
* @param fromAmount Amount of the token
|
|
105
|
-
* @param fromToken Token
|
|
119
|
+
* @param fromToken Token address
|
|
106
120
|
* @param abortSignal
|
|
107
|
-
* @param preFetchedPrice
|
|
121
|
+
* @param preFetchedPrice An optional price pre-fetched with {@link preFetchPrice}
|
|
108
122
|
* @throws {Error} when token is not found
|
|
109
123
|
*/
|
|
110
124
|
public async getToBtcSwapAmount(
|
|
@@ -121,30 +135,53 @@ export class SwapPriceWithChain<T extends MultiChain, ChainIdentifier extends Ch
|
|
|
121
135
|
/**
|
|
122
136
|
* Returns whether the token should be ignored and pricing for it not calculated
|
|
123
137
|
*
|
|
124
|
-
* @param tokenAddress
|
|
138
|
+
* @param tokenAddress Token address
|
|
125
139
|
* @throws {Error} if token is not found
|
|
126
140
|
*/
|
|
127
141
|
public shouldIgnore(tokenAddress: string): boolean {
|
|
128
142
|
return this.swapPrice.shouldIgnore<ChainIdentifier>(this.chainIdentifier, tokenAddress);
|
|
129
143
|
}
|
|
130
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Returns the USD value of the bitcoin amount
|
|
147
|
+
*
|
|
148
|
+
* @param btcSats Bitcoin amount in satoshis
|
|
149
|
+
* @param abortSignal
|
|
150
|
+
* @param preFetchedUsdPrice An optional price pre-fetched with {@link preFetchUsdPrice}
|
|
151
|
+
*/
|
|
131
152
|
public async getBtcUsdValue(
|
|
132
153
|
btcSats: bigint,
|
|
133
154
|
abortSignal?: AbortSignal,
|
|
134
|
-
|
|
155
|
+
preFetchedUsdPrice?: number
|
|
135
156
|
): Promise<number> {
|
|
136
|
-
return this.swapPrice.getBtcUsdValue(btcSats, abortSignal,
|
|
157
|
+
return this.swapPrice.getBtcUsdValue(btcSats, abortSignal, preFetchedUsdPrice);
|
|
137
158
|
}
|
|
138
159
|
|
|
160
|
+
/**
|
|
161
|
+
* Returns the USD value of the smart chain token amount
|
|
162
|
+
*
|
|
163
|
+
* @param tokenAmount Amount of the token in base units
|
|
164
|
+
* @param tokenAddress Token address
|
|
165
|
+
* @param abortSignal
|
|
166
|
+
* @param preFetchedUsdPrice An optional price pre-fetched with {@link preFetchUsdPrice}
|
|
167
|
+
*/
|
|
139
168
|
public async getTokenUsdValue(
|
|
140
169
|
tokenAmount: bigint,
|
|
141
|
-
|
|
170
|
+
tokenAddress: string,
|
|
142
171
|
abortSignal?: AbortSignal,
|
|
143
|
-
|
|
172
|
+
preFetchedUsdPrice?: number
|
|
144
173
|
): Promise<number> {
|
|
145
|
-
return this.swapPrice.getTokenUsdValue(this.chainIdentifier, tokenAmount,
|
|
174
|
+
return this.swapPrice.getTokenUsdValue(this.chainIdentifier, tokenAmount, tokenAddress, abortSignal, preFetchedUsdPrice);
|
|
146
175
|
}
|
|
147
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Returns the USD value of the token amount
|
|
179
|
+
*
|
|
180
|
+
* @param amount Amount in base units of the token
|
|
181
|
+
* @param token Token to fetch the usd price for
|
|
182
|
+
* @param abortSignal
|
|
183
|
+
* @param preFetchedUsdPrice An optional price pre-fetched with {@link preFetchUsdPrice}
|
|
184
|
+
*/
|
|
148
185
|
public getUsdValue(
|
|
149
186
|
amount: bigint,
|
|
150
187
|
token: Token<ChainIdentifier>,
|
|
@@ -2,7 +2,7 @@ import {ChainIds, MultiChain} from "../../swapper/Swapper";
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Coin type definition for price providers
|
|
5
|
-
* @category Pricing
|
|
5
|
+
* @category Pricing
|
|
6
6
|
*/
|
|
7
7
|
export type CoinType = {
|
|
8
8
|
coinId: string;
|
|
@@ -11,7 +11,7 @@ export type CoinType = {
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Constructor coin types for price providers
|
|
14
|
-
* @category Pricing
|
|
14
|
+
* @category Pricing
|
|
15
15
|
*/
|
|
16
16
|
export type CtorCoinTypes<T extends MultiChain> = {
|
|
17
17
|
coinId?: string,
|
|
@@ -25,7 +25,7 @@ export type CtorCoinTypes<T extends MultiChain> = {
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Coin types mapping by chain
|
|
28
|
-
* @category Pricing
|
|
28
|
+
* @category Pricing
|
|
29
29
|
*/
|
|
30
30
|
export type CoinTypes<T extends MultiChain> = {
|
|
31
31
|
[chainId in keyof T]?: {
|
|
@@ -35,7 +35,7 @@ export type CoinTypes<T extends MultiChain> = {
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Abstract base class for price provider implementations
|
|
38
|
-
* @category Pricing
|
|
38
|
+
* @category Pricing
|
|
39
39
|
*/
|
|
40
40
|
export abstract class IPriceProvider<T extends MultiChain> {
|
|
41
41
|
|