# RewardPool

## Introduction

The `RewardPool` contract encapsulates the emission logic for MOR tokens across multiple reward buckets. It defines how MOR tokens are distributed over time using emission curves, serving as a shared utility that ensures controlled and sustainable token issuance within the protocol.

The contract supports multiple independent reward pools, each corresponding to a specific bucket — a category of protocol participants eligible to earn MOR rewards. These buckets include Capital, Provider, Builder, Compute, Code, and Protection.

It implements a linear interval-based emission decay model using the `LinearDistributionIntervalDecrease` library. The contract allows the protocol owner to register reward pools with distinct configurations and provides utilities to query reward amounts over time. Each reward pool has its own emission curve, with customizable payout start time, emission amount, and decay interval.

By isolating emission logic from staking and distribution, `RewardPool` enables independent upgrades and adjustments to token economics without affecting user balances or yield sources. This modular design helps ensure scalability, transparency, and long-term reward sustainability across the ecosystem.

## Storage

### rewardPools

The MOR reward pools data, where the pool #0 is a capital reward. `pool. rewardPools[<rewardPool>]`

```solidity
RewardPool[] public rewardPools;

struct RewardPool {
  uint128 payoutStart;
  uint128 decreaseInterval;
  uint256 initialReward;
  uint256 rewardDecrease;
  bool isPublic;
}
```

| Name               | Description                                                                  |
| ------------------ | ---------------------------------------------------------------------------- |
| `payoutStart`      | The unix epoch timestamp in seconds when the pool starts to pay out rewards. |
| `decreaseInterval` | The interval in seconds between reward decreases.                            |
| `initialReward`    | The initial MOR reward for the bucket. Wei.                                  |
| `rewardDecrease`   | The MOR reward decrease per `decreaseInterval`. Wei.                         |
| `isPublic`         | `true` - for Capital bucket, `false` for others.                             |

## Write functions for the contract owner

### RewardPool\_init

Initializes the contract with a list of reward pool configurations.

```solidity
function RewardPool_init(RewardPool[] calldata poolsInfo_) external initializer
```

| Name         | Description                                      |
| ------------ | ------------------------------------------------ |
| `poolsInfo_` | Array of reward pool configs to initialize with. |

### addRewardPool

Adds a new reward pool to the registry. Only callable by the contract owner.

```solidity
function addRewardPool(RewardPool calldata rewardPool_) public onlyOwner
```

| Name          | Description                                         |
| ------------- | --------------------------------------------------- |
| `rewardPool_` | Reward pool configuration with emission parameters. |

## Validation functions uses by protocol

### onlyExistedRewardPool

Reverts if the specified reward pool does not exist.

```solidity
function onlyExistedRewardPool(uint256 index_) external view
```

| Name     | Description                         |
| -------- | ----------------------------------- |
| `index_` | Index of the reward pool to verify. |

### onlyPublicRewardPool

Reverts if the specified reward pool is not public.

```solidity
function onlyPublicRewardPool(uint256 index_) external view
```

| Name     | Description                         |
| -------- | ----------------------------------- |
| `index_` | Index of the reward pool to verify. |

### onlyNotPublicRewardPool

Reverts if the specified reward pool is public.

```solidity
function onlyNotPublicRewardPool(uint256 index_) external view
```

| Name     | Description                         |
| -------- | ----------------------------------- |
| `index_` | Index of the reward pool to verify. |

## Read functions

### getPeriodRewards

Calculates the total rewards to be distributed in a given time range using the pool’s emission curve.

```solidity
function getPeriodRewards(uint256 index_, uint128 startTime_, uint128 endTime_) external view returns (uint256)
```

| Name         | Description                                             |
| ------------ | ------------------------------------------------------- |
| `index_`     | Index of the reward pool.                               |
| `startTime_` | Start of the time interval (Unix timestamp in seconds). |
| `endTime_`   | End of the time interval (Unix timestamp in seconds).   |

### isRewardPoolExist

Checks if a reward pool exists at a specific index.

```solidity
function isRewardPoolExist(uint256 index_) public view returns (bool)
```

| Name     | Description                        |
| -------- | ---------------------------------- |
| `index_` | Index of the reward pool to check. |

### isRewardPoolPublic

Checks if a reward pool is marked as public.

```solidity
function isRewardPoolPublic(uint256 index_) public view returns (bool)
```

| Name     | Description                        |
| -------- | ---------------------------------- |
| `index_` | Index of the reward pool to query. |

### supportsInterface

Used for interface detection (ERC165). Returns true if the contract supports a specific `interfaceId_`. Supports `IChainLinkDataConsumer`, `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/distribution-protocol/v7-protocol/contracts/rewardpool.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.
