|
1 | | -## Foundry |
2 | | - |
3 | | -**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** |
4 | | - |
5 | | -Foundry consists of: |
6 | | - |
7 | | -- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools). |
8 | | -- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data. |
9 | | -- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network. |
10 | | -- **Chisel**: Fast, utilitarian, and verbose solidity REPL. |
11 | | - |
12 | | -## Documentation |
13 | | - |
14 | | -https://book.getfoundry.sh/ |
15 | | - |
16 | | -## Usage |
17 | | - |
18 | | -### Build |
19 | | - |
20 | | -```shell |
21 | | -$ forge build |
22 | | -``` |
23 | | - |
24 | | -### Test |
25 | | - |
26 | | -```shell |
27 | | -$ forge test |
| 1 | +# 🦋 FlyDex |
| 2 | + |
| 3 | +FlyDex is a decentralized token exchange built with Solidity and Foundry. It allows users to **swap tokens**, **add/remove liquidity**, and **collect protocol fees**, integrating directly with **Uniswap V2 on Arbitrum**. It includes production-ready patterns like reentrancy protection, fee tracking, slippage, clean architecture, and comprehensive test coverage. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## ✨ Features |
| 8 | + |
| 9 | +- 🔁 Swap ERC20 tokens |
| 10 | +- 🔁 Swap ETH for ERC20 tokens |
| 11 | +- ➕ Add liquidity to ERC20-ERC20 pools |
| 12 | +- ➕ Add liquidity to ETH-ERC20 pools |
| 13 | +- ➖ Remove liquidity from ERC20-ERC20 pools |
| 14 | +- ➖ Remove liquidity from ETH-ERC20 pools |
| 15 | +- 💰 Customizable fee mechanism (set by owner) |
| 16 | +- 🔓 Only owner can withdraw accumulated fees |
| 17 | +- 🛡️ Reentrancy protection on sensitive functions |
| 18 | +- 📢 Event emission for all features |
| 19 | +- 🧪 Complete unit tests and fuzzing with Foundry |
| 20 | +- 🔄 Forked mainnet testing (Arbitrum One) |
| 21 | + |
| 22 | +## 🔐 Security Measures |
| 23 | + |
| 24 | +- Reentrancy protection using OpenZeppelin's `ReentrancyGuard` on sensitive functions like `withdrawFees`. |
| 25 | +- Use of `SafeERC20` for all token transfers to handle non-standard ERC20 tokens. |
| 26 | +- Owner-only functions protected with `Ownable`. |
| 27 | +- Event logging for transparency and easier off-chain tracking. |
| 28 | +- Fes tracked per-token to avoid mixing funds. |
| 29 | +- Fee percentage capped at 5% to prevent excessive charges. |
| 30 | +- ETH tracked separately via `address(0)` in fee mappings. |
| 31 | + |
| 32 | +## 🧪 Tests |
| 33 | + |
| 34 | +All core functionalities are tested using Foundry: |
| 35 | + |
| 36 | +- ✅ `swapTokens()` |
| 37 | +- ✅ `swapETHForTokens()` |
| 38 | +- ✅ `addLiquidityTokens()` |
| 39 | +- ✅ `addLiquidityETH()` |
| 40 | +- ✅ `removeLiquidity()` |
| 41 | +- ✅ `removeLiquidityETH()` |
| 42 | +- ✅ `changeFee()` |
| 43 | +- ✅ `withdrawFees()` |
| 44 | +- ✅ Fuzzing tests for swap paths and amounts |
| 45 | +- ✅ Invariant test for fee consistency |
| 46 | +- ✅ Revert tests for negative scenarios |
| 47 | + |
| 48 | +Run tests with: |
| 49 | + |
| 50 | +```bash |
| 51 | +forge test --fork-url https://arb1.arbitrum.io/rpc --match-test test_swapTokens |
28 | 52 | ``` |
29 | 53 |
|
30 | | -### Format |
| 54 | +## 🧠 Technologies Used |
31 | 55 |
|
32 | | -```shell |
33 | | -$ forge fmt |
34 | | -``` |
| 56 | +- **Solidity** (`^0.8.24`) |
| 57 | +- **Foundry** – Smart contract development & testing framework |
| 58 | +- **Uniswap V2** – Token swap & liquidity router |
| 59 | +- **OpenZeppelin Contracts** – `Ownable`, `ReentrancyGuard`, `SafeERC20` |
| 60 | +- **Arbitrum One** – Mainnet fork for realistic tests |
35 | 61 |
|
36 | | -### Gas Snapshots |
| 62 | +## 📜 License |
37 | 63 |
|
38 | | -```shell |
39 | | -$ forge snapshot |
40 | | -``` |
41 | | - |
42 | | -### Anvil |
43 | | - |
44 | | -```shell |
45 | | -$ anvil |
46 | | -``` |
47 | | - |
48 | | -### Deploy |
49 | | - |
50 | | -```shell |
51 | | -$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> |
52 | | -``` |
53 | | - |
54 | | -### Cast |
55 | | - |
56 | | -```shell |
57 | | -$ cast <subcommand> |
58 | | -``` |
59 | | - |
60 | | -### Help |
61 | | - |
62 | | -```shell |
63 | | -$ forge --help |
64 | | -$ anvil --help |
65 | | -$ cast --help |
66 | | -``` |
| 64 | +This project is licensed under the MIT License. |
0 commit comments