bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 53쪽 중 21쪽
--------------------------------------------------------------------------------------------------------- |
| **`PublicLiquidator`** | **Anyone** — no role gate | **Your own capital**; you approve the loan token and receive the seized collateral | **Third-party liquidators. This is the contract to integrate against.** |
| `Liquidator` | `BOT` role only | Protocol-held funds | Lista's internal keeper. Not callable by external parties. |
| `BrokerLiquidator` | `BOT` role only | Protocol-held funds | Fixed-term / broker markets, where health accounting sits at the broker. Not callable by external parties. |
Deployed addresses: [BSC Core](/for-developer/lista-lending/smart-contract/smart-contract-bsc-core) for `Liquidator` and `PublicLiquidator`, [BSC Lending Brokers](/for-developer/lista-lending/smart-contract/smart-contract-bsc-brokers) for `BrokerLiquidator`, and [Ethereum](/for-developer/lista-lending/smart-contract/smart-contract-ethereum) for all three.
***
## Eligibility: which positions you can actually liquidate
Every `PublicLiquidator` liquidation path runs the same internal eligibility check. On the flash paths it runs *after* the pair / smart-provider whitelist checks, and all of them revert with the same `NotWhitelisted()` selector, so the selector alone will not tell you which one failed:
```solidity
function isLiquidatable(bytes32 id, address borrower) internal view returns (bool) {
return
IMoolah(MOOLAH).isLiquidationWhitelist(id, address(0)) || // 1. cheap probe — NOT proof the market is open; see below
marketWhitelist[id] || // 2. market opened on PublicLiquidator
marketUserWhitelist[id][borrower]; // 3. this position opened on PublicLiquidator
}
```
A position is reachable if **any** of three conditions holds:
1. **The market is open at the Moolah level.** `Moolah._checkLiquidationWhiteList` returns `liquidationWhitelist[id].length() == 0 || contains(account)`, so an *empty* per-market whitelist means the market is open to every caller. `isLiquidationWhitelist(id, address(0))` is the cheap probe `PublicLiquidator` itself uses, but it does **not** prove the market is open: it also returns `true` for a gated market that happens to have `address(0)` in its whitelist, and `batchToggleLiquidationWhitelist` has no zero-address guard to rule that out. In that case `PublicLiquidator` passes its own gate and Moolah then rejects the call, because the caller Moolah checks is `PublicLiquidator`, not `address(0)`.
Answer these two separately — one does not imply the other:
* **Is the market open to anyone?** `getLiquidationWhitelist(id).length == 0`. That is the only definitive test.
* **Can `PublicLiquidator` reach this market?** `isLiquidationWhitelist(id, <PublicLiquidator address>)`.
Query both rather than assuming — an open market is the common case, not a universal one.
2. **The market has been opened on `PublicLiquidator`** by the `BOT` role (`marketWhitelist[id]`). This is how a market that *is* gated at the Moolah level can still be routed through the public path.
3. **This specific borrower has been opened** by the `BOT` role (`marketUserWhitelist[id][borrower]`).
> On a market that is gated at the Moolah level, an under-water position must first be surfaced through condition 2 or 3. The gating is *not* a health check: a position failing `isLiquidatable` reverts with `NotWhitelisted()` even when it is deeply under water. Select the feed that matches the gate. `/api/liquidation/zone/list` returns the borrower **whitelist**, so it finds candidates on *gated* markets and may be empty for open markets. For open markets use [`/api/moolah/redPositions`](/for-developer/services/lending-api/position-liquidation-emission), which takes a single market `id` — enumerate markets from `/api/moolah/allMarkets` and fan out.
Both `setMarketWhitelist` and `setMarketUserWhitelist` refuse to run on a market that is already open at the Moolah level, and `setMarketUserWhitelist` additionally refuses when the market has already been opened on `PublicLiquidator` itself. These are **preconditions checked at set time only** — Moolah-level state can change afterwards (a `MANAGER` can empty `liquidationWhitelist[id]` later), so do not assume the two mechanisms stay mutually exclusive.
After a successful liquidation, `postLiquidate` removes the borrower from `marketUserWhitelist` if the position has become healthy again. A partial liquidation that leaves the position under water keeps it open — but see the sizing constraint below: not every partial size is permitted.
***
## Entry points
Five liquidation entry points. Pick by (a) whether you bring your own loan-token capital or flash-swap the collateral, and (b) whether the collateral is a plain ERC-20 or a **smart collateral** LP token.
### Self-funded
```solidity
function liquidate(bytes32 id, address borrower, uint256 seizedAssets, uint256 repaidShares) external;
```
The main path. Pulls the required loan token from you, calls `Moolah.liquidate`, and transfers the seized collateral to you. Thin wrapper over `liquidateWithCollTransferOpt(..., doTransferColl: true)`.
```solidity
function liquidateWithCollTransferOpt(
bytes32 id, address borrower, uint256 seizedAssets, uint256 repaidShares, bool doTransferColl
) public;
```
Same, but `doTransferColl: false` leaves the seized collateral inside `PublicLiquidator`, credited to you in `lpCollaterals[msg.sender][collateralToken]`, to be unwound later with `redeemSmartCollateral`. **Only pass `false` for smart-collateral LP tokens** — for a plain ERC-20 collateral there is no redeem path and the tokens are stranded in the contract.
```solidity
function liquidateSmartCollateral(
bytes32 id, address borrower, address smartProvider,
uint256 seizedAssets, uint256 repaidShares, bytes memory payload
) external returns (uint256, uint256);
```
Returns `(actualSeizedAssets, repaidAssets)`, both straight from `Moolah.liquidate`. Self-funded liquidation of a smart-collateral market that redeems the LP in the same transaction. `smartProvider` must be registered in `smartProviders` and its `TOKEN()` must equal the market's collateral token. `payload` is `abi.encode(minToken0Amt, minToken1Amt)` — your slippage bound on the LP redeem. **On `flashLiquidateSmartCollateral` these values do double duty:** for a leg whose token is native BNB, the contract forwards the min amount as the swap call's exact `msg.value`. Setting a conservative floor there underfunds the swap rather than protecting you, so for a native-BNB leg the value must be the amount you intend to send. Both underlying tokens are sent to you directly (native BNB is transferred as value, not wrapped).
### Flash-swap (no loan-token capital required)
```solidity
function flashLiquidate(
bytes32 id, address borrower, uint256 seizedAssets, address pair, bytes calldata swapCollateralData
) external;
```
Uses Moolah's `onMoolahLiquidate` callback to swap the seized collateral into the loan token *before* the repayment is pulled, so you need no loan-token balance — only enough gas. `swapCollateralData` is raw calldata low-level-called against `pair`; obtain it from an aggregator (1inch, etc.) **with slippage already applied**. Your profit is the loan-token surplus, transferred to you at the end.
> **The swap must pay out to `PublicLiquidator`, not to you.** The callback measures the contract's own loan-token balance before and after the swap and approves Moolah out of that balance. Aggregator calldata built with your own address as the recipient will leave the contract unable to repay and the transaction reverts. Set the recipient to the `PublicLiquidator` address on **every** leg — both token legs, for the smart-collateral variant.
```solidity
function flashLiquidateSmartCollateral(
bytes32 id, address borrower, address smartProvider, uint256 seizedAssets,
address token0Pair, address token1Pair,
bytes calldata swapToken0Data, bytes calldata swapToken1Data, bytes memory payload
) external returns (uint256, uint256);
```
The smart-collateral variant: redeems the LP inside the callback, then swaps each leg to the loan token. Any leftover of either underlying is returned to you. Returns `(actualSeizedAssets, repayAmount)` — note the second value here is the locally pre-computed `loanTokenAmountNeed`, not Moolah's returned repaid amount as in `liquidateSmartCollateral`.
> **Every pair must be whitelisted.** Both flash paths require `pairWhitelist[pair]`, which only the `MANAGER` role can set. On `flashLiquidateSmartCollateral` **both** `token0Pair` and `token1Pair` must be whitelisted unconditionally — including a leg that is never actually swapped, e.g. when that token already is the loan token — an arbitrary DEX router will revert with `NotWhitelisted()`. Read `pairWhitelist(address)` before building the route. Self-funded paths have no such constraint, so if the venue you want is not whitelisted, use `liquidate` and do the swap yourself afterwards.
### Unwinding deferred collateral
```solidity
function redeemSmartCollateral(
address smartProvider, uint256 lpAmount, uint256 minToken0Amt, uint256 minToken1Amt
) external returns (uint256, uint256);
```
Returns `(token0Amount, token1Amount)`.
Redeems LP collateral you previously accumulated via `doTransferColl: false`. Reverts with `"insufficient lp collateral"` if `lpAmount` exceeds your tracked balance.
***
## Sizing a liquidation
**Exactly one of `seizedAssets` / `repaidShares` must be non-zero.** The other is derived:
* **`seizedAssets > 0`** — "buy this much collateral." The required repayment is computed from the oracle price and the liquidation incentive factor.
* **`repaidShares > 0`** — "close this much debt." Pass the borrower's full `borrowShares` to close the position entirely. The Liquidation Zone front end uses this branch for a full close-out and the `seizedAssets` branch for a partial buy. This only succeeds when the resulting seizure does not exceed the borrower's remaining collateral — `Moolah.liquidate` does `position.collateral -= seizedAssets`, which underflows and reverts on a deeply under-water position. Size by `seizedAssets` in that case.
The incentive factor is the same formula as in Moolah core:
```
liquidationIncentiveFactor = min(
MAX_LIQUIDATION_INCENTIVE_FACTOR, // 1.15e18
WAD / (WAD - LIQUIDATION_CURSOR * (WAD - lltv)) // LIQUIDATION_CURSOR = 0.3e18
)
```
For standard (non-broker) markets, `PublicLiquidator` exposes a public view that reproduces Moolah's liquidation sizing:
```solidity
function loanTokenAmountNeed(bytes32 id, uint256 seizedAssets, uint256 repaidShares)
public view returns (uint256);
```
**Approve at least this amount of the loan token to `PublicLiquidator` before calling a self-funded path.** Any unused loan token is refunded in the same transaction. The quoted amount therefore covers the expected repayment; a small buffer may be needed where the quote can change before execution.
> **Do not use this quote on a broker market.** `loanTokenAmountNeed` prices the collateral with `Moolah.getPrice(marketParams)`, which is the plain market price (`user = address(0)`). `Moolah.liquidate` instead prices with `_getPrice(marketParams, borrower)`, and on a market with a broker that routes to the broker and can deviate from the market price according to the borrower's position. The broker's collateral price is the market price minus a deduction, so it is never higher — the quote therefore **over**-states the repayment. `PublicLiquidator` pulls the larger amount and refunds the surplus in the same transaction, so the call succeeds, but you must hold the inflated figure to make it. On broker markets, derive the repayment from the broker's own pricing — `peek(token, user)` and `getUserTotalDebt(user)`, see [Broker Reference](/for-developer/lista-lending/broker-reference).
Sizing a *partial* liquidation carries one more constraint:
**A residual below `minLoan` must be healthy.** After the repayment, Moolah requires `_isHealthyAfterLiquidate`: if the borrower still has both debt and collateral and the remaining borrow assets fall **below** `minLoan(marketParams)`, the position must be healthy or the whole transaction reverts Moolah's `"position is unhealthy"` (see the Reverts table below). So you cannot leave a small unhealthy dust position behind: either size the liquidation to restore health, keep the residual at or above `minLoan`, or clear the debt or collateral entirely.
Call it **after** interest has been accrued for the market, or accept that the quote drifts: every entry point calls `Moolah.accrueInterest(params)` before computing the amount, and `accrueInterest` is permissionless, so a fresh quote is best obtained by simulating against current state rather than reading a value cached from an earlier block.
***
## Reverts
| Error | Cause |
| ------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `NotWhitelisted()` | `isLiquidatable` failed (position not open to the public path), or `pair` / `smartProvider` not whitelisted. This one selector covers **both** eligibility and whitelist failures — check `isLiquidationWhitelist` / `marketWhitelist` / `marketUserWhitelist` and `pairWhitelist` separately to tell them apart. |
| `NoProfit()` | Self-funded paths: the contract's collateral balance did not strictly increase. Flash paths: the swap output did not **exceed** the repayment — exact break-even reverts too, since a strictly positive loan-token surplus is required. Widen slippage, reduce `seizedAssets`, or pick a deeper venue. |
| `SwapFailed()` | The low-level call to `pair` reverted. Stale aggregator calldata is the usual cause. |
| `"Invalid smart provider"` | `ISmartProvider(smartProvider).TOKEN() != marketParams.collateralToken`. |
| Moolah `"position is healthy"` | The position was healthy by the time your transaction landed — for example, because someone repaid or the price moved. Re-check immediately before submitting and expect execution races. |
| Moolah `"inconsistent input"` | `exactlyOneZero(seizedAssets, repaidShares)` failed. Note the flash paths hardcode `repaidShares = 0`, so calling one with `seizedAssets = 0` reverts here. |
| Moolah `"position is unhealthy"` | The residual position was left with debt and collateral, borrow assets below `minLoan`, and still unhealthy. Size the liquidation differently — see above. |
| Moolah `"not liquidation whitelist"` | `PublicLiquidator` itself is not on the market's Moolah-level whitelist. Can surface when a market was gated after `marketWhitelist[id]` was set. |
Four entry points carry `nonReentrant` directly; `liquidate` inherits it by delegating to `liquidateWithCollTransferOpt`, which is `public nonReentrant`. `redeemSmartCollateral` is `nonReentrant` too.
***
## Event
`PublicLiquidator` emits `Liquidated(id, borrower, seizedAssets, repaidAssets, repaidShares, liquidator)` — `id` and `borrower` indexed — in addition to Moolah's own `Liquidate` event (see [Events & Callbacks](/for-developer/lista-lending/events-and-callbacks)). Index on this one to attribute liquidations to the public path specifically — but read the **settled** amounts from Moolah's `Liquidate`: the fields here echo the caller's *inputs*, so `repaidShares` is `0` on both flash paths and on any `seizedAssets > 0` call even though Moolah burned a non-zero share amount, and `seizedAssets` is likewise the requested figure rather than Moolah's returned value. `repaidAssets` is `PublicLiquidator`'s own `loanTokenAmountNeed` quote, priced at the plain market price, so on a broker market it diverges from what Moolah actually settled. Settled liquidations are also served by [`/api/liquidation/zone/history`](/for-developer/services/lending-api/position-liquidation-emission).
***
## Reference flow
1. **Poll candidates.** `GET /api/liquidation/zone/list` for whitelisted / flagged positions, or `GET /api/liquidation/zone/closeToLiquidate` for positions approaching the threshold (safety factor `< 1.5`). The [Moolah liquidatable endpoint](/for-developer/services/lending-api/position-liquidation-emission) returns `borrowShares`, `totalBorrowAssets`, and `totalBorrowShares` so you can recompute exact current debt from shares.
2. **Re-verify on chain.** API data is indexed and can lag. Confirm reachability the way the eligibility section describes — `getLiquidationWhitelist(id).length == 0` for an open market, or `isLiquidationWhitelist(id, <PublicLiquidator>)` plus `marketWhitelist(id)` / `marketUserWhitelist(id, borrower)` for a gated one — and that the position is still unhealthy at the live oracle price — Moolah re-checks health at execution time and will revert otherwise.
3. **Size it.** Choose `seizedAssets` or `repaidShares`, then call `loanTokenAmountNeed` for the repayment.
4. **Approve** that amount of the loan token to `PublicLiquidator` (self-funded paths only).
5. **Execute.** `liquidate` for plain collateral; `liquidateSmartCollateral` for smart collateral; the `flash*` variants if you would rather not hold the loan token and the venue is whitelisted.
6. **Settle.** Seized collateral arrives in the same transaction unless you passed `doTransferColl: false`, in which case unwind later with `redeemSmartCollateral`.
# Vault Reference
`MoolahVault` is the ERC-4626 layer over Moolah: suppliers deposit one loan asset, a curator allocates it across markets, and shares accrue the blended yield. Call a vault **directly** — from Solidity, or from any stack that cannot use the [SDK](/for-developer/lista-lending/sdk) — with the surface below.
For deployed vault addresses see [Smart Contract](/for-developer/lista-lending/smart-contract). For the market-level contract see [Contract & Interface Reference](/for-developer/lista-lending/contract-reference); for the read-side REST API see [Vault API](/for-developer/services/lending-api/vault).
***
## Before you deposit: three things that can block you
These are the gates that make a deposit fail for reasons a plain ERC-4626 client would not expect.
**1. The vault may have a whitelist.** `deposit` and `mint` both require `isWhiteList(receiver)`. The check is `whiteList.length() == 0 || whiteList.contains(account)` — an **empty list means open to everyone**, which is the common case. Once any address is added, only listed receivers can be minted to. Read it before assuming:
```solidity
function isWhiteList(address account) external view returns (bool);
function getWhiteList() external view returns (address[] memory);
```
A blocked deposit reverts `NotWhiteList()`. Note the gate is on the **receiver**, not the caller, so depositing on someone else's behalf is constrained by *their* status.
**2. Capacity is finite and is not `totalAssets`.** Each market in the supply queue has a cap, and the vault can only absorb what the queue can still take. `maxDeposit` walks the supply queue and sums the remaining room:
```solidity
function maxDeposit(address) external view returns (uint256);
function maxMint(address) external view returns (uint256);
```
Call `maxDeposit` before sizing a deposit; exceeding it reverts `AllCapsReached()`. Both `maxDeposit` and `maxMint` can **over-report** when the supply queue contains the same market twice — that market's headroom gets counted once per entry. Treat either as an upper bound rather than a promise, and leave margin: a deposit sized at exactly `maxDeposit` can still revert.
**3. Withdrawal is bounded by reachable liquidity, not by your balance.** A vault withdraw pulls from markets in withdraw-queue order, and a market whose liquidity is fully borrowed cannot be pulled from. So a holder's shares are not always redeemable in full at that moment:
```solidity
fun프로젝트로 돌아가기