Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article explores the NounsDAOLogicV1 contract from Nouns using Bunzz's DeCipher feature.
DeCipher uses AI to generate smart contract documentation.
For a detailed guide to using DeCipher, see the following article.
This article reflects my personal experience with DeCipher. If you notice any inaccuracies, please let me know in the comments.
The DeCipher page used in this article is linked below.
The corresponding Etherscan page is available below.
Overview
NounsDAOLogicV1 is a core component of the original Nouns DAO (decentralized autonomous organization) governance system.
Purpose
The contract manages the rules and logic governing Nouns DAO.
It manages proposals, voting periods, voting delays, and thresholds within Nouns DAO. In particular, it configures how proposals are created, when voting occurs, and the voting power required for a proposal to succeed.
Responsibilities
The contract has the following responsibilities.
Proposal threshold configuration
Sets the minimum and maximum permitted proposal threshold percentages.
The minimum is 0.01% and the maximum is 10%.
Voting period configuration
Sets the period during which DAO members may vote. The historical implementation describes bounds of approximately 24 hours and two weeks, based on its assumed block time.
Voting delay configuration
Sets the delay between proposal creation and the start of voting. The minimum is one block, and the maximum is described as approximately one week under the original block-time assumption.
Proposal management
Tracks proposal IDs and manages proposals within the DAO.
Contract administration
Manages contract administration, including the current and pending administrators.
Usage
NounsDAOLogicV1 is part of Nouns DAO's governance system and manages proposals and voting.
1. Initialization
Initialize the contract by calling initialize. This sets the initial DAO configuration, including the timelock address, Nouns token address, vetoer, voting period, voting delay, proposal threshold, and quorum votes.
2. Creating proposals
Create a proposal through the proposal function, which emits ProposalCreated.
The event records the proposal ID, proposer address, targets, values, function signatures, calldata, start and end blocks, and description.
The contract also emits ProposalCreatedWithRequirements, recording the requirements associated with the proposal.
This event records the proposal's threshold and quorum requirement.
3. Voting on proposals
Once voting is active for a proposal, eligible DAO members may vote.
The voting period is configured at initialization within the bounds of MIN_VOTING_PERIOD and MAX_VOTING_PERIOD.
The voting delay is likewise configured within the bounds of MIN_VOTING_DELAY and MAX_VOTING_DELAY.
4. Configuring the proposal threshold
The proposal threshold determines the voting power an account must exceed to submit a proposal.
Its initial value is configured within the bounds of MIN_PROPOSAL_THRESHOLD_BPS and MAX_PROPOSAL_THRESHOLD_BPS.
5. Configuring quorum votes
The quorum requirement determines the minimum number of affirmative votes required for a proposal to succeed. Its initial value is set during initialization.
6. Checking the latest proposal
Call latestProposalIds with a proposer's address to retrieve their latest proposal ID.
Parameters
None.
Contract
NounsDAOEvents
ProposalCreated
ProposalCreated
event ProposalCreated(
uint256 id,
address proposer,
address[] targets,
uint256[] values,
string[] signatures,
bytes[] calldatas,
uint256 startBlock,
uint256 endBlock,
string description
);Overview Event emitted when a new proposal is created.
Details
id- Numeric proposal ID.
proposer- Address of the proposer.
targets- Array of target contract addresses.
values- Array of Ether values for the targets.
signatures- Array of function signature strings for the targets.
calldatas- Array of calldata byte strings for the target calls.
startBlock- Block number at which voting starts.
endBlock- Block number at which voting ends.
description- String containing the proposal description.
ProposalCreatedWithRequirements
ProposalCreatedWithRequirements
event ProposalCreatedWithRequirements(
uint256 id,
address proposer,
address[] targets,
uint256[] values,
string[] signatures,
bytes[] calldatas,
uint256 startBlock,
uint256 endBlock,
uint256 proposalThreshold,
uint256 quorumVotes,
string description
);Overview Event emitted when a new proposal is created with its requirements recorded.
Details
id- Numeric proposal ID.
proposer- Address of the proposer.
targets- Array of target contract addresses.
values- Array of Ether values for the targets.
signatures- Array of function signature strings for the targets.
calldatas- Array of calldata byte strings for the target calls.
startBlock- Block number at which voting starts.
endBlock- Block number at which voting ends.
proposalThreshold- Numeric proposal threshold.
quorumVotes- Required quorum votes.
description- String containing the proposal description.
VoteCast
event VoteCast(address indexed voter, uint256 proposalId, uint8 support, uint256 votes, string reason);Overview Event emitted when a vote is cast on a proposal.
Parameters
voter- Voter address.
proposalId- ID of the proposal voted on.
support- Vote support value (0 = against, 1 = for, 2 = abstain).
votes- Voting power used by the voter.
reason- Reason provided by the voter.
ProposalCanceled
event ProposalCanceled(uint256 id);Overview Event emitted when a proposal is canceled.
Parameters
id- ID of the canceled proposal.
ProposalQueued
event ProposalQueued(uint256 id, uint256 eta);Overview Event emitted when a proposal is queued in NounsDAOExecutor.
Parameters
id- ID of the queued proposal.
eta- Scheduled execution timestamp (ETA).
ProposalExecuted
ProposalExecuted
event ProposalExecuted(uint256 id);Overview Event emitted when a proposal is executed through NounsDAOExecutor.
Parameters
id- ID of the executed proposal.
ProposalVetoed
ProposalVetoed
event ProposalVetoed(uint256 id);Overview Event emitted when a proposal is vetoed by the authorized vetoer.
Parameters
id- ID of the vetoed proposal.
VotingDelaySet
VotingDelaySet
event VotingDelaySet(uint256 oldVotingDelay, uint256 newVotingDelay);Overview Event emitted when the voting delay changes.
Parameters
oldVotingDelay- Previous voting delay.
newVotingDelay- New voting delay.
VotingPeriodSet
VotingPeriodSet
event VotingPeriodSet(uint256 oldVotingPeriod, uint256 newVotingPeriod);Overview Event emitted when the voting period changes.
Parameters
oldVotingPeriod- Previous voting period.
newVotingPeriod- New voting period.
NewImplementation
NewImplementation
event NewImplementation(address oldImplementation, address newImplementation);Overview Event emitted when the implementation address changes.
Parameters
oldImplementation- Previous implementation address.
newImplementation- New implementation address.
ProposalThresholdBPSSet
ProposalThresholdBPSSet
event ProposalThresholdBPSSet(uint256 oldProposalThresholdBPS, uint256 newProposalThresholdBPS);Overview Event emitted when the proposal threshold in basis points changes.
Parameters
oldProposalThresholdBPS- Previous proposal threshold in basis points.
newProposalThresholdBPS- New proposal threshold in basis points.
QuorumVotesBPSSet
QuorumVotesBPSSet
event QuorumVotesBPSSet(uint256 oldQuorumVotesBPS, uint256 newQuorumVotesBPS);Overview Event emitted when the quorum requirement in basis points changes.
Parameters
oldQuorumVotesBPS- Previous quorum requirement in basis points.
newQuorumVotesBPS- New quorum requirement in basis points.
NewPendingAdmin
NewPendingAdmin
event NewPendingAdmin(address oldPendingAdmin, address newPendingAdmin);Overview Event emitted when the pending administrator address changes.
Parameters
oldPendingAdmin- Previous pending administrator address.
newPendingAdmin- New pending administrator address.
NewAdmin
NewAdmin
event NewAdmin(address oldAdmin, address newAdmin);Overview Event emitted when the administrator address changes.
Parameters
oldAdmin- Previous administrator address.
newAdmin- New administrator address.
NewVetoer
NewVetoer
event NewVetoer(address oldVetoer, address newVetoer);Overview
Event emitted when the vetoer address changes.
Parameters
oldVetoer- Previous
vetoeraddress.
- Previous
newVetoer- New
vetoeraddress.
- New
NounsDAOProxyStorage
admin
admin
address public admin;Overview Stores the address of the smart contract administrator. The administrator is authorized to perform administrative operations and configuration changes.
Details The administrator can perform privileged operations defined by the contract. These include operations such as upgrades and configuration changes, where supported. Updating this variable through the authorized transition mechanism transfers administrative authority to another address.
pendingAdmin
pendingAdmin
address public pendingAdmin;Overview Stores the pending administrator address. This address identifies the nominated administrator until that nominee accepts the role.
Details
The pendingAdmin variable temporarily stores the address of a newly nominated administrator.
Administrative authority does not transfer until the pending administrator accepts it.
This provides a two-step process for transferring administrative authority.
implementation
implementation
address public implementation;Overview Stores the address of the governor's active implementation. It identifies the contract containing the governor's underlying functionality.
Details
The implementation variable stores the address of the governor's logic contract.
This address identifies the code implementing the governor's functionality.
It may change when the governor is upgraded or new functionality is introduced.
NounsDAOStorageV1
vetoer
vetoer
address public vetoer;Overview Stores the address of the Vetoer, which has authority to veto proposals.
Details The Vetoer is authorized to veto a proposal. This authority may be exercised before a proposal is voted on, provided the applicable conditions are satisfied. This allows the vetoer to block proposals under the governance mechanism.
votingDelay
votingDelay
uint256 public votingDelay;Overview Stores the voting delay in blocks between proposal creation and the start of voting.
Details The delay is expressed in blocks and ensures that voting begins only after the configured interval. It gives community members time to examine proposals before voting.
votingPeriod
votingPeriod
uint256 public votingPeriod;Overview Stores the duration of voting on a proposal in blocks.
Details During the configured voting period, community members may cast votes for, against, or abstaining from the proposal. The choice of voting period affects the efficiency and reliability of the governance process.
proposalThresholdBPS
proposalThresholdBPS
uint256 public proposalThresholdBPS;Overview Stores the proposal threshold in basis points, determining the voting power needed to qualify as a proposer.
Details
One basis point represents 0.01%. This value is used to calculate the applicable voting-power threshold.
The threshold determines an account's eligibility to submit proposals.
Note that this differs from the corresponding Governor Bravo design.
GovernerBravo Governor Bravo is a proposal and voting mechanism used by Compound, a decentralized finance (DeFi) protocol. Compound is a financial platform implemented with Ethereum smart contracts, through which users can supply assets, earn interest, or borrow assets.
Governor Bravo is a smart contract that manages proposals and voting within Compound. It provides a mechanism for community members to propose new functionality or protocol changes and vote on them. Proposals succeed or fail based on voting results, determining the protocol's governance decisions.
Governor Bravo provides configurable governance parameters such as proposal thresholds, quorum requirements, and voting periods. These mechanisms allow community members to participate in decisions about protocol changes.
quorumVotesBPS
quorumVotesBPS
uint256 public quorumVotesBPS;Overview Stores the quorum requirement in basis points.
Details A proposal must receive sufficient affirmative voting power to meet its quorum requirement. The quorum percentage is expressed in basis points and determines the minimum affirmative votes required relative to the relevant token supply. Note that this differs from the corresponding Governor Bravo design.
Parameters
- None.
proposalCount
proposalCount
uint256 public proposalCount;Overview Stores the total number of proposals.
timelock
timelock
INounsDAOExecutor public timelock;Overview Stores the address of the Nouns DAO Executor (timelock).
Details The timelock provides a mechanism for scheduling transactions for execution after a delay. It delays the execution of transactions associated with successful proposals.
nouns
nouns
NounsTokenLike public nouns;Overview Stores the Nouns token address.
Details Nouns tokens provide voting power and support governance-related functionality in the protocol.
proposals
proposals
mapping(uint256 => Proposal) public proposals;Overview Mapping containing the details of all proposals.
Details
Information about each proposal is stored in a Proposal struct, including its proposer, voting period, and target addresses.
Parameters
proposalId- Proposal ID.
latestProposalIds
latestProposalIds
mapping(address => uint256) public latestProposalIds;Overview Mapping storing each proposer's latest proposal ID.
Details When a proposer submits a new proposal, this mapping is updated with the latest proposal ID.
Parameters
proposer- Proposer address.
Proposal struct
Proposal struct
struct Proposal {
uint256 id;
address proposer;
uint256 proposalThreshold;
uint256 quorumVotes;
uint256 eta;
address[] targets;
uint256[] values;
string[] signatures;
bytes[] calldatas;
uint256 startBlock;
uint256 endBlock;
uint256 forVotes;
uint256 againstVotes;
uint256 abstainVotes;
bool canceled;
bool vetoed;
bool executed;
mapping(address => Receipt) receipts;
}Overview Struct storing the details of a proposal.
Parameters
uint256 id- Unique proposal ID.
address proposer- Proposer address.
uint256 proposalThreshold- Voting-power threshold required at proposal creation.
uint256 quorumVotes- Number of votes required to reach quorum.
uint256 eta- Scheduled execution timestamp if the successful proposal is queued.
address[] targets- List of target addresses.
uint256[] values- List of Ether values for the calls.
string[] signatures- List of function signatures to invoke.
bytes[] calldatas- List of calldata values for the calls.
uint256 startBlock- Voting start block.
uint256 endBlock- Voting end block.
uint256 forVotes- Votes for the proposal.
uint256 againstVotes- Votes against the proposal.
uint256 abstainVotes- Abstaining votes.
bool canceled- Flag indicating whether the proposal was canceled.
bool vetoed- Flag indicating whether the proposal was vetoed.
bool executed- Flag indicating whether the proposal was executed.
mapping(address => Receipt) receipts- Mapping of voter addresses to voting receipts.
Receipt
Receipt
struct Receipt {
/// @notice Whether a vote has been cast
bool hasVoted;
/// @notice Whether the voter votes against, for, or abstains from the proposal
uint8 support;
/// @notice Number of votes cast by the voter
uint96 votes;
}Overview Struct storing a voter's receipt for a particular proposal.
Parameters
hasVoted- Boolean indicating whether the voter has voted.
trueindicates that a vote has been cast.
support- Numeric value indicating the voter's chosen position.
0means against,1means for, and2means abstain.
votes- Integer representing the voting power used by the voter.
- Records the voting power from the applicable snapshot; the voter may not vote twice on the same proposal.
ProposalState
ProposalState
enum ProposalState {
Pending,
Active,
Canceled,
Defeated,
Succeeded,
Queued,
Expired,
Executed,
Vetoed
}Overview Enum representing the state of a proposal.
Parameters
Pending- The proposal is pending.
- Voting has not started yet.
Active- The proposal is active.
- Voting is in progress.
Canceled- The proposal is canceled.
- The proposal has been canceled and will not proceed.
Defeated- The proposal is defeated.
- It did not meet the conditions required to succeed.
Succeeded- The proposal succeeded.
- Voting met the success conditions and the proposal can proceed to queueing.
Queued- The proposal is queued.
- Execution is scheduled through the timelock.
Expired- The proposal is expired.
- Its allowed execution period has expired.
Executed- The proposal is executed.
- Its actions have been executed.
Vetoed- The proposal is vetoed.
- It was blocked by the authorized vetoer.
NounsDAOLogicV1
name
name
string public constant name = 'Nouns DAO';Overview Contract name.
MIN_PROPOSAL_THRESHOLD_BPS
MIN_PROPOSAL_THRESHOLD_BPS
uint256 public constant MIN_PROPOSAL_THRESHOLD_BPS = 1;Overview Minimum proposal threshold.
Details
The proposal threshold is expressed in basis points (BPS); this value represents 0.01%.
It specifies the lower bound for the voting-power threshold used to determine proposer eligibility.
MAX_PROPOSAL_THRESHOLD_BPS
MAX_PROPOSAL_THRESHOLD_BPS
uint256 public constant MAX_PROPOSAL_THRESHOLD_BPS = 1_000;Overview Maximum proposal threshold.
Details
The proposal threshold is expressed in basis points (BPS); this value represents 10%.
It specifies the upper bound for the voting-power threshold used to determine proposer eligibility.
MIN_VOTING_PERIOD
MIN_VOTING_PERIOD
uint256 public constant MIN_VOTING_PERIOD = 5_760;Overview Minimum voting period.
Details The voting period is expressed in blocks and corresponds to approximately 24 hours under the original block-time assumption. It specifies the minimum duration of proposal voting.
MAX_VOTING_PERIOD
MAX_VOTING_PERIOD
uint256 public constant MAX_VOTING_PERIOD = 80_640;Overview Maximum voting period.
Details The voting period is expressed in blocks and corresponds to approximately two weeks under the original block-time assumption. It specifies the maximum duration of proposal voting.
MIN_VOTING_DELAY
MIN_VOTING_DELAY
uint256 public constant MIN_VOTING_DELAY = 1;Overview Minimum voting delay.
Details Specifies the minimum waiting period in blocks between proposal creation and the start of voting.
MAX_VOTING_DELAY
MAX_VOTING_DELAY
uint256 public constant MAX_VOTING_DELAY = 40_320;Overview Maximum voting delay.
Details Specifies the maximum waiting period in blocks between proposal creation and the start of voting. It corresponds to approximately one week under the original block-time assumption.
MIN_QUORUM_VOTES_BPS
MIN_QUORUM_VOTES_BPS
uint256 public constant MIN_QUORUM_VOTES_BPS = 200;Overview Minimum quorum requirement.
Details
The quorum requirement is expressed in basis points (BPS); this value represents 2%.
It specifies the lower bound on the configurable quorum percentage.
MAX_QUORUM_VOTES_BPS
MAX_QUORUM_VOTES_BPS
uint256 public constant MAX_QUORUM_VOTES_BPS = 2_000;Overview Maximum quorum requirement.
Details
The quorum requirement is expressed in basis points (BPS); this value represents 20%.
It specifies the upper bound on the configurable quorum percentage.
proposalMaxOperations
proposalMaxOperations
uint256 public constant proposalMaxOperations = 10;Overview Maximum number of actions per proposal.
Details Specifies how many actions may be included in a single proposal. This limits the number of operations executable through a proposal.
DOMAIN_TYPEHASH
DOMAIN_TYPEHASH
bytes32 public constant DOMAIN_TYPEHASH = keccak256('EIP712Domain(string name,uint256 chainId,address verifyingContract)');Overview EIP712 domain type hash for the contract.
Details Declared as a byte-string constant holding the EIP712 domain type hash. This hash is used in signing and verifying EIP712 messages.
BALLOT_TYPEHASH
BALLOT_TYPEHASH
bytes32 public constant BALLOT_TYPEHASH = keccak256('Ballot(uint256 proposalId,uint8 support)');Overview EIP712 type hash for the ballot structure.
Details Used when signing and verifying vote messages.
initialize
initialize
function initialize(
address timelock_,
address nouns_,
address vetoer_,
uint256 votingPeriod_,
uint256 votingDelay_,
uint256 proposalThresholdBPS_,
uint256 quorumVotesBPS_
) public virtual {
// Verify that the contract has not already been initialized
require(address(timelock) == address(0), 'NounsDAO::initialize: already initialized');
// Verify that only the administrator can initialize the contract
require(msg.sender == admin, 'NounsDAO::initialize: admin only');
// Reject an invalid timelock address
require(timelock_ != address(0), 'NounsDAO::initialize: invalid timelock address');
// Reject an invalid Nouns address
require(nouns_ != address(0), 'NounsDAO::initialize: invalid nouns address');
// Verify that the voting period is valid
require(
votingPeriod_ >= MIN_VOTING_PERIOD && votingPeriod_ <= MAX_VOTING_PERIOD,
'NounsDAO::initialize: invalid voting period'
);
// Verify that the voting delay is valid
require(
votingDelay_ >= MIN_VOTING_DELAY && votingDelay_ <= MAX_VOTING_DELAY,
'NounsDAO::initialize: invalid voting delay'
);
// Verify that the proposal threshold in basis points is valid
require(
proposalThresholdBPS_ >= MIN_PROPOSAL_THRESHOLD_BPS && proposalThresholdBPS_ <= MAX_PROPOSAL_THRESHOLD_BPS,
'NounsDAO::initialize: invalid proposal threshold'
);
// Verify that the quorum threshold in basis points is valid
require(
quorumVotesBPS_ >= MIN_QUORUM_VOTES_BPS && quorumVotesBPS_ <= MAX_QUORUM_VOTES_BPS,
'NounsDAO::initialize: invalid quorum votes threshold'
);
// Emit an event recording the voting period
emit VotingPeriodSet(votingPeriod, votingPeriod_);
// Emit an event recording the voting delay
emit VotingDelaySet(votingDelay, votingDelay_);
// Emit an event recording the proposal threshold
emit ProposalThresholdBPSSet(proposalThresholdBPS, proposalThresholdBPS_);
// Emit an event recording the quorum requirement
emit QuorumVotesBPSSet(quorumVotesBPS, quorumVotesBPS_);
// Set the timelock address
timelock = INounsDAOExecutor(timelock_);
// Set the Nouns address
nouns = NounsTokenLike(nouns_);
// Set the vetoer address
vetoer = vetoer_;
// Set the voting period
votingPeriod = votingPeriod_;
// Set the voting delay
votingDelay = votingDelay_;
// Set the proposal threshold
proposalThresholdBPS = proposalThresholdBPS_;
// Set the quorum requirement
quorumVotesBPS = quorumVotesBPS_;
}Overview Initializes the contract. Initialization can be performed only once and only by the administrator.
Details
- Verify that the contract has not yet been initialized.
- Verify that the caller is the administrator.
- Verify that the required addresses are valid.
- Verify that the voting period, voting delay, proposal threshold, and quorum requirement are within their permitted ranges.
- Emit events recording the new configuration.
Parameters
timelock_- NounsDAOExecutor address.
nouns_- Nouns token address.
vetoer_- Address authorized to veto proposals unilaterally.
votingPeriod_- Initial voting period.
votingDelay_- Initial voting delay.
proposalThresholdBPS_- Initial proposal threshold in basis points.
quorumVotesBPS_- Initial quorum requirement in basis points.
Return value This function has no return value.
ProposalTemp
ProposalTemp
struct ProposalTemp {
uint256 totalSupply;
uint256 proposalThreshold;
uint256 latestProposalId;
uint256 startBlock;
uint256 endBlock;
}Overview Struct storing temporary proposal information. Holds intermediate values used when constructing a proposal.
Parameters
totalSupply- Current total token supply.
proposalThreshold- Proposal eligibility threshold.
latestProposalId- Latest proposal ID.
startBlock- Proposal start block.
endBlock- Proposal end block.
propose
propose
function propose(
address[] memory targets,
uint256[] memory values,
string[] memory signatures,
bytes[] memory calldatas,
string memory description
) public returns (uint256) {
ProposalTemp memory temp;
temp.totalSupply = nouns.totalSupply();
temp.proposalThreshold = bps2Uint(proposalThresholdBPS, temp.totalSupply);
require(
nouns.getPriorVotes(msg.sender, block.number - 1) > temp.proposalThreshold,
'NounsDAO::propose: proposer votes below proposal threshold'
);
require(
targets.length == values.length &&
targets.length == signatures.length &&
targets.length == calldatas.length,
'NounsDAO::propose: proposal function information arity mismatch'
);
require(targets.length != 0, 'NounsDAO::propose: must provide actions');
require(targets.length <= proposalMaxOperations, 'NounsDAO::propose: too many actions');
temp.latestProposalId = latestProposalIds[msg.sender];
if (temp.latestProposalId != 0) {
ProposalState proposersLatestProposalState = state(temp.latestProposalId);
require(
proposersLatestProposalState != ProposalState.Active,
'NounsDAO::propose: one live proposal per proposer, found an already active proposal'
);
require(
proposersLatestProposalState != ProposalState.Pending,
'NounsDAO::propose: one live proposal per proposer, found an already pending proposal'
);
}
temp.startBlock = block.number + votingDelay;
temp.endBlock = temp.startBlock + votingPeriod;
proposalCount++;
Proposal storage newProposal = proposals[proposalCount];
newProposal.id = proposalCount;
newProposal.proposer = msg.sender;
newProposal.proposalThreshold = temp.proposalThreshold;
newProposal.quorumVotes = bps2Uint(quorumVotesBPS, temp.totalSupply);
newProposal.eta = 0;
newProposal.targets = targets;
newProposal.values = values;
newProposal.signatures = signatures;
newProposal.calldatas = calldatas;
newProposal.startBlock = temp.startBlock;
newProposal.endBlock = temp.endBlock;
newProposal.forVotes = 0;
newProposal.againstVotes = 0;
newProposal.abstainVotes = 0;
newProposal.canceled = false;
newProposal.executed = false;
newProposal.vetoed = false;
latestProposalIds[newProposal.proposer] = newProposal.id;
/// @notice Maintains backwards compatibility with GovernorBravo events
emit ProposalCreated(
newProposal.id,
msg.sender,
targets,
values,
signatures,
calldatas,
newProposal.startBlock,
newProposal.endBlock,
description
);
/// @notice Updated event with `proposalThreshold` and `quorumVotes`
emit ProposalCreatedWithRequirements(
newProposal.id,
msg.sender,
targets,
values,
signatures,
calldatas,
newProposal.startBlock,
newProposal.endBlock,
newProposal.proposalThreshold,
newProposal.quorumVotes,
description
);
return newProposal.id;
}Overview Creates a new proposal. The proposer must have delegated voting power exceeding the proposal threshold. The function requires proposal details, including target addresses, Ether values, function signatures, calldata, and a description. On success, it returns the new proposal ID.
Details
- Verify that the proposer's delegated voting power exceeds the proposal threshold.
- Verify that the proposal action arrays have matching lengths.
- Verify that the action arrays are not empty.
- Verify that the number of actions does not exceed the maximum.
- Prevent the proposer from creating another proposal while they already have a pending or active proposal.
- Set the voting period from
startBlocktoendBlock. - Store the proposal information and update the proposal ID.
- Emit the proposal creation events.
Parameters
targets- Array of target addresses for the proposed calls.
values- Array of Ether values for the proposed calls.
signatures- Array of function signatures for the proposed calls.
calldatas- Array of calldata values for the proposed calls.
description- Proposal description.
Return value
uint256- ID of the newly created proposal.
queue
queue
function queue(uint256 proposalId) external {
require(
state(proposalId) == ProposalState.Succeeded,
'NounsDAO::queue: proposal can only be queued if it is succeeded'
);
Proposal storage proposal = proposals[proposalId];
uint256 eta = block.timestamp + timelock.delay();
for (uint256 i = 0; i < proposal.targets.length; i++) {
queueOrRevertInternal(
proposal.targets[i],
proposal.values[i],
proposal.signatures[i],
proposal.calldatas[i],
eta
);
}
proposal.eta = eta;
emit ProposalQueued(proposalId, eta);
}Overview Queues a successful proposal.
Details
- Verify that the proposal is in the Succeeded state.
- Queue each action in the proposal.
- Set the scheduled execution timestamp (
eta). - Emit the event recording that the proposal has been queued.
Parameters
proposalId- ID of the proposal to queue.
execute
execute
function execute(uint256 proposalId) external {
require(
state(proposalId) == ProposalState.Queued,
'NounsDAO::execute: proposal can only be executed if it is queued'
);
Proposal storage proposal = proposals[proposalId];
proposal.executed = true;
for (uint256 i = 0; i < proposal.targets.length; i++) {
timelock.executeTransaction(
proposal.targets[i],
proposal.values[i],
proposal.signatures[i],
proposal.calldatas[i],
proposal.eta
);
}
emit ProposalExecuted(proposalId);
}Overview Executes a queued proposal when its timelock permits execution.
Details
- Verify that the proposal is in the Queued state.
- Execute each action in the proposal.
- Emit the event recording proposal execution.
Parameters
proposalId- ID of the proposal to execute.
cancel
cancel
function cancel(uint256 proposalId) external {
require(state(proposalId) != ProposalState.Executed, 'NounsDAO::cancel: cannot cancel executed proposal');
Proposal storage proposal = proposals[proposalId];
require(
msg.sender == proposal.proposer ||
nouns.getPriorVotes(proposal.proposer, block.number - 1) < proposal.proposalThreshold,
'NounsDAO::cancel: proposer above threshold'
);
proposal.canceled = true;
for (uint256 i = 0; i < proposal.targets.length; i++) {
timelock.cancelTransaction(
proposal.targets[i],
proposal.values[i],
proposal.signatures[i],
proposal.calldatas[i],
proposal.eta
);
}
emit ProposalCanceled(proposalId);
}Overview Cancels a proposal if the caller is its proposer or the proposer's voting power has fallen below the applicable proposal threshold.
Details
- Verify that the proposal has not been executed.
- Verify that the caller is the proposer or that the proposer's voting power is below the threshold.
- Cancel each queued proposal action.
- Emit the event recording proposal cancellation.
Parameters
proposalId- ID of the proposal to cancel.
queueOrRevertInternal
queueOrRevertInternal
function queueOrRevertInternal(
address target,
uint256 value,
string memory signature,
bytes memory data,
uint256 eta
) internal {
require(
!timelock.queuedTransactions(keccak256(abi.encode(target, value, signature, data, eta))),
'NounsDAO::queueOrRevertInternal: identical proposal action already queued at eta'
);
timelock.queueTransaction(target, value, signature, data, eta);
}Overview
Queues an action, reverting if the same action is already queued for the same eta.
Details
- Check whether the same action is already queued for the same
eta. - Revert if it is already queued.
- Otherwise, queue the action.
Parameters
target- Action target address.
value- Ether value.
signature- Function signature.
data- calldata。
eta- Scheduled execution timestamp.
veto
veto
function veto(uint256 proposalId) external {
require(vetoer != address(0), 'NounsDAO::veto: veto power burned');
require(msg.sender == vetoer, 'NounsDAO::veto: only vetoer');
require(state(proposalId) != ProposalState.Executed, 'NounsDAO::veto: cannot veto executed proposal');
Proposal storage proposal = proposals[proposalId];
proposal.vetoed = true;
for (uint256 i = 0; i < proposal.targets.length; i++) {
timelock.cancelTransaction(
proposal.targets[i],
proposal.values[i],
proposal.signatures[i],
proposal.calldatas[i],
proposal.eta
);
}
emit ProposalVetoed(proposalId);
}Overview Vetoes a proposal when called by the authorized vetoer, provided that the proposal has not been executed.
Details
- Verify that veto authority has not been permanently removed.
- Verify that the caller is the authorized vetoer.
- Verify that the proposal has not been executed.
- Cancel its queued actions and mark the proposal as vetoed.
- Emit the event recording the veto.
Parameters
proposalId- ID of the proposal to veto.
getActions
getActions
function getActions(uint256 proposalId)
external
view
returns (
address[] memory targets,
uint256[] memory values,
string[] memory signatures,
bytes[] memory calldatas
)
{
Proposal storage p = proposals[proposalId];
return (p.targets, p.values, p.signatures, p.calldatas);
}Overview Retrieves the actions of a proposal, including target addresses, Ether values, function signatures, and calldata.
Details
- Retrieve the proposal using its ID.
- Return the proposal's action information.
Parameters
proposalId- Proposal ID.
Return value
address[]- Array of target addresses.
uint256[]- Array of Ether values.
string[]- Array of function signatures.
bytes[]- Array of calldata values.
getReceipt
getReceipt
function getReceipt(uint256 proposalId, address voter) external view returns (Receipt memory) {
return proposals[proposalId].receipts[voter];
}Overview Retrieves a particular voter's voting receipt for a proposal.
Details
- Retrieve the corresponding receipt using the proposal ID and voter address.
Parameters
proposalId- Proposal ID.
voter- Voter address.
Return value
Receipt- Voting receipt.
state
state
function state(uint256 proposalId) public view returns (ProposalState) {
require(proposalCount >= proposalId, 'NounsDAO::state: invalid proposal id');
Proposal storage proposal = proposals[proposalId];
if (proposal.vetoed) {
return ProposalState.Vetoed;
} else if (proposal.canceled) {
return ProposalState.Canceled;
} else if (block.number <= proposal.startBlock) {
return ProposalState.Pending;
} else if (block.number <= proposal.endBlock) {
return ProposalState.Active;
} else if (proposal.forVotes <= proposal.againstVotes || proposal.forVotes < proposal.quorumVotes) {
return ProposalState.Defeated;
} else if (proposal.eta == 0) {
return ProposalState.Succeeded;
} else if (proposal.executed) {
return ProposalState.Executed;
} else if (block.timestamp >= proposal.eta + timelock.GRACE_PERIOD()) {
return ProposalState.Expired;
} else {
return ProposalState.Queued;
}
}Overview Retrieves the state of a specified proposal.
Details
- Retrieve the proposal using its ID.
- Return the appropriate proposal state based on the recorded information and current conditions.
Parameters
proposalId- Proposal ID.
Return value
ProposalState- Proposal state.
castVote
castVote
function castVote(uint256 proposalId, uint8 support) external {
emit VoteCast(msg.sender, proposalId, support, castVoteInternal(msg.sender, proposalId, support), '');
}Overview Casts a vote on a proposal.
Details
- Call
castVoteInternalwith the voter address, proposal ID, and support value. - Emit an event containing the vote details.
Parameters
proposalId- ID of the proposal to vote on.
support- Vote support value.
0= against,1= for,2= abstain.
castVoteWithReason
castVoteWithReason
function castVoteWithReason(
uint256 proposalId,
uint8 support,
string calldata reason
) external {
emit VoteCast(msg.sender, proposalId, support, castVoteInternal(msg.sender, proposalId, support), reason);
}Overview Casts a vote on a proposal and records a reason.
Details
- Call
castVoteInternalwith the voter address, proposal ID, and support value. - Emit an event containing the vote details and reason.
Parameters
proposalId- ID of the proposal to vote on.
support- Vote support value.
0= against,1= for,2= abstain.
reason- Reason provided by the voter.
castVoteBySig
castVoteBySig
function castVoteBySig(
uint256 proposalId,
uint8 support,
uint8 v,
bytes32 r,
bytes32 s
) external {
bytes32 domainSeparator = keccak256(
abi.encode(DOMAIN_TYPEHASH, keccak256(bytes(name)), getChainIdInternal(), address(this))
);
bytes32 structHash = keccak256(abi.encode(BALLOT_TYPEHASH, proposalId, support));
bytes32 digest = keccak256(abi.encodePacked('\x19\x01', domainSeparator, structHash));
address signatory = ecrecover(digest, v, r, s);
require(signatory != address(0), 'NounsDAO::castVoteBySig: invalid signature');
emit VoteCast(signatory, proposalId, support, castVoteInternal(signatory, proposalId, support), '');
}Overview Casts a vote on a proposal using an EIP712 signature.
Details
- Construct the domain separator and struct hash for signature verification.
- Recover the signer address from the signature and revert if the signature is invalid.
- Call
castVoteInternalwith the voter address, proposal ID, and support value. - Emit an event containing the vote details.
Parameters
proposalId- ID of the proposal to vote on.
support- Vote support value.
0= against,1= for,2= abstain.
v- Signature
vvalue.
- Signature
r- Signature
rvalue.
- Signature
s- Signature
svalue.
- Signature
castVoteInternal
castVoteInternal
function castVoteInternal(
address voter,
uint256 proposalId,
uint8 support
) internal returns (uint96) {
require(state(proposalId) == ProposalState.Active, 'NounsDAO::castVoteInternal: voting is closed');
require(support <= 2, 'NounsDAO::castVoteInternal: invalid vote type');
Proposal storage proposal = proposals[proposalId];
Receipt storage receipt = proposal.receipts[voter];
require(receipt.hasVoted == false, 'NounsDAO::castVoteInternal: voter already voted');
/// @notice: Unlike GovernerBravo, votes are considered from the block the proposal was created in order to normalize quorumVotes and proposalThreshold metrics
uint96 votes = nouns.getPriorVotes(voter, proposal.startBlock - votingDelay);
if (support == 0) {
proposal.againstVotes = proposal.againstVotes + votes;
} else if (support == 1) {
proposal.forVotes = proposal.forVotes + votes;
} else if (support == 2) {
proposal.abstainVotes = proposal.abstainVotes + votes;
}
receipt.hasVoted = true;
receipt.support = support;
receipt.votes = votes;
return votes;
}Overview Executes the internal voting logic.
Details
- Verify that the proposal is active.
- Verify that the support value is in the range from
0to2. - Check the proposal and the voter's receipt to prevent repeat voting.
- Retrieve the voter's historical voting power at the applicable snapshot block.
- Update the proposal's for, against, or abstaining vote count based on the support value.
- Update the voting receipt.
- Return the voting power used.
Parameters
voter- Address of the voter.
proposalId- ID of the proposal to vote on.
support- Vote support value.
0= against,1= for,2= abstain.
Return value
uint96- Voting power used.
_setVotingDelay
_setVotingDelay
function _setVotingDelay(uint256 newVotingDelay) external {
require(msg.sender == admin, 'NounsDAO::_setVotingDelay: admin only');
require(
newVotingDelay >= MIN_VOTING_DELAY && newVotingDelay <= MAX_VOTING_DELAY,
'NounsDAO::_setVotingDelay: invalid voting delay'
);
uint256 oldVotingDelay = votingDelay;
votingDelay = newVotingDelay;
emit VotingDelaySet(oldVotingDelay, votingDelay);
}Overview Allows the administrator to change the voting delay.
Details
- Verify that the caller is the administrator.
- Verify that the new voting delay is within the permitted range.
- Update the voting delay and emit an event containing the old and new values.
Parameters
newVotingDelay- New voting delay in blocks.
_setVotingPeriod
_setVotingPeriod
function _setVotingPeriod(uint256 newVotingPeriod) external {
require(msg.sender == admin, 'NounsDAO::_setVotingPeriod: admin only');
require(
newVotingPeriod >= MIN_VOTING_PERIOD && newVotingPeriod <= MAX_VOTING_PERIOD,
'NounsDAO::_setVotingPeriod: invalid voting period'
);
uint256 oldVotingPeriod = votingPeriod;
votingPeriod = newVotingPeriod;
emit VotingPeriodSet(oldVotingPeriod, votingPeriod);
}Overview Allows the administrator to change the voting period.
Details
- Verify that the caller is the administrator.
- Verify that the new voting period is within the permitted range.
- Update the voting period and emit an event containing the old and new values.
Parameters
newVotingPeriod- New voting period in blocks.
_setProposalThresholdBPS
_setProposalThresholdBPS
function _setProposalThresholdBPS(uint256 newProposalThresholdBPS) external {
require(msg.sender == admin, 'NounsDAO::_setProposalThresholdBPS: admin only');
require(
newProposalThresholdBPS >= MIN_PROPOSAL_THRESHOLD_BPS &&
newProposalThresholdBPS <= MAX_PROPOSAL_THRESHOLD_BPS,
'NounsDAO::_setProposalThreshold: invalid proposal threshold'
);
uint256 oldProposalThresholdBPS = proposalThresholdBPS;
proposalThresholdBPS = newProposalThresholdBPS;
emit ProposalThresholdBPSSet(oldProposalThresholdBPS, proposalThresholdBPS);
}Overview Allows the administrator to set the proposal threshold in basis points.
Details
- Verify that the caller is the administrator.
- Verify that the new proposal threshold is within the permitted range.
- Update the proposal threshold and emit an event containing the old and new values.
Parameters
newProposalThresholdBPS- New proposal threshold.
_setQuorumVotesBPS
_setQuorumVotesBPS
function _setQuorumVotesBPS(uint256 newQuorumVotesBPS) external {
require(msg.sender == admin, 'NounsDAO::_setQuorumVotesBPS: admin only');
require(
newQuorumVotesBPS >= MIN_QUORUM_VOTES_BPS && newQuorumVotesBPS <= MAX_QUORUM_VOTES_BPS,
'NounsDAO::_setProposalThreshold: invalid proposal threshold'
);
uint256 oldQuorumVotesBPS = quorumVotesBPS;
quorumVotesBPS = newQuorumVotesBPS;
emit QuorumVotesBPSSet(oldQuorumVotesBPS, quorumVotesBPS);
}Overview Allows the administrator to set the quorum requirement in basis points.
Details
- Verify that the caller is the administrator.
- Verify that the new quorum requirement is within the permitted range.
- Update the quorum requirement and emit an event containing the old and new values.
Parameters
newQuorumVotesBPS- New quorum requirement in basis points.
_setPendingAdmin
_setPendingAdmin
function _setPendingAdmin(address newPendingAdmin) external {
// Check caller = admin
require(msg.sender == admin, 'NounsDAO::_setPendingAdmin: admin only');
// Save current value, if any, for inclusion in log
address oldPendingAdmin = pendingAdmin;
// Store pendingAdmin with value newPendingAdmin
pendingAdmin = newPendingAdmin;
// Emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin)
emit NewPendingAdmin(oldPendingAdmin, newPendingAdmin);
}Overview Initiates the transfer of administrative authority by setting a new pending administrator.
Details
- Verify that the caller is the administrator.
- Save the current pending administrator address.
- Set the new pending administrator address.
- Emit
NewPendingAdmin.
The new pending administrator must call _acceptAdmin to complete the transfer.
Parameters
newPendingAdmin- New pending administrator address.
_acceptAdmin
_acceptAdmin
function _acceptAdmin() external {
// Check caller is pendingAdmin and pendingAdmin ≠ address(0)
require(msg.sender == pendingAdmin && msg.sender != address(0), 'NounsDAO::_acceptAdmin: pending admin only');
// Save current values for inclusion in log
address oldAdmin = admin;
address oldPendingAdmin = pendingAdmin;
// Store admin with value pendingAdmin
admin = pendingAdmin;
// Clear the pending value
pendingAdmin = address(0);
emit NewAdmin(oldAdmin, admin);
emit NewPendingAdmin(oldPendingAdmin, pendingAdmin);
}Overview Allows the pending administrator to accept the transfer and become the administrator.
Details
- Verify that the caller is the pending administrator.
Also verify that
pendingAdminis notaddress(0). - Save the existing administrator and pending administrator addresses.
- Update the administrator to the pending administrator address.
- Emit
NewAdminandNewPendingAdmin.
_setVetoer
_setVetoer
function _setVetoer(address newVetoer) public {
require(msg.sender == vetoer, 'NounsDAO::_setVetoer: vetoer only');
emit NewVetoer(vetoer, newVetoer);
vetoer = newVetoer;
}Overview
Changes the vetoer address.
Details
- Verify that the caller is the current
vetoer. - Emit
NewVetoerwith the old and new vetoer addresses. - Update the
vetoeraddress.
Parameters
newVetoer- New
vetoeraddress.
- New
_burnVetoPower
_burnVetoPower
function _burnVetoPower() public {
// Check caller is pendingAdmin and pendingAdmin ≠ address(0)
require(msg.sender == vetoer, 'NounsDAO::_burnVetoPower: vetoer only');
_setVetoer(address(0));
}Overview Permanently relinquishes veto authority.
Details
- Verify that the caller is the current
vetoer. - Call
_setVetoerto set thevetoeraddress toaddress(0), removing veto authority.
proposalThreshold
proposalThreshold
function proposalThreshold() public view returns (uint256) {
return bps2Uint(proposalThresholdBPS, nouns.totalSupply());
}Overview Retrieves the current proposal threshold calculated using the total supply of Nouns tokens.
Details
- Calculate the proposal threshold using
bps2Uint. - Use the current proposal threshold in basis points (
proposalThresholdBPS) and the total Nouns token supply as inputs. - The resulting threshold is calculated from the total supply rather than being a fixed token amount.
Return value
uint256- Current proposal threshold.
quorumVotes
quorumVotes
function quorumVotes() public view returns (uint256) {
return bps2Uint(quorumVotesBPS, nouns.totalSupply());
}Overview Retrieves the current quorum votes calculated using the total supply of Nouns tokens.
Details
- Calculate quorum votes using
bps2Uint. - Use the current quorum requirement in basis points (
quorumVotesBPS) and the total Nouns token supply as inputs. - The resulting quorum requirement is calculated from the total supply rather than being a fixed vote count.
Return value
uint256- Current quorum votes.
bps2Uint
bps2Uint
function bps2Uint(uint256 bps, uint256 number) internal pure returns (uint256) {
return (number * bps) / 10000;
}Overview Converts basis points into an integer portion of a value.
Details
- Basis points express a percentage using a denominator of
10000.- For example,
100%corresponds to10000basis points.
- For example,
- Multiply
numberbybpsand divide by10000using integer arithmetic.
Parameters
bps- Basis points.
number- Input number.
Return value
uint256- Converted integer.
getChainIdInternal
getChainIdInternal
function getChainIdInternal() internal view returns (uint256) {
uint256 chainId;
assembly {
chainId := chainid()
}
return chainId;
}Overview Internal function retrieving the chain ID.
Details
- Retrieve the chain ID using assembly.
Return value
uint256- Chain ID.
Code
NounsDAOLogicV1
/governance/NounsDAOLogicV1.sol
NounsDAOInterfaces
/governance/NounsDAOInterfaces.sol
Conclusion
This article examined NounsDAOLogicV1 from Nouns using Bunzz's DeCipher feature. I hope it helped clarify the contract's governance logic. I plan to continue examining specific NFTs and smart contracts.
I also publish articles about blockchain and AI on my blog and Qiita.




