# Computing Supply & Borrows

**Monitoring Instructions:**

* RefreshReserve - handles all the tracking work and updates ratio
* RefreshObligation - computes obligation balances based on reserve ratios

**For Supply:**

* cToken Ratio acts as a % ownership of the LP
* For a pool with 99 USDC, if you deposit 1 USDC, you will own 1% of the pool
* When the RefreshReserve occurs, the pool now has 110 USDC. Your 1% is now worth 1.1 USDC.
* Total Reserves / cTokens Minted&#x20;

**For Borrows:**

* APY is used to update CumulativeBorrowRate as an index
* When borrowing, calculate the initial CumulativeBorrowRate (let's say 1)
* RefreshReserve → Updates the CumulativeBorrowRate (let's say its 1.02)
* Obligation borrows would be increased by \*1.02/1 or 2%

```
/// Compound current borrow rate over elapsed slots
    fn compound_interest(
        &mut self,
        current_borrow_rate: Rate,
        slots_elapsed: u64,
    ) -> ProgramResult {
        let slot_interest_rate = current_borrow_rate.try_div(SLOTS_PER_YEAR)?;
        let compounded_interest_rate = Rate::one()
            .try_add(slot_interest_rate)?
            .try_pow(slots_elapsed)?;
        self.cumulative_borrow_rate_wads = self
            .cumulative_borrow_rate_wads
            .try_mul(compounded_interest_rate)?;
        self.borrowed_amount_wads = self
            .borrowed_amount_wads
            .try_mul(compounded_interest_rate)?;
        Ok(())
    }
}
```

**Why**: For efficiency, the RefreshReserve just has to update the cToken Rate or the CumulativeBorrowRate instead of updating every obligation’s supply or borrow numbers. Tracking is only done at the ratio/index level, and never at an individual level unless changes to the user's positions are being made.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.save.finance/architecture/computing-supply-and-borrows.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
