Liquidation starts when account maintenance health falls below 0 and end when liquidation end health increases above 0. See Health Overview.
Partial Liquidations are possible.
Liquidations are permissionless and open to anyone for a liquidation fee reward.
Oracle price is used to determine value of assets and liabilities.
Every MangoAccount must have a maint_health above zero. If it slips below zero, liquidators can start liquidating the account until the liquidation_end_health is above zero.
The first liquidation step is to cancel all open orders. This can increase the liqee's health without costing them anything.
The second step is to pay liquidators to close the liqee's liabilities. For example the liqee would give some of its token assets to the a liqor in exchange for receiving tokens that reduce a borrow. Another example would be a liqor taking over the liqee's perp base position in exchange for quote tokens.
These liquidation trades happen around the oracle price, adjusted by the liquidation fee, which differs for each spot asset and perp contract. That is what makes the exchange favorable to the liqor.
The third step is bankruptcy. The liqee has no more assets to give away, so either Mango's insurance fund pays the liqor to reduce the liqee's liabilities or - if no insurance is available for the liability - the loss will be socialized.
The following liquidation-related instructions that can be called on Mango Markets V4: