EpochBasedTokenClaim

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

rewardToken

contract IERC20 rewardToken

manager

address manager

epochRoots

mapping(uint256 => bytes32) epochRoots

epochCids

mapping(uint256 => string) epochCids

epochTraderClaimed

mapping(uint256 => mapping(address => bool)) epochTraderClaimed

ManagerUpdated

event ManagerUpdated(address newManager)

TokensWithdrawn

event TokensWithdrawn()

EpochMerkleRootSet

event EpochMerkleRootSet(uint256 epoch, bytes32 root, uint256 totalRewards, string cid)

TokensClaimed

event TokensClaimed(uint256 epoch, address user, uint256 rewardAmount)

TokensClaimed

event TokensClaimed(uint256[] epochs, address user, uint256 rewardAmount)

AddressZero

error AddressZero()

NotManager

error NotManager()

RootAlreadySet

error RootAlreadySet()

RootZero

error RootZero()

RewardsZero

error RewardsZero()

CidZero

error CidZero()

InvalidEpochs

error InvalidEpochs()

ArrayLengthMismatch

error ArrayLengthMismatch()

EpochNotSet

error EpochNotSet()

NotEnoughBalance

error NotEnoughBalance()

AlreadyClaimed

error AlreadyClaimed()

InvalidProof

error InvalidProof()

constructor

constructor(contract IERC20 _rewardToken, address _owner, address _manager) public

onlyManager

modifier onlyManager()

setManager

function setManager(address _manager) external

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

setRoot

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

function withdrawTokens() external

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

claimRewards

function claimRewards(uint256 _epoch, uint256 _rewardAmount, bytes32[] _proof) external

Claims trader rewards for a specific _epoch

claimMultipleRewards

function claimMultipleRewards(uint256[] _epochs, uint256[] _rewardAmounts, bytes32[][] _proofs) external

Claims trader rewards for multiple _epochs

_hashLeaf

function _hashLeaf(address _user, uint256 _amount) internal pure returns (bytes32)

Returns a hashed leaf of _user + _amount

_validateClaim

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_