Skip to content

Latest commit

 

History

History
30 lines (22 loc) · 2.48 KB

File metadata and controls

30 lines (22 loc) · 2.48 KB

English | 中文

Deep Dive into Uniswap v4 Smart Contracts

tags: uniswap uniswap-v4 smart contract solidity

Workflow

The following diagram shows the workflow of Uniswap v4 contracts:

Similar to Uniswap v2/v3, Uniswap v4 contracts are also divided into two repositories:

  • v4-core [Github]: Contains the core contracts of Uniswap v4, mainly including:

    • PoolManager.sol: Singleton contract that manages all Uniswap v4 pools, providing all external interfaces for pools, including creation, liquidity modification, swap, etc.
    • Library contracts:
      • Pool.sol: Pool Library contract, used to execute specific operations for each pool, such as liquidity modification, swap, etc.
      • Position.sol: Position Library contract, used to execute specific operations related to each position, such as modifying liquidity and fees.
      • Hooks.sol: Hooks Library contract, used to execute the Hooks functions of Uniswap v4 contracts.
      • CurrencyDelta.sol: CurrencyDelta Library contract, used to execute operations related to Flash Accounting.
      • BalanceDelta.sol:BalanceDelta defines the type of balance delta.
  • v4-periphery [Github]: Contains the peripheral contracts of Uniswap v4, mainly including:

    • PositionManager.sol: PositionManager contract, used to manage the minting, burning, and liquidity modification of positions, calling PoolManager to execute specific operations.
      • External contracts operate positions through the PositionManager contract, rather than directly calling the v4-core PoolManager contract.
      • Supports combining multiple operations into a single transaction, ensuring atomicity of transactions and reducing gas consumption.
    • V4Router.sol: V4Router contract, used to execute trading operations, calling PoolManager to execute specific trading operations.
      • Supports single-hop and multi-hop trading.
      • Supports specifying the exact input or output token amount.