Skip to main content

API Reference

Complete reference documentation for all TokenOps Airdrop V2 contracts and interfaces.

Overview

The TokenOps Airdrop V2 system consists of several interconnected contracts that provide a comprehensive solution for token distribution using Merkle trees. The architecture is designed for flexibility, security, and gas efficiency.

Contract Architecture

Core Contracts

Base Implementation

  • BaseTokenOpsMerkleDistributor
    • Abstract base contract providing core functionality
    • Merkle proof verification and claim tracking
    • Grace period management and access control
    • Foundation for all distributor implementations

Distributor Implementations

  • TokenOpsMerkleDistributor

    • ERC20 token distribution with staking integration
    • Supports both gas fees and token fees
    • Claim-and-stake functionality with bonus rewards
    • Comprehensive admin and fee management
  • TokenOpsMerkleDistributorNative

    • Native token distribution (ETH, MATIC, etc.)
    • Gas-only fee structure for simplicity
    • Optimized for native token transfers
    • Streamlined administration

Factory Contract

  • TokenOpsMerkleDistributorFactory
    • Centralized deployment and configuration
    • Custom fee management per campaign creator
    • Support for both ERC20 and native distributions
    • Standardized distributor creation

Audit Reports

You can find the audit reports for this project here.

Interface Definitions

The TokenOps Airdrop V2 system utilizes several key interfaces to ensure consistency and interoperability:

Core Interfaces

  • ITokenOpsMerkleDistributorBase

    • Base interface for all distributors
    • Common functionality across implementations
    • Time management and claim status
    • Access control patterns
  • ITokenOpsMerkleDistributor

    • ERC20 distributor interface
    • Staking integration definitions
    • Comprehensive event and error definitions
    • Fee management functions
  • ITokenOpsMerkleDistributorNative

    • Native token distributor interface
    • Simplified functionality for native tokens
    • Gas-only fee structure
    • Efficient native token handling

Supporting Interfaces

  • ITokenOpsMerkleDistributorFactory

    • Factory contract interface
    • Deployment and configuration functions
    • Custom fee management
    • Event definitions for tracking
  • ITokenOpsStaking

    • Staking integration interface
    • Used by ERC20 distributors
    • Fee configuration for staking
    • Direct staking operations
  • ITypes

    • Shared type definitions
    • FeeType enumeration
    • Used across all contracts
    • Type safety and consistency

Feature Matrix

FeatureERC20 DistributorNative DistributorFactory
Token SupportERC20 tokensNative tokensBoth
Fee TypesGas or Token feesGas fees onlyConfigurable
Staking Integration✅ Full support❌ Not available✅ Configurable
Claim✅ Yes✅ Yes❌ Not supported
Claim and Stake✅ Yes❌ Not available❌ Not supported
Bonus Rewards✅ Configurable❌ Not available✅ Per deployment
Grace Period✅ 7-day protection✅ 7-day protection✅ All deployments
Custom Fees❌ Factory controlled❌ Factory controlled✅ Per creator
Admin Separation✅ Owner + Fee Collector✅ Owner + Fee Collector✅ Owner + Fee Collector

Quick Reference

Common Operations

Creating a Distributor

// ERC20 distributor
const erc20Distributor = await factory.newMerkleDistributor(
tokenAddress,
merkleRoot,
startTime,
endTime,
stakingContract,
rewardOwner,
bonusPercentage
);

// Native distributor
const nativeDistributor = await factory.newMerkleDistributorNative(
merkleRoot,
startTime,
endTime,
{ value: totalAmount }
);

Claiming Tokens

// Basic claim
await distributor.claim(index, account, amount, proof, { value: fee });

// Claim and stake (ERC20 only)
await distributor.claimAndStake(index, account, amount, proof, { value: fee });

Admin Operations

// Withdraw remaining tokens
await distributor.withdraw();

// Withdraw fees (fee collector only)
await distributor.withdrawGasFee(recipient, amount);
await distributor.withdrawTokenFee(recipient, amount); // ERC20 only

Security Considerations

Access Control

  • Owner Role: Contract deployer, manages withdrawals
  • Fee Collector Role: Separate role for fee management
  • Role Transfer: Fee collector role can be transferred

Time Management

  • Start/End Times: Enforced claim windows
  • Grace Period: 7-day protection after first claim
  • Expiration Handling: Proper cleanup after campaigns end

Proof Validation

  • Merkle Proofs: Cryptographically secure validation
  • Single Claims: Each index can only be claimed once
  • Tamper Protection: Invalid proofs are rejected

Gas Optimization

Efficient Patterns

  • Bitmap Claims: Gas-efficient claim tracking
  • Packed Storage: Optimized storage layouts
  • Batch Operations: Multiple operations in single transaction
  • Native Token Transfers: Direct transfers for native tokens

Error Reference

Common Errors

ErrorContractCauseSolution
InvalidProof()All DistributorsInvalid Merkle proofGenerate correct proof
ClaimWindowFinished()All DistributorsPast end timeCheck timing
InsufficientFee()All DistributorsInsufficient fee paidPay correct amount
NoWithdrawDuringClaim()All DistributorsClaim period activeWait for end time
NotEnoughTokens()ERC20 DistributorInsufficient balanceFund contract
StakingNotEnabled()ERC20 DistributorStaking not configuredCheck staking setup

Deployment Checklist

Pre-Deployment

  • Merkle tree generated and validated
  • Start and end times configured
  • Fee structure determined
  • Admin and fee collector addresses set
  • Token contracts deployed (if ERC20)

Deployment

  • Factory contract deployed
  • Distributor contracts created via factory
  • Contract verification on block explorer
  • Initial funding completed
  • Access controls configured

Post-Deployment

  • Claims tested with sample proofs
  • Event monitoring setup
  • Admin functions tested
  • Fee collection tested
  • Documentation updated