# BuildersTreasuryV2

## Overview

The `BuildersTreasuryV2` contract serves as a dedicated storage vault and distribution mechanism for builder rewards in the protocol. It is tightly integrated with the `BuildersV4` contract and acts as the reward source when the Subnet admin or claim admin claim their share of MOR tokens.

The treasury holds the reward token (MOR) and is the only contract authorized to send out rewards. It tracks the total distributed rewards (claimed amount).

To function correctly, the protocol administrator (owner) must ensure that this contract is regularly and sufficiently funded.&#x20;

### Key Features

1. Reward source: acts as the source of truth and distribution for builder rewards in the protocol.
2. Access controlled: only the `BuildersV4` 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 payments.

## 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 `BuildersV4` 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

### BuildersTreasuryV2\_init

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

```solidity
function BuildersTreasuryV2_init(
  address rewardToken_,
) external initializer;
```

| Name           | Description                               |
| -------------- | ----------------------------------------- |
| `rewardToken_` | Address of the MOR token used for rewards |

### setBuilders

Updates the address of the `BuildersV4` contract.

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

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

### withdraw

The function to withdraw `rewardToken` from the contract.

```solidity
 function withdraw(address receiver_, uint256 amount_) external onlyOwner;
```

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

## Functions for the BuildersV4 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 tokens to transfer. Wei.        |

## Read functions

### supportsInterface

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

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

### version

Returns the current version of the contract.

```solidity
function version() external pure returns (uint256
```


---

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