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
Parameters
users
: An array of user addresses that need to be liquidated.maxBorrowParts
: A one-to-one mapping tousers
. It contains the maximum (partial) borrow amounts (to liquidate) for each respective user.to
: The address of the receiver in open liquidations if theswapper
is zero.swapper
: An instance of theISwapperV2
interface to perform the actual swap operation.swapperData
: Additional data to be passed to the swapper.
How Liquidation Works
The function begins by updating the exchange rate and calling the
accrue
function.It initializes variables to store the total collateral shares, borrow amounts, and borrow parts.
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.
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.
It emits events for removing collateral, repaying loans, and liquidation.
The function keeps track of the totals for collateral shares, borrow amounts, and borrow parts.
After processing all users, the function checks if at least one user was insolvent, otherwise, it reverts.
The function updates the total borrow elastic and base values, as well as the total collateral shares.
It calculates a distribution amount to share with sSpell holders as a percentage of the liquidation amount.
The function converts the total borrow amount to borrow shares.
The bentoBox transfers the collateral to the
to
address.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.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