Larix
  • Who is Larix
  • Community
  • Roadmap
  • Product Update
  • Monthly Report
    • Larix Monthly Report [Oct]2021
    • Larix Monthly Report [Nov]2021
    • Larix Monthly Report [Dec]2021
    • Larix Monthly Report [Jan ]2022
    • Larix Monthly Report [Feb] 2022
    • Larix Monthly Report [Mar] 2022
    • Larix Monthly Report [April] 2022
    • Larix Monthly Report [May] 2022
  • FAQ
    • General FAQ
    • Raydium LPs FAQ
    • Error Explanation
    • Trouble shooting
    • Liquidation
  • PROTOCOL
    • Mainnet
      • Main Pool
        • Addresses
      • Lending Launchpad
        • Bonfida Pool
        • xSOL Pool
        • LARIX Pool
        • Step Pool
        • Stepn Pool
    • Devnet
  • Larix Guide
    • Step 1: Get Wallet
    • Step 2: Connect Wallet
    • Step 3: Deposit
    • Step 4: Borrow
    • Step 5: Repay
    • Step 6: Withdraw
    • Step 7: Claim rewards
  • Interest Rate Model
  • Mathematics
    • APY
    • Mining
    • Price Feed
    • Obligation Health
  • Function
  • Design and Principle of the Liquidation
  • Access Controls
  • Security
    • Bug Bounty Reward
    • Audit
    • Oracles
  • Tokenomics
    • LARIX
    • Buy LARIX
      • b30LARIX
    • Larix Distribution
    • LARIX Token Distribution Rate Model
  • Risk
    • Risk Framework
    • Asset Risk
    • Liquidity Risk
    • External Audits & Analysis
  • API
    • Instruction
    • Function
    • Query
      • Logo
      • State
      • Reserve
      • Mining
      • Obligation
      • SDK
Powered by GitBook
On this page

Was this helpful?

  1. Mathematics

Obligation Health

Shows if you have the risk to be liquidated.

PreviousPrice FeedNextFunction

Last updated 3 years ago

Was this helpful?

For each obligation

Coding

let deposit_reserve_info = next_account_info(account_info_iter)?;
if deposit_reserve_info.owner != program_id {
    msg!(
         "Deposit reserve provided for collateral {} is not owned by the lending program",
         index
            );
return Err(LendingError::InvalidAccountOwner.into());
        }
        
if collateral.deposit_reserve != *deposit_reserve_info.key {
    msg!(
        "Deposit reserve of collateral {} does not match the deposit reserve provided",
        index
            );
return Err(LendingError::InvalidAccountInput.into());
        }
let deposit_reserve = Reserve::unpack(&deposit_reserve_info.data.borrow())?;
if deposit_reserve.last_update.is_stale(clock.slot)? {
    msg!( "Deposit reserve provided for collateral {} is stale and must be refreshed in the current slot",
    index);
return Err(LendingError::ReserveStale.into());}
// @TODO: add lookup table https://git.io/JOCYq
let decimals = 10u64
.checked_pow(deposit_reserve.liquidity.mint_decimals as u32)
.ok_or(LendingError::MathOverflow)?;
let market_value = deposit_reserve
.collateral_exchange_rate()?
.decimal_collateral_to_liquidity(collateral.deposited_amount.into())?
.try_mul(deposit_reserve.liquidity.market_price)?
.try_div(decimals)?;
collateral.market_value = market_value;
for (index, liquidity) in obligation.borrows.iter_mut().enumerate() {
    let borrow_reserve_info = next_account_info(account_info_iter)?;
    if borrow_reserve_info.owner != program_id {
        msg!("Borrow reserve provided for liquidity {} is not owned by the lending program",
        index
    );
return Err(LendingError::InvalidAccountOwner.into());
        }
if liquidity.borrow_reserve != *borrow_reserve_info.key {
msg!(
 "Borrow reserve of liquidity {} does not match the borrow reserve provided",
  index
);
return Err(LendingError::InvalidAccountInput.into());
}
let borrow_reserve = Reserve::unpack(&borrow_reserve_info.data.borrow())?;
if borrow_reserve.last_update.is_stale(clock.slot)? {
  msg!(
"Borrow reserve provided for liquidity {} is stale and must be refreshed in the current slot",
  index
);
return Err(LendingError::ReserveStale.into());
}
liquidity.accrue_interest(borrow_reserve.liquidity.cumulative_borrow_rate_wads)?;

// @TODO: add lookup table https://git.io/JOCYq
let decimals = 10u64
.checked_pow(borrow_reserve.liquidity.mint_decimals as u32)
.ok_or(LendingError::MathOverflow)?;
        
let market_value = liquidity
.borrowed_amount_wads
.try_mul(borrow_reserve.liquidity.market_price)?
.try_div(decimals)?;
liquidity.market_value = market_value;

borrowed_value = borrowed_value.try_add(market_value)?;
    }