pub struct HealthCache { /* private fields */ }

Implementations

Sum of only the positive health components (assets) and sum of absolute values of all negative health components (liabs, always >= 0)

Changes the cached user account token balance.

Changes the cached user account token and serum balances.

WARNING: You must also call recompute_token_weights() after all bank deposit/withdraw changes!

Phase1 is spot/perp order cancellation and spot settlement since neither of these come at a cost to the liqee

Phase2 is for:

  • token-token liquidation
  • liquidation of perp base positions (an open fill isn’t liquidatable, but it changes the base position, so need to wait for it to be processed…)
  • bringing positive trusted perp pnl into the spot realm

Phase3 is bankruptcy:

  • token bankruptcy
  • perp bankruptcy

Compute the health when it comes to settling perp pnl

Examples:

  • An account may have maint_health < 0, but settling perp pnl could still be allowed. (+100 USDC health, -50 USDT health, -50 perp health -> allow settling 50 health worth)
  • Positive health from trusted pnl markets counts
  • If overall health is 0 with two trusted perp pnl < 0, settling may still be possible. (+100 USDC health, -150 perp1 health, -150 perp2 health -> allow settling 100 health worth)
  • Positive trusted perp pnl can enable settling. (+100 trusted perp1 health, -100 perp2 health -> allow settling of 100 health worth)

The health ratio is

  • 0 if health is 0 - meaning assets = liabs
  • 100 if there’s 2x as many assets as liabs
  • 200 if there’s 3x as many assets as liabs
  • MAX if liabs = 0

Maybe talking about the collateralization ratio assets/liabs is more intuitive?

How many source native tokens may be swapped for target tokens while staying above the min_ratio health ratio.

price: The amount of target native you receive for one source native. So if we swap BTC -> SOL and they’re at ui prices of $20000 and $40, that means price should be 500000 native_SOL for a native_BTC. Because 1 BTC gives you 500 SOL so 1e6 native_BTC gives you 500e9 native_SOL.

Positions for the source and deposit token index must already exist in the account.

NOTE: keep getMaxSourceForTokenSwap in ts/client in sync with changes here

NOTE: keep getMaxSourceForTokenSwap in ts/client in sync with changes here

Trait Implementations

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes. Read more
Deserialize this instance from a slice of bytes.
Serialize this instance into a vector of bytes.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Casts the value.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Casts the value.
Casts the value.
Casts the value.

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Performs the conversion.
Performs the conversion.
Casts the value.
Casts the value.
The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Should always be Self
Casts the value.
Casts the value.
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Casts the value.
Casts the value.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Casts the value.
Casts the value.