> For the complete documentation index, see [llms.txt](https://docs.leequid.io/leequid/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.leequid.io/leequid/leequid-in-depth/smart-contracts/rewards.md).

# Rewards

The Rewards contract is a key piece in the liquid staking application, providing a way to distribute rewards to protocol participants, handling protocol fees, and managing checkpoints for efficient reward calculation. This contract is also the withdrawal address of the protocol's validators: where all the rewards and unstakes from the protocol's validators get sent to.&#x20;

The *Rewards* contract interacts with various other contracts including:

1. [*StakedLyxToken*](/leequid/leequid-in-depth/smart-contracts/merkle-distributor.md): Tracks the staked tokens.
2. [*Oracles*](/leequid/leequid-in-depth/smart-contracts/oracles.md): Responsible for updating the total rewards in the Rewards contract.
3. [*MerkleDistributor*](/leequid/leequid-in-depth/smart-contracts/merkle-distributor.md)*:* Distributes the rewards to the protocol's participants.
4. [*FeesEscrow*](/leequid/leequid-in-depth/smart-contracts/feesescrow.md): Handles the protocol's execution layer fees.
5. [*Pool*](/leequid/leequid-in-depth/smart-contracts/pool.md)*:* Handles incoming LYX.

### Key features

The *Rewards* contract tracks the total rewards earned by the staking protocol and the total amount that has been cashed out. It also calculates the reward per token for user reward calculation.

#### **Checkpointing**

To optimize gas usage and enhance scalability, the contract uses a checkpoint system that keeps track of an account's rewards at a particular point in time. The reward per token is stored in each checkpoint, along with the reward value, in a single memory slot. This allows the Rewards contract to calculate the user's reward.

```solidity
struct Checkpoint {
    uint128 reward;
    uint128 rewardPerToken;
}
```

#### **Fee Handling**

The contract calculates protocol fees and handles the distribution of these fees. It allows the protocol's admin to set the fee recipient address and fee percentage.

#### **Oracles**

An oracle system is in place that updates the total rewards in the Rewards contract.

#### **Reward disabling**

The contract provides an option to disable rewards for an account. The state is toggled by calling the `setRewardsDisabled` function. Rewards of addresses with rewards disabled accrue in the distributor principal, the balance of the [Merkle Distributor contract](/leequid/leequid-in-depth/smart-contracts/merkle-distributor.md), responsible for the token distribution of rewards calculated off-chain.

#### **Auto-compounding**

The contract stores a list of addresses who explicitly granted permission for rewards to be staked on their behalf and provides an interface to effectively re-stake these rewards. This operation can be done in batch and it will call the Pool contract's, transferring LYX to it.


---

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.leequid.io/leequid/leequid-in-depth/smart-contracts/rewards.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
