pub struct MarginState {
pub total_weighted_collateral: i128,
pub total_weighted_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.
total_weighted_liabilities: i128Total weighted liabilities in USDC base units (always non-negative).
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
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MarginState
impl Debug for MarginState
impl Copy for MarginState
Auto Trait Implementations§
impl Freeze for MarginState
impl RefUnwindSafe for MarginState
impl Send for MarginState
impl Sync for MarginState
impl Unpin for MarginState
impl UnsafeUnpin for MarginState
impl UnwindSafe for MarginState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more