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

add target config on return #45

Merged
merged 5 commits into from
Nov 18, 2024
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
4 changes: 2 additions & 2 deletions packages/contracts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 11 additions & 7 deletions packages/contracts/src/MajorityVotingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, applied to the proposal when it was created. Added in build 3.
function getProposal(
uint256 _proposalId
)
Expand All @@ -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];
Expand All @@ -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.
Expand Down Expand Up @@ -596,6 +599,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(
Expand Down Expand Up @@ -625,12 +629,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);

Expand Down
12 changes: 6 additions & 6 deletions packages/contracts/src/TokenVotingSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions packages/contracts/test/10_unit-testing/11_plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,7 @@ describe('TokenVoting', function () {
defaultVotingSettings,
dummyActions,
dummyMetadata,
defaultTargetConfig,
} = await loadFixture(globalFixture);

const allowFailureMap = 1;
Expand Down Expand Up @@ -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 () => {
Expand All @@ -1497,6 +1502,7 @@ describe('TokenVoting', function () {
defaultVotingSettings,
dummyActions,
dummyMetadata,
defaultTargetConfig,
} = await loadFixture(globalFixture);

// Set Alice's balance to 10.
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading