Fraction
constructor(numerator: BigintIsh, denominator: BigintIsh = ONE)
The base class which all subsequent fraction classes extend. Not meant to be used directly.
#
Properties#
numeratornumerator: JSBI;
#
denominatordenominator: JSBI;
#
quotientquotient: JSBI;
Performs floor division.
#
Methods#
invertinvert(): Fraction
#
addadd(other: Fraction | BigintIsh): Fraction
#
subtractsubtract(other: Fraction | BigintIsh): Fraction
#
multiplymultiply(other: Fraction | BigintIsh): Fraction
#
dividedivide(other: Fraction | BigintIsh): Fraction
#
toSignificanttoSignificant( significantDigits: number, format: object = { groupSeparator: '' }, rounding: Rounding = Rounding.ROUND_HALF_UP): string
Formats a fraction to the specified number of significant digits.
- For format options, see toFormat.
#
toFixedtoFixed( decimalPlaces: number, format: object = { groupSeparator: '' }, rounding: Rounding = Rounding.ROUND_HALF_UP): string
Formats a fraction to the specified number of decimal places.
- For format options, see toFormat.
Percent
Responsible for formatting percentages (10% instead of 0.1).
#
Exampleimport { Percent } from "@uniswap/sdk";
const percent = new Percent("60", "100");console.log(percent.toSignificant(2)); // 60
#
toSignificantSee toSignificant.
#
toFixedSee toFixed.
TokenAmount
constructor(token: Token, amount: BigintIsh)
Responsible for formatting token amounts with specific decimal places.
#
Exampleimport { Token, TokenAmount } from "@uniswap/sdk";
const FRIED = new Token( ChainId.MAINNET, "0xfa1aFe1000000000000000000000000000000000", 18, "FRIED", "Beans");
const tokenAmount = new TokenAmount(FRIED, "3000000000000000000");console.log(tokenAmount.toExact()); // 3
#
Properties#
tokentoken: Token;
#
rawraw: JSBI;
Returns the full token amount, unadjusted for decimals.
#
Methods#
addadd(other: TokenAmount): TokenAmount
#
subtractsubtract(other: TokenAmount): TokenAmount
#
toSignificantSee toSignificant.
#
toFixedSee toFixed.
#
toExacttoExact(format: object = { groupSeparator: '' }): string
Price
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.
#
Exampleimport { ChainId, WETH as WETHs, Token, Price } from "@uniswap/sdk";
const WETH = WETHs[ChainId.MAINNET];const ABC = new Token( ChainId.MAINNET, "0xabc0000000000000000000000000000000000000", 18, "ABC");
const price = new Price( WETH, ABC, "1000000000000000000", "123000000000000000000");console.log(price.toSignificant(3)); // 123
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#
fromRoutefromRoute(route: Route): Price
#
Properties#
baseTokenbaseToken: Token;
#
quoteTokenquoteToken: Token;
#
scalarscalar: Fraction;
Used to adjust the price for the decimals of the base and quote tokens.
#
rawraw: Fraction;
Returns the raw price, unadjusted for decimals.
#
adjustedadjusted: Fraction;
Returns the price, adjusted for decimals.
#
Methods#
invertinvert(): Price
#
multiplymultiply(other: Price): Price
#
quotequote(tokenAmount: TokenAmount): TokenAmount
Given an asset amount, returns an equivalent value of the other asset, according to the current price.
#
toSignificantSee toSignificant.
#
toFixedSee toFixed.