This project is a decentralized, exogenous, anchored (pegged), crypto-collateralized stablecoin system built with Foundry. It is part of the Cyfrin Foundry Solidity Course.
Etherscan Links (Examples):
This protocol aims to maintain a $1.00 peg through an algorithmic stability mechanism.
- Collateral Type: Exogenous (wETH and wBTC).
- Minting: Users can only mint the stablecoin by providing collateral (over-collateralized).
- Stability Mechanism: Algorithmic / Decentralized.
- Price Feed: Utilizes Chainlink Price Feeds to maintain the peg and calculate collateral values.
- Getting Started
- Updates
- Usage
- Deployment to a testnet or mainnet
- Scripts (Manual Interaction)
- Formatting
- Slither
- Git: Installation Guide
- Foundry: Installation Guide
- Run
curl -L https://foundry.paradigm.xyz | bashfollowed byfoundryup.
- Run
git clone git@github.com:Vavinan/DeFi-try.git
cd DeFi-try
forge install
forge build- OpenZeppelin Versioning: The latest version of
openzeppelin-contractshas changes in theERC20Mockfile. To ensure compatibility with the course logic, install version 4.8.3:forge install openzeppelin/openzeppelin-contracts@v4.8.3
Run the full test suite:
forge testRun a specific test with high verbosity (useful for debugging traces):
forge test --match-test testName -vvvEnsure the code adheres to the Solidity style guide:
forge fmtGenerate a gas usage report:
forge snapshotStart a local Ethereum node (Anvil):
anvilTo run your deployment scripts (e.g., on a local or testnet environment):
forge script script/DeployDSC.s.sol --rpc-url <your_rpc_url> --private-key <your_private_key> --broadcastmake anvil
# OR
anvilDefaults to the local Anvil node. Ensure Anvil is running in a separate terminal.
forge script script/DeployDSC.s.sol --rpc-url http://127.0.0.1:8545 --private-key <ANVIL_PRIVATE_KEY> --broadcastThe project includes Unit tests and Fuzzing logic.
Run all tests:
forge testRun a specific test (e.g., Liquidation Bonus):
forge test --match-test testLiquidatorReceivesBonusCollateral -vvvCheck how much of your code is covered by tests:
forge coverageFor a detailed coverage report:
forge coverage --report debug-
Setup Environment Variables Create a
.envfile or export them in your terminal:SEPOLIA_RPC_URL: Your Alchemy/Infura URL.PRIVATE_KEY: Your wallet private key (Use a burner wallet for safety!).ETHERSCAN_API_KEY: (Optional) For contract verification.
-
Deploy to Sepolia
forge script script/DeployDSC.s.sol --rpc-url $SEPOLIA_RPC_URL --private-key $PRIVATE_KEY --broadcast --verify
Generate a gas usage snapshot:
forge snapshotThis creates a .gas-snapshot file containing the gas cost for every function.
To keep the codebase clean and compliant with the Solidity style guide:
forge fmt