A decentralized, algorithmic stablecoin system pegged 1:1 to USD, backed by exogenous collateral (wETH & wBTC) with a liquidation mechanism to maintain stability.
- Overview
- Features
- Architecture
- Getting Started
- Usage
- Smart Contracts
- Testing
- Security Considerations
- License
Zero is a decentralized stablecoin protocol inspired by MakerDAO's DAI architecture with key features:
- Exogenously Collateralized: Backed by wETH and wBTC
- Algorithmic Stability: Maintains peg through over-collateralization
- Decentralized: No governance, fully algorithmic
- Pegged to USD: 1 ZERO = $1 USD
The system ensures stability through a minimum 200% collateralization ratio and automated liquidation mechanisms.
- β Mint ZERO: Deposit collateral and mint stablecoins
- β Burn ZERO: Burn tokens to reclaim collateral
- β Deposit Collateral: Add wETH or wBTC as backing
- β Redeem Collateral: Withdraw your collateral
- β Liquidation System: Incentivized liquidation of undercollateralized positions
- β Health Factor Monitoring: Real-time position health tracking
- Chainlink oracle integration for reliable price data
- Support for multiple collateral types
- Accurate USD value calculations
βββββββββββββββββββββββββββββββββββββββββββββββ
β Zero Token β
β (ERC20 Stablecoin) β
βββββββββββββββββββββββββββββββββββββββββββββββ
β²
β
β Mints/Burns
β
βββββββββββββββββββββββββββββββββββββββββββββββ
β ZeroEngine β
β ββββββββββββββββββββββββββββββββββββββ β
β β β’ Collateral Management β β
β β β’ Minting/Burning Logic β β
β β β’ Health Factor Calculations β β
β β β’ Liquidation Engine β β
β ββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββ
β² β²
β β
Chainlink Oracles wETH & wBTC
Zero Token
- ERC20 token implementation
- Burnable functionality
- Ownable (by ZeroEngine only)
ZeroEngine
- Manages all protocol logic
- Handles collateral deposits/withdrawals
- Mints/burns ZERO tokens
- Calculates health factors
- Executes liquidations
- Foundry
- Git
- Node.js (optional, for scripts)# Clone the repository
git clone <your-repo-url>
cd zero-stablecoin
# Install dependencies
forge install
# Build contracts
forge buildCreate a .env file:
SEPOLIA_RPC_URL=your_rpc_url
PRIVATE_KEY=your_private_key
ETHERSCAN_API_KEY=your_etherscan_keyforge script script/DeployZero.s.sol:DeployZero --rpc-url $SEPOLIA_RPC_URL --broadcast --verify// Approve collateral
IERC20(weth).approve(address(zeroEngine), collateralAmount);
// Deposit and mint in one transaction
zeroEngine.depositCollateralAndMintZero(
wethAddress,
collateralAmount,
amountZeroToMint
);uint256 healthFactor = zeroEngine.getHealthFactor(userAddress);
// healthFactor must be > 1e18 (i.e., > 1)zeroEngine.liquidate(
collateralAddress,
userToLiquidate,
debtToCover
);Main Functions:
depositCollateralAndMintZero()- Deposit collateral and mint ZERO in one transactionredeemCollateralForZero()- Burn ZERO and redeem collateralliquidate()- Liquidate undercollateralized positions (earn 10% bonus)getHealthFactor()- Check position healthgetAccountInformation()- Get user's collateral and debt info
Key Parameters:
- Minimum Health Factor: 1e18 (200% collateralization)
- Liquidation Bonus: 10%
- Liquidation Precision: 100
- Liquidation Threshold: 50%
Standard ERC20 with:
- Burn functionality
- Owner-controlled minting (only ZeroEngine)
# Run all tests
forge test
# Run with verbosity
forge test -vvv
# Run specific test
forge test --match-test testLiquidation
# Run fork tests
forge test --fork-url $SEPOLIA_RPC_URL
# Coverage
forge coverage- β Unit tests for all core functions
- β Fuzz testing for edge cases
- β Integration tests
- β Liquidation scenarios
- β Health factor calculations
- β Oracle failure handling
-
Oracle Dependency: Relies on Chainlink price feeds
- Mitigation: Heartbeat checks, staleness checks
-
Liquidation Risk: Users must maintain health factor > 1
- Mitigation: Clear documentation, UI warnings
-
Collateral Volatility: Price crashes can cause cascading liquidations
- Mitigation: 200% collateralization requirement, liquidation incentives
This project demonstrates the implementation of a decentralized stablecoin protocol with algorithmic stability mechanisms, collateral management, and liquidation systems.
MIT License - see LICENSE file for details
Contributions are welcome! Please feel free to submit a Pull Request.
For questions or issues, please open an issue on GitHub.
Built with β€οΈ using Foundry