1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//! This code was AUTOGENERATED using the Codama library.
use crate::types::WrappedI80F48;
/// A read-only cache of the internal risk engine's information. Only valid in
/// borrow/withdraw if the tx does not fail. To see the state in any context,
/// e.g. to figure out if the risk engine is failing due to some bad price
/// information, use `pulse_health`.
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct HealthCache {
/// Internal risk engine asset value, using initial weight (e.g. what is
/// used for borrowing purposes), with all confidence adjustments, and
/// other discounts on price.
/// * Uses EMA price
/// * In dollars
pub asset_value: WrappedI80F48,
/// Internal risk engine liability value, using initial weight (e.g. what is
/// used for borrowing purposes), with all confidence adjustments, and
/// other discounts on price.
/// * Uses EMA price
/// * In dollars
pub liability_value: WrappedI80F48,
/// Internal risk engine asset value, using maintenance weight (e.g. what is
/// used for liquidation purposes), with all confidence adjustments.
/// * Zero if the risk engine failed to load
/// * Uses SPOT price
/// * In dollars
pub asset_value_maint: WrappedI80F48,
/// Internal risk engine liability value, using maintenance weight (e.g.
/// what is used for liquidation purposes), with all confidence
/// adjustments.
/// * Zero if the risk engine failed to load
/// * Uses SPOT price
/// * In dollars
pub liability_value_maint: WrappedI80F48,
/// The "true" value of assets without any confidence or weight adjustments.
/// Internally, used only for bankruptcies.
/// * Zero if the risk engine failed to load
/// * Uses EMA price
/// * In dollars
pub asset_value_equity: WrappedI80F48,
/// The "true" value of liabilities without any confidence or weight
/// adjustments. Internally, used only for bankruptcies.
/// * Zero if the risk engine failed to load
/// * Uses EMA price
/// * In dollars
pub liability_value_equity: WrappedI80F48,
/// Unix timestamp from the system clock when this cache was last updated
pub timestamp: i64,
/// The flags that indicate the state of the health cache. This is a u32
/// bitfield, where each bit represents a flag.
/// * HEALTHY = 1 - If set, the account cannot be liquidated. If 0, the
/// account is unhealthy and
///
/// can be liquidated.
/// * ENGINE STATUS = 2 - If set, the engine did not error during the last
/// health pulse. If 0,
///
/// the engine would have errored and this cache is likely invalid.
/// `RiskEngineInitRejected` is ignored and will allow the flag to be
/// set anyways.
/// * ORACLE OK = 4 - If set, the engine did not error due to an oracle
/// issue. If 0, engine was
///
/// passed a bad bank or oracle account, or an oracle was stale. Check the
/// order in which accounts were passed and ensure each balance has the
/// correct banks/oracles, and that oracle cranks ran recently enough.
/// Check `internal_err` and `err_index` for more details
/// in some circumstances. Invalid if generated after borrow/withdraw (these
/// instructions will ignore oracle issues if health is still
/// satisfactory with some balance zeroed out).
/// * 8, 16, 32, 64, 128, etc - reserved for future use
pub flags: u32,
/// If the engine errored, look here for the error code. If the engine
/// returns ok, you may also check here to see if the risk engine
/// rejected this tx (3009).
pub mrgn_err: u32,
/// Each price corresponds to that index of Balances in the LendingAccount.
/// Useful for debugging or liquidator consumption, to determine how a
/// user's position is priced internally.
/// * An f64 stored as bytes
pub prices: [[u8; 8]; 16],
/// Errors in asset oracles are ignored (with prices treated as zero). If
/// you see a zero price and the `ORACLE_OK` flag is not set, check here
/// to see what error was ignored internally.
pub internal_err: u32,
/// Index in `balances` where `internal_err` appeared
pub err_index: u8,
/// Since 0.1.3, the version will be encoded here. See PROGRAM_VERSION.
pub program_version: u8,
pub pad0: [u8; 2],
/// Error code from the liquidation health check during the last health
/// pulse (0 if none)
pub internal_liq_err: u32,
/// Error code from the bankruptcy check during the last health pulse (0 if
/// none)
pub internal_bankruptcy_err: u32,
pub reserved0: [u8; 32],
pub reserved1: [u8; 16],
}