Liquidations

Liquidation is a mechanism designed to protect the overall system health during a market downturn. It helps prevent the accumulation of bad debt within the protocol by forcefully closing user positions.

Liquidation conditions

Liquidation can only be triggered and executed by liquidators once the total vault debt, which includes the debt principal and accumulated stability fees, starts to exceed the collateral liquidation threshold.

In the user interface, this relationship between the total vault debt and liquidation threshold is represented as a health factor. Once it drops below 100%, the vault becomes subject to liquidation.

Liquidation process

The BOB CDP only supports full-sized position liquidation, meaning that a position can only be liquidated in full within a single transaction. Partial liquidations are not supported within the BOB CDP.

To perform a liquidation, a whitelisted liquidator should first identify the vault number that meets the liquidation conditions. The liquidation can then be triggered by calling the liquidate(uint256 vaultId) function on the main Vault contract, passing the liquidated vault ID as a single argument.

The Vault contract will check the liquidation conditions of the selected vault, repay the necessary amount of BOB tokens from the liquidator's balance (ensure the necessary BOB allowance is set up beforehand), and transfer the liquidated vault's NFT collateral to the caller.

The total repayment amount is calculated using the following formula:

R=max(D,Cβˆ—(1βˆ’Fliq))R=max(D, C * (1 - F_{liq}))

Where:

  • DD - total vault debt, including debt pricipal and accumulated stability fees

  • CC - total collateral value, C=βˆ‘ci=βˆ‘px(ax+fx)+py(ay+fy)C = \sum{c_i} = \sum{p_x(a_x + f_x) + p_y(a_y + f_y)} from Position valuation (technical)

The liquidator is then free to do anything with the obtained collateral: keep it as is, redeem it for underlying assets, sell or auction underlying assets for BOB.

It is also possible to implement liquidations atomically, turning it into a MEV opportunity. In this case, the collateral should be redeemed and sold in a single atomic transaction. This method requires more engineering resources and increases bot complexity but simplifies the liquidation profitability calculation and removes capital requirements in favor of BOB flash loans.

The canonical BOB CDP liquidation bot implements such an atomic approach - Liqudation bot

Liquidation economics

If the obtained liquidation premium exceeds all required gas costs, AMM fees and slippage, and price oracles discrepancies, then the entire process can be considered strictly profitable for the liquidator.

Liqudation bot

The canonical BOB CDP liquidation implementation can be seen on the zkBob GitHub. Currently, only whitelisted actors, starting with the BOB Core Team as the first liquidator, can participate in the liquidation process. The requirements for liquidator whitelisting will be lifted as the protocol becomes more mature.

If you would like to participate in the liquidation process or develop your own liquidation bot implementation, reach out to us in Discord.

Liquidation example

Here is an example transaction demonstrating the successful liquidation of CDP vault #14 - https://polygonscan.com/tx/0x905af1d70f40cc11deb4dd66234a55e9a9b26ffd8beafb76965b5402805f5df2

Liquidator used the following control flow throughout this transaction for successful liquidation (used contract addresses are available at Deployment addresses):

  1. Calculate the total repayment amount - ~118.60 BOB

  2. Take out a BOB flash loan through the flash minter contract for a slightly greater amount - ~118.64 BOB

  3. Trigger the liquidation by calling the liquidate function on the main Vault contract

    1. The Vault contract burns the debt principal of ~95.68 BOB

    2. The Vault contract collects remaining stability fees and a 5% liquidation fee, totaling ~6.12 BOB

    3. The Vault contract records the repaid remainder of ~16.81 BOB as tokens owed to and claimable by the vault #14 owner

    4. The Vault contract transfers Uniswap V3 NFT collateral to the liquidator contract

  4. Redeems Uniswap V3 NFT #919697 (BOB/WMATIC 0.05%) for the underlying 200 WMATIC + 0 BOB

  5. Sell 198 WMATIC through 1inch for ~121.31 BOB

  6. Repay the BOB flash loan of ~118.64 BOB using the funds obtained during the collateral sell-off

  7. Observe the profit of ~2.7 BOB + 2 WMATIC

Last updated