Frequently Asked Questions

Everything you need to know about using the DEX Dashboard — from claiming tokens to understanding the smart contracts.

ℹ️ About (6)

+ What is the DEX Dashboard?

The DEX Dashboard is a full-stack educational Web3 platform that simulates a decentralized exchange experience. It lets you mint mock tokens, trade them on a simulated DEX, and track live market analytics — all without risking real funds.

It's built for developers, students, and crypto enthusiasts who want to understand how DeFi protocols work by interacting with one directly.

ℹ️

No real cryptocurrency or fiat money is involved. All tokens are mock ERC20 tokens deployed on test networks or a local Anvil node.

+ What blockchain networks does it support?

The DEX Dashboard works with two networks:

  • Anvil (Local) — A local Ethereum node provided by the Foundry toolchain. This is the default for development and testing. It runs on http://127.0.0.1:8545 and gives you instant transactions with no gas costs.
  • Sepolia (Testnet) — A public Ethereum testnet. You'll need test ETH from a Sepolia faucet to deploy contracts. The frontend automatically detects which network your wallet is connected to and shows the relevant contract addresses.

💡 Tip: Start with Anvil for local development, then deploy to Sepolia for public testing.

⚠️

Before deploying to Sepolia, make sure you have test ETH. You can get it from the Sepolia Faucet (sepoliafaucet.com).

+ Who is this project for?

This dashboard is designed for:

  • 👨‍💻 Developers — Learn Solidity smart contract development, Foundry testing, and full-stack Web3 integration with Next.js and wagmi.
  • 🎓 Students — Understand DeFi mechanics like token swaps, liquidity pools, and market analytics in a safe sandbox environment.
  • 🧪 Crypto Enthusiasts — Explore how DEXes work under the hood without risking real assets.
  • 🏫 Educators — Use this as a teaching tool for blockchain development courses and workshops.
+ What technology stack is used?

The project is divided into two main parts:

  • Smart Contracts (Backend): Solidity ^0.8.27 + Foundry + OpenZeppelin
  • Frontend: Next.js 16 (App Router) + TypeScript (strict) + shadcn/ui + Tailwind CSS v4 + wagmi + viem
  • Charts & Data: Recharts for candlestick charts, CoinGecko API for market data
  • Testing: Foundry (forge) — 182+ Solidity tests including fuzz and invariant tests; Vitest + Testing Library — frontend component tests
+ How do I get started?

Follow these steps:

  1. Clone the repository: git clone https://github.com/Men6d656e/DEX.git
  2. Install dependencies: make install
  3. Build contracts: make build-contracts
  4. Start Anvil: make anvil (Terminal 1)
  5. Deploy contracts: make deploy-anvil (Terminal 2)
  6. Start the frontend: make dev
  7. Open http://localhost:3000 and connect your wallet

💡 New to Foundry? The make commands automate everything. Just run make dev and the frontend will start with hot reload enabled.

Make sure you have Node.js >= 18, Foundry, and Git installed before starting.

+ What does the project structure look like?

The repository is organized into these main directories:

  • contracts/ — Foundry smart contracts (MockERC20, Faucet, MockDEX) with tests and deployment scripts.
  • frontend/ — Next.js 16 application with pages, components, hooks, and utilities.
  • docs/ — GitHub Pages documentation (this documentation hub).
  • scripts/ — Utility scripts like update-addresses.sh for auto-capturing deployed contract addresses.

The root Makefile provides automation for install, build, test, deploy, and dev commands.

💰 Faucet (6)

+ What is the Faucet?

The Faucet is a smart contract that distributes mock tokens to users for testing and learning purposes. It's like a water faucet for tokens — turn it on and get free tokens to play with.

Each user can claim a fixed amount of tokens once per cooldown period (24 hours), tracked independently for each token type. The faucet ensures fair distribution while preventing abuse.

ℹ️

The Faucet contract uses a checks-effects-interactions pattern for security. Your claim is recorded on-chain before tokens are minted.

+ How many tokens does the Faucet support?

The Faucet supports 3 mock tokens:

  • Token Index 0 → mETH (Mock Ethereum): MockERC20("Mock ETH", "mETH", faucetAddress)
  • Token Index 1 → mBTC (Mock Bitcoin): MockERC20("Mock BTC", "mBTC", faucetAddress)
  • Token Index 2 → mUSDC (Mock USD Coin): MockERC20("Mock USDC", "mUSDC", faucetAddress)

Each token is a full ERC20 implementation from OpenZeppelin with faucet-restricted minting. The faucet is the only address that can mint new tokens.

