> ## 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.

# Redeem Queue

> RedeemQueue is the user entrypoint for redeeming fund shares back into assets. Like deposits, redemptions are batched: users lock shares into the current batch, the batch is priced

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

## Responsibility

`RedeemQueue` is the **user entrypoint for redeeming fund shares back into assets**. Like deposits, redemptions are batched: users lock shares into the current batch, the batch is priced when the oracle report is accepted, and payouts become claimable once the Fund **funds** the batch with assets.

Redemption has one more stage than deposits because the fund's assets may be deployed in strategies at settlement — settling fixes *how much* is owed, while funding (a separate, role-gated Fund action) actually delivers the assets. Admin functions authorize against the **Fund's** access control.

## Redeem lifecycle

```mermaid theme={"dark"}
stateDiagram-v2
    [*] --> Pending: redeem(asset, shares)
    Pending --> [*]: cancelRedeem / adminCancelRedeem (shares returned)
    Pending --> Settled: Fund.acceptReport → settleRedeem (payout snapshotted)
    Settled --> Funded: Fund.fundRedeem (assets arrive)
    Funded --> [*]: claimRedeem (receive assets)
```

<Steps>
  <Step title="Request">
    The user calls `redeem`, choosing which allowed asset to be paid in. Shares are transferred into the queue (requires prior approval). `Fund.checkRedeem` → [RiskManager](/developers/contract-reference/risk-manager) enforces minimums and batch caps. One request per (asset, batch, user).
  </Step>

  <Step title="Cancel">
    The user can cancel their current-batch request before settlement and get shares back. An admin (`CANCEL_REDEEM_REQUEST_ROLE`) can cancel any request in any unsettled batch.
  </Step>

  <Step title="Settle">
    During `Fund.acceptReport`, `settleRedeem` transfers the batch's shares to the Fund (which burns them) and **snapshots the payout** (`batchAssetTotals`) at the accepted price minus exit fee. The batch is tracked as *settled-but-unfunded*.
  </Step>

  <Step title="Fund">
    The operator brings assets back to the Fund (pulled from strategies, or transferred back by external wallets / bridges), then `FUND_REDEEM_ROLE` calls `Fund.fundRedeem(asset, batchId)`, which delivers the snapshotted amount and marks the batch claimable.
  </Step>

  <Step title="Claim">
    The user calls `claimRedeem` and receives `shares × batchAssetTotals / batchRedeemTotals`.
  </Step>
</Steps>

## Function reference

### User actions

| Function                      | Access        | Description                                                                                                                                                                               |
| ----------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `redeem(asset, shares)`       | anyone        | Queue a redemption into the current batch, paid out in `asset`. Transfers `shares` into the queue. Reverts if asset not allowed/paused, shares 0, or a request already exists this batch. |
| `cancelRedeem(asset)`         | request owner | Cancel own current-batch request; shares returned.                                                                                                                                        |
| `claimRedeem(asset, batchId)` | request owner | Claim pro-rata assets once the batch is funded.                                                                                                                                           |

### Fund actions

| Function                                    | Access     | Description                                                                                                                 |
| ------------------------------------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------- |
| `settleRedeem(asset, batchId, assetAmount)` | `onlyFund` | Transfers the batch's shares to the Fund for burning, snapshots `batchAssetTotals`, and adds the batch to the unfunded set. |
| `fundRedeem(asset, batchId)`                | `onlyFund` | Marks a settled batch funded (assets transferred in by the Fund in the same tx). Reverts if not settled or already funded.  |

### Admin (roles checked on the Fund)

| Function                                            | Role                                        | Description                                                                                           |
| --------------------------------------------------- | ------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `setAllowedAssets(assets[])`                        | `SET_REDEEM_ALLOWED_ASSETS_ROLE`            | Replace the allowed payout-asset list. Reverts if a removed asset has pending current-batch requests. |
| `pause()` / `unpause()`                             | `PAUSE_REDEEM_ROLE` / `UNPAUSE_REDEEM_ROLE` | Global pause — blocks `redeem`, `cancelRedeem`, `claimRedeem`.                                        |
| `pauseAssets(assets[])` / `unpauseAssets(assets[])` | `PAUSE_REDEEM_ROLE` / `UNPAUSE_REDEEM_ROLE` | Per-asset pause for new requests.                                                                     |
| `adminCancelRedeem(asset, batchId, user)`           | `CANCEL_REDEEM_REQUEST_ROLE`                | Cancel any user's request in any unsettled batch; shares returned.                                    |
| `pullAsset(asset, amount)`                          | `PULL_REDEEM_ASSET_ROLE`                    | Escape hatch: transfer assets from the queue back to the Fund.                                        |

### Views

`getAllowedAssets()`, `getAssetStatuses()`, `getRedeemRequest(asset, batchId, investor)`, `getPendingRedeems(investor)`, `getClaimableRedeems(investor)`, `getUnfundedBatches()` (the operator's to-do list), `batchRedeemTotals(asset, batchId)`, `batchAssetTotals(asset, batchId)`, `isBatchFunded(asset, batchId)`, `isAssetPaused(asset)`, `fund()`.

## Related

[DepositQueue](/developers/contract-reference/deposit-queue) · [Oracle](/developers/contract-reference/oracle) · [Fund](/developers/contract-reference/fund)
