# Treasury

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

**Inherits:** ITreasury, Team

**Author:** Daniel Yamagata & Naveen Ailawadi

A Safe-like contract whose signers are a company's board of directors. A Mezzanine company resembles a tree data structure. The 'Treasury' is the root node of the tree, while 'departments' and 'modules' are internal and leaf nodes. A treasury should hold nearly all assets of a company. Funds can be spent recursively by departments and modules given there are sufficcient approvals and balances. The entirety of a company can be queried either directly from the treasury or via a tree traversal algorithm

## State Variables

### TreasuryStorageLocation

```solidity
bytes32 private constant TreasuryStorageLocation = 0xa29865ab22e3c13f4e3fda97514b6fba0b0844305463cbe6cf02bc044b877500;
```

## Functions

### \_getTreasuryStorage

```solidity
function _getTreasuryStorage() internal pure returns (TreasuryStorage storage $);
```

### constructor

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

### onlyMezzGovernance

```solidity
modifier onlyMezzGovernance();
```

### onlyPayrollManager

```solidity
modifier onlyPayrollManager();
```

### init

```solidity
function init(DataTypes.TreasuryInitArgs memory initArgs) external virtual initializer;
```

### \_\_Treasury\_init

```solidity
function __Treasury_init(DataTypes.TreasuryInitArgs memory initArgs) internal virtual onlyInitializing;
```

### capitalStack

Returns the address of the company's capital stack

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

### delegateRegistry

Returns the address of the company's delegate registry

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

### denominationAsset

Returns the address of the denomination asset

*All debt by the company will be recorded in terms of the denomination asset This value is immutable*

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

### getCommonShares

Returns the address of the company's common shares

*A treasury will only have a single set of common shares*

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

### getGovernor

Returns the address of the Governor

*The Governor is able to manage the signers of the Treasury*

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

### getTokenTimelock

Returns the address of the Token Timelock

*Used by Mezz Shares to issue and vest shares atomically*

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

### getPayrollManager

Returns the address of the Payroll Manager

*The Payroll Manager is a shortbound ERC721 contract that manages the payroll of employees. It is able to arbitrarily spend money and common shares from the treasury without approvals. It is controlled by the board of directors (i.e. the Treasury) and a set of admins, who are set by the board*

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

### isAddingAsset

Returns true if the treasury is adding an asset, false otherwise.  A callback used by the capital stack to prevent the treasury from arbitrarily adding an asset to the capital stack

```solidity
function isAddingAsset() public view returns (bool);
```

### isRemovingAsset

Returns true if the treasury is removing an asset, false otherwise. A callback used by the capital stack to prevent the treasury from arbitrarily removing an asset from the capital stack

```solidity
function isRemovingAsset() public view returns (bool);
```

### 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 action, bytes memory params)
    external
    virtual
    override(Team, ITeam)
    onlyMezzGovernance
    freezable;
```

**Parameters**

| Name     | Type     | Description                                        |
| -------- | -------- | -------------------------------------------------- |
| `action` | `bytes4` | The function selector of the function to call      |
| `params` | `bytes`  | The abi-encoded parameters to pass to the function |

### swapGuard

A function to swap the guard of a team contract.

*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)
    onlyMezzGovernance
    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 childToInsert) external virtual override(Team, ITeam) authorized pausable;
```

### removeChild

Removes 'childToRemove' from the '\_children' set. Will revert if 'childToRemove' is not in the '\_children' set

```solidity
function removeChild(address childToRemove) external virtual override(Team, ITeam) authorized freezable;
```

### changeGovernor

Deploys and initializes a new governor. Sets the new governor accordingly

*Changes the current governor to a new one associated with 'governorCoreId' A treasury cannot change its governor to one with the same core ID*

```solidity
function changeGovernor(bytes32 governorCoreId, bytes memory params)
    external
    virtual
    onlyMezzGovernance
    pausable
    returns (address);
```

**Parameters**

| Name             | Type      | Description                                                              |
| ---------------- | --------- | ------------------------------------------------------------------------ |
| `governorCoreId` | `bytes32` | The core ID of the governor to switch to                                 |
| `params`         | `bytes`   | Bespoke abi.encoded parameters to pass to the governor's init() function |

**Returns**

| Name     | Type      | Description                     |
| -------- | --------- | ------------------------------- |
| `<none>` | `address` | The address of the new governor |

### addAssetToCapitalStack

Deploys an asset with 'assetCoreId' via the Mezz Deployer and adds it to the seniority level with 'seniorityLevelIndex' in the capital stack. If the asset supports the Mezz Shares interface, adds it to the company's shares. Adds a document to the Document Registry with 'assetDocumentName' and 'assetDocumentUri'. The 'owner' of the document will be the *capital stack*. The name and URI can be updated retroactively at any time.

```solidity
function addAssetToCapitalStack(
    bytes32 assetCoreId,
    uint256 seniorityLevelIndex,
    bytes memory params,
    string memory assetDocumentName,
    string memory assetDocumentUri
) external virtual authorized pausable returns (address);
```

