mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
Completed basic version of beta contracts.
This commit is contained in:
parent
ff2657a11a
commit
d28c507085
|
@ -3,10 +3,80 @@ pragma solidity ^0.5.0;
|
||||||
import "./UserWallet.sol";
|
import "./UserWallet.sol";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Address Registry
|
||||||
|
*/
|
||||||
|
contract AddressRegistry {
|
||||||
|
event LogSetAddress(string name, address addr);
|
||||||
|
|
||||||
|
mapping(bytes32 => address) registry;
|
||||||
|
|
||||||
|
modifier isAdmin() {
|
||||||
|
require(
|
||||||
|
msg.sender == getAddress("admin") ||
|
||||||
|
msg.sender == getAddress("owner"),
|
||||||
|
"permission-denied"
|
||||||
|
);
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev get the address from system registry
|
||||||
|
*/
|
||||||
|
function getAddress(string memory name) public view returns(address) {
|
||||||
|
return registry[keccak256(abi.encodePacked(name))];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev set new address in system registry
|
||||||
|
*/
|
||||||
|
function setAddress(string memory name, address addr) public isAdmin {
|
||||||
|
registry[keccak256(abi.encodePacked(name))] = addr;
|
||||||
|
emit LogSetAddress(name, addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Logic Registry
|
||||||
|
*/
|
||||||
|
contract LogicRegistry is AddressRegistry {
|
||||||
|
|
||||||
|
event LogEnableLogic(address logicAddr);
|
||||||
|
|
||||||
|
mapping(address => bool) public logicProxies;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev get the boolean of the logic contract
|
||||||
|
* @param logicAddr is the logic proxy address
|
||||||
|
* @return bool logic proxy is authorised by system admin
|
||||||
|
* @return bool logic proxy is default proxy
|
||||||
|
*/
|
||||||
|
function isLogic(address logicAddr) public view returns (bool) {
|
||||||
|
if (logicProxies[logicAddr]) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev enable logic proxy address which sets it to true
|
||||||
|
* @param logicAddr is the logic proxy address
|
||||||
|
*/
|
||||||
|
function enableLogic(address logicAddr) public isAdmin {
|
||||||
|
logicProxies[logicAddr] = true;
|
||||||
|
emit LogEnableLogic(logicAddr);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @title User Wallet Registry
|
* @title User Wallet Registry
|
||||||
*/
|
*/
|
||||||
contract WalletRegistry {
|
contract WalletRegistry is LogicRegistry {
|
||||||
|
|
||||||
event Created(address indexed sender, address indexed owner, address proxy);
|
event Created(address indexed sender, address indexed owner, address proxy);
|
||||||
mapping(address => UserWallet) public proxies;
|
mapping(address => UserWallet) public proxies;
|
||||||
|
@ -23,4 +93,14 @@ contract WalletRegistry {
|
||||||
proxies[msg.sender] = proxy;
|
proxies[msg.sender] = proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
contract InstaRegistry is WalletRegistry {
|
||||||
|
|
||||||
|
constructor() public {
|
||||||
|
registry[keccak256(abi.encodePacked("admin"))] = msg.sender;
|
||||||
|
registry[keccak256(abi.encodePacked("owner"))] = msg.sender;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,12 +1,42 @@
|
||||||
pragma solidity ^0.5.0;
|
pragma solidity ^0.5.0;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title AddressRegistryInterface Interface
|
||||||
|
*/
|
||||||
|
interface AddressRegistryInterface {
|
||||||
|
function isLogic(address logicAddr) external view returns (bool);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Address Registry Record
|
||||||
|
*/
|
||||||
|
contract AddressRecord {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev address registry of system, logic and wallet addresses
|
||||||
|
*/
|
||||||
|
address public registry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Throws if the logic is not authorised
|
||||||
|
*/
|
||||||
|
modifier logicAuth(address logicAddr) {
|
||||||
|
AddressRegistryInterface logicProxy = AddressRegistryInterface(registry);
|
||||||
|
bool islogic = logicProxy.isLogic(logicAddr);
|
||||||
|
require(islogic, "logic-not-authorised");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @title User Auth
|
* @title User Auth
|
||||||
*/
|
*/
|
||||||
contract UserAuth {
|
contract UserAuth {
|
||||||
|
|
||||||
event LogSetOwner(address indexed owner, address setter);
|
|
||||||
address public owner;
|
address public owner;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,12 +48,12 @@ contract UserAuth {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev sets new owner
|
* @dev sets new owner only once
|
||||||
* @param _owner is the new owner of this proxy contract
|
* @param _owner is the new owner of this proxy contract
|
||||||
*/
|
*/
|
||||||
function setOwner(address _owner) public auth {
|
function setOwner(address _owner) public auth {
|
||||||
|
require(owner == address(0), "owner-already-assigned");
|
||||||
owner = _owner;
|
owner = _owner;
|
||||||
emit LogSetOwner(owner, msg.sender);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -65,15 +95,15 @@ contract UserNote {
|
||||||
/**
|
/**
|
||||||
* @title User Owned Contract Wallet
|
* @title User Owned Contract Wallet
|
||||||
*/
|
*/
|
||||||
contract UserWallet is UserAuth, UserNote {
|
contract UserWallet is AddressRecord, UserAuth, UserNote {
|
||||||
|
|
||||||
event LogExecute(address target);
|
event LogExecute(address target, uint src);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev sets the initial owner
|
* @dev sets the address registry
|
||||||
*/
|
*/
|
||||||
constructor() public {
|
constructor() public {
|
||||||
owner = msg.sender; // will be changed in initial call
|
registry = msg.sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
function() external payable {}
|
function() external payable {}
|
||||||
|
@ -82,16 +112,18 @@ contract UserWallet is UserAuth, UserNote {
|
||||||
* @dev execute authorised calls via delegate call
|
* @dev execute authorised calls via delegate call
|
||||||
* @param _target logic proxy address
|
* @param _target logic proxy address
|
||||||
* @param _data delegate call data
|
* @param _data delegate call data
|
||||||
|
* @param _src function execution interface source
|
||||||
*/
|
*/
|
||||||
function execute(address _target, bytes memory _data)
|
function execute(address _target, bytes memory _data, uint _src)
|
||||||
public
|
public
|
||||||
payable
|
payable
|
||||||
note
|
note
|
||||||
auth
|
auth
|
||||||
|
logicAuth(_target)
|
||||||
returns (bytes memory response)
|
returns (bytes memory response)
|
||||||
{
|
{
|
||||||
require(_target != address(0), "invalid-logic-proxy-address");
|
require(_target != address(0), "invalid-logic-proxy-address");
|
||||||
emit LogExecute(_target);
|
emit LogExecute(_target, _src);
|
||||||
|
|
||||||
// call contract in current context
|
// call contract in current context
|
||||||
assembly {
|
assembly {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user