# Quota Keeper

> Markdown export of the Gearbox Protocol documentation page for agents and retrieval systems.

Canonical page: https://docs.gearbox.finance/developers/gm-ref-qk
Source file: content/developers/gm-ref-qk.mdx
Section router: https://docs.gearbox.finance/developers/llms.txt
Section full export: https://docs.gearbox.finance/developers/llms-full.txt

The **PoolQuotaKeeperV3** regulates how much pool capital can be exposed to specific collateral types and at what cost. It tracks per-token quota limits, interest rates, and cumulative indices. Unlike the base debt which compounds, quota interest is additive (linear).

---

## Write Methods

### updateQuota

Updates the quota for a specific token on a Credit Account. Called by the Credit Manager during multicall execution.

```solidity
function updateQuota(
    address creditAccount,
    address token,
    int96 quotaChange,
    uint96 minQuota
) external returns (uint256 tokensToEnable, uint256 tokensToDisable);
```

| Parameter | Type | Description |
| --- | --- | --- |
| `creditAccount` | `address` | Credit Account to update |
| `token` | `address` | Token whose quota is being changed |
| `quotaChange` | `int96` | Amount to increase (positive) or decrease (negative) |
| `minQuota` | `uint96` | Minimum quota to maintain (reverts if result is below this and non-zero) |

**Returns:** Token masks to enable/disable based on quota state.

**Access:** Credit Manager only. Reverts with `QuotaIsOutOfBoundsException` if `totalQuoted` would exceed the token's limit.

---

### setTokenLimit

Sets the maximum aggregate quota for a specific token across all Credit Accounts.

```solidity
function setTokenLimit(address token, uint96 limit) external;
```

| Parameter | Type | Description |
| --- | --- | --- |
| `token` | `address` | Collateral token |
| `limit` | `uint96` | Maximum total quota allowed |

**Access:** Configurator only. Prevents over-exposure to any single asset.

---

### setTokenQuotaIncreaseFee

Sets the fee charged when a quota is increased.

```solidity
function setTokenQuotaIncreaseFee(address token, uint16 fee) external;
```

| Parameter | Type | Description |
| --- | --- | --- |
| `token` | `address` | Collateral token |
| `fee` | `uint16` | Fee in basis points |

**Access:** Configurator only.

---

### addQuotaToken

Registers a new token for quota tracking.

```solidity
function addQuotaToken(address token) external;
```

| Parameter | Type | Description |
| --- | --- | --- |
| `token` | `address` | Token to register |

**Access:** Configurator only.

---

### updateRates

Syncs quota interest rates from the Gauge/Tumbler (rate keeper). Must be called for rate changes to take effect.

```solidity
function updateRates() external;
```

**Access:** Rate keeper (Gauge or Tumbler) only.

---

## View Methods

### getTokenQuotaParams

Returns the global quota parameters for a token.

```solidity
function getTokenQuotaParams(address token)
    external view returns (
        uint16 rate,
        uint192 cumulativeIndex,
        uint16 quotaIncreaseFee,
        uint96 totalQuoted,
        uint96 limit,
        bool isActive
    );
```

| Return Value | Type | Description |
| --- | --- | --- |
| `rate` | `uint16` | Annual interest rate in basis points |
| `cumulativeIndex` | `uint192` | Cumulative index for interest calculation |
| `quotaIncreaseFee` | `uint16` | Fee charged on quota increases (bps) |
| `totalQuoted` | `uint96` | Total quota across all Credit Accounts |
| `limit` | `uint96` | Maximum allowed total quota |
| `isActive` | `bool` | Whether the token is currently active |

---

### getQuotaAndOutstandingInterest

Returns the quota and accrued interest for a specific Credit Account and token.

```solidity
function getQuotaAndOutstandingInterest(
    address creditAccount,
    address token
) external view returns (uint96 quoted, uint128 outstandingInterest);
```

| Return Value | Type | Description |
| --- | --- | --- |
| `quoted` | `uint96` | Amount of quota held by the account |
| `outstandingInterest` | `uint128` | Accrued interest not yet added to debt |

---

### quotedTokens

Returns the list of all tokens registered for quota tracking.

```solidity
function quotedTokens() external view returns (address[] memory);
```

---

### pool

Returns the associated pool address.

```solidity
function pool() external view returns (address);
```

---

### gauge

Returns the rate keeper (Gauge or Tumbler) address.

```solidity
function gauge() external view returns (address);
```

---

## Events

### UpdateQuota

```solidity
event UpdateQuota(
    address indexed creditAccount,
    address indexed token,
    int96 quotaChange
);
```

Emitted when a Credit Account's quota is changed.

### SetTokenLimit

```solidity
event SetTokenLimit(address indexed token, uint96 limit);
```

Emitted when a token's quota limit is updated.

### SetTokenQuotaIncreaseFee

```solidity
event SetTokenQuotaIncreaseFee(address indexed token, uint16 fee);
```

Emitted when a quota increase fee is set.

### AddQuotaToken

```solidity
event AddQuotaToken(address indexed token);
```

Emitted when a new token is registered for quota tracking.

### UpdateRates

```solidity
event UpdateRates();
```

Emitted when quota rates are synced from the rate keeper.

---

## Rate Keeper Models

The QuotaKeeper relies on an external rate keeper to provide interest rates:

| Model | Description |
| --- | --- |
| **GaugeV3** | Decentralized voting model where GEAR stakers vote to set rates between `minRate` and `maxRate` |
| **TumblerV3** | Curator-controlled model with direct rate setting via `setRate(token, rate)` and epoch-based updates |

---

## Related Pages

- [Pool (PoolV3)](https://docs.gearbox.finance/developers/gm-ref-pool) -- The vault that QuotaKeeper is associated with
- [Credit Manager](https://docs.gearbox.finance/developers/gm-ref-cm) -- Calls `updateQuota` during multicall execution
- [Credit Configurator](https://docs.gearbox.finance/developers/gm-ref-cc) -- Manages quota parameters through the configurator role
- [Smart Contracts Overview](https://docs.gearbox.finance/developers/gm-contracts) -- Full contract architecture
