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

# Deposit Queue

> DepositQueue is the user entrypoint for depositing into a fund. Deposits are not instant—they are queued into the current batch and converted to shares only when the batch's oracle

> Source: [`src/DepositQueue.sol`](https://github.com/zentryHQ/red-potion-contract/blob/main/src/DepositQueue.sol)

## Responsibility

`DepositQueue` is the **user entrypoint for depositing into a fund**. Deposits are not instant—they are queued into the current **batch** and converted to shares only when the batch's oracle report is accepted (see [Oracle](/developers/contract-reference/oracle)). This gives every depositor in a batch the same execution price and lets the operator screen prices before settlement.

It supports multiple deposit assets (ERC-20s and native ETH via the `0xEeee…EEeE` sentinel), per-asset and global pausing, cancellation before settlement, and pro-rata claiming after settlement. Admin functions authorize against the **Fund's** access control (spoke pattern).

## Deposit lifecycle

```mermaid theme={"dark"}
stateDiagram-v2
    [*] --> Pending: deposit(asset, amount, proof)
    Pending --> [*]: cancelDeposit / adminCancelDeposit (refund)
    Pending --> Settled: Fund.acceptReport → settleDeposit
    Settled --> [*]: claimDeposit (receive shares)
```

<Steps>
  <Step title="Request">
    The user calls `deposit`. The queue asks the Fund for the current batch id, runs `Fund.checkDeposit` → [RiskManager](/developers/contract-reference/risk-manager), then escrows the assets.

    One request is allowed per `(asset, batch, user)`.
  </Step>

  <Step title="Cancel">
    The user can cancel their current-batch request before settlement for a full refund.

    An admin (`CANCEL_DEPOSIT_REQUEST_ROLE`) can cancel any user's request in any *unsettled* batch.
  </Step>

  <Step title="Settle">
    During `Fund.acceptReport`, the Fund mints the batch's user shares *to the queue* and calls `settleDeposit`, transferring all escrowed assets of that batch to the Fund.
  </Step>

  <Step title="Claim">
    The user calls `claimDeposit` and receives:

    $$
    \text{depositAmount} \times \frac{\text{batchShareTotals}}{\text{batchDepositTotals}}
    $$

    There is no deadline.
  </Step>
</Steps>

## Function reference

### User actions

| Function                        | Access           | Description                                                                                                                                                                                                                                                                                  |
| ------------------------------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `deposit(asset, amount, proof)` | anyone (payable) | Queue a deposit into the current batch. `proof` is the merkle whitelist proof (empty if none). For ETH, `msg.value == amount`; for ERC-20s, `msg.value == 0` and the queue pulls via `transferFrom`. Reverts if asset not allowed, paused, amount 0, or a request already exists this batch. |
| `cancelDeposit(asset)`          | request owner    | Cancel own current-batch request, full refund.                                                                                                                                                                                                                                               |
| `claimDeposit(asset, batchId)`  | request owner    | Claim pro-rata shares after settlement.                                                                                                                                                                                                                                                      |

### Fund actions

| Function                                      | Access     | Description                                                                                                                                  |
| --------------------------------------------- | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `settleDeposit(asset, batchId, sharesToMint)` | `onlyFund` | Marks the batch settled, records `batchShareTotals`, and transfers all escrowed assets of the batch to the Fund. Reverts if already settled. |

### Admin

Roles are checked on the Fund.

| Function                                            | Role                                          | Description                                                                                           |
| --------------------------------------------------- | --------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `setAllowedAssets(assets[])`                        | `SET_DEPOSIT_ALLOWED_ASSETS_ROLE`             | Replaces the allowed-asset list. Reverts if a removed asset still has pending current-batch requests. |
| `pause()` / `unpause()`                             | `PAUSE_DEPOSIT_ROLE` / `UNPAUSE_DEPOSIT_ROLE` | Global pause—blocks `deposit`, `cancelDeposit`, and `claimDeposit`.                                   |
| `pauseAssets(assets[])` / `unpauseAssets(assets[])` | `PAUSE_DEPOSIT_ROLE` / `UNPAUSE_DEPOSIT_ROLE` | Per-asset pause for new deposits.                                                                     |
| `adminCancelDeposit(asset, batchId, user)`          | `CANCEL_DEPOSIT_REQUEST_ROLE`                 | Cancel any user's request in any unsettled batch; assets are refunded to the user.                    |
| `pullAsset(asset, amount)`                          | `PULL_DEPOSIT_ASSET_ROLE`                     | Escape hatch: transfer assets from the queue to the Fund. Always sends to the Fund.                   |

### Views

`getAllowedAssets()`, `getAssetStatuses()`, `getDepositRequest(asset, batchId, investor)`, `getPendingDeposits(investor)`, `getClaimableDeposits(investor)`, `batchDepositTotals(asset, batchId)`, `batchShareTotals(asset, batchId)`, `isAssetPaused(asset)`, `fund()`.

## Related

[RedeemQueue](/developers/contract-reference/redeem-queue) · [Oracle](/developers/contract-reference/oracle) · [RiskManager](/developers/contract-reference/risk-manager)
