pub struct MarginState {
pub total_weighted_collateral: i128,
pub total_weighted_liabilities: i128,
pub total_collateral: i128,
pub total_liabilities: i128,
}Expand description
Aggregated margin state across all positions.
Computed once from all positions, then used to derive per-market withdraw/borrow limits and credit usage.
Fields§
§total_weighted_collateral: i128Total weighted collateral in USDC base units (after IMF weight application).
total_weighted_liabilities: i128Total weighted liabilities in USDC base units (always non-negative, after IMF weight).
total_collateral: i128Total unweighted collateral in USDC base units (raw position value before weights).
total_liabilities: i128Total unweighted liabilities in USDC base units (always non-negative, before weights).
Implementations§
Source§impl MarginState
impl MarginState
Sourcepub fn calculate(positions: &[PositionData<'_>]) -> MathResult<Self>
pub fn calculate(positions: &[PositionData<'_>]) -> MathResult<Self>
Calculate margin state from a set of positions.
For each position: applies strict oracle pricing, computes USDC value, applies IMF-adjusted weights, and accumulates into collateral/liabilities.
Sourcepub fn free_collateral(&self) -> u64
pub fn free_collateral(&self) -> u64
Free collateral = weighted collateral - weighted liabilities, clamped to 0.
Sourcepub fn credit_usage_bps(&self) -> MathResult<u64>
pub fn credit_usage_bps(&self) -> MathResult<u64>
Credit usage in basis points (0 = no liabilities, 10_000 = 100%). Capped at 10_000 — an under-collateralized account is at 100% usage. Returns 0 if collateral is zero or negative.
Trait Implementations§
Source§impl Clone for MarginState
impl Clone for MarginState
Source§fn clone(&self) -> MarginState
fn clone(&self) -> MarginState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more