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

ApprovedImplementations

Functions

Constructor

Parameters:
  • globalParams: Global parameters contract reference
Effects:
  • Initializes admin access checker with GlobalParams
  • Sets up access control for platform and protocol admins

Treasury Implementation Registration

Register Treasury Implementation

Parameters:
  • platformHash: Platform identifier
  • implementationId: Unique ID for this implementation
  • implementation: Contract address of the treasury implementation
Effects:
  • Registers treasury implementation for platform
  • Can be called before approval
Requirements:
  • Only callable by platform admin
  • Implementation address must be non-zero
Usage:
  • Platform admin registers their treasury implementations
  • Multiple implementations can be registered per platform
  • Implementation IDs are platform-specific

Approve Treasury Implementation

Parameters:
  • platformHash: Platform identifier
  • implementationId: Implementation ID to approve
Effects:
  • Approves implementation for use in deployments
  • Emits approval event
Requirements:
  • Only callable by protocol admin
  • Implementation must be registered
Security:
  • Protocol admin review required before deployments
  • Prevents malicious implementations from being used

Disapprove Treasury Implementation

Parameters:
  • implementation: Implementation address to disapprove
Effects:
  • Revokes approval for implementation
  • Prevents new deployments using this implementation
Requirements:
  • Only callable by protocol admin
Use Cases:
  • Security issues discovered
  • Updated implementation available
  • Deprecated functionality

Remove Treasury Implementation

Parameters:
  • platformHash: Platform identifier
  • implementationId: Implementation ID to remove
Effects:
  • Removes implementation registration from platform
  • Prevents new deployments
Requirements:
  • Only callable by platform admin

Treasury Deployment

Deploy Treasury

Parameters:
  • platformHash: Platform identifier
  • infoAddress: CampaignInfo contract address
  • implementationId: Implementation to deploy
  • name: Treasury contract name
  • symbol: Treasury contract symbol
Returns:
  • Address of deployed treasury clone
Effects:
  • Creates new treasury contract using clone pattern
  • Initializes treasury with campaign info
  • Sets up platform configuration
Requirements:
  • Only callable by platform admin
  • Implementation must be approved
  • Campaign info address must be valid

Query Functions

Get Treasury Address

Parameters:
  • platformHash: Platform identifier
  • implementationId: Implementation ID
Returns:
  • Treasury implementation address

Check Implementation Approved

Parameters:
  • implementation: Implementation address to check
Returns:
  • True if implementation is approved

Events

TreasuryImplementationRegistered

Emitted when: Platform admin registers an implementation

TreasuryImplementationApproved

Emitted when: Protocol admin approves an implementation

TreasuryImplementationDisapproved

Emitted when: Protocol admin disapproves an implementation

TreasuryDeployed

Emitted when: New treasury is deployed

Errors

TreasuryFactoryUnauthorized

Emitted when: Unauthorized action attempted

TreasuryFactoryInvalidAddress

Emitted when: Zero address provided

TreasuryFactoryImplementationNotSet

Emitted when: Implementation not registered

TreasuryFactoryImplementationNotSetOrApproved

Emitted when: Implementation not approved for deployment

TreasuryFactoryTreasuryCreationFailed

Emitted when: Treasury deployment fails

TreasuryFactoryTreasuryInitializationFailed

Emitted when: Treasury initialization fails

TreasuryFactorySettingPlatformInfoFailed

Emitted when: Setting platform info on campaign fails

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