# FeeManager\_v1.sol

## FeeManager\_v1

[Git Source](https://github.com/InverterNetwork/inverter-contracts/blob/924235ad72271a7cb09cd1b027f938f90a42eb93/src/external/fees/FeeManager_v1.sol)

**Inherits:** [ERC165Upgradeable](<https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/52f6007348edc34304e9de9dc39cfbeb9ef314b9/contracts/utils/introspection/ERC165Upgradeable.sol&#xA;>), [IFeeManager\_v1](/contracts/technical-reference/external/fees/interfaces/ifeemanager_v1.sol.md), [Ownable2StepUpgradeable](<https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/52f6007348edc34304e9de9dc39cfbeb9ef314b9/contracts/access/Ownable2StepUpgradeable.sol&#xA;>)

**Author:** Inverter Network

This contract manages the different fees possible on a protocol level. The different fees can be fetched publicly and be set by the owner of the contract.

*Inherits from* [*{ERC165Upgradeable}*](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/52f6007348edc34304e9de9dc39cfbeb9ef314b9/contracts/utils/introspection/ERC165Upgradeable.sol) *for interface detection,* [*{Ownable2StepUpgradeable}*](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/52f6007348edc34304e9de9dc39cfbeb9ef314b9/contracts/access/Ownable2StepUpgradeable.sol) *for owner-based access control, and implements the* [*{IFeeManager\_v1}*](/contracts/technical-reference/external/fees/interfaces/ifeemanager_v1.sol.md) *interface.*

### State Variables

#### BPS

*Base Points used for percentage calculation. This value represents 100%.*

```solidity
uint public constant BPS = 10_000;
```

#### maxFee

*The maximum fee percentage amount that can be set. Based on the BPS.*

```solidity
uint public maxFee;
```

#### defaultProtocolTreasury

*The default protocol treasury address.*

```solidity
address internal defaultProtocolTreasury;
```

#### workflowTreasuries

*The workflow treasury address. Orchestrator => treasury*

```solidity
mapping(address => address) internal workflowTreasuries;
```

#### defaultIssuanceFee

*The default issuance fee percentage amount that apply unless workflow specific fees are set.*

```solidity
uint internal defaultIssuanceFee;
```

#### defaultCollateralFee

*The default collateral fee percentage amount that apply unless workflow specific fees are set.*

```solidity
uint internal defaultCollateralFee;
```

#### workflowIssuanceFees

*The workflow issuance fee. Orchestrator => hash(functionSelector + module address) => feeStruct.*

```solidity
mapping(address => mapping(bytes32 => Fee)) internal workflowIssuanceFees;
```

#### workflowCollateralFees

*The workflow collateral fee. Orchestrator => hash(functionSelector + module address) => feeStruct.*

```solidity
mapping(address => mapping(bytes32 => Fee)) internal workflowCollateralFees;
```

#### \_\_gap

*Storage gap for future upgrades.*

```solidity
uint[50] private __gap;
```

### Functions

#### supportsInterface

*See* [*{IERC165-supportsInterface}*](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/19a657bef8354f2a655900654955739b70dfbde9/contracts/utils/introspection/IERC165.sol#L24)*.*

```solidity
function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ERC165Upgradeable)
    returns (bool);
```

#### validAddress

*Modifier to check if the given address is valid.*

```solidity
modifier validAddress(address adr);
```

#### validFee

*Modifier to check if the given fee is valid.*

```solidity
modifier validFee(uint fee);
```

#### validMaxFee

*Modifier to check if the given max fee is valid.*

```solidity
modifier validMaxFee(uint max);
```

#### constructor

```solidity
constructor();
```

#### init

```solidity
function init(
    address owner,
    address _defaultProtocolTreasury,
    uint _defaultCollateralFee,
    uint _defaultIssuanceFee
)
    external
    initializer
    validAddress(owner)
    validAddress(_defaultProtocolTreasury);
```

#### getDefaultProtocolTreasury

Returns the default treasury for all workflows.

```solidity
function getDefaultProtocolTreasury() public view returns (address);
```

**Returns**

| Name     | Type      | Description                  |
| -------- | --------- | ---------------------------- |
| `<none>` | `address` | The address of the treasury. |

#### getWorkflowTreasuries

Returns the treasury assigned to the given workflow.

```solidity
function getWorkflowTreasuries(address workflow)
    public
    view
    returns (address);
```

**Parameters**

| Name       | Type      | Description                  |
| ---------- | --------- | ---------------------------- |
| `workflow` | `address` | The address of the workflow. |

**Returns**

| Name     | Type      | Description                  |
| -------- | --------- | ---------------------------- |
| `<none>` | `address` | The address of the treasury. |

#### getDefaultCollateralFee

Returns the default collateral fee for all workflows.

```solidity
function getDefaultCollateralFee() external view returns (uint);
```

**Returns**

| Name     | Type      | Description                                       |
| -------- | --------- | ------------------------------------------------- |
| `<none>` | `uint256` | The collateral fee amount in relation to the BPS. |

#### getDefaultIssuanceFee

Returns the default issuance fee for all workflows.

```solidity
function getDefaultIssuanceFee() external view returns (uint);
```

**Returns**

| Name     | Type      | Description                                     |
| -------- | --------- | ----------------------------------------------- |
| `<none>` | `uint256` | The issuance fee amount in relation to the BPS. |

#### getCollateralWorkflowFee

Returns the collateral fee for a specific workflow module function.

```solidity
function getCollateralWorkflowFee(
    address workflow,
    address module,
    bytes4 functionSelector
) public view returns (uint fee);
```

**Parameters**

| Name               | Type      | Description                                                    |
| ------------------ | --------- | -------------------------------------------------------------- |
| `workflow`         | `address` | The address of the workflow that contains the module function. |
| `module`           | `address` | The address of the module that contains the function.          |
| `functionSelector` | `bytes4`  | The function selector of the target function.                  |

**Returns**

| Name  | Type      | Description                                       |
| ----- | --------- | ------------------------------------------------- |
| `fee` | `uint256` | The collateral fee amount in relation to the BPS. |

#### getIssuanceWorkflowFee

Returns the issuance fee for a specific workflow module function.

```solidity
function getIssuanceWorkflowFee(
    address workflow,
    address module,
    bytes4 functionSelector
) public view returns (uint fee);
```

**Parameters**

| Name               | Type      | Description                                                    |
| ------------------ | --------- | -------------------------------------------------------------- |
| `workflow`         | `address` | The address of the workflow that contains the module function. |
| `module`           | `address` | The address of the module that contains the function.          |
| `functionSelector` | `bytes4`  | The function selector of the target function.                  |

**Returns**

| Name  | Type      | Description                                     |
| ----- | --------- | ----------------------------------------------- |
| `fee` | `uint256` | The issuance fee amount in relation to the BPS. |

#### getCollateralWorkflowFeeAndTreasury

Returns the collateral fee for a specific workflow module function and the according treasury address of the workflow.

```solidity
function getCollateralWorkflowFeeAndTreasury(
    address workflow,
    address module,
    bytes4 functionSelector
) external view returns (uint fee, address treasury);
```

**Parameters**

| Name               | Type      | Description                                                    |
| ------------------ | --------- | -------------------------------------------------------------- |
| `workflow`         | `address` | The address of the workflow that contains the module function. |
| `module`           | `address` | The address of the module that contains the function.          |
| `functionSelector` | `bytes4`  | The function selector of the target function.                  |

**Returns**

| Name       | Type      | Description                                       |
| ---------- | --------- | ------------------------------------------------- |
| `fee`      | `uint256` | The collateral fee amount in relation to the BPS. |
| `treasury` | `address` | The address of the treasury.                      |

#### getIssuanceWorkflowFeeAndTreasury

Returns the issuance fee for a specific workflow module function and the according treasury address of the workflow.

```solidity
function getIssuanceWorkflowFeeAndTreasury(
    address workflow,
    address module,
    bytes4 functionSelector
) external view returns (uint fee, address treasury);
```

**Parameters**

| Name               | Type      | Description                                                    |
| ------------------ | --------- | -------------------------------------------------------------- |
| `workflow`         | `address` | The address of the workflow that contains the module function. |
| `module`           | `address` | The address of the module that contains the function.          |
| `functionSelector` | `bytes4`  | The function selector of the target function.                  |

**Returns**

| Name       | Type      | Description                                     |
| ---------- | --------- | ----------------------------------------------- |
| `fee`      | `uint256` | The issuance fee amount in relation to the BPS. |
| `treasury` | `address` | The address of the treasury.                    |

#### setMaxFee

Sets the maximum fee percentage that can be assigned.

*This function can only be called by the owner.*

```solidity
function setMaxFee(uint _maxFee) external onlyOwner validMaxFee(_maxFee);
```

**Parameters**

| Name      | Type      | Description                         |
| --------- | --------- | ----------------------------------- |
| `_maxFee` | `uint256` | The max Fee in relation to the BPS. |

#### setDefaultProtocolTreasury

Sets the default protocol treasury address.

*This function can only be called by the owner.*

```solidity
function setDefaultProtocolTreasury(address _defaultProtocolTreasury)
    external
    onlyOwner
    validAddress(_defaultProtocolTreasury);
```

**Parameters**

| Name                       | Type      | Description                                   |
| -------------------------- | --------- | --------------------------------------------- |
| `_defaultProtocolTreasury` | `address` | The address of the default protocol treasury. |

#### setWorkflowTreasury

Sets the protocol treasury address for a specific workflow.

*This function can only be called by the owner.*

```solidity
function setWorkflowTreasury(address workflow, address treasury)
    external
    onlyOwner
    validAddress(treasury);
```

**Parameters**

| Name       | Type      | Description                                                      |
| ---------- | --------- | ---------------------------------------------------------------- |
| `workflow` | `address` | The address of the workflow.                                     |
| `treasury` | `address` | The address of the protocol treasury for that specific workflow. |

#### setDefaultCollateralFee

Sets the default collateral fee of the protocol.

*This function can only be called by the owner.*

```solidity
function setDefaultCollateralFee(uint _defaultCollateralFee)
    external
    onlyOwner;
```

**Parameters**

| Name                    | Type      | Description                                                        |
| ----------------------- | --------- | ------------------------------------------------------------------ |
| `_defaultCollateralFee` | `uint256` | The default collateral fee of the protocol in relation to the BPS. |

#### setDefaultIssuanceFee

Sets the default issuance fee of the protocol.

*This function can only be called by the owner.*

```solidity
function setDefaultIssuanceFee(uint _defaultIssuanceFee) external onlyOwner;
```

**Parameters**

| Name                  | Type      | Description                                                      |
| --------------------- | --------- | ---------------------------------------------------------------- |
| `_defaultIssuanceFee` | `uint256` | The default issuance fee of the protocol in relation to the BPS. |

#### setCollateralWorkflowFee

Sets the collateral fee for a specific workflow module function.

*This function can only be called by the owner.*

```solidity
function setCollateralWorkflowFee(
    address workflow,
    address module,
    bytes4 functionSelector,
    bool set,
    uint fee
) external onlyOwner validFee(fee);
```

**Parameters**

| Name               | Type      | Description                                                    |
| ------------------ | --------- | -------------------------------------------------------------- |
| `workflow`         | `address` | The address of the workflow that contains the module function. |
| `module`           | `address` | The address of the module that contains the function.          |
| `functionSelector` | `bytes4`  | The function selector of the target function.                  |
| `set`              | `bool`    | Boolean that determines if the fee is actually used or not.    |
| `fee`              | `uint256` | The collateral fee in relation to the BPS.                     |

#### setIssuanceWorkflowFee

Sets the issuance fee for a specific workflow module function.

*This function can only be called by the owner.*

```solidity
function setIssuanceWorkflowFee(
    address workflow,
    address module,
    bytes4 functionSelector,
    bool set,
    uint fee
) external onlyOwner;
```

**Parameters**

| Name               | Type      | Description                                                    |
| ------------------ | --------- | -------------------------------------------------------------- |
| `workflow`         | `address` | The address of the workflow that contains the module function. |
| `module`           | `address` | The address of the module that contains the function.          |
| `functionSelector` | `bytes4`  | The function selector of the target function.                  |
| `set`              | `bool`    | Boolean that determines if the fee is actually used or not.    |
| `fee`              | `uint256` | The issuance fee in relation to the BPS.                       |

#### \_getModuleFunctionHash

```solidity
function _getModuleFunctionHash(address module, bytes4 functionSelector)
    internal
    pure
    returns (bytes32);
```

#### \_setDefaultProtocolTreasury

```solidity
function _setDefaultProtocolTreasury(address _defaultProtocolTreasury)
    internal
    validAddress(_defaultProtocolTreasury);
```

#### \_setWorkflowTreasury

```solidity
function _setWorkflowTreasury(address workflow, address treasury)
    internal
    validAddress(treasury);
```

#### \_setDefaultCollateralFee

```solidity
function _setDefaultCollateralFee(uint _defaultCollateralFee)
    internal
    validFee(_defaultCollateralFee);
```

#### \_setDefaultIssuanceFee

```solidity
function _setDefaultIssuanceFee(uint _defaultIssuanceFee)
    internal
    validFee(_defaultIssuanceFee);
```

#### \_setIssuanceWorkflowFee

```solidity
function _setIssuanceWorkflowFee(
    address workflow,
    address module,
    bytes4 functionSelector,
    bool set,
    uint fee
) internal validFee(fee);
```

#### \_setMaxFee

```solidity
function _setMaxFee(uint _maxFee) internal validMaxFee(_maxFee);
```


---

# 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.inverter.network/contracts/technical-reference/external/fees/feemanager_v1.sol.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.
