CurrencyAmount

Enables the safe handling of currency amounts.

GitHub File: currencyAmount.ts

Extends

Properties

Public

PropertyTypeModifierDescription

currency

T

readonly

The currency amount.

decimalScale

readonly

Number of decimals for the currency.

Constructor - protected

Generics Type Definitions

Generics NameDescription

T

Extends Currency.

Parameters

ParamsTypeDescription

currency

T

The currency.

numerator

The numerator currency amount to be created.

denominator

The denominator currency amount to be created. Optional.

Methods

fromRawAmount() - public static

Returns a new currency amount instance from the unitless amount of token (i.e. the raw amount).

Parameters

ParamsTypeDescription

currency

T

The currency.

rawAmount

The unitless amount of tokens.

Returns

TypeDescription

CurrencyAmount<T>

The amount of currency in the specified currency amount format.


fromFractionalAmount() - public static

Returns a new currency amount instance with a denominator that is not equal to 1.

Parameters

ParamsTypeDescription

currency

T

The currency.

numerator

The numerator of the fractional token amount.

denominator

The denominator of the fractional token amount.

Returns

TypeDescription

CurrencyAmount<T>

The amount of currency in the specified currency amount format.


add() - public

Adds the provided currencyAmount to the CurrencyAmount instance and returns the result as a new currencyAmount.

Parameters

ParamsTypeDescription

other

CurrencyAmount<T>

The currencyAmount to be added to the CurrencyAmount instance.

Returns

TypeDescription

CurrencyAmount<T>

The currencyAmount representing the sum of the two currencyAmounts.


subtract() - public

Subtracts/minuses the provided currencyAmount from the CurrencyAmount instance and returns the result as a new currencyAmount.

Parameters

ParamsTypeDescription

other

CurrencyAmount<T>

The currencyAmount to be subtracted from the CurrencyAmount instance.

Returns

TypeDescription

CurrencyAmount<T>

The final currencyAmount after subtracting the given currencyAmount from the CurrencyAmount instance.


multiply() - public

Multiplies the CurrencyAmount instance with the provided currencyAmount and returns the result as a new currencyAmount.

Parameters

ParamsTypeDescription

other

CurrencyAmount<T>

The currencyAmount to be multiplied with the CurrencyAmount instance.

Returns

TypeDescription

CurrencyAmount<T>

The final currencyAmount after multiplying the given currencyAmount with the CurrencyAmount instance.


divide() - public

Divides the currencyAmount instance with the provided currencyAmount and returns the result as a new currencyAmount.

Parameters

ParamsTypeDescription

other

CurrencyAmount<T>

The currencyAmount to be divided from the CurrencyAmount instance.

Returns

TypeDescription

CurrencyAmount<T>

The final currencyAmount after dividing the CurrencyAmount instance by the provided currencyAmount.


toSignificant() - public

Rounds the CurrencyAmount instance to the significant digits specified.

Parameters

ParamsTypeDescription

significantDigits

number

The number of significant digits to round to. Default is 6 digits.

format

object

Configure output format per toformat specifications.

rounding

Specifies the rounding logic used. Default is ROUND_DOWN which rounds towards zero.

Returns

TypeDescription

string

The final quotient value rounded to the specified significant digits.


toFixed() - public

Rounds the currencyAmount instance to the fixed number of decimals specified.

Parameters

ParamsTypeDescription

decimalPlaces

number

The number of decimal places to round to. Default is the currency's decimal places.

format

object

Configure output format per toformat specifications.

rounding

Specifies the rounding logic used. Default is ROUND_DOWN which rounds towards zero.

Returns

TypeDescription

string

The final quotient value rounded to the decimal places specified.


toExact() - public

Gets the exact CurrencyAmount instance value with the default currency decimals.

Parameters

ParamsTypeDescription

format

object

Configure output format per toformat specifications.

Returns

TypeDescription

string

The final exact quotient value down to the currency's default decimals.


wrapped() - public get

Returns the wrapped version of the currencyAmount instance after accounting for whether the currency is a Token or NativeCurrency.

Returns

TypeDescription

Token

The wrapped version of the currencyAmount instance.

Last updated