# Uniswap v4 Core repo Source: https://github.com/Uniswap/v4-core Kiwi News: https://news.kiwistand.com/stories/Uniswap-v4-Core-repo?index=0x64886d0b1c3b2de17cb5997f471a9cc041adf704e7921b9718787e5c2789d7b864a46bea Submitted by thatalexpalmer.eth on 2023-06-13 UTC, 6 upvotes, 0 comments ## Summary Uniswap v4 Core is the draft code repository for Uniswap v4, a new automated market maker protocol with extensible, customizable pools, released so the protocol can be built in public with community feedback. The repo's README says the project is expected to be a months-long process and that any contribution is welcome. All pool state is managed in the PoolManager.sol contract, and integrators call unlock, then implement unlockCallback to run actions such as swap, modifyLiquidity and donate. Pools can be initialized with a hook contract, and the set of callbacks executed on a pool cannot change after initialization. ## Article Uniswap v4 is a new automated market maker protocol that provides extensible and customizable pools. v4-core hosts the core pool logic for creating pools and executing pool actions like swapping and providing liquidity. The contracts in this repo are in early stages - we are releasing the draft code now so that v4 can be built in public, with open feedback and meaningful community contribution. We expect this will be a months-long process, and we appreciate any kind of contribution, no matter how small. Contributing If you’re interested in contributing please see our contribution guidelines! Whitepaper A more detailed description of Uniswap v4 Core can be found in the draft of the Uniswap v4 Core Whitepaper. Architecture v4-core uses a singleton-style architecture, where all pool state is managed in the PoolManager.sol contract. Pool actions can be taken after an initial call to unlock. Integrators implement the unlockCallback and proceed with any of the following actions on the pools: swap modifyLiquidity donate take settle mint burn Note that pool initialization can happen outside the context of unlocking the PoolManager. Only the net balances owed to the user (positive) or to the pool (negative) are tracked throughout the duration of an unlock. This is the delta field held in the unlock state. Any number of actions can be run on the pools, as long as the deltas accumulated during the unlock reach 0 by the unlock’s release. This unlock and call style architecture gives callers maximum flexibility in integrating with the core code. Additionally, a pool may be initialized with a hook contract, that can implement any of the following callbacks in the lifecycle of pool actions: {before,after}Initialize {before,after}AddLiquidity {before,after}RemoveLiquidity {before,after}Swap {before,after}Donate The callback logic, may be updated by the hooks dependent on their implementation. However which callbacks are executed on a pool cannot change after pool initialization. Repository Structure All contracts are held within the v4-core/src folder. Note that helper contracts used by tests are held in the v4-core/src/test subfolder within the src folder. Any new test helper contracts should be added here, but all foundry tests are in the v4-core/test folder. src/ ----interfaces/ | IPoolManager.sol | ... ----libraries/ | Position.sol | Pool.sol | ... ----test ----PoolManager.sol ... test/ ----libraries/ | Position.t.sol | Pool.t.sol Local deployment and Usage To utilize the contracts and deploy to a local testnet, you can install the code in your repo with forge: forge install https://github.com/Uniswap/v4-core To integrate with the contracts, the interfaces are available to use: import {IPoolManager} from 'v4-core/contracts/interfaces/IPoolManager.sol'; import {IUnlockCallback} from 'v4-core/contracts/interfaces/callback/IUnlockCallback.sol'; contract MyContract is IUnlockCallback { IPoolManager poolManager; function doSomethingWithPools() { // this function will call `unlockCallback` below poolManager.unlock(...); } function unlockCallback(bytes calldata data) external returns (bytes memory) { // disallow arbitrary caller if (msg.sender != address(poolManager) revert Unauthorized(); // perform pool actions poolManager.swap(...) } } error Unauthorized(); License Uniswap V4 Core is licensed under the Business Source License 1.1 (BUSL-1.1), see BUSL_LICENSE, and the MIT License (MIT), see MIT_LICENSE. Each file in Uniswap V4 Core states the applicable license type in the header.