https://github.com/saucepoint/v4-constant-sum
Constant-sum AMM curve on Uniswap v4
https://github.com/saucepoint/v4-constant-sum
Last synced: 18 days ago
JSON representation
Constant-sum AMM curve on Uniswap v4
- Host: GitHub
- URL: https://github.com/saucepoint/v4-constant-sum
- Owner: saucepoint
- License: mit
- Created: 2023-12-04T15:20:21.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-19T23:45:13.000Z (3 months ago)
- Last Synced: 2025-04-30T05:02:06.972Z (18 days ago)
- Language: Solidity
- Size: 50.8 KB
- Stars: 16
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-uniswap-v4-resources - Constant-sum Swap - sum swaps (x + y = k), allowing for an exact 1:1 swap everytime. (📑 Table of Contents / From Community)
- awesome-uniswap-v4-resources - Constant-sum Swap - sum swaps (x + y = k), allowing for an exact 1:1 swap everytime. (📑 Table of Contents / From Community)
- awesome-uniswap-hooks - Constant-sum Swap - sum swaps (x + y = k), allowing for an exact 1:1 swap everytime. (📜 Examples / From Community)
README
# v4-constant-sum
### **Constant-sum swap on Uniswap v4 🦄**> **This repo is not production ready, and only serves as an example for custom curves on v4**
With [recent changes](https://github.com/Uniswap/v4-core/pull/404) to v4, Hooks can swap on custom curves!
`v4-constant-sum` implements constant-sum swaps (*x + y = k*), allowing for an exact 1:1 swap everytime
---
## Methodology
2. The hook will hold its own token balances (as liquidity for the constant-sum curve)
3. The `beforeSwap` hook will handle the constant-sum curve:
1. inbound tokens are taken from the PoolManager
* this creates a debt, that is paid for by the swapper via the swap router
* the inbound token is added to the hook's reserves
2. an *equivalent* number of outbound tokens is sent from the hook to the PoolManager
* the outbound token is removed from the hook's reserves
* this creates a credit -- the swap router claims it and sends it to the swapper---
Additional resources:
[v4-template](https://github.com/uniswapfoundation/v4-template) provides a minimal template and environment for developing v4 hooks
[Uniswap v4 docs](https://docs.uniswap.org/contracts/v4/overview)
[v4-periphery](https://github.com/uniswap/v4-periphery) contains advanced hook implementations that serve as a great reference
[v4-core](https://github.com/uniswap/v4-core)
[v4-by-example](https://v4-by-example.org)