Skip to main content

Fractions

Fraction#

The base class which all subsequent fraction classes extend. All the properties and methods are self-explanatory in this class. This sections breifs about all the properties and methods of other classes which inherit Fraction.

Source Code

constructor(numerator: BigintIsh, denominator: BigintIsh = ONE)

Properties#

numerator#

numerator: JSBI

denominator#

denominator: JSBI

quotient#

Performs floor division.

quotient: JSBI

Methods#

invert#

invert(): Fraction

add#

add(other: Fraction | BigintIsh): Fraction

subtract#

subtract(other: Fraction | BigintIsh): Fraction

multiply#

multiply(other: Fraction | BigintIsh): Fraction

divide#

divide(other: Fraction | BigintIsh): Fraction

toSignificant#

Formats a fraction to the specified number of significant digits.(Rounding-off)

toSignificant(
significantDigits: number,
format: object = { groupSeparator: '' },
rounding: Rounding = Rounding.ROUND_HALF_UP
): string

toFixed#

Formats a fraction to the specified number of decimal places.

toFixed(
decimalPlaces: number,
format: object = { groupSeparator: '' },
rounding: Rounding = Rounding.ROUND_HALF_UP
): string

Percent class extends Fraction#

Used for formatting percentages (10% instead of 0.1).

toSignificant#

See toSignificant.

toFixed#

See toFixed.

CurrencyAmount extends Fraction class#

constructor(currency: Currency, amount: BigintIsh)
  • this class has a static helper to call the constructor with ETH as currency

Properties#

raw#

Returns the full token amount, without rounding off to decimals.

raw: JSBI

Methods#

add#

add(other: CurrencyAmount): CurrencyAmount

subtract#

subtract(other: CurrencyAmount): CurrencyAmount

toSignificant#

See toSignificant.

toFixed#

See toFixed.

toExact#

toExact(format: object = { groupSeparator: '' }): string

TokenAmount extends currentAmount class#

constructor(token: Token, amount: BigintIsh)

Properties#

token#

token: Token

raw#

See raw.

Methods#

add#

add(other: TokenAmount): TokenAmount

subtract#

subtract(other: TokenAmount): TokenAmount

toSignificant#

See toSignificant.

toFixed#

See toFixed.

toExact#

See toExact.

Price extends Fraction#

Handles denominating the relative price between two tokens. Where, Denominator and numerator are not rounded off or raw price.

constructor(baseToken: Token, quoteToken: Token, denominator: BigintIsh, numerator: BigintIsh)

Static Methods#

fromRoute#

fromRoute(route: Route): Price

Properties#

baseToken#

baseToken: Token

quoteToken#

quoteToken: Token

scalar#

Used to adjust the price for the decimals of the base and quote tokens.

scalar: Fraction

raw#

Returns the raw price, without rounding off to decimals.

raw: Fraction

adjusted#

Returns the price, with rounding off to decimals.

adjusted: Fraction

Methods#

invert#

invert(): Price

multiply#

multiply(other: Price): Price

quote#

Returns an equivalent value of the asset, according to the current price.

quote(tokenAmount: TokenAmount): TokenAmount

toSignificant#

See toSignificant.

toFixed#

See toFixed.