A decentralized, overcollateralized algorithmic stablecoin protocol built in Vyper 0.4.1 using the Moccasin framework.
Inspired by MakerDAO/DAI. Extended and hardened with additional security features with a security-first design and comprehensive test coverage beyond the original course material from Cyfrin Updraft.
Users deposit crypto collateral (WETH or WBTC) to mint DSC, a USD-pegged stablecoin. It is backed exclusively by exogenous crypto collateral (WETH and WBTC), and governed by on-chain rules — no admin can print DSC out of thin air. The protocol enforces a minimum 200% collateralization ratio. Undercollateralized positions can be liquidated by anyone.
- Collateral: Exogenous (WETH, WBTC)
- Stability Mechanism: Algorithmic / Decentralized
- Peg: USD (via Chainlink price feeds)
- Deposit WETH or WBTC as collateral
- Mint DSC up to 50% of your collateral value (200% collateralization ratio)
- If your health factor drops below 1.0, your position becomes liquidatable
- Liquidators repay your debt and receive your collateral plus a bonus
| Contract | Description |
|---|---|
decentralized_stable_coin.vy |
ERC20 DSC token using Snekmate libraries |
dsc_engine.vy |
Core protocol engine: deposits, minting, liquidations, security |
- Emergency Pause — Owner can halt all state-changing operations instantly
- Chainlink Staleness Check — Rejects price data older than 1 hour
- Invalid Price Check — Rejects zero or negative price feed responses
- Two-Step Ownership Transfer — Prevents accidental loss of contract ownership; new owner must explicitly accept
- Health Factor Enforcement — Every mint and redemption checks collateralization ratio
- Dynamic Liquidation Bonus — Bonus scales with risk:
- Health Factor ≥ 0.8 → 10% bonus
- Health Factor ≥ 0.5 → 15% bonus
- Health Factor < 0.5 → 20% bonus
- Deposit & Mint in one transaction — Gas efficient combined operation
- Redeem & Burn in one transaction — Full exit in a single call
- Minting Fee — Small protocol fee on DSC minting
| Tool | Purpose |
|---|---|
| Vyper 0.4.1 | Smart contract language |
| Moccasin (mox) | Vyper framework (deployment, testing) |
| Titanoboa | EVM interpreter for Python-native testing |
| Chainlink | On-chain price feeds (ETH/USD, BTC/USD) |
| Snekmate | Audited Vyper libraries (ERC20, Ownable) |
| Hypothesis | Property-based fuzz testing |
- Unit tests — Full coverage of all contract functions and edge cases
- Fuzz tests — Stateful property-based testing with Hypothesis
- Coverage — 98% on
dsc_engine.vy
Key fuzz invariant tested:
The total USD value of collateral held by the protocol must always be ≥ the total DSC supply.
git clone https://github.com/pattool/Stablecoin-DSC
cd mox-stablecoin-cu
mox installIf you run into environment issues, use uv:
# macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv
uv sync
source .venv/bin/activate# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Full
uvdocs: docs.astral.sh/uv
# Deploy to a local in-memory network (no setup needed)
mox run deploy
# Compile
mox compile
# Run tests
mox test
# Run tests with print output
mox test -s
# Run a specific test
mox test -k test_name -sThis project is licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT license (LICENSE-MIT)
at your option.