Struct mango_v4::health::HealthCache
source · [−]pub struct HealthCache { /* private fields */ }
Implementations
sourceimpl HealthCache
impl HealthCache
pub fn health(&self, health_type: HealthType) -> I80F48
sourcepub fn health_assets_and_liabs(
&self,
health_type: HealthType
) -> (I80F48, I80F48)
pub fn health_assets_and_liabs(
&self,
health_type: HealthType
) -> (I80F48, I80F48)
Sum of only the positive health components (assets) and sum of absolute values of all negative health components (liabs, always >= 0)
pub fn token_info(&self, token_index: TokenIndex) -> Result<&TokenInfo>
pub fn perp_info(&self, perp_market_index: PerpMarketIndex) -> Result<&PerpInfo>
sourcepub fn adjust_token_balance(&mut self, bank: &Bank, change: I80F48) -> Result<()>
pub fn adjust_token_balance(&mut self, bank: &Bank, change: I80F48) -> Result<()>
Changes the cached user account token balance.
sourcepub fn adjust_serum3_reserved(
&mut self,
market_index: Serum3MarketIndex,
base_token_index: TokenIndex,
reserved_base_change: I80F48,
free_base_change: I80F48,
quote_token_index: TokenIndex,
reserved_quote_change: I80F48,
free_quote_change: I80F48
) -> Result<()>
pub fn adjust_serum3_reserved(
&mut self,
market_index: Serum3MarketIndex,
base_token_index: TokenIndex,
reserved_base_change: I80F48,
free_base_change: I80F48,
quote_token_index: TokenIndex,
reserved_quote_change: I80F48,
free_quote_change: I80F48
) -> Result<()>
Changes the cached user account token and serum balances.
WARNING: You must also call recompute_token_weights() after all bank deposit/withdraw changes!
pub fn recompute_perp_info(
&mut self,
perp_position: &PerpPosition,
perp_market: &PerpMarket
) -> Result<()>
pub fn has_spot_assets(&self) -> bool
pub fn has_serum3_open_orders_funds(&self) -> bool
pub fn has_perp_open_orders(&self) -> bool
pub fn has_perp_base_positions(&self) -> bool
pub fn has_perp_open_fills(&self) -> bool
pub fn has_perp_positive_pnl_no_base(&self) -> bool
pub fn has_perp_negative_pnl(&self) -> bool
sourcepub fn has_phase1_liquidatable(&self) -> bool
pub fn has_phase1_liquidatable(&self) -> bool
Phase1 is spot/perp order cancellation and spot settlement since neither of these come at a cost to the liqee
pub fn require_after_phase1_liquidation(&self) -> Result<()>
pub fn in_phase1_liquidation(&self) -> bool
sourcepub fn has_phase2_liquidatable(&self) -> bool
pub fn has_phase2_liquidatable(&self) -> bool
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
pub fn require_after_phase2_liquidation(&self) -> Result<()>
pub fn in_phase2_liquidation(&self) -> bool
sourcepub fn has_phase3_liquidatable(&self) -> bool
pub fn has_phase3_liquidatable(&self) -> bool
Phase3 is bankruptcy:
- token bankruptcy
- perp bankruptcy
pub fn in_phase3_liquidation(&self) -> bool
pub fn has_spot_borrows(&self) -> bool
sourcepub fn perp_settle_health(&self) -> I80F48
pub fn perp_settle_health(&self) -> I80F48
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)
pub fn total_serum3_potential(
&self,
health_type: HealthType,
token_index: TokenIndex
) -> Result<I80F48>
sourceimpl HealthCache
impl HealthCache
pub fn is_liquidatable(&self) -> bool
sourcepub fn health_ratio(&self, health_type: HealthType) -> I80F48
pub fn health_ratio(&self, health_type: HealthType) -> I80F48
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?
pub fn max_swap_source_for_health_ratio(
&self,
account: &MangoAccountValue,
source_bank: &Bank,
source_oracle_price: I80F48,
target_bank: &Bank,
price: I80F48,
min_ratio: I80F48
) -> Result<I80F48>
pub fn max_swap_source_for_health(
&self,
account: &MangoAccountValue,
source_bank: &Bank,
source_oracle_price: I80F48,
target_bank: &Bank,
price: I80F48,
min_ratio: I80F48
) -> Result<I80F48>
sourcepub fn max_swap_source_for_health_fn(
&self,
account: &MangoAccountValue,
source_bank: &Bank,
source_oracle_price: I80F48,
target_bank: &Bank,
price: I80F48,
min_fn_value: I80F48,
target_fn: fn(_: &HealthCache) -> I80F48
) -> Result<I80F48>
pub fn max_swap_source_for_health_fn(
&self,
account: &MangoAccountValue,
source_bank: &Bank,
source_oracle_price: I80F48,
target_bank: &Bank,
price: I80F48,
min_fn_value: I80F48,
target_fn: fn(_: &HealthCache) -> I80F48
) -> Result<I80F48>
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
sourcepub fn max_perp_for_health_ratio(
&self,
perp_market_index: PerpMarketIndex,
price: I80F48,
side: PerpOrderSide,
min_ratio: I80F48
) -> Result<i64>
pub fn max_perp_for_health_ratio(
&self,
perp_market_index: PerpMarketIndex,
price: I80F48,
side: PerpOrderSide,
min_ratio: I80F48
) -> Result<i64>
NOTE: keep getMaxSourceForTokenSwap in ts/client in sync with changes here
pub fn max_borrow_for_health_ratio(
&self,
account: &MangoAccountValue,
bank: &Bank,
min_ratio: I80F48
) -> Result<I80F48>
Trait Implementations
sourceimpl BorshDeserialize for HealthCachewhere
Vec<TokenInfo>: BorshDeserialize,
Vec<Serum3Info>: BorshDeserialize,
Vec<PerpInfo>: BorshDeserialize,
bool: BorshDeserialize,
impl BorshDeserialize for HealthCachewhere
Vec<TokenInfo>: BorshDeserialize,
Vec<Serum3Info>: BorshDeserialize,
Vec<PerpInfo>: BorshDeserialize,
bool: BorshDeserialize,
sourcefn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
fn try_from_slice(v: &[u8]) -> Result<Self, Error>
sourceimpl BorshSerialize for HealthCachewhere
Vec<TokenInfo>: BorshSerialize,
Vec<Serum3Info>: BorshSerialize,
Vec<PerpInfo>: BorshSerialize,
bool: BorshSerialize,
impl BorshSerialize for HealthCachewhere
Vec<TokenInfo>: BorshSerialize,
Vec<Serum3Info>: BorshSerialize,
Vec<PerpInfo>: BorshSerialize,
bool: BorshSerialize,
sourceimpl Clone for HealthCache
impl Clone for HealthCache
sourcefn clone(&self) -> HealthCache
fn clone(&self) -> HealthCache
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more