> For the complete documentation index, see [llms.txt](https://docs.accountable.capital/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.accountable.capital/accountable-documentation/vault-as-a-service/deposit-gateway.md). Agents can also search and read this documentation through its [MCP server](https://docs.accountable.capital/~gitbook/mcp).

# Deposit gateway

## Deposit Gateway

#### Overview

A **batched, NAV-fair deposit layer** in front of an `Accountable NAV` vault. Because the vault prices deposits synchronously, a deposit mints shares at the share price live at deposit time, and that price only moves when the NAV is updated via the DVN.

The Deposit Gateway introduces a subscription window, in which assets are escrowed off-vault and grouped into **epochs**. An epoch closes when NAV is published, and only then are its deposits minted, at the post-NAV price. Once a vault's gateway is set, retail users can no longer deposit into the vault directly, the gateway becomes the sole permitted depositor.

Redemptions are unchanged and continue through the vault's existing async redeem queue.

**Deposit Model — Open-Ended Epochs**

Users subscribe into **epochs**, not directly into the vault:

* Epoch *N* **opens** on the first `requestDeposit` when no epoch is open. At most **one epoch is Open** at a time.
* More users deposit into epoch *N* while it stays Open. Assets are escrowed in the gateway
* When the NAV is executed, the strategy invokes `gateway.onNavUpdate()`, which marks epoch *N* **Passed** and stamps the closing NAV.
* The next `requestDeposit` opens epoch *N+1*, so post-NAV subscriptions are isolated and price at the **next** valuation.

**Epoch Lifecycle**

{% code expandable="true" %}

```mermaid
stateDiagram-v2
    [*] --> None
    None --> Open: first requestDeposit
    Open --> Passed: onNavUpdate / forcePassEpoch / auto-heal
    Open --> Settled: pass with pendingCount = 0
    Passed --> Settled: all requests minted or refunded
    Passed --> Invalid: newer NAV before any settle
    Invalid --> Settled: all requests refunded
```

{% endcode %}

| Status      | Meaning                                                                 | Accepts deposits                    | Accepts cancellations |
| ----------- | ----------------------------------------------------------------------- | ----------------------------------- | --------------------- |
| **None**    | Id never opened                                                         | —                                   | —                     |
| **Open**    | Active subscription window                                              | Yes (into this epoch)               | Yes (two-step)        |
| **Passed**  | Closed at NAV, awaiting settle                                          | No (next deposit opens a new epoch) | No                    |
| **Invalid** | Settlement window missed, a newer NAV published after this epoch passed | No                                  | No                    |
| **Settled** | Every request minted or refunded                                        | No                                  | No                    |

**NAV Integration**

The gateway hooks the same DVN-driven publish-execute flow that updates the vault's NAV:

1. DVN publishes M-of-N NAV observations
2. The median value is executed by a designated role
3. This calls `strategy.publishRate(...)`. The strategy updates NAV.
4. The strategy then calls `gateway.onNavUpdate()`. The hook is **storage-only** — it marks the Open epoch Passed, stamps `navMeasuredAt`, and clears the open-epoch.

This is the only strategy → gateway call. `onNavUpdate` never deposits or settles, settlement is a separate transaction.

**Recovery (missed hook).** If `onNavUpdate` is skipped (caught) and the epoch stays Open across a NAV, the condition is detected by `strategy.lastNavMeasuredAt() > epoch.openNavMeasuredAt`. It is closed by either:

* **`forcePassEpoch()`** — permissionless; reverts (`NoMissedNavUpdate`) if there is no open epoch or no newer NAV, or
* **Auto-heal** — the next `requestDeposit` passes the stale epoch and opens a fresh one for the incoming deposit.

Both stamp `navMeasuredAt` exactly like a normal pass.

**Settlement — Mint Directly to Users**

Settlement uses a **push / mint-to-user** model. For each request, the gateway calls `vault.deposit(req.assets, req.user, gateway)`: assets come from gateway escrow, shares are minted straight to the depositor.

```
sharesMinted = assets × PRECISION / postNavSharePrice
```

where `postNavSharePrice` is the share price live at settle (i.e. after the `NAV update` that closed the epoch). The epoch is closed, so depositors cannot influence it.

| Settlement case                                   | Outcome                                                                             |
| ------------------------------------------------- | ----------------------------------------------------------------------------------- |
| Epoch not `Passed`                                | Reverts (`EpochNotPassed`)                                                          |
| Passed, no newer NAV since pass                   | Per-request mint; per-request failures skipped                                      |
| Passed, **newer NAV** published since pass        | Epoch → **Invalid** on first settle attempt; **no mints**; all requests must refund |
| Strategy paused / NAV stale                       | Request skipped; not a refund trigger by itself                                     |
| User de-whitelisted                               | Request skipped; stays refundable                                                   |
| Paginated / partial batch                         | Epoch stays Passed until `pendingCount == 0`                                        |
| Empty, duplicate, foreign, or already-handled ids | Skipped                                                                             |

> **Settlement window.** An epoch must settle before the **next** `published NAV`. If keepers miss that window, the epoch is invalidated rather than minting at an unintended later price.

**Request Lifecycle**

Each `requestDeposit` returns a monotonic `requestId`.

```mermaid
stateDiagram-v2
    [*] --> Escrowed: requestDeposit (Open epoch)
    Escrowed --> Refunded: cancel approved (Open only)
    Escrowed --> AwaitingDelivery: epoch passes
    AwaitingDelivery --> Settled: settle mints shares
    AwaitingDelivery --> Refunded: undeliverable -> refund
```

| Terminal state | User has                                | Gateway holds            |
| -------------- | --------------------------------------- | ------------------------ |
| **Settled**    | Vault shares (minted to `request.user`) | Nothing for this request |
| **Refunded**   | Original underlying returned            | Nothing for this request |

A Passed request that failed settle (e.g. de-whitelisted) stays escrowed and **refundable** while objectively undeliverable, but can still become **Settled** if conditions improve (re-whitelist, then settle).

**Subscription Intake**

`requestDeposit(assets)` validates, in order: gateway is accepting requests, caller is whitelisted (on a Whitelist vault), `state == OngoingDynamic`, `assets >= strategy.loan().minDeposit` and the vault `MIN_AMOUNT_WEI`, and capacity in additive form `assets + unsettledEscrow <= strategy.maxDeposit(vault, gateway)`. The additive check reserves capacity at request time so accepted escrow can never be over-capacity at settle.

| Case                                               | Outcome |
| -------------------------------------------------- | ------- |
| `acceptingRequests == false`                       | Reverts |
| Not whitelisted (Whitelist vault)                  | Reverts |
| `loanState != OngoingDynamic`                      | Reverts |
| Below `minDeposit` or vault `MIN_AMOUNT_WEI`       | Reverts |
| Would exceed capacity (incl. all unsettled escrow) | Reverts |

**Cancellation (Open epoch only)**

A two-step flow, **off by default** until the manager enables it:

1. User calls `requestCancelDeposit(requestId)` — sets `cancelPending`, escrow unchanged.
2. The manager calls `approveCancelDeposit(requestId)` — returns assets, decrements epoch totals

Cancellation is impossible once an epoch passes, an undeliverable request then exits through refund.

**Refunds**

`refund(requestId)` is **permissionless but only when the request objectively cannot settle**, so a deliverable request can never be refunded. This removes both operator censorship and any post-NAV free option. Escrow always returns to `request.user`, never the caller.

Use the view `refundable(epochId, user, assets)` to drive a refund success, it mirrors the on-chain checks (except the depositor-only pause/stale rule).

**Access Control**

| Action                                               | Caller                                                        |
| ---------------------------------------------------- | ------------------------------------------------------------- |
| `requestDeposit`                                     | Any user passing intake checks                                |
| `requestCancelDeposit`                               | Request owner (requires `acceptingCancellations`)             |
| `approveCancelDeposit`                               | Strategy manager                                              |
| `onNavUpdate`                                        | Strategy only                                                 |
| `forcePassEpoch`                                     | Permissionless (guarded by missed-NAV check)                  |
| `settle`                                             | Permissionless (paginated)                                    |
| `refund`                                             | Permissionless when eligible, pause/stale case depositor-only |
| `setAcceptingRequests` / `setAcceptingCancellations` | Manager                                                       |
| Direct `vault.deposit`                               | Blocked once `depositGateway` is set                          |

#### Visualization

```mermaid
sequenceDiagram
    actor U as Depositors
    actor K as Keeper
    participant G as DepositGateway
    participant S as AccountableYield
    participant V as Vault
    participant D as DVN

    U->>G: requestDeposit
    Note over G: Open epoch N, escrow, pendingCount++

    D->>S: publishRate
    S->>G: onNavUpdate
    Note over G: epoch N Passed, navMeasuredAt stamped

    U->>G: requestDeposit
    Note over G: Open epoch N+1

    loop paginated settle
        K->>G: settle(N, requestIds)
        G->>V: deposit per request to user
        V-->>U: shares minted
    end
    Note over G: epoch N Settled when pendingCount = 0

    opt undeliverable or Invalid
        U->>G: refund(requestId)
        G-->>U: assets returned
    end
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.accountable.capital/accountable-documentation/vault-as-a-service/deposit-gateway.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
