Smart Contracts

This section provides comprehensive documentation for the smart contracts powering Treem DAO governance.

Contract Architecture

Overview

The Treem DAO governance system consists of four main smart contracts working together to provide secure, transparent, and efficient governance:

graph TD
    A[TreemGovernanceToken] --> B[TreemGovernor]
    A --> C[TreemStaking]
    B --> D[TimelockController]
    C --> A
    C --> B

Contract Relationships

  • TreemGovernanceToken: Provides voting power and token transfers

  • TreemStaking: Manages token locks and voting eligibility

  • TreemGovernor: Handles proposal creation and voting

  • TimelockController: Enforces execution delays for security

TreemGovernanceToken Contract

Contract Overview

Purpose: ERC-20 governance token with voting capabilities

Standard: ERC-20, ERC-20Permit, ERC-20Votes

Features: Voting power delegation, permit signatures, governance integration

Token Specifications

Distribution Allocation

Recipient
Amount
Percentage
Purpose

Foundation Treasury

400,000,000 TREEM

40%

Operations & Development

Community Grants

300,000,000 TREEM

30%

Community Funding

Reserve Future

150,000,000 TREEM

15%

Strategic Reserves

Founders & Team

150,000,000 TREEM

15%

Team Allocation

Key Functions

Token Information

Voting Functions

Agreement Access

Events

TreemStaking Contract

Contract Overview

Purpose: Manage token staking with lock periods and voting eligibility

Features: Tiered staking, voting rewards, grant proposal permissions

Staking Tiers

Constructor

Core Functions

Staking Operations

Reward Management

Permission Checks

Administrative Functions

Events

TreemGovernor Contract

Contract Overview

Purpose: Main governance contract for proposals and voting

Standard: OpenZeppelin Governor with extensions

Features: Proposal creation, voting, execution with timelock

Governance Parameters

Core Functions

Proposal Creation

Voting Functions

State Management

Proposal Execution

Events

TimelockController Contract

Overview

Purpose: Add execution delay for security

Standard: OpenZeppelin TimelockController

Features: Multi-signature support, role-based access

Configuration

Key Functions

Deployment Guide

Prerequisites

  • Hardhat development environment

  • Ethereum wallet with ETH for deployment

  • Access to Ethereum node (Infura, Alchemy, etc.)

Deployment Sequence

1. Deploy TreemGovernanceToken

2. Deploy TimelockController

3. Deploy TreemStaking

4. Deploy TreemGovernor

5. Configure Contracts

Gas Estimates

Contract
Deployment Gas
Mainnet Cost (50 gwei)

TreemGovernanceToken

~2,500,000

~0.125 ETH

TreemStaking

~1,200,000

~0.060 ETH

TreemGovernor

~3,000,000

~0.150 ETH

TimelockController

~1,500,000

~0.075 ETH

Total

~8,200,000

~0.410 ETH

Security Considerations

Access Controls

Critical Functions Protected:

  • Contract ownership transfer

  • Parameter updates

  • Emergency functions

  • Treasury management

Role-Based Security:

Reentrancy Protection

Time-Based Security

Block Timestamp Usage:

  • Lock period calculations use block.timestamp

  • Resistant to minor manipulation

  • Suitable for periods measured in days

Snapshot Mechanism:

  • Voting power calculated at proposal creation

  • Prevents vote manipulation

  • Historical data preserved

Integration Examples

Frontend Integration

Contract Instance Creation

Common Operations

Event Listening

Troubleshooting

Common Deployment Issues

Insufficient Gas:

Constructor Arguments:

Network Configuration:

Runtime Issues

Staking Failures:

  • Check token approval

  • Verify sufficient balance

  • Ensure not already staked

Voting Issues:

  • Confirm tokens are staked

  • Check proposal is in active state

  • Verify voting power > 0

Proposal Creation:

  • Meet proposal threshold

  • Provide valid description

  • Check governor contract state

This comprehensive smart contracts documentation provides all necessary information for understanding, deploying, and interacting with the Treem DAO governance contracts.

Last updated

Was this helpful?