+ How do I import tokens into my wallet?

When you select a token in the Faucet page, its contract address is displayed in the section below the claim button. To import a token into MetaMask (or any wallet):

  1. Copy the contract address shown on the Faucet page.
  2. In MetaMask, click "Import tokens" (scroll to the bottom of your assets list).
  3. Paste the contract address. MetaMask will auto-detect the symbol and decimals (18).
  4. Click "Add Custom Token" then "Import Tokens".

✅ After importing, you'll see your balance update in real-time as you claim more tokens.

Token addresses are unique per deployment. Always use the address shown on the Faucet page — they change when contracts are redeployed.

+ How does the cooldown system work?

Each token has an independent 24-hour cooldown per wallet address. Here's the breakdown:

  • Per token, per wallet — Claiming mETH doesn't reset your mBTC cooldown. You can claim all 3 tokens on the same day, just not the same token twice.
  • Countdown timer — The UI shows an exact HH:MM:SS countdown until your next claim is available.
  • Progress indicator — A circular progress bar shows how much of the cooldown has elapsed.
  • State badges — The claim button shows "Claim Ready" (green) when available, or a disabled state with remaining time when on cooldown.
  • On-chain tracking — The lastClaim mapping and cooldown variable are stored in the Faucet contract. Even if you reload the page, the state persists.
⚠️

The cooldown is based on block timestamps, not your local clock. If there's a discrepancy, trust the on-chain countdown displayed in the UI.

+ How many tokens can I claim per day?

You can claim 10 tokens (with 18 decimal places, so 10 × 10¹⁸ wei) per token per 24-hour period.

Example:

  • Day 1: Claim 10 mETH, claim 10 mBTC, claim 10 mUSDC = 30 tokens total
  • Day 2: Claim 10 mETH again (cooldown for mETH has reset)

The claim amount and cooldown duration can be adjusted by the contract owner (the deployer) using the setClaimAmount() and setCooldown() admin functions.

+ How do I track my claim history?

The Faucet page shows detailed analytics for each token:

  • Lifetime Claimed — Total tokens you've claimed for this token over your entire history.
  • Last Claim — Timestamp of your most recent successful claim.
  • Cooldown Remaining — Time until your next claim becomes available.
  • Claim Count — Total number of claims you've made.

All this data comes from the Faucet contract's on-chain state (lastClaim and lifetimeClaimed mappings). It persists across sessions and browser restarts.

ℹ️

Lifetime claimed data is stored on-chain per wallet address. If you switch wallets, the history for the new wallet starts from zero.

🔄 Swap (7)

+ What swap pairs are available?

The DEX supports 6 swap paths across 3 token pairs:

  • Direct Pairs (via fixed ratio): mETH ↔ mUSDC, mBTC ↔ mUSDC
  • Cross-Rate Pairs (derived through mUSDC): mETH ↔ mBTC

The cross-rate is calculated by routing through mUSDC internally: ethAmount → USDC value (via ethSwapRate) → BTC output (via btcSwapRate)

ℹ️

The Swap interface shows all available pairs in a dropdown. Select your input and output tokens, and the rate will be calculated automatically.

+ How does the pricing work?

The DEX uses a fixed-ratio pricing model — not an AMM (Automated Market Maker) like Uniswap.

  • The contract owner sets ethSwapRate and btcSwapRate on deployment.
  • Simple ratio math: output = input × rate. Cross-rate swaps calculate through the USDC value.
  • Reserve limits: Each swap checks that the DEX has enough reserves to fulfill the order.
⚠️

This is NOT a real-time AMM. Prices don't change based on trade size or pool ratio — they're fixed by the contract owner. This is intentional for educational simplicity.

+ Is there a swap fee? Who takes it?

There is no swap fee in this educational DEX. The full swap amount goes to the user without any deduction.

Since there are no fees, the full input amount is converted to output at the configured rate. What you see is what you get.

+ Who provides liquidity to the pools?

The DEX contract owner is the sole liquidity provider. They call the addLiquidity() function to deposit mETH, mBTC, and mUSDC tokens into the DEX.

The current liquidity is visible on the Swap page in the Reserves panel.

ℹ️

In production DEXes like Uniswap, anyone can be a liquidity provider by depositing equal values of two tokens into a pool. Here, it's simplified to owner-only for educational clarity.

+ What is slippage protection and how do I use it?

Slippage is the difference between the expected price of a trade and the price at which it's actually executed. Even though this DEX uses fixed rates, slippage protection is implemented as a safety mechanism (minOutput). If the calculated output is less than your minOutput, the transaction reverts.

