# 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 %}
