Learn More about Liquidations

The health of the HopeLend Protocol is dependent on the 'health' of the collateralized positions within the protocol, also known as the 'health factor.' When the 'health factor' of an account's total loans is below 1, anyone can make a liquidationCall() to the Pool contract, pay back part of the debt owed and receive discounted collateral in return (also known as the liquidation bonus).

The health factor is calculated from the user's total collateral, i.e., all reserves for which usageAsCollateral is enabled, balance (in ETH) multiplied by the liquidation threshold percentage for all the user's outstanding assets, divided by the user's total borrow balance across all reserves (in ETH).

HopeLend allows 100% of debt (i.e. MAX_LIQUIDATION_CLOSE_FACTOR) to be liquidated in single liquidationCall() if: HF < CLOSE_FACTOR_HF_THRESHOLD

This incentivizes third parties to participate in the health of the overall protocol by acting in their interest (to receive the discounted collateral) and, as a result, ensuring borrowers are sufficiently collateralized.

This incentivizes third parties to participate in the health of the overall protocol by acting in their interest (to receive the discounted collateral) and, as a result, ensuring borrowers are sufficiently collateralized.

There are multiple ways to participate in liquidations:

  1. By calling the liquidationCall() directly in the Pool contract.

  2. By creating your automated bot or system to liquidate loans.

Calculating Profitability vs. Gas Cost

For liquidation calls to be profitable, liquidators must consider the gas cost of liquidating the loan. If a high gas price is used, liquidation may be unprofitable for liquidators.

One way to calculate the profitability is the following:

  1. Store and retrieve each collateral's relevant details, such as an address, decimals used, and liquidation bonus.

  2. Get the user's collateral balance (hTokenBalance).

  3. Get the asset's price according to the Hope Oracle contract using getAssetPrice().

  4. The maximum collateral bonus received on liquidation is given by the maxAmountOfCollateralToLiquidate * (1 - liquidationBonus) * collateralAssetPriceEth

  5. The maximum cost of your transaction will be your gas price multiplied by the amount of gas used. You should be able to get a good estimation of the gas amount used by calling estimateGas via your web3 provider.

  6. Your approximate profit will be the value of the collateral bonus (4) minus the cost of your transaction (5).

Liquidation Prerequisites

When making a liquidationCall(), you must:

  1. Know the account (i.e., the Ethereum address: user) whose health factor is below 1.

  2. Know the valid debt amount and asset (i.e., debtToCover & debtAsset).

    • If the HF is above CLOSE_FACTOR_HF_THRESHOLD, then only a maximum of 50% (i.e., DEFAULT_LIQUIDATION_CLOSE_FACTOR) of the debt can be liquidated per valid liquidationCall().

    • If the HF is below CLOSE_FACTOR_HF_THRESHOLD, then 100% (i.e., MAX_LIQUIDATION_CLOSE_FACTOR) of the debt can be liquidated in single valid liquidationCall().

    • You can set the debtToCover to uint(-1), and the protocol will proceed with the highest possible liquidation allowed by the close factor.

    • You must already have a sufficient balance of the debt asset, which will be used by liquidationCall to pay back the debt. You can use flashLoan for liquidations.

  3. Know the collateral asset collateralAsset you are closing, i.e., the asset that the user has backing their outstanding loan that you will receive as a bonus.

  4. Whether you want to receive hTokens or the underlying asset after a successful liquidationCall().

Getting accounts to liquidate

"User Account" in the HopeLend Protocol refers to a single Ethereum address interacting with the protocol. It can be an externally owned account or contract.

Only user accounts that have HF < 1 can be liquidated. There are multiple ways you can get the health factor:

On Chain

  1. To gather user account data from on-chain data, one way would be to monitor emitted events from the protocol and keep an up-to-date index of user data locally.

    • Events are emitted each time a user interacts with the protocol (supply, borrow, repay, withdraw, etc.)

  2. When you have the user's address, you can simply call getUserAccountData(), to read the user's current health factor. If the HF < 1, then the account can be liquidated.

Executing the liquidation call

Once you have the account(s) to liquidate, you will need to calculate the amount of collateral that can be liquidated:

  1. Use getUserReserveData()

  2. Max debt that is cleared by a single liquidation call is given by the DEFAULT_LIQUIDATION_CLOSE_FACTOR(when CLOSE_FACTOR_HF_THRESHOLD < HF < 1) or MAX_LIQUIDATION_CLOSE_FACTOR (when HF < CLOSE_FACTOR_HF_THRESHOLD)

    • debtToCover = (userStableDebt + userVariableDebt) * LiquidationCloseFactor

    • You can pass uint(-1), i.e., MAX_UINT, as the debtToCover to liquidate the maximum amount allowed.

  3. The max amount of collateral that can be liquidated to cover debt is given by the current liquidationBonus for the reserves that have usageAsCollateralEnabled as true.

    • maxAmountOfCollateralToLiquidate = (debtAssetPrice * debtToCover * liquidationBonus)/ collateralPrice

Last updated