The Complete Guide to MakerDAO's Collateralized Debt Position (CDP) for Borrowing Dai

·

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

Step 2: Generate Dai from the CDP

Step 3: Repay Debt & Stability Fees

Step 4: Withdraw Collateral & Close the CDP


Key Tokens in the MakerDAO Ecosystem

TokenPurposeContract Address
WETHERC-20 wrapped ETH 1:1 peg0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2
PETHPooled ETH with dynamic exchange rates0xf53ad2c6851052a81b42133467480961b2321c09
DAIUSD-pegged stablecoin0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359
SINRepresents liquidated debt (1 SIN = 1 DAI)0x79f6d0f646706e1261acf0b93dcb864f357d4680
MKRGovernance token for fee payments0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2

Smart Contracts Powering CDPs

Sai Tub Contract (Core CDP Logic)

Sai Tap Contract (Debt Liquidation)

👉 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


References