Liquidation Guide for Developers
This guide discusses how developers can participate in the liquidation process on ZeroLend.
Developers and traders can participate in liquidations through:
Direct Calls: Execute the
liquidationCall()
directly on the Pool or L2Pool contracts.Automation: Use or develop automated systems or bots to identify and execute profitable liquidation opportunities.
Profitability Considerations
While finding profitable liquidation actions, consider the gas costs to calculate the economic feasibility accurately. The liquidation may not be economically feasible if the gas price is too high.
Liquidation Details in Zerolend v3
ZeroLend allows for up to 100% of the debt to be liquidated in a single liquidationCall()
if the HF is below a certain threshold (CLOSE_FACTOR_HF_THRESHOLD).
Prerequisites for Liquidation
Before making a liquidationCall()
, ensure you:
Identify the user account with an HF below 1.
Know the valid debt amount and the asset to cover (debtToCover & debtAsset).
Understand the applicable liquidation close factor based on the HF.
Obtaining Liquidation Targets
User accounts in ZeroLend are individual addresses that have interacted with the protocol. These can be either externally owned accounts or contracts. Accounts eligible for liquidation have an HF < 1.
You can identify these accounts:
On-Chain: Monitor protocol events and maintain an up-to-date index of user data. Use
getUserAccountData()
to check an account's current HF.GraphQL: Utilize GraphQL to gather user account data and compute health factors using Zerolend utilities or SDKs, as real-time data like HF may not be directly available.
Executing a Liquidation Call
To liquidate an account, calculate the collateral that can be liquidated:
Retrieve user reserve data using
getUserReserveData()
.Determine the maximum debt clearance allowed by the liquidation close factor.
Optionally, set
debtToCover
to uint(-1) to liquidate the maximum amount permitted.Calculate the maximum collateral that can be liquidated based on the liquidation bonus and current asset prices.
Calculating Profitability vs. Gas Cost
To assess the profitability of a liquidation, consider:
Collateral details (address, decimals, liquidation bonus).
User's collateral balance.
Asset prices from ZeroLend's oracle using
getAssetPrice()
.Maximum collateral bonus and the cost of your transaction, including gas prices and usage.
Your potential profit is calculated as the value of the collateral bonus minus the transaction cost.
By closely following these steps and calculations, developers can effectively contribute to the protocol's health while potentially securing a profit through successful liquidations.
Last updated