> For the complete documentation index, see [llms.txt](https://gitbook.mor.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.mor.org/smart-contracts/documentation/builders-protocol/v2-protocol/contracts/feeconfig.md).

# FeeConfig

## Overview

The `FeeConfig` contract is a configuration module used within the protocol to manage and enforce protocol-level fees. It enables fine-grained control over fee application logic across different operations and protocol participants.

This contract is deployed on-chain and is designed to be upgradeable. It provides both default and customizable fee structures, allowing the protocol to charge fees for specific actions (such as withdrawals or reward claims) and route them to a designated treasury address.

## Key Features

1. Precision-based fee system: all fees are calculated using a precision constant (`PRECISION`) equal to 10<sup>25</sup>, which represents 100%. For example, `0.05*10^25` is equivalent to 5%.
2. Default and custom fees: allows setting a global base fee, operation-specific base fees, sender-specific custom fees, and operation-specific custom fees per sender.
3. Treasury routing: all collected fees are directed to a treasury address, which can be updated by the protocol owner.
4. Access control: only the contract owner (protocol administrator) can set or update fee configurations, ensuring controlled and secure modifications.

## Write functions

### FeeConfig\_init

Initializes the contract with essential parameters and configuration contracts. This function must be called once after deployment.

```solidity
function FeeConfig_init(
  address treasury_,
  uint256 baseFee_
) external initializer
```

| Name        | Description                                                                     |
| ----------- | ------------------------------------------------------------------------------- |
| `treasury_` | Address of the new treasury.                                                    |
| `baseFee_`  | The base fee value (must be less than PRECISION). Where 100% = 10<sup>25.</sup> |

### setTreasury

Updates the treasury address.

```solidity
function setTreasury(address treasury_) public onlyOwner
```

| Name        | Description                  |
| ----------- | ---------------------------- |
| `treasury_` | Address of the new treasury. |

## Set and receive base (default) fee for the caller

### setBaseFee

Sets the global base (default) fee for all callers. Only for the contract owner.

```solidity
function setBaseFee(uint256 baseFee_) public onlyOwner
```

| Name       | Description                                                                     |
| ---------- | ------------------------------------------------------------------------------- |
| `baseFee_` | The base fee value (must be less than PRECISION). Where 100% = 10<sup>25.</sup> |

### setFee

Sets the fee for the specific callers. Only for the contract owner.

```solidity
function setFee(address sender_, uint256 fee_) external onlyOwner
```

| Name      | Description                                                                     |
| --------- | ------------------------------------------------------------------------------- |
| `sender_` | The address for which to query fee.                                             |
| `fee_`    | The base fee value (must be less than PRECISION). Where 100% = 10<sup>25.</sup> |

### getFeeAndTreasury

Returns the fee for the caller or base fee (if caller fee isn't set), treasury address for a sender (contract).

```solidity
function getFeeAndTreasury(address sender_) external view returns (uint256, address)
```

| Name      | Description                         |
| --------- | ----------------------------------- |
| `sender_` | The address for which to query fee. |

## Set and receive operation fee for the caller

### setBaseFeeForOperation

Sets the base fee for a specific operation across the protocol. Only for the contract owner.

```solidity
function setBaseFeeForOperation(
  bytes32 operation_, 
  uint256 baseFeeForOperation_
) public onlyOwner
```

| Name                   | Description                                                                                  |
| ---------------------- | -------------------------------------------------------------------------------------------- |
| `operation_`           | Operation identifier.                                                                        |
| `baseFeeForOperation_` | The base fee for this operation (must be less than PRECISION). Where 100% = 10<sup>25.</sup> |

### setFeeForOperation

Sets the fee for a specific operation across the protocol for the specific caller. Only for the contract owner.

```solidity
function setFeeForOperation(
   address sender_, 
   bytes32 operation_, 
   uint256 fee_
) external onlyOwner
```

| Name                   | Description                                                                                 |
| ---------------------- | ------------------------------------------------------------------------------------------- |
| `operation_`           | Operation identifier.                                                                       |
| `baseFeeForOperation_` | The base fee for this operation (must be less than PRECISION). Where 100% = 10<sup>25</sup> |
| `sender_`              | The address for which to query fee.                                                         |

### discardCustomFee

Removes custom fee override for an operation for a specific caller.

```solidity
function discardCustomFee(
  address sender_, 
  bytes32 operation_
) external onlyOwner
```

| Name         | Description                                            |
| ------------ | ------------------------------------------------------ |
| `sender_`    | Address for which the custom fee is being discarded    |
| `operation_` | Operation identifier (e.g., `"claim"` or `"withdraw"`) |

### getFeeAndTreasuryForOperation

Returns the fee for a specific operation or base fee for a specific operation (if fee for a specific operation isn't set) and treasury address.

```solidity
function getFeeAndTreasuryForOperation(
  address sender_,
  bytes32 operation_
) external view returns (uint256, address)
```

| Name         | Description                                                  |
| ------------ | ------------------------------------------------------------ |
| `sender_`    | Address requesting the operation                             |
| `operation_` | Operation for which to retrieve the fee and treasury address |

## Read functions

### supportsInterface

Used for interface detection (ERC165). Returns true if the contract supports a specific `interfaceId_`. Supports `IFeeConfig`, `IERC165`.

```solidity
function supportsInterface(bytes4 interfaceId_) external pure returns (bool)
```


---

# 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://gitbook.mor.org/smart-contracts/documentation/builders-protocol/v2-protocol/contracts/feeconfig.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.
