Struct tulipv2_sdk_common::lending::obligation::Obligation
source · [−]pub struct Obligation {Show 15 fields
pub version: u8,
pub last_update: LastUpdate,
pub lending_market: Pubkey,
pub owner: Pubkey,
pub deposits: Vec<ObligationCollateral>,
pub borrows: Vec<ObligationLiquidity>,
pub borrowed_value: Decimal,
pub vault_shares: u64,
pub lp_tokens: u64,
pub coin_deposits: u64,
pub pc_deposits: u64,
pub deposits_market_value: Decimal,
pub lp_decimals: u8,
pub coin_decimals: u8,
pub pc_decimals: u8,
}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: PubkeyVault address the obligation is associated with 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
borrowed_value: DecimalMarket value of deposits Market value of borrows
The maximum borrow value at the weighted average loan to value ratio The dangerous borrow value at the weighted average liquidation threshold vault shares
lp_tokens: u64the number of lp token shares owned by this obligation when calculating loan to value ratio for obligations which have been used to borrow lp tokens, we calculate LTV using the pseudo deposits value instead of collateral value
coin_deposits: u64the number of coin tokens owned by this obligation coin is wrt the lp token for this obligation this is used for deposit value when calculating LTV
pc_deposits: u64the number of pc tokens owned by this obligation pc is wrt the lp token for this obligation this is used for deposit value when calculating LTV
deposits_market_value: Decimalthe market value of the user deposits includes lp (pseudo deposits), coin and pc tokens
lp_decimals: u8the lp token pyth price account address the pc / quote pyth price account address Decimals in lp token
coin_decimals: u8Decimals in coin
pc_decimals: u8Decimals in pc
Implementations
sourceimpl 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 pseudo_loan_to_value(&self) -> Result<Decimal, ProgramError>
pub fn pseudo_loan_to_value(&self) -> Result<Decimal, ProgramError>
Calculate the current ratio of borrowed value using their pseudo deposited value instead of deposited value, allowing us to measure LTV using lp token value instead
todo(bonedaddy): add a test for this function
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) -> Result<Decimal, ProgramError>
pub fn max_withdraw_value(&self) -> 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_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
sourceimpl Clone for Obligation
impl Clone for Obligation
sourcefn clone(&self) -> Obligation
fn clone(&self) -> Obligation
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more