# Department

[Git Source](https://github.com/EntreDevelopers-Lab-Inc/Mezz-Companies/blob/f7a3e84e3dd5bb33c4bd7f77283983f9e8ba20b2/src/core/departments/Department.sol)

**Inherits:** Team, IDepartment

**Author:** Daniel Yamagata & Jerry Qi & Naveen Ailawadi

A multi-signature wallet whose signers are determined by its ancestors. A department can transfer funds recursively from the treasury to themselves, given there is sufficient approvals and balances. An ancestor is a department or the treasury, which is higher in the organizational hierarchy than 'this'. Unlike the traditional definition, an 'ancestor' does not include 'this', itself.

## State Variables

### DepartmentStorageLocation

```solidity
bytes32 private constant DepartmentStorageLocation = 0xbcbd9931e6c2b25760bd06d79dd059ceba389ce5a1832f868178693a75fc3c00;
```

## Functions

### \_getDepartmentStorage

```solidity
function _getDepartmentStorage() internal pure returns (DepartmentStorage storage $);
```

### constructor

```solidity
constructor(address _mezzHub, address _mezzMigrator) Team(_mezzHub, _mezzMigrator);
```

### onlyAncestor

```solidity
modifier onlyAncestor();
```

### onlyAncestorOrAuthorized

*The msg.sender must be 'this' or an ancestor*

```solidity
modifier onlyAncestorOrAuthorized();
```

### init

Standardized init function that all departments must inherit

```solidity
function init(
    address initTreasury,
    address[] memory _owners,
    uint256 _threshhold,
    address initGuard,
    address initParent,
    bytes memory params
) external virtual;
```

**Parameters**

| Name           | Type        | Description                                                                                |
| -------------- | ----------- | ------------------------------------------------------------------------------------------ |
| `initTreasury` | `address`   | The address of the treasury                                                                |
| `_owners`      | `address[]` | The initial signers of the department's multisig                                           |
| `_threshhold`  | `uint256`   | The initial threshold of the department's multisig                                         |
| `initGuard`    | `address`   | The address of the guard contract, which should be deployed atomically with the department |
| `initParent`   | `address`   | The address of the department's parent                                                     |
| `params`       | `bytes`     | Any additional parameters that the department needs to initialize                          |

### \_\_Department\_init

*Sets the initial state for a department and validates inputs*

```solidity
function __Department_init(
    address initTreasury,
    address[] memory _owners,
    uint256 _threshold,
    address initGuard,
    address initParent,
    string memory initDepartmentName
) internal onlyInitializing;
```

### manageOwners

A function to manage the signers of a Gnosis Safe.

*Makes external, authorized calls on address(this) that are normally blocked by Mezz Guards. This function is overridden and access-controlled such that the caller must be a Treasury's governor or a department's ancestor Refer to Constants.sol for the given function selectors that can be used as an 'action'*

```solidity
function manageOwners(bytes4 functionSelector, bytes memory params)
    external
    virtual
    override(Team, ITeam)
    onlyAncestor
    freezable;
```

**Parameters**

| Name               | Type     | Description                                        |
| ------------------ | -------- | -------------------------------------------------- |
| `functionSelector` | `bytes4` |                                                    |
| `params`           | `bytes`  | The abi-encoded parameters to pass to the function |

### swapGuard

A function to swap the guard of a team contract. Deploys and initializes the guard via the Mezz Deployer.

*Makes external, authorized calls on address(this) that are normally blocked by Mezz Guards. This function is overridden and access-controlled such that the caller must be a Treasury's governor or a department's ancestor*

```solidity
function swapGuard(bytes32 guardCoreId, bytes memory params)
    external
    virtual
    override(Team, ITeam)
    onlyAncestor
    freezable
    returns (address);
```

### insertChild

Inserts 'childToInsert' to the '\_children' set. 'childToInsert' must support the module or department interface. Will revert if 'childToInsert' is already in the '\_children' set

```solidity
function insertChild(address departmentToInsert)
    external
    virtual
    override(Team, ITeam)
    freezable
    onlyAncestorOrAuthorized;
```

### spend

Recursively transfers an 'amount' of 'asset' from the treasury to the caller, who must be a descendant of the treasury Will revert if the treasury has insufficient funds or the ancestors of 'this' have insufficient approvals

```solidity
function spend(address asset, uint256 amount) external virtual freezable onlyChildOrThis;
```

### getParent

```solidity
function getParent() public view virtual override(Team, IChild) returns (address);
```

**Returns**

| Name     | Type      | Description                                                                              |
| -------- | --------- | ---------------------------------------------------------------------------------------- |
| `<none>` | `address` | The parent, which is either the treasury, a department, a module, or the sentinel parent |

### treasury

Returns the treasury as an ITreasury interface

```solidity
function treasury() public view returns (ITreasury);
```

### name

Returns the name of 'this', which is a string

```solidity
function name() public view override(Team, ITeam) returns (string memory);
```

### supportsInterface

*ERC165 support*

```solidity
function supportsInterface(bytes4 interfaceId) public view virtual override(Team, IERC165) returns (bool);
```

### \_validateCallerIsAncestor

*Reverts if the caller is not an ancestor*

```solidity
function _validateCallerIsAncestor() internal view virtual;
```

### \_validateCallerIsTeamOrAncestor

*Reverts if the caller is not an ancestor or address(this)*

```solidity
function _validateCallerIsTeamOrAncestor() internal view virtual;
```

### upgradeToNewerVersion

Upgrades 'this' to a newer version via the MezzMigrator

*Only callable by 'this' or an ancestor*

```solidity
function upgradeToNewerVersion(uint256 newVersion, bytes memory data)
    public
    virtual
    onlyProxy
    onlyAncestorOrAuthorized;
```

### \_authorizePatch

*Access control for 'resetToPatchedLatestVersion()'. Validation of 'data' is completd in Team.sol*

```solidity
function _authorizePatch(bytes memory data) internal view override;
```

## Structs

### DepartmentStorage

```solidity
struct DepartmentStorage {
    ITreasury _treasury;
    address _parent;
    string _departmentName;
}
```


---

# 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.mezzanine.xyz/smart-contracts/source-code/core/department.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.
