Updated initial wallet & removed beta contracts.

This commit is contained in:
Sowmayjain 2019-04-03 04:54:36 +05:30
parent db027c7f93
commit 20ec845185
4 changed files with 8 additions and 271 deletions

View File

@ -1,106 +0,0 @@
pragma solidity ^0.5.0;
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
*/
contract WalletRegistry is LogicRegistry {
event Created(address indexed sender, address indexed owner, address proxy);
mapping(address => UserWallet) public proxies;
/**
* @dev deploys a new proxy instance and sets custom owner of proxy
* Throws if the owner already have a UserWallet
*/
function build() public returns (UserWallet proxy) {
require(proxies[msg.sender] == UserWallet(0), "multiple-proxy-per-user-not-allowed");
proxy = new UserWallet();
proxy.setOwner(msg.sender);
emit Created(msg.sender, msg.sender, address(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;
}
}

View File

@ -1,146 +0,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
*/
contract UserAuth {
address public owner;
/**
* @dev Throws if not called by owner or contract itself
*/
modifier auth {
require(msg.sender == owner, "permission-denied");
_;
}
/**
* @dev sets new owner only once
* @param _owner is the new owner of this proxy contract
*/
function setOwner(address _owner) public auth {
require(owner == address(0), "owner-already-assigned");
owner = _owner;
}
}
/**
* @dev logging the execute events
*/
contract UserNote {
event LogNote(
bytes4 indexed sig,
address indexed guy,
bytes32 indexed foo,
bytes32 bar,
uint wad,
bytes fax
);
modifier note {
bytes32 foo;
bytes32 bar;
assembly {
foo := calldataload(4)
bar := calldataload(36)
}
emit LogNote(
msg.sig,
msg.sender,
foo,
bar,
msg.value,
msg.data
);
_;
}
}
/**
* @title User Owned Contract Wallet
*/
contract UserWallet is AddressRecord, UserAuth, UserNote {
event LogExecute(address target, uint src);
/**
* @dev sets the address registry
*/
constructor() public {
registry = msg.sender;
}
function() external payable {}
/**
* @dev execute authorised calls via delegate call
* @param _target logic proxy address
* @param _data delegate call data
* @param _src function execution interface source
*/
function execute(address _target, bytes memory _data, uint _src)
public
payable
note
auth
logicAuth(_target)
returns (bytes memory response)
{
require(_target != address(0), "invalid-logic-proxy-address");
emit LogExecute(_target, _src);
// call contract in current context
assembly {
let succeeded := delegatecall(sub(gas, 5000), _target, add(_data, 0x20), mload(_data), 0, 0)
let size := returndatasize
response := mload(0x40)
mstore(0x40, add(response, and(add(add(size, 0x20), 0x1f), not(0x1f))))
mstore(response, size)
returndatacopy(add(response, 0x20), 0, size)
switch iszero(succeeded)
case 1 {
// throw if delegatecall failed
revert(add(response, 0x20), size)
}
}
}
}

View File

@ -33,13 +33,14 @@ contract AddressRecord {
address public registry;
/**
* @param logicAddr is the logic proxy contract address
* @return the true boolean for logic proxy if authorised otherwise false
* @dev Throws if the logic is not authorised
*/
function isLogicAuthorised(address logicAddr) public view returns (bool, bool) {
modifier logicAuth(address logicAddr) {
require(logicAddr != address(0), "logic-proxy-address-required");
AddressRegistryInterface logicProxy = AddressRegistryInterface(registry);
(bool isLogic, bool isDefault) = logicProxy.isLogicAuth(logicAddr);
return (isLogic, isDefault);
(bool isLogicAuth, ) = logicProxy.isLogicAuth(logicAddr);
require(isLogicAuth, "logic-not-authorised");
_;
}
/**
@ -135,7 +136,7 @@ contract UserNote {
/**
* @title User Owned Contract Wallet
*/
contract InstaWallet is UserAuth, UserNote {
contract UserWallet is UserAuth, UserNote {
event LogExecute(address sender, address target, uint srcNum, uint sessionNum);
@ -166,7 +167,7 @@ contract InstaWallet is UserAuth, UserNote {
payable
note
auth
isExecutable(_target)
logicAuth(_target)
returns (bytes memory response)
{
emit LogExecute(
@ -194,16 +195,4 @@ contract InstaWallet is UserAuth, UserNote {
}
}
/**
* @dev checks if the proxy is authorised
* and if the sender is owner or contract itself or manager
* and if manager then Throws if target is default proxy address
*/
modifier isExecutable(address proxyTarget) {
require(proxyTarget != address(0), "logic-proxy-address-required");
(bool isLogic, ) = isLogicAuthorised(proxyTarget);
require(isLogic, "logic-proxy-address-not-allowed");
_;
}
}