> For the complete documentation index, see [llms.txt](https://docs.rei.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rei.network/developer/system-contracts/freefee.md).

# FreeFee

## Contents

## Globals

| Var             | Type                                          |
| --------------- | --------------------------------------------- |
| userUsage       | mapping(address => struct IFreeFee.UsageInfo) |
| totalUsage      | uint256                                       |
| globalTimestamp | uint256                                       |

## Functions

### constructor

No description

**Declaration:**

```solidity
  function constructor(
  ) public Only
```

**Modifiers:**

| Modifier |
| -------- |
| Only     |

### estimateTotalLeft

Estimate total daily free fee left.

**Declaration:**

```solidity
  function estimateTotalLeft(
    uint256 timestamp
  ) public returns (uint256 totalLeft)
```

**Modifiers:** No modifiers

**Args:**

| Arg         | Type    | Description       |
| ----------- | ------- | ----------------- |
| `timestamp` | uint256 | Current timestamp |

### estimateUsage

Estimate user daily free fee usage.

**Declaration:**

```solidity
  function estimateUsage(
    struct IFreeFee.UsageInfo ui,
    uint256 timestamp
  ) public returns (uint256)
```

**Modifiers:** No modifiers

**Args:**

| Arg         | Type                      | Description            |
| ----------- | ------------------------- | ---------------------- |
| `ui`        | struct IFreeFee.UsageInfo | User usage information |
| `timestamp` | uint256                   | Current timestamp      |

### estimateFreeFee

Estimate user daily free fee left.

**Declaration:**

```solidity
  function estimateFreeFee(
    address user,
    uint256 timestamp
  ) external returns (uint256)
```

**Modifiers:** No modifiers

**Args:**

| Arg         | Type    | Description       |
| ----------- | ------- | ----------------- |
| `user`      | address | User address      |
| `timestamp` | uint256 | Current timestamp |

### consume

Consume user usage, it only can be called by router.

**Declaration:**

```solidity
  function consume(
    address user,
    uint256 usage
  ) external nonReentrant onlyRouter
```

**Modifiers:**

| Modifier     |
| ------------ |
| nonReentrant |
| onlyRouter   |

**Args:**

| Arg     | Type    | Description        |
| ------- | ------- | ------------------ |
| `user`  | address | Transaction sender |
| `usage` | uint256 | Usage amount       |

### onAfterBlock

After block callback, it only can be called by router, it will update `globalTimestamp` if the time interval exceeds `freeFeeRecoverInterval`.

**Declaration:**

```solidity
  function onAfterBlock(
  ) external nonReentrant onlyRouter
```

**Modifiers:**

| Modifier     |
| ------------ |
| nonReentrant |
| onlyRouter   |


---

# 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 dynamically by asking a question.

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

```
GET https://docs.rei.network/developer/system-contracts/freefee.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
