Wepiggy liquidation
UpdatedIn the WePiggy lending protocol's published master implementation, liquidation lets another account repay debt in exchange for the borrower's collateral pTokens. The borrower must have a positive shortfall, meaning that oracle-valued debt exceeds collateral value after applying market collateral factors. The close factor caps repayment in the selected debt market, and the remaining contract checks must pass before collateral transfers.
When does an account cross the liquidation threshold?
The Comptroller's liquidation eligibility check requires a strictly positive shortfall. It values pToken balances in the account's entered markets using their underlying exchange rates, oracle prices and collateral factors, then compares the adjusted collateral total with oracle-valued borrow balances. Equal totals produce zero shortfall and do not permit liquidation.
getAccountLiquidity
returns an error code as well as available account liquidity and shortfall. Read the error code before treating either amount as valid. Liquidation first accrues interest in the selected debt and collateral markets; the account-wide calculation uses stored snapshots for the other entered markets.
How much debt can one liquidation repay?
The maximum requested repayment is
close factor * borrower debt in the selected borrowed market
, expressed in units of that market's underlying asset with integer truncation in the contract calculation. The debt balance includes the interest accrued before the eligibility check. Other borrowed markets have separate debt balances.
Both the close factor and liquidation incentive can be changed by the Comptroller owner. Their active values belong to the selected deployment; validation limits in the source code do not establish a live percentage.
What collateral does the liquidator receive?
The seizure calculation values actual repayment at the borrowed asset's oracle price, applies the configured liquidation incentive and converts that value into collateral pTokens using the collateral asset's oracle price and pToken exchange rate. Both prices must be nonzero. If a token transfer fee reduces the amount received by the debt market, debt reduction and collateral seizure use that actual received amount.
A successful seizure deducts pTokens from the borrower and credits them to the liquidator. These tokens represent a claim on the collateral market's underlying asset. Redeeming that claim is a separate operation that must pass redemption checks and requires available underlying cash in the collateral market.
Which checks can block an otherwise eligible liquidation?
For the published master liquidation path, check that:
- Both markets are listed under the same Comptroller on the selected network, and collateral seizure is not paused.
- The liquidator is a different address from the borrower and can transfer in the selected debt asset.
- The requested repayment is positive, stays within the close-factor limit and does not use the repay-all sentinel.
- Interest accrual succeeds in both selected markets and both are fresh for the execution block.
- The borrower has enough pTokens in the chosen collateral market to cover the calculated seizure.
Can repayment or added collateral prevent liquidation?
Successful repayment removes the actual amount received from the accrued debt balance. Additional supplied assets can raise the collateral contribution only when their market is entered by the account, has a positive collateral factor and has a usable oracle price. The supply must also pass that market's mint rules, including any pause or active cap. Changes that complete before liquidation's eligibility check affect the state that it evaluates; the resulting account totals decide whether a shortfall remains.
How can a completed liquidation be reconciled?
The
PToken liquidation path
emits
LiquidateBorrow
after repayment and successful seizure. It records the liquidator, borrower, actual underlying repayment, address of the collateral market and seized pToken count.
RepayBorrow
records the reduced debt, while the collateral market's
Transfer
event records the pTokens moved.
Protocol rejection can return an error code without a completed liquidation, so transaction inclusion alone is insufficient evidence of seizure. Match the recorded repayment to the debt change and the seized pToken count to the collateral balance change, allowing for other activity and subsequent interest. Then recalculate the shortfall; one liquidation can leave debt and a remaining shortfall.