Skip to content

Commit

Permalink
Refactoring interfaces and base contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
brickpop committed Jan 16, 2025
1 parent ed980b5 commit 157f27c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 94 deletions.
2 changes: 1 addition & 1 deletion src/LockManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.13;
import {ILockManager, LockManagerSettings, UnlockMode, PluginMode} from "./interfaces/ILockManager.sol";
import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol";
import {DaoAuthorizable} from "@aragon/osx-commons-contracts/src/permission/auth/DaoAuthorizable.sol";
import {ILockToVoteBase} from "./interfaces/ILockToVote.sol";
import {ILockToVoteBase} from "./interfaces/ILockToVoteBase.sol";
import {ILockToApprove} from "./interfaces/ILockToApprove.sol";
import {ILockToVote} from "./interfaces/ILockToVote.sol";
import {IMajorityVoting} from "./interfaces/IMajorityVoting.sol";
Expand Down
35 changes: 35 additions & 0 deletions src/base/LockToVoteBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

pragma solidity ^0.8.8;

/* solhint-disable max-line-length */

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ILockManager} from "../interfaces/ILockManager.sol";
import {ILockToVoteBase} from "../interfaces/ILockToVoteBase.sol";
import {IMembership} from "@aragon/osx-commons-contracts/src/plugin/extensions/membership/IMembership.sol";

