Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bytes param added #32

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/contracts/src/MajorityVotingBase.sol
Original file line number Diff line number Diff line change
@@ -377,7 +377,9 @@ abstract contract MajorityVotingBase is
}

/// @inheritdoc IMajorityVoting
function canExecute(uint256 _proposalId) public view virtual override(IMajorityVoting, IProposal) returns (bool) {
function canExecute(
uint256 _proposalId
) public view virtual override(IMajorityVoting, IProposal) returns (bool) {
return _canExecute(_proposalId);
}

51 changes: 42 additions & 9 deletions packages/contracts/src/TokenVoting.sol
Original file line number Diff line number Diff line change
@@ -11,13 +11,14 @@

import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol";
import {MajorityVotingBase} from "./MajorityVotingBase.sol";
import {IProposal} from "@aragon/osx-commons-contracts/src/plugin/extensions/proposal/IProposal.sol";

/// @title TokenVoting
/// @author Aragon X - 2021-2023
/// @notice The majority voting implementation using an
/// [OpenZeppelin `Votes`](https://docs.openzeppelin.com/contracts/4.x/api/governance#Votes)
/// compatible governance token.
/// @dev v1.3 (Release 1, Build 3). For each upgrade, if the reinitialization step is required, increment the version numbers in the modifier for both the initialize and initializeFrom functions.

Check failure on line 21 in packages/contracts/src/TokenVoting.sol

GitHub Actions / checks

Line length must be no more than 120 but current length is 195

Check failure on line 21 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 195

Check failure on line 21 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 195
/// @custom:security-contact [email protected]
contract TokenVoting is IMembership, MajorityVotingBase {
using SafeCastUpgradeable for uint256;
@@ -64,16 +65,16 @@
emit MembershipContractAnnounced({definingContract: address(_token)});
}

/// @notice Reinitializes the TokenVoting after an upgrade from a previous protocol version.For each reinitialization step, use the `_fromBuild` version to decide which internal functions to call for reinitialization.

Check failure on line 68 in packages/contracts/src/TokenVoting.sol

GitHub Actions / checks

Line length must be no more than 120 but current length is 221

Check failure on line 68 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 221

Check failure on line 68 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 221
/// @dev WARNING: The contract should only be upgradeable through PSP to ensure that _fromBuild is not incorrectly passed, and that the appropriate permissions for the upgrade are properly configured.

Check failure on line 69 in packages/contracts/src/TokenVoting.sol

GitHub Actions / checks

Line length must be no more than 120 but current length is 204

Check failure on line 69 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 204

Check failure on line 69 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 204
/// @param _fromBuild The build version number of the previous implementation contract this upgrade is transitioning from.

Check failure on line 70 in packages/contracts/src/TokenVoting.sol

GitHub Actions / checks

Line length must be no more than 120 but current length is 126

Check failure on line 70 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 126

Check failure on line 70 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 126
/// @param _initData The initialization data to be passed to via `upgradeToAndCall` (see [ERC-1967](https://docs.openzeppelin.com/contracts/4.x/api/proxy#ERC1967Upgrade)).

Check failure on line 71 in packages/contracts/src/TokenVoting.sol

GitHub Actions / checks

Line length must be no more than 120 but current length is 175

Check failure on line 71 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 175

Check failure on line 71 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 175
function initializeFrom(
uint16 _fromBuild,
bytes calldata _initData
) external reinitializer(2) {
if(_fromBuild < 3) {
(uint256 minApprovals, TargetConfig memory targetConfig) = abi.decode(_initData, (uint256, TargetConfig));
function initializeFrom(uint16 _fromBuild, bytes calldata _initData) external reinitializer(2) {
if (_fromBuild < 3) {
(uint256 minApprovals, TargetConfig memory targetConfig) = abi.decode(
_initData,
(uint256, TargetConfig)
);
_updateMinApprovals(minApprovals);

_setTargetConfig(targetConfig);
@@ -178,14 +179,46 @@
);
}

/// @inheritdoc IProposal
function createProposal(
bytes calldata _metadata,
IDAO.Action[] calldata _actions,
uint64 _startDate,
uint64 _endDate
uint64 _endDate,
bytes memory _data
) external override returns (uint256 proposalId) {
// Calls public function for permission check.
proposalId = createProposal(_metadata, _actions, 0, _startDate, _endDate, VoteOption.None, false);
// Note that this calls public function for permission check.
if (_data.length == 0) {
// Proposal can still be created with default values.
proposalId = createProposal(
_metadata,
_actions,
0,
_startDate,
_endDate,
VoteOption.None,
false
);
} else {
(uint256 allowFailureMap, VoteOption _voteOption, bool tryEarlyExecution) = abi.decode(
_data,
(uint256, VoteOption, bool)
);
proposalId = createProposal(
_metadata,
_actions,
allowFailureMap,
_startDate,
_endDate,
_voteOption,
tryEarlyExecution
);
}
}

/// @inheritdoc IProposal
function createProposalParamsABI() external pure override returns (string memory) {
return "[uint256 allowFailureMap, uint8 voteOption, bool tryEarlyExecution]";
}

/// @inheritdoc IMembership
@@ -197,12 +230,12 @@
}

/// @notice Hashing function used to (re)build the proposal id from the proposal details..
/// @dev The proposal id is produced by hashing the ABI encoded `targets` array, the `values` array, the `calldatas` array

Check failure on line 233 in packages/contracts/src/TokenVoting.sol

GitHub Actions / checks

Line length must be no more than 120 but current length is 126

Check failure on line 233 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 126

Check failure on line 233 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 126
/// and the descriptionHash (bytes32 which itself is the keccak256 hash of the description string). This proposal id
/// can be produced from the proposal data which is part of the {ProposalCreated} event. It can even be computed in
/// advance, before the proposal is submitted.
/// The chainId and the governor address are not part of the proposal id computation. Consequently, the
/// same proposal (with same operation and same description) will have the same id if submitted on multiple governors

Check failure on line 238 in packages/contracts/src/TokenVoting.sol

GitHub Actions / checks

Line length must be no more than 120 but current length is 121

Check failure on line 238 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 121

Check failure on line 238 in packages/contracts/src/TokenVoting.sol

GitHub Actions / formatting-linting / checks

Line length must be no more than 120 but current length is 121
/// across multiple networks. This also means that in order to execute the same operation twice (on the same
/// governor) the proposer will have to change the description in order to avoid proposal id conflicts.
/// @param _actions The actions that will be executed after the proposal passes.
7 changes: 2 additions & 5 deletions packages/contracts/src/TokenVotingSetup.sol
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ contract TokenVotingSetup is PluginUpgradeableSetup {
/// @dev TODO: Migrate this constant to a common library that can be shared across plugins.
bytes32 public constant EXECUTE_PERMISSION_ID = keccak256("EXECUTE_PERMISSION");

/// @notice The ID of the permission required to call the `setTargetConfig` function.
/// @notice The ID of the permission required to call the `setTargetConfig` function.
bytes32 public constant SET_TARGET_CONFIG_PERMISSION_ID =
keccak256("SET_TARGET_CONFIG_PERMISSION");

@@ -283,10 +283,7 @@ contract TokenVotingSetup is PluginUpgradeableSetup {
preparedSetupData.helpers = new address[](1);
preparedSetupData.helpers[0] = votingPowerCondition;

initData = abi.encodeCall(
TokenVoting.initializeFrom,
(_fromBuild, _payload.data)
);
initData = abi.encodeCall(TokenVoting.initializeFrom, (_fromBuild, _payload.data));
}
}

2 changes: 1 addition & 1 deletion packages/contracts/src/VotingPowerCondition.sol
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ contract VotingPowerCondition is PermissionCondition {
(_where, _data, _permissionId);

uint256 minProposerVotingPower_ = TOKEN_VOTING.minProposerVotingPower();

if (minProposerVotingPower_ != 0) {
if (
VOTING_TOKEN.getVotes(_who) < minProposerVotingPower_ &&
19 changes: 16 additions & 3 deletions packages/contracts/src/mocks/MajorityVotingMock.sol
Original file line number Diff line number Diff line change
@@ -33,14 +33,27 @@ contract MajorityVotingMock is MajorityVotingBase {
return 0;
}

function createProposal(
function createProposal(
bytes calldata _metadata,
IDAO.Action[] calldata _actions,
uint64 _startDate,
uint64 _endDate
uint64 _endDate,
bytes memory
) external pure override returns (uint256 proposalId) {
// Calls public function for permission check.
proposalId = createProposal(_metadata, _actions, 0, _startDate, _endDate, VoteOption.None, false);
proposalId = createProposal(
_metadata,
_actions,
0,
_startDate,
_endDate,
VoteOption.None,
false
);
}

function createProposalParamsABI() external pure override returns (string memory) {
return "[uint256 allowFailureMap, uint8 voteOption, bool tryEarlyExecution]";
}

function totalVotingPower(uint256 /* _blockNumber */) public pure override returns (uint256) {
Loading