The Secret Whales Helping DeFi Function
Brother, Can You Spare a Gwei?
Liquidators are underexamined actors in the DeFi space, working, like miners and validators, behind the scenes to keep the entire system functioning and being handsomely rewarded for doing so. Unlike miners and validators, however, liquidators require effectively no upfront capital investment, creating an ecosystem of professionals operating from potentially anywhere in the world, entirely anonymously, getting paid to keep markets solvent.
Over the past two years, a number of decentralized lending protocols, including MakerDAO, Compound, dYdX, and others, have launched on Ethereum, allowing anyone to trustlessly lend or borrow cryptoassets. While these protocols vary in go-to-market approach, assets offered, loan terms, etc., the fundamental loan structure is the same. The borrower places collateral in a smart contract and, in return, is allowed to borrow some lesser amount of another asset provided by the lender. This form of secured lending is one of the most primitive financial instruments, dating back to Venetian banking in the Middle Ages, and contrasts with unsecured, credit-based lending that consumers are more familiar with.
Secured loans can work well when the value of the collateral exceeds the value of the loan, giving borrowers access to working capital without needing to sell their often less liquid assets. However, when the value of the collateral drops, rational borrowers are now incentivized to abscond with the loaned asset, leaving lenders potentially underwater. After all, why return 100 DAI to get back $99 of ETH? With more traditional forms of secured lending, such as auto title loans or mortgages, this is not an issue as the value of those assets are typically less volatile than cryptoassets. However, when taking out a loan with e.g. ETH as collateral, the value can plummet in a matter of seconds.
To mitigate this risk, lending protocols typically require at least 115% collateralization, leaving plenty of buffer before collateral drops below the value of the loan. If the value of the collateral drops below this level, the borrower can simply top it up or sell it off to repay the lender and keep the system solvent. But this creates another set of issues. Transactions on Ethereum aren’t free and the borrower isn’t incurring any additional cost if they get liquidated, so no one is incentivized to keep the system solvent! In order to reward individuals for the costs and risks incurred in liquidating undercollateralized loans and to disincentivize borrowers from letting themselves become undercollateralized in the first place, lending protocols place an additional fee on liquidations which goes to the liquidators themselves. In this way, anyone can repay the debts of the borrowers and receive a nice bonus for doing so — paid for by selling the collateral at a discount to the liquidator — and keeping the system solvent.
Though liquidations vary in mechanism and terms across protocols, they fundamentally require the same components:
- a bot that monitors pending Ethereum transactions and looks for loans that are eligible for liquidation
- a decentralized exchange that can be used to instantly sell the liquidated collateral and guarantee a profit for the liquidator
- a smart contract that allows the liquidation and sale of the collateral to occur atomically in one transaction
Some protocols provide their own off-the-shelf tooling that facilitates the above, but others rely on a burgeoning, homebrew ecosystem of liquidation bots. It’s easiest to understand these actors and their roles within the DeFi ecosystem by walking through a few examples of successful liquidations across the most popular lending protocols.
Compound offers one of the most straightforward borrowing and lending experiences in DeFi, and its liquidation process follows matches this simplicity. Let’s take a look at a single liquidation in-depth.
This liquidation involves two actors, our liquidator (0x64a) who we’ll call “Alice” and our borrower (0xb5b) who we’ll call “Bob”.
Bob took out a loan of USDC on Compound using ETH as collateral. This is often done to purchase more ETH using the lent USDC as a permissionless way to get leverage. Unfortunately for Bob, this loan period coincided with a large drop in the price of ETH, leaving the value of this borrower’s collateral below the required collateral ratio for ETH (133%). Because different assets have different levels of quality, price stability, and liquidity, Compound assigns a different collateralization ratio to each asset (up to 200% for REP at the moment).
Alice notices that Bob is below the required collateralization ratio — presumably, by monitoring contract state or using Compound’s convenient
liquidateBorrowAllowed function — and calling
liquidateBorrow on Compound’s USDC market contract, triggering the liquidation process.
1. Compound first pays Bob any outstanding interest Bob has accrued on his collateral (which, after all, might put him over the require collateralization ratio)
2. Compound verifies that Bob is indeed in default using the market price from their oracles
3. Compound transfers the required amount of lent asset (USDC) from Alice to the cUSDC market contract. In doing so, Alice is rewarded with Bob’s ETH collateral at a fixed discount to market price (currently, 5%). The ETH collateral is returned as cETH, allowing the liquidator to either keep earning interest on the borrower’s ETH, or redeem the cETH for ETH on Compound. In this scenario, Alice made a nice ~$7 in free ETH for her efforts.
While this particular liquidator held onto the cETH, other liquidators use smart contracts to atomically redeem and sell their cTokens, locking in the 5% profit they accrue from this trade. At first glance, one might suspect that this liquidation was done manually, especially given that Compound has not released any open source liquidation bots and the mild popularity of liquidation tracking dashboards. However, when looking at the time-of-day distribution of this liquidator’s activity, we can clearly see that it’s active around the clock, and therefore, most likely a bot.
More sophisticated bots such as this one will perform actions such as quickly borrowing from Compound to liquidate other accounts. We see this happen in this particular liquidation, where the address redeems its USDC loan and uses it to liquidate another account’s USDC borrow, earning an easy 5% in a single transaction.
Maker’s liquidation process is a bit less straightforward as it occurs in two discrete steps: a “bite,” and then a “bust.” It’s similar to how a car might be liquidated — first it’s repossessed, and then it’s auctioned off to repay the owner’s debt. In the Maker system, repossession of a loan is triggered by calling
bite and liquidation is triggered by calling
bust on their set of smart contracts.
Let’s walk through a single liquidation of CDP 17361 through two transactions, the first and second, involving three actors: the repossessor (0xc2e) who we’ll call Ralph, the borrower (0x9c3) who we’ll call Brittany, and the liquidator (0x5a2) who we’ll call Larry.
Brittany borrowed 8.5 DAI against her 0.1 ETH collateral, placing this loan perfectly within Maker’s required collateralization ratio of 150% at the time of loan creation when ETH was at $170. Unfortunately, on December 27th, ETH fell to ~$125, making this CDP just slightly undercollateralized and allowing Ralph to call
bite on the CDP, repossessing ownership of this CDP from
SaiTub, the contract that holds all active CDPs, to the
SaiTap, the contract that performs liquidation of repossessed CDPs.
At this point, the system is still undercollateralized. There is more DAI outstanding than there is ETH in the Maker system to support the value of that DAI at the required ratio. Luckily, Larry, the liquidator, spots this CDP and pays 8.5 DAI for the .067 Pooled ETH in the CDP, equivalent to about 0.07 ETH. This takes DAI off the market, raising the collateralization ratio and keeping the system solvent. For his effort, Larry was able to purchase ETH at ~$121 / ETH, a nice discount to market rate, that Larry immediately sells on Uniswap back for DAI to lock in his .002 ETH of profit.
Note that while Ralph spent money on gas to
bite the risky CDP and initiate liquidation, he actually made no money from it, while Larry was rewarded for his effort with a nice 3% discount on ETH! While there are a large number of bots that will atomically bite and bust CDPs to profit from their effort, only half of all bites involve the same bot also profiting from the liquidation!
So, are there just a large number of good Samaritan bots running around biting CDPs for free? While there are a small number that appear to be doing this, most of the
bites appear to be bots that are unable to find an appropriate price to flip the discounted ETH for upon liquidation. As one such example, transaction 0x8b2 bites a CDP, gets the ETH-DAI quote from Maker, compares it to the best prices they could get on a DEX such as Oasis, and decides they’re better off not taking the risk and just lets the CDP sit in the
SaiTap. Another reason could be the lack of default tooling provided by Maker. While Maker provides a bite-keeper that bites CDPs and an arbitrage-keeper that will flip liquidated ETH on a decentralized exchange for a profit, some additional work is required to merge these into a single cohesive bot. With the transition to Multi-Collateral DAI, the system has moved to a collateral auction, which Maker’s auction-keeper bots can participate in to potentially purchase liquidated collateral at a profit.
Some of the more advanced strategies we see the largest bots employ include:
- Splitting CDP redemption across ETH through
exiting the CDP and across DAI by
booming and taking out more debt to maximize returns
- Use of gas tokens to be able to outbid other bots in the gas auction by using below-market-rate gas
- Splitting ETH sales across many DEXs (a la dex.ag or 1inch) to minimize slippage and maximize the amount of DAI they receive in return
dYdX’s liquidation process is a bit more similar to Compound’s, but differs in that dYdX does not expose a tokenized interface to its lending protocol like how Compound does through its cTokens. Instead, dYdX creates a series of trading accounts for each address within its main Solo Margin contract, and tracks the credits and debts of each account on each market it supports (ETH, DAI, USDC, etc.). Instead of having explicit function signatures like how Maker has
bite and Compound has
liquidateBorrow , dYdX has a single
operate function that takes in different ‘action types’, where action type number 6 liquidates a borrower’s account. The liquidator is able to purchase collateral from the borrower at 5% discount, earning the same healthy spread as Compound.
dYdX contracts also natively support atomic transactions, allowing users to fund, liquidate, and withdraw assets in one step. However, users can themselves become undercollateralized in the process of performing a liquidation and put themselves at risk of being liquidated! Luckily, dYdX has thought of this problem and provided its own proxy contract, which allows users to liquidate borrowers while keeping their accounts within a safe collateralization ratio. This has proven massively popular, with over 90% of liquidation volume going through this proxy. It’s probably no surprise then that the stock dYdX liquidator bot also uses this proxy by default.
dYdX also differs from other protocols in that flash borrowing is built into the protocol, allowing liquidators to atomically borrow the required asset, liquidate, and repay the loan in one single transaction and without needing to use an external proxy contract, making it possible to make true, free profit on dYdX. This combined with their accessible, off-the-shelf liquidator bot might explain why dYdX liquidations have gotten so competitive over the past few months, as discussed later.
While some dYdX liquidations look similar to other protocols’ (such as this one), others (such as this) appear inscrutable when looking at them through conventional chain analytics tools as no token transfer actually occurs and no exchange is actually made. It’s only when we look at the function calls directly that we see what’s going on behind the scenes.
Again, we have liquidator Laura (0x679) and borrower Brad (0xa0d), but unlike in the other examples, Brad deposited DAI and borrowed ETH, presumably to short ETH. When Brad fell under the required collateral rate, Laura swooped in to transfer 53.45 ETH for 7573.97, an effective price of $141.70 / ETH, or ~4% above market at the time, for a profit of $289.05.
Technical details aside, it’s much more interesting to see what happens when these designs are put into practice, especially with pseudonymous, profit-seeking actors. Many individuals and funds have been enticed by the idea of running liquidation bots as a way to generate alpha and support these networks, but as we’ve seen time and time again, there are no free lunches in crypto, and liquidations are no exception.
There were profits to be had
Undeniably, the foundations of the “generalized mining” concept in DeFi have merit. Individuals are making large sums of money by liquidating loans on DeFi! While amounts vary based on liquidation fee, asset, and market volatility, we see that protocols in aggregate have produced almost $1MM in pure profit for liquidators in certain months. Over the lifetime of these protocols, we’ve seen nearly $5MM in profits for liquidators. In certain cases, we’ve seen some liquidators net over $100k in a single liquidation!