Overview
MakerDAO is a decentralized blockchain-based financial system that offers stablecoins (Dai), collateralized loans (CDPs), and decentralized governance services.
The Collateralized Debt Position (CDP) is a smart contract operating on the Ethereum blockchain. It serves as the core component of the Dai stablecoin system, enabling users to generate Dai by locking up collateral assets. The CDP holds these assets until the borrowed Dai is repaid.
Through smart contracts, CDPs dynamically adjust the Dai supply—creating Dai when users lock collateral and destroying it when loans are repaid. This guide explores the implementation mechanics of CDPs.
CDP Workflow: Step-by-Step Process
Step 1: Create a CDP & Deposit Collateral
- Users initiate a transaction to create a CDP via Maker.
- ETH is converted to Wrapped ETH (WETH), then to Pooled ETH (PETH).
- The CDP is activated, with collateralized ETH stored securely.
Step 2: Generate Dai from the CDP
- CDP holders specify the desired Dai amount to generate.
- An equivalent debt is created, locking the collateral until repayment.
Step 3: Repay Debt & Stability Fees
- To redeem collateral, users repay the Dai debt plus stability fees (paid in MKR tokens).
- Upon settlement, the debt is cleared.
Step 4: Withdraw Collateral & Close the CDP
- After full repayment, users retrieve their collateral assets by submitting a closing transaction.
Key Tokens in the MakerDAO Ecosystem
| Token | Purpose | Contract Address |
|---|---|---|
| WETH | ERC-20 wrapped ETH 1:1 peg | 0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2 |
| PETH | Pooled ETH with dynamic exchange rates | 0xf53ad2c6851052a81b42133467480961b2321c09 |
| DAI | USD-pegged stablecoin | 0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359 |
| SIN | Represents liquidated debt (1 SIN = 1 DAI) | 0x79f6d0f646706e1261acf0b93dcb864f357d4680 |
| MKR | Governance token for fee payments | 0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2 |
Smart Contracts Powering CDPs
Sai Tub Contract (Core CDP Logic)
- Function: Manages PETH collateralization and Dai generation.
- Address:
0x448a5065aebb8e423f0896e6c5d525c040f59af3
Sai Tap Contract (Debt Liquidation)
- Function: Handles debt liquidation and profit distribution.
- Address:
0xbda109309f9fafa6dd6a9cb9f1df4085b27ee8ef
👉 Explore advanced DeFi strategies with MakerDAO
Critical Code Snippets
1. Creating a CDP
function open() public note returns (bytes32 cup) {
require(!off);
cupi = add(cupi, 1);
cup = bytes32(cupi);
cups[cup].lad = msg.sender;
LogNewCup(msg.sender, cup);
}2. Locking PETH into a CDP
function lock(bytes32 cup, uint wad) public note {
require(!off);
cups[cup].ink = add(cups[cup].ink, wad);
skr.pull(msg.sender, wad);
require(cups[cup].ink == 0 || cups[cup].ink > 0.005 ether);
}3. Generating Dai (Increasing Debt)
function draw(bytes32 cup, uint wad) public note {
require(msg.sender == cups[cup].lad);
cups[cup].art = add(cups[cup].art, rdiv(wad, chi()));
rum = add(rum, rdiv(wad, chi()));
sai.mint(cups[cup].lad, wad);
require(safe(cup) && sai.totalSupply() <= cap);
}FAQ: MakerDAO CDPs Explained
Q: What’s the minimum collateral requirement?
A: CDPs require over 0.005 ETH worth of PETH to mitigate microtransaction risks.
Q: How are stability fees calculated?
A: Fees accrue as a percentage of debt, payable exclusively in MKR upon repayment.
Q: Can liquidated assets be recovered?
A: No—once a CDP is liquidated, collateral is auctioned via Sai Tap.
Q: Is there a Dai generation limit?
A: Yes, controlled by the cap parameter in the Sai Tub contract.
👉 Start your CDP journey today