Skip to content

Hadung14/DecentralizeStableCoin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Foundry DeFi: Decentralized Stablecoin (DSC)

Minimal, over-collateralized algorithmic stablecoin system built with Foundry. The core contracts are:

  • DSCEngine: collateral management, mint/burn logic, and liquidations
  • DecentralizeStableCoin: ERC20 token with mint/burn controlled by the engine

The system targets a $1 peg with exogenous collateral (WETH/WBTC) and a minimum health factor of 2.0 (200%).

High-Level Design

  • Users deposit approved collateral (WETH/WBTC) and mint DSC.
  • Health factor is totalCollateralUsd / dscMinted.
  • If a user drops below the minimum health factor, they can be liquidated.
  • Liquidators burn DSC to cover debt and receive collateral plus a 10% bonus.

Contracts

src/DecentralizeStableCoin.sol

ERC20 token (DSC) with mint and burn restricted to the contract owner (the engine).

src/DSCEngine.sol

Core logic:

  • depositCollateral, withdrawCollateral
  • mintDsc, burnDsc
  • depositAndMintDsc, withdrawCollateralAndBurnDsc
  • liquidateUser
  • price conversions using Chainlink price feeds

Key parameters:

  • Minimum health factor: 2e18 (200%)
  • Liquidation bonus: 10%
  • Supported collateral: WETH, WBTC

Deployment

script/DeployDSCToken.s.sol deploys the token and engine, wires price feeds, and transfers token ownership to the engine.

script/HelperConfig.s.sol sets network configuration:

  • Sepolia: uses live Chainlink feeds and token addresses
  • Local Anvil: deploys mocks (ERC20 + MockV3Aggregator)

Tests

Unit tests: test/unit test/DscTokenTest.t.sol

  • deposit, mint, burn, withdraw
  • health factor checks
  • liquidation paths

Invariant fuzzing:

  • test/fuzz/Handler.t.sol
  • test/fuzz/InvariantsTest.t.sol

Invariant: total system collateral (USD) must be greater than or equal to total DSC supply.

Getting Started

Install dependencies (already vendored under lib):

forge install

Build:

forge build

Run tests:

forge test

Run only invariants:

forge test --match-path test/fuzz/InvariantsTest.t.sol

Notes

  • The system is intentionally minimal and does not include governance or fees.
  • Collateral prices are pulled from Chainlink price feeds; local tests use mock feeds.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors