πŸ“„ Smart Contracts

Three contracts form the backend of the DEX Dashboard: MockERC20 (token), Faucet (distribution), and MockDEX (trading). All contracts inherit from OpenZeppelin for battle-tested security.

1. MockERC20 β€” Mock Tokens

OpenZeppelin-based ERC20 token with mint capability restricted to a designated faucet address. Deployed as three independent instances.

Deployed Instances

Token Symbol Contract Decimal
Mock Ethereum mETH MockERC20("Mock ETH", "mETH", faucetAddress) 18
Mock Bitcoin mBTC MockERC20("Mock BTC", "mBTC", faucetAddress) 18
Mock USDC mUSDC MockERC20("Mock USDC", "mUSDC", faucetAddress) 18

Key Functions

Errors

2. Faucet β€” Token Distribution

Time-locked faucet distributing 10 tokens per claim with an independent 24-hour cooldown per wallet per token. Supports all three mock tokens (mETH, mBTC, mUSDC).

State Variables

mapping(address => mapping(uint256 => uint256)) lastClaim;
// user => tokenIndex => unix timestamp

mapping(address => mapping(uint256 => uint256)) lifetimeClaimed;
// user => tokenIndex => total tokens claimed

uint256 claimAmount;    // Default: 10 * 10**18
uint256 cooldown;       // Default: 24 hours (86400s)
MockERC20[] tokens;     // [mETH, mBTC, mUSDC]

Key Functions

Errors

3. MockDEX β€” Swap Engine

A fixed-ratio DEX supporting 6 swap paths across 3 tokens. Uses a simplified reserve-based model (not a constant product AMM like Uniswap).

State Variables

IERC20 public immutable mETH;     // mETH token contract
IERC20 public immutable mBTC;     // mBTC token contract
IERC20 public immutable mUSDC;    // mUSDC token contract

uint256 public ethReserve;        // Current mETH reserve
uint256 public btcReserve;        // Current mBTC reserve
uint256 public usdcReserve;       // Current mUSDC reserve

uint256 public ethSwapRate;       // mUSDC per 1 mETH (scaled 1e18)
uint256 public btcSwapRate;       // mUSDC per 1 mBTC (scaled 1e18)

Swap Paths (6 total)

Direction Function Calculation Reserve Check
mETH β†’ mUSDC swapETHForUSDC() usdcOut = ethIn Γ— ethRate / 1e18 usdcReserve
mUSDC β†’ mETH swapUSDCForETH() ethOut = usdcIn Γ— 1e18 / ethRate ethReserve
mBTC β†’ mUSDC swapBTCForUSDC() usdcOut = btcIn Γ— btcRate / 1e18 usdcReserve
mUSDC β†’ mBTC swapUSDCForBTC() btcOut = usdcIn Γ— 1e18 / btcRate btcReserve
mETH β†’ mBTC swapETHForBTC() usdcValue = ethIn Γ— ethRate / 1e18
btcOut = usdcValue Γ— 1e18 / btcRate
btcReserve
mBTC β†’ mETH swapBTCForETH() usdcValue = btcIn Γ— btcRate / 1e18
ethOut = usdcValue Γ— 1e18 / ethRate
ethReserve

Cross-rate swaps (mETH ↔ mBTC) route through mUSDC internally. For example, swapping mETH β†’ mBTC first converts ETH to USDC value via ethSwapRate, then converts that USDC value to BTC via btcSwapRate.

Key Functions

Security

Errors

Events

See the Testing Guide for details on the test suite covering all contracts.