CampaignInfoFactory contract is responsible for creating and managing campaign instances in the Oak Network protocol. It serves as the primary entry point for campaign creation and maintains a registry of all valid campaigns.
Overview
Key Features
- Campaign Creation: Creates new campaign instances using the clone pattern
- Campaign Registry: Maintains a registry of all valid campaigns
- Identifier Management: Ensures unique campaign identifiers
- Platform Validation: Validates selected platforms before campaign creation
- Implementation Management: Manages campaign implementation contracts
State Variables
Core Configuration
| Variable | Type | Description |
|---|---|---|
GLOBAL_PARAMS | IGlobalParams | Global parameters contract reference |
s_treasuryFactoryAddress | address | Address of the treasury factory |
s_initialized | bool | Whether the factory is initialized |
s_implementation | address | Campaign implementation contract address |
Campaign Registry
| Variable | Type | Description |
|---|---|---|
isValidCampaignInfo | mapping(address => bool) | Maps campaign addresses to validity status |
identifierToCampaignInfo | mapping(bytes32 => address) | Maps identifiers to campaign addresses |
Functions
Initialization
Constructor
globalParams: Address of the global parameters contractcampaignImplementation: Address of the campaign implementation contract
- Sets the global parameters reference
- Sets the campaign implementation address
- Initializes the owner
Initialize
treasuryFactoryAddress: Address of the treasury factoryglobalParams: Address of the global parameters contract
- Sets the treasury factory address
- Updates the global parameters reference
- Marks the factory as initialized
- Only callable by the owner
- Can only be called once
- Both addresses must be non-zero
Campaign Creation
Create Campaign
creator: Address of the campaign creatoridentifierHash: Unique identifier for the campaignselectedPlatformHash: Array of selected platform hashesplatformDataKey: Array of platform data keysplatformDataValue: Array of platform data valuescampaignData: Campaign configuration data
- Creates a new campaign instance
- Validates all platform selections
- Initializes the campaign with provided data
- Registers the campaign in the factory
- Campaign launch time must be in the future
- Campaign deadline must be after launch time
- All selected platforms must be listed
- Campaign identifier must be unique
- Platform data arrays must have matching lengths
CampaignInfoFactoryCampaignCreated(bytes32 indexed identifierHash, address indexed campaignAddress)CampaignInfoFactoryCampaignInitialized()
Implementation Management
Update Implementation
newImplementation: Address of the new implementation contract
- Updates the campaign implementation address
- Affects all future campaign creations
- Only callable by the owner
- New implementation must be non-zero
Events
Campaign Events
Error Events
Usage Examples
Basic Campaign Creation
Platform Validation
Campaign Registry Queries
Security Considerations
Access Control
- Owner Only: Critical functions like
updateImplementationare restricted to the owner - Initialization: Factory can only be initialized once to prevent reinitialization attacks
- Platform Validation: All platforms are validated before campaign creation
Input Validation
- Parameter Bounds: All parameters are validated for reasonable ranges
- Array Lengths: Platform data arrays must have matching lengths
- Address Validation: All addresses are validated for non-zero values
Reentrancy Protection
- External Calls: External calls are made last in functions
- State Updates: State is updated before external calls
- Checks-Effects-Interactions: Standard pattern implementation
Gas Optimization
Clone Pattern
The factory uses OpenZeppelin’sClones library for gas-efficient campaign creation:
- Gas Efficient: Much cheaper than deploying new contracts
- Immutable Args: Critical parameters stored in immutable args
- Upgradeable: Implementation can be upgraded without affecting existing campaigns
Storage Optimization
- Minimal Storage: Only essential data stored in factory
- Event Logging: Comprehensive event logging for off-chain indexing
- Efficient Mappings: Optimized data structures for lookups
Integration Patterns
Factory Pattern
Event Monitoring
Error Handling
Common Errors
Retry Logic
Testing
Unit Tests
Next Steps
- CampaignInfo Contract - Campaign instance contract
- GlobalParams Contract - Global parameters management
- TreasuryFactory Contract - Treasury creation