Skip to main content

Overview

A full on-chain governance system. Token holders can create proposals, vote, and execute transactions through a timelock-protected treasury. This follows the OpenZeppelin Governor pattern.

Quick Start

Generated Files

my-dao
dokrypt.yaml
foundry.toml
README.md
contracts
token
VotingToken.sol
governance
Governor.sol
Timelock.sol
Treasury.sol
test
token
VotingToken.t.sol
governance
Governor.t.sol
Timelock.t.sol
Treasury.t.sol
scripts
deploy-dao.js
create-proposal.js

Governance Lifecycle

  1. Propose — A token holder creates a proposal (requires >= 100 tokens)
  2. Voting Delay — 1 block before voting opens
  3. Voting Period — 45,818 blocks (~1 week at 12s/block) for token holders to vote
  4. Succeed/Defeat — Proposal passes if quorum (10,000 tokens) reached and more For than Against votes
  5. Queue — Passed proposal is queued in the Timelock
  6. Timelock — 1 day (86,400 seconds) mandatory waiting period
  7. Execute — After the delay, anyone can execute the proposal

Contracts

VotingToken.sol

ERC-20 with vote delegation and checkpoint-based historical voting power tracking. Constructor:
Key Functions: Checkpoint System:
Checkpoints are recorded whenever delegation changes, enabling accurate historical voting power lookups.
Token holders must call delegate() (even self-delegation) before their tokens count as voting power. Undelegated tokens have zero voting power.

Governor.sol

The core governance engine that manages proposals and voting. Configuration: Proposal States: PendingActiveCanceled / Defeated / SucceededQueuedExecuted Functions: Events: ProposalCreated, VoteCast, ProposalExecuted, ProposalCanceled, ProposalQueued

Timelock.sol

Enforces a mandatory delay before executing governance decisions. This gives token holders time to react to passed proposals. Configuration: Roles:
  • Proposer — Can schedule operations (Governor contract)
  • Executor — Can execute ready operations (Governor contract)
  • Admin — Can manage roles and update delay
Functions: Events: CallScheduled, CallExecuted, Cancelled, MinDelayChanged

Treasury.sol

Holds ETH and ERC-20 tokens for the DAO. Only the Timelock (via Governor proposals) can withdraw funds. Functions: Events: Deposited, ETHDeposited, Withdrawn, ETHWithdrawn, ControllerUpdated

Deployment

Deployment order:
  1. VotingToken — 1,000,000 initial supply
  2. Timelock — 1 day delay
  3. Governor — Connected to VotingToken and Timelock
  4. Treasury — Controlled by Timelock
The script also sets up roles and self-delegates the deployer’s voting power.

Testing with Time Travel