> 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/builderstreasury.md).

# BuildersTreasury

## Overview

The `BuildersTreasury` contract serves as a dedicated storage vault and distribution mechanism for builder rewards in the Morpheus protocol. It is tightly integrated with the `Builders` contract and acts as the reward source when builders (administrators of pools) claim their share of MOR tokens.

The treasury holds the reward token (typically MOR) and is the only contract authorized to send out rewards to builder pool administrators. It tracks the total distributed rewards to ensure correct accounting.

To function correctly, the Morpheus protocol administrators must ensure that this contract is regularly and sufficiently funded. This is critical for the accurate calculation and fair distribution of rewards, since the reward rate and availability are derived based on the current token balance in the treasury.

### Key Features

1. Reward source: acts as the source of truth and distribution for builder rewards in the protocol.
2. Access controlled: only the `Builders` contract can trigger reward transfers.
3. Reward accounting: tracks the total amount of rewards that have been distributed.
4. Protocol-funded: must be funded by Morpheus protocol operators on L1 (e.g., Ethereum) to ensure proper cross-chain reward emission calculations.

## Storage

### rewardToken

Holds the address of the MOR token used as the reward currency.

```solidity
address public rewardToken;
```

### builders

Stores the address of the authorized `Builders` contract that can distribute rewards.

```solidity
address public builders;
```

### distributedRewards

Tracks the total amount of rewards that have been distributed through this treasury.

```solidity
uint256 public distributedRewards;
```

## Functions for the contract owner

### BuildersTreasury\_init

Initializes the treasury contract with the reward token and  `Builders` contract.

```solidity
function BuildersTreasury_init(
  address rewardToken_,
  address builders_
) external initializer;
```

| Name           | Description                                                   |
| -------------- | ------------------------------------------------------------- |
| `rewardToken_` | Address of the MOR token used for rewards                     |
| `builders_`    | Address of the Builders contract authorized to manage rewards |

### setBuilders

Updates the address of the `Builders` contract.

```solidity
function setBuilders(address builders_) public onlyOwner
```

| Name        | Description                                       |
| ----------- | ------------------------------------------------- |
| `builders_` | Address of the new Builders contract to authorize |

## Functions for the Builders contract

### sendRewards

Transfers reward tokens to a specified receiver. Callable only by the Builders contract.

```solidity
function sendRewards(address receiver_, uint256 amount_) external onlyBuilders
```

| Name        | Description                               |
| ----------- | ----------------------------------------- |
| `receiver_` | Address of the user receiving the rewards |
| `amount_`   | Amount of reward tokens to transfer. Wei. |

## Read functions

### supportsInterface

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

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

### getAllRewards

Returns the total rewards managed by the treasury, including both distributed and undistributed tokens.

```solidity
function getAllRewards() public view returns (uint256)
```

***

***


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://gitbook.mor.org/smart-contracts/documentation/builders-protocol/v2-protocol/contracts/builderstreasury.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
