DSCEngine is a Solidity-based decentralized stablecoin system designed to maintain a 1:1 peg with the U.S. dollar using exogenous collateral. This contract implements a minimalistic yet robust stablecoin model with the following features:
-
Dollar Pegged: Maintains $1 peg per token.
-
Exogenous Collateral: Uses external assets like WETH and WBTC as collateral.
-
Algorithmically Stable: Ensures overcollateralization to preserve stability.
Inspired by MakerDAO's DAI but simplified to remove governance, fees, and additional complexities, DSCEngine provides a permissionless platform for decentralized finance (DeFi).
-
Collateral Deposits & Redemptions: Users can deposit collateral, mint stablecoins, redeem collateral, and burn stablecoins.
-
Liquidations: Implements liquidation mechanisms to maintain system health and ensure overcollateralization.
-
Health Factor Monitoring: Tracks and enforces minimum health factors to prevent undercollateralization.
-
Reentrancy Protection: Leverages OpenZeppelin's
ReentrancyGuard
to secure against reentrancy attacks. -
Price Feeds Integration: Uses Chainlink price oracles for accurate asset valuation.
-
Foundry (Smart contract development framework)
-
OpenZeppelin Contracts (Security libraries)
-
Chainlink Price Feeds (Oracle integration)
- Clone the repository:
git clone https://github.com/arefxv/DSCEngine.git
cd DSCEngine
- Install dependencies:
forge install
- Compile contracts:
forge build
- Run tests:
forge test
-
Configure your deployment parameters in
script/Deploy.s.sol.
-
Deploy using Foundry:
forge script script/Deploy.s.sol --rpc-url <YOUR_RPC_URL> --private-key <YOUR_PRIVATE_KEY> --broadcast
- Deposit Collateral:
depositCollateral(address tokenCollateral, uint256 amount)
Deposits collateral tokens into the contract.
- Mint Stablecoins:
mintDsc(uint256 amountToMint)
Mints decentralized stablecoins based on the deposited collateral.
- Redeem Collateral:
redeemCollateral(address tokenCollateral, uint256 amount)
Withdraws collateral while ensuring sufficient health factor.
- Liquidate Under-Collateralized Accounts:
liquidate(address collateral, address user, uint256 debtToCover)
Allows third parties to liquidate unhealthy positions for a reward.
-
Reentrancy Protection: Utilizes OpenZeppelin's ReentrancyGuard to prevent reentrancy attacks.
-
Health Factor Monitoring: Enforces minimum collateral ratios to safeguard against insolvency.
-
CEI Pattern: Implements "Checks-Effects-Interactions" to ensure secure execution of functions.