Smart contracts | Uniswap (2024)

Uniswap V2 is a binary smart contract system. Core contracts provide fundamental safety guarantees for all parties interacting with Uniswap. Periphery contracts interact with one or more core contracts but are not themselves part of the core.

Source code

The core consists of a singleton factory and many pairs, which the factory is responsible for creating and indexing. These contracts are quite minimal, even brutalist. The simple rationale for this is that contracts with a smaller surface area are easier to reason about, less bug-prone, and more functionally elegant. Perhaps the biggest upside of this design is that many desired properties of the system can be asserted directly in the code, leaving little room for error. One downside, however, is that core contracts are somewhat user-unfriendly. In fact, interacting directly with these contracts is not recommended for most use cases. Instead, a periphery contract should be used.

Factory

Reference documentation

The factory holds the generic bytecode responsible for powering pairs. Its primary job is to create one and only one smart contract per unique token pair. It also contains logic to turn on the protocol charge.

Pairs

Reference documentation

Reference documentation (ERC-20)

Pairs have two primary purposes: serving as automated market makers and keeping track of pool token balances. They also expose data which can be used to build decentralizedprice oracles.

Source code

The periphery is a constellation of smart contracts designed to support domain-specific interactions with the core. Because of Uniswap's permissionless nature, the contracts described below have no special privileges, and are in fact only a small subset of the universe of possible periphery-like contracts. However, they are useful examples of how to safely and efficiently interact with Uniswap V2.

Library

Reference documentation

The library provides a variety of convenience functions for fetching data and pricing.

Router

Reference documentation

The router, which uses the library, fully supports all the basic requirements of a front-end offering trading and liquidity management functionality. Notably, it natively supports multi-pair trades (e.g. x to y to z), treats ETH as a first-class citizen, and offers meta-transactions for removing liquidity.

The following sections describe some of the notable design decisions made in Uniswap V2. These are safe to skip unless you're interested in gaining a deep technical understanding of how V2 works under the hood, or writing smart contract integrations!

Sending Tokens

Typically, smart contracts which need tokens to perform some functionality require would-be interactors to first make an approval on the token contract, then call a function that in turn calls transferFrom on the token contract. This is not how V2 pairs accept tokens. Instead, pairs check their token balances at the end of every interaction. Then, at the beginning of the next interaction, current balances are differenced against the stored values to determine the amount of tokens that were sent by the current interactor. See the whitepaper for a justification of why this is the case, but the takeaway is that tokens must be transferred to the pair before calling any token-requiring method (the one exception to this rule is Flash Swaps.

WETH

Unlike Uniswap V1 pools, V2 pairs do not support ETH directly, so ETH⇄ERC-20 pairs must be emulated with WETH. The motivation behind this choice was to remove ETH-specific code in the core, resulting in a leaner codebase. End users can be kept fully ignorant of this implementation detail, however, by simply wrapping/unwrapping ETH in the periphery.

The router fully supports interacting with any WETH pair via ETH.

Minimum Liquidity

To ameliorate rounding errors and increase the theoretical minimum tick size for liquidity provision, pairs burn the first MINIMUM_LIQUIDITY pool tokens. For the vast majority of pairs, this will represent a trivial value. The burning happens automatically during the first liquidity provision, after which point the totalSupply is forevermore bounded.

Smart contracts | Uniswap (2024)
Top Articles
What is Coming soon in English?
Megalodon Size: How Big Was The Megalodon Shark?
Public Opinion Obituaries Chambersburg Pa
It’s Time to Answer Your Questions About Super Bowl LVII (Published 2023)
Victory Road Radical Red
Truist Bank Near Here
Overton Funeral Home Waterloo Iowa
What happened to Lori Petty? What is she doing today? Wiki
Blackstone Launchpad Ucf
Seething Storm 5E
Holly Ranch Aussie Farm
27 Places With The Absolute Best Pizza In NYC
Directions To Lubbock
Ou Class Nav
AB Solutions Portal | Login
41 annonces BMW Z3 occasion - ParuVendu.fr
Turning the System On or Off
Local Dog Boarding Kennels Near Me
Costco Gas Foster City
Craigslist Panama City Fl
Patrick Bateman Notebook
Second Chance Maryland Lottery
111 Cubic Inch To Cc
Sadie Proposal Ideas
Zack Fairhurst Snapchat
Missed Connections Inland Empire
Christina Steele And Nathaniel Hadley Novel
Panic! At The Disco - Spotify Top Songs
Walmart Car Department Phone Number
Selfservice Bright Lending
Garnish For Shrimp Taco Nyt
UMvC3 OTT: Welcome to 2013!
Regal Amc Near Me
Ticket To Paradise Showtimes Near Cinemark Mall Del Norte
Craigslist/Phx
Rugged Gentleman Barber Shop Martinsburg Wv
Fastpitch Softball Pitching Tips for Beginners Part 1 | STACK
Scioto Post News
Federal Student Aid
SOC 100 ONL Syllabus
ATM Near Me | Find The Nearest ATM Location | ATM Locator NL
Daily Times-Advocate from Escondido, California
Improving curriculum alignment and achieving learning goals by making the curriculum visible | Semantic Scholar
Gfs Ordering Online
412Doctors
Victoria Vesce Playboy
Devotion Showtimes Near Showplace Icon At Valley Fair
Okta Login Nordstrom
18 Seriously Good Camping Meals (healthy, easy, minimal prep! )
Great Clips Virginia Center Commons
Latest Posts
Article information

Author: Nathanael Baumbach

Last Updated:

Views: 5531

Rating: 4.4 / 5 (75 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Nathanael Baumbach

Birthday: 1998-12-02

Address: Apt. 829 751 Glover View, West Orlando, IN 22436

Phone: +901025288581

Job: Internal IT Coordinator

Hobby: Gunsmithing, Motor sports, Flying, Skiing, Hooping, Lego building, Ice skating

Introduction: My name is Nathanael Baumbach, I am a fantastic, nice, victorious, brave, healthy, cute, glorious person who loves writing and wants to share my knowledge and understanding with you.