| Crates.io | risk-metrics |
| lib.rs | risk-metrics |
| version | 0.1.0-alpha.2 |
| created_at | 2026-01-24 12:14:16.916484+00 |
| updated_at | 2026-01-25 18:01:04.771207+00 |
| description | Risk metrics and calculations for DeFi applications |
| homepage | |
| repository | https://github.com/dijkstra-keystone/keystone |
| max_upload_size | |
| id | 2066588 |
| size | 45,784 |
Risk metrics and calculations for DeFi applications.
no_std compatible[dependencies]
risk-metrics = "0.1"
use risk_metrics::{health_factor, liquidation_price, Decimal};
let collateral = Decimal::from(10000i64);
let debt = Decimal::from(5000i64);
let threshold = Decimal::new(80, 2); // 80%
// Health factor: (collateral * threshold) / debt
let hf = health_factor(collateral, debt, threshold)?; // 1.6
// Liquidation price
let liq = liquidation_price(
Decimal::from(5i64), // 5 ETH collateral
debt,
threshold,
)?; // $1,250 per ETH
health_factor(collateral, debt, threshold) - Calculate position healthis_healthy(collateral, debt, threshold) - Check if position is safecollateral_ratio(collateral, debt) - Raw collateralization ratioliquidation_price(collateral_amount, debt, threshold) - Price at which liquidation occursliquidation_threshold(collateral, debt, health_factor) - Threshold for given health factormax_borrowable(collateral, threshold, min_health_factor) - Maximum safe debtloan_to_value(debt, collateral) - LTV ratioutilization_rate(borrows, liquidity) - Pool utilizationavailable_liquidity(total_liquidity, borrows) - Remaining liquidityDesigned for integration with lending protocols:
Licensed under either of Apache License, Version 2.0 or MIT license at your option.