Better DSCEngine: Decentralized Stablecoin Engine with Dynamic Liquidation Threshold Based on Market Volatility
DSCEngine is a smart contract system for a decentralized stablecoin with dynamic collateralization features. It allows users to mint, burn, and manage a stablecoin backed by various collateral types.
- Multi-collateral support
- Minting and burning of stablecoins
- Collateral deposit and withdrawal
- Liquidation mechanism
- Dynamic liquidation threshold based on market volatility
- Health factor calculation for user positions
DSCEngine.sol
: Main contract handling core functionalitiesDecentralizedStableCoin.sol
: ERC20 token contract for the stablecoin
- Users can deposit multiple types of collateral tokens
- Each collateral type has an associated price feed
- Users can mint stablecoins against their deposited collateral
- Minting is subject to maintaining a healthy collateralization ratio
- A user's position health is measured by the "health factor"
- Positions with a health factor below the minimum are subject to liquidation
- The liquidation threshold adjusts based on market volatility
- Higher volatility leads to a higher threshold, providing more protection against rapid price movements
depositCollateralAndMintDsc
: Deposit collateral and mint stablecoins in one transactionredeemCollateralForDsc
: Burn stablecoins to redeem collateralliquidate
: Allow liquidators to liquidate unhealthy positions
The dynamic liquidation threshold feature adjusts the required collateralization ratio based on market conditions:
- Price history is maintained for each collateral type
- Volatility is calculated based on recent price movements
- The liquidation threshold increases during high volatility periods
- This adaptive approach provides better protection against market fluctuations
- Clone the repository
- Install dependencies:
npm install
- Compile contracts:
npx hardhat compile
Run the test suite:
npx hardhat test
- Set up your
.env
file with required parameters - Run deployment script:
npx hardhat run scripts/deploy.js --network <your-network>
- This contract has not been audited. Use at your own risk.
- Ensure proper access controls and input validation in production.
- Thoroughly test all scenarios, especially around liquidations and extreme market conditions.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.