# Protocol Math

## Calculating Accrued Interest <a href="#calculating-accrued-interest" id="calculating-accrued-interest"></a>

Interest rates for each market update on any block in which the ratio of borrowed assets to supplied assets in the market has changed. The amount interest rates are changed depends on the interest rate model smart contract implemented for the market, and the amount of change in the ratio of borrowed assets to supplied assets in the market.

Here is an example of borrow interest accrual:

Alice borrows 1 ETH from Panwfi Lending Market. At the time of borrow, the borrow interest is 0.000000000037893605 ETH per block. No one interacts with the iEther contract for 3 Ethereum blocks. On the subsequent 4th block, Bob borrows some ETH. Alice’s underlying balance is now 1.000000000151574420 ETH (which is 0.000000000037893605 times 4 blocks, plus the original 1 ETH). Alice’s underlying ETH balance in subsequent blocks will have interest accrued based on the new value of 1.000000000151574420 ETH instead of the initial 1 ETH. Note that the borrow rate per block value may change at any time.

That is, the interest will only be compounded whenever there is an interaction with each market. If there is no interaction with the market (let's say USDT), the supply and borrow APY for USDT will be calculated as simple interest.&#x20;

## Calculating the front-end APY Using Rate Per Block <a href="#calculating-the-apy-using-rate-per-block" id="calculating-the-apy-using-rate-per-block"></a>

The Annual Percentage Yield (APY) for supplying or borrowing displaying in each market can be calculated using the value of supply or borrow APY in smart contract with this formula:

```solidity
Rate = APY; // rate in smart contract
Blocks Per Year = 2102400
Blocks Per Day = 6570 (13.5 seconds per block)
Days Per Year = 365

APY = ((((Rate / Blocks Per Year * Blocks Per Day + 1) ^ Days Per Year)) - 1) * 100
```


---

# 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.pawnfi.com/risk/risk-framework/lending-market-liquidity-risk/protocol-math.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.
