Struct mango_v4::state::Bank

source ·
#[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

source

pub fn from_existing_bank( existing_bank: &Bank, vault: Pubkey, bank_num: u32, bump: u8 ) -> Self

source

pub fn name(&self) -> &str

source

pub fn are_deposits_reduce_only(&self) -> bool

source

pub fn are_borrows_reduce_only(&self) -> bool

source

pub fn is_force_close(&self) -> bool

source

pub fn native_borrows(&self) -> I80F48

source

pub fn native_deposits(&self) -> I80F48

source

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.

source

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

source

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.

source

pub fn deposit_internal_wrapper( &mut self, position: &mut TokenPosition, native_amount: I80F48, allow_dusting: bool, now_ts: u64 ) -> Result<bool>

source

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

source

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

source

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.

source

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

source

pub fn withdraw_loan_origination_fee( &mut self, position: &mut TokenPosition, already_borrowed_native_amount: I80F48, now_ts: u64 ) -> Result<(bool, I80F48)>

source

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

source

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

source

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.

source

pub fn check_net_borrows(&self, oracle_price: I80F48) -> Result<()>

source

pub fn update_cumulative_interest( &self, position: &mut TokenPosition, opening_indexed_position: I80F48 )

source

pub fn compute_index( &self, indexed_total_deposits: I80F48, indexed_total_borrows: I80F48, diff_ts: I80F48 ) -> Result<(I80F48, I80F48, I80F48, I80F48, I80F48)>

source

pub fn compute_interest_rate(&self, utilization: I80F48) -> I80F48

returns the current interest rate in APR

source

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

source

pub fn compute_new_avg_utilization( &self, indexed_total_deposits: I80F48, indexed_total_borrows: I80F48, now_ts: u64 ) -> I80F48

source

pub fn compute_rates(&self) -> (I80F48, I80F48, I80F48)

source

pub fn oracle_price( &self, oracle_acc: &impl KeyedAccountReader, staleness_slot: Option<u64> ) -> Result<I80F48>

source

pub fn stable_price(&self) -> I80F48

source

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.

source

pub fn scaled_init_liab_weight(&self, price: I80F48) -> I80F48

Trait Implementations§

source§

impl AccountDeserialize for Bank

source§

fn try_deserialize(buf: &mut &[u8]) -> Result<Self>

Deserializes previously initialized account data. Should fail for all uninitialized accounts, where the bytes are zeroed. Implementations should be unique to a particular account type so that one can never successfully deserialize the data of one account type into another. For example, if the SPL token program were to implement this trait, it should be impossible to deserialize a Mint account into a token Account.
source§

fn try_deserialize_unchecked(buf: &mut &[u8]) -> Result<Self>

Deserializes account data without checking the account discriminator. This should only be used on account initialization, when the bytes of the account are zeroed.
source§

impl Clone for Bank

source§

fn clone(&self) -> Bank

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Bank

source§

fn fmt(&self, __f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Discriminator for Bank

source§

impl Owner for Bank

source§

fn owner() -> Pubkey

source§

impl Zeroable for Bank

§

fn zeroed() -> Self

source§

impl Copy for Bank

source§

impl Pod for Bank

source§

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dstwhere T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dstwhere Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,

Casts the value.
§

impl<T> CheckedBitPattern for Twhere T: AnyBitPattern,

§

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

If this function returns true, then it must be valid to reinterpret bits as &Self.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> DynClone for Twhere T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Srcwhere Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.
§

impl<T> AnyBitPattern for Twhere T: Pod,

§

impl<T> NoUninit for Twhere T: Pod,