Quickswap Documentation
  • πŸ‰What is Quickswap?
  • Overview
    • ♻️Quickswap AMM
    • πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦Ecosystem Participants
    • ✨Key Features
    • πŸ”Swap
    • πŸ’¦Pools
    • πŸ‘¨β€πŸŒΎFarms
    • 🀝Bonds
    • βš–οΈPerps
    • 🐲Dragon's Lair
    • πŸ›οΈGovernance
    • πŸ—ΊοΈRoadmap
    • πŸ“²Social Media
    • πŸ“Contracts & Addresses
  • Tokens
    • πŸͺ™QUICK
    • πŸͺ™DD
  • Networks & Wallets
    • ⛓️Supported Chains
    • πŸ’³Supported Wallets
  • How To Guides
    • πŸ”How To Swap
      • ℹ️dLIMIT Guide
      • ℹ️dTWAP Guide
    • πŸ’§LP (Liquidity Providing)
    • πŸ‘©β€πŸŒΎFarm
    • πŸ₯©Stake
  • πŸ’»Technical Reference
    • πŸ‘©β€πŸ’»API
      • API Overview
      • Entities
      • Queries
    • πŸ“œSmart Contracts
      • 2️⃣V2
        • Factory
        • Pair
        • Pair (ERC-20)
        • Library
        • Router02
        • Router01
        • Common Errors
      • 3️⃣V3
        • Position Manager
        • Factory
        • Pool Deployer
        • Quoter
        • V3 Migrator
        • Farming Center
        • Limit Farming
        • Pool
        • Audits
    • ⌨️SDK
      • Getting Started
      • Token
      • Pair
      • Route
      • Trade
      • Fractions
      • Fetcher
      • Other Exports
    • ❔Guides
      • Interface Integration
        • Using the API
        • Query Parameters
        • Iframe Integration
      • Javascript SDK
        • SDK Quick start
        • Fetching Data
        • Pricing
        • Trading
        • Pair Addresses
      • Smart Contract Integration
        • Smart Contract Quick Start
        • Implement A Swap
        • Providing Liquidity
        • Building An Oracle
        • Flash Swaps
        • V2 Pair Addresses
        • Supporting Meta Transactions
        • V3 Pool Addresses
    • πŸ”ŽSubgraphs
    • ℹ️Glossary
    • πŸ“–Core Concepts
      • Swaps
      • Pools
      • Flash Swaps
      • Oracles
    • βš–οΈAdvanced Topics
      • Fees
      • Pricing
      • Understanding Returns
      • Security
      • Math
      • Research
Powered by GitBook
On this page
  • Fraction
  • Properties
  • Methods
  • Percent
  • Example
  • TokenAmount
  • Example
  • Properties
  • Methods
  • Price
  • Example
  • Static Methods
  • Properties
  • Methods
  1. Technical Reference
  2. SDK

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

add(other: Fraction | BigintIsh): Fraction

subtract

subtract(other: Fraction | BigintIsh): Fraction

multiply

multiply(other: Fraction | BigintIsh): Fraction

divide

divide(other: Fraction | BigintIsh): Fraction

toSignificant

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

Formats a fraction to the specified number of significant digits.

toFixed

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

Formats a fraction to the specified number of decimal places.

Percent

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

Example

import { Percent } from '@uniswap/sdk'

const percent = new Percent('60', '100')
console.log(percent.toSignificant(2)) // 60

toSignificant

See toSignificant.

toFixed

See toFixed.

TokenAmount

constructor(token: Token, amount: BigintIsh)

Responsible for formatting token amounts with specific decimal places.

Example

import { 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

token

token: Token

raw

raw: JSBI

Returns the full token amount, unadjusted for decimals.

Methods

add

add(other: TokenAmount): TokenAmount

subtract

subtract(other: TokenAmount): TokenAmount

toSignificant

See toSignificant.

toFixed

See toFixed.

toExact

toExact(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.

Example

import { 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

fromRoute

fromRoute(route: Route): Price

Properties

baseToken

baseToken: Token

quoteToken

quoteToken: Token

scalar

scalar: Fraction

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

raw

raw: Fraction

Returns the raw price, unadjusted for decimals.

adjusted

adjusted: Fraction

Returns the price, adjusted for decimals.

Methods

invert

invert(): Price

multiply

multiply(other: Price): Price

quote

quote(tokenAmount: TokenAmount): TokenAmount

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

toSignificant

See toSignificant.

toFixed

See toFixed.

PreviousTradeNextFetcher

For format options, see .

For format options, see .

πŸ’»
⌨️
toFormat
toFormat