Skip to main content
The BaseTreasury is an abstract base contract that provides common functionality for all treasury implementations in the Oak Network protocol. It defines the standard interface for fee distribution, fund management, and campaign state handling that all treasury types inherit.

Overview

Key Features

  • Abstract Base Contract: Extended by AllOrNothing and other treasury types
  • Fee Distribution: Standard fee disbursement logic
  • Access Control: Inherits campaign-specific access control
  • State Management: Pausable and cancellable functionality
  • Success Condition: Abstract method for funding model-specific logic
  • Safe Token Handling: Uses SafeERC20 for secure transfers

Constants

PERCENT_DIVIDER

Purpose: Used for percentage calculations (10000 = 100%) Usage: Fee percentages are stored in basis points

ZERO_BYTES

Purpose: Zero bytes comparison value Usage: Checking for empty hash values

State Variables

Platform Configuration

Funding State

Functions

Initialization

Init Base Contract

Parameters:
  • platformHash: Platform identifier
  • infoAddress: CampaignInfo contract address
Effects:
  • Initializes campaign access checker
  • Sets platform hash
  • Loads token address from campaign info
  • Sets platform fee percentage
Called by:
  • All treasury implementations in their initialize() functions

Query Functions

Get Platform Hash

Returns:
  • Platform identifier for this treasury

Get Platform Fee Percent

Returns:
  • Platform fee percentage in basis points

Fee Distribution

Disburse Fees

Effects:
  • Checks success condition (must be met)
  • Calculates protocol and platform fee shares
  • Transfers protocol fee to protocol admin
  • Transfers platform fee to platform admin
  • Marks fees as disbursed
  • Emits FeesDisbursed event
Requirements:
  • Campaign must not be paused or cancelled
  • Success condition must be met
  • Implementation must override _checkSuccessCondition()
Calculation:

Success Condition Check

Returns:
  • True if campaign succeeded, false otherwise
Note: Must be overridden by implementing contracts
  • AllOrNothing: Returns totalRaised >= goal

Withdrawal

Withdraw

Effects:
  • Transfers all remaining funds to campaign owner
  • Requires fees to be disbursed first
  • Emits WithdrawalSuccessful event
Requirements:
  • Only callable by campaign owner
  • Campaign must not be paused or cancelled
  • Fees must be disbursed

Modifiers

When Campaign Not Paused

Effect: Reverts if campaign is paused

When Campaign Not Cancelled

Effect: Reverts if campaign is cancelled

Events

FeesDisbursed

Emitted when: Fees successfully distributed Includes: Amounts sent to protocol and platform

WithdrawalSuccessful

Emitted when: Campaign owner withdraws funds

SuccessConditionNotFulfilled

Emitted when: Attempt to disburse fees on unsuccessful campaign

Errors

TreasuryTransferFailed

Emitted when: Token transfer fails

TreasurySuccessConditionNotFulfilled

Emitted when: Attempting to disburse fees on failed campaign

TreasuryFeeNotDisbursed

Emitted when: Attempting to withdraw before fees disbursed

TreasuryCampaignInfoIsPaused

Emitted when: Campaign is paused

Usage Examples

Implementing a Custom Treasury

Fee Distribution Flow

Campaign State Checks

Security Considerations

Safe Token Transfers

  • Uses SafeERC20 for all token transfers
  • Prevents silent failures
  • Provides descriptive error messages

Access Control

  • Campaign owner only for withdrawal
  • Success condition must be met before fee distribution
  • Paused/cancelled campaigns cannot disburse fees or withdraw

Fee Calculation

  • Fee percentages stored in basis points (1/10000)
  • Precise integer math, no rounding errors
  • Percentages are immutable once set

State Protection

  • Fees can only be disbursed once
  • Withdrawal requires fees to be disbursed
  • Campaign state checked before all operations

Integration Notes

With CampaignInfo

With GlobalParams

Inheritance Pattern

Best Practices

Custom Success Conditions

State Management

  • Always check if fees are disbursed before withdrawal
  • Track pledge amounts correctly
  • Update state before external calls (CEI pattern)

Error Handling

  • Use descriptive error messages
  • Check all preconditions
  • Emit events for all state changes

Abstract Function Requirements

Must Override

Purpose: Define funding model success criteria Examples:
  • AllOrNothing: Checks if total >= goal

Optional Override

Consider overriding when:
  • Custom fee calculations needed
  • Different withdrawal logic required
  • Additional state tracking necessary

Next Steps