Skip to content

Lempkey/foundry-defi-stablecoin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Decentralised Stablecoin

A minimal DeFi stablecoin system that is overcollateralized and algorithmically stable, designed to maintain a 1:1 USD peg. The stablecoin (DSC) is backed by exogenous collateral assets such as ETH and BTC. This project contains two core smart contracts:

  • DecentralisedStableCoin.sol – An ERC20-based stablecoin with burn and mint functionality.
  • DSCEngine.sol – The protocol engine that manages collateral deposits, stablecoin minting/redemption, and liquidations.

Table of Contents

Overview

The Decentralised Stablecoin project is designed to offer a simplified, algorithmic stablecoin mechanism. Users deposit collateral (e.g., ETH or BTC) to mint DSC tokens, ensuring that the total collateral value always exceeds the minted stablecoin supply. The system uses Chainlink price feeds to determine the USD value of the collateral, and incorporates liquidation logic to incentivize healthy collateralization ratios.

Features

  • Exogenous Collateral: Support for assets like ETH and BTC.
  • Overcollateralization: Ensures that the value of collateral exceeds the stablecoin supply.
  • Algorithmic Stability: Maintains a 1 DSC ≙ 1 USD peg through protocol rules.
  • Liquidation Mechanism: Liquidators can cover undercollateralized positions and receive a bonus.
  • Chainlink Integration: Uses Chainlink Price Feeds to obtain up-to-date USD prices for collateral assets.
  • Security: Leverages OpenZeppelin’s audited contracts (ERC20, Ownable, ReentrancyGuard) for robust security practices.

Architecture

The system is composed of two main contracts:

1. DecentralisedStableCoin.sol

  • ERC20 Implementation: Inherits from OpenZeppelin’s ERC20Burnable and Ownable.
  • Minting and Burning: Only the protocol engine (DSCEngine) can mint or burn DSC tokens, ensuring that the stablecoin supply remains controlled.
  • Error Handling: Custom errors provide clear failure messages for invalid operations.

2. DSCEngine.sol

  • Collateral Management: Allows users to deposit supported collateral tokens and tracks deposits per user.
  • Minting & Redemption: Users can mint DSC against their collateral and redeem collateral by burning DSC.
  • Health Factor: Calculates a user’s health factor based on collateral value and debt, ensuring the system remains overcollateralized.
  • Liquidation: Provides a mechanism to liquidate undercollateralized positions, rewarding liquidators with a bonus.
  • Chainlink Price Feeds: Fetches real-time price data for collateral assets, ensuring accurate valuation.

Getting Started

Prerequisites

About

A minimal, overcollateralized, algorithmic stablecoin system featuring exogenous collateral (e.g. ETH & BTC) and a USD peg. Built with Solidity, OpenZeppelin libraries, and Chainlink Price Feeds, this system is inspired by MakerDAO’s DAI but with a lean design for educational and experimental purposes.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors