Skip to content

DHRUVCHARNE/mdsc-stablecoin-vyper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸͺ™ Decentralized Stable Coin (MDSC) β€” USD Pegged Stablecoin

A decentralized stablecoin protocol pegged to USD, inspired by Maker-like mechanics and built with Vyper + Moccasin + Boa.

βœ… Overcollateralized
βœ… Multi-collateral (WETH + WBTC)
βœ… Chainlink-style price feeds
βœ… Liquidation mechanism with bonus
βœ… Unit tests + fuzz/invariant testing (80%+ coverage)
βœ… Deployed on zkSync Sepolia


✨ Features

πŸͺ™ Stablecoin Token (MDSC)

  • ERC20 compliant
  • Minting controlled via minters
  • Ownership controlled via ownable
  • Built using Snekmate ERC20

Contract: Decentralized Stable Coin (MDSC)
Symbol: MDSC
Decimals: 18


βš™οΈ Engine Contract (DSCEngine)

The protocol logic lives here.

Supports:

  • 🏦 Deposit collateral (WETH/WBTC)
  • πŸ’΅ Mint DSC against collateral
  • πŸ”₯ Burn DSC to reduce debt
  • πŸ’³ Redeem collateral
  • 🧨 Liquidations for unhealthy positions

🧠 Protocol Rules / Risk Parameters

Parameter Value
Liquidation Threshold 50%
Liquidation Bonus 10%
Min Health Factor 1.0
Precision 1e18
Feed Precision 1e8
Additional Feed Precision 1e10

βœ… Users must remain safely overcollateralized.
⚠️ If health factor < 1e18, position can be liquidated.


πŸ—οΈ Architecture

User
 β”‚
 β”‚ deposit_collateral()
 β–Ό
DSCEngine  ─────────────► Price Feeds (ETH/USD, BTC/USD)
 β”‚
 β”‚ mint_dsc()
 β–Ό
DecentralizedStableCoin (MDSC)

πŸ“¦ Contracts

1) decentralized_stable_coin.vy

  • ERC20 token based on Snekmate

  • Supports:

    • mint(address,uint256)
    • burn_from(address,uint256)
    • set_minter(address,bool)
    • ownership transfer

2) dsc_engine.vy

Core protocol engine:

  • Deposit collateral

  • Mint/burn DSC

  • Health factor checks

  • Liquidations

  • Oracle price conversions:

    • get_usd_value(token, amount)
    • get_token_amount_from_usd(token, usd_amount_in_wei)

3) oracle_lib.vy

Oracle safety layer βœ…

Prevents stale price usage:

  • enforces timeout (3 hours)
  • reverts when feed stale
  • renders protocol unusable when oracles stale (by design)

πŸ§ͺ Testing

This project includes:

βœ… Unit Tests

  • Token mint/burn logic
  • Collateral deposit/redemption
  • Health factor invariants
  • Liquidation functionality

🧬 Fuzz + Invariant Tests

  • Stateful fuzzing using Hypothesis

  • Randomized sequences:

    • deposits
    • mint
    • redeem
    • price updates
  • Invariant examples:

    • protocol collateral value β‰₯ total DSC supply

πŸ“Š Coverage

βœ… 80%+ test coverage (unit + fuzz/invariant)

Run tests:

mox test

Run tests with prints:

mox test -s

Run coverage:

mox test --coverage

Run only fuzz tests:

mox test -s -k fuzz

πŸ› οΈ Build

Compile all contracts:

mox build

Artifacts generated in:

out/

Example:

  • out/decentralized_stable_coin.json
  • out/dsc_engine.json
  • out/oracle_lib.json

πŸš€ Deploy (zkSync Sepolia)

Network:

  • zkSync Sepolia
  • Chain ID: 300
  • RPC: https://sepolia.era.zksync.dev
  • Explorer: https://explorer.sepolia.era.zksync.dev

Deploy Command

mox run script/deploy.py --network zksync-sepolia

βœ… Deployed Addresses (zkSync Sepolia)

πŸͺ™ MDSC Token

  • DecentralizedStableCoin (MDSC) 0x1c17Dbb3Cd79d37fBbE0a9d2F462b09717d77D3b

βš™οΈ DSCEngine

  • DSCEngine 0x7FaE3141341Ca5985D5412102C3C66965866BC52

🏦 Collateral Tokens

  • WBTC 0xE544cAd11e108775399358Bd0790bb72c9e3AD9E

  • WETH 0xdd13E55209Fd76AfE204dBda4007C227904f0a81

πŸ“ˆ Price Feeds

  • BTC/USD Price Feed 0x95Bc57e794aeb02E4a16eff406147f3ce2531F83

  • ETH/USD Price Feed 0xfEefF7c3fB57d18C5C6Cdd71e45D2D0b4F9377bF


πŸ” Post-Deployment Setup (zkSync workaround)

Boa/Moccasin zkSync env currently cannot perform some contract calls due to simulate incompatibility, so minter/ownership setup is done using cast.

βœ… Set DSCEngine as minter

cast send 0x1c17Dbb3Cd79d37fBbE0a9d2F462b09717d77D3b \
  "set_minter(address,bool)" 0x7FaE3141341Ca5985D5412102C3C66965866BC52 true \
  --rpc-url https://sepolia.era.zksync.dev \
  --private-key $PRIVATE_KEY

βœ… Transfer ownership to DSCEngine

cast send 0x1c17Dbb3Cd79d37fBbE0a9d2F462b09717d77D3b \
  "transfer_ownership(address)" 0x7FaE3141341Ca5985D5412102C3C66965866BC52 \
  --rpc-url https://sepolia.era.zksync.dev \
  --private-key $PRIVATE_KEY

🧾 Project Commands Cheat Sheet

Action Command
Build mox build
Test mox test
Coverage mox test --coverage
Deploy zkSync Sepolia mox run script/deploy.py --network zksync-sepolia
Deploy local anvil mox run script/deploy.py --network anvil

πŸ§‘β€πŸ’» Author

Made with ❀️ by Dhruv4ne


πŸ“œ License

MIT

About

πŸͺ™ MDSC: USD-pegged decentralized stablecoin built in Vyper (DSCEngine + Chainlink-style oracles) with 80%+ unit + fuzz/invariant test coverage. Deployed on zkSync Sepolia.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors