The health of Exactly's Protocol depends 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
liquidate()call to the Market contract, paying back part of the debt owed, and receiving discounted collateral in return (also known as the liquidation bonus as previously seen here).
This incentivizes third parties to participate in the solvency of the overall protocol by acting in their interest (to receive the discounted collateral) and, as a result, ensure loans are sufficiently collateralized.
In order to know whether an account can be liquidated or not, the
accountLiquidityfunction in the Auditor contract can be called.
As for the
marketToSimulateparameter, the address zero should be passed, and zero (
0) should also be sent as
function accountLiquidity(address account, contract Market marketToSimulate, uint256 withdrawAmount) external view returns (uint256 sumCollateral, uint256 sumDebtPlusEffects)
account in which the liquidity will be calculated.
market in which to simulate withdraw operation.
amount to simulate as withdraw.
sum of all collateral, already multiplied by each adjust factor (denominated in base).
sum of all debt divided by adjust factor considering withdrawal (denominated in base).
This function will return the total adjusted collateral and debt of the account. Then the collateral can be divided by the debt to get the health factor.
If its value is lower than
1, then the liquidate function will not revert when being called for that user.
Other more efficient ways of checking for account positions require monitoring block-to-block transactions. This is the approach followed by our open-source and team-driven bot.
Once there's an account opened to be liquidated, the
liquidatefunction can be called to successfully repay the debt of that user and seize a portion of its collateral with a discount.
The function expects and returns the following arguments:
function liquidate(address borrower, uint256 maxAssets, contract Market seizeMarket) external nonpayable returns (uint256 repaidAssets)
wallet that has an outstanding debt across fixed and variable pools.
maximum amount of debt that the liquidator is willing to accept. (it can be less)
market from which the collateral will be seized to give the liquidator.
actual amount repaid.
It's important to highlight that
maxAssetsshould also include an extra bonus that the variable pool of the Market will keep that the debt is being repaid.