> 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/distribution-protocol/v7-protocol/guides/mor-distribution.-step-1.md).

# MOR distribution. Step #1

This document describes how MOR token rewards are distributed across deposit pools within the protocol.

## Overview

The `Distributor` contract is responsible for periodically allocating MOR rewards to registered deposit pools under a specific reward pool. The distribution process ensures that each deposit pool receives a fair share of MOR tokens based on its generated yield and token value in USD.

## Reward distribution flow

The distribution of MOR tokens is executed through the [`distributeRewards`](https://gitbook.mor.org/smart-contracts/documentation/distribution-protocol/v7-protocol/contracts/distributor.md#distributedrewards) function and follows the steps below:

#### 1. Fetch Emission Rewards from RewardPool

The `Distributor` contract queries the `RewardPool` contract to calculate the total amount of MOR tokens to emit for a given reward pool over the elapsed time period. This is based on a linear decay model defined per pool.

```solidity
uint256 rewards = rewardPool.getPeriodRewards(
  rewardPoolIndex,
  lastCalculatedTimestamp,
  uint128(block.timestamp)
);
```

The contract updates the `rewardPoolLastCalculatedTimestamp` to the current block timestamp after fetching.

#### 2. Update Token Prices for Each Deposit Pool

The `Distributor` updates USD prices for all deposit tokens in the reward pool using Chainlink data feeds:

```solidity
bytes32 chainLinkPathId = chainLinkDataConsumer.getPathId(depositPool.chainLinkPath);
uint256 price = chainLinkDataConsumer.getChainLinkDataFeedLatestAnswer(chainLinkPathId);
```

This ensures that all token values are normalized to the same unit (USD) before comparison.

#### 3. Calculate USD Yield Per Deposit Pool

For each deposit pool, the protocol calculates the **USD-denominated yield**:

```solidity
uint256 yield = (tokenBalance - lastUnderlyingBalance).to18(decimals) * tokenPrice;
```

* `tokenBalance` - current token or aToken balance held by the contract.
* `lastUnderlyingBalance` - previously recorded balance (after last reward allocation).
* `to18()` - utility to normalize token decimals to 18.
* `tokenPrice` - latest USD price from Chainlink.

The `lastUnderlyingBalance` is updated after this step.

#### 4. Compute Yield Shares and Assign Rewards

Once all yields are collected and expressed in USD, the contract calculates the **relative share** of each deposit pool:

```solidity
uint256 rewardShare = (poolYield * totalRewards) / totalYield;
```

* `poolYield` - USD yield of the deposit pool.
* `totalYield` - sum of all deposit pool yields.
* `totalRewards` - emission amount retrieved from `RewardPool`.

Rewards are then added to the `distributedRewards` mapping:

```solidity
distributedRewards[rewardPoolIndex][depositPoolAddress] += rewardShare;
```

If `totalYield` is zero, rewards are temporarily stored in `undistributedRewards`.

## Notes

* For private pools (strategy `NO_YIELD`), all rewards go to the only pool registered under that reward index.
* The reward assignment is proportional to real yield, meaning pools with higher dollar-denominated yield get more MOR.

***


---

# 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/distribution-protocol/v7-protocol/guides/mor-distribution.-step-1.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.
