# 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="https://2770293654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FP0GgzuaAMRXFbXDPKHfP%2Fuploads%2F7iPG4LXHXnupwF2kWU0w%2Fimage%20(1).png?alt=media&#x26;token=4a9c489f-ee46-426d-94b3-a36073fdfd2e" alt="" width="262"><figcaption></figcaption></figure> <figure><img src="https://2770293654-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FP0GgzuaAMRXFbXDPKHfP%2Fuploads%2FdvGOrdBTg9FMEvFVRKLn%2Fimage.png?alt=media&#x26;token=f697d331-9091-474a-a0d2-11f8bab06eb1" 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.
