# Delegation

### 🔄 P2P and Idle Liquidity

P2P lending on Rainfi works like an order book. Lenders create a pool, and their liquidity is made available to be borrowed based on the conditions they define.

However, whenever this liquidity isn’t borrowed, it generates **0% APY,** this is called **idle liquidity**.

To optimize returns, idle funds can be **delegated** to an external protocol that provides a constant yield. As soon as a borrower requests liquidity on Rainfi, the delegated funds are automatically undelegated and lent to the borrower.

***

### ⚙️ How It Works

1. A lender creates a pool on Rainfi to lend tokens.
2. On the pool page, the lender can access their available vaults and choose to delegate funds to generate yield until a borrow request occurs.

<div><figure><img src="/files/IfzUaWtWDt5aBJ7fpPGX" alt="" width="262"><figcaption></figcaption></figure> <figure><img src="/files/DWKl9NYdCKlQaImUp1kt" alt="" width="291"><figcaption></figcaption></figure></div>

1. Once delegation is activated for a vault:
   * All idle funds are automatically delegated every hour.
   * This includes new deposits, repaid loans, and earned interest.
   * This ensures optimized yield generation.
2. When a borrow request is made on Rainfi, the delegated funds are instantly undelegated and redirected to the borrower.

### 🛠️ Flexibility

Delegation gives each user full discretion to decide on which external platform they want to allocate their idle funds.


---

# 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.rain.fi/earn/delegation.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.
