#[repr(C)]pub struct Bank {Show 67 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 disable_asset_liquidation: u8,
pub force_withdraw: u8,
pub padding: [u8; 4],
pub fees_withdrawn: u64,
pub token_conditional_swap_taker_fee_rate: f32,
pub token_conditional_swap_maker_fee_rate: f32,
pub flash_loan_swap_fee_rate: f32,
pub interest_target_utilization: f32,
pub interest_curve_scaling: f64,
pub potential_serum_tokens: u64,
pub maint_weight_shift_start: u64,
pub maint_weight_shift_end: u64,
pub maint_weight_shift_duration_inv: I80F48,
pub maint_weight_shift_asset_target: I80F48,
pub maint_weight_shift_liab_target: I80F48,
pub fallback_oracle: Pubkey,
pub deposit_limit: u64,
pub zero_util_rate: I80F48,
pub platform_liquidation_fee: I80F48,
pub collected_liquidation_fees: I80F48,
pub collected_collateral_fees: I80F48,
pub collateral_fee_per_day: f32,
pub reserved: [u8; 1900],
}
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
The unscaled borrow interest curve is defined as continuous piecewise linear with the points:
- 0% util: zero_util_rate
- util0% util: rate0
- util1% util: rate1
- 100% util: max_rate
The final rate is this unscaled curve multiplied by interest_curve_scaling.
rate0: I80F48
§util1: I80F48
§rate1: I80F48
§max_rate: I80F48
the 100% utilization rate
This isn’t the max_rate, since this still gets scaled by interest_curve_scaling, which is >=1.
collected_fees_native: I80F48
Fees collected over the lifetime of the bank
See fees_withdrawn for how much of the fees was withdrawn. See collected_liquidation_fees for the (included) subtotal for liquidation related fees.
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
Liquidation fee that goes to the liqor.
Liquidation always involves two tokens, and the sum of the two configured fees is used.
A fraction of the price, like 0.05 for a 5% fee during liquidation.
See also platform_liquidation_fee.
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
The maximum utilization allowed when borrowing is 1-this value WARNING: Outdated name, kept for IDL compatibility
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
§disable_asset_liquidation: u8
If set to 1, deposits cannot be liquidated when an account is liquidatable. That means bankrupt accounts may still have assets of this type deposited.
force_withdraw: u8
§padding: [u8; 4]
§fees_withdrawn: u64
§token_conditional_swap_taker_fee_rate: f32
Fees for the token conditional swap feature
token_conditional_swap_maker_fee_rate: f32
§flash_loan_swap_fee_rate: f32
§interest_target_utilization: f32
Target utilization: If actual utilization is higher, scale up interest. If it’s lower, scale down interest (if possible)
interest_curve_scaling: f64
Current interest curve scaling, always >= 1.0
Except when first migrating to having this field, then 0.0
potential_serum_tokens: u64
Largest amount of tokens that might be added the the bank based on serum open order execution.
maint_weight_shift_start: u64
Start timestamp in seconds at which maint weights should start to change away from maint_asset_weight, maint_liab_weight towards _asset_target and _liab_target. If _start and _end and _duration_inv are 0, no shift is configured.
maint_weight_shift_end: u64
End timestamp in seconds until which the maint weights should reach the configured targets.
maint_weight_shift_duration_inv: I80F48
Cache of the inverse of maint_weight_shift_end - maint_weight_shift_start, or zero if no shift is configured
maint_weight_shift_asset_target: I80F48
Maint asset weight to reach at _shift_end.
maint_weight_shift_liab_target: I80F48
§fallback_oracle: Pubkey
Oracle that may be used if the main oracle is stale or not confident enough. If this is Pubkey::default(), no fallback is available.
deposit_limit: u64
zero means none, in token native
zero_util_rate: I80F48
The unscaled borrow interest curve point for zero utilization.
See util0, rate0, util1, rate1, max_rate
platform_liquidation_fee: I80F48
Additional to liquidation_fee, but goes to the group owner instead of the liqor
collected_liquidation_fees: I80F48
Platform fees that were collected during liquidation (in native tokens)
See also collected_fees_native and fees_withdrawn.
collected_collateral_fees: I80F48
Collateral fees that have been collected (in native tokens)
See also collected_fees_native and fees_withdrawn.
collateral_fee_per_day: f32
The daily collateral fees rate for fully utilized collateral.
reserved: [u8; 1900]
Implementations§
source§impl Bank
impl Bank
pub fn from_existing_bank( existing_bank: &Bank, vault: Pubkey, bank_num: u32, bump: u8 ) -> Self
pub fn verify(&self) -> Result<()>
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 is_force_withdraw(&self) -> bool
pub fn allows_asset_liquidation(&self) -> bool
pub fn native_borrows(&self) -> I80F48
pub fn native_deposits(&self) -> I80F48
pub fn maint_weights(&self, now_ts: u64) -> (I80F48, I80F48)
pub fn enforce_borrows_lte_deposits(&self) -> Result<()>
sourcepub fn enforce_max_utilization_on_borrow(&self) -> Result<()>
pub fn enforce_max_utilization_on_borrow(&self) -> 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<WithdrawResult>
pub fn withdraw_with_fee( &mut self, position: &mut TokenPosition, native_amount: I80F48, now_ts: u64 ) -> Result<WithdrawResult>
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<WithdrawResult>
sourcepub fn dust_if_possible(
&mut self,
position: &mut TokenPosition,
now_ts: u64
) -> Result<bool>
pub fn dust_if_possible( &mut self, position: &mut TokenPosition, now_ts: u64 ) -> Result<bool>
Returns true if the position remains active
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<WithdrawResult>
pub fn change_with_fee( &mut self, position: &mut TokenPosition, native_amount: I80F48, now_ts: u64 ) -> Result<WithdrawResult>
Change a position, while taking the loan origination fee into account
sourcepub fn checked_transfer_with_fee(
&mut self,
source: &mut TokenPosition,
source_amount: I80F48,
target: &mut TokenPosition,
target_amount: I80F48,
now_ts: u64,
oracle_price: I80F48
) -> Result<TransferResult>
pub fn checked_transfer_with_fee( &mut self, source: &mut TokenPosition, source_amount: I80F48, target: &mut TokenPosition, target_amount: I80F48, now_ts: u64, oracle_price: I80F48 ) -> Result<TransferResult>
Generic “transfer” from source to target.
Amounts for source and target can differ and can be zero. Checks reduce-only, net borrow limits and deposit limits.
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 remaining_net_borrows_quote(&self, oracle_price: I80F48) -> I80F48
pub fn check_net_borrows(&self, oracle_price: I80F48) -> Result<()>
pub fn remaining_deposits_until_limit(&self) -> I80F48
pub fn check_deposit_and_oo_limit(&self) -> 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,
zero_util_rate: I80F48,
util0: I80F48,
rate0: I80F48,
util1: I80F48,
rate1: I80F48,
max_rate: I80F48,
scaling: f64
) -> I80F48
pub fn interest_rate_curve_calculator( utilization: I80F48, zero_util_rate: I80F48, util0: I80F48, rate0: I80F48, util1: I80F48, rate1: I80F48, max_rate: I80F48, scaling: f64 ) -> I80F48
calculator 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 update_interest_rate_scaling(&mut self)
sourcepub fn oracle_price<T: KeyedAccountReader>(
&self,
oracle_acc_infos: &OracleAccountInfos<'_, T>,
staleness_slot: Option<u64>
) -> Result<I80F48>
pub fn oracle_price<T: KeyedAccountReader>( &self, oracle_acc_infos: &OracleAccountInfos<'_, T>, staleness_slot: Option<u64> ) -> Result<I80F48>
Tries to return the primary oracle price, and if there is a confidence or staleness issue returns the fallback oracle price if possible.
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
sourcepub fn update_potential_serum_tokens(&mut self, old: u64, new: u64)
pub fn update_potential_serum_tokens(&mut self, old: u64, new: u64)
Grows potential_serum_tokens if new > old, shrinks it otherwise
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>
source§impl Discriminator for Bank
impl Discriminator for Bank
const DISCRIMINATOR: [u8; 8] = _
fn discriminator() -> [u8; 8]
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§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,
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
.