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
//! This code was AUTOGENERATED using the Codama library.
use {
crate::types::{MarginMode, Order, PerpPosition, SpotPosition},
solana_pubkey::Pubkey,
};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct User {
/// The owner/authority of the account
pub authority: Pubkey,
/// An addresses that can control the account on the authority's behalf. Has
/// limited power, cant withdraw
pub delegate: Pubkey,
/// Encoded display name e.g. "toly"
pub name: [u8; 32],
/// The user's spot positions
pub spot_positions: [SpotPosition; 8],
/// The user's perp positions
pub perp_positions: [PerpPosition; 8],
/// The user's orders
pub orders: [Order; 32],
/// The last time the user added perp lp positions
pub last_add_perp_lp_shares_ts: i64,
/// The total values of deposits the user has made
/// precision: QUOTE_PRECISION
pub total_deposits: u64,
/// The total values of withdrawals the user has made
/// precision: QUOTE_PRECISION
pub total_withdraws: u64,
/// The total socialized loss the users has incurred upon the protocol
/// precision: QUOTE_PRECISION
pub total_social_loss: u64,
/// Fees (taker fees, maker rebate, referrer reward, filler reward) and pnl
/// for perps precision: QUOTE_PRECISION
pub settled_perp_pnl: i64,
/// Fees (taker fees, maker rebate, filler reward) for spot
/// precision: QUOTE_PRECISION
pub cumulative_spot_fees: i64,
/// Cumulative funding paid/received for perps
/// precision: QUOTE_PRECISION
pub cumulative_perp_funding: i64,
/// The amount of margin freed during liquidation. Used to force the
/// liquidation to occur over a period of time Defaults to zero when not
/// being liquidated precision: QUOTE_PRECISION
pub liquidation_margin_freed: u64,
/// The last slot a user was active. Used to determine if a user is idle
pub last_active_slot: u64,
/// Every user order has an order id. This is the next order id to be used
pub next_order_id: u32,
/// Custom max initial margin ratio for the user
pub max_margin_ratio: u32,
/// The next liquidation id to be used for user
pub next_liquidation_id: u16,
/// The sub account id for this user
pub sub_account_id: u16,
/// Whether the user is active, being liquidated or bankrupt
pub status: u8,
/// Whether the user has enabled margin trading
pub is_margin_trading_enabled: bool,
/// User is idle if they haven't interacted with the protocol in 1 week and
/// they have no orders, perp positions or borrows Off-chain keeper bots
/// can ignore users that are idle
pub idle: bool,
/// number of open orders
pub open_orders: u8,
/// Whether or not user has open order
pub has_open_order: bool,
/// number of open orders with auction
pub open_auctions: u8,
/// Whether or not user has open order with auction
pub has_open_auction: bool,
pub margin_mode: MarginMode,
pub pool_id: u8,
pub padding1: [u8; 3],
pub last_fuel_bonus_update_ts: u32,
pub padding: [u8; 12],
}
impl User {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.len() < 8 {
return None;
}
let discriminator = &data[0..8];
if discriminator != [159, 117, 95, 227, 239, 151, 58, 236] {
return None;
}
let mut data_slice = data;
data_slice = &data_slice[8..];
borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
}
}