RewardDistributor
Inherits: Pausable, ReentrancyGuard
Contract to distribute rewards using a merkle tree.
State Variables
addressProvider
The addressProvider contract
IAddressProvider public addressProvider;
EPOCH_LENGTH
The length of a claim/allocate epoch
uint64 public constant EPOCH_LENGTH = 28 days;
TOKEN
The token to distribute.
IERC20 public immutable TOKEN;
totalClaimed
The total amount of tokens claimed.
uint256 public totalClaimed;
lastEpochId
The last epoch id.
uint64 public lastEpochId = 1;
merkleDrops
The merkle drops.
mapping(uint64 epochId => MerkleDrop merkleDrop) public merkleDrops;
hasClaimed
The rewards already claimed.
mapping(address account => mapping(uint64 epochId => bool hasClaimed)) public hasClaimed;
totalClaimedPerUser
Tracks total amount of user claimed amounts.
mapping(address account => uint256 totalClaimed) public totalClaimedPerUser;
totalClaimedPerEpoch
Maps total claimed amount per epoch.
mapping(uint64 epochId => uint256 totalClaimed) public totalClaimedPerEpoch;
Functions
onlyMaintainer
check that msg.sender has MAINTAINER_ROLE
modifier onlyMaintainer();
onlyUserCentralized
check that msg.sender has USER_CENTRALIZED_ROLE
modifier onlyUserCentralized();
constructor
Constructs RewardsDistributor contract.
constructor(address _addressProvider, address _token);
Parameters
| Name | Type | Description |
|---|---|---|
_addressProvider | address | The address of the AddressProvider. |
_token | address | The address of the token to distribute. |
claims
Claims rewards for multi Epoch.
function claims(ClaimCallData[] calldata _claimsData) external whenNotPaused nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
_claimsData | ClaimCallData[] | The claim data array info. |
forwardExpiredRewards
Transfer expired rewards to the fee collector.
function forwardExpiredRewards(uint64[] calldata _epochIds) external;
Parameters
| Name | Type | Description |
|---|---|---|
_epochIds | uint64[] | The list of epoch that will be claimed. |
getExpiredEpochRewards
Get the total rewards that can be forward to the recipient address for the list of epoch.
will revert if an epoch is not expired.
function getExpiredEpochRewards(uint64[] calldata _epochIds) external view returns (uint256 totalExpiredRewards);
Parameters
| Name | Type | Description |
|---|---|---|
_epochIds | uint64[] | The list of epoch to check. |
updateMerkleDrop
Updates the merkleDrop for a specific epoch.
This function can only be called by AccessManager.
function updateMerkleDrop(uint64 _epoch, MerkleDrop memory _merkleDrop) external onlyUserCentralized;
emergencyRescue
Allow to rescue tokens own by the contract.
function emergencyRescue(address _token, address _to, uint256 _amount) external onlyMaintainer whenPaused;
Parameters
| Name | Type | Description |
|---|---|---|
_token | address | The address of the token. |
_to | address | The address of the recipient. |
_amount | uint256 | The amount of tokens to rescue. |
setAddressProvider
Allow maintainer to update the address of the AddressProvider contract.
function setAddressProvider(address newAddressProvider) external onlyMaintainer;
Parameters
| Name | Type | Description |
|---|---|---|
newAddressProvider | address | The new address to set. |
pause
Allow AccessManager to pause the contract.
This function can only be called by AccessManager.
function pause() external onlyMaintainer;
unpause
Allow AccessManager to unpause the contract
This function can only be called by AccessManager
function unpause() external onlyMaintainer;
_claim
Claims rewards.
function _claim(uint64 _epochId, address _account, uint256 _amount, bytes32[] calldata _proof) private;
Parameters
| Name | Type | Description |
|---|---|---|
_epochId | uint64 | |
_account | address | The address of the claimer. |
_amount | uint256 | The amount that the account should claim for the epoch. |
_proof | bytes32[] | The merkle proof that validates this claim. |
_getEpochExpiredRewards
function _getEpochExpiredRewards(uint64 _epochId) private view returns (uint256 epochExpiredRewards);
_setAddressProvider
Set the addressProvider address.
function _setAddressProvider(address newAddressProvider) private;
Parameters
| Name | Type | Description |
|---|---|---|
newAddressProvider | address | The new value to set |
Events
MerkleDropUpdated
Emitted when the root is updated.
event MerkleDropUpdated(uint64 epochId, bytes32 root, uint256 totalAmount, uint64 startTime, uint64 endTime);
Parameters
| Name | Type | Description |
|---|---|---|
epochId | uint64 | The epoch id. |
root | bytes32 | The merkle's tree root. |
totalAmount | uint256 | The totalAmount to distribute. |
startTime | uint64 | The start time of the epoch. |
endTime | uint64 | The time at which all none claimed token will be send to the expiredRewardsRecipient address. |
EmergencyRescued
Emitted when tokens are rescued.
event EmergencyRescued(address token, address to, uint256 amount);
Parameters
| Name | Type | Description |
|---|---|---|
token | address | The address of the token. |
to | address | The address of the recipient. |
amount | uint256 | The amount of tokens rescued. |
RewardsClaimed
Emitted when an account claims rewards.
event RewardsClaimed(uint64 epochId, address account, uint256 amount);
Parameters
| Name | Type | Description |
|---|---|---|
epochId | uint64 | The epochId claimed. |
account | address | The address of the claimer. |
amount | uint256 | The amount of rewards claimed. |
ExpiredRewardsForwarded
Emitted when expired rewards are forwarded.
event ExpiredRewardsForwarded(uint64 epochId, uint256 amount);
Parameters
| Name | Type | Description |
|---|---|---|
epochId | uint64 | The epochId forwarded. |
amount | uint256 | The amount of rewards forwarded. |
AddressProviderUpdated
Emitted when the addressProvider is updated.
event AddressProviderUpdated(address newAddressProvider);
Parameters
| Name | Type | Description |
|---|---|---|
newAddressProvider | address | The new addressProvider. |
Errors
ProofInvalid
Thrown when the proof is invalid or expired.
error ProofInvalid();
AlreadyClaimed
Thrown when the claimer has already claimed the rewards.
error AlreadyClaimed();
EpochExpired
Thrown when epoch expired.
error EpochExpired();
EpochNotExpired
Thrown when epoch didn't expired.
error EpochNotExpired();
NotStarted
Thrown when claim windows didn't not start.
error NotStarted();
EpochZeroNotAllowed
Thrown when epoch is zero.
error EpochZeroNotAllowed();
EpochCantBeUpdated
Thrown when epoch can't be updated.
error EpochCantBeUpdated();
EpochGapNotAllowed
Thrown when epoch updated create a gap.
error EpochGapNotAllowed();
TotalEpochRewardsExceeded
Thrown when totalAmountClaimed for the epoch after a claim will exceed the total amount to distribute.
error TotalEpochRewardsExceeded();
EmptyArray
Thrown when the epochIds array is empty.
error EmptyArray();
EpochAlreadySet
Thrown when the epoch is already set.
error EpochAlreadySet();
Structs
MerkleDrop
struct MerkleDrop {
bytes32 root;
uint256 totalAmount;
uint64 startTime;
uint64 expiryTime;
}
ClaimCallData
struct ClaimCallData {
uint64 epochId;
address account;
uint256 amount;
bytes32[] merkleProof;
}