{"content":{"title":"uniswap_v4 core 合约结构解析","body":"# uniswap_v4 core 合约结构解析\r\n\r\n## 备注\r\n\r\n时间：2023 年 8 月 6 日\r\n\r\n作者：[33357](https://github.com/33357)\r\n\r\n## 正文\r\n\r\nuniswap-v4 core 由 23 个实现合约构成，通过解析图可以快速了解该合约的结构。\r\n\r\n### 完整版\r\n\r\n```mermaid\r\n\tgraph TD\r\n    FeeLibrary --> Hooks\r\n    SafeCast --> Pool\r\n    TickBitmap --> Pool\r\n    Position --> Pool\r\n    FullMath --> Pool\r\n    FixedPoint128 --> Pool\r\n    TickMath --> Pool\r\n    SqrtPriceMath --> Pool\r\n    SwapMath --> Pool\r\n    BalanceDelta --> Pool\r\n    FullMath --> Position\r\n    FixedPoint128 --> Position\r\n    SafeCast --> SqrtPriceMath\r\n    FullMath --> SqrtPriceMath\r\n    UnsafeMath --> SqrtPriceMath\r\n    FixedPoint96 --> SqrtPriceMath\r\n    FullMath --> SwapMath\r\n    SqrtPriceMath --> SwapMath\r\n    BitMath --> TickBitmap\r\n\r\n    Currency --> PoolKey\r\n    PoolKey --> PoolId\r\n\r\n    Currency -->Fees\r\n    FeeLibrary -->Fees\r\n    PoolKey -->Fees\r\n    Owned -->Fees\r\n    Hooks --> PoolManager\r\n    Pool --> PoolManager\r\n    SafeCast --> PoolManager\r\n    Position --> PoolManager\r\n    FeeLibrary --> PoolManager\r\n    Currency --> PoolManager\r\n    PoolKey --> PoolManager\r\n    LockDataLibrary --> PoolManager\r\n    NoDelegateCall --> PoolManager\r\n    Fees --> PoolManager\r\n    ERC1155 --> PoolManager\r\n    PoolId --> PoolManager\r\n    BalanceDelta --> PoolManager\r\n```\r\n\r\n### 简化版\r\n\r\n```mermaid\r\n\tgraph TD\r\n    FeeLibrary --> Hooks\r\n    TickBitmap --> Pool\r\n    Position --> Pool\r\n    TickMath --> Pool\r\n    SwapMath --> Pool\r\n    BalanceDelta --> Pool\r\n    FullMath --> Position\r\n    FixedPoint128 --> Position\r\n    SafeCast --> SqrtPriceMath\r\n    FullMath --> SqrtPriceMath\r\n    UnsafeMath --> SqrtPriceMath\r\n    FixedPoint96 --> SqrtPriceMath\r\n    SqrtPriceMath --> SwapMath\r\n    BitMath --> TickBitmap\r\n\r\n    Currency --> PoolKey\r\n    PoolKey --> PoolId\r\n\r\n    FeeLibrary -->Fees\r\n    PoolKey -->Fees\r\n    Owned -->Fees\r\n    Hooks --> PoolManager\r\n    Pool --> PoolManager\r\n    LockDataLibrary --> PoolManager\r\n    NoDelegateCall --> PoolManager\r\n    Fees --> PoolManager\r\n    ERC1155 --> PoolManager\r\n    PoolId --> PoolManager\r\n```\r\n\r\n### 解释版\r\n\r\n```mermaid\r\n\tgraph TD\r\n    FeeLibrary(FeeLibrary fee方法)\r\n    FullMath(FullMath 安全计算)\r\n    FixedPoint128(FixedPoint128)\r\n    FixedPoint96(FixedPoint96)\r\n    SafeCast(SafeCast 类型转换)\r\n    UnsafeMath(UnsafeMath 不安全计算)\r\n    SqrtPriceMath(SqrtPriceMath price计算)\r\n    BitMath(BitMath bit计算)\r\n    TickBitmap(TickBitmap tick映射bit)\r\n    TickMath(TickMath tick计算)\r\n    SwapMath(SwapMath swap计算)\r\n    Position(Position 头寸)\r\n    LockDataLibrary(LockDataLibrary lockData方法)\r\n    Hooks(Hooks 钩子)\r\n    Pool(Pool 流动池)\r\n\r\n    BalanceDelta(BalanceDelta delta方法)\r\n    Currency(Currency token方法)\r\n    PoolKey(PoolKey 流动池key)\r\n    PoolId(PoolId 流动池id)\r\n    \r\n    Owned(Owned 所有者)\r\n    Fees(Fees 手续费)\r\n    NoDelegateCall(NoDelegateCall 禁止委托调用)\r\n    ERC1155(ERC1155 1155实现)\r\n    PoolManager(PoolManager 流动池管理)\r\n\r\n    FeeLibrary --> Hooks\r\n    TickBitmap --> Pool\r\n    Position --> Pool\r\n    TickMath --> Pool\r\n    SwapMath --> Pool\r\n    BalanceDelta --> Pool\r\n    FullMath --> Position\r\n    FixedPoint128 --> Position\r\n    SafeCast --> SqrtPriceMath\r\n    FullMath --> SqrtPriceMath\r\n    UnsafeMath --> SqrtPriceMath\r\n    FixedPoint96 --> SqrtPriceMath\r\n    SqrtPriceMath --> SwapMath\r\n    BitMath --> TickBitmap\r\n\r\n    Currency --> PoolKey\r\n    PoolKey --> PoolId\r\n\r\n    FeeLibrary -->Fees\r\n    PoolKey -->Fees\r\n    Owned -->Fees\r\n    Hooks --> PoolManager\r\n    Pool --> PoolManager\r\n    LockDataLibrary --> PoolManager\r\n    NoDelegateCall --> PoolManager\r\n    Fees --> PoolManager\r\n    ERC1155 --> PoolManager\r\n    PoolId --> PoolManager\r\n```\r\n\r\n## 原文发布在 <https://github.com/33357/smartcontract-apps> 这是一个面向中文社区，分析市面上智能合约应用的架构与实现的仓库。欢迎关注开源知识项目！"},"author":{"user":"https://learnblockchain.cn/people/3877","address":"0x1f2479ee1b4aFE789e19D257D2D50810ac90fa59"},"history":null,"timestamp":1694402033,"version":1}