Skip to main content

SwapPriceWithChain<T, ChainIdentifier>

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:12

Chain-specific wrapper for swap pricing

Type Parameters​

Type Parameter
T extends MultiChain
ChainIdentifier extends ChainIds<T>

Constructors​

Constructor​

new SwapPriceWithChain<T, ChainIdentifier>(swapPrice, chainIdentifier): SwapPriceWithChain<T, ChainIdentifier>;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:18

Parameters​

ParameterType
swapPriceISwapPrice<T>
chainIdentifierChainIdentifier

Returns​

SwapPriceWithChain<T, ChainIdentifier>

Properties​

chainIdentifier​

chainIdentifier: ChainIdentifier;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:15


maxAllowedFeeDifferencePPM​

maxAllowedFeeDifferencePPM: bigint;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:16


swapPrice​

swapPrice: ISwapPrice<T>;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:14

Methods​

getBtcUsdValue()​

getBtcUsdValue(
btcSats,
abortSignal?,
preFetchedUsdPrice?): Promise<number>;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:152

Returns the USD value of the bitcoin amount

Parameters​

ParameterTypeDescription
btcSatsbigintBitcoin amount in satoshis
abortSignal?AbortSignal
preFetchedUsdPrice?numberAn optional price pre-fetched with preFetchUsdPrice

Returns​

Promise<number>


getFromBtcSwapAmount()​

getFromBtcSwapAmount(
fromAmount,
toToken,
abortSignal?,
preFetchedPrice?): Promise<bigint>;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:104

Returns amount of toToken that is equivalent to fromAmount satoshis

Parameters​

ParameterTypeDescription
fromAmountbigintAmount of satoshis
toTokenstringToken address
abortSignal?AbortSignal
preFetchedPrice?bigintAn optional price pre-fetched with preFetchPrice

Returns​

Promise<bigint>

Throws​

when token is not found


getToBtcSwapAmount()​

getToBtcSwapAmount(
fromAmount,
fromToken,
abortSignal?,
preFetchedPrice?): Promise<bigint>;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:124

Returns amount of satoshis that are equivalent to fromAmount of fromToken

Parameters​

ParameterTypeDescription
fromAmountbigintAmount of the token
fromTokenstringToken address
abortSignal?AbortSignal
preFetchedPrice?bigintAn optional price pre-fetched with preFetchPrice

Returns​

Promise<bigint>

Throws​

when token is not found


getTokenUsdValue()​

getTokenUsdValue(
tokenAmount,
tokenAddress,
abortSignal?,
preFetchedUsdPrice?): Promise<number>;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:168

Returns the USD value of the smart chain token amount

Parameters​

ParameterTypeDescription
tokenAmountbigintAmount of the token in base units
tokenAddressstringToken address
abortSignal?AbortSignal
preFetchedUsdPrice?numberAn optional price pre-fetched with preFetchUsdPrice

Returns​

Promise<number>


getUsdValue()​

getUsdValue(
amount,
token,
abortSignal?,
preFetchedUsdPrice?): Promise<number>;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:185

Returns the USD value of the token amount

Parameters​

ParameterTypeDescription
amountbigintAmount in base units of the token
tokenToken<ChainIdentifier>Token to fetch the usd price for
abortSignal?AbortSignal
preFetchedUsdPrice?numberAn optional price pre-fetched with preFetchUsdPrice

Returns​

Promise<number>


isValidAmountReceive()​

isValidAmountReceive(
amountSats,
satsBaseFee,
feePPM,
receiveToken,
tokenAddress,
abortSignal?,
preFetchedPrice?): Promise<PriceInfoType>;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:60

Checks whether the swap amounts are valid given the current market rate for a given pair

Parameters​

ParameterTypeDescription
amountSatsbigintAmount of sats (BTC) to be paid to the swap
satsBaseFeebigintBase fee in sats (BTC) as reported by the intermediary
feePPMbigintPPM fee rate as reported by the intermediary
receiveTokenbigintAmount of token to be received from the swap
tokenAddressstringToken address to be received
abortSignal?AbortSignalAbort signal
preFetchedPrice?bigintAn optional price pre-fetched with preFetchPrice

Returns​

Promise<PriceInfoType>


isValidAmountSend()​

isValidAmountSend(
amountSats,
satsBaseFee,
feePPM,
paidToken,
tokenAddress,
abortSignal?,
preFetchedPrice?): Promise<PriceInfoType>;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:35

Checks whether the swap amounts are valid given the current market rate for a given pair

Parameters​

ParameterTypeDescription
amountSatsbigintAmount of sats (BTC) to be received from the swap
satsBaseFeebigintBase fee in sats (BTC) as reported by the intermediary
feePPMbigintPPM fee rate as reported by the intermediary
paidTokenbigintAmount of token to be paid to the swap
tokenAddressstringToken address to be paid
abortSignal?AbortSignalAbort signal
preFetchedPrice?bigintAn optional price pre-fetched with preFetchPrice

Returns​

Promise<PriceInfoType>


preFetchPrice()​

preFetchPrice(tokenAddress, abortSignal?): Promise<bigint>;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:81

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

Parameters​

ParameterTypeDescription
tokenAddressstringToken address
abortSignal?AbortSignalAbort signal

Returns​

Promise<bigint>


preFetchUsdPrice()​

preFetchUsdPrice(abortSignal?): Promise<number>;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:91

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​

ParameterTypeDescription
abortSignal?AbortSignal

Returns​

Promise<number>


shouldIgnore()​

shouldIgnore(tokenAddress): boolean;

Defined in: atomiq-sdk/src/prices/SwapPriceWithChain.ts:141

Returns whether the token should be ignored and pricing for it not calculated

Parameters​

ParameterTypeDescription
tokenAddressstringToken address

Returns​

boolean

Throws​

if token is not found