You can set the slippage tolerance in the Swap page via the ⚙️ Settings button (gear icon). Default is 0.5%.

⚠️

Setting slippage too low (e.g., 0.1%) may cause transactions to fail if reserves change slightly. Setting it too high (e.g., 10%) defeats the purpose. 0.5% is a good starting point.

+ How do I approve tokens for swapping?

Before you can swap, the DEX contract needs permission to spend your tokens via the ERC20 approve() function.

  1. Select your input token and enter an amount.
  2. Click "Approve" and confirm the MetaMask transaction.
  3. Once approved, the button changes to "Swap".

Approval is per-token and persists across swaps.

ℹ️

The approval sets type(uint256).max (infinite approval) so you don't need to re-approve for subsequent swaps. You can revoke this at any time by approving 0.

+ How does the liquidity pool work in this DEX?

This DEX uses a simplified reserve-based model, not a constant product AMM. Reserves track exactly how many tokens the DEX holds (ethReserve, btcReserve, usdcReserve).

It does NOT use the x × y = k formula, have automated price discovery, or LP tokens.

The reserve invariants are tested in Foundry with randomized sequences (256 runs × 15 depth) — reserves always match the DEX balance exactly.

📊 Analytics (7)

+ What data is shown on the Analytics page?

The Analytics page shows:

  • 📈 Market Stats Cards: 24h Volume, Total Trades, Active Users, TVL.
  • 📊 Candlestick Charts: Interactive charts for ETH, BTC, and an overview.
  • 📋 Token Statistics: Price, 24h change, market cap, and volume for each token.
  • 🔄 Trade History: Recent swap transactions.
  • 👛 Portfolio Overview: Connected wallet balance and allocation.
+ Where does the market data come from?

Market data is powered by the CoinGecko API (Free Tier). The frontend fetches candlestick data, prices, and market metrics.

⚠️

CoinGecko's free tier has rate limits. If you see stale data, you may have exceeded the request limit. Consider adding a delay or using the API key for higher limits.

+ How do I read the candlestick charts?

Each candle shows 4 data points for a period: Open, Close, High, and Low. Green means the price increased (Close > Open), Red means it decreased (Close < Open). The wicks show the high/low range, and the body shows open/close.

ℹ️

Hover over any candle to see the exact Open, High, Low, Close values for that period. Use the timeframe selector (1D, 1W, 1M, 1Y) to zoom in and out.

+ What are the key metrics and how should I interpret them?
  • 24h Volume: Total value of swaps; higher means more activity.
  • Total Trades: Count of successful swaps.
  • Active Users: Wallets that performed a swap or claim in the last 24h.
  • TVL: Total USD value locked in the DEX.

All include trend indicators (↑ or ↓) vs. yesterday.

+ How does the portfolio tracking work?

It displays your token balances (mETH, mBTC, mUSDC), USD values, and an allocation pie chart. It uses balanceOf() calls to fetch data directly from the blockchain via wagmi/viem.

ℹ️

The portfolio only shows tokens held by your connected wallet. If you switch wallets or disconnect, the data resets for the new address.

+ What is shown in the Trade History table?

It displays a chronological list of transactions, including Time, Swap Type, Amount In, Amount Out, and the User address.

You can click any trade to see more details. The table automatically updates when new swaps occur on the connected network.

+ What token statistics are available?

Price, 24h Change, Market Cap, 24h Volume, and Circulating Supply.

ℹ️

For mock tokens (mETH, mBTC, mUSDC), the supply shown is the total minted by the Faucet. Real market data (price, volume) comes from CoinGecko.

🔧 Developer (2)

+ How are the smart contracts structured?

They use a modular architecture:

  • MockERC20: Standard ERC20 with minting restricted to a faucet address.
  • Faucet: Manages time-locked distributions and claim history.
  • MockDEX: Manages 3 reserves, 2 swap rates, and 6 swap paths using SafeERC20.

Uses custom errors and the checks-effects-interactions pattern for security.

+ How is the project tested?

182+ Solidity tests across all contracts:

  • MockERC20: 35 tests
  • Faucet: 51 tests
  • MockDEX: 96 tests (including 14 fuzz tests and 4 invariant tests to ensure reserves match balances)
  • Frontend: Vitest + Testing Library

Run make test-contracts or forge test -vvv to run all 182+ Solidity tests. Fuzz runs + invariant tests take ~30 seconds.

🔍 No matching questions found.

Try a different search term or clear the filter.