TreasuryFactory contract is responsible for deploying treasury contracts for campaigns. It manages treasury implementations, handles platform-specific configurations, and creates treasury instances using the clone pattern for gas efficiency.
Overview
Key Features
- Treasury Deployment: Creates treasury contracts for campaigns using clone pattern
- Implementation Management: Registers and approves treasury implementations per platform
- Platform-Specific: Each platform can have multiple treasury implementations
- Protocol Approval: All implementations must be approved by protocol admin before use
- Access Control: Platform admins register implementations, protocol admin approves them
- Gas Efficient: Uses minimal proxy pattern for low-cost deployments
State Variables
ImplementationMap
| Variable | Type | Description |
|---|---|---|
implementationMap | mapping(bytes32 => mapping(uint256 => address)) | Maps platform and implementation ID to implementation address |
ApprovedImplementations
| Variable | Type | Description |
|---|---|---|
approvedImplementations | mapping(address => bool) | Whether an implementation is approved by protocol admin |
Functions
Constructor
globalParams: Global parameters contract reference
- Initializes admin access checker with GlobalParams
- Sets up access control for platform and protocol admins
Treasury Implementation Registration
Register Treasury Implementation
platformHash: Platform identifierimplementationId: Unique ID for this implementationimplementation: Contract address of the treasury implementation
- Registers treasury implementation for platform
- Can be called before approval
- Only callable by platform admin
- Implementation address must be non-zero
- Platform admin registers their treasury implementations
- Multiple implementations can be registered per platform
- Implementation IDs are platform-specific
Approve Treasury Implementation
platformHash: Platform identifierimplementationId: Implementation ID to approve
- Approves implementation for use in deployments
- Emits approval event
- Only callable by protocol admin
- Implementation must be registered
- Protocol admin review required before deployments
- Prevents malicious implementations from being used
Disapprove Treasury Implementation
implementation: Implementation address to disapprove
- Revokes approval for implementation
- Prevents new deployments using this implementation
- Only callable by protocol admin
- Security issues discovered
- Updated implementation available
- Deprecated functionality
Remove Treasury Implementation
platformHash: Platform identifierimplementationId: Implementation ID to remove
- Removes implementation registration from platform
- Prevents new deployments
- Only callable by platform admin
Treasury Deployment
Deploy Treasury
platformHash: Platform identifierinfoAddress: CampaignInfo contract addressimplementationId: Implementation to deployname: Treasury contract namesymbol: Treasury contract symbol
- Address of deployed treasury clone
- Creates new treasury contract using clone pattern
- Initializes treasury with campaign info
- Sets up platform configuration
- Only callable by platform admin
- Implementation must be approved
- Campaign info address must be valid
Query Functions
Get Treasury Address
platformHash: Platform identifierimplementationId: Implementation ID
- Treasury implementation address
Check Implementation Approved
implementation: Implementation address to check
- True if implementation is approved
Events
TreasuryImplementationRegistered
TreasuryImplementationApproved
TreasuryImplementationDisapproved
TreasuryDeployed
Errors
TreasuryFactoryUnauthorized
TreasuryFactoryInvalidAddress
TreasuryFactoryImplementationNotSet
TreasuryFactoryImplementationNotSetOrApproved
TreasuryFactoryTreasuryCreationFailed
TreasuryFactoryTreasuryInitializationFailed
TreasuryFactorySettingPlatformInfoFailed
Usage Examples
Platform Setup
Protocol Approval
Deploy Treasury for Campaign
Check Implementation Status
Complete Workflow
Security Considerations
Two-Stage Approval
- Registration: Platform admin registers implementation
- Approval: Protocol admin must approve before use
- Review Process: Allows code review before production use
- Deprecation: Can disapprove implementations with issues
Access Control
- Platform Admin: Registers implementations, deploys treasuries
- Protocol Admin: Approves implementations, can revoke approval
- Separation of Concerns: Platform manages platform-level config, protocol manages security
Clone Pattern
- Gas Efficiency: Minimal proxy pattern reduces deployment costs
- Upgradeability: Implementation can be upgraded, existing clones use new logic
- Consistency: All clones share same implementation code
Implementation Verification
- Approval Required: Cannot deploy unapproved implementations
- Audit Trail: All approvals/disapprovals logged via events
- Quick Revocation: Can disapprove implementations immediately
Integration Notes
With CampaignInfoFactory
With Treasury Contracts
Event Monitoring
Best Practices
Implementation Management
- Test implementations thoroughly before registration
- Use semantic versioning for implementation IDs
- Document implementation differences and use cases
- Keep approved implementations minimal
Platform Configuration
- Use one implementation per funding model (AllOrNothing)
- Reserve implementation ID 1 for default implementation
- Use higher IDs for experimental or platform-specific models
Security
- Regular security audits of implementations
- Quick disapproval process for vulnerabilities
- Monitor all deployment events
- Maintain implementation registry off-chain
Upgrade Path
Updating Implementation
Deprecation
Next Steps
- CampaignInfo - Campaign contract
- GlobalParams - Protocol configuration
- AllOrNothing - Treasury implementation
- BaseTreasury - Treasury base contract
- Platform Integration - Integration guide