https://github.com/jitendragangwar123/peer2play-swap
A decentralized liquidity pool that supports custom ERC20 tokens, using a constant product AMM model. Users can add liquidity, remove liquidity, swap tokens, and earn rewards.
https://github.com/jitendragangwar123/peer2play-swap
dapps defi ethereum foundry nextjs solidity testing token-swap
Last synced: 3 months ago
JSON representation
A decentralized liquidity pool that supports custom ERC20 tokens, using a constant product AMM model. Users can add liquidity, remove liquidity, swap tokens, and earn rewards.
- Host: GitHub
- URL: https://github.com/jitendragangwar123/peer2play-swap
- Owner: jitendragangwar123
- Created: 2025-01-16T16:49:54.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-17T14:58:34.000Z (over 1 year ago)
- Last Synced: 2025-01-27T06:38:14.320Z (over 1 year ago)
- Topics: dapps, defi, ethereum, foundry, nextjs, solidity, testing, token-swap
- Language: TypeScript
- Homepage: https://peer2-play-swap.vercel.app
- Size: 483 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Peer2Play Swap ๐ฐ
**Peer2Play Swap** is a decentralized liquidity pool contract that facilitates the swapping and liquidity provision of two ERC20 tokens. It implements a **constant product AMM model** with a **5% fee split** (4% for liquidity providers and 1% for the contract), ensuring a fair and efficient environment for token swaps and liquidity mining.

---
### ๐ Features
- **Decentralized Liquidity Pool**: A smart contract-based pool for token swaps between two ERC20 tokens.
- **Constant Product AMM**: Uses the constant product formula for swap calculations (x * y = k).
- **Liquidity Provider Incentives**: 4% of swap fees distributed to liquidity providers.
- **Contract Fee**: 1% of swap fees go to the contract.
- **Fair Fee Distribution**: Fees are distributed proportionally based on liquidity shares.
- **Flexible Liquidity Addition and Removal**: Liquidity can be added or removed in proportion to shares in the pool.
- **Provably Fair Swaps**: Token swaps are based on a constant product model for fair pricing.
- **Event Logging**: Tracks key events such as liquidity addition/removal, swaps, and fee distributions.
---
### ๐ Requirements
Before you start, ensure that you have the following installed:
- [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- [Foundry](https://getfoundry.sh/)
### โก Quickstart
Clone the repository and set up your environment:
```
$ git clone https://github.com/jitendragangwar123/Peer2Play-Swap
$ cd Peer2Play-Swap
$ make install
$ forge build
```
### ๐ Deployment to a Testnet or Mainnet
#### 1. Setup Environment Variables
You'll need to set your `SEPOLIA_RPC_URL` and `PRIVATE_KEY` as environment variables. You can add them to a `.env` file in your project directory.
Optionally, you can also add your `ETHERSCAN_API_KEY` if you want to verify your contract on [Etherscan](https://etherscan.io/).
#### 2. Get Testnet ETH
Head over to [faucets.chain.link](https://faucets.chain.link/) to get some testnet ETH. The ETH should show up in your MetaMask wallet shortly.
#### 3. Deploy to Sepolia Testnet
To deploy your contract to the **Sepolia** testnet, run:
```
$ make deploy ARGS="--network sepolia"
```
### ๐งช Testing
You can run tests in various environments:
1. **Unit Tests**
2. **Integration Tests**
3. **Forked Network Tests**
4. **Staging Tests**
To run all tests, use:
```
$ forge test
```
or
```
$ forge test --fork-url $SEPOLIA_RPC_URL
```
### Test Coverage
```
$ forge coverage
```
### โฝ Estimate Gas
You can estimate how much gas transactions will cost by running:
```
$ forge snapshot
```
And you'll see an output file called `.gas-snapshot`
### ๐ Formatting
To run code formatting, use the following command:
```
$ forge fmt
```
## ๐ Front-End
### โก Quickstart
```
$ cd front-end
# Create .env file in the front-end
NEXT_PUBLIC_PROJECT_ID=paste_your_walletconnect_project_id_here
# Install the dependencies
$ npm i
# Start the client
$ npm run dev
```