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.


- 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.
Before you start, ensure that you have the following installed:
Clone the repository and set up your environment:
$ git clone https://github.com/jitendragangwar123/Peer2Play-Swap
$ cd Peer2Play-Swap
$ make install
$ forge build
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.
Head over to faucets.chain.link to get some testnet ETH. The ETH should show up in your MetaMask wallet shortly.
To deploy your contract to the Sepolia testnet, run:
$ make deploy ARGS="--network sepolia"
You can run tests in various environments:
- Unit Tests
- Integration Tests
- Forked Network Tests
- Staging Tests
To run all tests, use:
$ forge test
or
$ forge test --fork-url $SEPOLIA_RPC_URL
$ forge coverage
You can estimate how much gas transactions will cost by running:
$ forge snapshot
And you'll see an output file called .gas-snapshot
To run code formatting, use the following command:
$ forge fmt
$ 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