Minimal, over-collateralized algorithmic stablecoin system built with Foundry. The core contracts are:
DSCEngine: collateral management, mint/burn logic, and liquidationsDecentralizeStableCoin: 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%).
- 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.
ERC20 token (DSC) with mint and burn restricted to the contract owner (the engine).
Core logic:
depositCollateral,withdrawCollateralmintDsc,burnDscdepositAndMintDsc,withdrawCollateralAndBurnDscliquidateUser- price conversions using Chainlink price feeds
Key parameters:
- Minimum health factor:
2e18(200%) - Liquidation bonus:
10% - Supported collateral: WETH, WBTC
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)
Unit tests: test/unit test/DscTokenTest.t.sol
- deposit, mint, burn, withdraw
- health factor checks
- liquidation paths
Invariant fuzzing:
test/fuzz/Handler.t.soltest/fuzz/InvariantsTest.t.sol
Invariant: total system collateral (USD) must be greater than or equal to total DSC supply.
Install dependencies (already vendored under lib):
forge installBuild:
forge buildRun tests:
forge testRun only invariants:
forge test --match-path test/fuzz/InvariantsTest.t.sol- 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.