> For the complete documentation index, see [llms.txt](https://docs.hashstack.finance/developers/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hashstack.finance/developers/supply-and-borrow/supply.md).

# Supply

When a user supplies funds to the protocol, they receive rTokens. We use the following formula (as per EIP 4626) to calculate the number of tokens minted to the user.

$$
rTokens\_{new} = \frac{Asset\_{new} \cdot rTokens\_{total}}{Asset\_{total}}
$$

The formula uses existing total rTokens supply and Total asset supply to decide the quantity of rTokens to be minted as per the user deposit.

$$
Asset\_{total} = Asset.balanceOf(contract) + Assets\_{lent} + Interest\_{accrued}
$$

```jsx
// Definitions
Assets_lent => Assets borrowed by borrower contract to issue loans to the user
Interest_accrued => Interest recievable by suppliers since last update
```

The contract exposes the following features for user and open contracts to interact with:

1. **User:** Technically, a user can usually perform 3 main actions with supplier contract: Deposit, Withdraw & Transfer. User can further use the received rTokens as collateral to borrow or stake to earn higher yield.

<figure><img src="/files/sNp5Q5gfe2r4gHDV8RVY" alt=""><figcaption><p>Fig. 2 - Supply use-cases</p></figcaption></figure>

2. **Open:** The supply contract provides special privileges to the Open contract to allow it for some book-keeping. These options include:

* Accrue the interest
* Lock/unlock supply - to prevent the transfer of collateralised supply
* Transfer & withdraw supplied funds on the users behalf - to liquidate the loan
* Borrow and repay - to utilise funds to issue & close loans


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.hashstack.finance/developers/supply-and-borrow/supply.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
