-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit b4dec0b Author: Emily Williams <[email protected]> Date: Thu Jun 8 19:53:42 2023 -0400 extsload interface as view function (#201) commit ebff901 Author: Alice <[email protected]> Date: Thu Jun 8 20:55:25 2023 +0100 Fix tree and example in readme (#198) * Fix tree and example in readme * Update README.md commit 7e940f8 Author: guoemma13 <[email protected]> Date: Thu Jun 8 13:28:10 2023 -0400 migrate init and mint tests (#185) * tests in progress * initialize and mint tests * tests cleanup * checks are passing * delete hardhat tests * fix comments * failing tests with negative tick * all working swap tests * check swap tests * run formatter * remove hardhat tests * failing with EmptyTestHooks * simplified MockHooksSimple * separate tests * update gas snapshot tests * failing with testhooksimpl * finish tests * cleanup * fix error --------- Co-authored-by: Emma Guo <[email protected]> Co-authored-by: emmaguo13 <[email protected]> Co-authored-by: emmaguo13 <[email protected]> Co-authored-by: emma <[email protected]> commit e46262c Author: Emily Williams <[email protected]> Date: Thu Jun 8 11:20:14 2023 -0400 extsload (#199) * extsload with tests * consistent number formatting in assembly commit ae7a8e1 Author: Sara Reynolds <[email protected]> Date: Thu Jun 8 13:41:21 2023 +0000 pr template (#196) Co-authored-by: Alice <[email protected]> commit d797d8d Author: Sara Reynolds <[email protected]> Date: Thu Jun 8 11:44:29 2023 +0000 readme update (#195) Co-authored-by: Alice <[email protected]> commit 4e161fa Author: Noah Zinsmeister <[email protected]> Date: Thu Jun 8 06:24:10 2023 -0400 make BalanceDelta a type (#180) * add type * add type to impl fix tests update snapshots * create new toInt128 commit 93ab363 Author: Sara Reynolds <[email protected]> Date: Thu Jun 8 01:26:18 2023 +0000 add contribution guidelines (#194) commit 2279064 Author: Sara Reynolds <[email protected]> Date: Wed Jun 7 23:48:16 2023 +0000 fix: feature template (#193) commit 6264ed3 Author: Sara Reynolds <[email protected]> Date: Wed Jun 7 22:49:42 2023 +0000 Revert "fix feature template" This reverts commit 479a00a. commit 479a00a Author: Sara Reynolds <[email protected]> Date: Wed Jun 7 22:48:43 2023 +0000 fix feature template commit 85b16d3 Author: Sara Reynolds <[email protected]> Date: Wed Jun 7 22:40:30 2023 +0000 Update FEATURE_IMPROVEMENT.yml commit 283409f Author: Sara Reynolds <[email protected]> Date: Wed Jun 7 22:36:11 2023 +0000 add feature improvement template (#192) commit 469a87c Author: Sara Reynolds <[email protected]> Date: Wed Jun 7 21:06:57 2023 +0000 Add bug report template (#191) Co-authored-by: Alice <[email protected]>
- Loading branch information
Showing
39 changed files
with
1,618 additions
and
1,192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
131974 | ||
131166 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
186556 | ||
185853 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
61078 | ||
61013 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
37159 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
319866 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
293959 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
312546 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
1151 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2763 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
161936 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
161293 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
145923 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
67335 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Bug report | ||
description: File a bug report to help us improve the code | ||
title: "[Bug]: " | ||
labels: ["bug"] | ||
|
||
body: | ||
- type: markdown | ||
attributes: | ||
value: | | ||
Please check that the bug is not already being tracked. | ||
- type: textarea | ||
attributes: | ||
label: Describe the bug | ||
description: Provide a clear and concise description of what the bug is and which contracts it affects. | ||
validations: | ||
required: true | ||
- type: textarea | ||
attributes: | ||
label: Expected Behavior | ||
description: Provide a clear and concise description of the desired fix. | ||
validations: | ||
required: true | ||
- type: input | ||
attributes: | ||
label: To Reproduce | ||
description: If you have written tests to showcase the bug, what can we run to reproduce the issue? | ||
placeholder: "git checkout <branchname> / forge test --match-test <testName>" | ||
- type: textarea | ||
attributes: | ||
label: Additional context | ||
description: If there is any additional context needed like a dependency or integrating contract that is affected please describe it below. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Feature Improvement | ||
description: Suggest an improvement to v4-core. | ||
labels: ["triage"] | ||
|
||
body: | ||
- type: markdown | ||
attributes: | ||
value: | | ||
Please ensure that the feature has not already been requested. | ||
- type: checkboxes | ||
attributes: | ||
label: Components | ||
description: What architectural feature or area of code does your idea improve? | ||
options: | ||
- label: Hooks | ||
- label: Singleton | ||
- label: Lock and Call | ||
- label: Delta accounting | ||
- label: 1155 Balances | ||
- label: Pool Actions (swap, modifyPosition, donate, take, settle, mint) | ||
- label: Gas Optimization | ||
- label: General design optimization (improving efficiency, cleanliness, or developer experience) | ||
- label: Documentation | ||
validations: | ||
required: true | ||
- type: textarea | ||
attributes: | ||
label: Describe the suggested feature and problem it solves. | ||
description: Provide a clear and concise description of what feature you would like to see, and what problems it solves. | ||
validations: | ||
required: true | ||
- type: textarea | ||
attributes: | ||
label: Describe the desired implementation. | ||
description: If possible, provide a suggested architecture change or implementation. | ||
- type: textarea | ||
attributes: | ||
label: Describe alternatives. | ||
description: If possible, describe the alternatives you've considered, or describe the current functionality and how it may be sub-optimal. | ||
- type: textarea | ||
attributes: | ||
label: Additional context. | ||
description: Please list any additional dependencies or integrating contacts that are affected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## Related Issue | ||
Which issue does this pull request resolve? | ||
|
||
## Description of changes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Contribution Guidelines | ||
|
||
Thanks for your interest in contributing to v4 of the Uniswap Protocol! The contracts in this repo are in early stages. There is a lot more development left before v4 is in a stable and production-ready state, and so we appreciate any kind of contribution, no matter how small. | ||
|
||
If you need to get in contact with the repository maintainers, please reach out in our [Discord](https://discord.com/invite/FCfyBSbCU5) . | ||
|
||
## Types of Contributing | ||
|
||
There are many ways to contribute, but here are a few if you want a place to start: | ||
|
||
1. **Opening an issue.** Before opening an issue please check that there is not an issue already open. If there is, feel free to comment more details, explanations, or examples within the open issue rather than duplicating it. Suggesting changes to the open development process are within the bounds of opening issues. We are always open to feedback and receptive to suggestions! | ||
2. **Resolving an issue.** You can resolve an issue either by showing that it is not an issue or by fixing the issue with code changes, additional tests, etc. Any pull request fixing an issue should reference that issue. | ||
3. **Reviewing open PRs.** You can provide comments, standards guidance, naming suggesetions, gas optimizations, or ideas for alternative designs on any open pull request. | ||
|
||
## Opening an Issue | ||
|
||
When opening an [issue](https://github.com/Uniswap/core-next/issues/new/choose), choose a template to start from, either a Bug Report or a Feature Improvement. For bug reports, you should be able to reproduce the bug through tests or proof of concept integrations. For feature improvements, please title it with a concise problem statement and check that a similar request is not already open or already in progress. Not all issues may be deemed worth resolving, so please follow through with responding to any questions or comments that others may have regarding the issue. | ||
|
||
Feel free to tag the issue as a “good first issue” for any clean-up related issues, or small scoped changes to help encourage pull requests from first time contributors! | ||
|
||
## Opening a Pull Request | ||
|
||
All pull requests should be opened against the `main` branch. In the pull request, please reference the issue you are fixing. | ||
|
||
Pull requests can be reviewed by community members, but to be merged they will need approval from 2 of the repository maintainers. Please allow up to a week to receive a response, although the maintainers will aim to respond and comment as soon as possible. | ||
|
||
**For larger, more substantial changes to the code, it is best to open an issue and start a discussion with the maintainers to align on the change before spending time on the development.** | ||
|
||
Finally, before opening a pull request please do the following: | ||
|
||
- Check that the code style follows the [standards](#standards). | ||
- Run the tests and snapshots. Commands are outlined in the [tests](#tests) section. | ||
- Document any new functions, structs, or interfaces following the natspec standard. | ||
- Add tests! For smaller contributions, they should be tested with unit tests, and fuzz tests where possible. For bigger contributions, they should be tested with integration tests and invariant tests where possible. | ||
|
||
## Standards | ||
|
||
All contributions must follow the below standards. Maintainers will close out PRs that do not adhere to these standards. | ||
|
||
1. All contracts should be formatted with the default forge fmt config. Run `forge fmt`. | ||
2. These contracts follow the [solidity style guide](https://docs.soliditylang.org/en/v0.8.17/style-guide.html) with one minor exception of using the _prependUnderscore style naming for internal contract functions, internal top-level parameters, and function parameters with naming collisions. | ||
3. All external facing contracts should inherit from interfaces, which specify and document its functions with natspec. | ||
4. Picking up stale issues by other authors is fine! Please just communicate with them ahead of time and it is best practice to include co-authors in any commits. | ||
5. Squash commits where possible to make reviews clean and efficient. PRs that are merged to main will be squashed into 1 commit. | ||
|
||
## Tests | ||
|
||
This repo currently uses hardhat and forge tests.* Please run both test suites before opening a PR. | ||
|
||
`yarn snapshots` to update the hardhat gas snapshots | ||
|
||
`yarn test` to run hardhat tests | ||
|
||
`yarn prettier` to run the formatter (runs both typescript and solidity formatting) | ||
|
||
`forge snapshot`to update the forge gas snapshots | ||
|
||
`forge test` to run forge tests | ||
|
||
Any new tests that you add should be written with forge, as the repo is undergoing a full migration to the forge test suite. | ||
|
||
*Mythx was also used but is no longer run and in the process of being deprecated fully from the repo. | ||
|
||
## Code of Conduct | ||
|
||
Above all else, please be respectful of the people behind the code. Any kind of aggressive or disrespectful comments, issues, and language will be removed. | ||
|
||
Issues and PRs that are obviously spam and unhelpful to the development process or unrelated to the core code will also be closed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,94 @@ | ||
# Uniswap Protocol | ||
# Uniswap v4 Core | ||
|
||
[![Lint](https://github.com/Uniswap/core-next/actions/workflows/lint.yml/badge.svg)](https://github.com/Uniswap/core-next/actions/workflows/lint.yml) | ||
[![Tests](https://github.com/Uniswap/core-next/actions/workflows/tests.yml/badge.svg)](https://github.com/Uniswap/core-next/actions/workflows/tests.yml) | ||
[![Mythx](https://github.com/Uniswap/core-next/actions/workflows/mythx.yml/badge.svg)](https://github.com/Uniswap/core-next/actions/workflows/mythx.yml) | ||
[![npm version](https://img.shields.io/npm/v/@uniswap/core-next/latest.svg)](https://www.npmjs.com/package/@uniswap/core-next/v/latest) | ||
|
||
This repository contains the smart contracts for the Uniswap Protocol. | ||
Uniswap v4 is a new automated market market protocol that provides extensibility and customizability to pools. `v4-core` hosts the core pool logic for creating pools and executing pool actions like swapping and providing liquidity. | ||
|
||
## Local deployment | ||
## Architecture | ||
|
||
In order to deploy this code to a local testnet, you should install the npm package | ||
`@uniswap/core-next` | ||
and import the factory bytecode located at | ||
`@uniswap/core-next/artifacts/contracts/PoolManager.sol/PoolManager.json`. | ||
For example: | ||
`v4-core` uses a singleton-style architecture, where all pool state is managed in the `PoolManager.sol` contract. Pool actions can be taken by acquiring a lock on the contract and implementing the `lockAcquired` callback to then proceed with any of the following actions on the pools: | ||
|
||
```typescript | ||
import { | ||
abi as FACTORY_ABI, | ||
bytecode as FACTORY_BYTECODE, | ||
} from '@uniswap/core-next/artifacts/contracts/PoolManager.sol/PoolManager.json' | ||
- `swap` | ||
- `modifyPosition` | ||
- `donate` | ||
- `take` | ||
- `settle` | ||
- `mint` | ||
|
||
// deploy the bytecode | ||
Only the net balances owed to the pool (negative) or to the user (positive) are tracked throughout the duration of a lock. This is the `delta` field held in the lock state. Any number of actions can be run on the pools, as long as the deltas accumulated during the lock reach 0 by the lock’s release. This lock 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}ModifyPosition | ||
- {before,after}Swap | ||
- {before,after}Donate | ||
|
||
Hooks may also elect to specify fees on swaps, or liquidity withdrawal. Much like the actions above, fees are implemented using callback functions. | ||
|
||
The fee values, or callback logic, may be updated by the hooks dependent on their implementation. However _which_ callbacks are executed on a pool, including the type of fee or lack of fee, cannot change after pool initialization. | ||
|
||
Read a more in-depth overview of the design decisions in the working v4-whitepaper. | ||
|
||
## Repository Structure | ||
|
||
All contracts are held within the `core-next/contracts` folder. | ||
|
||
Note that helper contracts used by tests are held in the `core-next/contracts/test` subfolder within the contracts folder. Any new test helper contracts should be added here, but all foundry tests are in the `core-next/test/foundry-tests` folder. | ||
|
||
```markdown | ||
contracts/ | ||
----interfaces/ | ||
| IPoolManager.sol | ||
| ... | ||
----libraries/ | ||
| Position.sol | ||
| Pool.sol | ||
| ... | ||
----test | ||
... | ||
PoolManager.sol | ||
test/ | ||
----foundry-tests/ | ||
``` | ||
|
||
This will ensure that you are testing against the same bytecode that is deployed to | ||
mainnet and public testnets, and all Uniswap code will correctly interoperate with | ||
your local deployment. | ||
## Local deployment and Usage | ||
|
||
## Using solidity interfaces | ||
To utilize the contracts and deploy to a local testnet, you can install the code in your repo with forge: | ||
|
||
The Uniswap v3 interfaces are available for import into solidity smart contracts | ||
via the npm artifact `@uniswap/core-next`, e.g.: | ||
```markdown | ||
forge install https://github.com/Uniswap/core-next | ||
``` | ||
|
||
To integrate with the contracts, the interfaces are available to use: | ||
|
||
```solidity | ||
import '@uniswap/core-next/contracts/interfaces/IPoolManager.sol'; | ||
contract MyContract { | ||
IPoolManager pool; | ||
import {IPoolManager} from 'core-next/contracts/interfaces/IPoolManager.sol'; | ||
import {ILockCallback} from 'core-next/contracts/interfaces/callback/ILockCallback.sol'; | ||
contract MyContract is ILockCallback { | ||
IPoolManager poolManager; | ||
function doSomethingWithPools() { | ||
// this function will call `lockAcquired` below | ||
poolManager.lock(...); | ||
} | ||
function doSomethingWithPool() { | ||
// pool.swap(...); | ||
} | ||
function lockAcquired(uint256 id, bytes calldata data) external returns (bytes memory) { | ||
// perform pool actions | ||
poolManager.swap(...) | ||
} | ||
} | ||
``` | ||
|
||
## Contributing | ||
|
||
If you’re interested in contributing please see the [contribution guidelines](https://github.com/Uniswap/core-next/blob/main/CONTRIBUTING.md)! | ||
|
||
## License | ||
|
||
The primary license for Uniswap V4 Core is the Business Source License 1.1 (`BUSL-1.1`), see [LICENSE](https://github.com/Uniswap/core-next/blob/main/LICENSE) | ||
|
Oops, something went wrong.