B.AMM — A DeFi Backstop Liquidation Rebalancer By B.Protocol

Joseph Appolos
20 min readApr 13, 2022

--

Content

Introduction

Meaning of DeFi liquidation

How lending and borrowing in DeFi works

Liquidation process

Problems of liquidation

The Solution

B.Protocol

V1 (Deprecated)

Challenges of V1

V2 (B.AMM)

Benefits of B.Protocol’s B.AMM

Integrations and testimonies

Closing Thoughts

Introduction

According to data tracker DeFi Llama, DeFi has exploded in value over the last year, with the total value of crypto assets rising from roughly $5 billion to $220.52 billion. Data from Dune Analytics reveals that the number of decentralized finance (DeFi) users (i.e. unique addresses)on Ethereum has been on the increase and is currently at a new all-time high of 4.6 million.

But, despite all the massive growth seen in this industry, DeFi adoption is still in its early stage. According to a Chainalysis analysis, mainstream adoption of decentralized finance (DeFi) protocols is still in its early stages compared to the rest of the crypto business. The report said: “DeFi adoption has primarily been powered by experienced cryptocurrency traders and investors looking for new sources of alpha in innovative new platforms, even when we weight our index to favor grassroots adoption.”

The major challenges of DeFi — A lack of consumer protection which means users often have little or no protection when things go wrong, no state-run reimbursement schemes cover DeFi; High Collateral requirements where nearly all the loans available in DeFi lending protocols are overcolatarized (i.e. the collateral provided for a loan is more than the actual loan disbursed); Complexity where protocol users are required to be tech-savvy to build additional system on top of these protocols to maximally enjoy the full benefits and reward of the said protocol or where the terms of use of these DeFi protocols are frequently explained on a high technical level or deeply embedded in financial jargon or where the use of the platform can only be fully maximized by users who are well renowned on blockchain systems have posed a huge threat to the mass adoption of several DeFi projects in the longterm and have hampered or limited the mainstream adoption of DeFi by crypto users and the general population as a whole.

Looking at a specific part of decentralized finance — Lending; which is another way DeFi has outperformed traditional finance systems through its high-interest rates. Although lending and borrowing in DeFi are more profitable as it promises and provides significantly higher APYs compared to traditional finance (e.g. banks), it comes with higher risks because collateralized positions are prone to a higher risk of being liquidated because of the volatility of cryptocurrencies.

Before anything else, let’s look at what liquidation in DeFi means.

What are DeFi Liquidations?

Liquidation in DeFi is basically the process of selling the debt collateral at a discount to liquidators (those who buy the discounted collateral and cover the account’s depth, it is also the first Ethereum account to call a liquidation function in the platform’s smart contract). Liquidation is a term used in traditional finance to describe when a firm or corporation needs to sell part of its assets at a discount to pay off a debt. Users take out loans from a protocol and offer crypto assets as collateral to support the debt, which is comparable to DeFi liquidations.

How lending and Borrowing in DeFi Works

To borrow assets in DeFi, the borrower must first deposit another cryptocurrency asset worth a specific percentage more than the amount borrowed. The maximum amount users can borrow is limited by the collateral factors of the assets they have supplied. For example, if the collateral factor for ETH is 0.75 or 75%. That means you can borrow up to 75% of the value of your deposit. Lenders provide liquidity for borrowers of the protocols for a high-interest rate in form of APYs (passive income) For example, a user deposits DAI in a pool with a certain amount of APY — say 16.5%, this DAI can then be used as a liquidity supply to borrowers in need of it, the lender gets 16.5% yearly interest accrued daily on his dashboard which can be withdrawn anytime.

How DeFi loans work
How DeFi Loans Work. Courtesy: https://www.leewayhertz.com

Liquidation Process

If there were no steep price fluctuations, the process shown in the figure above will be completed, but in the event that the value of the collateral deposited drops drastically due to a fall in market value caused by a huge dip in market price, liquidation will occur. A user account is undercollateralized if his total loan exceeds his total collateral. Once an account is undercollateralized, a liquidation process is carried out by giving the liquidator the borrower’s collateral at a discount price.

