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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! This code was AUTOGENERATED using the Codama library.
use {
crate::types::{BankCache, BankConfig, BankRateLimiter, EmodeSettings, WrappedI80F48},
solana_pubkey::Pubkey,
};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Clone, borsh::BorshSerialize, borsh::BorshDeserialize, PartialEq)]
pub struct Bank {
/// The SPL token mint this bank manages
pub mint: Pubkey,
/// Number of decimals of the `mint`. Must be < 24.
pub mint_decimals: u8,
/// The `MarginfiGroup` this bank belongs to
pub group: Pubkey,
pub _pad0: [u8; 7],
/// Monotonically increases as interest rate accumulates. For typical banks,
/// a user's asset value in token = (number of shares the user has *
/// asset_share_value).
/// * A float (arbitrary decimals)
/// * Initially 1
pub asset_share_value: WrappedI80F48,
/// Monotonically increases as interest rate accumulates. For typical banks,
/// a user's liabilty value in token = (number of shares the user has *
/// liability_share_value)
/// * A float (arbitrary decimals)
/// * Initially 1
pub liability_share_value: WrappedI80F48,
/// The SPL token account holding deposited liquidity
pub liquidity_vault: Pubkey,
/// PDA bump for the liquidity vault
pub liquidity_vault_bump: u8,
/// PDA bump for the liquidity vault authority
pub liquidity_vault_authority_bump: u8,
/// The SPL token account holding insurance fund tokens
pub insurance_vault: Pubkey,
/// PDA bump for the insurance vault
pub insurance_vault_bump: u8,
/// PDA bump for the insurance vault authority
pub insurance_vault_authority_bump: u8,
pub pad1: [u8; 4],
/// Fees collected and pending withdraw for the `insurance_vault`
pub collected_insurance_fees_outstanding: WrappedI80F48,
/// The SPL token account holding collected group fees
pub fee_vault: Pubkey,
/// PDA bump for the fee vault
pub fee_vault_bump: u8,
/// PDA bump for the fee vault authority
pub fee_vault_authority_bump: u8,
pub pad2: [u8; 6],
/// Fees collected and pending withdraw for the `fee_vault`
pub collected_group_fees_outstanding: WrappedI80F48,
/// Sum of all liability shares held by all borrowers in this bank.
/// Multiply by `liability_share_value` to get the total liability amount in
/// native token units.
pub total_liability_shares: WrappedI80F48,
/// Sum of all asset shares held by all depositors in this bank.
/// Multiply by `asset_share_value` to get the total asset amount in native
/// token units.
/// * For Kamino banks, this is the quantity of collateral tokens (NOT
/// liquidity tokens) in the
///
/// bank, and also uses `mint_decimals`, though the mint itself will always
/// show (6) decimals exactly (i.e Kamino ignores this and treats it as
/// if it was using `mint_decimals`)
pub total_asset_shares: WrappedI80F48,
/// Unix timestamp (i64) of the last interest accrual
pub last_update: i64,
/// The bank's configuration parameters (weights, limits, oracle setup,
/// interest rate config)
pub config: BankConfig,
/// Bank flags bitfield (u64).
/// - Bit 0 (1): `EMISSIONS_FLAG_BORROW_ACTIVE` — borrow-side emissions are
/// active
/// - Bit 1 (2): `EMISSIONS_FLAG_LENDING_ACTIVE` — lending-side emissions
/// are active
/// - Bit 2 (4): `PERMISSIONLESS_BAD_DEBT_SETTLEMENT_FLAG` — anyone can
/// settle bad debt
/// - Bit 3 (8): `FREEZE_SETTINGS` — bank configuration is frozen (only
/// limits can change)
/// - Bit 4 (16): `CLOSE_ENABLED_FLAG` — bank can be closed (set at creation
/// for banks >= 0.1.4)
/// - Bit 5 (32): `TOKENLESS_REPAYMENTS_ALLOWED` — risk admin can repay debt
/// without tokens
/// - Bit 6 (64): `TOKENLESS_REPAYMENTS_COMPLETE` — all debt cleared, lender
/// purge enabled
pub flags: u64,
/// Emissions APR. Number of emitted tokens (emissions_mint) per
/// 1e(bank.mint_decimal) tokens (bank mint) (native amount) per 1 YEAR.
pub emissions_rate: u64,
/// Remaining emissions tokens available for distribution
pub emissions_remaining: WrappedI80F48,
/// The SPL token mint used for emissions rewards
pub emissions_mint: Pubkey,
/// Fees collected and pending withdraw for the
/// `FeeState.global_fee_wallet`'s canonical ATA for `mint`
pub collected_program_fees_outstanding: WrappedI80F48,
/// Controls this bank's emode configuration, which enables some banks to
/// treat the assets of certain other banks more preferentially as
/// collateral.
pub emode: EmodeSettings,
/// Set with `update_fees_destination_account`. Fees can be withdrawn to the
/// canonical ATA of this wallet without the admin's input
/// (withdraw_fees_permissionless). If pubkey default, the bank doesn't
/// support this feature, and the fees must be collected manually
/// (withdraw_fees).
pub fees_destination_account: Pubkey,
/// Cached bank metrics (interest rates, oracle price, etc.)
pub cache: BankCache,
/// Number of user lending positions currently open in this bank
/// * For banks created prior to 0.1.4, this is the number of positions
/// opened/closed after
///
/// 0.1.4 goes live, and may be negative.
/// * For banks created in 0.1.4 or later, this is the number of positions
/// open in total, and
///
/// the bank may safely be closed if this is zero. Will never go negative.
pub lending_position_count: i32,
/// Number of user borrowing positions currently open in this bank
/// * For banks created prior to 0.1.4, this is the number of positions
/// opened/closed after
///
/// 0.1.4 goes live, and may be negative.
/// * For banks created in 0.1.4 or later, this is the number of positions
/// open in total, and
///
/// the bank may safely be closed if this is zero. Will never go negative.
pub borrowing_position_count: i32,
/// Reserved for future use
pub padding0: [u8; 16],
/// Integration account slot 1 (default Pubkey for non-integrations).
/// - Kamino: reserve
/// - Drift: spot market
/// - Solend: reserve
/// - JupLend: lending state
pub integration_acc1: Pubkey,
/// Integration account slot 2 (default Pubkey for non-integrations).
/// - Kamino: obligation
/// - Drift: user
/// - Solend: obligation
/// - JupLend: fToken vault
pub integration_acc2: Pubkey,
/// Integration account slot 3 (default Pubkey for non-integrations).
/// - Drift: user stats
/// - JupLend: withdraw intermediary ATA (ATA of liquidity_vault_authority
/// for bank mint)
pub integration_acc3: Pubkey,
/// Rate limiter for controlling withdraw/borrow outflow.
/// Tracks net outflow (outflows - inflows) in native tokens.
pub rate_limiter: BankRateLimiter,
pub pad0: [u8; 16],
pub padding1: [[u64; 2]; 7],
}
impl Bank {
pub fn decode(data: &[u8]) -> Option<Self> {
if data.len() < 8 {
return None;
}
let discriminator = &data[0..8];
if discriminator != [142, 49, 166, 242, 50, 66, 97, 188] {
return None;
}
let mut data_slice = data;
data_slice = &data_slice[8..];
borsh::BorshDeserialize::deserialize(&mut data_slice).ok()
}
}