Skip to content

Commit

Permalink
#58
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill authored and Kirill committed Sep 25, 2018
1 parent 118eea6 commit b919c53
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 316 deletions.
14 changes: 7 additions & 7 deletions contracts/0-FineGrainedPermissions/0-FineGrainedPermissions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ contract ExampleOfFineGrainedPerms is DaoClient {
StdDaoToken public tokenReputationDev;

////
constructor(IDaoBase _dao) public DaoClient(_dao){
constructor(IDaoBase _daoBase) public DaoClient(_daoBase){
// 1 - create tokens
tokenGovernance = new StdDaoToken("YourDaoGovToken","GOV",18, true, false, 10**25);
tokenReputation = new StdDaoToken("YourDaoRepToken","REP",18, true, true, 10**25);
tokenReputationDev = new StdDaoToken("YourDaoRepDevToken","REPD",18, true, false, 10**25);

// 2 - transfer ownership to the Dao
tokenGovernance.transferOwnership(dao);
tokenReputation.transferOwnership(dao);
tokenReputationDev.transferOwnership(dao);
tokenGovernance.transferOwnership(daoBase);
tokenReputation.transferOwnership(daoBase);
tokenReputationDev.transferOwnership(daoBase);
}

// ACTIONS:
function issueTokensGovr(address _to, uint _amount) external isCanDo("CUSTOM_issueTokensGovr"){
// you should grant issueTokens permission to THIS contract
dao.issueTokens(tokenGovernance, _to, _amount);
daoBase.issueTokens(tokenGovernance, _to, _amount);
}

function issueTokensRep(address _to, uint _amount) external isCanDo("CUSTOM_issueTokensRep"){
// you should grant issueTokens permission to THIS contract
dao.issueTokens(tokenReputation, _to, _amount);
daoBase.issueTokens(tokenReputation, _to, _amount);
}

function issueTokensRepDev(address _to, uint _amount) external isCanDo("CUSTOM_issueTokensRepDev"){
// you should grant issueTokens permission to THIS contract
dao.issueTokens(tokenReputationDev, _to, _amount);
daoBase.issueTokens(tokenReputationDev, _to, _amount);
}
}
28 changes: 9 additions & 19 deletions contracts/1-HierarchyDao/HierarchyDaoFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ contract HierarchyDaoFactory {
) public {
createDao(_boss, _managers, _employees, _outsiders);
setupHierarchyDaoAuto();
daoBase.renounceOwnership();
}

function createDao(
Expand All @@ -41,15 +42,11 @@ contract HierarchyDaoFactory {
daoBase = new DaoBaseWithUnpackers(store);
hierarcyDao = new HierarchyDao(IDaoBase(daoBase));

store.allowActionByAddress(keccak256("manageGroups"), address(this));
store.allowActionByAddress(daoBase.MANAGE_GROUPS(), address(this));
store.transferOwnership(daoBase);
token.transferOwnership(daoBase);

// 2 - setup
setPermissions(_boss, _managers, _employees);

// 3 - return
daoBase.renounceOwnership();
}

function setPermissions(address _boss, address[] _managers, address[] _employees) internal {
Expand All @@ -58,22 +55,15 @@ contract HierarchyDaoFactory {
daoBase.addGroupMember("Managers", _boss);
daoBase.addGroupMember("Employees", _boss);

daoBase.allowActionByAddress(keccak256("issueTokens"), _boss);
daoBase.allowActionByAddress(keccak256("upgradeDaoContract"), _boss);
daoBase.allowActionByAddress(daoBase.ISSUE_TOKENS(), _boss);
daoBase.allowActionByAddress(daoBase.UPGRADE_DAO_CONTRACT(), _boss);

// 2 - set managers group permission
daoBase.allowActionByAnyMemberOfGroup(keccak256("addNewProposal"), "Managers");
daoBase.allowActionByAnyMemberOfGroup(keccak256("addNewTask"), "Managers");
daoBase.allowActionByAnyMemberOfGroup(keccak256("startTask"), "Managers");
daoBase.allowActionByAnyMemberOfGroup(keccak256("startBounty"), "Managers");

// 3 - set employees group permissions
daoBase.allowActionByAnyMemberOfGroup(keccak256("startTask"), "Employees");
daoBase.allowActionByAnyMemberOfGroup(keccak256("startBounty"), "Employees");
daoBase.allowActionByAnyMemberOfGroup(daoBase.ADD_NEW_PROPOSAL(), "Managers");

// 4 - the rest is by voting only (requires addNewProposal permission)
// so accessable by Managers only even with voting
daoBase.allowActionByVoting(keccak256("manageGroups"), token);
daoBase.allowActionByVoting(daoBase.MANAGE_GROUPS(), token);

// 5 - populate groups
uint i = 0;
Expand All @@ -91,10 +81,10 @@ contract HierarchyDaoFactory {

// set voring params 1 person 1 vote
uint8 VOTING_TYPE_1P1V = 1;
hierarchyDaoAuto.setVotingParams(keccak256("manageGroups"), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("Managers"), bytes32(50), bytes32(50), 0);
hierarchyDaoAuto.setVotingParams(daoBase.MANAGE_GROUPS(), VOTING_TYPE_1P1V, bytes32(0), UtilsLib.stringToBytes32("Managers"), bytes32(50), bytes32(50), 0);

daoBase.allowActionByAddress(keccak256("addNewProposal"), hierarchyDaoAuto);
daoBase.allowActionByAddress(keccak256("manageGroups"), hierarchyDaoAuto);
daoBase.allowActionByAddress(daoBase.ADD_NEW_PROPOSAL(), hierarchyDaoAuto);
daoBase.allowActionByAddress(daoBase.MANAGE_GROUPS(), hierarchyDaoAuto);

hierarchyDaoAuto.transferOwnership(msg.sender);
}
Expand Down
1 change: 1 addition & 0 deletions contracts/3-DevZenDao/DevZenDao.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.4.24;
pragma experimental ABIEncoderV2;

import "@thetta/core/contracts/DaoBase.sol";
import "@thetta/core/contracts/DaoBaseImpersonated.sol";
import "@thetta/core/contracts/IDaoBase.sol";
import "@thetta/core/contracts/tokens/StdDaoToken.sol";

Expand Down
2 changes: 1 addition & 1 deletion contracts/3-DevZenDao/DevZenDaoAuto.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract DevZenDaoAuto is GenericCaller{
event BurnGuestStakeAuto();

DevZenDaoWithUnpackers devZenDao;
constructor(IDaoBase _dao, DevZenDaoWithUnpackers _devZenDao) public GenericCaller(_dao){
constructor(IDaoBase _daoBase, DevZenDaoWithUnpackers _devZenDao) public GenericCaller(_daoBase){
devZenDao = _devZenDao;
}

Expand Down
4 changes: 2 additions & 2 deletions contracts/3-DevZenDao/DevZenDaoAutoTestable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ import "./DevZenDaoWithUnpackersTestable.sol";

contract DevZenDaoAutoTestable is GenericCaller{
DevZenDaoWithUnpackersTestable devZenDao;
constructor(IDaoBase _dao, DevZenDaoWithUnpackersTestable _devZenDao) public GenericCaller(_dao){
constructor(IDaoBase _daoBase, DevZenDaoWithUnpackersTestable _devZenDao) public GenericCaller(_daoBase){
devZenDao = _devZenDao;
}

function updateDaoParamsAuto(bytes32 _param, uint _value) public returns(address proposalOut) {
bytes32[] memory params = new bytes32[](2);
params[0] = _param;
params[1] = bytes32(_value);
return doAction(devZenDao.DEV_ZEN_UPDATE_DAO_PARAMS(), dao, msg.sender, "updateDaoParamsGeneric(bytes32[])", params);
return doAction(devZenDao.DEV_ZEN_UPDATE_DAO_PARAMS(), daoBase, msg.sender, "updateDaoParamsGeneric(bytes32[])", params);
}

function withdrawEtherAuto(address _output) public returns(address proposalOut) {
Expand Down
16 changes: 16 additions & 0 deletions migrations/2_deploy_contracts_libraries.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var migrateLibs = require('../node_modules/@thetta/core/scripts/migrateLibs');

module.exports = function (deployer, network, accounts) {
let additionalContracts = [ "./BodDaoFactory"
, "./DevZenDaoAuto"
, "./DevZenDaoAutoTestable"
, "./DevZenDaoFactory"
, "./DevZenDaoFactoryTestable"
, "./DevZenDaoTestable"
, "./DevZenDaoWithUnpackers"
, "./DevZenDaoWithUnpackersTestable"
, "./HierarchyDaoFactory"
]

return migrateLibs(artifacts, additionalContracts, deployer, network, accounts);
};
38 changes: 0 additions & 38 deletions migrations/2_deploy_contracts_utilsLib.js

This file was deleted.

37 changes: 0 additions & 37 deletions migrations/3_deploy_contracts_votingLib.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,14 @@ var DevZenDao = artifacts.require("DevZenDao");
var DevZenDaoAuto = artifacts.require("DevZenDaoAuto");
var DevZenDaoCore = artifacts.require("DevZenDaoCore");
var DevZenDaoWithUnpackers = artifacts.require("DevZenDaoWithUnpackers");
var utf8 = require('utf8');
const { uintToBytes32, padToBytes, fromUtf8 } = require("../test/utils/helpers");

function uintToBytes32(n) {
n = Number(n).toString(16);
while (n.length < 64) {
n = "0" + n;
}
return "0x" + n;
}

function padToBytes32(n, dir='right', withPrefix=true) {
n = n.replace('0x', '');
while (n.length < 64) {
if(dir == 'right') n = n + "0";
if(dir == 'left') n = "0" + n;
}
return withPrefix ? "0x" + n : n;
}

function fromUtf8(str) {
str = utf8.encode(str);
var hex = "";
for (var i = 0; i < str.length; i++) {
var code = str.charCodeAt(i);
if (code === 0) {
break;
}
var n = code.toString(16);
hex += n.length < 2 ? '0' + n : n;
}

return padToBytes32(hex);
};
let emp1 = '0xfac20ad5f3bfc1748235edf919d473272ca0fd55';
let emp2 = '0x38ed1a11e4f2fd85995a058e1f65d41a483a662a';
let emp3 = '0x92bc71cd9a9a6ad3a1dcacc2b8c9eab13f4d547e';

module.exports = function(deployer, network, accounts) {
return deployer.then(async () => {
/*
return deployer.then(async () => {
let devZenToken = await StdDaoToken.new("DevZenToken", "DZT", 18, true, true, 100000000000000000000);
let repToken = await StdDaoToken.new("DevZenRepToken", "DZTREP", 18, true, true, 100000000000000000000);
let store = await DaoStorage.new([devZenToken.address, repToken.address]);
Expand All @@ -59,6 +30,9 @@ module.exports = function(deployer, network, accounts) {

// await await 2 - setup
await store.addGroupMember(web3.sha3("DevZenTeam"), accounts[0]);
await store.addGroupMember(web3.sha3("DevZenTeam"), emp1);
await store.addGroupMember(web3.sha3("DevZenTeam"), emp2);
await store.addGroupMember(web3.sha3("DevZenTeam"), emp3);

await store.transferOwnership(daoBase.address);
await devZenDao.setParam(await devZenDao.MINT_TOKENS_PER_WEEK_AMOUNT(), 10 * 1e18);
Expand Down Expand Up @@ -116,6 +90,5 @@ module.exports = function(deployer, network, accounts) {
await devZenDaoAuto.transferOwnership(daoBase.address);

await daoBase.renounceOwnership();
*/
});
};
54 changes: 54 additions & 0 deletions migrations/4_deploy_HierarchyDao.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
var StdDaoToken = artifacts.require("StdDaoToken");
var DaoStorage = artifacts.require("DaoStorage");
var DaoBase = artifacts.require("DaoBase");
var IDaoBase = artifacts.require("IDaoBase");
var DaoBaseAuto = artifacts.require("DaoBaseAuto");
var HierarchyDao = artifacts.require("HierarchyDao");
const { uintToBytes32, padToBytes, fromUtf8 } = require("../test/utils/helpers");

let mng1 = '0x5a2203e516d8f025eaa37d1f6d7f114ac654da05';
let mng2 = '0x9dc108ae0579a1c856b8eff862fcab76c6e6ee15';
let mng3 = '0x564dcf23922de39970b2b442b1a2de8d2fd25330';
let emp1 = '0xfac20ad5f3bfc1748235edf919d473272ca0fd55';
let emp2 = '0x38ed1a11e4f2fd85995a058e1f65d41a483a662a';
let emp3 = '0x92bc71cd9a9a6ad3a1dcacc2b8c9eab13f4d547e';

module.exports = function(deployer, network, accounts) {
return deployer.then(async () => {
let token = await StdDaoToken.new("StdToken", "STD", 18, true, true, 100000000000000000000);
let store = await DaoStorage.new([token.address]);
let daoBase = await DaoBase.new(store.address);
let hierarcyDao = await HierarchyDao.new(daoBase.address);

await store.allowActionByAddress(await daoBase.MANAGE_GROUPS(), accounts[0]);
await store.transferOwnership(daoBase.address);
await token.transferOwnership(daoBase.address);

await daoBase.addGroupMember("Managers", accounts[0]);
await daoBase.addGroupMember("Employees", accounts[0]);

await daoBase.allowActionByAddress(await daoBase.ISSUE_TOKENS(), accounts[0]);
await daoBase.allowActionByAddress(await daoBase.UPGRADE_DAO_CONTRACT(), accounts[0]);
await daoBase.allowActionByAnyMemberOfGroup(await daoBase.ADD_NEW_PROPOSAL(), "Managers");
await daoBase.allowActionByVoting(await daoBase.MANAGE_GROUPS(), token.address);

await daoBase.addGroupMember("Managers", mng1);
await daoBase.addGroupMember("Managers", mng2);
await daoBase.addGroupMember("Managers", mng3);
await daoBase.addGroupMember("Employees", emp1);
await daoBase.addGroupMember("Employees", emp2);
await daoBase.addGroupMember("Employees", emp3);

let hierarchyDaoAuto = await DaoBaseAuto.new(daoBase.address);

// set voring params 1 person 1 vote
let VOTING_TYPE_1P1V = 1;
await hierarchyDaoAuto.setVotingParams(await daoBase.MANAGE_GROUPS(), VOTING_TYPE_1P1V, uintToBytes32(0), fromUtf8("Managers"), uintToBytes32(50), uintToBytes32(50), 0);

await daoBase.allowActionByAddress(await daoBase.ADD_NEW_PROPOSAL(), hierarchyDaoAuto.address);
await daoBase.allowActionByAddress(await daoBase.MANAGE_GROUPS(), hierarchyDaoAuto.address);

await hierarchyDaoAuto.transferOwnership(daoBase.address);
await daoBase.renounceOwnership();
});
};
32 changes: 0 additions & 32 deletions migrations/4_deploy_contracts_genericCallerLib.js

This file was deleted.

Loading

0 comments on commit b919c53

Please sign in to comment.