/// @title LockToVoteBase
/// @author Aragon X 2024-2025
abstract contract LockToVoteBase is ILockToVoteBase, IMembership {
/// @inheritdoc ILockToVoteBase
ILockManager public lockManager;

/// @inheritdoc ILockToVoteBase
function token() external view returns (IERC20) {
return lockManager.token();
}

/// @inheritdoc ILockToVoteBase
function underlyingToken() external view returns (IERC20) {
return lockManager.underlyingToken();
}

/// @inheritdoc IMembership
function isMember(address _account) external view returns (bool) {
if (lockManager.lockedBalances(_account) > 0) return true;
else if (lockManager.token().balanceOf(_account) > 0) return true;
return false;
}

}
5 changes: 4 additions & 1 deletion src/interfaces/ILockManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ interface ILockManager {

/// @notice Locks the balance currently allowed by msg.sender on this contract and registers the given vote on the target plugin
/// @param proposalId The ID of the proposal where the vote will be registered
function lockAndVote(uint256 proposalId, IMajorityVoting.VoteOption vote) external;
function lockAndVote(
uint256 proposalId,
IMajorityVoting.VoteOption vote
) external;

/// @notice Uses the locked balance to place an approval on the given proposal for the registered plugin
/// @param proposalId The ID of the proposal where the approval will be registered
Expand Down
48 changes: 0 additions & 48 deletions src/interfaces/ILockToApprove.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,8 @@

pragma solidity ^0.8.17;

import {IDAO} from "@aragon/osx-commons-contracts/src/dao/IDAO.sol";
import {Action} from "@aragon/osx-commons-contracts/src/executors/IExecutor.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {PluginUUPSUpgradeable} from "@aragon/osx-commons-contracts/src/plugin/PluginUUPSUpgradeable.sol";
import {IPlugin} from "@aragon/osx-commons-contracts/src/plugin/IPlugin.sol";
import {ILockManager} from "./ILockManager.sol";
import {ILockToVoteBase} from "./ILockToVoteBase.sol";

/// @notice A container for the voting settings that will be applied as parameters on proposal creation.
/// @param minApprovalRatio The minimum approval ratio required to approve over the total supply.
/// Its value has to be in the interval [0, 10^6] defined by `RATIO_BASE = 10**6`.
/// @param minProposalDuration The minimum duration of the proposal voting stage in seconds.
struct LockToApproveSettings {
uint32 minApprovalRatio;
uint64 minProposalDuration;
}

/// @notice A container for proposal-related information.
/// @param executed Whether the proposal is executed or not.
/// @param parameters The proposal parameters at the time of the proposal creation.
/// @param approvalTally The vote tally of the proposal.
/// @param approvals The voting power cast by each voter.
/// @param actions The actions to be executed when the proposal passes.
/// @param allowFailureMap A bitmap allowing the proposal to succeed, even if individual actions might revert.
/// If the bit at index `i` is 1, the proposal succeeds even if the `i`th action reverts.
/// A failure map value of 0 requires every action to not revert.
/// @param targetConfig Configuration for the execution target, specifying the target address and operation type
/// (either `Call` or `DelegateCall`). Defined by `TargetConfig` in the `IPlugin` interface,
/// part of the `osx-commons-contracts` package, added in build 3.
struct ProposalApproval {
bool executed;
ProposalApprovalParameters parameters;
uint256 approvalTally;
mapping(address => uint256) approvals;
Action[] actions;
uint256 allowFailureMap;
IPlugin.TargetConfig targetConfig;
}

/// @notice A container for the proposal parameters at the time of proposal creation.
/// @param minApprovalRatio The approval threshold above which the proposal becomes executable.
/// The value has to be in the interval [0, 10^6] defined by `RATIO_BASE = 10**6`.
/// @param startDate The start date of the proposal vote.
/// @param endDate The end date of the proposal vote.
struct ProposalApprovalParameters {
uint32 minApprovalRatio;
uint64 startDate;
uint64 endDate;
}

/// @title ILockToApprove
/// @author Aragon X
/// @notice Governance plugin allowing token holders to use tokens locked without a snapshot requirement and engage in proposals immediately
Expand Down
21 changes: 10 additions & 11 deletions src/interfaces/ILockToVoteBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {IPlugin} from "@aragon/osx-commons-contracts/src/plugin/IPlugin.sol";
import {ILockManager} from "./ILockManager.sol";

/// @title ILockToVoteBase
/// @author Aragon X
/// @author Aragon X 2024-2025
interface ILockToVoteBase {
/// @notice Returns the address of the manager contract, which holds the locked balances and the allocated vote balances.
function lockManager() external view returns (ILockManager);
Expand All @@ -23,21 +23,20 @@ interface ILockToVoteBase {
/// @return The address of the underlying token.
function underlyingToken() external view returns (IERC20);

/// @notice Internal function to check if a proposal is still open.
/// @param _proposalId The ID of the proposal.
/// @return True if the proposal is open, false otherwise.
function isProposalOpen(uint256 _proposalId) external view returns (bool);

/// @notice Returns whether the account has voted for the proposal.
/// @param proposalId The ID of the proposal.
/// @param voter The account address to be checked.
/// @return The amount of balance that has been allocated to the proposal by the given account.
function usedVotingPower(uint256 proposalId, address voter) external view returns (uint256);
function usedVotingPower(
uint256 proposalId,
address voter
) external view returns (uint256);

/// @notice Internal function to check if a proposal is still open.
/// @param _proposalId The ID of the proposal.
/// @return True if the proposal is open, false otherwise.
function isProposalOpen(uint256 _proposalId) external view returns (bool);

error NoVotingPower();
error ProposalAlreadyExists(uint256 proposalId);
error DateOutOfBounds(uint256 limit, uint256 actual);
error ExecutionForbidden(uint256 proposalId);

event Executed(uint256 proposalId);
}
33 changes: 0 additions & 33 deletions src/interfaces/IMajorityVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,44 +89,11 @@ interface IMajorityVoting {
uint256 _proposalId
) external view returns (bool);

/// @notice Checks if an account can participate on a proposal. This can be because the vote
/// - has not started,
/// - has ended,
/// - was executed, or
/// - the voter doesn't have voting powers.
/// - the voter can increase the amount of tokens assigned
/// @param proposalId The proposal Id.
/// @param voter The account address to be checked.
/// @return Returns true if the account is allowed to vote.
function canVote(
uint256 proposalId,
address voter
) external view returns (bool);

/// @notice Checks if a proposal can be executed.
/// @param _proposalId The ID of the proposal to be checked.
/// @return True if the proposal can be executed, false otherwise.
function canExecute(uint256 _proposalId) external view returns (bool);

/// @notice Votes on a proposal and, depending on the mode, executes it.
/// @dev `voteOption`, 1 -> abstain, 2 -> yes, 3 -> no
/// @param proposalId The ID of the proposal to vote on.
/// @param voter The address of the account whose vote will be registered
/// @param voteOption The value of the new vote to register. If an existing vote existed, it will be replaced.
/// @param votingPower The new balance that should be allocated to the voter. It can only be bigger.
/// @dev votingPower updates any prior voting power, it does not add to the existing amount.
function vote(
uint256 proposalId,
address voter,
VoteOption voteOption,
uint256 votingPower
) external;

/// @notice Reverts the existing voter's vote, if existing.
/// @param proposalId The ID of the proposal.
/// @param voter The voter's address.
function clearVote(uint256 proposalId, address voter) external;

/// @notice Executes a proposal.
/// @param _proposalId The ID of the proposal to be executed.
function execute(uint256 _proposalId) external;
Expand Down

0 comments on commit 157f27c

Please sign in to comment.