> For the complete documentation index, see [llms.txt](https://docs.ees.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ees.xyz/concepts/fee-modules.md).

# Fee modules

Fee modules are smart contracts with the purpose of calculating the execution fee for a given job. Similarly to execution modules, a job commits to a fee module upon creation. However, data for a job within a fee module can be updated and a job can even migrate to use another fee module with time. Fee modules must implement the `IFeeModule` interface:

```solidity
interface IFeeModule {
    function onExecuteJob(uint256 _index, address _caller, uint32 _executionWindow, uint256 _executionTime, uint256 _variableGasConsumption) external returns (uint256, address);
    function onCreateJob(uint256 _index, bytes calldata _inputs) external;
    function onDeleteJob(uint256 _index) external;
    function onUpdateData(uint256 _index, bytes calldata _inputs) external;
    function getEncodedData(uint256 _index) external view returns (bytes memory);
}

```

The `onExecuteJob` callback function is called by the `JobRegistry` upon execution. It returns the execution fee and execution fee token.   The `onCreateJob` callback function is called upon creation of a job and is passed arbitrary input data in form of the argument `_input`. It can be used to initialise auxiliary data structures within the module. Similarly, the `onDeleteJob` callback function is called by the `JobRegistry` contract upon deletion of a job. The `jobIsExpired` function returns a bool whether a job is expired and can be canceled. `jobIsInExecutionMode` returns whether the job is in execution mode. Lastly, the `getEncodedData` function returns all data stored in the fee module contract for a job index as an encoded bytes array.

Similarly to execution modules, fee modules are created and tested by the EES before being supported by the `JobRegistry` contract. The modularity of fee computation allows implementation of new fee mechanisms which might be relevant in the future.

{% hint style="info" %}
**Note:** The execution fee returned by the `onExecuteJob` function is the amount withdrawn from the sponsor of the job upon execution.
{% endhint %}

{% hint style="warning" %}
**Warning:** Updating or migrating to another fee module is not permitted while a job is in execution mode.
{% endhint %}


---

# 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.ees.xyz/concepts/fee-modules.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.
