Skip to content

fix: make liquidation criterion account for 'min_collateral_value_cen… - #189

Merged
tiamo merged 4 commits into
mainfrom
fix/make_liquidation_criterion_account_for_min_collateral_value_cents
Sep 2, 2026
Merged

tiamo merged 4 commits into
mainfrom
fix/make_liquidation_criterion_account_for_min_collateral_value_cents

Conversation

@khomiakmaxim

@khomiakmaxim khomiakmaxim commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Account for min_collateral_value_cents in liquidation eligibility

Summary

The liquidation eligibility check (Obligation::liquidate) previously compared debt against the raw close-LTV collateral value, ignoring min_collateral_value_cents. This left a gap: a position whose collateral had drifted below the configured minimum could remain non-liquidatable while still being economically too small for a liquidator to bother with.

The borrowing-capacity path already reserves N * min_collateral_value_cents (where N is the number of deposit positions), so the two sides were previously inconsistent.

Changes

  • obligation.rs: The eligibility check now deducts N * min_collateral_threshold from the close-LTV collateral value before comparing against debt, matching the borrowing-capacity formula. compute_collateral_value_scaled_w_close_ltvs now also returns the count of positions with non-zero close_ltv_bps.
  • market_manager/contract.rs: The market's admin signature is now required for queue_in_market_upgrade, next to the manager's admin signature. cancel_market_upgrade still needs only the manager's admin, so a queued upgrade stays easier to withdraw than to raise.
  • events.rs / processors.rs: ClaimCoverBadDebtResults now carries the resulting Option<Obligation> (None if the obligation was removed, Some otherwise).
  • tests/src/liquidate.rs: Added tests covering the following scenarios:
    • Sub-minimum-collateral position becomes liquidatable while close-LTV-solvent.
    • Deduction scales with position count (N=1 healthy vs N=2 liquidatable at equal total collateral/debt).
    • and others

Behavioral Impact

  • Positions with collateral below min_collateral_value_cents become liquidatable earlier (before closeLTV/liability factors insolvency).

@khomiakmaxim
khomiakmaxim marked this pull request as ready for review July 24, 2026 11:15
@khomiakmaxim
khomiakmaxim requested a review from Copilot July 24, 2026 11:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the market contract’s liquidation eligibility logic to reserve N * min_collateral_value_cents (where N is the number of collateral positions with non-zero close_ltv_bps) when checking whether an obligation is liquidatable, aligning liquidation eligibility with the existing borrowing-capacity reservation logic.

Changes:

  • Update Obligation::liquidate health check to subtract N * compute_min_collateral_threshold_scaled() from close-LTV-scaled collateral value before comparing against debt.
  • Extend compute_collateral_value_scaled_w_close_ltvs to also return the count of collateral positions with non-zero close_ltv_bps.
  • Emit ClaimCoverBadDebtResults with Option<Obligation> and add liquidation tests for sub-min-collateral and position-count scaling behavior.

Reviewed changes

Copilot reviewed 4 out of 17 changed files in this pull request and generated no comments.

File Description
contracts/market/src/obligation.rs Adjusts liquidation eligibility by reserving min-collateral value per close-LTV-eligible collateral position.
contracts/market/src/events.rs Extends ClaimCoverBadDebtResults event payload to include Option<Obligation>.
contracts/market/src/processors.rs Publishes updated ClaimCoverBadDebtResults event with None/Some(obligation) depending on whether the obligation was removed.
tests/src/liquidate.rs Adds helper to set min_collateral_value_cents and introduces tests validating earlier liquidation for sub-min collateral and scaling with position count.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@khomiakmaxim
khomiakmaxim force-pushed the fix/make_liquidation_criterion_account_for_min_collateral_value_cents branch from 275d1df to dfb34db Compare July 29, 2026 06:14
@tiamo
tiamo merged commit 1283dff into main Sep 2, 2026
5 checks passed
@tiamo
tiamo deleted the fix/make_liquidation_criterion_account_for_min_collateral_value_cents branch September 2, 2026 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants