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
Show file tree
Hide file tree
Changes from all 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
11 changes: 7 additions & 4 deletions packages/contracts/src/MajorityVotingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import {PluginUUPSUpgradeable} from "@aragon/osx-commons-contracts/src/plugin/PluginUUPSUpgradeable.sol";
import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol";
import {IProposal} from "@aragon/osx-commons-contracts/src/plugin/extensions/proposal/IProposal.sol";
import {IExecutor, Action} from "@aragon/osx-commons-contracts/src/executors/IExecutor.sol";

Check warning on line 16 in packages/contracts/src/MajorityVotingBase.sol

View workflow job for this annotation

GitHub Actions / checks

imported name IExecutor is not used

Check warning on line 16 in packages/contracts/src/MajorityVotingBase.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

imported name IExecutor is not used

Check warning on line 16 in packages/contracts/src/MajorityVotingBase.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

imported name IExecutor is not used

import {IMajorityVoting} from "./IMajorityVoting.sol";

Expand Down Expand Up @@ -174,7 +175,7 @@
ProposalParameters parameters;
Tally tally;
mapping(address => IMajorityVoting.VoteOption) voters;
IDAO.Action[] actions;
Action[] actions;
uint256 allowFailureMap;
uint256 minApprovalPower;
TargetConfig targetConfig; // added in v1.3
Expand Down Expand Up @@ -377,7 +378,9 @@
}

/// @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);
}

Expand Down Expand Up @@ -484,7 +487,7 @@
bool executed,
ProposalParameters memory parameters,
Tally memory tally,
IDAO.Action[] memory actions,
Action[] memory actions,
uint256 allowFailureMap
)
{
Expand Down Expand Up @@ -531,7 +534,7 @@
/// @return proposalId The ID of the proposal.
function createProposal(
bytes calldata _metadata,
IDAO.Action[] calldata _actions,
Action[] calldata _actions,
uint256 _allowFailureMap,
uint64 _startDate,
uint64 _endDate,
Expand Down
53 changes: 41 additions & 12 deletions packages/contracts/src/TokenVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import {_applyRatioCeiled} from "@aragon/osx-commons-contracts/src/utils/math/Ratio.sol";

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

Check warning on line 14 in packages/contracts/src/TokenVoting.sol

View workflow job for this annotation

GitHub Actions / checks

imported name IExecutor is not used

Check warning on line 14 in packages/contracts/src/TokenVoting.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

imported name IExecutor is not used

Check warning on line 14 in packages/contracts/src/TokenVoting.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

imported name IExecutor is not used

import {MajorityVotingBase} from "./MajorityVotingBase.sol";

/// @title TokenVoting
Expand All @@ -17,7 +20,7 @@
/// @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 23 in packages/contracts/src/TokenVoting.sol

View workflow job for this annotation

GitHub Actions / checks

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

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

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

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

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

View workflow job for this annotation

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;
Expand Down Expand Up @@ -64,16 +67,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 70 in packages/contracts/src/TokenVoting.sol

View workflow job for this annotation

GitHub Actions / checks

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

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

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

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

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

View workflow job for this annotation

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 71 in packages/contracts/src/TokenVoting.sol

View workflow job for this annotation

GitHub Actions / checks

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

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

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

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

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

View workflow job for this annotation

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 72 in packages/contracts/src/TokenVoting.sol

View workflow job for this annotation

GitHub Actions / checks

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

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

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

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

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

View workflow job for this annotation

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 73 in packages/contracts/src/TokenVoting.sol

View workflow job for this annotation

GitHub Actions / checks

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

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

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

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

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

View workflow job for this annotation

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);
Expand Down Expand Up @@ -106,7 +109,7 @@
/// @inheritdoc MajorityVotingBase
function createProposal(
bytes calldata _metadata,
IDAO.Action[] calldata _actions,
Action[] calldata _actions,
uint256 _allowFailureMap,
uint64 _startDate,
uint64 _endDate,
Expand Down Expand Up @@ -178,14 +181,40 @@
);
}

/// @inheritdoc IProposal
function createProposal(
bytes calldata _metadata,
IDAO.Action[] calldata _actions,
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.
uint256 allowFailureMap;
VoteOption _voteOption = VoteOption.None;
bool tryEarlyExecution;

if (_data.length != 0) {
(allowFailureMap, _voteOption, 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
Expand All @@ -197,19 +226,19 @@
}

/// @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 229 in packages/contracts/src/TokenVoting.sol

View workflow job for this annotation

GitHub Actions / checks

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

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

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

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

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

View workflow job for this annotation

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 234 in packages/contracts/src/TokenVoting.sol

View workflow job for this annotation

GitHub Actions / checks

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

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

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

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

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

View workflow job for this annotation

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.
/// @param _metadata The metadata of the proposal.
/// @return proposalId The ID of the proposal.
function createProposalId(
IDAO.Action[] calldata _actions,
Action[] calldata _actions,
bytes memory _metadata
) public pure override returns (uint256) {
return uint256(keccak256(abi.encode(_actions, _metadata)));
Expand Down
7 changes: 2 additions & 5 deletions packages/contracts/src/TokenVotingSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/src/VotingPowerCondition.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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_ &&
Expand Down
26 changes: 26 additions & 0 deletions packages/contracts/src/mocks/CustomExecutorMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

pragma solidity ^0.8.8;

import {IExecutor, Action} from "@aragon/osx-commons-contracts/src/executors/IExecutor.sol";

Check warning on line 5 in packages/contracts/src/mocks/CustomExecutorMock.sol

View workflow job for this annotation

GitHub Actions / checks

imported name IExecutor is not used

Check warning on line 5 in packages/contracts/src/mocks/CustomExecutorMock.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

imported name IExecutor is not used

Check warning on line 5 in packages/contracts/src/mocks/CustomExecutorMock.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

imported name IExecutor is not used

/// @dev DO NOT USE IN PRODUCTION!
contract CustomExecutorMock {
error FailedCustom();

event ExecutedCustom();

function execute(
bytes32 callId,
Action[] memory,
uint256
) external returns (bytes[] memory execResults, uint256 failureMap) {
(execResults, failureMap);

if (callId == bytes32(0)) {
revert FailedCustom();
} else {
emit ExecutedCustom();
}
}
}
3 changes: 2 additions & 1 deletion packages/contracts/src/mocks/DAOMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ pragma solidity ^0.8.8;
import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol";
import {IPermissionCondition} from "@aragon/osx-commons-contracts/src/permission/condition/IPermissionCondition.sol";
import {PermissionLib} from "@aragon/osx-commons-contracts/src/permission/PermissionLib.sol";
import {IExecutor, Action} from "@aragon/osx-commons-contracts/src/executors/IExecutor.sol";

contract DAOMock is IDAO {
contract DAOMock is IDAO, IExecutor {
address internal constant NO_CONDITION = address(0);

event Granted(
Expand Down
27 changes: 21 additions & 6 deletions packages/contracts/src/mocks/MajorityVotingMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

pragma solidity ^0.8.8;

import {IExecutor, Action} from "@aragon/osx-commons-contracts/src/executors/IExecutor.sol";

Check warning on line 5 in packages/contracts/src/mocks/MajorityVotingMock.sol

View workflow job for this annotation

GitHub Actions / checks

imported name IExecutor is not used

Check warning on line 5 in packages/contracts/src/mocks/MajorityVotingMock.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

imported name IExecutor is not used

Check warning on line 5 in packages/contracts/src/mocks/MajorityVotingMock.sol

View workflow job for this annotation

GitHub Actions / formatting-linting / checks

imported name IExecutor is not used

import {MajorityVotingBase, IDAO} from "../MajorityVotingBase.sol";

contract MajorityVotingMock is MajorityVotingBase {
Expand All @@ -15,15 +17,15 @@
}

function createProposalId(
IDAO.Action[] calldata _actions,
Action[] calldata _actions,
bytes memory _metadata
) public pure override returns (uint256) {
return uint256(keccak256(abi.encode(_actions, _metadata)));
}

function createProposal(
bytes calldata /* _metadata */,
IDAO.Action[] calldata /* _actions */,
Action[] calldata /* _actions */,
uint256 /* _allowFailureMap */,
uint64 /* _startDate */,
uint64 /* _endDate */,
Expand All @@ -33,14 +35,27 @@
return 0;
}

function createProposal(
function createProposal(
bytes calldata _metadata,
IDAO.Action[] calldata _actions,
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) {
Expand Down
Loading
Loading