Before this, liquidate() paid every liquidator the exact same flat
liquidationBonusBps regardless of how underwater a position was -- no
extra incentive to rush the positions most likely to become unrecoverable
bad debt over barely-underwater ones. Added an immutable
liquidationBonusMaxBps + _dynamicLiquidationBonusBps(hf): the bonus
linearly interpolates from the base rate (healthFactor == 1.0) up to the
max (healthFactor <= 0.5), clamped at both ends. Setting max == base
disables the curve entirely (flat, the exact pre-existing behavior) --
every pre-existing liquidation test passes unchanged under that default.
Exposed liquidationBonusBpsFor(user) for bots/dashboards to read the real
current rate without simulating liquidate().
Found and fixed a real bug within this same pass: liquidate()'s forward
seize calculation picked up the new dynamic bonus, but the same
function's collateral-exhausted branch still back-calculated
coveredValueUsd off the old flat rate -- the two would have silently
diverged for exactly the case most likely to hit that branch.
Verified two ways: forge test adds 5 regression tests (constructor
validation, flat-curve backward compatibility, exact closed-form
interpolation/clamp-to-max math, a real liquidate() seizing the predicted
amount) -- 52 -> 57/57 pass, zero regressions. Live on the persistent
self-hosted demo chain (130.61.180.42:8647): deployed a separate vault,
read liquidationBonusBpsFor at three real price points (500/757/2000bps
exactly matching the closed-form math), then executed a real liquidate()
tx seizing exactly 400 WQIE at the clamped 20% max bonus.
Redeployed the live public demo (DeployDemo.s.sol now passes
liquidationBonusMaxBps too) and updated the 5 affected
NEXT_PUBLIC_QIE_FORGE_* Vercel address env vars -- in the process found
and fixed a real latent bug where `echo | vercel env add` had been baking
a trailing newline into every one of those address values, breaking
vault-position reads until re-added with `printf '%s'`. Re-verified /,
/swap, /pool, /vault all 200, /api/quote and /api/vault-position match
every prior documented demo number exactly, plus the new
liquidationBonusBps field. Re-ran scripts/liquidation-bot-demo.sh
end-to-end against the updated deploy script: real on-chain bonus came
back as 5.60% (above the 5% floor, correctly reflecting a barely-
underwater 0.98 health factor), not the old flat 5%.
Surfaced the new per-user bonus on the frontend's vault-position API and
VaultCard (a real risk-dashboard improvement: "Liquidation bonus right
now" next to health factor, shown once a position is actually
underwater).
npm test (33/33), next build, npx eslint . all clean.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>