Liquidations

The liquidate function is a critical component of the Abracadabra cauldron. This function allows liquidators to handle the liquidation of users' balances when the users' amount of collateral is too low.

Function Signature

function liquidate(
    address[] memory users,
    uint256[] memory maxBorrowParts,
    address to,
    ISwapperV2 swapper,
    bytes memory swapperData
) public;

Parameters

  • users: An array of user addresses that need to be liquidated.

  • maxBorrowParts: A one-to-one mapping to users. It contains the maximum (partial) borrow amounts (to liquidate) for each respective user.

  • to: The address of the receiver in open liquidations if the swapper is zero.

  • swapper: An instance of the ISwapperV2 interface to perform the actual swap operation.

  • swapperData: Additional data to be passed to the swapper.

How Liquidation Works

  1. The function begins by updating the exchange rate and calling the accrue function.

  2. It initializes variables to store the total collateral shares, borrow amounts, and borrow parts.

  3. The function iterates through each user and checks if they are solvent, i.e., their collateral is sufficient. If not, it proceeds with the liquidation process.

  4. For each insolvent user, the function calculates their borrow part, borrow amount, and collateral share. It updates the user's borrow part and collateral share accordingly.

  5. It emits events for removing collateral, repaying loans, and liquidation.

  6. The function keeps track of the totals for collateral shares, borrow amounts, and borrow parts.

  7. After processing all users, the function checks if at least one user was insolvent, otherwise, it reverts.

  8. The function updates the total borrow elastic and base values, as well as the total collateral shares.

  9. It calculates a distribution amount to share with sSpell holders as a percentage of the liquidation amount.

  10. The function converts the total borrow amount to borrow shares.

  11. The bentoBox transfers the collateral to the to address.

  12. If a swapper is provided, the function calls the swap function of the swapper to perform the actual swap operation, providing the collateral and borrow shares.

  13. The bentoBox transfers the magicInternetMoney (borrow asset) to the msg.sender (liquidator).

Events

  • LogRemoveCollateral: Emitted when collateral is removed from the user's account.

  • LogRepay: Emitted when a user's borrow is repaid.

  • LogLiquidation: Emitted when a liquidation occurs.

\

Last updated