risk-metrics
Risk metrics and calculations for DeFi applications.
Features
- Health factor calculations
- Liquidation price and threshold
- Position sizing and LTV
- Pool utilization metrics
no_stdcompatible- Deterministic results
Installation
[]
= "0.1"
Quick Start
use ;
let collateral = from;
let debt = from;
let threshold = new; // 80%
// Health factor: (collateral * threshold) / debt
let hf = health_factor?; // 1.6
// Liquidation price
let liq = liquidation_price?; // $1,250 per ETH
Functions
Health
health_factor(collateral, debt, threshold)- Calculate position healthis_healthy(collateral, debt, threshold)- Check if position is safecollateral_ratio(collateral, debt)- Raw collateralization ratio
Liquidation
liquidation_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 debt
Position
loan_to_value(debt, collateral)- LTV ratioutilization_rate(borrows, liquidity)- Pool utilizationavailable_liquidity(total_liquidity, borrows)- Remaining liquidity
DeFi Protocol Compatibility
Designed for integration with lending protocols:
- Aave-style health factor calculations
- Compound-style collateral ratios
- MakerDAO-style liquidation thresholds
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.