From 0b02110de42ef0fcb341bd6378b31032a56aeab6 Mon Sep 17 00:00:00 2001 From: Giorgi Lagidze Date: Thu, 14 Nov 2024 17:13:03 +0400 Subject: [PATCH 1/4] add target config on return --- packages/contracts/src/MajorityVotingBase.sol | 7 +++++-- packages/contracts/test/10_unit-testing/11_plugin.ts | 10 ++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/contracts/src/MajorityVotingBase.sol b/packages/contracts/src/MajorityVotingBase.sol index ae17d720..baf760c8 100644 --- a/packages/contracts/src/MajorityVotingBase.sol +++ b/packages/contracts/src/MajorityVotingBase.sol @@ -523,8 +523,9 @@ abstract contract MajorityVotingBase is /// @return executed Whether the proposal is executed or not. /// @return parameters The parameters of the proposal. /// @return tally The current tally of the proposal. - /// @return actions The actions to be executed in the associated DAO after the proposal has passed. + /// @return actions The actions to be executed to the `target` contract address. /// @return allowFailureMap The bit map representations of which actions are allowed to revert so tx still succeeds. + /// @return targetConfig Execution configuration that was applied to the proposal when it was created. Added in build 3. function getProposal( uint256 _proposalId ) @@ -537,7 +538,8 @@ abstract contract MajorityVotingBase is ProposalParameters memory parameters, Tally memory tally, Action[] memory actions, - uint256 allowFailureMap + uint256 allowFailureMap, + TargetConfig memory targetConfig ) { Proposal storage proposal_ = proposals[_proposalId]; @@ -548,6 +550,7 @@ abstract contract MajorityVotingBase is tally = proposal_.tally; actions = proposal_.actions; allowFailureMap = proposal_.allowFailureMap; + targetConfig = proposal_.targetConfig; } /// @notice Updates the voting settings. diff --git a/packages/contracts/test/10_unit-testing/11_plugin.ts b/packages/contracts/test/10_unit-testing/11_plugin.ts index 11094e79..920a5d0a 100644 --- a/packages/contracts/test/10_unit-testing/11_plugin.ts +++ b/packages/contracts/test/10_unit-testing/11_plugin.ts @@ -1401,6 +1401,7 @@ describe('TokenVoting', function () { defaultVotingSettings, dummyActions, dummyMetadata, + defaultTargetConfig, } = await loadFixture(globalFixture); const allowFailureMap = 1; @@ -1487,6 +1488,10 @@ describe('TokenVoting', function () { expect(proposal.actions[0].to).to.equal(dummyActions[0].to); expect(proposal.actions[0].value).to.equal(dummyActions[0].value); expect(proposal.actions[0].data).to.equal(dummyActions[0].data); + expect(proposal.targetConfig).to.deep.equal([ + defaultTargetConfig.target, + defaultTargetConfig.operation, + ]); }); it('should create a vote and cast a vote immediately', async () => { @@ -1497,6 +1502,7 @@ describe('TokenVoting', function () { defaultVotingSettings, dummyActions, dummyMetadata, + defaultTargetConfig, } = await loadFixture(globalFixture); // Set Alice's balance to 10. @@ -1563,6 +1569,10 @@ describe('TokenVoting', function () { expect(proposal.tally.yes).to.equal(10); expect(proposal.tally.no).to.equal(0); expect(proposal.tally.abstain).to.equal(0); + expect(proposal.targetConfig).to.deep.equal([ + defaultTargetConfig.target, + defaultTargetConfig.operation, + ]); }); it('reverts creation when voting before the start date', async () => { From e557a58c5e0949c5a9f573f1d63d384e51879c60 Mon Sep 17 00:00:00 2001 From: Giorgi Lagidze Date: Fri, 15 Nov 2024 14:55:39 +0400 Subject: [PATCH 2/4] add more fixes --- packages/contracts/src/MajorityVotingBase.sol | 11 ++++++----- packages/contracts/src/TokenVotingSetup.sol | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/contracts/src/MajorityVotingBase.sol b/packages/contracts/src/MajorityVotingBase.sol index ae17d720..15f457bd 100644 --- a/packages/contracts/src/MajorityVotingBase.sol +++ b/packages/contracts/src/MajorityVotingBase.sol @@ -401,14 +401,14 @@ abstract contract MajorityVotingBase is /// @dev Reverts if the proposal with the given `_proposalId` does not exist. function canVote( uint256 _proposalId, - address _voter, + address _account, VoteOption _voteOption ) public view virtual returns (bool) { if (!_proposalExists(_proposalId)) { revert NonexistentProposal(_proposalId); } - return _canVote(_proposalId, _voter, _voteOption); + return _canVote(_proposalId, _account, _voteOption); } /// @inheritdoc IMajorityVoting @@ -596,6 +596,7 @@ abstract contract MajorityVotingBase is /// @notice Internal function to cast a vote. It assumes the queried proposal exists. /// @param _proposalId The ID of the proposal. /// @param _voteOption The chosen vote option to be casted on the proposal vote. + /// @param _voter The address of the account that is voting on the `_proposalId`. /// @param _tryEarlyExecution If `true`, early execution is tried after the vote cast. /// The call does not revert if early execution is not possible. function _vote( @@ -625,12 +626,12 @@ abstract contract MajorityVotingBase is /// @notice Internal function to check if a voter can vote. It assumes the queried proposal exists. /// @param _proposalId The ID of the proposal. - /// @param _voter The address of the voter to check. - /// @param _voteOption Whether the voter abstains, supports or opposes the proposal. + /// @param _account The address of the voter to check. + /// @param _voteOption Whether the voter abstains, supports or opposes the proposal. /// @return Returns `true` if the given voter can vote on a certain proposal and `false` otherwise. function _canVote( uint256 _proposalId, - address _voter, + address _account, VoteOption _voteOption ) internal view virtual returns (bool); diff --git a/packages/contracts/src/TokenVotingSetup.sol b/packages/contracts/src/TokenVotingSetup.sol index 58b1c656..0d79daf8 100644 --- a/packages/contracts/src/TokenVotingSetup.sol +++ b/packages/contracts/src/TokenVotingSetup.sol @@ -36,24 +36,24 @@ contract TokenVotingSetup is PluginUpgradeableSetup { using ProxyLib for address; /// @notice The identifier of the `EXECUTE_PERMISSION` permission. - bytes32 public constant EXECUTE_PERMISSION_ID = keccak256("EXECUTE_PERMISSION"); + bytes32 private constant EXECUTE_PERMISSION_ID = keccak256("EXECUTE_PERMISSION"); /// @notice The ID of the permission required to call the `setTargetConfig` function. - bytes32 public constant SET_TARGET_CONFIG_PERMISSION_ID = + bytes32 private constant SET_TARGET_CONFIG_PERMISSION_ID = keccak256("SET_TARGET_CONFIG_PERMISSION"); /// @notice The ID of the permission required to call the `setMetadata` function. - bytes32 public constant SET_METADATA_PERMISSION_ID = keccak256("SET_METADATA_PERMISSION"); + bytes32 private constant SET_METADATA_PERMISSION_ID = keccak256("SET_METADATA_PERMISSION"); /// @notice The ID of the permission required to call the `upgradeToAndCall` function. - bytes32 internal constant UPGRADE_PLUGIN_PERMISSION_ID = keccak256("UPGRADE_PLUGIN_PERMISSION"); + bytes32 private constant UPGRADE_PLUGIN_PERMISSION_ID = keccak256("UPGRADE_PLUGIN_PERMISSION"); /// @notice The ID of the permission required to call the `execute` function. - bytes32 internal constant EXECUTE_PROPOSAL_PERMISSION_ID = + bytes32 private constant EXECUTE_PROPOSAL_PERMISSION_ID = keccak256("EXECUTE_PROPOSAL_PERMISSION"); /// @notice A special address encoding permissions that are valid for any address `who` or `where`. - address internal constant ANY_ADDR = address(type(uint160).max); + address private constant ANY_ADDR = address(type(uint160).max); /// @notice The address of the `TokenVoting` base contract. // solhint-disable-next-line immutable-vars-naming From 6702381b7d94d00029a9463acd619d81ee5408b2 Mon Sep 17 00:00:00 2001 From: Giorgi Lagidze Date: Fri, 15 Nov 2024 15:02:51 +0400 Subject: [PATCH 3/4] prettier --- packages/contracts/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/contracts/CHANGELOG.md b/packages/contracts/CHANGELOG.md index c395950d..53ab5f09 100644 --- a/packages/contracts/CHANGELOG.md +++ b/packages/contracts/CHANGELOG.md @@ -10,10 +10,10 @@ and this project adheres to the [Aragon OSx Plugin Versioning Convention](https: ### Added - Copied files from [aragon/osx commit 1130df](https://github.com/aragon/osx/commit/1130dfce94fd294c4341e91a8f3faccc54cf43b7) -- `createProposal` standardized function. +- `createProposal` standardized function. - `createProposal` function is auth protected. - `ListedCheckCondition` permission condition to grant the create proposal permission. This condition will allow the creation based on plugin's setup. -- `execute` function is auth protected, when the plugin is installed this permission will be granted to `ANY_ADDRESS`. +- `execute` function is auth protected, when the plugin is installed this permission will be granted to `ANY_ADDRESS`. - The plugin inherits now from `MetadataExtensionUpgradeable`, meaning that the plugin has metadata that can be get/set (`getMetadata`, `setMetadata`). - `initialize` function receives also `pluginMetadata` and `TargetConfig`. - `hasSucceeded` and `customProposalParamsABI` function implementing to `IProposal` interface. From 2aaade8b77fc44a559b1751b5849499a01f290dd Mon Sep 17 00:00:00 2001 From: Giorgi Lagidze Date: Fri, 15 Nov 2024 15:13:16 +0400 Subject: [PATCH 4/4] lint contract --- packages/contracts/src/MajorityVotingBase.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contracts/src/MajorityVotingBase.sol b/packages/contracts/src/MajorityVotingBase.sol index 132964d6..dacd0aa9 100644 --- a/packages/contracts/src/MajorityVotingBase.sol +++ b/packages/contracts/src/MajorityVotingBase.sol @@ -525,7 +525,7 @@ abstract contract MajorityVotingBase is /// @return tally The current tally of the proposal. /// @return actions The actions to be executed to the `target` contract address. /// @return allowFailureMap The bit map representations of which actions are allowed to revert so tx still succeeds. - /// @return targetConfig Execution configuration that was applied to the proposal when it was created. Added in build 3. + /// @return targetConfig Execution configuration, applied to the proposal when it was created. Added in build 3. function getProposal( uint256 _proposalId )