Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

RewardDistributor

ABI

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

NameTypeDescription
_addressProvideraddressThe address of the AddressProvider.
_tokenaddressThe address of the token to distribute.

claims

Claims rewards for multi Epoch.

function claims(ClaimCallData[] calldata _claimsData) external whenNotPaused nonReentrant;

Parameters

NameTypeDescription
_claimsDataClaimCallData[]The claim data array info.

forwardExpiredRewards

Transfer expired rewards to the fee collector.

function forwardExpiredRewards(uint64[] calldata _epochIds) external;

Parameters

NameTypeDescription
_epochIdsuint64[]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

NameTypeDescription
_epochIdsuint64[]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

NameTypeDescription
_tokenaddressThe address of the token.
_toaddressThe address of the recipient.
_amountuint256The amount of tokens to rescue.

setAddressProvider

Allow maintainer to update the address of the AddressProvider contract.

function setAddressProvider(address newAddressProvider) external onlyMaintainer;

Parameters

NameTypeDescription
newAddressProvideraddressThe 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

NameTypeDescription
_epochIduint64
_accountaddressThe address of the claimer.
_amountuint256The amount that the account should claim for the epoch.
_proofbytes32[]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

NameTypeDescription
newAddressProvideraddressThe 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

NameTypeDescription
epochIduint64The epoch id.
rootbytes32The merkle's tree root.
totalAmountuint256The totalAmount to distribute.
startTimeuint64The start time of the epoch.
endTimeuint64The 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

NameTypeDescription
tokenaddressThe address of the token.
toaddressThe address of the recipient.
amountuint256The amount of tokens rescued.

RewardsClaimed

Emitted when an account claims rewards.

event RewardsClaimed(uint64 epochId, address account, uint256 amount);

Parameters

NameTypeDescription
epochIduint64The epochId claimed.
accountaddressThe address of the claimer.
amountuint256The amount of rewards claimed.

ExpiredRewardsForwarded

Emitted when expired rewards are forwarded.

event ExpiredRewardsForwarded(uint64 epochId, uint256 amount);

Parameters

NameTypeDescription
epochIduint64The epochId forwarded.
amountuint256The amount of rewards forwarded.

AddressProviderUpdated

Emitted when the addressProvider is updated.

event AddressProviderUpdated(address newAddressProvider);

Parameters

NameTypeDescription
newAddressProvideraddressThe 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;
}