constructor(numerator: BigintIsh, denominator: BigintIsh = ONE)
The base class which all subsequent fraction classes extend. Not meant to be used directly.
numerator: JSBI
denominator: JSBI
quotient: JSBI
Performs floor division.
invert(): Fraction
add(other: Fraction | BigintIsh): Fraction
subtract(other: Fraction | BigintIsh): Fraction
multiply(other: Fraction | BigintIsh): Fraction
divide(other: Fraction | BigintIsh): Fraction
toSignificant(significantDigits: number,format: object = { groupSeparator: '' },rounding: Rounding = Rounding.ROUND_HALF_UP): string
Formats a fraction to the specified number of significant digits.
toFixed(decimalPlaces: number,format: object = { groupSeparator: '' },rounding: Rounding = Rounding.ROUND_HALF_UP): string
Formats a fraction to the specified number of decimal places.
Responsible for formatting percentages (10% instead of 0.1).
import { Percent } from '@materia/sdk'const percent = new Percent('60', '100')console.log(percent.toSignificant(2)) // 60
See toSignificant.
See toFixed.
constructor(token: Token, amount: BigintIsh)
Responsible for formatting token amounts with specific decimal places.
import { Token, TokenAmount } from '@materia/sdk'const WUSD = new Token(ChainId.MAINNET, '0x7C974104DF9dd7fb91205ab3D66d15AFf1049DE8', 18, 'WUSD', 'Wrapped USD')const tokenAmount = new TokenAmount(WUSD, '3000000000000000000')console.log(tokenAmount.toExact()) // 3
token: Token
raw: JSBI
Returns the full token amount, unadjusted for decimals.
add(other: TokenAmount): TokenAmount
subtract(other: TokenAmount): TokenAmount
See toSignificant.
See toFixed.
toExact(format: object = { groupSeparator: '' }): string
constructor(baseToken: Token, quoteToken: Token, denominator: BigintIsh, numerator: BigintIsh)
Responsible for denominating the relative price between two tokens. Denominator and numerator must be unadjusted for decimals.
import { ChainId, IETH as WETHs, Token, Price } from '@materia/sdk'const WUSD = new Token(ChainId.MAINNET, '0x7C974104DF9dd7fb91205ab3D66d15AFf1049DE8', 18, 'WUSD', 'Wrapped USD')const price = new Price(WUSD, IETH[ChainId.MAINNET], '1000000000000000000', '123000000000000000000')console.log(price.toSignificant(3)) // 123
This example shows the WUSD/IETH price, where WUSD is the base token, and IETH is the quote token. The price is constructed from an amount of IETH (the numerator) / an amount of WUSD (the denominator).
fromRoute(route: Route): Price
baseToken: Token
quoteToken: Token
scalar: Fraction
Used to adjust the price for the decimals of the base and quote tokens.
raw: Fraction
Returns the raw price, unadjusted for decimals.
adjusted: Fraction
Returns the price, adjusted for decimals.
invert(): Price
multiply(other: Price): Price
quote(tokenAmount: TokenAmount): TokenAmount
Given an asset amount, returns an equivalent value of the other asset, according to the current price.
See toSignificant.
See toFixed.