Empowering Stable, Secure, Decentralized Finance Innovation
Built with the tools and technologies:
- Overview
- Getting Started
- Smart Contracts
- Testing Infrastructure
- Foundry Settings
- Core Concepts
- Resources
- Connect
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.
⚙️ DSCEngine
Handles collateral deposits & withdrawals.
Manages DSC minting/burning.
Enforces system solvency rules.
ERC20-compliant stablecoin.
Minted when collateral is locked, burned on repayment.
Always fully collateralized.
ERC20Mock for WETH & WBTC in tests.
Allows arbitrary minting for fuzzing.
Provides token addresses & config.
Deployment scripts for DSCEngine + DSC.
🛠 Foundry (forge-std)
Test → Base for unit/invariant tests.
StdInvariant → Fuzzing harness & utilities.
console → Debugging logs.
Defines stateful user actions for fuzzing:
depositCollateral
redeemCollateral
Ensures proper minting, approvals, and system safety.
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.
runs → Number of fuzzing campaigns.
depth → Actions per campaign.
fails_on_revert → Treat reverts as safety checks.
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 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.
$ forge build$ forge test$ forge fmt$ forge snapshot$ anvil$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>$ cast <subcommand>$ forge --help
$ anvil --help
$ cast --help