KyberSwap Docs
Search
K

CurrencyAmount

Enables the safe handling of currency amounts.
GitHub File: currencyAmount.ts

Extends

Properties

Public

Property
Type
Modifier
Description
currency
T
readonly
The currency amount.
decimalScale
JSBI
readonly
Number of decimals for the currency.

Constructor - protected

Generics Type Definitions

Generics Name
Description
T
Extends Currency.

Parameters

Params
Type
Description
currency
T
The currency.
numerator
BigintIsh
The numerator currency amount to be created.
denominator
BigintIsh
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

Params
Type
Description
currency
T
The currency.
rawAmount
BigintIsh | BN
The unitless amount of tokens.
Returns
Type
Description
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

Params
Type
Description
currency
T
The currency.
numerator
BigintIsh
The numerator of the fractional token amount.
denominator
The denominator of the fractional token amount.

Returns

Type
Description
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

Params
Type
Description
other
CurrencyAmount<T>
The currencyAmount to be added to the CurrencyAmount instance.

Returns

Type
Description
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

Params
Type
Description
other
CurrencyAmount<T>
The currencyAmount to be subtracted from the CurrencyAmount instance.

Returns

Type
Description
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

Params
Type
Description
other
CurrencyAmount<T>
The currencyAmount to be multiplied with the CurrencyAmount instance.

Returns

Type
Description
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

Params
Type
Description
other
CurrencyAmount<T>
The currencyAmount to be divided from the CurrencyAmount instance.

Returns

Type
Description
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

Params
Type
Description
significantDigits
number
The number of significant digits to round to. Default is 6 digits.
format
object
Configure output format per toformat specifications.
rounding
Rounding
Specifies the rounding logic used. Default is ROUND_DOWN which rounds towards zero.

Returns

Type
Description
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

Params
Type
Description
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
Rounding
Specifies the rounding logic used. Default is ROUND_DOWN which rounds towards zero.

Returns

Type
Description
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

Params
Type
Description
format
object
Configure output format per toformat specifications.

Returns

Type
Description
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

Type
Description
Token
The wrapped version of the currencyAmount instance.
Last modified 4mo ago