> ## Documentation Index
> Fetch the complete documentation index at: https://docs.saffron.finance/llms.txt
> Use this file to discover all available pages before exploring further.

# Vault Lifecycle

> How vaults are created, funded, and settled on-chain.

### Phase 0: Vault Creation

<Note>
  These steps assume a `VaultFactory` has already been deployed and configured with valid vault and adapter types.
</Note>

Vault creation is a three-step process:

1. `createAdapter(adapterTypeId, poolAddress, data)` — Deploys and initializes an adapter for a specific Uniswap V3 pool
2. `createVault(vaultTypeId, adapterAddress)` — Deploys a vault; caller must own the adapter, and the adapter must not already be linked to a vault
3. `initializeVault(vaultId, fixedSideCapacity, variableSideCapacity, duration, variableAsset, expectedFeeBps)` — Sets the vault parameters and binds the adapter

Only the factory owner can perform these actions.

### Phase 1: Depositing

Two deposit paths exist: fixed side and variable side.

#### Fixed Side

`vault.deposit(amount, FIXED, deployCapitalData)`

* The `amount` must be 0 — token amounts are derived from `fixedSideCapacity` and current pool price
* `deployCapitalData` encodes slippage protection (`amount0Min`, `amount1Min`) and a transaction `deadline`
* Adapter mints a Uniswap V3 LP position; depositor receives 1 `claimToken`
* There is only one fixed side depositor per vault

#### Variable Side

`vault.deposit(amount, VARIABLE, deployCapitalData)`

* Mints `variableBearerToken` 1:1 with the deposit
* `deployCapitalData` optionally encodes a minimum accepted amount (for partial fills near capacity)

Balances are tracked against `fixedSideCapacity` and `variableSideCapacity`.

### Phase 2: Vault Start

Once both sides reach capacity, the vault starts automatically.

### Phase 3: Earning Period

The Uniswap V3 position accrues trading fees for the configured duration. No withdrawals are permitted during this phase.

After the vault starts, the fixed side depositor may claim their premium:

`vault.claim()`

* Transfers a proportional share of variable side deposits (the fixed premium) to the caller
* Burns the caller's `claimToken` and mints an equivalent `fixedBearerToken`
* Can be called at any time after the vault starts

### Phase 4: Settlement and Withdrawal

Once maturity is reached, the first withdrawal triggers `settleEarnings()` and mints the protocol fee (in `variableBearerToken` to the vault for the current `feeReceiver()`).

#### Fixed Side

`vault.withdraw(FIXED, removeLiquidityData)`

* Removes all liquidity from Uniswap V3 and returns the underlying tokens (`token0` and `token1`) to the depositor

#### Variable Side

`vault.withdraw(VARIABLE, "")`

* Returns a proportional share of the Uniswap trading fees collected during the vault's lifetime, minus the protocol fee
