A robust, overcollateralized stablecoin protocol built on the Ethereum blockchain, featuring algorithmic stability and exogenous collateral backing. 💎
This protocol implements a decentralized stablecoin (DSC) pegged to USD, backed by cryptocurrency collateral (wETH and wBTC). The system is designed with the following key properties:
- Relative Stability: Pegged to USD through Chainlink Price Feeds 📈
- Stability Mechanism: Algorithmic with coded collateralization rules ⚙️
- Collateral Type: Exogenous (wETH, wBTC) 🔐
- Minimum Collateralization Ratio: 200% 💪
- Liquidation Threshold: 50% of collateral value
⚠️
graph TD
subgraph External
User[User/dApp]
CP[Chainlink Price Feeds]
WETH[WETH Token]
WBTC[WBTC Token]
end
subgraph Protocol Core
DSE[DSCEngine]
DSC[DecentralizedStableCoin]
OL[OracleLib]
end
%% User interactions
User -->|Deposit Collateral| DSE
User -->|Mint/Burn DSC| DSE
User -->|Transfer DSC| DSC
%% Internal interactions
DSE -->|Mint/Burn| DSC
DSE -->|Get Prices| OL
OL -->|Validate Prices| CP
%% Collateral flows
WETH -->|Collateral| DSE
WBTC -->|Collateral| DSE
%% Special nodes
style DSE fill:#ff9900,stroke:#333,stroke-width:2px
style DSC fill:#66b2ff,stroke:#333,stroke-width:2px
style OL fill:#99ff99,stroke:#333,stroke-width:2px
-
DSCEngine.sol
- Main protocol logic
- Handles collateral deposits/withdrawals
- Manages minting/burning of DSC
- Implements liquidation mechanics
- Maintains health factors
-
DecentralizedStableCoin.sol
- ERC20 implementation
- Controlled minting/burning mechanics
- Owner-only operations
-
OracleLib.sol
- Price feed management
- Stale price protection
- Chainlink integration
- Overcollateralization: Always maintains >100% collateral backing 💰
- Liquidation System: Automated position management with bonus incentives 🤖
- Price Oracle Integration: Real-time price feeds with staleness checks 📊
- Reentrancy Protection: Secure against common attack vectors 🛡️
- Modular Design: Separated concerns for maintainability 🧩
- Comprehensive test suite including:
- Unit tests ✅
- Integration tests 🔄
- Fuzz testing with invariant checks 🎲
- Failure case handling ⛓️💥
- Multiple security patterns:
- Checks-Effects-Interactions pattern
- Pull over push payments
- Guard checks
- Reentrancy guards
The protocol includes extensive testing infrastructure:
- Invariant Tests: Ensuring system-wide properties hold under any conditions
- Fuzz Testing: Random input testing with both fail-on-revert and continue-on-revert strategies
- Integration Tests: Complete system interaction verification
- Mock Contracts: Thorough edge case testing
- Solidity Version: 0.8.19
- Framework: Foundry
- Dependencies: OpenZeppelin, Chainlink
- Clean, well-documented code following best practices
- Extensive commenting for maintainability
- Gas-optimized operations ⚡
- Modular architecture for upgradability
- Comprehensive error handling
- Clone the repository
git clone https://github.com/SquilliamX/Foundry-Defi-Stablecoin.git- Install dependencies
forge install- Run tests
forge test- Run specific test file
forge test --mt <name_of_test>- Run coverage report
forge coverageThis protocol has been designed with security as a primary concern, implementing:
- Rigorous input validation
- Secure math operations
- Access controls
- Price feed validation
- Emergency pause functionality
- Chainlink oracle dependency
- Market volatility risks
- Liquidation threshold parameters
- Price feed staleness checks
- Collateral value fluctuations
This protocol draws inspiration from successful stablecoin systems like MakerDAO while implementing unique features and improvements. It's designed to be minimal yet robust, focusing on core functionality and security.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
This project is licensed under the MIT License
Note: This protocol is a demonstration of advanced Solidity development practices and should not be used in production without thorough auditing.
Built with ❤️ by Squilliam