Obligation

Struct Obligation 

Source
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: u8

Version of the struct

§last_update: LastUpdate

Last update to collateral, liquidity, or their market values

§lending_market: Pubkey

Lending market address

§owner: Pubkey

Owner 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: Decimal

Market value of deposits

§borrowed_value: Decimal

Market value of borrows

§allowed_borrow_value: Decimal

The maximum borrow value at the weighted average loan to value ratio

§unhealthy_borrow_value: Decimal

The dangerous borrow value at the weighted average liquidation threshold

Implementations§

Source§

impl Obligation

Source

pub fn new(params: InitObligationParams) -> Self

Create a new obligation

Source

pub fn init(&mut self, params: InitObligationParams)

Initialize an obligation

Source

pub fn loan_to_value(&self) -> Result<Decimal, ProgramError>

Calculate the current ratio of borrowed value to deposited value

Source

pub fn repay( &mut self, settle_amount: Decimal, liquidity_index: usize, ) -> ProgramResult

Repay liquidity and remove it from borrows if zeroed out

Source

pub fn withdraw( &mut self, withdraw_amount: u64, collateral_index: usize, ) -> ProgramResult

Withdraw collateral and remove it from deposits if zeroed out

Source

pub fn max_withdraw_value( &self, withdraw_collateral_ltv: Rate, ) -> Result<Decimal, ProgramError>

Calculate the maximum collateral value that can be withdrawn

Source

pub fn remaining_borrow_value(&self) -> Result<Decimal, ProgramError>

Calculate the maximum liquidity value that can be borrowed

Source

pub fn max_liquidation_amount( &self, liquidity: &ObligationLiquidity, ) -> Result<Decimal, ProgramError>

Calculate the maximum liquidation amount for a given liquidity

Source

pub fn find_collateral_in_deposits( &self, deposit_reserve: Pubkey, ) -> Result<(&ObligationCollateral, usize), ProgramError>

Find collateral by deposit reserve

Source

pub fn find_or_add_collateral_to_deposits( &mut self, deposit_reserve: Pubkey, ) -> Result<&mut ObligationCollateral, ProgramError>

Find or add collateral by deposit reserve

Source

pub fn find_liquidity_in_borrows( &self, borrow_reserve: Pubkey, ) -> Result<(&ObligationLiquidity, usize), ProgramError>

Find liquidity by borrow reserve

Source

pub fn find_liquidity_in_borrows_mut( &mut self, borrow_reserve: Pubkey, ) -> Result<(&mut ObligationLiquidity, usize), ProgramError>

Find liquidity by borrow reserve mut

Source

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

Source§

fn clone(&self) -> Obligation

Returns a duplicate 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 Obligation

Source§

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

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

impl Default for Obligation

Source§

fn default() -> Obligation

Returns the “default value” for a type. Read more
Source§

impl IsInitialized for Obligation

Source§

fn is_initialized(&self) -> bool

Is initialized
Source§

impl Pack for Obligation

Source§

const LEN: usize = 1_300usize

The length, in bytes, of the packed representation
Source§

fn get_packed_len() -> usize

Get the packed length
Source§

fn unpack(input: &[u8]) -> Result<Self, ProgramError>
where Self: IsInitialized,

Unpack from slice and check if initialized
Source§

fn unpack_unchecked(input: &[u8]) -> Result<Self, ProgramError>

Unpack from slice without checking if initialized
Source§

fn pack(src: Self, dst: &mut [u8]) -> Result<(), ProgramError>

Pack into slice
Source§

impl PartialEq for Obligation

Source§

fn eq(&self, other: &Obligation) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sealed for Obligation

Source§

impl StructuralPartialEq for Obligation

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> AbiExample for T

Source§

default fn example() -> T

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

fn vzip(self) -> V