mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
merged logic and address registry.
This commit is contained in:
parent
3e8147a26d
commit
dc02040871
68
contracts/AddressRegistry.sol
Normal file
68
contracts/AddressRegistry.sol
Normal file
|
@ -0,0 +1,68 @@
|
|||
pragma solidity ^0.5.0;
|
||||
|
||||
|
||||
contract AddressRegistry {
|
||||
|
||||
event AddressSet(string name, address addr);
|
||||
mapping(bytes32 => address) registry;
|
||||
|
||||
constructor() public {
|
||||
registry[keccak256(abi.encodePacked("admin"))] = msg.sender;
|
||||
registry[keccak256(abi.encodePacked("owner"))] = msg.sender;
|
||||
}
|
||||
|
||||
function getAddress(string memory name) public view returns(address) {
|
||||
return registry[keccak256(abi.encodePacked(name))];
|
||||
}
|
||||
|
||||
function setAddress(string memory name, address addr) public {
|
||||
require(
|
||||
msg.sender == getAddress("admin") ||
|
||||
msg.sender == getAddress("owner"),
|
||||
"Permission Denied"
|
||||
);
|
||||
registry[keccak256(abi.encodePacked(name))] = addr;
|
||||
emit AddressSet(name, addr);
|
||||
}
|
||||
|
||||
modifier isAdmin() {
|
||||
require(
|
||||
msg.sender == getAddress("admin"),
|
||||
"Permission Denied"
|
||||
);
|
||||
_;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
contract LogicRegistry is AddressRegistry {
|
||||
event DefaultLogicSet(address logicAddr);
|
||||
event LogicSet(address logicAddr, bool isLogic);
|
||||
|
||||
mapping(address => bool) public defaultLogicProxies;
|
||||
mapping(address => bool) public logicProxies;
|
||||
|
||||
function getLogic(address logicAddr) public view returns (bool) {
|
||||
if (defaultLogicProxies[logicAddr]) {
|
||||
return true;
|
||||
} else if (logicProxies[logicAddr]) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function setLogic(address logicAddr, bool isLogic) public isAdmin {
|
||||
require(msg.sender == getAddress("admin"), "Permission Denied");
|
||||
logicProxies[logicAddr] = true;
|
||||
emit LogicSet(logicAddr, isLogic);
|
||||
}
|
||||
|
||||
function setDefaultLogic(address logicAddr) public isAdmin {
|
||||
require(msg.sender == getAddress("admin"), "Permission Denied");
|
||||
defaultLogicProxies[logicAddr] = true;
|
||||
emit DefaultLogicSet(logicAddr);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
pragma solidity ^0.5.0;
|
||||
|
||||
interface AddrRegistry {
|
||||
function getAddr(string calldata) external view returns (address);
|
||||
}
|
||||
|
||||
|
||||
contract AddressRegistry {
|
||||
address public registry;
|
||||
|
||||
modifier onlyAdmin() {
|
||||
require(msg.sender == getAddress("admin"), "Permission Denied");
|
||||
_;
|
||||
}
|
||||
|
||||
function getAddress(string memory name) internal view returns (address) {
|
||||
AddrRegistry addrReg = AddrRegistry(registry);
|
||||
return addrReg.getAddr(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
contract LogicRegistry is AddressRegistry {
|
||||
event DefaultLogicSet(address logicAddr);
|
||||
event LogicSet(address logicAddr, bool isLogic);
|
||||
|
||||
mapping(address => bool) public defaultLogicProxies;
|
||||
mapping(address => bool) public logicProxies;
|
||||
|
||||
constructor(address registry_) public {
|
||||
registry = registry_;
|
||||
}
|
||||
|
||||
function getLogic(address logicAddr) public view returns (bool) {
|
||||
if (defaultLogicProxies[logicAddr]) {
|
||||
return true;
|
||||
} else if (logicProxies[logicAddr]) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function setLogic(address logicAddr, bool isLogic) public onlyAdmin {
|
||||
require(msg.sender == getAddress("admin"), "Permission Denied");
|
||||
logicProxies[logicAddr] = true;
|
||||
emit LogicSet(logicAddr, isLogic);
|
||||
}
|
||||
|
||||
function setDefaultLogic(address logicAddr) public onlyAdmin {
|
||||
require(msg.sender == getAddress("admin"), "Permission Denied");
|
||||
defaultLogicProxies[logicAddr] = true;
|
||||
emit DefaultLogicSet(logicAddr);
|
||||
}
|
||||
|
||||
}
|
|
@ -12,14 +12,11 @@ contract ProxyRegistry {
|
|||
logicProxyAddr = logicProxyAddr_;
|
||||
}
|
||||
|
||||
// deploys a new proxy instance
|
||||
// sets owner of proxy to caller
|
||||
function build(uint activeDays) public returns (UserProxy proxy) {
|
||||
proxy = build(msg.sender, activeDays);
|
||||
}
|
||||
|
||||
// deploys a new proxy instance
|
||||
// sets custom owner of proxy
|
||||
// deploys a new proxy instance and sets custom owner of proxy
|
||||
function build(address owner, uint activeDays) public returns (UserProxy proxy) {
|
||||
require(
|
||||
proxies[owner] == UserProxy(0) || proxies[owner].owner() != owner,
|
||||
|
|
|
@ -93,7 +93,7 @@ contract UserNote {
|
|||
}
|
||||
|
||||
|
||||
interface LogicRegistry {
|
||||
interface AddressRegistry {
|
||||
function getLogic(address logicAddr) external view returns (bool);
|
||||
}
|
||||
|
||||
|
@ -101,8 +101,8 @@ interface LogicRegistry {
|
|||
// checking if the logic proxy is authorised
|
||||
contract UserLogic {
|
||||
address public logicProxyAddr;
|
||||
function isAuthorisedLogic(address logicAddr) internal view returns (bool) {
|
||||
LogicRegistry logicProxy = LogicRegistry(logicProxyAddr);
|
||||
function isLogicAuthorised(address logicAddr) internal view returns (bool) {
|
||||
AddressRegistry logicProxy = AddressRegistry(logicProxyAddr);
|
||||
return logicProxy.getLogic(logicAddr);
|
||||
}
|
||||
}
|
||||
|
@ -110,17 +110,17 @@ contract UserLogic {
|
|||
|
||||
|
||||
contract UserProxy is UserAuth, UserNote, UserLogic {
|
||||
constructor(address logicProxyAddr_, uint activePeriod_) public {
|
||||
logicProxyAddr = logicProxyAddr_;
|
||||
constructor(address _logicProxyAddr, uint _activePeriod) public {
|
||||
logicProxyAddr = _logicProxyAddr;
|
||||
lastActivity = block.timestamp;
|
||||
activePeriod = activePeriod_;
|
||||
activePeriod = _activePeriod;
|
||||
}
|
||||
|
||||
function() external payable {}
|
||||
|
||||
function execute(address _target, bytes memory _data) public payable auth note returns (bytes memory response) {
|
||||
require(_target != address(0), "user-proxy-target-address-required");
|
||||
require(isAuthorisedLogic(_target), "logic-proxy-address-not-allowed");
|
||||
require(isLogicAuthorised(_target), "logic-proxy-address-not-allowed");
|
||||
lastActivity = block.timestamp;
|
||||
// call contract in current context
|
||||
assembly {
|
||||
|
|
Loading…
Reference in New Issue
Block a user