Fractions

Fraction

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

The base class which all subsequent fraction classes extend. Not meant to be used directly.

Properties

numerator

numerator: JSBI

denominator

denominator: JSBI

quotient

quotient: JSBI

Performs floor division.

Methods

invert

invert(): Fraction

add

subtract

multiply

divide

toSignificant

Formats a fraction to the specified number of significant digits.

toFixed

Formats a fraction to the specified number of decimal places.

Percent

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

Example

toSignificant

See toSignificant.

toFixed

See toFixed.

TokenAmount

Responsible for formatting token amounts with specific decimal places.

Example

Properties

token

raw

Returns the full token amount, unadjusted for decimals.

Methods

add

subtract

toSignificant

See toSignificant.

toFixed

See toFixed.

toExact

Price

Responsible for denominating the relative price between two tokens. Denominator and numerator must be unadjusted for decimals.

Example

This example shows the ETH/XYZ price, where ETH is the base token, and XYZ is the quote token. The price is constructed from an amount of XYZ (the numerator) / an amount of WETH (the denominator).

Static Methods

fromRoute

Properties

baseToken

quoteToken

scalar

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

raw

Returns the raw price, unadjusted for decimals.

adjusted

Returns the price, adjusted for decimals.

Methods

invert

multiply

quote

Given an asset amount, returns an equivalent value of the other asset, according to the current price.

toSignificant

See toSignificant.

toFixed

See toFixed.

Last updated

Was this helpful?