# SLF Module

## Overview

The **SLF** module is the protocol's lending and fund pool management core, implementing three major functions: **liquidity provision, fixed-rate lending, and dynamic-rate lending**. It combines user-deposited liquidity with borrower collateral positions through static (fixed-rate) and dynamic (floating-rate) modes, providing funding utilization and interest distribution mechanisms for Looper & YT.

## Functions and Responsibilities

#### 1. Liquidity Provision

* Allow liquidity providers (LPs) to deposit tokens in exchange for shares
* Support deposit (depositShares), share redemption (withdrawShares), and amount-based redemption (withdrawAmount)
* Automatically accumulate LP earnings (totalEarning) and distribute by shares
* Protocol can extract a portion as protocol income (protocolEarning)

#### 2. Borrowing Mechanism (Looper & YT Only)

Support two modes:

**Fixed-Rate Borrowing (Static Borrow)**

* Borrowers agree on **fixed interest rates** and **maturity times** with the protocol
* Collateralize CCR when borrowing to obtain liquidity tokens
* Repay principal + fixed interest at maturity to redeem collateral
* Support premature processing to prepare for unstaking when approaching maturity

**Dynamic-Rate Borrowing (Dynamic Borrow)**

* Borrowing rates float in real-time based on fund pool utilization and market conditions
* Support additional borrowing (increaseDynamicBorrow), partial repayment (decreaseDynamicBorrow), and closure (closeDynamic)
* Interest rates and payable interest are updated before operations (upkeepUserDynamicInterest)

#### 3. Liquidity Pool Management

* Liquidity pools are available liquidity for specific token strategies
* Manage pool interest rate algorithm contracts (StaticInterestProvider / DynamicInterestProvider) and cap parameters (CapArgs)
* Can be dynamically updated by protocol administrators:
  * Interest rate parameters (updatePoolInterestArgs)
  * Cap parameters (updatePoolCapArgs)
  * Interest rate algorithm contract addresses

## Interactions and Dependencies

#### Liquidity Providers

* Deposit liquidity tokens to obtain shares
* Can redeem tokens and interest anytime
* Earnings distributed proportionally by shares

#### Borrowers (Looper & YT Only)

* Collateralize CCR to borrow liquidity tokens
* Can choose **fixed-rate** or **dynamic-rate** borrowing methods
* Can redeem collateral after repaying principal and interest according to rules

#### Liquidity Pools

* Manage correspondence between collateral tokens and liquidity tokens
* Configure interest rate calculation logic (static/dynamic)
* Track utilization ratios (borrowed amounts vs total available liquidity) for interest rate calculations and capacity management

#### Interest Providers

* **StaticInterestProvider**: Calculate term loan interest rates
* **DynamicInterestProvider**: Calculate demand loan interest rates
