๐Ÿ“’
Native Docs
  • ๐ŸฆŽAbout Native
    • ๐Ÿ—บ๏ธRoadmap
    • ๐Ÿ“žContact Us
    • ๐Ÿ”Security Audit
    • ๐Ÿ–ผ๏ธBrand Assets
  • ๐ŸŽ‰Campaigns
    • ๐Ÿ–ผ๏ธOfficial NFTs
  • INTRODUCTION
    • ๐Ÿ”€Flexible Market Making
      • Pricing Models
        • On-chain Pricing
          • Constant Sum
          • Uniswap V2
        • Off-chain Pricing
          • Fixed Price
          • RFQ - Private Market Maker
    • ๐ŸŽ’Self Custody
      • Externally Owned Account (EOA)
      • Hardware Wallet
      • Multi-signature Wallet
    • ๐Ÿ’นProject Owned DEX
  • GETTING STARTED
    • ๐Ÿš€Product Overview
    • ๐ŸŽ“Tutorial
      • Accessing Native Portal
      • Creating A Private Pool
      • Adding Allowance
      • Creating A Public LP Pool
      • Adding LP Rewards
      • Getting Started with the Swap Widget
      • Changing Swap Widget Settings
    • ๐Ÿ™‹โ€โ™‚๏ธFAQ
  • DEVLOPERS
    • ๐ŸงฉNative V1
    • ๐Ÿ“ฑWidget
Powered by GitBook
On this page
  1. INTRODUCTION
  2. Flexible Market Making
  3. Pricing Models
  4. On-chain Pricing

Uniswap V2

PreviousConstant SumNextOff-chain Pricing

Last updated 2 years ago

The constant product market maker is the most common AMM invariant that was made popular with Uniswap. It can be simply modeled as x * y = k . X and Y are the reserves for each asset, as assets are traded through this function X and Y increase or decrease in their reserves in a way that keeps a constant K (not counting fees charged).

Constant Product

Example โ€” Trader Swap Tokens

Assume there are two ERC-20 tokens: ABC and USDT, and there is a ABC/USDT Uniswap liquidity pool created. Letโ€™s say this ABC/USDT liquidity pool currently has 10 ABC and 40 USDT in it, so the ratio is 1 ABC : 4 USDT. Assuming thatโ€™s the current market ratio, 1 ABC is now worth 4 USDT.

Now if John swaps his 1 ABC for USDT, the pool will take his 1 ABC, transfer a certain amount of USDT from the pool to him.

Uniswap determines the output token amount by using a constant product formula:

x * y = k

Instead of 4 USDT, John will actually receive a bit less: 3.626444 USDT.

The constant product formula requires the trades should not change the product (K) of a pairโ€™s reserved balances (X and Y). Letโ€™s walk through the calculation step by step.

Originally, the liquidity pool has 10 ABC and 40 USDT, so X = 10 and Y = 40. When John swaps 1 ABC , he will pay a 0.3% fee first, which is 0.003 ABC (0.3% * 1). After the fee is paid, the remaining ABC, which is 0.997 ABC, will be swapped for USDT, so the new X becomes 10.997 ABC. Since K must remain unchanged, the new Y can be calculated from the formula X * Y = newX * newY. So newY is 36.373556 (X * Y / newX = 10 * 40 / 10.997 = 36.373556). This means the pool will hold 36.373556 USDT, the remaining USDT will be sent to John, which means John will receive 3.626444 USDT(Y โ€” newY = 40 โ€“ 36.373556 = 3.626444). After the swap, the pool has 11 ABC and 36.373556 USDT.

๐Ÿ”€
Constant Product Market Maker