# How a Loan Works

A Trilobyte loan follows a structured lifecycle from creation to settlement. Here's how a typical loan flows through the protocol.

## Step-by-Step

### 1. Vault Creation

A **Pool Manager** evaluates a business's creditworthiness and negotiates loan terms off-chain. Once agreed, the manager creates a vault via the **Factory** contract with the following parameters:

* **Principal** — The loan amount (e.g. 100,000 USDC)
* **Interest rate** — Annual rate in basis points (e.g. 1000 = 10%)
* **Loan term** — Duration in months (e.g. 12)
* **Split ratio** — Percentage of each repayment routed to the EMI pool for investors (e.g. 80%)
* **Funding deadline** — Optional deadline for full funding
* **Approval deadline** — Optional deadline for manager approval after funding
* **Grace period** — Window before default can be triggered after a missed payment
* **Permissioned** — Whether only allowlisted investors can participate

The Factory validates all parameters against global settings, checks the manager's collateral and credit limit, and deploys a new Vault smart contract.

### 2. Fundraising

The vault enters the **RaisingFunds** phase. Investors deposit funds and receive **SEP-41 debt tokens** at a 1:1 ratio. A 0.5% protocol fee is deducted from each deposit.

The vault automatically transitions to **AwaitingApproval** once the full principal is raised.

{% hint style="info" %}
If a funding deadline is set and the vault fails to raise the full principal by that date, anyone can call `check_funding_expiry()` to cancel the vault and refund all investors.
{% endhint %}

### 3. Approval & Disbursement

The **Pool Manager** reviews the funded vault and calls `approve_and_disburse`. This:

* Disburses the funded amount to the borrower
* Calculates the EMI (Equated Monthly Instalment)
* Sets the first payment due date (30 days from disbursement)
* Transitions the vault to **Active**

{% hint style="info" %}
If an approval deadline is set and the manager fails to approve by that date, anyone can call `check_approval_expiry()` to cancel the vault and refund investors.
{% endhint %}

### 4. Repayments

The **Borrower** makes periodic repayments. Each payment is processed as follows:

1. A 0.5% protocol fee is deducted and sent to the treasury
2. The remainder is split by the `split_ratio`:
   * **EMI pool** — Investor yield (e.g. 80%)
   * **Cash pool** — Borrower operating capital (e.g. 20%)
3. The outstanding principal is amortised
4. The payment counter advances and the next due date is set

### 5. Yield Distribution

**Investors** can call `claim_yield` at any time during the Active or FullyRepaid phases to claim their pro-rata share of the EMI pool. An investor's share is proportional to their debt token balance relative to the total supply.

$$
\text{claimable} = \frac{\text{balance}}{\text{total\_supply}} \times \text{emi\_pool} - \text{already\_claimed}
$$

### 6. Settlement

When all payments are made, the vault transitions to **FullyRepaid**. The manager's collateral is released. Once all investors have claimed their yield and the borrower has withdrawn remaining cash, the vault can be finalised — transitioning to the terminal **Finalized** state.

## Visual Overview

```
Pool Manager creates vault
         │
         ▼
    ┌─────────────┐
    │ RaisingFunds │ ◄── Investors deposit
    └──────┬──────┘
           │ fully funded
           ▼
   ┌───────────────┐
   │AwaitingApproval│ ◄── Manager reviews
   └───────┬───────┘
           │ approve & disburse
           ▼
      ┌────────┐
      │ Active │ ◄── Borrower makes payments
      └───┬────┘     Investors claim yield
          │
    ┌─────┴──────┐
    │            │
    ▼            ▼
┌──────────┐ ┌───────────┐
│FullyRepaid│ │ Defaulted │
└────┬─────┘ └───────────┘
     │
     ▼
 ┌──────────┐
 │ Finalized │
 └──────────┘
```


---

# 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.trilobyte.finance/overview/how-a-loan-works.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.
