This repository has been archived by the owner on Mar 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathKit.sol
93 lines (70 loc) · 3.13 KB
/
Kit.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
pragma solidity 0.4.18;
import "@aragon/os/contracts/factory/DAOFactory.sol";
import "@aragon/os/contracts/apm/Repo.sol";
import "@aragon/os/contracts/lib/ens/ENS.sol";
import "@aragon/os/contracts/lib/ens/PublicResolver.sol";
import "@aragon/os/contracts/apm/APMNamehash.sol";
import "@aragon/apps-voting/contracts/Voting.sol";
import "@aragon/apps-token-manager/contracts/TokenManager.sol";
import "@aragon/os/contracts/lib/minime/MiniMeToken.sol";
import "./CounterApp.sol";
contract KitBase is APMNamehash {
ENS public ens;
DAOFactory public fac;
event DeployInstance(address dao);
event InstalledApp(address appProxy, bytes32 appId);
function KitBase(DAOFactory _fac, ENS _ens) {
ens = _ens;
// If no factory is passed, get it from on-chain bare-kit
if (address(_fac) == address(0)) {
bytes32 bareKit = apmNamehash("bare-kit");
fac = KitBase(latestVersionAppBase(bareKit)).fac();
} else {
fac = _fac;
}
}
function latestVersionAppBase(bytes32 appId) public view returns (address base) {
Repo repo = Repo(PublicResolver(ens.resolver(appId)).addr(appId));
(,base,) = repo.getLatest();
return base;
}
}
contract Kit is KitBase {
MiniMeTokenFactory tokenFactory;
uint256 constant PCT = 10 ** 16;
address constant ANY_ENTITY = address(-1);
function Kit(ENS ens) KitBase(DAOFactory(0), ens) {
tokenFactory = new MiniMeTokenFactory();
}
function newInstance() {
Kernel dao = fac.newDAO(this);
ACL acl = ACL(dao.acl());
acl.createPermission(this, dao, dao.APP_MANAGER_ROLE(), this);
address root = msg.sender;
bytes32 appId = apmNamehash("app");
bytes32 votingAppId = apmNamehash("voting");
bytes32 tokenManagerAppId = apmNamehash("token-manager");
CounterApp app = CounterApp(dao.newAppInstance(appId, latestVersionAppBase(appId)));
Voting voting = Voting(dao.newAppInstance(votingAppId, latestVersionAppBase(votingAppId)));
TokenManager tokenManager = TokenManager(dao.newAppInstance(tokenManagerAppId, latestVersionAppBase(tokenManagerAppId)));
MiniMeToken token = tokenFactory.createCloneToken(address(0), 0, "App token", 0, "APP", true);
token.changeController(tokenManager);
tokenManager.initialize(token, true, 0, true);
// Initialize apps
voting.initialize(token, 50 * PCT, 20 * PCT, 1 days);
acl.createPermission(this, tokenManager, tokenManager.MINT_ROLE(), this);
tokenManager.mint(root, 1); // Give one token to root
acl.createPermission(ANY_ENTITY, voting, voting.CREATE_VOTES_ROLE(), root);
acl.createPermission(voting, app, app.INCREMENT_ROLE(), voting);
acl.createPermission(ANY_ENTITY, app, app.DECREMENT_ROLE(), root);
acl.grantPermission(voting, tokenManager, tokenManager.MINT_ROLE());
// Clean up permissions
acl.grantPermission(root, dao, dao.APP_MANAGER_ROLE());
acl.revokePermission(this, dao, dao.APP_MANAGER_ROLE());
acl.setPermissionManager(root, dao, dao.APP_MANAGER_ROLE());
acl.grantPermission(root, acl, acl.CREATE_PERMISSIONS_ROLE());
acl.revokePermission(this, acl, acl.CREATE_PERMISSIONS_ROLE());
acl.setPermissionManager(root, acl, acl.CREATE_PERMISSIONS_ROLE());
DeployInstance(dao);
}
}