For example, Let’s say that a user leverage ETH on MakerDAO, and the current price of ETH is $1,000. The user locks up 10 ETH into an ETH-A Maker Vault and borrows 5,000 DAI.

Borrowing process in MakeeDAO. Source: Zapper Learn

Note: the ratio between the outstanding debt and the value of the collateral is known as the collateralization ratio (c-Ratio). So if the user locks up the 10 ETH ($10,000 worth of ETH) and borrows 5,000 DAI they have a c-Ratio of 200% (10,000/5,000 x 100). If the price of ETH increases (in this case to $2,000), the user makes more profit.

an undercollateralized loan
when a loan becomes undercollateralized. Source: Zapper Learn

This particular Maker Vault requires that you maintain a c-Ratio above 150%. If the position drops drastically below 150%, then the associated debt can be recovered through three means:

  1. The loan can be made available for liquidation by the smart contract. Liquidators then pay back the debt in exchange for receiving the collateral at a discount (i.e., liquidation spread), or the collateral is liquidated through an auction.
  2. Debt can also be rescued by “topping up” the collateral, such that the loan is sufficiently collateralized.
  3. Finally, the borrower can repay parts of their debt.

While users can repay their debts or top-up manually, this appears impracticable for the average user, as it requires infrastructure to constantly monitor the blockchain, collateral price, and transaction fee fluctuations, even professional liquidation bots from MakerDAO failed to monitor and act upon price variations during blockchain congestion. This leaves the First option of liquidation to be the most common and more prominent means of handling undercollaterization.

Liquidation process. Source: Tom Schmidt

Problems of Liquidation

Liquidations, as much less complicated as it is in traditional centralized finance, present some challenges in this present DeFi infrastructure. We’ll try to analyze some of them.

1) Sophistication

Let’s take a critical look at a single liquidation process on Compound protocol for better understanding as Compound provides one of the most simple borrowing and lending experiences in DeFi, and its liquidation process mirrors this simplicity.

Let’s call our liquidator “Mark” and our borrower “James”. James took out a loan of USDC on Compound using ETH as collateral, unfortunately for James, this loan period coincided with a large drop in the price of ETH, leaving the value of his collateral below the required collateral ratio for ETH (133%). Mark notices that James is below the required collateralization ratio — presumably, by monitoring the contract state or using Compound’s convenient liquidateBorrowAllowed function — and calling liquidateBorrow on Compound’s USDC market contract, triggering the liquidation process. Compound performs the following operations once the call was made:

  1. First pays James any outstanding interest he has accrued on his collateral (which, after all, might put him over the required collateralization ratio).
  2. Verifies that James is indeed in default using the market price from their oracles.
  3. Transfers the required amount of lent asset (USDC) from Mark to the cUSDC market contract. In doing so, Mark is rewarded with James’ ETH collateral at a fixed discount to the market price. 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.

At first look, it’s easy to assume that this liquidation was done by hand or manually, however, when we examine the time-of-day distribution of several liquidators’ activities on several protocols — this transaction, for example, we can clearly see that it is active at all hours of the day and night, indicating that it is almost certainly a bot. Now the cost, experience, and technical know-how of setting up a bot for this process is somewhat sophisticated for an average crypto user. Only advanced developers are capable of such, thus, leaving the playing field slightly unbalanced for non-developers and hence creating an entry barrier into the liquidation business.

Despite the level of sophistication involved, users and investors still perform liquidator functions in lending protocols when liquidation calls are made, the primary reason for this is that liquidation is a lucrative business that offers high profit. The chart below shows a cumulative liquidation of 11,480 as of April 11 on Aave V2.

Aave V2 Cumulative Liquidations
Aave V2 Cumulative Liquidations in Bearish case. Source Dune Analytics

Below is the liquidation by assets and liquidators which shows a spike to 1,377 on Aave, DeFi’s largest protocol, on Jan. 17. That’s the highest since the crash in late May 2021. During this event, only 12 liquidators were involved in 1,377 liquidations that occurred that month, displaying a monopoly fueled by the level of sophistication involved, as only a few could build systems that could level up with the competition involved.

Aave liquidations & liquidators
Aave liquidations & liquidators. Source: Dune Analytics

