Skip to content

Commit

Permalink
Merge branch 'dev2' into dev2RostyslavLiquidDemocracy.sol
Browse files Browse the repository at this point in the history
  • Loading branch information
RostyslavBortman committed Jul 17, 2018
2 parents 470c584 + f9136d4 commit 370821a
Show file tree
Hide file tree
Showing 18 changed files with 780 additions and 419 deletions.
54 changes: 21 additions & 33 deletions contracts/DaoBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,16 @@ contract DaoBase is IDaoBase, Ownable {
}

modifier isCanDo(bytes32 _what){
require(_isCanDoAction(msg.sender,_what));
require(isCanDoAction(msg.sender,_what));
_;
}

// IDaoBase:
function addObserver(IDaoObserver _observer) external {
function addObserver(IDaoObserver _observer) public {
store.addObserver(_observer);
}

function upgradeDaoContract(IDaoBase _new) external isCanDo(UPGRADE_DAO_CONTRACT) {
_upgradeDaoContract(_new);
}

function _upgradeDaoContract(IDaoBase _new) internal{
function upgradeDaoContract(IDaoBase _new) public isCanDo(UPGRADE_DAO_CONTRACT) {
emit DaoBase_UpgradeDaoContract(_new);
// call observers.onUpgrade() for all observers
for(uint i=0; i<store.getObserverCount(); ++i){
Expand All @@ -85,41 +81,41 @@ contract DaoBase is IDaoBase, Ownable {
}

// Groups:
function getMembersCount(string _groupName) external constant returns(uint){
function getMembersCount(string _groupName) public constant returns(uint){
return store.getMembersCount(keccak256(abi.encodePacked(_groupName)));
}
function addGroupMember(string _groupName, address _a) external isCanDo(MANAGE_GROUPS) {
function addGroupMember(string _groupName, address _a) public isCanDo(MANAGE_GROUPS) {
emit DaoBase_AddGroupMember(_groupName, _a);
store.addGroupMember(keccak256(abi.encodePacked(_groupName)), _a);
}
function getGroupMembers(string _groupName) external constant returns(address[]){
function getGroupMembers(string _groupName) public constant returns(address[]){
return store.getGroupMembers(keccak256(abi.encodePacked(_groupName)));
}
function removeGroupMember(string _groupName, address _a) external isCanDo(MANAGE_GROUPS){
function removeGroupMember(string _groupName, address _a) public isCanDo(MANAGE_GROUPS){
emit DaoBase_RemoveGroupMember(_a);
store.removeGroupMember(keccak256(abi.encodePacked(_groupName)), _a);
}
function isGroupMember(string _groupName,address _a)external constant returns(bool) {
function isGroupMember(string _groupName,address _a)public constant returns(bool) {
return store.isGroupMember(keccak256(abi.encodePacked(_groupName)), _a);
}
function getMemberByIndex(string _groupName, uint _index) external view returns (address) {
function getMemberByIndex(string _groupName, uint _index) public view returns (address) {
return store.getMemberByIndex(keccak256(abi.encodePacked(_groupName)), _index);
}

// Actions:
function allowActionByShareholder(bytes32 _what, address _tokenAddress) external isCanDo(MANAGE_GROUPS){
function allowActionByShareholder(bytes32 _what, address _tokenAddress) public isCanDo(MANAGE_GROUPS){
emit DaoBase_AllowActionByShareholder(_what, _tokenAddress);
store.allowActionByShareholder(_what, _tokenAddress);
}
function allowActionByVoting(bytes32 _what, address _tokenAddress) external isCanDo(MANAGE_GROUPS){
function allowActionByVoting(bytes32 _what, address _tokenAddress) public isCanDo(MANAGE_GROUPS){
emit DaoBase_AllowActionByVoting(_what, _tokenAddress);
store.allowActionByVoting(_what,_tokenAddress);
}
function allowActionByAddress(bytes32 _what, address _a) external isCanDo(MANAGE_GROUPS) {
function allowActionByAddress(bytes32 _what, address _a) public isCanDo(MANAGE_GROUPS) {
emit DaoBase_AllowActionByAddress(_what, _a);
store.allowActionByAddress(_what,_a);
}
function allowActionByAnyMemberOfGroup(bytes32 _what, string _groupName) external isCanDo(MANAGE_GROUPS){
function allowActionByAnyMemberOfGroup(bytes32 _what, string _groupName) public isCanDo(MANAGE_GROUPS){
emit DaoBase_AllowActionByAnyMemberOfGroup(_what, _groupName);
store.allowActionByAnyMemberOfGroup(_what, keccak256(abi.encodePacked(_groupName)));
}
Expand All @@ -135,11 +131,7 @@ contract DaoBase is IDaoBase, Ownable {
* b. caller is voting and it is succeeded -> allow
* 4. deny
*/
function isCanDoAction(address _a, bytes32 _permissionNameHash) external constant returns(bool){
return _isCanDoAction(_a, _permissionNameHash);
}

function _isCanDoAction(address _a, bytes32 _permissionNameHash) internal constant returns(bool){
function isCanDoAction(address _a, bytes32 _permissionNameHash) public constant returns(bool){
// 0 - is can do by address?
if(store.isCanDoByAddress(_permissionNameHash, _a)){
return true;
Expand Down Expand Up @@ -188,25 +180,21 @@ contract DaoBase is IDaoBase, Ownable {
}

// Proposals:
function addNewProposal(IProposal _proposal) external isCanDo(ADD_NEW_PROPOSAL) {
function addNewProposal(IProposal _proposal) public isCanDo(ADD_NEW_PROPOSAL) {
emit DaoBase_AddNewProposal(address(_proposal));
store.addNewProposal(_proposal);
}

function getProposalAtIndex(uint _i)external constant returns(IProposal){
function getProposalAtIndex(uint _i)public constant returns(IProposal){
return store.getProposalAtIndex(_i);
}

function getProposalsCount()external constant returns(uint){
function getProposalsCount()public constant returns(uint){
return store.getProposalsCount();
}

// Tokens:
function issueTokens(address _tokenAddress, address _to, uint _amount)external isCanDo(ISSUE_TOKENS) {
_issueTokens(_tokenAddress,_to,_amount);
}

function _issueTokens(address _tokenAddress, address _to, uint _amount)internal{
function issueTokens(address _tokenAddress, address _to, uint _amount)public isCanDo(ISSUE_TOKENS) {
emit DaoBase_IssueTokens(_tokenAddress, _to, _amount);
for(uint i=0; i<store.getAllTokenAddresses().length; ++i){
if(store.getAllTokenAddresses()[i]==_tokenAddress){
Expand All @@ -221,7 +209,7 @@ contract DaoBase is IDaoBase, Ownable {
revert();
}

function burnTokens(address _tokenAddress, address _who, uint _amount)external isCanDo(BURN_TOKENS){
function burnTokens(address _tokenAddress, address _who, uint _amount)public isCanDo(BURN_TOKENS){
emit DaoBase_BurnTokens(_tokenAddress, _who, _amount);

for(uint i=0; i<store.getAllTokenAddresses().length; ++i){
Expand Down Expand Up @@ -254,7 +242,7 @@ contract DaoBaseWithUnpackers is DaoBase {

function upgradeDaoContractGeneric(bytes32[] _params) external {
IDaoBase _b = IDaoBase(address(_params[0]));
_upgradeDaoContract(_b);
upgradeDaoContract(_b);
}

function addGroupMemberGeneric(bytes32[] _params) external {
Expand All @@ -270,7 +258,7 @@ contract DaoBaseWithUnpackers is DaoBase {
address _to = address(_params[1]);
uint _amount = uint(_params[2]);

_issueTokens(_tokenAddress, _to, _amount);
issueTokens(_tokenAddress, _to, _amount);
}

// TODO: add other methods:
Expand Down
42 changes: 21 additions & 21 deletions contracts/IDaoBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,44 @@ import './governance/IProposal.sol';
* @title IDaoObserver, can be called IDaoClient really.
* @dev Also, see DaoClient contract below.
*/
interface IDaoObserver {
function onUpgrade(address _newAddress) external;
contract IDaoObserver {
function onUpgrade(address _newAddress) public;
}

/**
* @title This is the base interface that you should use.
* @dev Derive your DAO from it and provide the method implementation or
* see DaoBase contract that implements it.
*/
interface IDaoBase {
function addObserver(IDaoObserver _observer)external;
function upgradeDaoContract(IDaoBase _new)external;
contract IDaoBase {
function addObserver(IDaoObserver _observer)public;
function upgradeDaoContract(IDaoBase _new)public;

// Groups
function addGroupMember(string _groupName, address _a) external;
function removeGroupMember(string _groupName, address _a) external;
function getMembersCount(string _groupName) external constant returns(uint);
function isGroupMember(string _groupName,address _a)external constant returns(bool);
function getMemberByIndex(string _groupName, uint _index) external view returns (address);
function addGroupMember(string _groupName, address _a) public;
function removeGroupMember(string _groupName, address _a) public;
function getMembersCount(string _groupName) public constant returns(uint);
function isGroupMember(string _groupName,address _a)public constant returns(bool);
function getMemberByIndex(string _groupName, uint _index) public view returns (address);

// Permissions
function allowActionByShareholder(bytes32 _what, address _tokenAddress) external;
function allowActionByVoting(bytes32 _what, address _tokenAddress) external;
function allowActionByAddress(bytes32 _what, address _a) external;
function allowActionByAnyMemberOfGroup(bytes32 _what, string _groupName) external;
function allowActionByShareholder(bytes32 _what, address _tokenAddress) public;
function allowActionByVoting(bytes32 _what, address _tokenAddress) public;
function allowActionByAddress(bytes32 _what, address _a) public;
function allowActionByAnyMemberOfGroup(bytes32 _what, string _groupName) public;

function isCanDoAction(address _a, bytes32 _permissionName)external constant returns(bool);
function isCanDoAction(address _a, bytes32 _permissionName)public constant returns(bool);

// Tokens
// ???? TODO: needed
//function addTokenAddressToList();
function issueTokens(address _tokenAddress, address _to, uint amount)external;
function burnTokens(address _tokenAddress, address _who, uint amount)external;
function issueTokens(address _tokenAddress, address _to, uint amount)public;
function burnTokens(address _tokenAddress, address _who, uint amount)public;

// Governance/Proposals
function addNewProposal(IProposal _proposal) external;
function getProposalAtIndex(uint _i)external constant returns(IProposal);
function getProposalsCount()external constant returns(uint);
function addNewProposal(IProposal _proposal) public;
function getProposalAtIndex(uint _i)public constant returns(IProposal);
function getProposalsCount()public constant returns(uint);
}

/**
Expand Down Expand Up @@ -72,7 +72,7 @@ contract DaoClient is IDaoObserver {
* dao will point at NEW contract!
* @param _newAddress New controller.
*/
function onUpgrade(address _newAddress) external {
function onUpgrade(address _newAddress) public {
require(msg.sender==address(dao));

dao = IDaoBase(_newAddress);
Expand Down
6 changes: 3 additions & 3 deletions contracts/governance/IProposal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import '../IDaoBase.sol';
* @dev This is the basic DAO Proposal interface. Each Proposal should have voting attached.
* Proposal can do some action if voting is finished with 'yes' result. Or action can be empty.
*/
interface IProposal {
function action()external;
function getVoting()external view returns(IVoting voting);
contract IProposal {
function action()public;
function getVoting()public view returns(IVoting voting);

// ???
// function isOpen() public constant returns(bool);
Expand Down
15 changes: 8 additions & 7 deletions contracts/governance/IVoting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ pragma solidity ^0.4.22;
* The result is binary (yes or no only)
* Any algorightm inside (1p1v, linear, quadratic, etc)
*/
interface IVoting {
contract IVoting {
// _tokenAmount -> if this voting type DOES NOT use tokens -> set to any value (e.g., 0);
// will execute action automatically if the voting is finished
function vote(bool _yes, uint _tokenAmount) external;
function vote(bool _yes, uint _tokenAmount) public;

// stop the voting
function cancelVoting() external;
function cancelVoting() public;

// This is for statistics
// Can get this stats if voting is finished.
// Can get this stats if voting is NOT finished.
function getVotingStats() external view returns(uint yesResults, uint noResults, uint totalResults);
function getVotingStats() public view returns(uint yesResults, uint noResults, uint totalResults);

// Is voting finished?
//
Expand All @@ -29,7 +29,7 @@ interface IVoting {
// When isFinished():
// 1 - i can not vote any more
// 2 - i can get results with isYes()
function isFinished()external view returns(bool);
function isFinished()public view returns(bool);

// The result of voting
//
Expand All @@ -38,12 +38,13 @@ interface IVoting {
// 2 - all these conditions should be met:
// 2.1 - isFinished()
// 2.2 - is quorum reached
function isYes()external view returns(bool);
function isYes()public view returns(bool);
}

// for "liquid democracy"
// in this case the delegate does all voting
interface IDelegationTable {

contract IDelegationTable {
function delegateMyVoiceTo(address _to, uint _tokenAmount) public;
function removeDelegation(address _to) public;
}
Expand Down
14 changes: 7 additions & 7 deletions contracts/governance/Proposals.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ contract GenericProposal is IProposal, Ownable {
event GenericProposal_Action(IVoting _voting);

// IVoting implementation
function action() external {
function action() public {
emit GenericProposal_Action(voting);

// in some cases voting is still not set
Expand All @@ -48,15 +48,15 @@ contract GenericProposal is IProposal, Ownable {
uint256(params.length), // length of the array
params)
){
revert();
//revert();
}
}

function setVoting(IVoting _voting) external onlyOwner{
function setVoting(IVoting _voting) public onlyOwner{
voting = _voting;
}

function getVoting()external view returns(IVoting){
function getVoting() public view returns(IVoting){
return voting;
}
}
Expand All @@ -76,16 +76,16 @@ contract InformalProposal is IProposal, Ownable {
proposalText = _proposalText;
}

function getProposalText()external view returns(string){
function getProposalText() public view returns(string){
return proposalText;
}

// IVoting implementation
function setVoting(IVoting _voting) external onlyOwner{
function setVoting(IVoting _voting) public onlyOwner{
voting = _voting;
}

function getVoting()external view returns(IVoting){
function getVoting() public view returns(IVoting){
return voting;
}

Expand Down

0 comments on commit 370821a

Please sign in to comment.