# RateLimited

## Functions

### constructor

```solidity
function constructor(
    uint256 _maxRateLimitPerSecond,
    uint256 _rateLimitPerSecond,
    uint256 _bufferCap,
    bool _doPartialAction
) internal
```

#### Parameters

| Name                     | Type    | Description |
| ------------------------ | ------- | ----------- |
| `_maxRateLimitPerSecond` | uint256 |             |
| `_rateLimitPerSecond`    | uint256 |             |
| `_bufferCap`             | uint256 |             |
| `_doPartialAction`       | bool    |             |

### setRateLimitPerSecond

```solidity
function setRateLimitPerSecond(
    uint256 newRateLimitPerSecond
) external
```

set the rate limit per second

#### Parameters

| Name                    | Type    | Description |
| ----------------------- | ------- | ----------- |
| `newRateLimitPerSecond` | uint256 |             |

### setBufferCap

```solidity
function setBufferCap(
    uint256 newBufferCap
) external
```

set the buffer cap

#### Parameters

| Name           | Type    | Description |
| -------------- | ------- | ----------- |
| `newBufferCap` | uint256 |             |

### buffer

```solidity
function buffer() public returns (uint256)
```

the amount of action used before hitting limit

replenishes at rateLimitPerSecond per second up to bufferCap

### \_depleteBuffer

```solidity
function _depleteBuffer(
    uint256 amount
) internal returns (uint256)
```

the method that enforces the rate limit. Decreases buffer by "amount". If buffer is <= amount either 1. Does a partial mint by the amount remaining in the buffer or 2. Reverts Depending on whether doPartialAction is true or false

#### Parameters

| Name     | Type    | Description |
| -------- | ------- | ----------- |
| `amount` | uint256 |             |

### \_setRateLimitPerSecond

```solidity
function _setRateLimitPerSecond(
    uint256 newRateLimitPerSecond
) internal
```

#### Parameters

| Name                    | Type    | Description |
| ----------------------- | ------- | ----------- |
| `newRateLimitPerSecond` | uint256 |             |

### \_setBufferCap

```solidity
function _setBufferCap(
    uint256 newBufferCap
) internal
```

#### Parameters

| Name           | Type    | Description |
| -------------- | ------- | ----------- |
| `newBufferCap` | uint256 |             |

### \_resetBuffer

```solidity
function _resetBuffer() internal
```

### \_updateBufferStored

```solidity
function _updateBufferStored() internal
```

## Events

### BufferUsed

```solidity
event BufferUsed(
    uint256 amountUsed,
    uint256 bufferRemaining
)
```

#### Parameters

| Name                | Type    | Description |
| ------------------- | ------- | ----------- |
| `amountUsed`        | uint256 |             |
| `bufferRemaining`   | uint256 |             |
| ### BufferCapUpdate |         |             |

```solidity
event BufferCapUpdate(
    uint256 oldBufferCap,
    uint256 newBufferCap
)
```

#### Parameters

| Name                         | Type    | Description |
| ---------------------------- | ------- | ----------- |
| `oldBufferCap`               | uint256 |             |
| `newBufferCap`               | uint256 |             |
| ### RateLimitPerSecondUpdate |         |             |

```solidity
event RateLimitPerSecondUpdate(
    uint256 oldRateLimitPerSecond,
    uint256 newRateLimitPerSecond
)
```

#### Parameters

| Name                    | Type    | Description |
| ----------------------- | ------- | ----------- |
| `oldRateLimitPerSecond` | uint256 |             |
| `newRateLimitPerSecond` | uint256 |             |


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.essencefinance.io/development/smart-contracts/utils/ratelimited.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
