Lending and borrowing in DeFi are supported by liquidations, but these often feel like a dark art. Unlike traditional finance, decentralized liquidations are frequent, instant, and often performed by anonymous operators.

In the early days of DeFi, liquidators were extremely profitable and drove innovations like flash loans and mempool competition. At the same time, decentralized finance lenders experienced market turmoil that could cause traditional financial companies to disappear.

Yet despite the large amounts of money involved and the magnitude of the work involved, information on how to build a clearing mechanism is fragmented and dispersed. It’s an emerging field, with new lenders trying different mechanisms to solve existing or imagined problems.

In this post, we will take you through liquidation mechanisms from the basics to the most advanced. We will explain what factors are involved in liquidation mechanisms so that you can understand existing liquidation mechanisms and even design your own.

About Strong Liquidation

As a traditional lender, you expect borrowers to repay the loans they take from you. If they don't, you accumulate bad debt and potentially go bankrupt. What you can do to ensure that borrowers repay their loans is to require them to lend you something of value in return.

This is called collateral.

If the borrower does not repay the loan, or the lender believes that the loan is unlikely to be repaid, the lender will sell the collateral and enforce repayment of the loan, which is called liquidation. Traditional lenders will hire a trusted party to liquidate an insolvent loan and, if necessary, resort to legal proceedings to avoid losses.

In decentralized finance, there is no legal recourse for non-payment of loans, and bad debts can never be recovered. On the other hand, the exact value of the collateral can be known at any time. For these reasons, insolvent loans in decentralized finance are liquidated immediately if they become insolvent, rather than waiting to be repaid on a given date.

It is easy to view customers who are unable to repay their loans as bad customers and give little thought to their well-being. However, lenders want to protect these customers and make the liquidation process as painless as possible because these customers are likely to be returning customers.

Another difference between liquidations in traditional finance and decentralized finance is that DeFi liquidators are anonymous parties and are generally not subject to censorship. We will see how incentives can be created so that anonymous liquidators protect lenders from bad debts.

All liquidation processes are a trade-off between incentivizing liquidators and protecting users.

Solvency

For a loan to be solvent, the collateral value must always be higher than the debt value. The relative value of the two assets changes with volatility, and a loan that was solvent at one time may become insolvent later.

If a loan becomes insolvent, borrowers have no incentive to repay their debts because the value of the collateral they receive back is less than the value of the debt they repay. Capital losses for lenders can accumulate quickly, leading to bankruptcy.

To avoid this outcome, lenders will allow insolvent loans to be liquidated, with the collateral sold to the liquidator in exchange for paying off the debt.

Solvency as a comparison between collateral and debt value

In order for lenders to remain solvent, basic liquidation can be implemented as follows:

  • Liquidation Condition: A loan becomes eligible for liquidation once the solvency formula is violated: value(collateral) == value(debt)

  • Liquidation Action: All collateral backing the loan is sold in exchange for the assets needed to repay the debt.

The main flaw in the described liquidation process is that a loan can only be liquidated if the market value of the collateral falls below the market value of the assets required to repay the debt. This is a problem because we need to convince anonymous parties to liquidate the loan, and they won’t do so if there is no profit to be made.

To ensure liquidators make a profit, we need to account for collateralization ratios and make loans overcollateralized.

Solvency as a comparison between collateral and debt value

Mortgage ratio

The basic liquidation mechanism described in the previous section does not apply to anonymous liquidators because they do not profit from it.

A simple way to solve this problem is to liquidate loans before they become insolvent. If borrowers are asked to post more collateral than is needed to repay the value of their debt, liquidators have time to liquidate loans for a profit when prices fall.

The collateralization ratio of a loan is defined as the ratio of the collateral value divided by the debt value. The above scenario is an example of an overcollateralized loan where the collateralization ratio is required to be higher than 1.0.

ratio = value(collateral) / value(debt)

Taking into account the collateralization ratio, we now have a different formula to determine whether a loan is healthy and will not be liquidated. Bad loans are still solvent but are eligible for liquidation.

value(collateral) < value(debt) * ratio

A collateralization ratio of over 1.0 protects lenders by incentivizing liquidators to pay off loans that are in danger of bankruptcy. However, the collateralization ratio is determined by the expected volatility between the debt and the collateral assets. The higher the expected volatility, the larger the collateralization ratio must be in order to give liquidators time to act.

Liquidating highly collateralized loans can be very costly for borrowers. As a result, this liquidation model has only been implemented in proofs of concept, such as Yield v1 and MakerDAO predecessor Sai.

Lenders may end up over-incentivizing liquidators for safety reasons. We address this next.

Collateralization ratios increase margin so that liquidations do not result in losses for lenders

Liquidation Bonus

Now, lenders are protected from bad debts due to the selfish actions of liquidators who pay off risky loans for personal gain.

However, lenders need to maintain a balance between being solvent and attracting borrowers. The higher the collateral ratio, the safer the lender, but users will bear higher costs in the event of liquidation.

To manage the trade-off between liquidator profits, user loss size, and lender solvency, liquidation bonuses have been applied since at least Compound v1. When a liquidation bonus is used, liquidators typically receive additional collateral for the debt they repay at a configurable factor (usually much lower than the collateralization ratio).

Of course, the liquidation bonus itself can be a function of any of the following:

  • Total debt or debt paid

  • Total amount of collateral or liquidation collateral

  • Some other factors

Imagine a loan where 150 units of collateral are used to borrow 100 units of debt, with a collateral ratio of 1.5. The relative value of the collateral to the debt drops, and a liquidator steps in to repay the 100 units of debt. Without the liquidation bonus, the liquidator would receive 150 units of collateral, potentially making an immediate profit of nearly 50%

If the liquidation bonus is 5%, the liquidator will repay 100 units of debt and receive 105 units of collateral, a profit of up to 5%. The borrower's debt will be eliminated and will be able to withdraw the remaining 45 units of collateral, with a maximum loss of only 5%.

When we add additional factors to the liquidation process, the risk of misallocation increases.

With the liquidation bonus, we need to ensure that the minimum collateral ratio is higher than the liquidation bonus. Otherwise, either the liquidation bonus will never be paid in full, or the lender will go bankrupt.

Liquidation bonuses limit liquidators’ profits

Closing Factors

If liquidation bonuses were a factor in the size of the loan being liquidated, then large borrowers would pay more than small borrowers when liquidated. To address this, lenders will often only liquidate a portion of the loan.

If a solvent but unhealthy loan is split in half and one of the loans is liquidated, the borrower will receive half of the loan plus half of the collateral after the liquidation (not taken as a liquidation bonus). This means that the remaining half of the loan has more collateral than before.

The proximity factor determines what percentage of loans should be liquidated to keep the liquidation size as small as possible while restoring the reduced loans to a healthy state. Typically, it is defined as a static value (e.g. 50%) in an instant liquidation mechanism.

Consider an example:

  1. A user borrows $750 worth of assets by providing $1,000 worth of collateral

  2. The initial mortgage rate is 1.5, which is reflected in the health of the account

  3. The price of the collateral falls relative to its debt asset, causing it to become undercollateralized

  4. In this example, we assume a proximity factor of 50%. The liquidation bonus is 8%.

Note that in this example, the ETH collateralization factor is defined as 75% - if you deposit $1000 worth of ETH, you can take on a maximum of $750 worth of debt.

At lower collateral prices, the collateralization ratio is still above 1.0, and users and lenders are solvent. The liquidator receives $20 in collateral, which we hope is enough to cover his costs and realize a profit.

We cannot always perform partial liquidations. In some cases, the collateral returned to the borrower may not be enough to make the remaining loan healthy enough. It may remain unhealthy and be liquidated immediately, or it may be healthy but will be liquidated soon due to volatility. In these cases, the lender may choose to ignore the closing factor and liquidate the entire loan.

Liquidation costs

Today, liquidations are tightly coupled with a variety of market mechanisms. Liquidators often receive assets in the form of flash loans to repay debts, which can come at a cost. Flash loans are often repaid by exchanging part of the collateral received on a decentralized exchange, which incurs additional costs such as exchange fees and slippage. Only the collateral remaining after fees is counted as profit.

Liquidators must also pay gas to execute liquidation transactions. Liquidations typically occur during periods of high price volatility, intense competition for block space, and higher-than-usual gas prices.

Liquidators incur other costs, such as developing and maintaining software that must check all new blocks in the blockchain in order to compete with other liquidators to liquidate loans.

Flash loans and transaction costs eat into the liquidation bonus factor, while development and maintenance costs are constant. The liquidation bonus factor needs to be higher than the estimated flash loan and transaction factors, so that the larger the loan size, the higher the profit.

Liquidation costs erode liquidators’ profits

Note that we assume that liquidation costs are linear in this diagram - this may change in practice.

Throttling

Another factor to consider when thinking about market mechanisms is market liquidity.

After liquidation, loan collateral is usually sold immediately; unless the liquidator is keen to hold onto an asset that is depreciating in value. But this is unlikely. Therefore, this raises concerns about the available market liquidity for such sales.

Some people hold more of a particular asset than they have available liquidity; CRV is a notorious recent example. If loans were allowed to be collateralized by amounts that were not easily traded, then those loans would be effectively non-liquidable.

The solution is to set a hard limit on the collateral allowed per loan so that a single liquidation will never exceed the tradable amount of collateral. Even if a borrower takes out multiple loans at the highest collateral, these will be separate liquidations and the market will have a chance to process them one by one.

A different solution is a dynamic closing factor to achieve a similar effect by breaking large loans into smaller portions for liquidation.

None of these solutions are perfect, as market liquidity cannot be consistently predicted in advance. Only integration between lenders and exchanges can allow liquidations to be triggered not only by price changes but also by liquidity changes.

dust

Once we take gas costs into account, smaller loans become unprofitable because the gas required to liquidate them is more expensive than the bonus granted by the lender.

MakerDAO introduced a dust factor that prohibits loans with collateral amounts below a threshold that is expected to make the loan profitable.

This approach is problematic because it depends on unknown and unpredictable factors, such as gas prices and the value of collateral relative to the price of Ethereum. Major lenders have refused to implement dust thresholds, and after years of operation, large-scale vulnerabilities remain unknown.

Given the operational overhead and attack surface dust of implementing thresholds, we avoid them.

auction

So far, we have been discussing instant liquidations that occur in a single transaction. A loan becomes unhealthy and is liquidated at the same instant for a predictable profit. The profit is also proportional to the size of the loan.

This means that large loans are more profitable for liquidators and more risky for borrowers.

Lenders don’t want to punish their biggest customers, and auctions are a tool sometimes used. When liquidating a loan in an auction, the goal is to have liquidators compete and give liquidation rights to the liquidator who accepts to execute with the smallest profit.

The initial implementation of a liquidation auction was likely Sai’s implementation, which used an English auction where a liquidator escrows funds to pay off debts while quoting a price equivalent to a decreasing liquidation bonus over a certain period of time. Liquidators escrow funds, preventing them from using flash loans, which makes this method unusable today.

Dutch auctions were introduced in MakerDAO. In a Dutch auction, the bonus paid to the liquidator increases with the time during the auction. If the liquidator waits, it has the potential to achieve higher profits, but also the risk of being taken advantage of by other liquidators. In a competitive environment, the result is usually that the liquidator ends the auction once it exceeds its profit threshold.

If a Dutch auction is set up to offer a liquidation bonus above 0% at the start of the auction, the effect can be an instant auction, followed by a gradually increasing liquidation bonus if no liquidator can be found. This is the approach used by Yield v2.

Liquidation auctions are more complex than instant liquidations for both lenders who implement them and liquidators who hope to reap the profits. The benefits of dynamic debt pricing must be weighed against the increased attack surface and barriers to entry for liquidators.

In either of these cases, the additional complexity of implementing auction clearing must be considered. In instant clearing, there is only one participant, the liquidator, and only one transaction, the clearing. In an auction, we will have an auctioneer and a liquidator, who will typically submit a transaction at different times and must be rewarded for doing so. The attack surface is greatly increased, and the incentive scheme is more complex, which may not always be a reasonable tradeoff for more efficient clearing pricing.

Auctions ensure that liquidators receive a constant, rather than proportional, profit

Socialization of bad debts

Loans that cannot be liquidated are collectively referred to as bad debts. Sometimes they are combined into a single value that is easy to use, such as sin in MakerDAO.

Bad debt is dangerous because it indicates that the lender is unable to fulfill all of its promises, whether it is returning the collateral it entrusted or providing profits to users who provided liquidity to the lender. Since this may be a situation where the last user to abandon the lender bears all the losses, this is often a race to the exit with disastrous results.

Normally, this hole in the balance sheet is filled by those who manage the lenders from the treasury. However, it seems to be a better idea to immediately socialize bad debts among all or some of the protocol users. This avoids a self-reinforcing cycle.

A completely different approach

I recently read about a completely different approach to building Fluid by Instadapp. The code is not yet available, but it hints at integration with a Uniswap v3 style DEX, and their statement about liquidations allows us to infer a possible design.

In Uniswap v3, liquidity providers are equivalent to options traders within a certain price range. When the price in the trading pool crosses the range in which they provide liquidity, their assets will be traded. Let's extend this idea to the field of lending, but with a twist.

When a borrower provides collateral, that collateral is used as liquidity in the relevant DEX, in a pool where the collateral is traded against the assets that the user has borrowed. The debt is not collateralized by the collateral itself, but rather by the positions that provide liquidity.

If the value of the collateral drops relative to the borrowed asset, the price will move through the associated liquidity positions in the DEX. The result is that the collateral is immediately exchanged for the borrowed asset at market price.

From the lender's perspective, loans are always collateralized. From the user's perspective, the value of their collateral depends on the market, and if the market moves against them, they may receive less collateral than they deposited.

This approach requires deep integration with a Uniswap v3-style functional DEX, but it has undeniable advantages:

  • There is no dedicated liquidator role, and liquidations are performed by regular activities in DEX.

  • Users do not pay any bonuses to liquidators, which means their liquidation penalties are minimal.

  • Market liquidity is not an issue as borrowers provide liquidity when they make loans.

in conclusion

Liquidation mechanisms are critical to DeFi lending, but they are rarely understood. Users are interested in their ROI, not the stability of the lender. No one thinks they will be liquidated, so they only care about how much they lose when liquidated.

On the other hand, the designers of lenders should know that an improperly designed liquidation mechanism will be a fundamental problem. Even if a complete disaster is avoided, dissatisfied liquidated users will make their voices heard.

The best liquidation mechanism is the one that minimizes the risk of bad debts at the lowest possible cost to the user. However, the liquidated users must pay a certain cost to convince the liquidator to liquidate them.

In this article, we have discussed solvency and health. We have discussed collateralization ratios, liquidation bonuses, liquidation factors, liquidation costs, and market limits. We have discussed auctions as a path to optimal liquidation. Finally, we have also hinted at market integration, which could make current liquidation mechanisms obsolete.

Now it's your turn to take all this information and apply it. Happy Clearing.