**Parameters**

| Name                  | Type      | Description                                                               |
| --------------------- | --------- | ------------------------------------------------------------------------- |
| `assetCoreId`         | `bytes32` |                                                                           |
| `seniorityLevelIndex` | `uint256` |                                                                           |
| `params`              | `bytes`   | The bespoke abi.encoded parameters to pass to the asset's init() function |
| `assetDocumentName`   | `string`  |                                                                           |
| `assetDocumentUri`    | `string`  |                                                                           |

### removeAssetFromCapitalStack

Removes an asset from the capital stack. The 'removable()' function of 'assetToRemove()' must return true for this function to succeed. The conditions for removal are bespoke to each asset. For example, the total supply of a share class must be zero for it to be removed. If 'assetToRemove' supports the Mezz Shares interface, it will be removed from the company's shares. The document associated with the asset will be updated to null

```solidity
function removeAssetFromCapitalStack(address assetToRemove) external virtual authorized freezable;
```

### spendPayroll

Transfers an 'amount' of an 'asset' to the payroll module. Only callable by the payroll module. The asset must either be a whitelisted denomination asset or the company's common shares. Returns the amount of the asset paid to the recipient, inclusive of ERC20 transfer fees.

*This function bypasses all of the treasury's ERC20 allowances. This was designed in a manner to prevent the board from needing to manually setting approvals for payroll*

```solidity
function spendPayroll(address recipient, address asset, uint256 amount)
    external
    virtual
    onlyPayrollManager
    pausable
    returns (uint256);
```

**Parameters**

| Name        | Type      | Description                                  |
| ----------- | --------- | -------------------------------------------- |
| `recipient` | `address` | The recipient of the funds                   |
| `asset`     | `address` | The asset to pay the recipient in            |
| `amount`    | `uint256` | The amount of the asset to pay the recipient |

**Returns**

| Name     | Type      | Description                                                                                 |
| -------- | --------- | ------------------------------------------------------------------------------------------- |
| `<none>` | `uint256` | The amount paid, which takes into account any native ERC20 transfer fees built into 'asset' |

### spend

Transfers 'amount' of asset to the caller, who must be a child. Sends any set fees for the treasury implementation to the fee controller

```solidity
function spend(address asset, uint256 amount) external virtual onlyChild pausable;
```

### coreId

Returns the coreId of the implementation as a bytes32

*The core ID is the keccak256 hash of the contract name followed by a version under the following syntax: "mezzanine.coreId.ContractName.vX" For example, the core ID of the 2nd version of the Treasury would be the following: keccak256(abi.encodePacked("mezzanine.coreId.Treasury.v2"))*

```solidity
function coreId() public pure virtual override(Credentialed, ICredentialed) returns (bytes32);
```

### version

Returns the version of the implementation as a uint256

```solidity
function version() public pure virtual override(Credentialed, ICredentialed) returns (uint256);
```

### name

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

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

### symbol

Returns the symbol for the company

```solidity
function symbol() public view returns (string memory);
```

### getParent

Returns the parent of 'this'. If 'this' is a department or module, returns the team that directly controls 'this'. If 'this' is the Treasury, returns the sentinel parent, which is address(0x1)

```solidity
function getParent() public pure 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 |

### getShares

Returns the addresses for the company's share classes as an address array

```solidity
function getShares() public view returns (address[] memory);
```

### isValidShares

Returns true if 'sharesToCheck' is a valid share class for the company, false otherwise

```solidity
function isValidShares(address sharesToCheck) public view returns (bool);
```

**Parameters**

| Name            | Type      | Description         |
| --------------- | --------- | ------------------- |
| `sharesToCheck` | `address` | The shares to check |

### outstandingSupply

Returns the summation of the outstanding supply for all share classes. This does not include any vesting or treasury shares

```solidity
function outstandingSupply() external view returns (uint256);
```

### fullyDilutedSupply

Returns the summation of the fully diluted supply for all share classes. This includes authorized, vesting, and treasury shares

```solidity
function fullyDilutedSupply() external view returns (uint256);
```

### \_validateCallerIsPayrollManager

```solidity
function _validateCallerIsPayrollManager() internal view;
```

### \_validateCallerIsGovernance

```solidity
function _validateCallerIsGovernance() internal view;
```

### \_authorizePatch

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

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

### supportsInterface

*ERC165 support*

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

## Structs

### TreasuryStorage

```solidity
struct TreasuryStorage {
    bool _addingAssetHook;
    bool _removingAssetHook;
    address _commonShares;
    address _denominationAsset;
    address _capitalStack;
    address _delegateRegistry;
    address _tokenTimelock;
    address _payrollManager;
    address _governor;
    string _name;
    string _symbol;
    EnumerableSet.AddressSet _shares;
}
```


---

# 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/treasury.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.
