Sources
Uniswap-v2 Contract Walk-Through | ethereum.org
https://github.com/Uniswap/v2-core
Code Structure
Core
Minimal code for leaving little room for error. However, it is user-unfriendly, so interacting directly with core contracts are not recommended.
-
Factory
Create one and only uniquer smart contract per unique token pair
-
Pairs
Serves as automated market makers and keep track of pool token balances. Also expose data for price oracles.
Periphery
Useful examples of how to safely and efficiently interact with Uniswap V2.
-
Library
Convenience functions for fetching data and pricing
-
Router
Basic requirements of front-end offering trading and liquidity management functionality.
Design Decisions
Sending Tokens
- Before V2
- Interactors approve token contract.
- Call function that calls
transferFrom
on token contract.
- Since V2
- End of interaction, pairs check their token balances.
- Beginning of next interaction, compare the current balance with stored value to determine the amount of token sent by interactor.
WETH
V2 doesn’t support ETH, which emulates ETH with WETH. This is because to remove the ETH-specific code in the core. Wrapping/Unwrapping in supported in periphery.
Top comments (0)