Skip to content

Commit

Permalink
exploratory code for protocol rewards
Browse files Browse the repository at this point in the history
because we hit the contract size limit, this commit has a POC for
reducing it.
all the admin functions are replaced with a fallback function that
delegate calls the admin lib.
  • Loading branch information
davidbrai committed Nov 10, 2023
1 parent b7bf7e9 commit b50b96a
Show file tree
Hide file tree
Showing 13 changed files with 1,141 additions and 439 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,8 @@ contract NounsDAOStorageV3 {
address[] signers;
/// @notice When true, a proposal would be executed on timelockV1 instead of the current timelock
bool executeOnTimelockV1;
// TODO bitpack and natspec
uint16 client;
}

/// @notice Ballot receipt record for a voter
Expand Down
516 changes: 265 additions & 251 deletions packages/nouns-contracts/contracts/governance/NounsDAOLogicV3.sol

Large diffs are not rendered by default.

237 changes: 115 additions & 122 deletions packages/nouns-contracts/contracts/governance/NounsDAOV3Admin.sol

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ library NounsDAOV3Proposals {
function propose(
NounsDAOStorageV3.StorageV3 storage ds,
ProposalTxs memory txs,
string memory description
string memory description,
uint16 client
) internal returns (uint256) {
uint256 adjustedTotalSupply = ds.adjustedTotalSupply();
uint256 proposalThreshold_ = checkPropThreshold(
Expand All @@ -177,7 +178,8 @@ library NounsDAOV3Proposals {
proposalId,
proposalThreshold_,
adjustedTotalSupply,
txs
txs,
client
);
ds.latestProposalIds[msg.sender] = proposalId;

Expand All @@ -197,9 +199,10 @@ library NounsDAOV3Proposals {
function proposeOnTimelockV1(
NounsDAOStorageV3.StorageV3 storage ds,
ProposalTxs memory txs,
string memory description
string memory description,
uint16 client
) internal returns (uint256) {
uint256 newProposalId = propose(ds, txs, description);
uint256 newProposalId = propose(ds, txs, description, client);

NounsDAOStorageV3.Proposal storage newProposal = ds._proposals[newProposalId];
newProposal.executeOnTimelockV1 = true;
Expand All @@ -209,6 +212,12 @@ library NounsDAOV3Proposals {
return newProposalId;
}

struct ProposalTemp {
uint256 proposalId;
uint256 adjustedTotalSupply;
uint256 propThreshold;
}

/**
* @notice Function used to propose a new proposal. Sender and signers must have delegates above the proposal threshold
* @param proposerSignatures Array of signers who have signed the proposal and their signatures.
Expand All @@ -221,22 +230,24 @@ library NounsDAOV3Proposals {
NounsDAOStorageV3.StorageV3 storage ds,
NounsDAOStorageV3.ProposerSignature[] memory proposerSignatures,
ProposalTxs memory txs,
string memory description
string memory description,
uint16 client
) external returns (uint256) {
if (proposerSignatures.length == 0) revert MustProvideSignatures();
checkProposalTxs(txs);
uint256 proposalId = ds.proposalCount = ds.proposalCount + 1;

uint256 adjustedTotalSupply = ds.adjustedTotalSupply();

uint256 propThreshold = proposalThreshold(ds, adjustedTotalSupply);
ProposalTemp memory temp;
temp.proposalId = ds.proposalCount = ds.proposalCount + 1;
temp.adjustedTotalSupply = ds.adjustedTotalSupply();
temp.propThreshold = proposalThreshold(ds, temp.adjustedTotalSupply);

NounsDAOStorageV3.Proposal storage newProposal = createNewProposal(
ds,
proposalId,
propThreshold,
adjustedTotalSupply,
txs
temp.proposalId,
temp.propThreshold,
temp.adjustedTotalSupply,
txs,
client
);

// important that the proposal is created before the verification call in order to ensure
Expand All @@ -246,16 +257,16 @@ library NounsDAOV3Proposals {
proposerSignatures,
txs,
description,
proposalId
temp.proposalId
);
if (signers.length == 0) revert MustProvideSignatures();
if (votes <= propThreshold) revert VotesBelowProposalThreshold();
if (votes <= temp.propThreshold) revert VotesBelowProposalThreshold();

newProposal.signers = signers;

emitNewPropEvents(newProposal, signers, ds.minQuorumVotes(adjustedTotalSupply), txs, description);
emitNewPropEvents(newProposal, signers, ds.minQuorumVotes(temp.adjustedTotalSupply), txs, description);

return proposalId;
return temp.proposalId;
}

/**
Expand Down Expand Up @@ -482,16 +493,6 @@ library NounsDAOV3Proposals {
executeInternal(ds, proposal, timelock);
}

/**
* @notice Executes a queued proposal on timelockV1 if eta has passed
* This is only required for proposal that were queued on timelockV1, but before the upgrade to DAO V3.
* These proposals will not have the `executeOnTimelockV1` bool turned on.
*/
function executeOnTimelockV1(NounsDAOStorageV3.StorageV3 storage ds, uint256 proposalId) external {
NounsDAOStorageV3.Proposal storage proposal = ds._proposals[proposalId];
executeInternal(ds, proposal, ds.timelockV1);
}

function executeInternal(
NounsDAOStorageV3.StorageV3 storage ds,
NounsDAOStorageV3.Proposal storage proposal,
Expand Down Expand Up @@ -893,7 +894,8 @@ library NounsDAOV3Proposals {
uint256 proposalId,
uint256 proposalThreshold_,
uint256 adjustedTotalSupply,
ProposalTxs memory txs
ProposalTxs memory txs,
uint16 client
) internal returns (NounsDAOStorageV3.Proposal storage newProposal) {
uint64 updatePeriodEndBlock = SafeCast.toUint64(block.number + ds.proposalUpdatablePeriodInBlocks);
uint256 startBlock = updatePeriodEndBlock + ds.votingDelay;
Expand All @@ -912,6 +914,7 @@ library NounsDAOV3Proposals {
newProposal.totalSupply = adjustedTotalSupply;
newProposal.creationBlock = SafeCast.toUint64(block.number);
newProposal.updatePeriodEndBlock = updatePeriodEndBlock;
newProposal.client = client;
}

function emitNewPropEvents(
Expand Down
Loading

0 comments on commit b50b96a

Please sign in to comment.