ShareXAirdrop
Inherits: Initializable, AccessControlUpgradeable, PausableUpgradeable, ReentrancyGuardUpgradeable, IShareXAirdrop
Title: ShareXAirdrop - Token Airdrop with Whitelist and Time Control
Author: ShareX Team
Upgradeable airdrop contract for SHARE tokens Key Features:
- Admin sets whitelist allocations per address
- Time-controlled claim window (start/end timestamps)
- Users can claim partial or full allocated amounts
- Gas-optimized storage layout
State Variables
_shareToken
SHARE token contract - slot 0 (20 bytes)
IERC20 private _shareToken;
_startTime
Claim start timestamp - slot 0 (8 bytes, packed with token)
uint64 private _startTime;
_endTime
Claim end timestamp - slot 0 (8 bytes, packed)
uint64 private _endTime;
_allocations
User address => allocation info - slot 1
mapping(address user => AllocationInfoInternal info) private _allocations;
_totalAllocated
Total tokens allocated - slot 2 (16 bytes)
uint128 private _totalAllocated;
_totalClaimed
Total tokens claimed - slot 2 (16 bytes, packed)
uint128 private _totalClaimed;
__gap
Reserved storage gap for upgrades
uint256[47] private __gap;
Functions
validAddress
modifier validAddress(address addr);
whenClaimActive
modifier whenClaimActive();
initialize
Initialize the airdrop contract
function initialize(address shareToken_, address admin_)
external
initializer
validAddress(shareToken_)
validAddress(admin_);
Parameters
| Name | Type | Description |
|---|---|---|
shareToken_ | address | SHARE token contract address |
admin_ | address | Admin address with DEFAULT_ADMIN_ROLE |
setAllocation
Set allocation for a single address
function setAllocation(address account, uint256 amount)
external
override
onlyRole(DEFAULT_ADMIN_ROLE)
validAddress(account);
Parameters
| Name | Type | Description |
|---|---|---|
account | address | The address to set allocation for |
amount | uint256 | The amount of SHARE tokens allocated |
setAllocations
Set allocations for multiple addresses in batch
function setAllocations(address[] calldata accounts, uint256[] calldata amounts)
external
override
onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
accounts | address[] | Array of addresses |
amounts | uint256[] | Array of allocation amounts |
setAirdropTime
Set the airdrop time window
function setAirdropTime(uint64 startTime_, uint64 endTime_)
external
override
onlyRole(DEFAULT_ADMIN_ROLE);
Parameters
| Name | Type | Description |
|---|---|---|
startTime_ | uint64 | Timestamp when claims start |
endTime_ | uint64 | Timestamp when claims end |
withdrawUnclaimedTokens
Withdraw unclaimed tokens after airdrop ends
function withdrawUnclaimedTokens(uint256 amount)
external
override
onlyRole(DEFAULT_ADMIN_ROLE)
nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint256 | Amount of tokens to withdraw |
pause
Pause the contract
function pause() external onlyRole(DEFAULT_ADMIN_ROLE);
unpause
Unpause the contract
function unpause() external onlyRole(DEFAULT_ADMIN_ROLE);
claim
Claim a specific amount of tokens
function claim(uint256 amount) external override nonReentrant whenNotPaused whenClaimActive;
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint256 | Amount of tokens to claim |
claimAll
Claim all available tokens
function claimAll() external override nonReentrant whenNotPaused whenClaimActive;
getAllocation
Get allocation info for an address
function getAllocation(address account)
external
view
override
returns (AllocationInfo memory info);
Parameters
| Name | Type | Description |
|---|---|---|
account | address | The address to query |
Returns
| Name | Type | Description |
|---|---|---|
info | AllocationInfo | AllocationInfo struct with allocated and claimed amounts |
getClaimableAmount
Get claimable amount for an address
function getClaimableAmount(address account) external view override returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
account | address | The address to query |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | claimable Amount that can be claimed |
getAirdropInfo
Get airdrop configuration and status
function getAirdropInfo() external view override returns (AirdropInfo memory info);
Returns
| Name | Type | Description |
|---|---|---|
info | AirdropInfo | AirdropInfo struct with all details |
isClaimActive
Check if claim period is currently active
function isClaimActive() external view override returns (bool);
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | active True if claims are allowed |
shareToken
Get the SHARE token address
function shareToken() external view override returns (address);
Returns
| Name | Type | Description |
|---|---|---|
<none> | address | token The token address |
startTime
Get the claim start time
function startTime() external view override returns (uint64);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint64 | startTime The start timestamp |
endTime
Get the claim end time
function endTime() external view override returns (uint64);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint64 | endTime The end timestamp |
totalAllocated
Get total allocated amount
function totalAllocated() external view override returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | total The total allocated |
totalClaimed
Get total claimed amount
function totalClaimed() external view override returns (uint256);
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | total The total claimed |
_setAllocation
Set allocation for a single address
function _setAllocation(address account, uint256 amount) internal;
_claim
Process a claim for a user
function _claim(address user, uint256 amount) internal;
_getClaimableAmount
Get claimable amount for an address
function _getClaimableAmount(address account) internal view returns (uint256);
_isClaimActive
Check if claim period is active
function _isClaimActive() internal view returns (bool);
Structs
AllocationInfoInternal
Packed allocation info (1 storage slot)
struct AllocationInfoInternal {
uint128 allocated; // 16 bytes - max allocation
uint128 claimed; // 16 bytes - amount claimed
}