Skip to content

Commit

Permalink
bytes param added
Browse files Browse the repository at this point in the history
  • Loading branch information
novaknole committed Sep 19, 2024
1 parent b2eef30 commit 96bf27b
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 149 deletions.
4 changes: 3 additions & 1 deletion packages/contracts/src/MajorityVotingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
51 changes: 42 additions & 9 deletions packages/contracts/src/TokenVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {_applyRatioCeiled} from "@aragon/osx-commons-contracts/src/utils/math/Ra

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
Expand Down Expand Up @@ -68,12 +69,12 @@ contract TokenVoting is IMembership, MajorityVotingBase {
/// @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

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 69 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 69 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 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 126

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 126

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 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

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 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 175

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 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 @@ -178,14 +179,46 @@ contract TokenVoting is IMembership, MajorityVotingBase {
);
}

/// @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 createProposalParams() external pure override returns (string memory) {
return "[uint256 allowFailureMap, uint8 voteOption, bool tryEarlyExecution]";
}

/// @inheritdoc IMembership
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
19 changes: 16 additions & 3 deletions packages/contracts/src/mocks/MajorityVotingMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 createProposalParams() 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

0 comments on commit 96bf27b

Please sign in to comment.