KyberSwap Docs
Search
K

Price

Enables the safe handling of prices.
GitHub File: price.ts

Extends

Properties

Public

Property
Type
Modifier
Description
baseCurrency
TBase
readonly
The input currency (i.e. denominator) from which to construct the price.
quoteCurrency
TQoute
readonly
The output currency (i.e. numerator) to which the price is constructed.
scalar
Fraction
readonly
Used to adjust the raw fraction with regards to the decimals of the base and quote Token.

Constructor

Parameters

Params
Type
Description
args
Object
An object containing either: - The array literally detailing the Currency classes and amounts; or - A second array that contains the Currency details in the CurrencyAmount instances

Methods

invert() - public

Flips the base and quote currency to display the inverted price.

Returns

Type
Description
Price<TQuote, TBase>
The inverted price of the Price instance.

multiply() - public

Multiplies the Price instance with the provided price and returns a new price. The provided price must have the same base currency as the Price's quote currency.

Parameters

Params
Type
Description
other
Price<TQuote, TBase>
The price to be multiplied with the Price instance.

Returns

Type
Description
Price<TBase, TOtherQuote>
The final Price after multiplying the two prices.

quote() - public

Returns the amount of quote currency corresponding to a given amount of the base currency. That is, what is the provided currency amount when quoted in currency corresponding to the Price instance.

Parameters

Params
Type
Description
currencyAmount
currencyAmount<TBase>
The base currency amount to convert.

Returns

Type
Description
CurrencyAmount<TQuote>
The amount of quote currency equivalent to the given base currency amount.

adjustedForDecimals() - private

Scale the Price value by the scalar amount to prepare the price for further formatting

Returns

Type
Description
Fraction
The Price value adjusted for the decimal difference between base and quote currencies.

toSignificant() - public

Rounds the Price to the significant digits specified.

Parameters

Params
Type
Description
significantDigits
number
The number of significant digits to round to. Default is 6.
format
object
Configure output format per toformat specifications. Optional.
rounding
Rounding
Specifies the rounding logic used. Default is ROUND_HALF_UP which rounds to the nearest neighbour and rounds up if equidistant.

Returns

Type
Description
string
The final price value rounded to the specified significant digits.

toFixed() - public

Rounds the Price to the fixed number of decimals specified.

Parameters

Params
Type
Description
decimalPlaces
number
The number of decimal places to round to. Default is 4.
format
object
Configure output format per toformat specifications. Optional.
rounding
Rounding
Specifies the rounding logic used. Default is ROUND_HALF_UP which rounds to the nearest neighbour and rounds up if equidistant.

Returns

Type
Description
string
The final price value rounded to the decimal places specified.
Last modified 5mo ago