ZenithDEX is a gas-optimized, modernized decentralized exchange (DEX) protocol based on the AMM (Automated Market Maker) model (
Built for the post-2025 Web3 ecosystem, it leverages Solidity 0.8.20+, Foundry for rigorous fuzz testing, and custom gas-optimized mathematics libraries.
The protocol is designed with a separation of concerns pattern:
- Core Layer (
src/core): * Factory: Deploys pairs usingCREATE2for deterministic addresses.- Pair: Handles low-level liquidity minting/burning and swapping with checks-effects-interactions pattern protection.
- Security: Implements "Minimum Liquidity Locking" (1000 wei) to prevent inflation attacks.
- Periphery Layer (
src/periphery):- Router: Abstraction layer for user interactions (Add Liquidity / Swap).
- Library: Pure gas-optimized math for path pricing and reserve calculation.
- Modern Solidity Stack: Unlike older DEXs (Solidity 0.5.x), ZenithDEX utilizes Solidity 0.8.x's built-in overflow checks, removing the need for
SafeMathand reducing gas costs. - Architectural Decoupling: Strict separation between core logic and user-facing routing logic.
- Flash Loan Compatible: The
swapfunction supports optimistic transfers, enabling flash swaps. - Create2 Deterministic Deployment: Allows for off-chain pair address pre-computation.
- Language: Solidity (
^0.8.20) - Framework: Foundry (Forge, Cast, Anvil)
- Testing: * Unit Tests (Logic verification)
- Integration Tests (Mint -> Swap -> Burn flows)
- Libraries: Solmate (Gas-optimized ERC20), OpenZeppelin.
1. Clone the repository
git clone [https://github.com/yiguangchao/ZenithDEX.git](https://github.com/yiguangchao/ZenithDEX.git)
cd ZenithDEX2. Install dependencies
forge install3. Run Tests
forge test -vv4. Deploy (Simulation)
forge script script/DeployZenithDEX.s.sol:DeployZenithDEXThe exchange relies on the constant product formula:
GuangchaoYi Senior Blockchain Engineer & Java Veteran [LinkedIn Link]