A very simple consant sum AMM
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
To get a local copy up and running follow these simple example steps.
To get a local copy up and running follow these simple example steps.
-
npm
npm install npm@latest -g
-
hardhat
npm install --save-dev hardhat
npm install @nomiclabs/hardhat-ethers @nomiclabs/hardhat-waffle
run:
npx hardhat
- Clone the repo
git clone https://github.com/Aboudoc/Constant-Sum-AMM.git
- Install NPM packages
npm install
If you need testnet funds, use the Alchemy testnet faucet.
This project shows a basic example of Constant Sum AMM
Constant sum AMM (automated market maker) is a decentralized exchange that trades two tokens in the contract.
Users will be able to add liquidity and earn swap fees, swap tokens and remove liquidity
The amount of token to come out of the trade is determined by the following equation.
X = amount of token A in the contract
Y = amount of token B in the contract
K = a constant that satisfies the following equation
X + Y = K
X + Y equals some constant K, hence the name constant sum.
This equation X + Y = K must be true before and after every swap.
dx = Amount of token A that came in from the swap
dy = Amount of token B that went out from the swap
# Before the trade
X + Y = K
# After the trade
X + dx + Y - dy = K
Since X + Y = K, replace K in the second equation X + dx + Y - dy = K with X + Y
X + dx + Y - dy = X + Y
dx - dy = 0
dx = dy
In other words, the amount of token coming in from a swap must equal the amount of token going out.
This contract assumes that token0 and token1 both have same decimals
Consider fees = 3%
(...soon)
- Further reading
- Deploy script
- Unit test
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Reda Aboutika - @twitter - reda.aboutika@gmail.com
Project Link: https://github.com/Aboudoc/Constant-Sum-AMM.git