# Deposit (Supply) Flow

#### Deposit (Supply) Flow

1. **User Deposits Collateral:** A user calls `deposit(asset, amount, onBehalfOf, referralCode)` on the LendingPool to supply an asset. The contract validates the deposit (e.g. amount > 0) and determines the corresponding aToken for that asset. It then updates the asset’s reserve state by accruing any pending interest: `updateState()` calculates how much interest has accumulated since last update and updates indices, also minting any protocol reserve interest to the treasury. Next, `updateInterestRates()` is called to recompute the new liquidity rate and borrow rates given the increased liquidity from this deposit. The underlying tokens are then transferred from the user into the aToken contract (using `safeTransferFrom`). The user receives aToken balance minted via `aToken.mint(onBehalfOf, amount, currentLiquidityIndex)`. If the user had no prior aToken balance, their deposit is now marked as collateral by default (making it available to borrow against). The result: the user holds aTokens, and the pool’s available liquidity increases by the deposit. The transaction emits a `Deposit` event recording the action. From now on, the user’s aTokens will increase in value as interest accrues (reflected by the growing liquidity index).
2. **Earning Interest:** Once deposited, interest begins accruing for the supplier. Interest is earned continuously based on the borrowing activity in that asset’s reserve. Technically, the accrual is applied by updating the reserve’s `liquidityIndex` over time: each time someone interacts with that reserve (deposit, withdraw, borrow, repay, etc.), the `updateState()` function uses the time elapsed and current rates to compound the index. A value of liquidityIndex > 1 indicates growth (e.g. 1.05 means a 5% gain has accumulated). The user’s **aToken balance** stays constant in token units, but when they withdraw or check balance, the index is applied to compute the *actual* amount of underlying asset they can redeem. For example, if a user deposited 100 USDC when the index was 1.0, they got 100 aUSDC. If the index rises to 1.1 (10% interest accrued) by the time they withdraw, their 100 aUSDC allows them to withdraw 110 USDC (100 \* 1.1). This mechanism spreads the interest earned by borrowers to all depositors fairly, proportional to their share of the pool.
3. **Rewards Accrual for Lender:** When the user deposited, the incentives controller was notified. The aToken’s internal logic calls `ChefIncentivesController.handleActionAfter(user, newBalance, totalSupply)` during the mint/transfer. The Chef controller updates the reward pool for that aToken address: it calculates any pending PRFI reward for the user and resets the user’s `rewardDebt` to match the new balance. From this point on, as long as the user holds the aToken, they will continue accumulating PRFI rewards each second. The global reward for the aToken pool increases over time (based on its allocation weight and the PRFI emission rate), and when other users deposit or withdraw, the relative shares update accordingly. The user can later claim their accumulated PRFI via the MultiFeeDistribution contract (which may allow direct claim or require locking, depending on PrimeFi’s settings). This reward is in addition to the interest APY the user earns from lending.


---

# 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.primefi.xyz/know-your-algorithm/operational-flow/deposit-supply-flow.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.
