SimpleSwap is a DEX implemented in Solidity that enables:
- ✅ Adding liquidity between two ERC20 tokens
- 🔁 Swapping tokens with exact input amounts
- 💧 Removing proportional liquidity
- 📊 Querying current prices and swap estimates
All interactions are protected with input validation and deadline
constraints to ensure safe and fair operations.
The web application is deployed on Vercel and interacts with the contracts on Sepolia.
🔗 Live Demo: https://simple-swap-amm-nextjs.vercel.app/
- 🔁
SimpleSwap
: Manages liquidity pools and token swaps - 💧 ERC20 Tokens: Dynamically generated via
TokenFactory
- 🧱 LP Tokens: The
SimpleSwap
contract also acts as a liquidity token (inherits fromERC20
)
BOOKE (Bokita Coin)
:0x3b6BEcE5Ec2Ac59c073B085D32D0962E2911bae8
MIAMI (General Coin)
:0xf622c8a6634BC87C9cE4eC40C4Cf6Fccf257c9A1
SimpleSwap
:0xb4E6d982Bb76c02a510B2144e810470bd08616Bb
addLiquidity(...)
removeLiquidity(...)
swapExactTokensForTokens(...)
getPrice(...)
getAmountOut(...)
min(uint a, uint b)
sqrt(uint y)
The smart contracts reach ~65% coverage across statements, branches, functions, and lines. Tests use Hardhat and Chai. Run them with:
cd packages/hardhat
npx hardhat coverage
Contracts are automatically deployed to the Sepolia testnet and verified on Etherscan (if a valid API key is provided).
To deploy:
cd packages/hardhat
yarn deploy
The user calls addLiquidity()
with the selected ERC20 tokens. The contract calculates the optimal ratio and mints LP tokens to the provider.
The user calls swapExactTokensForTokens()
to exchange a fixed amount of one token for another, based on current reserves.
The user burns LP tokens via removeLiquidity()
and receives a proportional share of both tokens.
- ✅ Deadline validations
- ✅ Reserve and amount checks
- ✅ Explicit reverts for failed transfers
The ISimpleSwap
interface standardizes all core functions, ensuring compatibility with external tools and explorer verification.
// Add liquidity
simpleSwap.addLiquidity(
tokenA,
tokenB,
1000,
1000,
900,
900,
msg.sender,
block.timestamp + 120
);
// Swap tokens
simpleSwap.swapExactTokensForTokens(
1000,
900,
[tokenA, tokenB],
msg.sender,
block.timestamp + 120
);
simple-swap/
├── packages/
│ ├── hardhat/ # Contracts and deployment scripts
│ └── nextjs/ # Next.js frontend
├── deployments/ # Contracts generated at deploy time (copied to frontend)
MIT © 2025