liquid-funding/contracts/LPFactory.sol

64 lines
2.4 KiB
Solidity
Raw Normal View History

2018-02-10 14:14:52 +00:00
pragma solidity ^0.4.18;
import "@aragon/os/contracts/factory/DAOFactory.sol";
import "./LPVault.sol";
import "./LiquidPledging.sol";
2018-03-12 15:51:16 +00:00
import "./LPConstants.sol";
2018-02-10 14:14:52 +00:00
2018-06-16 17:54:30 +00:00
contract LPFactory is LPConstants, DAOFactory(new Kernel(), new ACL(), 0) {
bytes32 public constant RECOVERY_VAULT_ID = keccak256("recoveryVault");
2018-02-10 14:14:52 +00:00
address public vaultBase;
address public lpBase;
event DeployVault(address vault);
event DeployLiquidPledging(address liquidPledging);
2018-06-16 17:54:30 +00:00
function LPFactory(address _vaultBase, address _lpBase) public {
2018-02-10 14:14:52 +00:00
require(_vaultBase != 0);
require(_lpBase != 0);
vaultBase = _vaultBase;
lpBase = _lpBase;
}
2018-03-27 17:55:37 +00:00
function newLP(address _root, address _escapeHatchDestination) external {
2018-02-10 14:14:52 +00:00
Kernel kernel = newDAO(this);
ACL acl = ACL(kernel.acl());
bytes32 appManagerRole = kernel.APP_MANAGER_ROLE();
acl.createPermission(this, address(kernel), appManagerRole, this);
LPVault v = LPVault(kernel.newAppInstance(VAULT_APP_ID, vaultBase));
2018-06-16 00:27:47 +00:00
// deploy & register the lp instance w/ the kernel
LiquidPledging lp = LiquidPledging(kernel.newAppInstance(LP_APP_ID, lpBase, true));
v.initialize(address(lp));
lp.initialize(address(v));
// set the recoveryVault to the escapeHatchDestination
2018-06-16 17:54:30 +00:00
kernel.setRecoveryVaultId(RECOVERY_VAULT_ID);
kernel.setApp(APP_ADDR_NAMESPACE, RECOVERY_VAULT_ID, _escapeHatchDestination);
2018-02-10 14:14:52 +00:00
_setPermissions(_root, acl, kernel, v, lp);
}
function _setPermissions(address _root, ACL acl, Kernel kernel, LPVault v, LiquidPledging lp) internal {
bytes32 appManagerRole = kernel.APP_MANAGER_ROLE();
bytes32 permRole = acl.CREATE_PERMISSIONS_ROLE();
bytes32 hatchCallerRole = v.ESCAPE_HATCH_CALLER_ROLE();
bytes32 pluginManagerRole = lp.PLUGIN_MANAGER_ROLE();
acl.createPermission(_root, address(v), hatchCallerRole, _root);
acl.createPermission(_root, address(lp), pluginManagerRole, _root);
acl.grantPermission(_root, address(kernel), appManagerRole);
acl.grantPermission(_root, address(acl), permRole);
acl.revokePermission(this, address(kernel), appManagerRole);
acl.revokePermission(this, address(acl), permRole);
acl.setPermissionManager(_root, address(kernel), appManagerRole);
acl.setPermissionManager(_root, address(acl), permRole);
DeployVault(address(v));
DeployLiquidPledging(address(lp));
}
}