The health of the Aave Protocol is dependant on the 'health' of the loans within the system, also known as the 'health factor'. When the 'health factor' of an account's total loans is below 1, anyone can make a [liquidationCall()](notion://www.notion.so/developers/the-core-protocol/lendingpool#liquidationcall) to the LendingPool contract, paying back part of the debt owed and receiving discounted collateral in return (also known as the liquidation bonus as listed here).

This incentivises third parties to participate in the health of the overall protocol, by acting in their own interest (to receive the discounted collateral) and as a result, ensure loans are sufficiently collateralised.

There are multiple ways to participate in liquidations:

  1. By calling the [liquidationCall()](notion://www.notion.so/developers/the-core-protocol/lendingpool#liquidationcall) directly in the LendingPool contract.
  2. By creating your own automated bot or system to liquidate loans.

For liquidation calls to be profitable, you must take into account the gas cost involved in liquidating the loan. If a high gas price is used, then the liquidation may be unprofitable for you. See the 'Calculating profitability vs gas cost' section for more details.

0. Prerequisites

When making a liquidationCall(), you must:

1. Getting accounts to liquidate

Only user accounts that have a health factor below 1 can be liquidated. There are multiple ways you can get the health factor, with most of them involving 'user account data'.

"Users" in the Aave Protocol refer to a single ethereum address that has interacted with the protocol. This can be an externally owned account or contract.

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.
    1. Events are emitted each time a user interacts with the protocol (deposit, repay, borrow, etc). See the contract source code for relevant events.
  2. When you have the user's address, you can simply call [getUserAccountData()](notion://www.notion.so/developers/the-core-protocol/lendingpool#getuseraccountdata) to read the user's current healthFactor. If the healthFactor is below 1, then the account can be liquidated.