# CLOB Lending Protocol

### 📖 Centuari Protocol — deCentalized Lending Order Book (CLOB) Matching Engine

#### 📌 Overview

In traditional DeFi lending protocols, liquidity provision and borrowing often rely on **pooled automated market makers (AMMs)** or static peer-to-pool models. However, Centuari innovates by integrating a **Central Limit Order Book** as its core matching infrastructure, enabling lenders and borrowers to directly submit and compete through limit orders. While it follows the foundational mechanics of traditional CLOB systems as found in spot or perpetual trading it adapts them specifically for fixed-rate lending use cases.

This allows the protocol to achieve:

* **Dynamic interest rate discovery**
* **Composable order-based lending markets**

***

#### 📌 How It Works: Lender & Borrower Matching

In Centuari:

* **Lenders** submit _lend orders_, specifying the amount of assets they’re willing to lend, the fixed interest rate, and market duration.
* **Borrowers** submit _borrow orders_, detailing how much they wish to borrow, the maximum rate they’re willing to pay, and the loan period.
* Centuari supports two primary order types **Market Order & Limit Order.**

Once a match occurs:

* The system locks the lender’s liquidity.
* The position is opened, and repayment obligations are tracked.

***

#### Limit Order

A **Limit Order** allows users to specify a target **interest rate**.

* A **lender** can place a limit order to lend at a specific minimum rate. The order will only be matched if a borrower accepts that rate or better.
* A **borrower** can place a limit order to borrow at a specific maximum rate. The order remains pending until a lender is willing to lend at that rate or lower.

Limit orders are stored on the order book and follow a matching logic based on rate priority (best rate first)

#### Market Order

A **Market Order** is executed immediately against the best available rate in the order book.

* If the user acts as a **lender**, the system will automatically match their order with the **highest available rate** offered by borrowers at that moment.
* If the user acts as a **borrower**, the system will match their order with the **lowest available rate** offered by lenders.



#### 📌 Why Use a CLOB for DeFi Lending?

| **Advantage**             | **Explanation**                                                                     |
| ------------------------- | ----------------------------------------------------------------------------------- |
| **True Market Discovery** | Rates are set by supply and demand through visible limit orders, not static curves. |
| **Order Customization**   | Lenders and borrowers can specify exact terms: amount, duration, rate.              |
| **Composability**         | CLOB integrates smoothly with underwriting and oracle validation processes.         |
| **Capital Efficiency**    | Orders remain open until matched — no idle capital stuck in a pool.                 |

***

#### 🧠 Order Book Engine: Powered by Solady

Centuari’s order book is implemented using the highly efficient and gas-optimized **Solady** library. Solady provides low-level utilities and data structures that enable:

* Fast and deterministic matching logic
* Efficient storage of order state
* Minimal gas overhead for execution and cancellation

This foundation ensures that the Centuari CLOB is not only trustless and transparent, but also performant enough for high-frequency order flow in a lending environment. Read more [here](clob-lending-protocol/interactive-blocks).

## Conceptual Process Flow

### Borrower:

1. **Submit Order**\
   The borrower submits a _market_ or _limit_ order to borrow funds.
2. **Collateral Supplied**\
   The borrower provides collateral (e.g., ETH, WBTC) which is securely stored in the smart contract.
3. **CLOB Matching Engine Activated**
   * For _market orders_, the system searches for the **lowest available lending rate**.
   * For _limit orders_, the order is added to the queue based on the specified borrowing rate.
4. **Order Matched**\
   Once a match is found, the borrower receives the requested loan amount.
5. **Debt Position Recorded**\
   The protocol records the loan parameters: borrower address, borrowed amount, interest rate, and maturity.
6. **Repayment or Liquidation**
   * If repayment is made on time, the collateral is returned to the borrower.
   * If the borrower defaults, the position becomes eligible for liquidation.

### Lender:

1. **Submit Order**\
   The lender submits a _market_ or _limit_ order to lend funds.
2. **Funds Deposited**\
   The lender transfers funds (e.g., USDC) to the contract as part of the order placement.
3. **CLOB Matching Engine Activated**
   * For _market orders_, the system looks for the **highest available borrowing rate**.
   * For _limit orders_, the funds are queued by the rate set by the lender.
4. **Order Matched**\
   When a borrower match is found, the funds are lent out instantly.

* **Receive CBT Token**\
  The lender receives a **CBT (Centuari Bond Token)** representing their active lending position.
* **Borrow Share Allocation**\
  The lender receives a proportionate share of the lending pool, used for debt accounting and interest accrual.
* **Redemption with Interest**\
  Upon successful loan repayment by the borrower, the lender receives the principal and interest based on the agreed rate and maturity.

***
