|
| 1 | +/* |
| 2 | + * SPDX-License-Identitifer: GPL-3.0-or-later |
| 3 | + * |
| 4 | + * This file requires contract dependencies which are licensed as |
| 5 | + * GPL-3.0-or-later, forcing it to also be licensed as such. |
| 6 | + * |
| 7 | + * This is the only file in your project that requires this license and |
| 8 | + * you are free to choose a different license for the rest of the project. |
| 9 | + */ |
| 10 | + |
| 11 | +pragma solidity 0.4.24; |
| 12 | + |
| 13 | +import "@aragon/os/contracts/factory/DAOFactory.sol"; |
| 14 | +import "@aragon/os/contracts/apm/Repo.sol"; |
| 15 | +import "@aragon/os/contracts/lib/ens/ENS.sol"; |
| 16 | +import "@aragon/os/contracts/lib/ens/PublicResolver.sol"; |
| 17 | +import "@aragon/os/contracts/apm/APMNamehash.sol"; |
| 18 | + |
| 19 | +import "@aragon/apps-voting/contracts/Voting.sol"; |
| 20 | +import "@aragon/apps-token-manager/contracts/TokenManager.sol"; |
| 21 | +import "@aragon/apps-shared-minime/contracts/MiniMeToken.sol"; |
| 22 | + |
| 23 | +import "./CounterApp.sol"; |
| 24 | + |
| 25 | + |
| 26 | +contract TemplateBase is APMNamehash { |
| 27 | + ENS public ens; |
| 28 | + DAOFactory public fac; |
| 29 | + |
| 30 | + event DeployInstance(address dao); |
| 31 | + event InstalledApp(address appProxy, bytes32 appId); |
| 32 | + |
| 33 | + constructor(DAOFactory _fac, ENS _ens) public { |
| 34 | + ens = _ens; |
| 35 | + |
| 36 | + // If no factory is passed, get it from on-chain bare-kit |
| 37 | + if (address(_fac) == address(0)) { |
| 38 | + bytes32 bareKit = apmNamehash("bare-kit"); |
| 39 | + fac = TemplateBase(latestVersionAppBase(bareKit)).fac(); |
| 40 | + } else { |
| 41 | + fac = _fac; |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + function latestVersionAppBase(bytes32 appId) public view returns (address base) { |
| 46 | + Repo repo = Repo(PublicResolver(ens.resolver(appId)).addr(appId)); |
| 47 | + (,base,) = repo.getLatest(); |
| 48 | + |
| 49 | + return base; |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | +contract Template is TemplateBase { |
| 55 | + MiniMeTokenFactory tokenFactory; |
| 56 | + |
| 57 | + uint64 constant PCT = 10 ** 16; |
| 58 | + address constant ANY_ENTITY = address(-1); |
| 59 | + |
| 60 | + constructor(ENS ens) TemplateBase(DAOFactory(0), ens) public { |
| 61 | + tokenFactory = new MiniMeTokenFactory(); |
| 62 | + } |
| 63 | + |
| 64 | + function newInstance() public { |
| 65 | + Kernel dao = fac.newDAO(this); |
| 66 | + ACL acl = ACL(dao.acl()); |
| 67 | + acl.createPermission(this, dao, dao.APP_MANAGER_ROLE(), this); |
| 68 | + |
| 69 | + address root = msg.sender; |
| 70 | + bytes32 appId = apmNamehash("home"); |
| 71 | + bytes32 votingAppId = apmNamehash("voting"); |
| 72 | + bytes32 tokenManagerAppId = apmNamehash("token-manager"); |
| 73 | + |
| 74 | + CounterApp app = CounterApp(dao.newAppInstance(appId, latestVersionAppBase(appId))); |
| 75 | + Voting voting = Voting(dao.newAppInstance(votingAppId, latestVersionAppBase(votingAppId))); |
| 76 | + TokenManager tokenManager = TokenManager(dao.newAppInstance(tokenManagerAppId, latestVersionAppBase(tokenManagerAppId))); |
| 77 | + |
| 78 | + MiniMeToken token = tokenFactory.createCloneToken(MiniMeToken(0), 0, "App token", 0, "APP", true); |
| 79 | + token.changeController(tokenManager); |
| 80 | + |
| 81 | + app.initialize(); |
| 82 | + tokenManager.initialize(token, true, 0); |
| 83 | + // Initialize apps |
| 84 | + voting.initialize(token, 50 * PCT, 20 * PCT, 1 days); |
| 85 | + |
| 86 | + acl.createPermission(this, tokenManager, tokenManager.MINT_ROLE(), this); |
| 87 | + tokenManager.mint(root, 1); // Give one token to root |
| 88 | + |
| 89 | + acl.createPermission(ANY_ENTITY, voting, voting.CREATE_VOTES_ROLE(), root); |
| 90 | + |
| 91 | + acl.createPermission(voting, app, app.INCREMENT_ROLE(), voting); |
| 92 | + acl.createPermission(ANY_ENTITY, app, app.DECREMENT_ROLE(), root); |
| 93 | + acl.grantPermission(voting, tokenManager, tokenManager.MINT_ROLE()); |
| 94 | + |
| 95 | + // Clean up permissions |
| 96 | + acl.grantPermission(root, dao, dao.APP_MANAGER_ROLE()); |
| 97 | + acl.revokePermission(this, dao, dao.APP_MANAGER_ROLE()); |
| 98 | + acl.setPermissionManager(root, dao, dao.APP_MANAGER_ROLE()); |
| 99 | + |
| 100 | + acl.grantPermission(root, acl, acl.CREATE_PERMISSIONS_ROLE()); |
| 101 | + acl.revokePermission(this, acl, acl.CREATE_PERMISSIONS_ROLE()); |
| 102 | + acl.setPermissionManager(root, acl, acl.CREATE_PERMISSIONS_ROLE()); |
| 103 | + |
| 104 | + emit DeployInstance(dao); |
| 105 | + } |
| 106 | +} |
0 commit comments