How to Liquidate

A step by step guide.

General Knowledge

If you are familiar with AAVE V2 already, you can skip this section

VMEX, like other lending protocols, has a threshold for liquidations. Like, AAVE, there is a health factor. They can go as high as infinity (meaning you have no outstanding borrows), and down to 0. The liquidation threshold for an unhealthy loan is when a users health factor drops below 1, meaning that you cannot liquidate a loan unless the health factor is below 1.

You must make calls to LendingPool.sol to perform liquidations, specifically you must call liquidationCall() and pass in the correct parameters for the loan you are trying to liquidate. Keep in mind that liquidations are tranche specific, so you will need to make sure the loan you are passing in the correct trancheId.

Getting Data

As stated previously, there are two main ways to collect data for your liquidation calls. You can query the subgraph, or you can listen to events on-chain. If you need help querying with graphQL, there is an example repo containing a sample query you can use to get started. You can also ask in our discord.

Performing the Liquidation

The following is taken directly from the AAVE V2 docs, as it is the same in our protocol:

Once you have the account(s) to liquidate, you will need to calculate the amount of collateral that can be liquidated: Use on the contract (for Solidity) or the UserReserve object (for GraphQL) with the relevant parameters. Max debt that can be cleared by single liquidation call is given by the current close factor (which is 0.5 currently).

debtToCover = (userStableDebt + userVariableDebt) * LiquidationCloseFactorPercent

You can also pass in type(uint256).max as the debtToCover in to liquidate the maximum amount allowed.

For reserves that have usageAsCollateralEnabled as true, the current gives the max amount of collateral that need to be liquidated to cover debt 👇🏻

maxAmountOfCollateralToLiquidate = (debtAssetPrice * debtToCover * liquidationBonus)/ collateralPrice

Example Repo

Our bot can be viewed here. It is meant simply as a general overview for how you might go about designing a bot, and is by no means guaranteed to be optimal.

Last updated