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

# Earn Vault Flows

These diagrams follow each depositor and manager flow through the Loopscale app, the Loopscale APIs, and the underlying [Exponent Strategy Vault](https://docs.loopscale.com/protocol-concepts/earn-vault-architecture.md). Instruction names are from the Exponent vault program.

## Deposit

```mermaid theme={null}
sequenceDiagram
    actor U as Depositor
    participant App as Loopscale App
    participant P as Pandora API
    participant J as Jito
    participant V as Vault program
    participant SQ as Squads vault

    U->>App: Choose vault and amount
    opt Vault requires acknowledgment
        App->>U: Show terms
        U->>App: Accept (recorded once per wallet)
    end
    App->>P: POST /earn/vaults/deposit/tx
    P-->>App: [AUM refresh tx, deposit tx]
    App->>U: Sign both
    U->>J: Submit as one bundle
    J->>V: tx 1: update prices, refresh_aum
    J->>V: tx 2: deposit_liquidity(amount, min_lp_out)
    V->>SQ: Move tokens into the Squads token account
    V->>U: Mint shares at NAV per share
```

What happens:

* Shares minted = deposit value × share supply ÷ total AUM, computed against the AUM refreshed earlier in the same slot.
* The deposit reverts if it would mint fewer than `min_lp_out` shares or push the vault past its deposit cap.
* Deposited capital starts in the vault's reserves. The allocator then deploys it according to the strategy.

## Queued Withdrawal

```mermaid theme={null}
sequenceDiagram
    actor U as Depositor
    participant App as Loopscale App
    participant P as Pandora API
    participant V as Vault program
    actor M as Manager
    participant SQ as Squads vault

    U->>App: Withdraw N shares (queued)
    App->>P: POST /earn/vaults/withdraw_request/tx (mode: queued)
    P-->>App: [AUM refresh tx, request tx], requestId
    U->>V: queue_withdrawal(N) (bundle)
    V->>V: Move shares to escrow, create withdrawal account

    Note over M,SQ: Before the window deadline
    M->>SQ: Unwind positions if reserves are short
    M->>V: fill_withdrawal (via Squads policy)
    V->>V: Record fills (token entry, share of request)

    Note over U,V: After the withdrawal period unlocks
    U->>App: Claim
    App->>P: POST /earn/vaults/withdraw_claim/tx
    U->>V: execute_withdrawal (bundle)
    V->>U: Pay out filled tokens, burn escrowed shares
```

* A request can be filled in several partial fills, and each fill can pay out in a different token entry.
* Claiming needs both a fill and an unlocked withdrawal period (a lock interval, or the vault's scheduled withdrawal days).
* The manager has to clear queued requests before each window closes. If they don't, the vault blocks new manager actions until they do.

### Cancelling a request

```mermaid theme={null}
sequenceDiagram
    actor U as Depositor
    participant P as Pandora API
    participant V as Vault program

    U->>P: POST /earn/vaults/withdraw_cancel/tx (requestId)
    P-->>U: [AUM refresh tx, cancel tx]
    U->>V: cancel_withdrawal (bundle)
    V->>U: Return escrowed shares
```

Cancelling is only possible on vaults that allow it, after the vault's cancel cooldown, and (in the Loopscale app) only before any part of the request has been filled.

## Instant Withdrawal

```mermaid theme={null}
sequenceDiagram
    actor U as Depositor
    participant App as Loopscale App
    participant P as Pandora API
    participant V as Vault program
    participant SQ as Squads vault

    U->>App: Withdraw N shares (instant)
    App->>App: Check instant capacity
    App->>P: POST /earn/vaults/withdraw_request/tx (mode: instant)
    P-->>App: [AUM refresh tx, withdraw tx]
    U->>V: execute_withdrawal_from_reserves(entry, N) (bundle)
    V->>V: Burn shares, apply withdrawal + instant fee
    SQ->>U: Pay out from reserves
```

Instant withdrawals skip the queue but are limited by available reserves and the vault's per-window instant cap (see [Withdrawals](https://docs.loopscale.com/protocol-concepts/earn-vault-architecture.md#withdrawals)). The instant fee stays in the vault, compensating remaining depositors for the drain on liquidity.

## Strategy Rebalance (Manager)

```mermaid theme={null}
sequenceDiagram
    actor A as Allocator
    participant SQ as Squads
    participant Venue as Venue (e.g. Kamino, Loopscale)
    participant V as Vault program

    A->>SQ: Propose instruction(s) under a policy
    SQ->>SQ: Match against policy (program, accounts, data)
    SQ->>Venue: Execute as Squads vault
    SQ->>V: Post-hook: validate_interaction_hook
    V->>V: Check reserves floor, slippage, NAV change, balances
    alt Invariants hold
        V-->>SQ: OK, transaction commits
    else Any check fails
        V-->>SQ: Error, whole transaction reverts
    end
```

Depositors never sign rebalances. Their protection comes from the policy whitelist and the post-hook checks running atomically with every action.

## Parameter Change (Governance)

```mermaid theme={null}
sequenceDiagram
    actor M as Manager
    participant V as Vault program
    actor H as Share holders
    actor Any as Anyone

    M->>V: init_proposal, append_proposal_actions
    M->>V: activate_proposal (voting starts)
    H->>V: stake_vote (Reject or Opt Out)
    Note over V: Voting period ends
    Any->>V: finalize_proposal
    alt Rejections below threshold
        Note over V: Approved, then timelock
        Any->>V: execute_proposal
        V->>V: Apply settings / policy changes
        V->>H: Opt Out voters' shares are queued for withdrawal
    else Rejections reach threshold
        Note over V: Rejected, nothing changes
    end
```

Changes to fees, reserves, withdrawal schedule, deposit cap, roles, token entries, and policies all take this path once a vault holds depositor capital.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.