A fully decentralized, exogenously collateralized stablecoin system pegged to the US Dollar.
DSC (Decentralized Stablecoin) is an algorithmic stablecoin designed to maintain a 1:1 peg with the US Dollar. It's:
- Exogenously Collateralized: Backed by assets outside the protocol (WETH, WBTC)
- Dollar Pegged: Maintains a target value of $1 USD
- Algorithmically Stable: Uses code-based mechanisms to maintain stability
- Overcollateralized: Always maintains collateral value greater than the minted stablecoin value
This system is similar to MakerDAO's DAI but with simpler mechanics: no governance, no fees, and only WETH and WBTC as collateral.
The core contract that manages the minting, burning, and liquidation processes:
- Handles collateral deposits and withdrawals
- Controls the minting and burning of DSC tokens
- Manages liquidations for undercollateralized positions
- Maintains the health factor (collateralization ratio) for all users
The ERC20 token implementation of the stablecoin:
- Implements standard ERC20 functionality
- Adds burn functionality for redemption
- Controlled by the DSCEngine contract
- Minimum Health Factor: 1.0 (representing 100%)
- Liquidation Threshold: 50% (positions must maintain 200% collateralization)
- Liquidation Bonus: 50% bonus for liquidators
When a user's position becomes undercollateralized (health factor < 1.0):
- Any user can trigger liquidation
- The liquidator pays back some of the user's debt
- In return, they receive an equivalent amount of collateral plus a bonus
- This process helps maintain the protocol's overall solvency
Uses Chainlink price feeds to obtain reliable collateral valuations.
depositeCollateralAndMintDSC: Deposit collateral and mint DSC in one transactiondepositeCollateral: Deposit supported tokens as collateralredeemCollateralForDsc: Burn DSC and redeem collateral in one transactionredeemCollateral: Withdraw collateral (subject to maintaining health factor)mintDsc: Mint new DSC tokens (subject to collateralization requirements)burnDsc: Burn DSC tokens
liquidateDsc: Liquidate undercollateralized positions
getHealthFactor: Check a user's health factorgetAccountCollateralValueInUSD: Get the USD value of a user's collateralgetAccountInformation: Get a user's DSC debt and collateral value
- Node.js and npm
- Foundry/Forge for testing
- Clone the repository:
git clone https://github.com/your-username/dsc-stablecoin.git
cd dsc-stablecoin- Install dependencies:
npm install- Compile contracts:
forge buildRun the test suite:
forge testDeploy to a local network:
forge script script/DeployDSC.s.sol --rpc-url http://localhost:8545 --broadcast- The system is designed to be overcollateralized at all times
- Liquidation mechanisms help maintain solvency
- Price feed oracles are checked for staleness
- Reentrancy protection is implemented
This project is licensed under the MIT License - see the LICENSE file for details.