# CDPs

{% hint style="info" %}
**This documentation is a work in progress!**
{% endhint %}

A collateralized debt position (CDP) is a system introduced by MakerDAO team with their decentralized stablecoin DAI.&#x20;

Generally speaking it is a overcollateralized lending contract where borrowers [deposit](https://kresko.gitbook.io/kresko-docs/fundamentals/cdps/icdp/deposit) collateral and [borrow](https://kresko.gitbook.io/kresko-docs/fundamentals/cdps/icdp/minting-borrowing) assets against the deposited collateral. The contract itself acts as a counterparty when borrowers open a debt position.

Borrowers using these CDP's cannot [withdraw](https://kresko.gitbook.io/kresko-docs/fundamentals/cdps/icdp/withdraw) their collateral if it takes the CDP below the [minimum collateralization ratio](#minimum-collateralization-ratio) set in the contract.

### CDPs Act As Cross Positions In Kresko

One or more collaterals back each CDP and borrowers can take multiple debt positions on a single CDP. They effectively act as *cross-margined* positions with many-to-many collateralization as opposed to 1-to-1 positions also known as isolated margin.

### CDP Example&#x20;

{% hint style="success" %}
**Example**

* Collateral **DAI** has a cFactor of **1**. Oracle price **$1**
* Collateral **wBTC** has a cFactor of **0.8**. Oracle price **$15000**
* krAsset **krETH** has a krFactor of **1.1**. Oracle price **$1000**
* krAsset **krQQQ** has a krFactor of **1**. Oracle price **$200**
* Protocol MCR is **140%**

Bob deposits **1500 DAI** and **0.1 wBTC** as collateral

Calculating the [deposit values](https://kresko.gitbook.io/kresko-docs/collateral-assets#collateral-deposit-value)

1. **DAI:** $1500 \* 1 = **$1500**
2. **wBTC:** $150 \* 0.8 = **$120**

Bob's total collateral value is **$1620**

Bob sends a transaction to mint **1 krETH**&#x20;

Calculating the [debt value](https://kresko.gitbook.io/kresko-docs/kresko-assets#calculating-debt)

1. **krETH:** $1000 \* 1.1 = **$1100**

Total collateral Bob needs to cover this mint:&#x20;

$1100 \* 140% = **$1540**

As $1540 is less than $1620. Bob is a able to mint **1 krETH**

Bob wants to mint **1 krQQQ**

Calculating the debt value

1. **krQQQ:** $200 \* 1 = **$200**

Total collateral value Bob needs to cover this mint:&#x20;

($1100 + $200) \* 140% = **$1820**

We can see that Bob has insufficient collateral ($1620) to cover the mint so the transaction would **fail.**

{% endhint %}

## Overcollateralization

In simple terms this means that for any amount of [Kresko Asset](https://kresko.gitbook.io/kresko-docs/fundamentals/kresko-assets) to exist it must be backed by a [Collateral Asset](https://kresko.gitbook.io/kresko-docs/fundamentals/collateral-assets) deposit of equal or greater value.

The protocol needs to stay solvent, avoiding scenario where any CDP has a [Deposit Value](#collateral-deposit-value) less than its [Debt Value](#debt-value). Protocol ensures this by only allows borrows up to a portion of the collateral provided, enforced by [MCR](#minimum-collateralization-ratio), [kFactor](https://kresko.gitbook.io/kresko-docs/kresko-assets#krfactor) and [cFactor](https://kresko.gitbook.io/kresko-docs/collateral-assets#collateral-factor). As asset valuations change over time, the final backstop for solvency is [liquidations](https://kresko.gitbook.io/kresko-docs/fundamentals/liquidations).

## Collateral/Deposit Value

The quantity, price, and the asset's collateral factor are used to determine the *deposit value* (v) of an individual collateral deposit. Deposit value enables the protocol to properly weight different collaterals and calculate the total deposit value of the assets in real-time.

Given a user’s collateral *a*, oracle price $$P\_a$$, quantity $$Q\_a$$, and collateral factor $$CF\_a$$, the deposit value $$v\_a$$ can be represented as follows:

$$
v\_a = Q\_a*P\_a*CF\_a
$$

{% hint style="success" %}
**Example**

If Alice has deposited 1,000 USDC, oracle price of 1 USDC = $1.01, CF for USDC = 0.99, then the deposit value can be calculated as follows:

$$
v\_{USDC} = 1,000 \* $1.01 \* 0.99 = $990
$$
{% endhint %}

### Total Deposit Value

For multiple collaterals, the *total deposit value* (V) is calculated by adding the deposit values of all the individual assets deposited.

Given *n* collaterals, a user’s total deposit value *V* is calculated as follows:

$$
V = \sum\_{i=i}^n v\_i = \sum\_{i=1}^n Q\_i \* P\_i \* CF\_i
$$

{% hint style="success" %}
**Example**

If Alice has deposited 1,000 USDC (v = $990), 1 ETH (v = $2,734.01), and 600 OP (v = $1,072.55), then the total deposit value is:

$$
V = $990 + $2,734.01 + $1,072.55 = $4,796.56
$$
{% endhint %}

## Debt Value

The quantity, price, and kFactor are used to determine the *debt value* (d) incurred by borrowing a Kresko Asset.

Given a borrower’s krAsset *b*, oracle price $$P\_b$$, quantity $$Q\_b$$, and krFactor $$krFactor\_b$$, the debt value $$d\_b$$ is calculated as follows:

$$
d\_b = Q\_b \* P\_b \* kFactor\_b
$$

{% hint style="success" %}
**Example**

Alice wants to borrow 1 krTSLA, Oracle price of 1 TSLA = $1,000, kFactor for TSLA = 1.05, then the debt is:

$$
d\_{krTSLA} = 1 \* $1,000 \* 1.05 = $1,050
$$
{% endhint %}

### Total Debt Value

For multiple Kresko Assets borrowed, the *total debt value* (D) is calculated by combining the debt values of each asset.

Given *n* krAssets, total debt *D* is:

$$
D = \sum\_{i=i}^n d\_i = Q\_i \* P\_i \* kFactor\_i
$$

{% hint style="success" %}
**Example**

if Alice has borrowed 1 krTSLA (d = $1,050), 1 krAAPL (d = $180), and 1.2 krIAU (d = $48), then the total debt is:

$$
D = $1,050 + $180 + $48 = $1,278
$$
{% endhint %}

{% hint style="success" %}
**Example**

If Alice has borrowed 1 krTSLA (d = $1,050), 1 krAAPL (d = $180), and 1.2 krIAU (d = $48), then the total debt is:

$$
D = $1,050 + $180 + $48 = $1,278
$$
{% endhint %}

## Collateralization Ratio

Collateralization Ratio (CR) for an account is obtained by dividing the combined collateral value *V* with outstanding combined debt value *D*.

$$
CR = \frac{V}{D}
$$

If Alice’s total deposit value is $4,806.46 and her total debt is $1,278, then her collateral ratio is

$$
CR = \frac{$4,806.46} {$1,278} = 3.7609 = 376.09%
$$

### **Minimum Collateralization Ratio**

Core risk mitigation of a CDP is the minimum collateralization ratio *(*&#x4D;CR). It is the minimum collateralization ratio that allows taking on new debt.&#x20;

{% hint style="info" %}
If a CDP's collateralization ratio is under the MCR It does **not** mean it can be liquidated.&#x20;

This is decided by the [Liquidation Threshold](https://kresko.gitbook.io/kresko-docs/liquidations#liquidation-threshold) instead.
{% endhint %}

The MCR is used to calculate a minimum [collateral value](https://kresko.gitbook.io/kresko-docs/collateral-assets#collateral-deposit-value) for that a CDP needs to back up it's total debt value.

{% hint style="success" %}
Minimum collateral value required

$$(cValue\_0 + ...+ cValue\_n) \* MCR$$
{% endhint %}

### Liquidation Threshold

Liquidation Threshold (LT) is a protocol parameter which holds the value for absolute minimum collateralization ratio. If the [Collateralization Ratio](#collateralization-ratio) of an account is lower than the Liquidation Threshold, it can be liquidated by the liquidation functions in the protocol.&#x20;

The liquidation threshold is always lower or equal to the [MCR](#minimum-collateralization-ratio). These two values are separate to allow creation of a safety window before accounts are in danger of being liquidated.

### **Health Factor**

[Collateralization Ratio](#collateralization-ratio) converted to a percentage.

<table data-view="cards"><thead><tr><th></th><th></th><th></th><th data-hidden data-card-target data-type="content-ref"></th></tr></thead><tbody><tr><td></td><td><strong>How borrowing works in Kresko</strong></td><td></td><td><a href="cdps/icdp/minting-borrowing">minting-borrowing</a></td></tr><tr><td></td><td><strong>How repayments work in Kresko</strong></td><td></td><td><a href="cdps/icdp/burn-repay">burn-repay</a></td></tr><tr><td></td><td><strong>How Withdrawals work in Kresko</strong></td><td></td><td><a href="cdps/icdp/withdraw">withdraw</a></td></tr></tbody></table>
