Skip to main content
The 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

Campaign Registry

Functions

Initialization

Constructor

Parameters:
  • globalParams: Address of the global parameters contract
  • campaignImplementation: Address of the campaign implementation contract
Effects:
  • Sets the global parameters reference
  • Sets the campaign implementation address
  • Initializes the owner

Initialize

Parameters:
  • treasuryFactoryAddress: Address of the treasury factory
  • globalParams: Address of the global parameters contract
Effects:
  • Sets the treasury factory address
  • Updates the global parameters reference
  • Marks the factory as initialized
Requirements:
  • Only callable by the owner
  • Can only be called once
  • Both addresses must be non-zero

Campaign Creation

Create Campaign

Parameters:
  • creator: Address of the campaign creator
  • identifierHash: Unique identifier for the campaign
  • selectedPlatformHash: Array of selected platform hashes
  • platformDataKey: Array of platform data keys
  • platformDataValue: Array of platform data values
  • campaignData: Campaign configuration data
Effects:
  • Creates a new campaign instance
  • Validates all platform selections
  • Initializes the campaign with provided data
  • Registers the campaign in the factory
Requirements:
  • 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
Events:
  • CampaignInfoFactoryCampaignCreated(bytes32 indexed identifierHash, address indexed campaignAddress)
  • CampaignInfoFactoryCampaignInitialized()

Implementation Management

Update Implementation

Parameters:
  • newImplementation: Address of the new implementation contract
Effects:
  • Updates the campaign implementation address
  • Affects all future campaign creations
Requirements:
  • 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 updateImplementation are 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’s Clones library for gas-efficient campaign creation:
Benefits:
  • 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