Skip to main content

TokenAmount<T, Known>

type TokenAmount<T, Known> = object;

Defined in: atomiq-sdk/src/types/TokenAmount.ts:11

Represents a token amount along with its formatted values and USD valuation helpers

Type Parameters​

Type ParameterDefault type
T extends TokenToken
Known extends booleanboolean

Properties​

_amount​

_amount: number;

Defined in: atomiq-sdk/src/types/TokenAmount.ts:27

Number representation of the decimal token amount (can lose precision!), might be NaN when the amount is unknown


amount​

amount: string;

Defined in: atomiq-sdk/src/types/TokenAmount.ts:22

Human readable amount with decimal places, might be empty string "" when the amount is unknown


currentUsdValue()​

currentUsdValue: (abortSignal?, preFetchedUsdPrice?) => Promise<number>;

Defined in: atomiq-sdk/src/types/TokenAmount.ts:39

Fetches the current USD value of the amount, might return NaN when the amount is unknown

Parameters​

ParameterTypeDescription
abortSignal?AbortSignal
preFetchedUsdPrice?numberYou can supply a pre-fetched usd price to the pricing function

Returns​

Promise<number>

A promise resolving to the current USD value of the token amount


isUnknown​

isUnknown: Known extends true ? false : true;

Defined in: atomiq-sdk/src/types/TokenAmount.ts:66

Whether the token amount contains an unknown or undefined amount, in this case numeric values are NaN, raw amount is undefined, string representation is "" and toString() returns "??? {ticker}"


pastUsdValue?​

optional pastUsdValue: number;

Defined in: atomiq-sdk/src/types/TokenAmount.ts:56

USD value of the amount when swap was created - only present for token amounts obtained from swaps, left for convenience only, use usdValue() instead, which automatically recognizes which pricing to use (either past value if available or fetches it on-demand), might be NaN when the amount is unknown


rawAmount​

rawAmount: Known extends true ? bigint : undefined;

Defined in: atomiq-sdk/src/types/TokenAmount.ts:18

Raw amount in base units represented as bigint, might be undefined when the amount is unknown


token​

token: T;

Defined in: atomiq-sdk/src/types/TokenAmount.ts:31

Token associated with this amount


toString()​

toString: () => string;

Defined in: atomiq-sdk/src/types/TokenAmount.ts:61

Returns the string representation of the amount along with the token ticker in format: "{amount} {ticker}", in case the anmount is unknown returns "??? {ticker}"

Returns​

string


usdValue()​

usdValue: (abortSignal?, preFetchedUsdPrice?) => Promise<number>;

Defined in: atomiq-sdk/src/types/TokenAmount.ts:49

Gets USD value of the amount, if this amount was returned from a swap it uses the USD value when the swap was created, otherwise fetches the usd value on-demand, might return NaN when the amount is unknown

Parameters​

ParameterTypeDescription
abortSignal?AbortSignal
preFetchedUsdPrice?numberYou can supply a pre-fetched usd price to the pricing function

Returns​

Promise<number>

A promise resolving to the current USD value of the token amount