2) Gas Wars

At a fairly stable market price, liquidators stay idle and monitor the market with their liquidation bots, when there’s serious market fluctuation and the price plunges, they wait for the call to be made as price oracles update the price of assets, signaling under collateralization. As soon as the call is made, Ethereum accounts compete on who will give the highest gas price for the liquidation transaction, in order to get higher priority among miners who decide the order of transactions. As a result, great value is shifted away from the platform users (i.e., borrowers and lenders) to the Ethereum miners. In all of the main DeFi platforms, the fairness is typically obtained by a first come first serve approach, in which the liquidator that executes the liquidation first enjoys all of the discount (Compound, Aave, Dydx), or at least improves their positions (MakerDAO).

Let’s take a detailed example of a liquidation event on MakerDAO. Maker’s liquidation process is a bit less straightforward as it occurs in two discrete steps: a bite — repossession of a loan, and then a bust—the actual liquidation, which means the liquidation involves two transactions, and three actors, let’s say Adam the repossessor, Michael the borrower, and Susan the liquidator.

Michael borrowed 8.5 DAI against his 0.1 ETH collateral when the price of ETH was $170 forming a Collateralized debt position (CDP). Unfortunately, the Price of ETH fell to $125, making the (CDP) just slightly undercollateralized and allowing Adam 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. While Adam was still sitting around or using an under-optimized system, luckily, Susan, the liquidator, spotted this CDP, acted before Adam, calls the bustfunction on the CDP, and pays the 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 her effort, Susan was able to purchase ETH at $121, a nice discount from the market rate, giving her a 0.002 ETH profit.

Note that while Adam spent money on gas to bite the risky CDP and initiate liquidation, he actually made no money from it, while Susan was rewarded for her effort with a nice 3% discount on ETH. There are a large number of liquidation bots that will atomically bite and bust CDPs to profit from their effort, but only half of all bites involve the same bot also profiting from the liquidation. So, there are a handful of good Samaritan bots running around biting CDPs for free, while others make the real profit. For a liquidation bot to be able to bite and bust CDPs concurrently successfully and carry out the liquidation, the bot has to be fully optimized to offer the highest gas fees in the shortest possible time, and out-perform other bots.

Gas paid for liquidations (USD) on Compound
Gas paid for liquidations (USD) on Compound. Source: Dune Analytics

3) Liquidation Crisis

During a liquidation event, if the price falls below the liquidation threshold and the collateral is sold at a discount, the market value of the collateral asset may decline even lower. This could result in a chain reaction of liquidations on a particular asset. When market conditions are sub-optimal, liquidators are less likely to engage due to the danger of purchasing a dropping asset’s worth. In a market liquidation crisis, if the asset’s price falls too low, liquidators will pull out completely, leaving DeFi lenders and the protocol itself with massive losses.

The largest single day of liquidations so far was May 12, 2020, as the three most dominant DeFi protocols (Aave, Compound and MakerDAO) together witnessed $377 million worth of collateral liquidated. Aave accounts for $170 million, while Compound lags not far behind with $147 million worth of liquidations, and Maker accounts for $60 million worth of liquidations; the cause of these wave of liquidations was due to a sharp and brief but yet constant plunge of the market on that day.

Total daily liquidation and gas spent on them during the largest liquidation crisis
Total daily liquidation and gas spent on them during the largest liquidation crisis. Source: Covalent

The Solution

The challenges mentioned above have caused some major drawbacks for decentralized lending platforms, e.g., Compound, MakerDAO, Aave, and dYdX, some of them are:

  1. Low yield on user deposits.
  2. Lack of commitment from the liquidators who are responsible for the underlying security of the lending platform.
  3. A big part of the lending protocol value is taken by the underlying blockchain miners due to gas wars between liquidators who “fight” for undertaking borrowers’ under-collateralized loans.

But there’s a solution, and the solution is here.

B.Protocol

