mirror of
https://github.com/Instadapp/InstaContract.git
synced 2024-07-29 22:47:45 +00:00
92 lines
2.6 KiB
Solidity
92 lines
2.6 KiB
Solidity
// addresses name - address, asset, resolver, moatkyber, moatmaker, admin
|
|
|
|
pragma solidity ^0.4.24;
|
|
|
|
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
|
|
|
|
|
|
contract AddressRegistry {
|
|
|
|
event AddressChanged(string name, address addr);
|
|
event ResolverApproved(address user, address addr);
|
|
event ResolverDisapproved(address user, address addr);
|
|
|
|
// Addresses managing the protocol governance
|
|
mapping(address => bool) public governors;
|
|
|
|
// Address registry of connected smart contracts
|
|
mapping(bytes32 => address) public registry;
|
|
|
|
// Contract addresses having rights to perform tasks, approved by users
|
|
// Resolver Contract >> User >> Approved
|
|
mapping(address => mapping(address => bool)) public resolvers;
|
|
|
|
}
|
|
|
|
|
|
contract ManageRegistry is AddressRegistry {
|
|
|
|
using SafeMath for uint;
|
|
using SafeMath for uint256;
|
|
|
|
address public pendingAdmin;
|
|
uint public pendingTime;
|
|
|
|
function setPendingAdmin() public {
|
|
require(block.timestamp > pendingTime, "Pending!");
|
|
registry[keccak256("admin")] = pendingAdmin;
|
|
}
|
|
|
|
function setAddr(string name, address newAddr) public {
|
|
if (keccak256(abi.encodePacked(name)) != keccak256(abi.encodePacked("admin"))) {
|
|
require(
|
|
governors[msg.sender],
|
|
"Permission Denied"
|
|
);
|
|
pendingAdmin = newAddr;
|
|
pendingTime = block.timestamp.add(24 * 60 * 60); // adding 24 hours
|
|
} else {
|
|
require(
|
|
msg.sender == getAddr("admin"),
|
|
"Permission Denied"
|
|
);
|
|
registry[keccak256(abi.encodePacked(name))] = newAddr;
|
|
emit AddressChanged(name, newAddr);
|
|
}
|
|
}
|
|
|
|
function getAddr(string name) public view returns(address addr) {
|
|
addr = registry[keccak256(abi.encodePacked(name))];
|
|
require(addr != address(0), "Not a valid address.");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
contract ManageResolvers is ManageRegistry {
|
|
|
|
function approveResolver() public {
|
|
resolvers[getAddr("resolver")][msg.sender] = true;
|
|
emit ResolverApproved(msg.sender, getAddr("resolver"));
|
|
}
|
|
|
|
function disapproveResolver() public {
|
|
resolvers[getAddr("resolver")][msg.sender] = false;
|
|
emit ResolverDisapproved(msg.sender, getAddr("resolver"));
|
|
}
|
|
|
|
function isApprovedResolver(address user) public view returns(bool) {
|
|
return resolvers[getAddr("resolver")][user];
|
|
}
|
|
|
|
}
|
|
|
|
|
|
contract InitRegistry is ManageResolvers {
|
|
|
|
constructor() public {
|
|
registry[keccak256(abi.encodePacked("admin"))] = msg.sender;
|
|
}
|
|
|
|
}
|