#[repr(C)]pub struct Bank {Show 45 fields
pub group: Pubkey,
pub name: [u8; 16],
pub mint: Pubkey,
pub vault: Pubkey,
pub oracle: Pubkey,
pub oracle_config: OracleConfig,
pub stable_price_model: StablePriceModel,
pub deposit_index: I80F48,
pub borrow_index: I80F48,
pub indexed_deposits: I80F48,
pub indexed_borrows: I80F48,
pub index_last_updated: u64,
pub bank_rate_last_updated: u64,
pub avg_utilization: I80F48,
pub adjustment_factor: I80F48,
pub util0: I80F48,
pub rate0: I80F48,
pub util1: I80F48,
pub rate1: I80F48,
pub max_rate: I80F48,
pub collected_fees_native: I80F48,
pub loan_origination_fee_rate: I80F48,
pub loan_fee_rate: I80F48,
pub maint_asset_weight: I80F48,
pub init_asset_weight: I80F48,
pub maint_liab_weight: I80F48,
pub init_liab_weight: I80F48,
pub liquidation_fee: I80F48,
pub dust: I80F48,
pub flash_loan_token_account_initial: u64,
pub flash_loan_approved_amount: u64,
pub token_index: TokenIndex,
pub bump: u8,
pub mint_decimals: u8,
pub bank_num: u32,
pub min_vault_to_deposits_ratio: f64,
pub net_borrow_limit_window_size_ts: u64,
pub last_net_borrows_window_start_ts: u64,
pub net_borrow_limit_per_window_quote: i64,
pub net_borrows_in_window: i64,
pub borrow_weight_scale_start_quote: f64,
pub deposit_weight_scale_start_quote: f64,
pub reduce_only: u8,
pub force_close: u8,
pub reserved: [u8; 2118],
}
Fields§
§group: Pubkey
§name: [u8; 16]
§mint: Pubkey
§vault: Pubkey
§oracle: Pubkey
§oracle_config: OracleConfig
§stable_price_model: StablePriceModel
§deposit_index: I80F48
the index used to scale the value of an IndexedPosition TODO: should always be >= 0, add checks?
borrow_index: I80F48
§indexed_deposits: I80F48
deposits/borrows for this bank
Note that these may become negative. It’s perfectly fine for users to borrow one one bank (increasing indexed_borrows there) and paying back on another (possibly decreasing indexed_borrows below zero).
The vault amount is not deducable from these values.
These become meaningful when summed over all banks (like in update_index_and_rate).
indexed_borrows: I80F48
§index_last_updated: u64
§bank_rate_last_updated: u64
§avg_utilization: I80F48
§adjustment_factor: I80F48
§util0: I80F48
§rate0: I80F48
§util1: I80F48
§rate1: I80F48
§max_rate: I80F48
§collected_fees_native: I80F48
§loan_origination_fee_rate: I80F48
§loan_fee_rate: I80F48
§maint_asset_weight: I80F48
§init_asset_weight: I80F48
§maint_liab_weight: I80F48
§init_liab_weight: I80F48
§liquidation_fee: I80F48
§dust: I80F48
§flash_loan_token_account_initial: u64
§flash_loan_approved_amount: u64
§token_index: TokenIndex
§bump: u8
§mint_decimals: u8
§bank_num: u32
§min_vault_to_deposits_ratio: f64
Min fraction of deposits that must remain in the vault when borrowing.
net_borrow_limit_window_size_ts: u64
Size in seconds of a net borrows window
last_net_borrows_window_start_ts: u64
Timestamp at which the last net borrows window started
net_borrow_limit_per_window_quote: i64
Net borrow limit per window in quote native; set to -1 to disable.
net_borrows_in_window: i64
Sum of all deposits and borrows in the last window, in native units.
borrow_weight_scale_start_quote: f64
Soft borrow limit in native quote
Once the borrows on the bank exceed this quote value, init_liab_weight is scaled up. Set to f64::MAX to disable.
See scaled_init_liab_weight().
deposit_weight_scale_start_quote: f64
Limit for collateral of deposits in native quote
Once the deposits in the bank exceed this quote value, init_asset_weight is scaled down to keep the total collateral value constant. Set to f64::MAX to disable.
See scaled_init_asset_weight().
reduce_only: u8
§force_close: u8
§reserved: [u8; 2118]
Implementations§
source§impl Bank
impl Bank
pub fn from_existing_bank( existing_bank: &Bank, vault: Pubkey, bank_num: u32, bump: u8 ) -> Self
pub fn name(&self) -> &str
pub fn are_deposits_reduce_only(&self) -> bool
pub fn are_borrows_reduce_only(&self) -> bool
pub fn is_force_close(&self) -> bool
pub fn native_borrows(&self) -> I80F48
pub fn native_deposits(&self) -> I80F48
sourcepub fn enforce_min_vault_to_deposits_ratio(
&self,
vault_ai: &AccountInfo<'_>
) -> Result<()>
pub fn enforce_min_vault_to_deposits_ratio( &self, vault_ai: &AccountInfo<'_> ) -> Result<()>
Prevent borrowing away the full bank vault. Keep some in reserve to satisfy non-borrow withdraws.
sourcepub fn deposit(
&mut self,
position: &mut TokenPosition,
native_amount: I80F48,
now_ts: u64
) -> Result<bool>
pub fn deposit( &mut self, position: &mut TokenPosition, native_amount: I80F48, now_ts: u64 ) -> Result<bool>
Deposits native_amount
.
If the token position ends up positive but below one native token and this token position isn’t marked as in-use, the token balance will be dusted, the position will be set to zero and this function returns Ok(false).
native_amount must be >= 0 fractional deposits can be relevant during liquidation, for example
sourcepub fn deposit_with_dusting(
&mut self,
position: &mut TokenPosition,
native_amount: I80F48,
now_ts: u64
) -> Result<bool>
pub fn deposit_with_dusting( &mut self, position: &mut TokenPosition, native_amount: I80F48, now_ts: u64 ) -> Result<bool>
Like deposit()
, but allows dusting of in-use accounts.
Returns Ok(false) if the position was dusted and was not in-use.
pub fn deposit_internal_wrapper( &mut self, position: &mut TokenPosition, native_amount: I80F48, allow_dusting: bool, now_ts: u64 ) -> Result<bool>
sourcepub fn deposit_internal(
&mut self,
position: &mut TokenPosition,
native_amount: I80F48,
allow_dusting: bool,
now_ts: u64
) -> Result<bool>
pub fn deposit_internal( &mut self, position: &mut TokenPosition, native_amount: I80F48, allow_dusting: bool, now_ts: u64 ) -> Result<bool>
Internal function to deposit funds
sourcepub fn withdraw_without_fee(
&mut self,
position: &mut TokenPosition,
native_amount: I80F48,
now_ts: u64
) -> Result<bool>
pub fn withdraw_without_fee( &mut self, position: &mut TokenPosition, native_amount: I80F48, now_ts: u64 ) -> Result<bool>
Withdraws native_amount
without applying the loan origination fee.
If the token position ends up positive but below one native token and this token position isn’t marked as in-use, the token balance will be dusted, the position will be set to zero and this function returns Ok(false).
native_amount must be >= 0 fractional withdraws can be relevant during liquidation, for example
sourcepub fn withdraw_without_fee_with_dusting(
&mut self,
position: &mut TokenPosition,
native_amount: I80F48,
now_ts: u64
) -> Result<bool>
pub fn withdraw_without_fee_with_dusting( &mut self, position: &mut TokenPosition, native_amount: I80F48, now_ts: u64 ) -> Result<bool>
Like withdraw_without_fee()
but allows dusting of in-use token accounts.
Returns Ok(false) on dusted positions that weren’t in-use.
sourcepub fn withdraw_with_fee(
&mut self,
position: &mut TokenPosition,
native_amount: I80F48,
now_ts: u64
) -> Result<(bool, I80F48)>
pub fn withdraw_with_fee( &mut self, position: &mut TokenPosition, native_amount: I80F48, now_ts: u64 ) -> Result<(bool, I80F48)>
Withdraws native_amount
while applying the loan origination fee if a borrow is created.
If the token position ends up positive but below one native token and this token position isn’t marked as in-use, the token balance will be dusted, the position will be set to zero and this function returns Ok(false).
native_amount must be >= 0 fractional withdraws can be relevant during liquidation, for example
pub fn withdraw_loan_origination_fee( &mut self, position: &mut TokenPosition, already_borrowed_native_amount: I80F48, now_ts: u64 ) -> Result<(bool, I80F48)>
sourcepub fn change_without_fee(
&mut self,
position: &mut TokenPosition,
native_amount: I80F48,
now_ts: u64
) -> Result<bool>
pub fn change_without_fee( &mut self, position: &mut TokenPosition, native_amount: I80F48, now_ts: u64 ) -> Result<bool>
Change a position without applying the loan origination fee
sourcepub fn change_with_fee(
&mut self,
position: &mut TokenPosition,
native_amount: I80F48,
now_ts: u64
) -> Result<(bool, I80F48)>
pub fn change_with_fee( &mut self, position: &mut TokenPosition, native_amount: I80F48, now_ts: u64 ) -> Result<(bool, I80F48)>
Change a position, while taking the loan origination fee into account
sourcepub fn update_net_borrows(&mut self, native_amount: I80F48, now_ts: u64)
pub fn update_net_borrows(&mut self, native_amount: I80F48, now_ts: u64)
Update the bank’s net_borrows fields.
If oracle_price is set, also do a net borrows check and error if the threshold is exceeded.
pub fn check_net_borrows(&self, oracle_price: I80F48) -> Result<()>
pub fn update_cumulative_interest( &self, position: &mut TokenPosition, opening_indexed_position: I80F48 )
pub fn compute_index( &self, indexed_total_deposits: I80F48, indexed_total_borrows: I80F48, diff_ts: I80F48 ) -> Result<(I80F48, I80F48, I80F48, I80F48, I80F48)>
sourcepub fn compute_interest_rate(&self, utilization: I80F48) -> I80F48
pub fn compute_interest_rate(&self, utilization: I80F48) -> I80F48
returns the current interest rate in APR
sourcepub fn interest_rate_curve_calculator(
utilization: I80F48,
util0: I80F48,
rate0: I80F48,
util1: I80F48,
rate1: I80F48,
max_rate: I80F48
) -> I80F48
pub fn interest_rate_curve_calculator( utilization: I80F48, util0: I80F48, rate0: I80F48, util1: I80F48, rate1: I80F48, max_rate: I80F48 ) -> I80F48
calcualtor function that can be used to compute an interest rate based on the given parameters
pub fn compute_new_avg_utilization( &self, indexed_total_deposits: I80F48, indexed_total_borrows: I80F48, now_ts: u64 ) -> I80F48
pub fn compute_rates(&self) -> (I80F48, I80F48, I80F48)
pub fn oracle_price( &self, oracle_acc: &impl KeyedAccountReader, staleness_slot: Option<u64> ) -> Result<I80F48>
pub fn stable_price(&self) -> I80F48
sourcepub fn scaled_init_asset_weight(&self, price: I80F48) -> I80F48
pub fn scaled_init_asset_weight(&self, price: I80F48) -> I80F48
Returns the init asset weight, adjusted for the number of deposits on the bank.
If max_collateral is 0, then the scaled init weight will be 0. Otherwise the weight is unadjusted until max_collateral and then scaled down such that scaled_init_weight * deposits remains constant.
pub fn scaled_init_liab_weight(&self, price: I80F48) -> I80F48
Trait Implementations§
source§impl AccountDeserialize for Bank
impl AccountDeserialize for Bank
source§fn try_deserialize(buf: &mut &[u8]) -> Result<Self>
fn try_deserialize(buf: &mut &[u8]) -> Result<Self>
Mint
account into a token
Account
.source§fn try_deserialize_unchecked(buf: &mut &[u8]) -> Result<Self>
fn try_deserialize_unchecked(buf: &mut &[u8]) -> Result<Self>
impl Copy for Bank
impl Pod for Bank
impl ZeroCopy for Bank
Auto Trait Implementations§
impl RefUnwindSafe for Bank
impl Send for Bank
impl Sync for Bank
impl Unpin for Bank
impl UnwindSafe for Bank
Blanket Implementations§
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,
§impl<T> CheckedBitPattern for Twhere
T: AnyBitPattern,
impl<T> CheckedBitPattern for Twhere T: AnyBitPattern,
§type Bits = T
type Bits = T
Self
must have the same layout as the specified Bits
except for
the possible invalid bit patterns being checked during
is_valid_bit_pattern
.§fn is_valid_bit_pattern(_bits: &T) -> bool
fn is_valid_bit_pattern(_bits: &T) -> bool
bits
as &Self
.