mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
Merged all the registries.
This commit is contained in:
parent
8350d1f74c
commit
04eb343142
|
@ -1,82 +0,0 @@
|
|||
pragma solidity ^0.5.0;
|
||||
|
||||
import "./UserProxy.sol";
|
||||
|
||||
|
||||
// checking if the logic proxy is authorised
|
||||
contract SystemAdmin {
|
||||
|
||||
address public addrRegistry;
|
||||
|
||||
modifier isAdmin() {
|
||||
require(msg.sender == getAdmin(), "permission-denied");
|
||||
_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev get the system admin
|
||||
*/
|
||||
function getAdmin() internal view returns (address) {
|
||||
AddressRegistryInterface registry = AddressRegistryInterface(addrRegistry);
|
||||
return registry.getAddress("admin");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
contract ProxyRegistry is SystemAdmin {
|
||||
|
||||
event Created(address indexed sender, address indexed owner, address proxy);
|
||||
|
||||
mapping(address => UserProxy) public proxies;
|
||||
bool public guardianEnabled;
|
||||
|
||||
constructor(address _addrRegistry) public {
|
||||
addrRegistry = _addrRegistry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev deploys a new proxy instance and sets msg.sender as owner of proxy
|
||||
*/
|
||||
function build() public returns (UserProxy proxy) {
|
||||
proxy = build(msg.sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev deploys a new proxy instance and sets custom owner of proxy
|
||||
*/
|
||||
function build(address owner) public returns (UserProxy proxy) {
|
||||
require(
|
||||
proxies[owner] == UserProxy(0) || proxies[owner].owner() != owner,
|
||||
"multiple-proxy-per-user-not-allowed"
|
||||
); // Not allow new proxy if the user already has one and remains being the owner
|
||||
proxy = new UserProxy(owner, addrRegistry);
|
||||
emit Created(msg.sender, owner, address(proxy));
|
||||
proxies[owner] = proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev update the proxy record whenever owner changed on any proxy
|
||||
* Throws if msg.sender is not a proxy contract created via this contract
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev enable guardian in overall system
|
||||
*/
|
||||
function enableGuardian() public isAdmin {
|
||||
guardianEnabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev disable guardian in overall system
|
||||
*/
|
||||
function disableGuardian() public isAdmin {
|
||||
guardianEnabled = false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,14 +1,12 @@
|
|||
pragma solidity ^0.5.0;
|
||||
|
||||
import "./UserWallet.sol";
|
||||
|
||||
|
||||
contract AddressRegistry {
|
||||
event LogSetAddress(string name, address addr);
|
||||
event LogSetDefaultLogic(address logicAddr);
|
||||
event LogSetLogic(address logicAddr, bool isLogic);
|
||||
|
||||
mapping(bytes32 => address) registry;
|
||||
mapping(address => bool) public defaultLogicProxies;
|
||||
mapping(address => bool) public logicProxies;
|
||||
|
||||
constructor() public {
|
||||
registry[keccak256(abi.encodePacked("admin"))] = msg.sender;
|
||||
|
@ -40,6 +38,17 @@ contract AddressRegistry {
|
|||
_;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
contract LogicRegistry is AddressRegistry {
|
||||
|
||||
event LogSetDefaultLogic(address logicAddr);
|
||||
event LogSetLogic(address logicAddr, bool isLogic);
|
||||
|
||||
mapping(address => bool) public defaultLogicProxies;
|
||||
mapping(address => bool) public logicProxies;
|
||||
|
||||
/**
|
||||
* @dev get the boolean of the logic proxy contract
|
||||
* @param logicAddr is the logic proxy address
|
||||
|
@ -73,4 +82,56 @@ contract AddressRegistry {
|
|||
emit LogSetLogic(logicAddr, isLogic);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
contract ProxyRegistry is LogicRegistry {
|
||||
|
||||
event Created(address indexed sender, address indexed owner, address proxy);
|
||||
|
||||
mapping(address => UserWallet) public proxies;
|
||||
bool public guardianEnabled;
|
||||
|
||||
/**
|
||||
* @dev deploys a new proxy instance and sets msg.sender as owner of proxy
|
||||
*/
|
||||
function build() public returns (UserWallet proxy) {
|
||||
proxy = build(msg.sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev deploys a new proxy instance and sets custom owner of proxy
|
||||
* Throws if the owner already have a UserWallet
|
||||
*/
|
||||
function build(address owner) public returns (UserWallet proxy) {
|
||||
require(proxies[owner] == UserWallet(0), "multiple-proxy-per-user-not-allowed");
|
||||
proxy = new UserWallet(owner);
|
||||
emit Created(msg.sender, owner, address(proxy));
|
||||
proxies[owner] = proxy;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev update the proxy record whenever owner changed on any proxy
|
||||
* Throws if msg.sender is not a proxy contract created via this contract
|
||||
*/
|
||||
function updateProxyRecord(address currentOwner, address nextOwner) public {
|
||||
require(msg.sender == address(proxies[currentOwner]), "invalid-proxy-or-owner");
|
||||
proxies[nextOwner] = proxies[currentOwner];
|
||||
proxies[currentOwner] = UserWallet(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev enable guardian in overall system
|
||||
*/
|
||||
function enableGuardian() public isAdmin {
|
||||
guardianEnabled = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev disable guardian in overall system
|
||||
*/
|
||||
function disableGuardian() public isAdmin {
|
||||
guardianEnabled = false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,9 @@
|
|||
pragma solidity ^0.5.0;
|
||||
|
||||
|
||||
/**
|
||||
* @dev because math is not safe
|
||||
*/
|
||||
library SafeMath {
|
||||
function add(uint256 a, uint256 b) internal pure returns (uint256) {
|
||||
uint256 c = a + b;
|
||||
|
@ -9,46 +12,53 @@ library SafeMath {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title ProxyRegistry Interface
|
||||
*/
|
||||
interface ProxyRegistryInterface {
|
||||
function updateProxyRecord(address currentOwner, address nextOwner) external;
|
||||
function guardianEnabled() external returns (bool);
|
||||
}
|
||||
|
||||
/**
|
||||
* @title AddressRegistryInterface Interface
|
||||
*/
|
||||
interface AddressRegistryInterface {
|
||||
function getLogic(address logicAddr) external view returns (bool);
|
||||
function getAddress(string calldata name) external view returns(address);
|
||||
function updateProxyRecord(address currentOwner, address nextOwner) external;
|
||||
function guardianEnabled() external returns (bool);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title Proxy Record
|
||||
* @title Address Record
|
||||
*/
|
||||
contract ProxyRecord {
|
||||
|
||||
address public proxyRegistryContract;
|
||||
contract AddressRecord {
|
||||
|
||||
/**
|
||||
* @dev address registry of system, logic and proxy addresses
|
||||
*/
|
||||
address public registry;
|
||||
|
||||
/**
|
||||
* @dev this updates the internal proxy ownership on "proxy registry" contract
|
||||
* @dev this updates the internal proxy ownership on "registry" contract
|
||||
* @param currentOwner is the current owner
|
||||
* @param nextOwner is the new assigned owner
|
||||
*/
|
||||
function setProxyRecordOwner(address currentOwner, address nextOwner) internal {
|
||||
ProxyRegistryInterface initCall = ProxyRegistryInterface(proxyRegistryContract);
|
||||
AddressRegistryInterface initCall = AddressRegistryInterface(registry);
|
||||
initCall.updateProxyRecord(currentOwner, nextOwner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param logicAddr is the logic proxy contract address
|
||||
* @return the true boolean for logic proxy if authorised otherwise false
|
||||
*/
|
||||
function isLogicAuthorised(address logicAddr) internal view returns (bool) {
|
||||
AddressRegistryInterface logicProxy = AddressRegistryInterface(registry);
|
||||
return logicProxy.getLogic(logicAddr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title User Auth
|
||||
*/
|
||||
contract UserAuth is ProxyRecord {
|
||||
contract UserAuth is AddressRecord {
|
||||
using SafeMath for uint;
|
||||
using SafeMath for uint256;
|
||||
|
||||
|
@ -63,7 +73,6 @@ contract UserAuth is ProxyRecord {
|
|||
* @dev defines the "proxy registry" contract and sets the owner
|
||||
*/
|
||||
constructor() public {
|
||||
proxyRegistryContract = msg.sender;
|
||||
gracePeriod = 3 days;
|
||||
}
|
||||
|
||||
|
@ -117,6 +126,7 @@ contract UserAuth is ProxyRecord {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @title User Guardians
|
||||
*/
|
||||
|
@ -134,8 +144,8 @@ contract UserGuardian is UserAuth {
|
|||
* @dev Throws if guardians not enabled by system admin
|
||||
*/
|
||||
modifier guard() {
|
||||
ProxyRegistryInterface initCall = ProxyRegistryInterface(proxyRegistryContract);
|
||||
require(initCall.guardianEnabled());
|
||||
AddressRegistryInterface initCall = AddressRegistryInterface(registry);
|
||||
require(initCall.guardianEnabled(), "guardian-not-enabled");
|
||||
_;
|
||||
}
|
||||
|
||||
|
@ -173,6 +183,7 @@ contract UserGuardian is UserAuth {
|
|||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dev logging the execute events
|
||||
*/
|
||||
|
@ -207,24 +218,9 @@ contract UserNote {
|
|||
|
||||
|
||||
/**
|
||||
* @title User Proxy Logic
|
||||
* @title User Owned Contract Wallet
|
||||
*/
|
||||
contract UserLogic {
|
||||
address public logicRegistryAddr;
|
||||
|
||||
/**
|
||||
* @param logicAddr is the logic proxy contract address
|
||||
* @return the true boolean for logic proxy if authorised otherwise false
|
||||
*/
|
||||
function isLogicAuthorised(address logicAddr) internal view returns (bool) {
|
||||
AddressRegistryInterface logicProxy = AddressRegistryInterface(logicRegistryAddr);
|
||||
return logicProxy.getLogic(logicAddr);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
contract UserProxy is UserGuardian, UserNote, UserLogic {
|
||||
contract UserWallet is UserGuardian, UserNote {
|
||||
|
||||
event LogExecute(address target, uint srcNum, uint sessionNum);
|
||||
|
||||
|
@ -233,8 +229,8 @@ contract UserProxy is UserGuardian, UserNote, UserLogic {
|
|||
* @param _owner initial owner of the contract
|
||||
* @param _logicRegistryAddr address registry address which have logic proxy registry
|
||||
*/
|
||||
constructor(address _owner, address _logicRegistryAddr) public {
|
||||
logicRegistryAddr = _logicRegistryAddr;
|
||||
constructor(address _owner) public {
|
||||
registry = msg.sender;
|
||||
owner = _owner;
|
||||
lastActivity = block.timestamp;
|
||||
activePeriod = 30 days; // default and changeable
|
Loading…
Reference in New Issue
Block a user