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

ShareXAirdrop

Git Source

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

NameTypeDescription
shareToken_addressSHARE token contract address
admin_addressAdmin 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

NameTypeDescription
accountaddressThe address to set allocation for
amountuint256The 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

NameTypeDescription
accountsaddress[]Array of addresses
amountsuint256[]Array of allocation amounts

setAirdropTime

Set the airdrop time window

function setAirdropTime(uint64 startTime_, uint64 endTime_)
    external
    override
    onlyRole(DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
startTime_uint64Timestamp when claims start
endTime_uint64Timestamp when claims end

withdrawUnclaimedTokens

Withdraw unclaimed tokens after airdrop ends

function withdrawUnclaimedTokens(uint256 amount)
    external
    override
    onlyRole(DEFAULT_ADMIN_ROLE)
    nonReentrant;

Parameters

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

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

NameTypeDescription
accountaddressThe address to query

Returns

NameTypeDescription
infoAllocationInfoAllocationInfo struct with allocated and claimed amounts

getClaimableAmount

Get claimable amount for an address

function getClaimableAmount(address account) external view override returns (uint256);

Parameters

NameTypeDescription
accountaddressThe address to query

Returns

NameTypeDescription
<none>uint256claimable Amount that can be claimed

getAirdropInfo

Get airdrop configuration and status

function getAirdropInfo() external view override returns (AirdropInfo memory info);

Returns

NameTypeDescription
infoAirdropInfoAirdropInfo struct with all details

isClaimActive

Check if claim period is currently active

function isClaimActive() external view override returns (bool);

Returns

NameTypeDescription
<none>boolactive True if claims are allowed

shareToken

Get the SHARE token address

function shareToken() external view override returns (address);

Returns

NameTypeDescription
<none>addresstoken The token address

startTime

Get the claim start time

function startTime() external view override returns (uint64);

Returns

NameTypeDescription
<none>uint64startTime The start timestamp

endTime

Get the claim end time

function endTime() external view override returns (uint64);

Returns

NameTypeDescription
<none>uint64endTime The end timestamp

totalAllocated

Get total allocated amount

function totalAllocated() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256total The total allocated

totalClaimed

Get total claimed amount

function totalClaimed() external view override returns (uint256);

Returns

NameTypeDescription
<none>uint256total 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
}