This commit is contained in:
Samyak 2019-03-21 15:29:51 +05:30
commit bedba4fce1
4 changed files with 145 additions and 5 deletions

View File

@ -0,0 +1,26 @@
pragma solidity ^0.5.0;
import "./UserWallet.sol";
/**
* @title User Wallet Registry
*/
contract WalletRegistry {
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;
}
}

View File

@ -0,0 +1,114 @@
pragma solidity ^0.5.0;
/**
* @title User Auth
*/
contract UserAuth {
event LogSetOwner(address indexed owner, address setter);
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
* @param _owner is the new owner of this proxy contract
*/
function setOwner(address _owner) public auth {
owner = _owner;
emit LogSetOwner(owner, msg.sender);
}
}
/**
* @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 UserAuth, UserNote {
event LogExecute(address target);
/**
* @dev sets the initial owner
*/
constructor() public {
owner = msg.sender; // will be changed in initial call
}
function() external payable {}
/**
* @dev execute authorised calls via delegate call
* @param _target logic proxy address
* @param _data delegate call data
*/
function execute(address _target, bytes memory _data)
public
payable
note
auth
returns (bytes memory response)
{
require(_target != address(0), "invalid-logic-proxy-address");
emit LogExecute(_target);
// 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

@ -106,8 +106,8 @@ contract WalletRegistry is LogicRegistry {
event Created(address indexed sender, address indexed owner, address proxy);
mapping(address => UserWallet) public proxies;
bool public guardianEnabled; // user guardian mechanism enabled
bool public managerEnabled; // is user admin mechanism enabled
bool public guardianEnabled; // user guardian mechanism enabled in overall system
bool public managerEnabled; // user manager mechanism enabled in overall system
/**
* @dev deploys a new proxy instance and sets msg.sender as owner of proxy
@ -152,7 +152,7 @@ contract WalletRegistry is LogicRegistry {
guardianEnabled = false;
}
/**
/**
* @dev enable user manager in overall system
*/
function enableManager() public isAdmin {

View File

@ -245,7 +245,7 @@ contract UserManager is UserGuardian {
/**
* @dev Throws if the msg.sender is not manager
*/
function isManager() internal view returns (bool) {
function isManager() internal isManagerEnabled returns (bool) {
if (msg.sender == managers[1] || msg.sender == managers[2] || msg.sender == managers[3]) {
return true;
} else {
@ -354,7 +354,7 @@ contract UserWallet is UserManager, UserNote {
* and if the sender is owner or contract itself or manager
* and if manager then Throws if target is default proxy address
*/
function isExecutable(address proxyTarget) internal view returns (bool) {
function isExecutable(address proxyTarget) internal returns (bool) {
(bool isLogic, bool isDefault) = isLogicAuthorised(proxyTarget);
require(isLogic, "logic-proxy-address-not-allowed");
if (isAuth(msg.sender)) {