# MultiMerkleDistributor

The MultiMerkleDistributor is the Distributor smart contract in the Quest system. This smart contract is based on the logic of a Merkle Tree Distributor, adapted to handle multiple Merkl Tree, for each Quest, and each period of those Quests.\
The Distributor will receive the rewards that voter will claim when a period is closed, and then Merkle Roots, generated using Quests parameters, and votes from the closed periods (& previous periods). Once a Merkle Root is set for a period of a Quest, voters can claim the rewards anytime they wish.

## Storage mappings & variables

### questRewardToken

Mapping listing the reward token associated to each Quest ID

`mapping(uint256 => address) public questRewardToken;`

### rewardTokens

Mapping of tokens this contract is or was distributing&#x20;

`mapping(address => bool) public rewardTokens;`

### questClosedPeriods

List of Closed QuestPeriods by Quest ID&#x20;

`mapping(uint256 => uint256[]) public questClosedPeriods;`

### questMerkleRootPerPeriod

Merkle Root for each period of a Quest (indexed by Quest ID)

`mapping(uint256 => mapping(uint256 => bytes32)) public questMerkleRootPerPeriod;`

### questRewardsPerPeriod

Amount of rewards for each period of a Quest (indexed by Quest ID)

`mapping(uint256 => mapping(uint256 => uint256)) public questRewardsPerPeriod;`

### questPeriodClaimedBitMap

BitMap of claims for each period of a Quest&#x20;

`mapping(uint256 => mapping(uint256 => mapping(uint256 => uint256))) private questPeriodClaimedBitMap;`

### questBoard

Address of the QuestBoard contract

`address public immutable questBoard;`

## Read only methods

### isClaimed

Checks if the rewards were claimed for an user on a given period

`function isClaimed(uint256 questID, uint256 period, uint256 index) public view returns (bool)`

### getClosedPeriodsByQuests

Returns all current Closed periods for the given Quest ID

`function getClosedPeriodsByQuests(uint256 questID) external view returns (uint256[] memory)`

## User state-changing functions

### claim

Claims the reward for an user for a given period of a Quest

`function claim(uint256 questID, uint256 period, uint256 index, address account, uint256 amount, bytes32[] calldata merkleProof) public`

**Parameters:**

* `questID` ID of the Quest&#x20;
* `period` Timestamp of the period&#x20;
* `index` Index in the Merkle Tree&#x20;
* `account` Address of the user claiming the rewards&#x20;
* `amount` Amount of rewards to claim&#x20;
* `merkleProof` Proof to claim the rewards

### multiClaim

Claims multiple rewards for a given list

`function multiClaim(address account, ClaimParams[] calldata claims) external`

**Parameters:**

* `account` Address of the user claiming the rewards
* `claims` List of ClaimParams struct data to claim

With the Struct:

`struct ClaimParams { uint256 questID; uint256 period; uint256 index; uint256 amount; bytes32[] merkleProof; }`

### claimQuest

Claims the reward for all the given periods of a Quest, and transfer all the rewards at once

`function claimQuest(address account, uint256 questID, ClaimParams[] calldata claims) external`

**Parameters:**

* `account` Address of the user claiming the rewards
* `questID` ID of the Quest
* `claims` List of ClaimParams struct data to claim


---

# 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://docs.paladin.vote/warden-quest-v1-deprecated/smart-contracts/multimerkledistributor.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.
