Skip to content

[PR #33] Health factor is binary placeholder — scanner cannot rank liquidation urgency #98

@obchain

Description

@obchain

PR: #33 (feat/08-venus-adapter)
File: crates/charon-protocols/src/venus.rs
Lines: 299-308

Problem: Health factor hardcoded to 0 when shortfall > 0 and 2e18 otherwise. Inline comment acknowledges placeholder and defers to follow-up. But getAccountLiquidity already returns (errorCode, liquidity, shortfall) at line 234 — both liquidity and shortfall available with no additional RPC. Real ratio computable immediately.

Impact: Scanner cannot distinguish a 0.01% underwater position from a 50% underwater one. All underwater accounts receive health_factor=0, treated identically. Defeats profit ranking: bot may spend gas on near-zero-shortfall account while high-shortfall position (larger bonus) goes unliquidated. PRD requires Position.health_factor be a 1e18-scaled ratio, not a sentinel.

Fix: Compute from values in scope:

let one_e18 = U256::from(10u64).pow(U256::from(18u64));
let health_factor = if shortfall > U256::ZERO {
    one_e18.saturating_sub(
        shortfall.saturating_mul(one_e18)
        / (liq._1 + shortfall + U256::from(1u64))
    )
} else {
    one_e18 + liq._1.saturating_mul(one_e18) / (liq._1 + U256::from(1u64))
};

Open tracking issue for finer-grained oracle-weighted HF if wanted; remove sentinel immediately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    layer:rustRust crates (core / scanner / protocols / executor / cli)pr-reviewFindings from PR review processpriority:p1-coreCore MVP scope

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions