Governance Mechanisms

GovernanceFree Lesson

Advertisement

Governance Mechanisms

On-chain governance, off-chain voting, governance attacks, and design.

Overview

Governance enables decentralized decision-making.

Governance Models

ModelDescription
Token Voting1 token = 1 vote
QuadraticSquare root weighting
ConvictionTime-weighted
DelegationRepresentative voting

Governor Contract

import "@openzeppelin/contracts/governance/Governor.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorVotes.sol";
import "@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol";

contract MyGovernor is Governor, GovernorCountingSimple, GovernorVotes, GovernorVotesQuorumFraction {
    constructor(IVotes _token, uint48 _votingDelay, uint32 _votingPeriod, uint256 _quorumPercentage)
        Governor("MyGovernor")
        GovernorVotes(_token)
        GovernorVotesQuorumFraction(_quorumPercentage)
    {
        votingDelay = _votingDelay;
        votingPeriod = _votingPeriod;
    }
    
    function propose(address[] memory targets, uint256[] memory values, bytes[] memory calldatas, string memory description)
        public override returns (uint256)
    {
        return super.propose(targets, values, calldatas, description);
    }
}

Voting Power

def calculate_voting_power(tokens, delegation_time):
    # Time-weighted voting
    weight = min(delegation_time / (365 * 24 * 60 * 60), 1)
    return tokens * weight

Governance Attacks

AttackDescription
Flash LoanTemporary voting power
Vote BuyingBribery
SybilFake identities
PlutocracyWhale dominance

Best Practices

  1. Timelock — Delay execution
  2. Quorum — Minimum participation
  3. Delegation — Enable representation
  4. Transparency — Clear proposals

Practice

Deploy a governance system with a timelock.

Advertisement

Need Expert Blockchain Help?

Get personalized Web3 training or smart contract consulting.

Advertisement