Struct mango_v4::state::Bank

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

source

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

source

pub fn verify(&self) -> Result<()>

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 is_force_withdraw(&self) -> bool

source

pub fn allows_asset_liquidation(&self) -> bool

source

pub fn native_borrows(&self) -> I80F48

source

pub fn native_deposits(&self) -> I80F48

source

pub fn maint_weights(&self, now_ts: u64) -> (I80F48, I80F48)

source

pub fn enforce_borrows_lte_deposits(&self) -> Result<()>

source

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.

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<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

source

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

source

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

Returns true if the position remains active

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<WithdrawResult>

Change a position, while taking the loan origination fee into account

source

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.

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 remaining_net_borrows_quote(&self, oracle_price: I80F48) -> I80F48

source

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

source

pub fn remaining_deposits_until_limit(&self) -> I80F48

source

pub fn check_deposit_and_oo_limit(&self) -> 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, 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

source

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

source

pub fn update_interest_rate_scaling(&mut self)

source

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.

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

source

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

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§

const DISCRIMINATOR: [u8; 8] = _

§

fn discriminator() -> [u8; 8]

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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> 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<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,