Skip to content

Repository files navigation

DeFiDollar — Decentralized Stablecoin Engine (DSCEngine)

Exogenous • Over-Collateralized • Dollar-Pegged • Algorithmic Stablecoin
A minimal, MakerDAO-inspired stablecoin system built on Ethereum.

DeFiDollar (DFD) is a decentralized stablecoin pegged 1:1 to the US dollar, backed exclusively by WETH (and formerly WBTC) on the Sepolia testnet.
The protocol is designed to remain permanently over-collateralized:

Total USD value of deposited collateral ≥ Total DFD in circulation


Deployed Contracts — Sepolia Testnet

Contract Address Etherscan
DSCEngine 0x94AfbdE9fdbc4842bCD14D7875c22a6199899266 View ↗
DeFiDollar (DFD) 0xB8F5D22dF2CEadF8c4577101a7dc5221F70281A4 View ↗
OracleLib 0xC7f2Cf4845C6db0e1a1e91ED41Bcd0FcC1b0E141 View ↗
WETH (Collateral) 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 View ↗
WBTC (Collateral) 0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063 (Discontinued)

Core Components

DeFiDollar (DFD) — ERC20 Stablecoin

  • Name: DeFiDollar
  • Symbol: DFD
  • Inherits ERC20Burnable + Ownable
  • Only the DSCEngine can mint or burn tokens

DSCEngine — The Protocol Brain

Handles:

  • Collateral deposit & withdrawal
  • Minting & burning of DFD
  • Health factor calculation
  • Liquidation with 10% bonus for liquidators
  • Integration with Chainlink price feeds (via OracleLib)

Key Risk Parameters

Parameter Value Meaning
Liquidation Threshold 50% ~200% over-collateralization required
Minimum Health Factor 1e18 Below → liquidatable
Liquidation Bonus 10% Reward for liquidators

OracleLib — Stale-Price Protection

Wraps Chainlink price feeds and reverts if data is older than 3 hours, freezing the protocol rather than risking bad prices.


User Flow — How to Use the Protocol

Important: Always approve the collateral token (WETH), not the stablecoin.

1. Get Sepolia ETH & WETH

  • ETH: Use a Sepolia faucet
  • WETH: Wrap ETH via the mock token at 0xdd13…f0a81

2. Approve WETH → DSCEngine

cast send 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 \
  "approve(address,uint256)" \
  0x94AfbdE9fdbc4842bCD14D7875c22a6199899266 1000000000000000000 \
  --rpc-url $SEPOLIA_RPC_URL --private-key $PK

3. Deposit Collateral & Mint DFD

One-step (recommended):

cast send 0x94AfbdE9fdbc4842bCD14D7875c22a6199899266 \
  "depositCollateralAndMintDsc(address,uint256,uint256)" \
  0xdd13E55209Fd76AfE204dBda4007C227904f0a81 \
  1000000000000000000 \         # 1 WETH
  1000000000000000000000 \      # 1000 DFD (assuming sufficient collateral value)
  --rpc-url $SEPOLIA_RPC_URL --private-key $PK

4. Check Your Health Factor

cast call 0x94AfbdE9fdbc4842bCD14D7875c22a6199899266 \
  "getHealthFactor(address)(uint256)" YOUR_ADDRESS \
  --rpc-url $SEPOLIA_RPC_URL

≥ 1e18 = safe | < 1e18 = liquidatable

5. Redeem & Repay

# Burn DFD and redeem collateral in one transaction
cast send 0x94AfbdE9fdbc4842bCD14D7875c22a6199899266 \
  "redeemCollateralForDsc(address,uint256,uint256)" \
  WETH_ADDRESS amountToRedeem amountDfdToBurn \
  --rpc-url $SEPOLIA_RPC_URL --private-key $PK

6. Liquidate Undercollateralized Positions

Anyone can call:

liquidate(address collateral, address user, uint256 debtToCover)

→ Burn DFD, receive collateral + 10% bonus


Development & Testing

Built with Foundry.

Requirements

  • Foundry (forge)
  • .env with SEPOLIA_RPC_URL, PRIVATE_KEY, ETHERSCAN_API_KEY

Commands

forge build                  # Compile
forge test                   # Run full test suite (>90% coverage) with unit, fuzz, invariant tests
forge coverage               # View coverage report
forge snapshot               # Gas report

Deploy to Sepolia

forge script script/DeployDSC.s.sol \
  --rpc-url $SEPOLIA_RPC_URL \
  --private-key $PRIVATE_KEY \
  --broadcast --verify \
  --etherscan-api-key $ETHERSCAN_API_KEY \
  -vvvv

Project Structure

src/
├── DecentralizedStableCoin.sol     # DFD token
├── DSCEngine.sol                   # Core engine
└── libraries/
    └── OracleLib.sol               # Stale price guard
test/
├── unit/
├── fuzz/
└── invariants/
script/
└── DeployDSC.s.sol                 # Deployment script

Safety & Disclaimers

  • Educational / Experimental — Not audited
  • Deployed only on Sepolia testnet
  • WBTC support is disabled (use WETH only)
  • In case of Chainlink oracle failure → protocol freezes (by design)

TL;DR — Quick Start Checklist

  1. Get Sepolia ETH → Wrap to WETH
  2. WETH.approve(DSCEngine, amount)
  3. depositCollateralAndMintDsc(...)
  4. Monitor getHealthFactor(you) ≥ 1
  5. Repay with redeemCollateralForDsc(...)

Enjoy experimenting with your own decentralized dollar.

Built with curiosity, tested with rigor. 🧪💵

About

DeFiDollar (DFD) is a decentralized stablecoin pegged 1:1 to the US dollar, backed exclusively by WETH on Sepolia Testnet

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages