Understanding Compound’s Liquidation

Executive summary

Decentralized Finance (DeFi) is one of today’s most compelling crypto narratives and Compound is one of its most prominent examples. As we are adding support for Compound within the Zengo wallet, the Zengo research team has taken a deeper look into one of the most intriguing and novel aspects of the Compound protocol, the Liquidation process.

This whitepaper offers a step-by-step technological explanation and financial survey of Compound’s Liquidation process and thus offers a learning opportunity on a prominent DeFi project, relevant for both experts and beginners.

Key Findings and Predictions

  • Supplying Liquidity on Compound is easy and is a very viable option for both beginners and experienced crypto holders to earn interest on their crypto.
  • In contrast, borrowing and liquidating on the protocol are currently relevant for experts only, as they require technological, operational and economic skills and resources. We predict that they will be used as building blocks for other DeFi products that can be consumed by less sophisticated users.
  • During 2019, $10,375,064 was repaid by liquidators using Compound version 2, resulting in a total of $518,752 profit for liquidators.
  • The innovative incentive-based liquidation process seems to work, as mostly all of the risky borrowings are quickly liquidated once they cross the liquidation threshold.
  • We have observed some sophisticated DeFi users that combine several DeFi solutions together to create new functionalities. We predict that it is a precursor for the next generation of DeFi products and services to be built upon the existing DeFi services.

Outline

The paper is organized as follows:

  • Section 1 gives a short intro to DeFi, Compound.
  • Section 2 takes a deeper technical dive into Compound supplying, borrowing and liquidations
  • Section 3 discusses the technical aspects of liquidation, including a step-by-step “do-it-yourself” recipe to liquidating.
  • Section 4 analyzes the liquidation as observed in the wild, including statistics on the volumes of liquidations in 2019, identifying the main players and gaining more insights on liquidations
  • Section 5 highlights some specific “hand picked” interesting liquidation incidents we have observed
  • Section 6 concludes with our findings and insights

Section 1: Introduction

DeFi and Ethereum

Decentralized Finance (DeFi) is one of today’s most compelling crypto narratives. The initial promise of cryptocurrencies was to make transferring money cheaper and more efficient while minimizing or eliminating altogether the role of intermediaries. DeFi takes this promise and extends it to more sophisticated financial services, such as lending and exchanging.

To do so, DeFi projects are mostly developed on the Ethereum blockchain to leverage its smart contract functionality. Smart contracts allow developers to define protocols, create products and have them executed on the blockchain. DeFi products and protocols are made possible by having the ability to code the rules of financial interactions into blockchains.

Total value locked (USD) in DeFi
Source: defipulse.com

One of the first successful financial use cases enabled by smart contracts, which may be considered as the first generation of DeFi, is the ERC20 standard. ERC20 allows easy issuance of new Ethereum based coins. Some companies and projects used this standard to issue tokens (ICO) to get funding. Others have created stablecoins that are following the behavior of real world assets such as the US Dollar or Gold. As a result, a vibrant financial ecosphere of multiple Ethereum assets were created and which now requires financial services such as lending and exchanging. Naturally, a new generation of DeFi products have come to fill the gap.

Compound

Compound is one of the most prominent examples for DeFi, having recently raised a $25M investment round led by Andreessen Horowitz (a16z VC). Compound creates markets for Ethereum based assets that allows users to be suppliers and borrowers.

The need for asset markets

If you are already familiar with short positions, asset markets and over-collateralized borrowing you can skip to the next section.

To better understand the need for Compound, let’s start with an allegorical example. To simplify we would use real world assets of Gold and Silver and set their initial price to be the same, $100 for one ounce of Gold or Silver.

Borrower Bob is a big believer in Gold and has already invested in it. Bob now estimates that the price of Silver will drop compared to Gold. Using his bank’s asset market, Bob puts 2 ounces of Gold (worth $200) as a collateral and borrows 1 ounce of Silver (with $100) which he then immediately exchange for 1 ounce of Gold. When the price of Silver drops to $50 per ounce, as Bob expected, he exchanges back half an ounce of Gold to get an ounce of Silver, repays his debt in Silver and reclaims his collateral. Using asset markets, Bob was able to leverage his economic predictions to end up with 2.5 ounce of Gold worth $250 and earn $50. Using professional investor terms, the ability to borrow assets allows users to open short positions.

What happens if Bob’s prediction is proven wrong and the price of Silver rises to $200? The preferable option is that Bob repays his borrowed silver with other funds he may have, but if he fails to do so, the bank can liquidate his Gold collateral and exchange it to Silver. This is why in our example, we made Bob have a collateral ($200) bigger than his borrowings ($100). The professional term for that is “over-collateralization”. This enables the bank to have a safety margin to liquidate the collateral before the borrowed sum surpasses it in value; when the Silver price goes to $150, the bank will call Bob telling him either to repay the borrow, top-up his collateral or have his collateral liquidated.

But how did the bank have Silver to give to Bob? One answer might be that borrower Betty made a bet and put a collateral in Silver and now the bank can use it. Additional means to liquidity is that Supplier Susan has some Silver with no immediate intentions to use it. The bank offers her to supply it and get some interest in return. The bank can make this Silver available to borrower Bob. The Bank is incentivized to do so by charging Bob with interest rates which are, naturally, higher than the rates the bank pays to Susan. The interest rates are determined by the bank as a result of the supply and the demand. The higher the demand to borrow an asset, or the lower the supply for it, supplying and borrowing it will have higher interest rates respectively.

So how does the allegorical example above relate to Compound and cryptocurrency?

The first obvious difference is that Compound users are not supplying and borrowing physical precious metals but Ethereum based assets such as ETH, USDC (a stablecoin that is pegged to the US Dollar) and many others.

However, the more important change is that Compound is doing all that without having a centralized bank and replaces it by coding its roles in a set of Ethereum smart contracts. Specifically, all the aforementioned bank roles described in the allegorical example above, such as maintaining a ledger of suppliers and borrowers, computing the interest rates based on supply and demand, paying interest, etc. are now computed automatically by the Ethereum blockchain. By eliminating (or at least minimizing) the middle man, this solution can offer better efficiency and rates.

Compound: DeFi meets asset markets

Compound built a system in which crypto users can supply their Ethereum assets (Ethereum or Ethereum based tokens) to earn interest. The funds to support earning interest are provided by allowing Borrowers to borrow the previously supplied assets against a collateral, and repay them with interest. The interest rate is determined by the ratio between the total supplied funds and total borrowing demand. Thus the system is divided into Suppliers and Borrowers.

While this concept is not new in itself, Compound’s novelty is they were able to eliminate the centralized role of the middleman between Suppliers and Borrowers and replace it with a decentralized alternative by implementing these concepts in code through Ethereum’s smart contracts. These smart contracts automate much of the work traditionally done by a centralized trusted third party.

In the words of Compound’s white paper1, Compound is “a decentralized protocol which establishes money markets with algorithmically set interest rates based on supply and demand, allowing users to frictionlessly exchange the time value of Ethereum assets.”

However, in some cases, automation through coding financial functionality into smart contracts is not enough and there is a need to create economic-based incentives for other players to step in. Such is the case with liquidation. When borrowers exceed their borrowing allowance, according to rules coded into the smart contract, someone needs to liquidate the collateral and balance the account. To incentivize players to take this role and actually liquidate, Compound offers them a portion (currently 5%) of the collateral as a reward.

In this report we will take a deeper look at this distributed liquidation, from both the technical and the economic perspective.

 Compound white paper

Section 2: Compound in more technical terms

In this section we will dive a little deeper into the technical aspects of Compound’s three different players: Suppliers, Borrowers and Liquidators

Compound’s Supplying

Compound suppliers send funds to a smart contract in one of the supported assets to add liquidity to the assets and earn interest. Most of Compound users use this option to earn interest in a simple and risk-less2 manner, and we will support this option in our Zengo wallet. From the technical point of view, supplying involves sending a single message3 over the Ethereum blockchain to call the mint() function in Compound’s smart contract.

In exchange for the supplied assets, the user received cTokens (e.g cETH in exchange for supplying ETH). The cTokens gain interest, and can be later redeemed for the underlying token, if the user no longer wishes to supply liquidity.

Compound’s Supplying

Supplying by sending a mint transaction (source: etherscan)


3
In case the supplied coin is ERC20, an additional approve() message is required to allow Compound’s smart contract to withdraw the user’s funds from the ERC20 smart contract2 Besides systematic risks to Compound, such as Ethereum problems, Vulnerabilities in Compound’s smart contracts, etc.

Compound’s Borrowing

Borrowers, much like suppliers, send funds to a smart contract of one of the supported assets in order to add liquidity to the assets and earn interest. However, unlike passive suppliers, borrowers then use their supplied liquidity as collateral and borrow funds against it in another asset.

Borrowing is over-collateralized, meaning borrowers can only borrow less than their initial supplied liquidity. Borrowers can repay the borrowed funds, along with an interest, according to the interest rate. This interest is used in part to finance the suppliers. If the value of an account’s borrowing outstanding exceeds their borrowing allowance, some collateral needs to be liquidized to rebalance the account.

This means that borrowers, unlike suppliers, must be experts. They must be financially smart to make sure their borrowing makes sense from an economic perspective. They need to make sure they have both the technical capability and financial liquidity to quickly respond if their predictions prove to be wrong and they need to quickly repay their borrowed funds or increase their collateral in order to prevent liquidation.

Compound’s Borrowing

Borrowing by sending a borrow transaction (source: etherscan)

Compound’s Liquidation

To remain decentralized, the Compound protocol cannot rely on a central entity to perform the liquidation but needs to incentivize other players to liquidate the collateral; repay the borrowed funds, in return receive the collateral in another asset with some discount.

In theory, any Ethereum user can be a liquidator. However, liquidation is a game of professionals. In order to be successful, liquidators must be prepared to catch the liquidation opportunity as soon as it arises. Therefore they must be technically ready (e.g. highly available and automated) to identify the opportunity and have enough liquidity in the relevant asset to seize it.

The following section, takes an even deeper dive into the technical aspects of liquidation.

Section 3: Liquidation in practice

This section explains the technical aspects of liquidation and presents the details of an actual liquidation action we had performed ourselves.

The Liquidation process

Finding under-collateralized accounts

All required information to find under-collateralized accounts can be obtained from the blockchain. Compound’s smart contracts provide information on the participating accounts, the amount of funds supplied by and account as well as outstanding borrows. In addition they provide the collateral factor and the relative price of each asset.

A collateral factor is set for each asset and determines the percentage you can borrow against the collateral. A collateral factor is always between 0 and 1, such that the borrowing allowance is determined as supplied_assets x collateral_factor. Each borrow is thus always initially over-collateralized.

Supplied assets, collateral factor, borrowed assets and determine the Account Health. Account Health is the ratio between total ETH supplied and total ETH borrowed. More precisely, it is the sum of all supplied tokens, converted to ETH, multiplied by the collateral factor, divided by the total sum of borrowed tokens converted to ETH. When Account Health is lower than 1 it means the account has exceeded its allowance for borrowing or borrowing capacity.

Several scenarios can lead to this state:

  • The interest on the borrowed funds in higher than the interest on the collateral, and it accumulates over time
  • The price of the collateral suddenly drops
  • The price of the borrowed asset suddenly shoots up

Although all required information on account health is public available on the blockchain, Compound conveniently provides a public API that enables reading a summary of accounts and their respective health value. In fact the API is simply reading information from the blockchain and presenting it in a convenient form. By using the API call AccountRequest4 with the filter “max_health”: { “value”: “1.0” }, Liquidators can obtain information on all accounts which have exceeded their borrowing capacity. (Using higher than 1 threshold for health query, can give early alerts on accounts that are in danger of being liquidated soon).

4 https://compound.finance/developers/api#AccountService

Performing the liquidation

Once a liquidateable account is detected, the actual liquidation is performed by calling the liquidateBorrow() function in the smart contract with the following parameters

  • The address of the liquidated account
  • The repay amount paid by liquidator
  • The token of the collateral, represented by address of Compound smart contract for this token, to be repaid to the liquidator, with a 5% discount

Performing the liquidation
Liquidating by sending a liquidateBorrow transaction (source: Etherscan)

Actual liquidation

To perform Liquidation, we used the publicly available “Compound Liquidator” tool5. The tool shows a list of accounts, sorted by their health, using the aforementioned Compound API.

Actual liquidation

Entries with an Account Health score less than 1 are marked as “Unsafe” and are subject to liquidation. For example:

Pressing the “inspect” button details the account’s current collaterals and borrowings

inspect

5 https://chiragkhatri.me/compound-liquidator/

details the account’s current collaterals and borrowings

The owner of the account has borrowed some ZRX and has some ETH in collateral.

We choose the liquidations details: The token in which we would like to repay on behalf of the borrower, and the token collateral we liquidate and receive as a reward.

choose the liquidations details

We choose to repay in the ZRX token, and receive ETH in return. We choose the maximum amount repayable. This is limited by the close factor, a limit on how much of the outstanding borrow can be collateralized in a single transaction. Currently, the close factor is 0.5.

the close factor is 0.5
Ether - supply

The transaction6 is executed, some amount of ZRX is paid to the market, and we received cETH in return.

Our Compound account now shows we are supplying Ether. The cETH can be left in Compound and gain interest, or redeemed for actual ETH.

As a result of our liquidation, the liquidated account is now slightly above the point of liquidation and the health of the system has improved.

So did we make a fortune with our liquidation proof of concept? Not much so. We gained only $0.01, while paying $0.3 in transaction fees, resulting in a negative bottom line. It is of course the expected outcome, as profitable liquidation opportunities are quickly picked up by the liquidators, and swiftly disappear, leaving only the non-profitable liquidation opportunities to linger on.

https://etherscan.io/tx/0xb7ba825294f757f8b8b6303b2aef542bcaebc9cc0217ddfaf822200a005 94ed9

Section 4: Statistics of Liquidation in the wild

In order to understand when and why liquidations happen and be able to answer questions such as who are the main players, the amounts that are lost and earned, we had collected and analyzed all of Compound liquidation events,

Research methodology

We have gathered information about liquidation events for Compound version 2 (v2 for short). Compound v2 was launched on May 23rd, with 6 Tokens, Ether, 0x, Augur, Basic Attention Token, Dai, and USDC. WBTC was later added, and Dai was superseded with multi-collateral Dai (Original Dai becoming Sai).

To obtain liquidation events data, we analyzed the events emitted by the contracts and stored on the Ethereum blockchain. Each liquidation emits the event: Liquidate Borrow (address liquidator, address borrower, uint256 repayAmount, address cTokenCollateral, uint256seizeTokens).

From this event, we can learn who performed the liquidation (liquidator), who was liquidated (borrower), as well as the amount repaid. The repaid amount is added to the liquidity pool while a collateralized token of choice is sold to the liquidator for a discount. This gives us the total profit from the transaction, excluding transaction fees.

To get the price in USD, we used the historical price of the token on the day of the transaction, obtained from coingecko.

Key stats

  • In total, $10,375,064 were repaid by liquidators
  • These result in a total of $518,752 of profit for the liquidators, assuming a constant 5% liquidation incentive and excluding transaction
  • 1800 liquidation events were executed on Compound v2 during the time
  • Given that the median liquidation profit is $6.35, and the average is $288

When do liquidations happen?

A known adage claims that “deaths come in threes”. We found out that liquidations seem to adhere to a similar pattern as they come in clusters too. The reason behind this phenomena is that liquidations are highly correlated with steep changes in exchange rate. The changes cause borrowers that betted on the wrong side of the change to exceed their borrowing quota allowed by their collateral and become subject to liquidation. When the change is steep, unprepared borrowers either lack the liquidity or the operational readiness to repay their borrowings or to increase the collateral.

We looked at the liquidation activity since the launch of Compound v2, through 2019. November was the month of most liquidations, both in transactions and in volume. This can be mostly attributed to price’ volatility during that month.

When liquidations happen? liquidation activity per month

Zooming in on the most active month liquidation-wise, November, we can examine our hypothesis on the correlation between sudden price changes and liquidation amounts. The upper chart shows price difference in ETH, while the bottom charts shows amounts repaid by liquidators on the same day. As expected, we notice that days with high volatility (close to 10% in price change), were the most lucrative days for liquidators to operate, with almost $2M changing hands and moving from borrowers to liquidators.

Ethereum price during November 2019

Ethereum price during November

Total liquidated and price volatility

Zooming in even further to November 21st, we can see sudden drops in ethereum price, at 03:00, 06:00 and 09:00.

Comparing the information to the liquidations performed on that day, the correlation is clear. We witness liquidations exactly at the time of sudden price changes. The data suggests that liquidation opportunities do not live very long and are immediately picked up by the liquidators.

Ethereum liquidation - Ethereum price per hour - November 21st

Ethereum price per hour – November 21st

liquidated per hour

Liquidations per hour – November 21st

Who are the liquidators and liquidated borrowers?

It appears that liquidation is a game of a few players. A total of 119 different liquidators were recorded, with the median profit being $3.4. The chart below presents the total profit earned by the top 20 liquidators, accounting for 50% of total earned profit.

Most liquidated Borrowers

Similarly, looking at the 20 most liquidated accounts, we see many borrowers are liquidated multiple times, for high amounts. These are the risk takers, looking to maximize their profit from predicting the market and thus using a lot of leverage, often paying dearly for mispredictions.

Most active liquidator revenue
Transaction Hash 

Date

 

Profit ($)

 

Liquidator

 

Borrower

Collateralized TokenRepaid Token
0xa93b2019-12-1710910.697840x10aab0x39bDETHUSDC
0x71c42019-12-2310025.254040x10aab0x586eETHDAI
0x4a132019-12-048994.9327180x10aab0x586eETHUSDC
0x2bf22019-11-227715.4557150x10aab0x586eETHUSDC
0x06e32019-11-227272.646550x10aab0x586eETHUSDC

Looking at the most lucrative liquidation events of 2019, we can see that all were executed by the same liquidator, and almost all for the same borrower.

A total of $120,065 was collected by the most successful liquidator, 20% of the total gained.

Which assets are involved in liquidations?

Liquidations are the results of unsuccessful bets on the direction of the market. Since during the observed period ETH mostly lost value against the USD we expected most liquidated collateral to be in ETH, while the repay borrow to be in stablecoins

Which assets are involved in liquidations?

And indeed ETH was by far the most collected coin by the liquidators, while stablecoins (SAI, DAI, USDC) are most popular for repaying borrows.

Total Repaid Borrow
Total Collateral Colletcted

Section 5: Specific stories of liquidations in the wild

While the statistics in the previous section tells the high level story of Compound’s liquidations, zooming in on some specific examples may yield additional insights.

The biggest liquidation

Big numbers are always interesting and indeed the biggest payout was made on December 17th 2019, resulting a payment of more than 88K cETH, which equates to $330K USD at the date the screenshot below was taken.

The biggest liquidation 88k cETH

The biggest liquidation payout (source: etherscan)

It’s interesting to observe the behavior of the Liquidated account (0x39bde2f9254cfef7d0487a27e107ef6c1685e44).

On June 12th ETH price was ~ $250 USD

The account started a long position on ETH (= expecting ETH to beat USD) on June 12th 2019, by supplying ETH and borrowing mostly USDC (and some SAI)

On June 12th ETH price was ~ $250 USD

Shorting USD: supplying ETH, borrowing USDC

To increase the leverage the account used the Binance exchange to exchange the borrowed USDC back to ETH.

Specifically see the correlation in sums and dates, the 10K USDC borrowed on 7:49 are sent on 7:53 to Binance exchange and result a payment of ~40ETH that is soon added back to the borrowed sums in compound

the borrowed sums in compound

Sending USDC to Binance (source: Etherscan)

Sending USDC to Binance (source: Etherscan)
Getting ETH from Binance (Source Etherscan)

The account never withdraws but makes some small repays, probably to prevent liquidations

The account never withdraws but makes some small repays

When the account needed to repay they bought USDC on the Binance exchange as can be seen in the screenshots below

they bought USDC on the Binance exchange as can be seen in the screenshots below
they bought USDC on the Binance exchange as can be seen in the screenshots below

(source: coinmarketcap)

However, on December 17th ETH price steeply dropped.

Ethereum charts - On December 17th ETH price steeply dropped (source: coinmarketcap)However, on December 17th ETH price steeply dropped.

This time, the account did not have enough liquidity to defend its position (either by increasing the collateral or by repaying) against liquidation and was liquidated for the biggest liquidation payout of 2019 shown above.

Liquidating with a smart contract

The liquidation process often involves additional steps, as the liquidator may need to exchange its current coins with the one relevant to the repayment and/or need to exchange the collected collateral to another coin. In the case described below, the whole process was automated via a smart contract.

Liquidating with a smart contract

Liquidating with a smart contract (source: etherscan)

This smart contract automates the whole compound liquidation process: The liquidator sends ETH to a smart contract, the smart contract exchanges ETH to SAI (using uniswap, another DeFi product that enables exchanging between assets), then the smart contract uses the obtained SAI to repay the borrow and liquidate the collateral in BAT, and finally exchanges BAT back to ETH (using uniswap) and sends back to user for an easy ~6% profit.

Besides the elegant way to make some profit, it really shows the power of DeFi being able to freely mix and match services (in this case Compound and Uniswap) to create new earning opportunities.

Another advantage is that a smart contract either succeeds and its user gets back more ETH than they started with or completely fails. If this process was not implemented as a smart contract, in the case something goes wrong during the liquidation process, the user might have been left with some undesired intermediate results; owning SAI or BAT.

Section 7: Findings and insights

  • Supplying Liquidity on Compound is easy and is a very viable option for beginners to earn interest on their crypto. However, borrowing and liquidating on the protocol is aimed for experts only, as it requires technological and economical skills and resources.
    • Specifically, borrowing requires operational excellence and available liquidity to quickly respond to market changes and restore the health of the borrowing account either by repaying borrowed funds or increasing collateral
    • Similarly, to be a successful liquidator, operational excellence and available liquidity is required to quickly respond to liquidation opportunities and beat other potential liquidators. As a result only a few liquidators are actually successful.
  • We had observed some sophisticated DeFi users that combine several DeFi solutions together to create new functionalities. We predict that it is a precursor for the next generation of DeFi products and services to be built Specifically we expect to see
    • Services that offer leveraged trading based on Compound borrowing
    • Services that allow user to participate in liquidation opportunities
    • Services that combining exchanging with DeFi exchanges (e.g. Uniswap, Kyber) and Compound functionality
  • The innovative incentive-based liquidation process seems to work, as mostly all of the risky borrowings are quickly liquidated once they cross the liquidation The between the appearance of the liquidation opportunity and its exercise is less than an hour (as we only have the historic price granularity of one hour resolution). We assume that the actual exercise time is much less than that and probably is within seconds.
  • We predict that the emergence of DeFi will create a need for analytical tools to harvest the blockchain data and convert it to financially actionable insights.
  • The use of automated trading via smart contracts with DeFi will increase the need for privacy solutions to protect the players’ investment strategy

Authors and Acknowledgements

This report was assembled by Zengo research team, main authors: Alex Manuskin and Tal Be’ery.

Some special thanks to Jeremy Felder, Dan Carmel for proofing, editing and designing the final report.