Skip to content

Rayannnzn/Defi-Stable-Coin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🪙 DEFI-STABLE-COIN

Empowering Stable, Secure, Decentralized Finance Innovation

Last Commit Solidity Languages


Built with the tools and technologies:

Foundry

Markdown TOML GitHub Actions


📑 Table of Contents


🔹 Overview

This project is a Foundry-based invariant testing setup for a decentralized stablecoin protocol:

  • DSCEngine → Core logic for deposits, redemptions, and minting.
  • DecentralizedStableCoin (DSC) → ERC20-compliant stablecoin, always backed by collateral.
  • Mocks (WETH & WBTC) → For fuzzing and arbitrary testing.
  • HelperConfig & DeployDSC → Deployment and configuration utilities.

The system is rigorously tested with fuzzing + stateful invariant testing to ensure solvency and safety at all times.


🔹 Smart Contracts

⚙️ DSCEngine

Handles collateral deposits & withdrawals.

Manages DSC minting/burning.

Enforces system solvency rules.

💵 DecentralizedStableCoin (DSC)

ERC20-compliant stablecoin.

Minted when collateral is locked, burned on repayment.

Always fully collateralized.

🧪 Collateral Tokens (Mocks)

ERC20Mock for WETH & WBTC in tests.

Allows arbitrary minting for fuzzing.

🛠️ HelperConfig & DeployDSC

Provides token addresses & config.

Deployment scripts for DSCEngine + DSC.

🧪 Testing Infrastructure

🛠 Foundry (forge-std)

Test → Base for unit/invariant tests.

StdInvariant → Fuzzing harness & utilities.

console → Debugging logs.

🎯 Handler Contract

Defines stateful user actions for fuzzing:

depositCollateral

redeemCollateral

Ensures proper minting, approvals, and system safety.

🔒 Invariant Contract

Invariant: “The total USD value of collateral in the system must always be ≥ DSC supply.”

Random sequences of actions are tested.

Guarantees protocol remains solvent under arbitrary behavior.

⚙️ Foundry Settings

runs → Number of fuzzing campaigns.

depth → Actions per campaign.

fails_on_revert → Treat reverts as safety checks.

📚 Core Concepts Tested

Collateralization → DSC must always be backed.

Reverts as Safety → Prevents over-minting & over-withdrawals.

Stateful Fuzzing → Randomized multi-step testing.

Invariant Properties → Solvency is never broken.

Foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.

Foundry consists of:

  • Forge: Ethereum testing framework (like Truffle, Hardhat and DappTools).
  • Cast: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
  • Anvil: Local Ethereum node, akin to Ganache, Hardhat Network.
  • Chisel: Fast, utilitarian, and verbose solidity REPL.

Documentation

https://book.getfoundry.sh/

Usage

Build

$ forge build

Test

$ forge test

Format

$ forge fmt

Gas Snapshots

$ forge snapshot

Anvil

$ anvil

Deploy

$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>

Cast

$ cast <subcommand>

Help

$ forge --help
$ anvil --help
$ cast --help

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors