MerkleDistributor
Inherits: Owned, ReentrancyGuard
Title: MerkleDistributor
Distributes ERC20 tokens to eligible addresses using Merkle proofs
Implements a custom claiming window with admin pause functionality
State Variables
_paused
Internal variable to track pause status
bool private _paused
token
The ERC20 token being distributed
ERC20 public immutable token
merkleRoot
The Merkle root of the distribution tree
bytes32 public immutable merkleRoot
claimDeadline
Timestamp when the claiming period ends (90 days from deployment)
uint256 public immutable claimDeadline
claimed
Tracks claimed amounts for each address
mapping(address => uint256) public claimed
totalClaimed
Total amount of tokens claimed so far
uint256 public totalClaimed
totalAllocated
Total amount of tokens allocated for distribution
uint256 public totalAllocated
Functions
constructor
Initializes the distributor with token and merkle root
constructor(
address _token,
bytes32 _merkleRoot,
address _owner,
uint256 window,
uint256 _totalAllocated
) Owned(_owner);
Parameters
| Name | Type | Description |
|---|---|---|
_token | address | The ERC20 token to distribute |
_merkleRoot | bytes32 | The merkle root of the distribution tree |
_owner | address | The owner address for admin functions |
window | uint256 | Time window to allow claims for in seconds |
_totalAllocated | uint256 | Total token allocation for merkle drop |
whenNotPaused
Modifier to make a function callable only when the contract is not paused.
modifier whenNotPaused() ;
claim
Claims tokens for the caller
function claim(uint256 amount, bytes32[] calldata merkleProof)
external
nonReentrant
whenNotPaused;
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint256 | The amount of tokens to claim |
merkleProof | bytes32[] | The merkle proof for the claim |
claimFor
Claims tokens on behalf of an account
function claimFor(
address account,
uint256 amount,
bytes32[] calldata merkleProof
) external nonReentrant whenNotPaused;
Parameters
| Name | Type | Description |
|---|---|---|
account | address | The account to claim for |
amount | uint256 | The amount of tokens to claim |
merkleProof | bytes32[] | The merkle proof for the claim |
canClaim
Checks if an address can claim tokens
function canClaim(
address account,
uint256 amount,
bytes32[] calldata merkleProof
) external view returns (bool _canClaim, uint256 claimableAmount);
Parameters
| Name | Type | Description |
|---|---|---|
account | address | The address to check |
amount | uint256 | The amount to check |
merkleProof | bytes32[] | The merkle proof |
Returns
| Name | Type | Description |
|---|---|---|
_canClaim | bool | Whether the address can claim |
claimableAmount | uint256 | The amount that can be claimed |
pause
Pauses claiming functionality
Only callable by owner
function pause() external whenNotPaused onlyOwner;
unpause
Unpauses claiming functionality
Only callable by owner
function unpause() external onlyOwner;
recoverERC20
Recovers ERC20 tokens sent to this contract
Can only recover non-distribution tokens before deadline, or any token after deadline
function recoverERC20(address tokenAddress, address to) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
tokenAddress | address | The token to recover |
to | address | The address to send recovered tokens to |
withdrawUnclaimed
Withdraws unclaimed tokens after the deadline
Only callable by owner after claim deadline
function withdrawUnclaimed(address to) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
to | address | The address to send unclaimed tokens to |
setTotalAllocated
Sets the total allocated amount for tracking
Should be called after funding the contract
function setTotalAllocated(uint256 _totalAllocated) external onlyOwner;
Parameters
| Name | Type | Description |
|---|---|---|
_totalAllocated | uint256 | The total amount allocated for distribution |
_claim
Internal claim logic
function _claim(
address account,
uint256 amount,
bytes32[] calldata merkleProof
) internal;
Parameters
| Name | Type | Description |
|---|---|---|
account | address | The account claiming tokens |
amount | uint256 | The total amount allocated to the account |
merkleProof | bytes32[] | The merkle proof for verification |
getClaimedAmount
Returns the amount already claimed by an account
function getClaimedAmount(address account) external view returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
account | address | The account to check |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The amount already claimed |
getRemainingTime
Returns the remaining time until claim deadline
function getRemainingTime() external view returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | The remaining time in seconds (0 if deadline passed) |
isClaimingActive
Checks if the claiming period is still active
function isClaimingActive() external view returns (bool);
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | Whether claiming is still possible |
paused
Returns true if the contract is paused, and false otherwise.
function paused() public view virtual returns (bool);
Events
Claimed
event Claimed(address indexed account, uint256 amount);
EmergencyWithdraw
event EmergencyWithdraw(
address indexed token, address indexed to, uint256 amount
);
Paused
event Paused(address account);
Unpaused
event Unpaused(address account);
Errors
InvalidProof
error InvalidProof();
ClaimingPeriodEnded
error ClaimingPeriodEnded();
AlreadyClaimed
error AlreadyClaimed();
ZeroAddress
error ZeroAddress();
ZeroAmount
error ZeroAmount();
InvalidMerkleRoot
error InvalidMerkleRoot();
DeadlineNotReached
error DeadlineNotReached();
EnforcedPause
error EnforcedPause();