A decentralized, algorithmic stablecoin protocol built with Foundry and Solidity. Users deposit exogenous crypto collateral (WETH or WBTC) and mint DSC — a token pegged 1:1 to the US dollar — against it. The system is fully on-chain, requires no governance or central authority, and enforces solvency through a strict overcollateralization ratio and an open liquidation mechanism backed by Chainlink price feeds.
DSC (Decentralized Stablecoin) is an algorithmic, exogenous-collateral-backed token pegged 1:1 to the US dollar. Users deposit WETH or WBTC as collateral and mint DSC against it.
Key properties:
| Property | Description |
|---|---|
| Peg | $1.00 USD — maintained via Chainlink price feeds |
| Stability mechanism | Algorithmic (fully decentralized, no governance) |
| Collateral | Exogenous crypto: WETH and WBTC |
| Overcollateralization | 200% minimum — users can mint at most 50% of their collateral value |
- Deposit WETH or WBTC as collateral into
DSCEngine - Mint DSC up to 50% of your collateral's USD value
- Your health factor must always stay at or above
1e18
- Health factor ≥ 1e18 → position is safe
- Health factor < 1e18 → position is undercollateralized and can be liquidated
- Health factor is
type(uint256).maxif no DSC has been minted
If a user's health factor drops below 1e18, anyone can liquidate them:
- The liquidator repays some or all of the user's DSC debt
- In return they receive the equivalent collateral plus a 10% bonus
- The liquidator must maintain their own health factor after the liquidation
git clone -b main https://github.com/JoaquinSkorg/A-Defi-Stablecoin.git
cd foundry-A-defi-stablecoin-
forge install
forge buildNote: Install OpenZeppelin v4.8.3 :
forge install openzeppelin/openzeppelin-contracts@v4.8.3
Use cast to interact with a live or local deployment without writing scripts.
1. Wrap ETH into WETH
cast send 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 "deposit()" \
--value 0.1ether \
--rpc-url $SEPOLIA_RPC_URL \
--private-key $PRIVATE_KEY2. Approve DSCEngine to spend your WETH
cast send 0xdd13E55209Fd76AfE204dBda4007C227904f0a81 "approve(address,uint256)" \
<DSC_ENGINE_ADDRESS> 1000000000000000000 \
--rpc-url $SEPOLIA_RPC_URL \
--private-key $PRIVATE_KEY3. Deposit collateral and mint DSC
cast send <DSC_ENGINE_ADDRESS> \
"depositCollateralAndMintDsc(address,uint256,uint256)" \
0xdd13E55209Fd76AfE204dBda4007C227904f0a81 \
100000000000000000 \
10000000000000000 \
--rpc-url $SEPOLIA_RPC_URL \
--private-key $PRIVATE_KEYSet up environment variables (add to .env):
SEPOLIA_RPC_URL=<your-alchemy-or-infura-url>
PRIVATE_KEY=<your-dev-wallet-private-key>
ETHERSCAN_API_KEY=<optional-for-verification>
Get testnet ETH from faucets.chain.link.
Deploy:
forge script script/DeployDSC.s.sol \
--rpc-url $SEPOLIA_RPC_URL \
--private-key $PRIVATE_KEY \
--broadcast \
--verify \
--etherscan-api-key $ETHERSCAN_API_KEYEstimate gas costs:
forge snapshot
# outputs .gas-snapshotFormat code:
forge fmtStatic analysis with Slither:
slither . --config-file slither.config.json