Overview
Treasury contracts handle the actual fund collection and distribution in Oak Network. They are responsible for:- Fund Collection: Accepting contributions from backers
- Fee Distribution: Distributing protocol and platform fees
- Success Validation: Determining if campaigns meet their goals
- Fund Disbursement: Releasing funds to campaign creators or backers
Available Treasury Models
All or Nothing
The All or Nothing model is the most common crowdfunding approach:- Success Condition: Campaign must reach its goal amount
- Fund Release: Funds are only released if the goal is met
- Refund Policy: All contributions are refunded if the goal is not met
- Use Cases: Product launches, creative projects, charitable causes
Keep What’s Raised
The Keep What’s Raised model allows creators to keep all contributions:- Success Condition: Always considered successful
- Fund Release: Funds are released regardless of goal achievement
- Refund Policy: No refunds available
- Use Cases: Ongoing projects, flexible funding, community support
Treasury Architecture
BaseTreasury
All treasury contracts inherit fromBaseTreasury:
Key Functions
Fund Collection
Fee Distribution
Fund Withdrawal
Treasury Selection
Choosing the Right Model
All or Nothing
Best for:- Product launches with specific funding targets
- Projects that require minimum funding to succeed
- High-risk, high-reward projects
- Campaigns with clear deliverables
- Hardware product development
- Software development with specific milestones
- Creative projects with production costs
- Charitable causes with specific goals
Keep What’s Raised
Best for:- Ongoing projects and initiatives
- Community support and donations
- Flexible funding goals
- Projects that can scale with available funds
- Open source software development
- Community events and meetups
- Research and development
- Flexible creative projects
Advanced Treasury Features
Reward System Integration
Item Management
Fiat Integration
Treasury Lifecycle
Creation Phase
State Transitions
- Created: Treasury contract deployed and initialized
- Active: Campaign is live and accepting contributions
- Collecting: Contributions are being received
- Ended: Campaign deadline has passed
- Successful: Goal was reached, funds can be withdrawn
- Failed: Goal was not reached, refunds are available
Treasury Management
Campaign Owner Functions
Backer Functions
Best Practices
Treasury Design
- Clear Success Criteria: Define clear, measurable success conditions
- Appropriate Timeline: Set realistic campaign durations
- Fee Structure: Consider the impact of fees on campaign success
- Refund Policy: Clearly communicate refund policies to backers
Security Considerations
- Access Control: Implement proper permission checks
- Reentrancy Protection: Use checks-effects-interactions pattern
- Input Validation: Validate all user inputs
- Emergency Procedures: Have plans for pausing/cancelling campaigns
Gas Optimization
- Batch Operations: Group related operations when possible
- Efficient Storage: Use appropriate data types and storage patterns
- Event Optimization: Emit only necessary events
- Function Optimization: Minimize external calls and computations
Next Steps
- Treasury Factory - Treasury creation and management
- All or Nothing Treasury - Detailed implementation
- Keep What’s Raised Treasury - Alternative model
- Integration Examples - Practical implementation