
Bulldex Finance
The Problem
Most Web3 tutorials stop at smart contracts. Deploy a token, call a function, done. There was no clean open-source reference showing the full DeFi stack from Solidity to UI to wallet UX in a single coherent codebase. Builders who wanted to understand how a real DeFi product works had nowhere to start. Bulldex is that reference.
How It Works
- A set of Solidity smart contracts handles the core logic: token swap using a constant-product AMM formula, a faucet contract for Sepolia testnet token distribution, and an LP pool contract that tracks reserves and issues LP tokens.
- The Next.js frontend reads on-chain state via ethers.js v6 using read-only provider calls for data and signer-based calls for transactions.
- Wallet connection is handled by MetaMask and WalletConnect adapters. The UI shows price impact, slippage tolerance input, and expected output before any transaction is sent.
- Optimistic UI updates show expected outcomes immediately. The actual on-chain confirmation is reconciled in the background without blocking the interface.
- The LP dashboard polls reserve data at an interval and calculates impermanent loss in real time from current versus entry reserves.
Tech Stack
| Next.js | App Router with RSC and static export, consistent across the portfolio stack |
| Solidity | OpenZeppelin standards reduce attack surface for a reference codebase |
| ethers.js v6 | Cleaner TypeScript API than v5, aligns with current industry practice |
| OpenZeppelin | Audited contract library prevents common token and AMM vulnerabilities |
| Sepolia testnet | Primary Ethereum testnet with reliable public faucets for development |
What I Would Improve
The price oracle is naive. A real AMM uses TWAPs to prevent flash loan manipulation. Adding a TWAP oracle would make this a more accurate reference for production patterns. The frontend polling is also inefficient. Replacing it with WebSocket event listeners from ethers.js would reduce RPC calls and improve responsiveness on slow connections. Finally, the test suite only covers the happy path. Property-based tests for the AMM invariant (k = x * y) would catch edge cases that deterministic unit tests miss.
Screenshots
