Calculate Health Factor
calculate_health_factorCalculates a lending health factor from position inputs, with no wallet or on-chain lookup required. Give it collateral (one or more assets, each with its own liquidation threshold) and the debt, and it returns the health factor, the blended threshold, the collateral drop that would trigger liquidation, and the collateral value at which liquidation begins. Optionally simulates a collateral price drop and a change in the borrowed asset's price. Formula: HF = (Σ collateral value × liquidation threshold) ÷ debt. Works for Aave, Morpho, Spark, Kamino and any protocol using the standard formula. Use this when asked: "What is my health factor if I supply 5 ETH at 80% and borrow $6,500?", "How far can ETH fall before I get liquidated?", "What happens to my HF if I add collateral or repay?", "Work out the health factor for this position".
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| debt_usd | Yes | Total borrowed value in USD. Zero means no debt, so no liquidation risk. | |
| collateral | Yes | Collateral legs. Pass one entry per supplied asset; each keeps its own liquidation threshold and the blended figure is derived. | |
| debt_change_pct | No | Optional: simulate the borrowed asset's price moving by this percentage. Positive grows the debt and pushes HF down (borrowing a volatile asset); 0 or omitted is stablecoin debt. | |
| collateral_drop_pct | No | Optional: simulate the collateral falling by this percentage, e.g. 30 for a 30% crash. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| debtUsd | Yes | Total debt used in the calculation | |
| riskLevel | Yes | Risk tier, or null when there is no debt | |
| simulated | No | Present only when a simulation was requested | |
| healthFactor | Yes | Health factor, or null when there is no debt — with nothing borrowed there is no liquidation point | |
| collateralValueUsd | Yes | Total collateral value across every leg | |
| blendedThresholdPct | Yes | Weighted liquidation threshold across all collateral legs | |
| dropToLiquidationPct | Yes | How far the collateral can fall before the health factor reaches 1.0 | |
| riskAdjustedCollateralUsd | Yes | Collateral value after each leg is discounted by its own liquidation threshold | |
| liquidationAtCollateralValueUsd | Yes | Total collateral value at which liquidation begins, or null when there is no debt |