RedundantSwapPrice<T>
Defined in: atomiq-sdk/src/prices/RedundantSwapPrice.ts:56
Swap price API using multiple price sources, handles errors on the APIs and automatically switches between them, such that there always is a functional API
Extends
ICachedSwapPrice<T>
Type Parameters
| Type Parameter |
|---|
T extends MultiChain |
Constructors
Constructor
new RedundantSwapPrice<T>(
maxAllowedFeeDiffPPM,
coinsDecimals,
priceApis,
cacheTimeout?): RedundantSwapPrice<T>;
Defined in: atomiq-sdk/src/prices/RedundantSwapPrice.ts:110
Parameters
| Parameter | Type |
|---|---|
maxAllowedFeeDiffPPM | bigint |
coinsDecimals | CtorCoinDecimals<T> |
priceApis | IPriceProvider<T>[] |
cacheTimeout? | number |
Returns
RedundantSwapPrice<T>
Overrides
ICachedSwapPrice<T>.constructor
Properties
cache
cache: { [chainIdentifier in string | number | symbol]?: { [tokenAddress: string]: { expiry: number; price: Promise<bigint> } } } = {};
Defined in: atomiq-sdk/src/prices/abstract/ICachedSwapPrice.ts:8
Inherited from
ICachedSwapPrice.cache
cacheTimeout
cacheTimeout: number;
Defined in: atomiq-sdk/src/prices/abstract/ICachedSwapPrice.ts:20
Inherited from
ICachedSwapPrice.cacheTimeout
maxAllowedFeeDifferencePPM
maxAllowedFeeDifferencePPM: bigint;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:12
Inherited from
ICachedSwapPrice.maxAllowedFeeDifferencePPM
usdCache?
optional usdCache: object;
Defined in: atomiq-sdk/src/prices/abstract/ICachedSwapPrice.ts:16
expiry
expiry: number;
price
price: Promise<number>;
Inherited from
ICachedSwapPrice.usdCache
coinsDecimals
protected coinsDecimals: CoinDecimals<T> = {};
Defined in: atomiq-sdk/src/prices/RedundantSwapPrice.ts:104
priceApis
protected priceApis: object[];
Defined in: atomiq-sdk/src/prices/RedundantSwapPrice.ts:105
operational?
optional operational: boolean;
priceApi
priceApi: IPriceProvider<T>;
Methods
createFromTokenMap()
static createFromTokenMap<T>(
maxAllowedFeeDiffPPM,
assets,
cacheTimeout?): RedundantSwapPrice<T>;
Defined in: atomiq-sdk/src/prices/RedundantSwapPrice.ts:67
Creates a new RedundantSwapPrice instance from an asset list and other data, using all the available price providers: BinancePriceProvider, OKXPriceProvider, CoinGeckoPriceProvider, CoinPaprikaPriceProvider, KrakenPriceProvider
Type Parameters
| Type Parameter |
|---|
T extends MultiChain |
Parameters
| Parameter | Type | Description |
|---|---|---|
maxAllowedFeeDiffPPM | bigint | Maximum allowed price difference between returned swap prices & market prices |
assets | RedundantSwapPriceAssets<T> | Specifications of the assets |
cacheTimeout? | number | Timeout of the internal cache holding prices |
Returns
RedundantSwapPrice<T>
getBtcUsdValue()
getBtcUsdValue(
btcSats,
abortSignal?,
preFetchedUsdPrice?): Promise<number>;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:325
Returns the USD value of the bitcoin amount
Parameters
| Parameter | Type | Description |
|---|---|---|
btcSats | bigint | Bitcoin amount in satoshis |
abortSignal? | AbortSignal | |
preFetchedUsdPrice? | number | An optional price pre-fetched with preFetchUsdPrice |
Returns
Promise<number>
Inherited from
ICachedSwapPrice.getBtcUsdValue
getFromBtcSwapAmount()
getFromBtcSwapAmount<C>(
chainIdentifier,
fromAmount,
toToken,
abortSignal?,
preFetchedPrice?): Promise<bigint>;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:261
Returns amount of toToken that is equivalent to fromAmount satoshis
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | Chain identifier string for the smart chain |
fromAmount | bigint | Amount of satoshis |
toToken | string | Token address |
abortSignal? | AbortSignal | |
preFetchedPrice? | bigint | An optional price pre-fetched with preFetchPrice |
Returns
Promise<bigint>
Throws
when token is not found
Inherited from
ICachedSwapPrice.getFromBtcSwapAmount
getToBtcSwapAmount()
getToBtcSwapAmount<C>(
chainIdentifier,
fromAmount,
fromToken,
abortSignal?,
preFetchedPrice?): Promise<bigint>;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:288
Returns amount of satoshis that are equivalent to fromAmount of fromToken
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | Chain identifier string for the smart chain |
fromAmount | bigint | Amount of the token |
fromToken | string | Token address |
abortSignal? | AbortSignal | |
preFetchedPrice? | bigint | An optional price pre-fetched with preFetchPrice |
Returns
Promise<bigint>
Throws
when token is not found
Inherited from
ICachedSwapPrice.getToBtcSwapAmount
getTokenUsdValue()
getTokenUsdValue<C>(
chainIdentifier,
tokenAmount,
tokenAddress,
abortSignal?,
preFetchedUsdPrice?): Promise<number>;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:342
Returns the USD value of the smart chain token amount
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | Chain identifier string for the smart chain |
tokenAmount | bigint | Amount of the token in base units |
tokenAddress | string | Token address |
abortSignal? | AbortSignal | |
preFetchedUsdPrice? | number | An optional price pre-fetched with preFetchUsdPrice |
Returns
Promise<number>
Inherited from
ICachedSwapPrice.getTokenUsdValue
getUsdValue()
getUsdValue<C>(
amount,
token,
abortSignal?,
preFetchedUsdPrice?): Promise<number>;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:364
Returns the USD value of the token amount
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
amount | bigint | Amount in base units of the token |
token | Token<C> | Token to fetch the usd price for |
abortSignal? | AbortSignal | |
preFetchedUsdPrice? | number | An optional price pre-fetched with preFetchUsdPrice |
Returns
Promise<number>
Inherited from
ICachedSwapPrice.getUsdValue
isValidAmountReceive()
isValidAmountReceive<C>(
chainIdentifier,
amountSats,
satsBaseFee,
feePPM,
receiveToken,
tokenAddress,
abortSignal?,
preFetchedPrice?): Promise<PriceInfoType>;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:189
Checks whether the swap amounts are valid given the current market rate for a given pair
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | Chain identifier of the smart chain |
amountSats | bigint | Amount of sats (BTC) to be paid to the swap |
satsBaseFee | bigint | Base fee in sats (BTC) as reported by the intermediary |
feePPM | bigint | PPM fee rate as reported by the intermediary |
receiveToken | bigint | Amount of token to be received from the swap |
tokenAddress | string | Token address to be received |
abortSignal? | AbortSignal | |
preFetchedPrice? | bigint | An optional price pre-fetched with preFetchPrice |
Returns
Promise<PriceInfoType>
Inherited from
ICachedSwapPrice.isValidAmountReceive
isValidAmountSend()
isValidAmountSend<C>(
chainIdentifier,
amountSats,
satsBaseFee,
feePPM,
paidToken,
tokenAddress,
abortSignal?,
preFetchedPrice?): Promise<PriceInfoType>;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:104
Checks whether the swap amounts are valid given the current market rate for a given pair
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | Chain identifier of the smart chain |
amountSats | bigint | Amount of sats (BTC) to be received from the swap |
satsBaseFee | bigint | Base fee in sats (BTC) as reported by the intermediary |
feePPM | bigint | PPM fee rate as reported by the intermediary |
paidToken | bigint | Amount of token to be paid to the swap |
tokenAddress | string | Token address to be paid |
abortSignal? | AbortSignal | |
preFetchedPrice? | bigint | An optional price pre-fetched with preFetchPrice |
Returns
Promise<PriceInfoType>
Inherited from
ICachedSwapPrice.isValidAmountSend
preFetchPrice()
preFetchPrice<C>(
chainIdentifier,
tokenAddress,
abortSignal?): Promise<bigint>;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:237
Pre-fetches the pricing data for a given token, such that further calls to isValidAmountReceive or isValidAmountSend are quicker and don't need to wait for the price fetch
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | Chain identifier of the smart chain |
tokenAddress | string | Token address |
abortSignal? | AbortSignal |
Returns
Promise<bigint>
Inherited from
ICachedSwapPrice.preFetchPrice
preFetchUsdPrice()
preFetchUsdPrice(abortSignal?): Promise<number>;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:247
Pre-fetches the Bitcoin USD price data, such that further calls to getBtcUsdValue, getTokenUsdValue or getUsdValue are quicker and don't need to wait for the price fetch
Parameters
| Parameter | Type | Description |
|---|---|---|
abortSignal? | AbortSignal |
Returns
Promise<number>
Inherited from
ICachedSwapPrice.preFetchUsdPrice
recomputePriceInfoReceive()
recomputePriceInfoReceive<C>(
chainIdentifier,
amountSats,
satsBaseFee,
feePPM,
receiveToken,
tokenAddress): PriceInfoType;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:154
Recomputes pricing info without fetching the current price
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | Chain identifier of the smart chain |
amountSats | bigint | Amount of sats (BTC) to be paid to the swap |
satsBaseFee | bigint | Base fee in sats (BTC) as reported by the intermediary |
feePPM | bigint | PPM fee rate as reported by the intermediary |
receiveToken | bigint | Amount of token to be received from the swap |
tokenAddress | string | Token address to be received |
Returns
PriceInfoType
Inherited from
ICachedSwapPrice.recomputePriceInfoReceive
recomputePriceInfoSend()
recomputePriceInfoSend<C>(
chainIdentifier,
amountSats,
satsBaseFee,
feePPM,
paidToken,
tokenAddress): PriceInfoType;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:69
Recomputes pricing info without fetching the current price
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | Chain identifier of the smart chain |
amountSats | bigint | Amount of sats (BTC) to be received from the swap |
satsBaseFee | bigint | Base fee in sats (BTC) as reported by the intermediary |
feePPM | bigint | PPM fee rate as reported by the intermediary |
paidToken | bigint | Amount of token to be paid to the swap |
tokenAddress | string | Token address to be paid |
Returns
PriceInfoType
Inherited from
ICachedSwapPrice.recomputePriceInfoSend
shouldIgnore()
shouldIgnore<C>(chainIdentifier, tokenAddress): boolean;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:312
Returns whether the token should be ignored and pricing for it not calculated
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | Chain identifier string for the smart chain |
tokenAddress | string | Token address |
Returns
boolean
Throws
if token is not found
Inherited from
ICachedSwapPrice.shouldIgnore
fetchPrice()
protected fetchPrice<C>(
chainIdentifier,
token,
abortSignal?): Promise<bigint>;
Defined in: atomiq-sdk/src/prices/RedundantSwapPrice.ts:190
Fetches the prices, first tries to use the operational price API (if any) and if that fails it falls back to using maybe operational price APIs
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | |
token | string | |
abortSignal? | AbortSignal |
Returns
Promise<bigint>
Overrides
ICachedSwapPrice.fetchPrice
fetchUsdPrice()
protected fetchUsdPrice(abortSignal?): Promise<number>;
Defined in: atomiq-sdk/src/prices/RedundantSwapPrice.ts:251
Fetches the USD prices, first tries to use the operational price API (if any) and if that fails it falls back to using maybe operational price APIs
Parameters
| Parameter | Type | Description |
|---|---|---|
abortSignal? | AbortSignal |
Returns
Promise<number>
Overrides
ICachedSwapPrice.fetchUsdPrice
getDecimals()
protected getDecimals<C>(chainIdentifier, token): number;
Defined in: atomiq-sdk/src/prices/RedundantSwapPrice.ts:210
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type |
|---|---|
chainIdentifier | C |
token | string |
Returns
number
Inherit Doc
Overrides
ICachedSwapPrice.getDecimals
getDecimalsThrowing()
protected getDecimalsThrowing<C>(chainIdentifier, tokenAddress): number;
Defined in: atomiq-sdk/src/prices/abstract/ISwapPrice.ts:53
Gets the decimal places for a given token, returns -1 if token should be ignored & throws if token is not found
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | Chain identifier of the smart chain |
tokenAddress | string | Token address |
Returns
number
Throws
When token is not known
Inherited from
ICachedSwapPrice.getDecimalsThrowing
getPrice()
protected getPrice<C>(
chainIdentifier,
tokenAddress,
abortSignal?): Promise<bigint>;
Defined in: atomiq-sdk/src/prices/abstract/ICachedSwapPrice.ts:30
Returns the price of the token in BTC uSats (microSats)
Type Parameters
| Type Parameter |
|---|
C extends string |
Parameters
| Parameter | Type | Description |
|---|---|---|
chainIdentifier | C | Chain identifier of the smart chain |
tokenAddress | string | Token address |
abortSignal? | AbortSignal |
Returns
Promise<bigint>
Inherited from
ICachedSwapPrice.getPrice
getUsdPrice()
protected getUsdPrice(abortSignal?): Promise<number>;
Defined in: atomiq-sdk/src/prices/abstract/ICachedSwapPrice.ts:64
Returns BTC price in USD (sats/USD)
Parameters
| Parameter | Type | Description |
|---|---|---|
abortSignal? | AbortSignal |
Returns
Promise<number>
Throws
if token is not found
Inherited from
ICachedSwapPrice.getUsdPrice