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
  • Code
  • Internal Functions
  • sortTokens
  • pairFor
  • getReserves
  • quote
  • getAmountOut
  • getAmountIn
  • getAmountsOut
  • getAmountsIn
  1. Technical Reference
  2. Smart Contracts
  3. V2

Library

PreviousPair (ERC-20)NextRouter02

Code

Internal Functions

sortTokens

function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1);

Sorts token addresses.

pairFor

function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair);

Calculates the address for a pair without making any external calls (see Pair Addresses).

getReserves

function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB);

Calls getReserves on the pair for the passed tokens, and returns the results sorted in the order that the parameters were passed in.

quote

function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB);

Given some asset amount and reserves, returns an amount of the other asset representing equivalent value.

  • Useful for calculating optimal token amounts before calling mint.

getAmountOut

function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut);

Given an input asset amount, returns the maximum output amount of the other asset (accounting for fees) given reserves.

  • Used in getAmountsOut.

getAmountIn

function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn);

Returns the minimum input asset amount required to buy the given output asset amount (accounting for fees) given reserves.

  • Used in getAmountsIn.

getAmountsOut

function getAmountsOut(uint amountIn, address[] memory path) internal view returns (uint[] memory amounts);

Given an input asset amount and an array of token addresses, calculates all subsequent maximum output token amounts by calling getReserves for each pair of token addresses in the path in turn, and using these to call getAmountOut.

  • Useful for calculating optimal token amounts before calling swap.

getAmountsIn

function getAmountsIn(uint amountOut, address[] memory path) internal view returns (uint[] memory amounts);

Given an output asset amount and an array of token addresses, calculates all preceding minimum input token amounts by calling getReserves for each pair of token addresses in the path in turn, and using these to call getAmountIn.

  • Useful for calculating optimal token amounts before calling swap.

πŸ’»
πŸ“œ
2️⃣
UniswapV2Library.sol