> For the complete documentation index, see [llms.txt](https://docs.trilobyte.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.trilobyte.finance/protocol-mechanics/vault-lifecycle/raising-funds.md).

# RaisingFunds

The **RaisingFunds** phase is the initial state of every vault. During this phase, the vault is open for investor deposits — junior first, then senior once the junior tranche is locked.

## What Happens

* The manager's Globals-locked collateral is credited toward the **junior tranche** target the moment the vault is created
* **Junior investors** call `deposit(investor, amount, Tranche::Junior)` to fund the junior tranche, up to `junior_target`
* Once junior capital (manager credit + junior deposits) reaches `junior_target`, the manager calls `lock_junior(manager)` — this opens the vault to **senior deposits**. A senior deposit before `lock_junior` fails with `JuniorNotLocked`
* **Senior investors** call `deposit(investor, amount, Tranche::Senior)`, up to `senior_target`
* Every deposit mints **SEP-41 debt tokens** (tVLT) 1:1 with the **net** amount (after the protocol fee), and a **minimum-investment floor** (`min_investment`, default 100 USDC) rejects dust deposits
* An investor may hold a position in **both** tranches — each is tracked as a separate `InvestorPosition`
* In **permissioned vaults**, only allowlisted addresses can deposit; if the protocol's compliance gate is set, it is checked too

## Capital Raise, Step by Step

```mermaid
sequenceDiagram
  autonumber
  participant M as Manager
  participant JI as Junior investors
  participant SI as Senior investors
  participant V as Vault
  Note over V: junior_target credited from manager collateral
  JI->>V: deposit(amount, Tranche::Junior)
  V-->>JI: mint debt tokens (net of fee)
  Note over V: junior_raised + collateral_amount >= junior_target
  M->>V: lock_junior(manager)
  V-->>M: JuniorLocked event — senior deposits now open
  SI->>V: deposit(amount, Tranche::Senior)
  V-->>SI: mint debt tokens (net of fee)
  Note over V: junior_raised + senior_raised == principal
  V->>V: phase -> AwaitingApproval
```

## Key Rules

* A deposit above either tranche's target is rejected with `TrancheFull`
* Junior deposits remain open even after `lock_junior` is called, so the real junior target can still be reached (junior capital being locked only means it can no longer be **withdrawn**, not that new junior deposits stop being accepted)
* Investors can **withdraw** their senior deposit at any time during RaisingFunds. **Junior withdrawals are blocked once junior is locked** (`JuniorLocked`) — before that point, junior withdrawals are allowed like senior's
* The phase transitions automatically to **AwaitingApproval** once `junior_raised + senior_raised == principal`
* The vault caps the number of (investor, tranche) positions at `max_investors` (snapshotted from Globals' `max_investors_per_vault`, default 250) — further deposits fail with `TooManyInvestors`

## Funding Deadline

If the vault was created with a `funding_deadline`, the vault can be cancelled if it fails to raise the full principal by the deadline.

* Anyone can call `check_funding_expiry()` after the deadline passes
* The manager's locked collateral and any borrower pledge are released, **once** (O(1) — this no longer loops over every investor)
* The vault transitions to **Cancelled**
* Each investor then calls `claim_refund(investor, tranche)` for their own position(s), burning their own debt tokens — bounded cost regardless of how many other investors the vault has

{% hint style="warning" %}
If no funding deadline is set (`funding_deadline = 0`), the vault remains in RaisingFunds indefinitely until fully funded.
{% endhint %}

## Relevant Functions

| Function                              | Caller   | Description                                                                |
| ------------------------------------- | -------- | -------------------------------------------------------------------------- |
| `deposit(investor, amount, tranche)`  | Investor | Deposit funds into a tranche and mint debt tokens                          |
| `lock_junior(manager)`                | Manager  | Lock the junior tranche once it reaches target, opening senior deposits    |
| `withdraw(investor, amount, tranche)` | Investor | Withdraw a deposit and burn debt tokens (junior only before `lock_junior`) |
| `check_funding_expiry()`              | Anyone   | Move the vault to Cancelled if the funding deadline passed                 |
| `claim_refund(investor, tranche)`     | Investor | Pull your own refund after a Cancelled funding/approval expiry             |
| `add_to_allowlist(caller, investor)`  | Manager  | Add investor to allowlist (permissioned vaults)                            |

*As of September 2026.*
