From 7aef0e491f8a6c186caba5614e754de01f37efa4 Mon Sep 17 00:00:00 2001 From: jbeanz Date: Fri, 24 Jun 2022 01:13:31 +0900 Subject: [PATCH] upgrade GovernorBravoDelegateG2 to 0.8.10 --- .../Governance/GovernorBravoDelegateG1.sol | 1 + .../Governance/GovernorBravoDelegateG2.sol | 60 +++++++++++-------- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/contracts/Governance/GovernorBravoDelegateG1.sol b/contracts/Governance/GovernorBravoDelegateG1.sol index 63aebfb5b..2c1442df9 100644 --- a/contracts/Governance/GovernorBravoDelegateG1.sol +++ b/contracts/Governance/GovernorBravoDelegateG1.sol @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: BSD-3-Clause pragma solidity ^0.8.10; pragma experimental ABIEncoderV2; diff --git a/contracts/Governance/GovernorBravoDelegateG2.sol b/contracts/Governance/GovernorBravoDelegateG2.sol index cc8ea398a..f14111fad 100644 --- a/contracts/Governance/GovernorBravoDelegateG2.sol +++ b/contracts/Governance/GovernorBravoDelegateG2.sol @@ -1,4 +1,5 @@ -pragma solidity ^0.5.16; +// SPDX-License-Identifier: BSD-3-Clause +pragma solidity ^0.8.10; pragma experimental ABIEncoderV2; import "./GovernorBravoInterfaces.sol"; @@ -39,7 +40,7 @@ contract GovernorBravoDelegate is GovernorBravoDelegateStorageV2, GovernorBravoE bytes32 public constant BALLOT_TYPEHASH = keccak256("Ballot(uint256 proposalId,uint8 support)"); /** - * @notice Used to initialize the contract during delegator contructor + * @notice Used to initialize the contract during delegator constructor * @param timelock_ The address of the Timelock * @param comp_ The address of the COMP token * @param votingPeriod_ The initial voting period @@ -91,24 +92,24 @@ contract GovernorBravoDelegate is GovernorBravoDelegateStorageV2, GovernorBravoE uint endBlock = add256(startBlock, votingPeriod); proposalCount++; - Proposal memory newProposal = Proposal({ - id: proposalCount, - proposer: msg.sender, - eta: 0, - targets: targets, - values: values, - signatures: signatures, - calldatas: calldatas, - startBlock: startBlock, - endBlock: endBlock, - forVotes: 0, - againstVotes: 0, - abstainVotes: 0, - canceled: false, - executed: false - }); - - proposals[newProposal.id] = newProposal; + Proposal storage newProposal = proposals[proposalCount]; + // This should never happen but add a check in case. + require(newProposal.id == 0, "GovernorBravo::propose: ProposalID collsion"); + newProposal.id = proposalCount; + newProposal.proposer = msg.sender; + newProposal.eta = 0; + newProposal.targets = targets; + newProposal.values = values; + newProposal.signatures = signatures; + newProposal.calldatas = calldatas; + newProposal.startBlock = startBlock; + newProposal.endBlock = endBlock; + newProposal.forVotes = 0; + newProposal.againstVotes = 0; + newProposal.abstainVotes = 0; + newProposal.canceled = false; + newProposal.executed = false; + latestProposalIds[newProposal.proposer] = newProposal.id; emit ProposalCreated(newProposal.id, msg.sender, targets, values, signatures, calldatas, startBlock, endBlock, description); @@ -144,7 +145,7 @@ contract GovernorBravoDelegate is GovernorBravoDelegateStorageV2, GovernorBravoE Proposal storage proposal = proposals[proposalId]; proposal.executed = true; for (uint i = 0; i < proposal.targets.length; i++) { - timelock.executeTransaction.value(proposal.values[i])(proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], proposal.eta); + timelock.executeTransaction{value:proposal.values[i]}(proposal.targets[i], proposal.values[i], proposal.signatures[i], proposal.calldatas[i], proposal.eta); } emit ProposalExecuted(proposalId); } @@ -180,7 +181,10 @@ contract GovernorBravoDelegate is GovernorBravoDelegateStorageV2, GovernorBravoE /** * @notice Gets actions of a proposal * @param proposalId the id of the proposal - * @return Targets, values, signatures, and calldatas of the proposal actions + * @return targets of the proposal actions + * @return values of the proposal actions + * @return signatures of the proposal actions + * @return calldatas of the proposal actions */ function getActions(uint proposalId) external view returns (address[] memory targets, uint[] memory values, string[] memory signatures, bytes[] memory calldatas) { Proposal storage p = proposals[proposalId]; @@ -292,7 +296,15 @@ contract GovernorBravoDelegate is GovernorBravoDelegateStorageV2, GovernorBravoE * @return If the account is whitelisted */ function isWhitelisted(address account) public view returns (bool) { - return (whitelistAccountExpirations[account] > now); + uint currentBlockTimestamp = getBlockTimestamp(); + return (whitelistAccountExpirations[account] > currentBlockTimestamp); + } + + /** + * @dev Function to simply retrieve block timestamp + */ + function getBlockTimestamp() internal view returns (uint) { + return block.timestamp; } /** @@ -424,7 +436,7 @@ contract GovernorBravoDelegate is GovernorBravoDelegateStorageV2, GovernorBravoE return a - b; } - function getChainIdInternal() internal pure returns (uint) { + function getChainIdInternal() internal view returns (uint) { uint chainId; assembly { chainId := chainid() } return chainId;