DSC is an algorithmic, decentralized stablecoin system designed to maintain a 1:1 peg with the US Dollar. It's built on the principles of overcollateralization and exogenous collateral, similar to DAI but without governance, fees, and only backed by WETH and WBTC.
- Decentralized: No central authority controls the system
- Overcollateralized: Always maintains > 100% collateralization
- Algorithmic Stability: Uses smart contracts to maintain the peg
- Exogenous Collateral: Backed by WETH and WBTC
- Liquidation System: Ensures system solvency
- No Governance: Fully autonomous operation
- No Fees: Zero transaction or stability fees
-
Clone the repository:
git clone https://github.com/zeroaddresss/dsc-stablecoin.git cd dsc-stablecoin
-
Install dependencies:
forge install
-
Compile the contracts:
forge build
-
Run tests:
forge test
- DecentralizedStableCoin.sol: The ERC20 token implementation of DSC.
- DSCEngine.sol: The core logic for minting, burning, depositing, and redeeming DSC.
- OracleLib.sol: A library for interacting with Chainlink price feeds and checking for stale data.
depositCollateralAndMintDSC
: Deposit collateral and mint DSC in one transactionredeemCollateralForDSC
: Burn DSC and redeem collateral in one transactionliquidate
: Liquidate undercollateralized positions
- Liquidation Threshold: 50% (200% overcollateralized)
- Liquidation Bonus: 10%
- Minimum Health Factor: 1e18 (1 in standard units)
-
Minting DSC:
// Deposit 1 WETH as collateral IERC20(WETH).approve(address(dscEngine), 1e18); dscEngine.depositCollateralAndMintDSC(WETH, 1e18, 100e18);
-
Redeeming Collateral:
dscEngine.redeemCollateralForDSC(WETH, 0.5e18, 50e18);
-
Liquidating a Position:
dscEngine.liquidate(WETH, userAddress, 100e18);
dsc-stablecoin/
├── src/
│ ├── DecentralizedStableCoin.sol
│ ├── DSCEngine.sol
│ └── libraries/
│ └── OracleLib.sol
├── script/
│ ├── DeployDSC.s.sol
│ └── HelperConfig.s.sol
└── test/
└── mocks/
└── MockV3Aggregator.sol
- OpenZeppelin Contracts
- Chainlink Contracts
Run the test suite using Foundry:
forge test
For more verbose output:
forge test -vvvv
To deploy the DSC system:
- Set up your
.env
file with the required environment variables (e.g.,PRIVATE_KEY
,ETHERSCAN_API_KEY
) - Run the deployment script:
forge script script/DeployDSC.s.sol:DeployDSC --rpc-url $RPC_URL --broadcast --verify -vvvv