Liquidations
Last updated
Last updated
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 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.
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:
Where:
- total vault debt, including debt pricipal and accumulated stability fees
- total collateral value, from Position valuation (technical)
- current liquidation premium -
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
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.
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.
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):
Calculate the total repayment amount - ~118.60 BOB
Take out a BOB flash loan through the flash minter contract for a slightly greater amount - ~118.64 BOB
Trigger the liquidation by calling the liquidate
function on the main Vault contract
The Vault contract burns the debt principal of ~95.68 BOB
The Vault contract collects remaining stability fees and a 5% liquidation fee, totaling ~6.12 BOB
The Vault contract records the repaid remainder of ~16.81 BOB as tokens owed to and claimable by the vault #14 owner
The Vault contract transfers Uniswap V3 NFT collateral to the liquidator contract
Redeems Uniswap V3 NFT #919697 (BOB/WMATIC 0.05%) for the underlying 200 WMATIC + 0 BOB
Sell 198 WMATIC through 1inch for ~121.31 BOB
Repay the BOB flash loan of ~118.64 BOB using the funds obtained during the collateral sell-off
Observe the profit of ~2.7 BOB + 2 WMATIC
As the maximum position size is limited by , the maximum liquidation size is also limited to roughly the same amount.
There is no hard limit on the lower limit for the position and liquidation size, but each collateral should be valued at least , which makes smaller liquidations extremely unlikely.
During a successful liquidation process, the liquidator essentially obtains user collateral at a discount equal to the liquidation premium and then has the opportunity to sell it for a profit.