> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gains.trade/llms.txt
> Use this file to discover all available pages before exploring further.

# EpochBasedTokenClaim

*Contract to claim rewards based on epoch and merkle tree (used for Arbitrum STIP trading incentives)*

## rewardToken

```solidity theme={null}
contract IERC20 rewardToken
```

## manager

```solidity theme={null}
address manager
```

## epochRoots

```solidity theme={null}
mapping(uint256 => bytes32) epochRoots
```

## epochCids

```solidity theme={null}
mapping(uint256 => string) epochCids
```

## epochTraderClaimed

```solidity theme={null}
mapping(uint256 => mapping(address => bool)) epochTraderClaimed
```

## ManagerUpdated

```solidity theme={null}
event ManagerUpdated(address newManager)
```

## TokensWithdrawn

```solidity theme={null}
event TokensWithdrawn()
```

## EpochMerkleRootSet

```solidity theme={null}
event EpochMerkleRootSet(uint256 epoch, bytes32 root, uint256 totalRewards, string cid)
```

## TokensClaimed

```solidity theme={null}
event TokensClaimed(uint256 epoch, address user, uint256 rewardAmount)
```

## TokensClaimed

```solidity theme={null}
event TokensClaimed(uint256[] epochs, address user, uint256 rewardAmount)
```

## AddressZero

```solidity theme={null}
error AddressZero()
```

## NotManager

```solidity theme={null}
error NotManager()
```

## RootAlreadySet

```solidity theme={null}
error RootAlreadySet()
```

## RootZero

```solidity theme={null}
error RootZero()
```

## RewardsZero

```solidity theme={null}
error RewardsZero()
```

## CidZero

```solidity theme={null}
error CidZero()
```

## InvalidEpochs

```solidity theme={null}
error InvalidEpochs()
```

## ArrayLengthMismatch

```solidity theme={null}
error ArrayLengthMismatch()
```

## EpochNotSet

```solidity theme={null}
error EpochNotSet()
```

## NotEnoughBalance

```solidity theme={null}
error NotEnoughBalance()
```

## AlreadyClaimed

```solidity theme={null}
error AlreadyClaimed()
```

## InvalidProof

```solidity theme={null}
error InvalidProof()
```

## constructor

```solidity theme={null}
constructor(contract IERC20 _rewardToken, address _owner, address _manager) public
```

## onlyManager

```solidity theme={null}
modifier onlyManager()
```

## setManager

```solidity theme={null}
function setManager(address _manager) external
```

*Sets manager address to `_manager`. Only callable by `owner()` (multisig)*

## setRoot

```solidity theme={null}
function setRoot(uint256 _epoch, bytes32 _root, uint256 _totalRewards, string _cid) external
```

\_Sets Merkle Tree `_root` and '*cid' for an `_epoch` and transfers `_totalRewards` from the `owner()` (multisig) to this contract. Only callable by `manager`.*

## withdrawTokens

```solidity theme={null}
function withdrawTokens() external
```

*Prevents stuck tokens in case of misconfiguration; Only `owner()` (multisig) can claim the tokens back*

## claimRewards

```solidity theme={null}
function claimRewards(uint256 _epoch, uint256 _rewardAmount, bytes32[] _proof) external
```

*Claims trader rewards for a specific `_epoch`*

## claimMultipleRewards

```solidity theme={null}
function claimMultipleRewards(uint256[] _epochs, uint256[] _rewardAmounts, bytes32[][] _proofs) external
```

*Claims trader rewards for multiple `_epochs`*

## \_hashLeaf

```solidity theme={null}
function _hashLeaf(address _user, uint256 _amount) internal pure returns (bytes32)
```

*Returns a hashed leaf of `_user` + `_amount`*

## \_validateClaim

```solidity theme={null}
function _validateClaim(uint256 _epoch, address _trader, uint256 _rewardAmount, bytes32[] _proof) internal view
```

\_Validates that:

1. The `_epoch` merkle tree root is set
2. There are enough token rewards in the contract
3. Rewards for leaf are unclaimed
4. The `leaf` and `_proof` validate against `epochRoot`\_
