# Liquidation in eBTC
###### tags: `DeFi` `eBTC` `Lending`
See more in this blog https://badgerdao.medium.com/ebtc-builder-series-liquidations-and-bad-debt-handling-c75196aefdae
## Basic Terminology
- **CDP**: Collateralized Debt Position is the basic unit in eBTC system which is created by depositing valid collateral asset(`stETH`) to mint(borrow) `eBTC` asset. Typically, CDP is **over-collateralized** which means borrower must deposit more collateral in market-value than whatever asset borrowed
- **Collateral Ratio**: collateral asset is priced against BTC according to on-chain oracle feed while `eBTC` is deemed to pegged to BTC thus we could define collateral ratio as `pricing(collateral) * deposited_collateral / borrowed_eBTC`. Due to the nature of over-collateralization, typical Collateral Ratio for healthy CDPs always stay above `100%`.
- **ICR**: Individual Collateral Ratio for a single CDP
- **TCR**: Total Collateral Ratio for entire eBTC system, i.e., `pricing(collateral) * total_deposited_collateral / total_borrowed_eBTC`
- **MCR**: Minimal Collateral Ratio defines the lowest collateralization requirement for a CDP to avoid liquidation. If ICR of a CDP falls below MCR(for example due to sudden market price drop), then this CDP will be liquidated. Current MCR is `110%`.
- **CCR**: Critical Collateral Ratio is introduced to maintain a necessary safety buffer for eBTC to keep healthy collateralization at system level in case sudden market move. CCR is usually set to higher than MCR, currently as `125%`
- **Normal & Recovery Mode**: When TCR is above CCR, system is in normal mode. When TCR drops below CCR, recovery mode is triggered. In Recovery Mode, not only those CDPs whose ICR below MCR are liquidatable but also those CDPs whose ICR below TCR are.
## How does full liquidation work in eBTC?
To guarantee that eBTC remains fully backed by adequate collateral at all time, CDPs whose ICR satisfy following condition will be liquidated:
- ICR < MCR (in BOTH normal mode and recovery mode)
- ICR < TCR (ONLY in recovery mode)
The debt of the CDP will be repaid by and burned from **liquidator** which could be any EOA or smart contract as long as enough debt asset is available in liquidator address approved as repayment.
Liquidator will receive part or all of the collateral in the CDP plus an one-time gas compensation (around `0.2 stETH`, could be queried against smart contract `CdpManager#getCdpLiquidatorRewardShares(cdpId)` for exact value) as the return for full liquidation.
Depending on the ICR when full liquidation is executed, there are several different scenarios as following:
| ICR | debt for liquidator to repay | collateral for liquidator to receive | collateral surplus for CDP owner to claim| resulting bad debt|
| :------: | :------: | :------: | :------: | :------: |
| ICR > `110%` |full_debt_of_cdp| `gasCompensation` + worth of (full_debt_of_cdp * `110%`) | full_collateral_of_cdp - (worth of (full_debt_of_cdp * 110%)) | 0 |
| `103%` < ICR < `110%` |full_debt_of_cdp| `gasCompensation` + full_collateral_of_cdp | 0 | 0 |
| ICR < `103%` |worth of (full_collateral_of_cdp / `103%`)| `gasCompensation` + full_collateral_of_cdp | 0 | full_debt_of_cdp - worth of (full_collateral_of_cdp / `103%`)
As illustrated in above table, liquidator is guaranteed to always have reasonable profit in liquidation. Although there is some unfortunate case which results bad debt to the system, we believe this mechanism is designed to incentivize liquidator quite well to keep the impact as minimum as possible.
Let us see a concrete example: Alice opened a CDP with `20 stETH` at the price of `0.07428 BTC per stETH` and borrowed `1.14 eBTC`. Then the collateral market price drops to `0.062 BTC per stETH`, ICR of Alice's CDP now sits at `20 * 0.062 / 1.14=108.8%` which falls below MCR of `110%` thus make it liquidatable. Liquidator Bob come in to repay the full debt of `1.14 eBTC` and got all collateral (`20 stETH`) in the CDP as return.
Another similar example for Recovery Mode: both Alice and Charlie opened a CDP with `20 stETH` at price of `0.07428 BTC per stETH` while Alice borrowed `1.14 eBTC` and Charlie borrowed only `1 eBTC` so current TCR is `20 * 2 * 0.07428/ (1.14 + 1)=138.8%`. Then collateral market price drops to `0.065 BTC per stETH`, TCR drops to `20 * 2 * 0.065 / (1.14 + 1)=121.5%` accordingly and system now enter Recovery Mode. Alice's CDP ICR is `20 * 0.065 / 1.14=114%` which is less than TCR so liquidator Bob could come in to liquidate this CDP by repaying full debt of `1.14 eBTC` and receive `0.2 + (1.14 * 110% / 0.065)=19.492 stETH` as return while Alice has around `20 - 19.492=0.508 stETH` as surplus to claim.
## Partial liquidation
If the debt for one liquidatable CDP is somehow too big to repay in full or market conditions (like liquidity and slippage) for collateral/debt assets change too quickly to secure full liquidation incentive, liquidator could also perform partial liquidation against the CDP as long as after partial liquidation the CDP still got more collateral than the minimum-size requirement (currently 2 `stETH`).
Similar to full liquidation above, liquidator for partial liquidation will also receive the collateral in the CDP as the return for the liquidation. Depending on the ICR when partial liquidation is executed, there are several different scenarios as following:
| ICR | collateral for liquidator to receive (partial liquidation) |
| :------: | :------: |
| ICR > `110%` (only in Recovery Mode) | worth of (partial_repaid_debt * `110%`) |
| `103%` < ICR < `110%` |worth of (partial_repaid_debt * ICR) |
| ICR < `103%` | worth of (partial_repaid_debt * `103%`) |
Consider an example of partial liquidation against a big CDP: `2000 stETH` collateral deposited at price of `0.07428 BTC per stETH` with borrowed debt of `114 eBTC`. If marke price drops to `0.062 BTC per stETH`, ICR of this big CDP now sits at `2000 * 0.062 / 114=108.8%` which falls below MCR of `110%`. However, liquidator Bob might only has the capacity to liquidate a small fraction of the debt due to the big size of this CDP, so Bob choose to repay `14 eBTC` debt and get back `14 * 108.8% / 0.062=245.68 stETH` as return. Now this big CDP is open to other liquidators as long as its ICR still being underwater, i.e., below MCR or TCR (in Recovery Mode)
## Bad Debt redistribution
Upon liquidation and close of a liquidatable CDP, if the total collateral of the CDP is rewarded to liquidator and there is still some remaining debt of the CDP to be repaid yet, then we will have bad debt in this case. Then the resulting bad debt would be redistributed to entire eBTC system, i.e., every active CDP will take a share of the debt proportional to its CDP size (bigger CDP get more bad debt redistirubted). As a result, ICR of each active CDP would decrease accordingly due to the bad debt redistribution.
For above example of full liquidation against Alice's CDP (`20 stETH` collateral at price of `0.07428 BTC per stETH` with borrowed `1.14 eBTC`), if price drops deeper to `0.057 BTC per stETH`, then liquidator Bob could get full collateral of `20 stETH` by repaying only `20 * 0.057 / 103%=1.107 eBTC` to leave `1.14- 1.107=0.033 eBTC` as bad debt to be redistributed among other active CDPs.
## What oracle is used to determine the pricing of collateral?
eBTC currently uses an aggregated oracle from Chainlink’s [`stETH:ETH`](https://data.chain.link/ethereum/mainnet/crypto-other/eth-btc) and [`ETH:BTC`](https://data.chain.link/ethereum/mainnet/crypto-other/eth-btc) as the primary price feed and might fallback to optional backup feed under the following (extreme) conditions:
- Chainlink price has not been updated for more than `1 hours & 20min` (considering `ETH:BTC` feed heartbeat is 1 hour)
- Chainlink response call reverts or returns an invalid timestamp
- The price change between two consecutive Chainlink price updates is `>50%`