Governance Mechanisms
On-chain governance, off-chain voting, governance attacks, and design.
Overview
Governance enables decentralized decision-making.
Governance Models
| Model | Description |
|---|---|
| Token Voting | 1 token = 1 vote |
| Quadratic | Square root weighting |
| Conviction | Time-weighted |
| Delegation | Representative 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
| Attack | Description |
|---|---|
| Flash Loan | Temporary voting power |
| Vote Buying | Bribery |
| Sybil | Fake identities |
| Plutocracy | Whale dominance |
Best Practices
- Timelock — Delay execution
- Quorum — Minimum participation
- Delegation — Enable representation
- Transparency — Clear proposals
Practice
Deploy a governance system with a timelock.