pub struct Obligation {
pub version: u8,
pub last_update: LastUpdate,
pub lending_market: Pubkey,
pub owner: Pubkey,
pub deposits: Vec<ObligationCollateral>,
pub borrows: Vec<ObligationLiquidity>,
pub deposited_value: Decimal,
pub borrowed_value: Decimal,
pub allowed_borrow_value: Decimal,
pub unhealthy_borrow_value: Decimal,
}Expand description
Lending market obligation state
Fields§
§version: u8Version of the struct
last_update: LastUpdateLast update to collateral, liquidity, or their market values
lending_market: PubkeyLending market address
owner: PubkeyOwner authority which can borrow liquidity
deposits: Vec<ObligationCollateral>Deposited collateral for the obligation, unique by deposit reserve address
borrows: Vec<ObligationLiquidity>Borrowed liquidity for the obligation, unique by borrow reserve address
deposited_value: DecimalMarket value of deposits
borrowed_value: DecimalMarket value of borrows
allowed_borrow_value: DecimalThe maximum borrow value at the weighted average loan to value ratio
unhealthy_borrow_value: DecimalThe dangerous borrow value at the weighted average liquidation threshold
Implementations§
Source§impl Obligation
impl Obligation
Sourcepub fn new(params: InitObligationParams) -> Self
pub fn new(params: InitObligationParams) -> Self
Create a new obligation
Sourcepub fn init(&mut self, params: InitObligationParams)
pub fn init(&mut self, params: InitObligationParams)
Initialize an obligation
Sourcepub fn loan_to_value(&self) -> Result<Decimal, ProgramError>
pub fn loan_to_value(&self) -> Result<Decimal, ProgramError>
Calculate the current ratio of borrowed value to deposited value
Sourcepub fn repay(
&mut self,
settle_amount: Decimal,
liquidity_index: usize,
) -> ProgramResult
pub fn repay( &mut self, settle_amount: Decimal, liquidity_index: usize, ) -> ProgramResult
Repay liquidity and remove it from borrows if zeroed out
Sourcepub fn withdraw(
&mut self,
withdraw_amount: u64,
collateral_index: usize,
) -> ProgramResult
pub fn withdraw( &mut self, withdraw_amount: u64, collateral_index: usize, ) -> ProgramResult
Withdraw collateral and remove it from deposits if zeroed out
Sourcepub fn max_withdraw_value(
&self,
withdraw_collateral_ltv: Rate,
) -> Result<Decimal, ProgramError>
pub fn max_withdraw_value( &self, withdraw_collateral_ltv: Rate, ) -> Result<Decimal, ProgramError>
Calculate the maximum collateral value that can be withdrawn
Sourcepub fn remaining_borrow_value(&self) -> Result<Decimal, ProgramError>
pub fn remaining_borrow_value(&self) -> Result<Decimal, ProgramError>
Calculate the maximum liquidity value that can be borrowed
Sourcepub fn max_liquidation_amount(
&self,
liquidity: &ObligationLiquidity,
) -> Result<Decimal, ProgramError>
pub fn max_liquidation_amount( &self, liquidity: &ObligationLiquidity, ) -> Result<Decimal, ProgramError>
Calculate the maximum liquidation amount for a given liquidity
Sourcepub fn find_collateral_in_deposits(
&self,
deposit_reserve: Pubkey,
) -> Result<(&ObligationCollateral, usize), ProgramError>
pub fn find_collateral_in_deposits( &self, deposit_reserve: Pubkey, ) -> Result<(&ObligationCollateral, usize), ProgramError>
Find collateral by deposit reserve
Sourcepub fn find_or_add_collateral_to_deposits(
&mut self,
deposit_reserve: Pubkey,
) -> Result<&mut ObligationCollateral, ProgramError>
pub fn find_or_add_collateral_to_deposits( &mut self, deposit_reserve: Pubkey, ) -> Result<&mut ObligationCollateral, ProgramError>
Find or add collateral by deposit reserve
Sourcepub fn find_liquidity_in_borrows(
&self,
borrow_reserve: Pubkey,
) -> Result<(&ObligationLiquidity, usize), ProgramError>
pub fn find_liquidity_in_borrows( &self, borrow_reserve: Pubkey, ) -> Result<(&ObligationLiquidity, usize), ProgramError>
Find liquidity by borrow reserve
Sourcepub fn find_liquidity_in_borrows_mut(
&mut self,
borrow_reserve: Pubkey,
) -> Result<(&mut ObligationLiquidity, usize), ProgramError>
pub fn find_liquidity_in_borrows_mut( &mut self, borrow_reserve: Pubkey, ) -> Result<(&mut ObligationLiquidity, usize), ProgramError>
Find liquidity by borrow reserve mut
Sourcepub fn find_or_add_liquidity_to_borrows(
&mut self,
borrow_reserve: Pubkey,
cumulative_borrow_rate_wads: Decimal,
) -> Result<&mut ObligationLiquidity, ProgramError>
pub fn find_or_add_liquidity_to_borrows( &mut self, borrow_reserve: Pubkey, cumulative_borrow_rate_wads: Decimal, ) -> Result<&mut ObligationLiquidity, ProgramError>
Find or add liquidity by borrow reserve
Trait Implementations§
Source§impl Clone for Obligation
impl Clone for Obligation
Source§fn clone(&self) -> Obligation
fn clone(&self) -> Obligation
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Obligation
impl Debug for Obligation
Source§impl Default for Obligation
impl Default for Obligation
Source§fn default() -> Obligation
fn default() -> Obligation
Source§impl IsInitialized for Obligation
impl IsInitialized for Obligation
Source§fn is_initialized(&self) -> bool
fn is_initialized(&self) -> bool
Source§impl Pack for Obligation
impl Pack for Obligation
Source§fn get_packed_len() -> usize
fn get_packed_len() -> usize
Source§fn unpack(input: &[u8]) -> Result<Self, ProgramError>where
Self: IsInitialized,
fn unpack(input: &[u8]) -> Result<Self, ProgramError>where
Self: IsInitialized,
Source§fn unpack_unchecked(input: &[u8]) -> Result<Self, ProgramError>
fn unpack_unchecked(input: &[u8]) -> Result<Self, ProgramError>
Source§impl PartialEq for Obligation
impl PartialEq for Obligation
impl Sealed for Obligation
impl StructuralPartialEq for Obligation
Auto Trait Implementations§
impl Freeze for Obligation
impl RefUnwindSafe for Obligation
impl Send for Obligation
impl Sync for Obligation
impl Unpin for Obligation
impl UnwindSafe for Obligation
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more