2019-03-11 12:30:45 +00:00
|
|
|
pragma solidity ^0.5.0;
|
2019-03-10 08:38:03 +00:00
|
|
|
|
2019-03-10 11:23:11 +00:00
|
|
|
import "./UserProxy.sol";
|
2019-03-09 20:42:05 +00:00
|
|
|
|
2019-03-11 12:30:45 +00:00
|
|
|
|
2019-03-18 21:14:58 +00:00
|
|
|
// checking if the logic proxy is authorised
|
|
|
|
contract SystemAdmin {
|
|
|
|
|
|
|
|
address public logicProxyAddr;
|
|
|
|
|
|
|
|
modifier isAdmin() {
|
|
|
|
require(msg.sender == getAdmin(), "permission-denied");
|
|
|
|
_;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getAdmin() internal view returns (address) {
|
|
|
|
AddressRegistryInterface registry = AddressRegistryInterface(logicProxyAddr);
|
|
|
|
return registry.getAddress("admin");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
contract ProxyRegistry is SystemAdmin {
|
|
|
|
|
2019-03-09 20:42:05 +00:00
|
|
|
event Created(address indexed sender, address indexed owner, address proxy);
|
2019-03-18 21:14:58 +00:00
|
|
|
|
2019-03-10 08:38:03 +00:00
|
|
|
mapping(address => UserProxy) public proxies;
|
2019-03-18 21:14:58 +00:00
|
|
|
bool public guardianEnabled;
|
2019-03-10 08:38:03 +00:00
|
|
|
|
2019-03-18 21:14:58 +00:00
|
|
|
constructor(address _logicProxyAddr) public {
|
|
|
|
logicProxyAddr = _logicProxyAddr;
|
2019-03-10 08:38:03 +00:00
|
|
|
}
|
2019-03-09 20:42:05 +00:00
|
|
|
|
2019-03-18 21:14:58 +00:00
|
|
|
function build() public returns (UserProxy proxy) {
|
|
|
|
proxy = build(msg.sender);
|
2019-03-09 20:42:05 +00:00
|
|
|
}
|
|
|
|
|
2019-03-11 22:52:48 +00:00
|
|
|
// deploys a new proxy instance and sets custom owner of proxy
|
2019-03-18 21:14:58 +00:00
|
|
|
function build(address owner) public returns (UserProxy proxy) {
|
2019-03-10 11:23:11 +00:00
|
|
|
require(
|
2019-03-18 21:14:58 +00:00
|
|
|
proxies[owner] == UserProxy(0) || proxies[owner].owner() != owner,
|
2019-03-10 11:23:11 +00:00
|
|
|
"multiple-proxy-per-user-not-allowed"
|
|
|
|
); // Not allow new proxy if the user already has one and remains being the owner
|
2019-03-18 21:14:58 +00:00
|
|
|
proxy = new UserProxy(owner, logicProxyAddr);
|
2019-03-09 20:42:05 +00:00
|
|
|
emit Created(msg.sender, owner, address(proxy));
|
|
|
|
proxies[owner] = proxy;
|
|
|
|
}
|
2019-03-18 21:14:58 +00:00
|
|
|
|
|
|
|
// msg.sender should always be proxies created via this contract for successful execution
|
|
|
|
function updateProxyRecord(address currentOwner, address nextOwner) public {
|
|
|
|
require(msg.sender == address(proxies[currentOwner]), "invalid-proxy-or-owner");
|
|
|
|
proxies[nextOwner] = proxies[currentOwner];
|
|
|
|
proxies[currentOwner] = UserProxy(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableGuardian() public isAdmin {
|
|
|
|
guardianEnabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function disableGuardian() public isAdmin {
|
|
|
|
guardianEnabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|