Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
vrde committed Nov 14, 2023
1 parent b8cff73 commit 06ec9df
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 148 deletions.
4 changes: 4 additions & 0 deletions contracts/ResolutionManager/IResolutionManager.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

interface IResolutionManager {}
2 changes: 1 addition & 1 deletion contracts/ResolutionManager/ResolutionManagerBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.16;

import "../extensions/DAORegistryProxy.sol";

contract ResolutionManagerBase is DAORegistryProxy {
abstract contract ResolutionManagerBase is DAORegistryProxy {
event ResolutionCreated(address indexed from, uint256 indexed resolutionId);

event ResolutionUpdated(address indexed from, uint256 indexed resolutionId);
Expand Down
14 changes: 7 additions & 7 deletions contracts/ShareholderRegistry/ShareholderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract ShareholderRegistry is Initializable, ShareholderRegistrySnapshot {
public
virtual
override
onlyRole(Roles.RESOLUTION_ROLE)
onlyResolutionManager
returns (uint256)
{
return _snapshot();
Expand All @@ -56,7 +56,7 @@ contract ShareholderRegistry is Initializable, ShareholderRegistrySnapshot {
function setStatus(
bytes32 status,
address account
) public virtual onlyRole(Roles.RESOLUTION_ROLE) {
) public virtual onlyResolutionManager {
_setStatus(status, account);
}

Expand All @@ -69,7 +69,7 @@ contract ShareholderRegistry is Initializable, ShareholderRegistrySnapshot {
function mint(
address account,
uint256 amount
) public virtual onlyRole(Roles.RESOLUTION_ROLE) {
) public virtual onlyResolutionManager {
_mint(account, amount);
}

Expand All @@ -82,7 +82,7 @@ contract ShareholderRegistry is Initializable, ShareholderRegistrySnapshot {
function burn(
address account,
uint256 amount
) external virtual onlyRole(Roles.RESOLUTION_ROLE) {
) external virtual onlyResolutionManager {
_burn(account, amount);
}

Expand All @@ -93,7 +93,7 @@ contract ShareholderRegistry is Initializable, ShareholderRegistrySnapshot {
*/
function batchTransferFromDAO(
address[] memory recipients
) public virtual onlyRole(Roles.RESOLUTION_ROLE) {
) public virtual onlyResolutionManager {
super._batchTransferFromDAO(recipients);
}

Expand All @@ -109,7 +109,7 @@ contract ShareholderRegistry is Initializable, ShareholderRegistrySnapshot {
address from,
address to,
uint256 amount
) public virtual override onlyRole(Roles.RESOLUTION_ROLE) returns (bool) {
) public virtual override onlyResolutionManager returns (bool) {
_transfer(from, to, amount);
return true;
}
Expand All @@ -124,7 +124,7 @@ contract ShareholderRegistry is Initializable, ShareholderRegistrySnapshot {
function transfer(
address to,
uint256 amount
) public virtual override onlyRole(Roles.RESOLUTION_ROLE) returns (bool) {
) public virtual override onlyResolutionManager returns (bool) {
return super.transfer(to, amount);
}
}
73 changes: 9 additions & 64 deletions contracts/Voting/Voting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,23 @@ pragma solidity 0.8.16;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "../ShareholderRegistry/IShareholderRegistry.sol";
import "./VotingSnapshot.sol";
import { Roles } from "../extensions/Roles.sol";
import "../extensions/DAORoles.sol";
import "../extensions/HasRole.sol";

/**
* @title Voting
* @notice The smart contract handles voting power delegation and manages voting snapshots.
*/
contract Voting is VotingSnapshot, Initializable, HasRole {
contract Voting is VotingSnapshot, Initializable {
/**
* @notice Initializes the contract with given DAO roles.
* @param roles Instance of a DAORoles contract.
* @param daoRegistry Instance of a DAORoles contract.
*/
function initialize(DAORoles roles) public initializer {
require(address(roles) != address(0), "Voting: 0x0 not allowed");
_setRoles(roles);
function initialize(DAORegistry daoRegistry) public initializer {
__DAORegistryProxy_init(daoRegistry);
}

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() initializer {}

/**
* @dev Modifier that restricts access to only the token contract.
*/
modifier onlyToken() virtual {
require(
msg.sender == address(_token) ||
msg.sender == address(_shareholderRegistry),
"Voting: only Token contract can call this method."
);
_;
}

modifier zeroCheck(address address_) {
require(address_ != address(0), "Voting: 0x0 not allowed");
_;
}

// Dependencies

/**
* @notice Sets the token contract address.
* @param token Address of the token contract.
*/
function setToken(
IERC20Upgradeable token
)
external
virtual
override
onlyRole(Roles.OPERATOR_ROLE)
zeroCheck(address(token))
{
super._setToken(token);
}

/**
* @notice Sets the shareholder registry contract address.
* @param shareholderRegistry Address of the shareholder registry contract.
*/
function setShareholderRegistry(
IShareholderRegistry shareholderRegistry
)
external
virtual
override
onlyRole(Roles.OPERATOR_ROLE)
zeroCheck(address(shareholderRegistry))
{
_setShareholderRegistry(shareholderRegistry);
}

// Snapshottable

/**
Expand All @@ -86,7 +31,7 @@ contract Voting is VotingSnapshot, Initializable, HasRole {
public
virtual
override
onlyRole(Roles.RESOLUTION_ROLE)
onlyResolutionManager
returns (uint256)
{
return _snapshot();
Expand All @@ -105,7 +50,7 @@ contract Voting is VotingSnapshot, Initializable, HasRole {
address from,
address to,
uint256 amount
) external virtual override onlyToken {
) external virtual override onlyGovernanceToken {
_afterTokenTransfer(from, to, amount);
}

Expand All @@ -115,7 +60,7 @@ contract Voting is VotingSnapshot, Initializable, HasRole {
*/
function beforeRemoveContributor(
address account
) external virtual override onlyRole(Roles.SHAREHOLDER_REGISTRY_ROLE) {
) external virtual override onlyShareholderRegistry {
_beforeRemoveContributor(account);
}

Expand All @@ -125,7 +70,7 @@ contract Voting is VotingSnapshot, Initializable, HasRole {
*/
function afterAddContributor(
address account
) external virtual override onlyRole(Roles.SHAREHOLDER_REGISTRY_ROLE) {
) external virtual override onlyShareholderRegistry {
_afterAddContributor(account);
}

Expand All @@ -149,7 +94,7 @@ contract Voting is VotingSnapshot, Initializable, HasRole {
function delegateFrom(
address delegator,
address newDelegate
) public virtual override onlyRole(Roles.RESOLUTION_ROLE) {
) public virtual override onlyResolutionManager {
_delegate(delegator, newDelegate);
}
}
37 changes: 9 additions & 28 deletions contracts/Voting/VotingBase.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.16;

import "../extensions/DAORegistryProxy.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "../ShareholderRegistry/IShareholderRegistry.sol";
import "./IVoting.sol";

abstract contract VotingBase is IVoting {
abstract contract VotingBase is IVoting, DAORegistryProxy {
event DelegateChanged(
address indexed delegator,
address currentDelegate,
Expand All @@ -18,9 +19,6 @@ abstract contract VotingBase is IVoting {
uint256 newVotingPower
);

IShareholderRegistry internal _shareholderRegistry;
IERC20Upgradeable internal _token;

bytes32 internal _contributorRole;

mapping(address => address) internal _delegates;
Expand All @@ -29,17 +27,10 @@ abstract contract VotingBase is IVoting {

uint256 internal _totalVotingPower;

// Abstract
function setToken(IERC20Upgradeable token) external virtual;

function beforeRemoveContributor(address account) external virtual;

function afterAddContributor(address account) external virtual;

function setShareholderRegistry(
IShareholderRegistry shareholderRegistry
) external virtual;

function canVote(address account) public view virtual returns (bool) {
return getDelegate(account) != address(0);
}
Expand Down Expand Up @@ -75,17 +66,6 @@ abstract contract VotingBase is IVoting {

// Internal

function _setToken(IERC20Upgradeable token) internal virtual {
_token = token;
}

function _setShareholderRegistry(
IShareholderRegistry shareholderRegistry
) internal virtual {
_shareholderRegistry = shareholderRegistry;
_contributorRole = _shareholderRegistry.CONTRIBUTOR_STATUS();
}

function _afterTokenTransfer(
address from,
address to,
Expand All @@ -106,11 +86,11 @@ abstract contract VotingBase is IVoting {
// - participants are contributors
// (this automatically enforces also that the address is not 0)
require(
_shareholderRegistry.isAtLeast(_contributorRole, delegator),
getShareholderRegistry().isAtLeast(_contributorRole, delegator),
"Voting: only contributors can delegate."
);
require(
_shareholderRegistry.isAtLeast(_contributorRole, newDelegate),
getShareholderRegistry().isAtLeast(_contributorRole, newDelegate),
"Voting: only contributors can be delegated."
);
// - no sub delegation allowed
Expand Down Expand Up @@ -138,8 +118,8 @@ abstract contract VotingBase is IVoting {

_beforeDelegate(delegator);

uint256 delegatorBalance = _token.balanceOf(delegator) +
_shareholderRegistry.balanceOf(delegator);
uint256 delegatorBalance = getGovernanceToken().balanceOf(delegator) +
getShareholderRegistry().balanceOf(delegator);
_delegates[delegator] = newDelegate;

if (delegator != newDelegate && newDelegate != address(0)) {
Expand Down Expand Up @@ -197,8 +177,9 @@ abstract contract VotingBase is IVoting {

delete _delegates[account];

uint256 individualVotingPower = _token.balanceOf(account) +
_shareholderRegistry.balanceOf(account);
uint256 individualVotingPower = getGovernanceToken().balanceOf(
account
) + getShareholderRegistry().balanceOf(account);
if (individualVotingPower > 0) {
_moveVotingPower(account, address(0), individualVotingPower);
}
Expand Down
Loading

0 comments on commit 06ec9df

Please sign in to comment.