This repository contains the implementation of a Decentralized Stablecoin (DSC) system, which consists of two main contracts: DecentralizedStableCoin
and DSCEngine
. The DSC is an exogenous, decentralized, anchored (pegged), and crypto-collateralized low-volatility coin pegged to the US dollar.
The DSC system is designed to maintain a 1:1 peg with the US dollar by utilizing overcollateralization. Users can deposit collateral (e.g., wETH, wBTC) and mint DSC tokens. The system ensures that the total value of the collateral is always greater than the total value of the minted DSC tokens.
The DecentralizedStableCoin
contract is an ERC20 token that represents the stablecoin. It includes standard ERC20 functionalities such as minting, burning, and transferring tokens. The minting and burning of DSC tokens are controlled by the DSCEngine contract.
The DSCEngine
contract is responsible for managing the collateral, minting and redeeming DSC tokens, and handling the stability of the system. It keeps track of the deposited collateral and the minted DSC tokens for each user.
Users can interact with the DSCEngine
contract to perform the following actions:
- Deposit collateral and mint DSC tokens
- Redeem collateral by burning DSC tokens
- Liquidate undercollateralized positions
The DSCEngine
contract uses Chainlink price feeds to determine the value of the collateral in USD. It maintains a minimum health factor to ensure that the system remains overcollateralized. If a user's health factor drops below the minimum threshold, their position can be liquidated.
- Node.js (v14 or higher)
- Hardhat
- Foundry
- Clone the repository:
git clone https://github.com/your-username/decentralized-stablecoin.git
- Install the dependencies:
cd decentralized-stablecoin
npm install
- Compile the contracts:
npx hardhat compile
- Run the tests:
npx hardhat test
- Deploy the contracts:
npx hardhat run scripts/deploy.js --network <network-name>
- Install Foundry (if not already installed):
curl -L https://foundry.paradigm.xyz | bash
- Update Foundry to the latest version:
foundryup
- Build the contracts:
forge build
- Run the tests:
forge test
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License.# foundry-defi-stablecoin-f23