Disperse Overview
Overview
The TokenOps Disperse Protocol is a comprehensive smart contract system designed for efficient batch distribution of cryptocurrencies (ETH and ERC20 tokens) to multiple recipients. The protocol features a factory pattern architecture that allows users to deploy custom disperse contracts with tailored fee structures.
🏗️ Architecture
The protocol consists of three main components:
1. Factory Contract
- DisperseFactory - Central deployment and management contract
- Deploys custom disperse contracts with configurable fees
- Manages default and custom fee structures
- Provides access control and fee collection management
2. Disperse Contracts
- DisperseGasFee - Fixed gas-based fee structure
- DisperseTokenFee - Percentage-based token fee structure
3. Shared Libraries
- Errors - Centralized error definitions and handling
Audit Reports
You can find the audit reports for this project here.
🎯 Key Features
Multi-Asset Support
- ETH Dispersion: Batch transfer of Ether to multiple recipients
- ERC20 Token Dispersion: Batch transfer of any ERC20 token
- Mixed Operations: Support for both assets in a single deployment
Flexible Fee Structures
- Gas-Based Fees: Fixed fee charged in ETH per transaction
- Token-Based Fees: Percentage-based fees charged in the distributed token
- Custom Fee Configuration: Per-user custom fee settings
- Fee Deduction Options: Pay fees on top or deduct from recipient amounts
Advanced Management
- Role-Based Access Control: Owner and fee collector role separation
- Fee Collection: Secure withdrawal mechanisms for accumulated fees
- Per-Token Accounting: Separate fee tracking for each token type
- Emergency Controls: Owner-controlled emergency withdrawal functions
📊 Fee Structure Comparison
Feature | DisperseGasFee | DisperseTokenFee |
---|---|---|
Fee Type | Fixed gas fee (ETH) | Percentage-based (tokens) |
Payment Method | ETH alongside distribution | Tokens (on top or deducted) |
Use Case | ETH distributions, gas sponsorship | Token distributions, proportional fees |
Fee Calculation | gasFee per transaction | (amount * feePercentage) / 10000 |
Minimum Fee | Set gas fee amount | Based on distributed amounts |
🔐 Security Features
Access Control
- Owner Role: Deploy contracts, emergency controls, configuration updates
- Fee Collector Role: Withdraw accumulated fees, role management
- Creator Role: Individual contract ownership after deployment
Safety Mechanisms
- Address Validation: Zero address protection throughout
- Array Length Validation: Prevents mismatched recipient/amount arrays
- Balance Checks: Ensures sufficient funds before operations
- Safe Transfer: OpenZeppelin SafeERC20 implementation
- Reentrancy Protection: Secure transfer patterns
Fee Protection
- Reserved Fee Tracking: Separate accounting prevents accidental withdrawals
- Fee Bounds: Maximum fee limits prevent excessive charges
- Role Separation: Fee collection isolated from owner functions
🔄 Workflow Examples
Standard Distribution Workflow
- Deploy: Use factory to create disperse contract
- Configure: Set custom fees if needed (factory owner)
- Prepare: Approve tokens (for token distributions)
- Distribute: Call disperse function with recipients and amounts
- Collect: Fee collector withdraws accumulated fees
Custom Fee Configuration
- Set Custom Fee: Factory owner configures per-user fees
- Deploy Contract: User deploys with custom fee structure
- Operate: Contract uses custom fees instead of defaults
🛠️ Contract Interfaces
Core Interfaces
IDisperseFactory
- Factory contract interfaceIDisperseGasFee
- Gas-based disperse interfaceIDisperseTokenFee
- Token-based disperse interfaceITypes
- Shared type definitions
Events
All contracts emit comprehensive events for:
- Distribution operations
- Fee collection
- Role changes
- Configuration updates
⚡ Gas Optimization
Batch Operations
- Single transaction for multiple transfers
- Reduced gas costs compared to individual transfers
- Optimized loops with minimal external calls
Storage Optimization
- Immutable variables for deployment-time constants
- Efficient mapping structures for fee tracking
- Minimal storage updates during operations
📝 Error Handling
The protocol uses a centralized error library providing:
- Descriptive Error Messages: Clear failure reasons
- Standardized Errors: Consistent error handling across contracts
- Gas Efficient: Custom errors instead of revert strings
🎨 Best Practices
For Users
- Always validate recipient addresses and amounts before distribution
- Use appropriate fee type based on your distribution needs
- Monitor gas prices for ETH distributions
- Batch operations to minimize transaction costs
For Integrators
- Implement proper error handling for all contract calls
- Use events for tracking distribution history
- Validate contract addresses before operations
- Test with small amounts before large distributions
🔍 Contract Addresses
Note: Contract addresses will be updated after deployment to respective networks.
Contract | Network | Address |
---|---|---|
DisperseFactory | Mainnet | TBD |
DisperseFactory | Polygon | TBD |
DisperseFactory | Arbitrum | TBD |