Liquidation

When the Health Factor of a position is below one. the position becomes subject to liquidation.
Asset liquidation is divided into two different categories:
  • ERC20
  • ERC721
Liquidating each one these asset categories has its own prerequisites and requires calling a different smart contract function.

ERC20 Liquidation

ERC20 Liquidation can be done through calling liquidateERC20() from the PoolCore contract.
function liquidateERC20(
address collateralAsset,
address liquidationAsset,
address borrower,
uint256 liquidationAmount,
bool receivePToken
) external;
Prerequisites
When making a liquidateERC20() call, you must:
  • Know the account (i.e. the ethreum address: borrower) whose health factor is below 1.
  • Supply an asset that the user is currently using in a borrow position (liquidationAsset)
  • Know the user debt amount and asset address (i.e. liquidationAmount & liquidationAsset)
    • 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 liquidationAmount to MAX_UINT = uint256(-1) and the protocol will proceed with the highest possible liquidation allowed.
    • You must already have sufficient balance of the liquidation asset, which will be used by the liquidationCall to pay back the debt.
  • Know the ERC20 collateral asset collateralAsset you closing, i.e. the asset that the user has backing their outstanding loan that you will receive as a bonus.
  • Whether you want to receive p_Tokens or the underlying asset after a successful liquidateERC20()

ERC20 Liquidation Flow Chart

ERC721 Liquidation

ERC721 Liquidation can be done through calling liquidateERC721() from the PoolCore contract.
function liquidateERC721(
address collateralAsset,
address borrower,
uint256 collateralTokenId,
uint256 maxLiquidationAmount,
bool receiveNToken
) external;
Prerequisites
When making a liquidateERC721() call, you must:
  • Know the account (i.e. the ethreum address: borrower) whose ERC721 health factor is below 1.
    • ERC721 Health Factor is the new health factor that is resulted after liquidating all ERC20 collateral. This is to protect ERC721 from getting liquidated when there are ERC20 assets that can be liquidated to save the health of the user's position.
  • Supply ETH/wETH for liquidating ERC721.
    • User ERC20 debt won be repaid, but liquidation funds will be supplied on his behalf through collateral swap. User will receive pWETH tokens.
    • If liquidation auction is not enabled for the asset being liquidated, normal liquidation would proceed with no bonus.
    • If liquidation auction is enabled, liquidation price will be calculated based on dutch auction (see below).
  • Know the collateral asset collateralAsset you are closing and it's token id (i.e. collateralTokenId)
  • Know the collateral ERC721 liquidation price in ETH (i.e. maxLiquidationAmount).
    • Protocol fees are calculated as a percentage of the liquidation bonus: protocol_fees = liquidation_bonus * protocol_fee_percentage, where liquidation_bonus = collateralToLiquidate - actualLiquidationAmountPaid
    • If auction is disabled, there will not be any bonus.
    • You can set the maxLiquidationAmount to uint(-1) and the protocol will automatically calculate the exact amount needed.
    • You must already have sufficient ETH balance, which will be used by the liquidateERC721 to support debt.
  • Whether you want to receive n_Tokens or the underlying asset after a successful liquidateERC721(). ``

ERC721 Liquidation Flow Chart

Dutch Auction
When the NFT floor price fluctuates, supplied NFTs can potentially be liquidated if the ERC721HF is below 1. For most assets, rather than liquidating directly using floor price, we use dutch auction to do price discovery, by marking some assets as auctionable (Blue-chips) while others are not (Uniswap v3 LP token).
In order to liquidate Blue-chips, liquidator will need to call startAuction on that NFT first, then the price will drop exponentially at the beginning and linearly later until it reaches a minimum price set on the collection. Liquidation will be based on this auction price instead of the original floor price. If the NFT owner successfully repaid the debt to bring ERC721HF above 1.5 (known as RecoveryHF), then the auctioned NFT cannot be liquidated anymore, and the auction needs to be closed manually to allow NFT transfer/withdraw.
function startAuction(
address user,
address collateralAsset,
uint256 collateralTokenId
) external;
function endAuction(
address user,
address collateralAsset,
uint256 collateralTokenId
) external;