TokenDistributor

Git Source

Inherits: Authorizable, ITokenDistributor

This contract allows users to claim tokens from a merkle tree proof

State Variables

root

The merkle root of the token distribution

bytes32 public root;

token

Address of the ERC20 token to be distributed

ERC20Votes public token;

totalClaimable

Total amount of tokens to be distributed

uint256 public totalClaimable;

claimPeriodStart

Timestamp when the claim period starts

uint256 public claimPeriodStart;

claimPeriodEnd

Timestamp when the claim period ends

uint256 public claimPeriodEnd;

claimed

Mapping containing the users that have already claimed

mapping(address _user => bool _hasClaimed) public claimed;

Functions

constructor

constructor(
  bytes32 _root,
  ERC20Votes _token,
  uint256 _totalClaimable,
  uint256 _claimPeriodStart,
  uint256 _claimPeriodEnd,
  address _delegateTo
) Authorizable(msg.sender);

Parameters

NameTypeDescription
_rootbytes32Bytes32 representation of the merkle root
_tokenERC20VotesAddress of the ERC20 token to be distributed
_totalClaimableuint256Total amount of tokens to be distributed
_claimPeriodStartuint256Timestamp when the claim period starts
_claimPeriodEnduint256Timestamp when the claim period ends
_delegateToaddressAddress to delegate the token votes to before they are claimed

canClaim

Checks if a user can claim tokens

function canClaim(bytes32[] calldata _proof, address _user, uint256 _amount) external view returns (bool _claimable);

Parameters

NameTypeDescription
_proofbytes32[]Array of bytes32 merkle proof hashes
_useraddressAddress of the user to check
_amountuint256Amount of tokens to check

Returns

NameTypeDescription
_claimableboolWhether the user can claim the amount with the proof provided

claim

Claims tokens from the distributor

function claim(bytes32[] calldata _proof, uint256 _amount) external;

Parameters

NameTypeDescription
_proofbytes32[]Array of bytes32 merkle proof hashes
_amountuint256Amount of tokens to claim

claimAndDelegate

Claims tokens from the distributor and delegates them using a signature

function claimAndDelegate(
  bytes32[] calldata _proof,
  uint256 _amount,
  address _delegatee,
  uint256 _expiry,
  uint8 _v,
  bytes32 _r,
  bytes32 _s
) external;

Parameters

NameTypeDescription
_proofbytes32[]Array of bytes32 merkle proof hashes
_amountuint256Amount of tokens to claim
_delegateeaddressAddress to delegate the token votes to
_expiryuint256Expiration timestamp of the signature
_vuint8Recovery byte of the signature
_rbytes32ECDSA signature r value
_sbytes32ECDSA signature s value

sweep

Withdraws tokens from the distributor to a given address after the claim period has ended

function sweep(address _sweepReceiver) external override isAuthorized;

Parameters

NameTypeDescription
_sweepReceiveraddressAddress to send the tokens to

withdraw

Withdraws tokens from the distributor to a given address

function withdraw(address _to, uint256 _amount) external override isAuthorized;

Parameters

NameTypeDescription
_toaddressAddress to send the tokens to
_amountuint256Amount of tokens to send

_canClaim

function _canClaim(bytes32[] calldata _proof, address _user, uint256 _amount) internal view returns (bool _claimable);

_claim

function _claim(bytes32[] calldata _proof, uint256 _amount) internal;

_validateClaim

function _validateClaim(bytes32[] calldata _proof, uint256 _amount) internal view;

_claimPeriodActive

function _claimPeriodActive() internal view returns (bool _active);

_merkleVerified

function _merkleVerified(bytes32[] calldata _proof, address _user, uint256 _amount) internal view returns (bool _valid);