B.Protocol is DeFi’s backstop liquidity protocol. A new DeFi building block, bringing some of the best practices of traditional finance (a backstop) into DeFi, aiming to stabilize the ever-growing market of DeFi assets which are crucially dependent on adequate liquidation processes. B.Protocol has created a system that incentivizes liquidity providers, rather than bots and miners to liquidate undercollateralized loans within decentralized lending markets.It democratizes the liquidation system of lending platforms which is integrated into it, providing a stronger safety net to their lenders, and enabling higher collateral factors for its borrowers. This is done by creating a transparent, committed, smart contract-based liquidation system, which enables better capital efficiency for DeFi users while creating another layer of stability for the lending platforms themselves.

How Does it Work?

V1 (Deprecated)

When it was launched back in 2020, B.protocol attempts to solve the liquidation problems with a democratized backstop pool. B.Protocol V1 incentivizes professional traders to act as keepers(liquidators) in MakerDAO and Compound, by letting MakerDAO and Compound users give liquidation priority to these keepers, in return for sharing the proceeds of the liquidations. This way the miners’ extracted profits (MEV) go back to the users of the platform, and the platform enjoys more committed liquidators.

The backstop pool consists of B.Protocol backstop liquidators (BLP)who share their profits with the users of the platform in return for a franchise. A periodic auction process was done to determine the franchise winners which gives them a priority in the liquidation process. During the auction, liquidators bid on the percentage of profit sharing. These profits go to a jar which is periodically distributed to users according to their rating.

Simplified flow of B.Protocol V1 (Deprecated). Source: B.Protocol

This is how it works —when B.Protocol is integrated with existing lending platforms, say, Compound in this illustration, users interact with Compound via a dedicated smart contract interface. This means that deposits are made with the B. protocol app which in turn deposits the asset to the vault of the user’s choice on Compound. B.Protocol liquidators get a priority in the liquidation process by providing a cushion with a top-up operation on the user’s account when it is getting close to the liquidation price, and a scoring engine updates the user’s rating whenever he (the liquidator)performs an operation. The liquidation discount (i.e. liquidation penalty) of that liquidation being processed by B.Protocol’s liquidators over Compound is being divided between the liquidators and the users. The users’ part (other lenders and borrowers) is being accumulated in the B.Protocol-Compound cJar and will be distributed among the users at the end of each epoch according to their User Score.

How B-Protocol is built atop Compound (V1 depreciated

Challenges of V1

Although the design allowed users to get extra yield when using platforms like Maker and Compound, it came with some inadequacies:

  1. It did not address the capital inefficiency of the current system. Namely, users were still bound by the same poor collateral factor that Maker and Compound offer.
  2. In V1, B.Protocol witnessed that even with a TVL of over $250M it was hard to onboard more professional liquidators and the community kept asking for a way for users to participate in the liquidation process themselves, rather than using only the professional liquidators’ liquidity
  3. It also came with the manual process of rebalancing where, for example, a liquidator on Compound receives cETH for an ETH collateral that was returned, he can decide to sell the cETH or keep it to earn more interest on the borrower’s ETH. This is a manual process that is inherent in the normal way of liquidation which is non-user/protocol friendly.

Hence the birth of V2.

V2 (B.AMM)

Automated market makers (AMM) currently present have a similar problem of relatively high slippage w.r.t deposited amount (e.g., Uniswap V2, Sushi, Balancer, and Bancor) and tight spreads which can get depleted upon price changes (e.g., Uniswap V3, Kyber’s DMM); and since most of DeFi liquidity is concentrated on them, lending platforms are being conservative with their collateral factors (compared to CeFi systems like FTX, ByBit, Binance and others who offer x100 leverage to their users). Owing to this fact, decentralized lending platforms like Maker, Compound, dYdX, bZx, Aave, and others, notoriously enable a poor leverage ratio of three to five times, despite having billions of dollars of liquidity at decentralized exchanges that can be used for liquidations at the time of need. Hence, AMMs like Uniswap V2, will fail to facilitate $20M DAI liquidation, despite having over $200M deposited inventory at its ETH/DAI pool. As a result of the uncertainty about the liquidation results, lending platforms are unable to offer adequate leverage/higher collateral factors, and liquidators do not optimize their systems for anything other than arbitrages.

B.Protocol’s solution to the problem is in the form of a platform that allows users to provide liquidity for possible liquidations — debt repayment in return for collateral — via an automatic rebalancing protocol that converts collateral for debt repayment. It provides a system where users provide liquidity that is used for liquidations (e.g., repay DAI debt in return for ETH collateral), and after liquidation happens, an automatic re-balancing process begins. The re-balance process converts the seized collateral from the liquidation, back to the original asset (e.g., the ETH collateral is converted back to DAI).

The rebalance is done by offering the collateral for sale according to the market price, which is determined according to a price oracle (e.g., Chainlink). An optional discount on market price is given according to the imbalance size (the size of collateral to sell), and the exact formula is an adaptation of Curve Finance stable swap invariant.

As user deposits are expected to sit idle for the majority of the time (when liquidations do not occur), the system will deposit it onto the preferred pool in the desired protocol on behalf of the users, e.g., Uniswap, YFI, or Compound, and will withdraw it only to facilitate liquidations.

The summary of this is that in B.Protocol V2, currently live over Liquity protocol, Vesta Finance, Hundreds finance, (and soon over bZx and others), users are incentivized to deposit funds that will be used for the liquidation process in order to enjoy the full liquidation proceeds (e.g. becoming the keepers themselves). Users deposited funds are kept in a yield-bearing platform, and when liquidation is needed, their funds are withdrawn and used to execute the liquidation with 5–10% profit. Finally, a novel on-chain algorithm is used to rebalance the liquidation proceeds back to the originally deposited currency without any intervention by the user.

Rebalancing process using B.AMM. Source: B.Protocol

Simulations done on the model suggests the B.AMM could handle such a size of liquidations worth between $100M-$200M capital and could handle liquidations of $1B monthly.

Percentage of missed liquidation. Source: B.Protocol

Benefits of B.Protocol’s B.AMM

1) Higher Safety net for the Protocol

The democratization of liquidation using the backstop provides a guaranteed profit for users of the protocol, thus more users (lenders and borrowers) are incentivized to deposit and take part in the activities of the platform, hence, increasing the security circle of the protocol. This process also increases the safety margins of the pool involved. In times of a serious market plunge, the automatic rebalancer (B.AMM) performs the liquidation without the help of liquidators and converts the collateral back to the borrowed asset preventing huge losses for the protocol and the lenders involved.

2) Guaranteed Profit for Liquidations

Users and liquidators on lending protocol no longer have to compete for liquidation calls with the whole ethereum community, because B.Protocol has provided a democratized backstop pool where all liquidity providers get a share of the profits from liquidations obtained from the discounted collateral on top of their regular yeilds on their deposits. This profit is guaranteed as their regular APYs as long as liquidation event happens.

3) Elimnation of Gas Wars

The existing liquidation mechanism on most lending platform involves an approach that gives rise to gas price wars where Ethereum accounts compete on who will give the highest gas price for the liquidation transaction in order to get higher priority among miners who decide the order of transactions. B.AMM eliminates this entirely as there’s no single liquidator involved, rather a democratized backstop pool where a single liquidation call is made and every user shares the profit.

4) Automatic Rebalancing System

Once liquidation happens, the discounted collateral is automatically offered for sale by B.Protocol’s Backstop AMM (B.AMM). This is done according to a deterministic formula, which takes into account the current inventory of the assets (the collateral and the reward)involved, and the current market price (which is taken from Chainlink). Whenever the sale occurs, the smart contract deposits the returned pool token back to the pool. This forms a circular system, in which the collateral is always eventually sold and the size of the pool does not decrease over time unless users actively withdraw their deposits. This enhances continuity and improves the user experience of lending protocols.

5) Higher Collateral (Loan-to-Value) Factor

The B.protocol B.AMM does not only democratize the liquidation system for lending protocols by letting anyone provide liquidity to the backstop, but it also adds another layer of stability to lending platforms that it is integrated with. As the backstop facilitates rapid liquidations in a transparent and automated way even in sub-optimal market conditions, it also opens up the option for greater capital efficiency in the form of higher collateral factors and better liquidation thresholds. This means that B.AMM facilitates a larger amount of individual and cumulative liquidation even with a low TVL in its inventory (capable of handling liquidations worth between $100M-$200M).

6) Reduces the Level of Sophistication, thereby Reducing the Entry Barrier

Liquidation bot, price trackers, keepers (in MakerDAO), and systems dedicated to liquidation that are used by advanced players in the field of liquidation to stay ahead of the game have been eliminated. liquidations can now occur seamlessly without any hassle. The whole process is replaced by the Backstop AMM (B.AMM), providing an average user a chance to get a slice of the profit from the process and get involved in the lucrative business of liquidation. Also, by eliminating these additional systems, the capital efficiency required to get involved (for the users) and to keep the pool safe and running (for the protocol) is reduced.

Integrations and Testimonies

Since its launch in 2020, B.Protocol has been integrated into a handful of lending protocols, and the implementation of the backstop automated market maker (B.AMM) in mid-2021, brought in more integrations for B.Protocol.

Compound and MakerDAO

B.Protocol launched integration on top of MakerDAO (available here) in the last quarter of 2020 and on top of Compound early last year, which is available here. Users are able to import their Maker and Compound account into B.Protocol with a simple one-click widget, and will get their rewards as usual on their respective protocols, earn a share from liquidation proceeds, take part in B.Protocol future upgrading decisions, and help make the platforms more resilient to critical sub-optimal conditions. B.Protocol currently has a TVL of over $170 million over these Protocols even though it currently runs on the first version (V1) of B.Protocol. Read the full post about MakerDAO and Compound integration here and here respectively.

Liquity

The liquity integration currently runs on the backstop AMM and hence users enjoy all the amazing benefits that come with it. B.Protocol integration with Liquity does not only save gas expenses to users and allows them for passive participation, it also makes Liquity’s Stability Pool more capital-efficient, and could contribute to the stability of the Liquity protocol. Below are the pool statistics of deposits made through B.Protocol. Read the full post here, and the tutorial on how to get started here

Pool statistics of deposits made through B.Protocol to Liquity
Pool statistics of deposits made through B.Protocol to Liquity. Source: B.protocol

Hundred Finance

Hundred Finance partnered with B.Protocol in order to provide a Backstop Automated Market Maker (B.AMM) product on its Arbitrum and Fantom Opera deployments which allows more efficient and democratic liquidations to be carried out without the need to develop complex flash bot integration and where users contribute funds to the Backstop that are used in automated liquidations, and in return, receives the liquidation proceeds. This service helps maintain the health of the protocol and at the same time, value is directed back towards the participating community members. Learn more about Hundred Finance here. Read more about the integration and how to deposit using the backstop pool here. Below is a breakdown of the current TVL and APR of the USDC backstop pool on Hundred Finance, while the USDT pool has a TVL of over $450K and an APR of 11.4% (find out more here)

Current TVL and APR of the Backstop pool on Hundred Finance. Source: HUndred Finance

Vesta Finance

Vesta Finance was integrated with B.Protocol in February 2022 with the aim of using B.Protocol’s smart contract to automate the rebalancing process of liquidation events (i.e automatically converts liquidated ETH, renBTC, and gOHM back to VST and re-deposits it into the Stability Pools) thus achieving stable return for the depositors as all liquidation gains are locked into VST after rebalancing, more incentive reward as only the VST portion of a user’s position is eligible for incentive reward, not the liquidated asset portion, more capital is ready to liquidate under-collateralized vaults. Learn more here. In the long run, an automated rebalancing process leads to lower capital requirements from the stability pool, as liquidated assets are converted into VST much quicker than manual rebalancing. Learn more about Vesta Finance here. The TVL of Vesta Finance’s ETH pool through the Backstop B.AMM is shown below. other pools in Vestea Finance can be found using B.Protocol’s dashboard as well as other platforms using the B.AMM.

TVL of ETH pool of Vesta Finance
TVL of ETH pool of Vesta Finance. Source: B.Protocol

Closing Thoughts

Anyone can participate in the profitable industry of liquidations using B.Protocol, tapping into the $1B/Year market of DeFi liquidations on its way to the $100B/Year market of CeFi liquidations. B.Protocol V2 could open up a whole new variety of use-cases in DeFi lending as more partnerships and collaborations takes palce and demand for B.Protocol and its backstop solution.

--

--