> 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/accountable-withdrawal-queue.md). Agents can also search and read this documentation through its [MCP server](https://docs.accountable.capital/~gitbook/mcp).

# Accountable Withdrawal Queue

### Overview

The `AccountableWithdrawalQueue` contract is the core component that manages withdrawal operations for redemptions that cannot be fulfilled instantly.

### Core Concepts

#### Interface methods

```solidity
/// @notice Interface for the withdrawal queue
interface IAccountableWithdrawalQueue {
    function fulfillRedeemRequest(address controller, uint256 shares) external;
    function processUpToShares(uint256 maxShares) external returns (uint256 assetsUsed);

    function previewRequiredShares(uint256 maxAssets)
        external
        view
        returns (uint256 processedShares, uint256 assetsUsed);
        
    function totalQueuedShares() external view returns (uint256 totalQueuedShares);
    function reservedLiquidity() external view returns (uint256 reservedLiquidity);
    function queue() external view returns (uint128 nextRequestId, uint128 lastRequestId);
    function withdrawalRequest(address controller) external view returns (WithdrawalRequest memory request);

    function withdrawalRequests(uint128 start, uint128 end)
        external
        view
        returns (WithdrawalRequest[] memory requests);
}
```

#### State Management

**WithdrawalRequest Structure**

```solidity
/// @notice Struct tracking a withdrawal request
struct WithdrawalRequest {
    /// @notice The number of shares requested
    uint256 shares;
    /// @notice The total value of the request
    uint256 totalValue;
    /// @notice The controller of the request
    address controller;
}
```

The queue storage is represented by the `WithdrawalQueue` struct holding the ends of the queue:

```solidity
/// @notice Struct tracking the withdrawal queue
struct WithdrawalQueue {
    /// @notice The next request ID to be processed
    uint128 nextRequestId;
    /// @notice The last request ID to be processed
    uint128 lastRequestId;
    /// @notice The mapping of request IDs to withdrawal requests
    mapping(uint128 requestId => WithdrawalRequest request) requests;
}
```

#### Request Lifecycle Management

1. **Request Creation**

```solidity
function _push(address controller, uint256 sharePrice, uint256 shares) internal returns (uint128 requestId)
```

* Pushes a new request or updates an existing one.
* Multiple enqueues increment the request shares instead of creating new requests.
* This has been chosen to avoid spamming the queue with small share amounts and to allow partial processing of a request, instead of full request fulfillment.

2. **Request deletion**

```solidity
function _reduce(address controller, uint256 shares) internal returns (uint256 remainingShares) 
```

* For a valid controller, it matches a `requestId.`
* If the remaining shares after reduction equal zero, it deletes the request entry from the queue.

3. **Preview functions**

```solidity
function _previewRequiredShares(uint256 maxAssets, uint256 liquidity, uint256 currentPrice)
        internal
        view
        returns (uint256 processedShares, uint256 assetsUsed)
```

* `_previewRequiredShares` returns the max processable shares.

4. **Request processing**

```solidity
function _processUpToShares(uint256 maxShares, uint256 liquidity, uint256 currentPrice)
        internal
        returns (uint256 assetsUsed)
```

* `_processUpToShares` processes the max possible using liquidity and maxShares, not more than the `min3(remainingShares, liquidity, request.shares).`

**Pricing and liquidity**

* Share price is provided by the vault implementing the queue, by calling the `sharePrice(address share)` hook.
* Liquidity is computed depending on the `totalAssets` returned by the vault and subtracting any previously registered obligations (`accruedAssets`, which can include reserved interest or other reserve ratio liquidities).
* Reserved liquidity is exposed to inform the strategy that a portion of the available liquidities is already reserved following successful withdrawal requests processing.


---

# 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/accountable-withdrawal-queue.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.
