mirror of
https://github.com/Instadapp/smart-contract.git
synced 2024-07-29 22:08:07 +00:00
Added Logic Proxy & Address Registry.
This commit is contained in:
parent
e592145c48
commit
0666a6b72e
27
AddressRegistry.sol
Normal file
27
AddressRegistry.sol
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
pragma solidity ^0.4.23;
|
||||||
|
|
||||||
|
|
||||||
|
contract AddressRegistry {
|
||||||
|
|
||||||
|
event AddressSet(string name, address addr);
|
||||||
|
mapping(bytes32 => address) registry;
|
||||||
|
|
||||||
|
constructor() public {
|
||||||
|
registry[keccak256(abi.encodePacked("admin"))] = msg.sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAddr(string memory name) public view returns(address) {
|
||||||
|
return registry[keccak256(abi.encodePacked(name))];
|
||||||
|
}
|
||||||
|
|
||||||
|
function setAddr(string memory name, address addr) public {
|
||||||
|
require(
|
||||||
|
msg.sender == getAddr("admin") ||
|
||||||
|
msg.sender == getAddr("owner"),
|
||||||
|
"Permission Denied"
|
||||||
|
);
|
||||||
|
registry[keccak256(abi.encodePacked(name))] = addr;
|
||||||
|
emit AddressSet(name, addr);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
58
LogicProxy.sol
Normal file
58
LogicProxy.sol
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
pragma solidity ^0.4.23;
|
||||||
|
|
||||||
|
interface AddrRegistry {
|
||||||
|
function getAddr(string calldata name) 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 LogicProxyRegistry 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,16 +1,16 @@
|
||||||
pragma solidity ^0.4.23;
|
pragma solidity ^0.4.23;
|
||||||
|
|
||||||
contract DSAuthority {
|
contract UserAuthority {
|
||||||
function canCall(address src, address dst, bytes4 sig) public view returns (bool);
|
function canCall(address src, address dst, bytes4 sig) public view returns (bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
contract DSAuthEvents {
|
contract UserAuthEvents {
|
||||||
event LogSetAuthority (address indexed authority);
|
event LogSetAuthority (address indexed authority);
|
||||||
event LogSetOwner (address indexed owner);
|
event LogSetOwner (address indexed owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
contract DSAuth is DSAuthEvents {
|
contract UserAuth is UserAuthEvents {
|
||||||
DSAuthority public authority;
|
UserAuthority public authority;
|
||||||
address public owner;
|
address public owner;
|
||||||
|
|
||||||
constructor() public {
|
constructor() public {
|
||||||
|
@ -26,7 +26,7 @@ contract DSAuth is DSAuthEvents {
|
||||||
emit LogSetOwner(owner);
|
emit LogSetOwner(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAuthority(DSAuthority authority_)
|
function setAuthority(UserAuthority authority_)
|
||||||
public
|
public
|
||||||
auth
|
auth
|
||||||
{
|
{
|
||||||
|
@ -44,7 +44,7 @@ contract DSAuth is DSAuthEvents {
|
||||||
return true;
|
return true;
|
||||||
} else if (src == owner) {
|
} else if (src == owner) {
|
||||||
return true;
|
return true;
|
||||||
} else if (authority == DSAuthority(0)) {
|
} else if (authority == UserAuthority(0)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return authority.canCall(src, this, sig);
|
return authority.canCall(src, this, sig);
|
||||||
|
@ -52,7 +52,7 @@ contract DSAuth is DSAuthEvents {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract DSNote {
|
contract UserNote {
|
||||||
event LogNote(
|
event LogNote(
|
||||||
bytes4 indexed sig,
|
bytes4 indexed sig,
|
||||||
address indexed guy,
|
address indexed guy,
|
||||||
|
@ -77,13 +77,13 @@ contract DSNote {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DSProxy
|
// UserProxy
|
||||||
// Allows code execution using a persistant identity This can be very
|
// Allows code execution using a persistant identity This can be very
|
||||||
// useful to execute a sequence of atomic actions. Since the owner of
|
// useful to execute a sequence of atomic actions. Since the owner of
|
||||||
// the proxy can be changed, this allows for dynamic ownership models
|
// the proxy can be changed, this allows for dynamic ownership models
|
||||||
// i.e. a multisig
|
// i.e. a multisig
|
||||||
contract DSProxy is DSAuth, DSNote {
|
contract UserProxy is UserAuth, UserNote {
|
||||||
DSProxyCache public cache; // global cache for contracts
|
UserProxyCache public cache; // global cache for contracts
|
||||||
|
|
||||||
constructor(address _cacheAddr) public {
|
constructor(address _cacheAddr) public {
|
||||||
setCache(_cacheAddr);
|
setCache(_cacheAddr);
|
||||||
|
@ -114,7 +114,7 @@ contract DSProxy is DSAuth, DSNote {
|
||||||
payable
|
payable
|
||||||
returns (bytes memory response)
|
returns (bytes memory response)
|
||||||
{
|
{
|
||||||
require(_target != address(0), "ds-proxy-target-address-required");
|
require(_target != address(0), "User-proxy-target-address-required");
|
||||||
|
|
||||||
// call contract in current context
|
// call contract in current context
|
||||||
assembly {
|
assembly {
|
||||||
|
@ -141,13 +141,13 @@ contract DSProxy is DSAuth, DSNote {
|
||||||
note
|
note
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
require(_cacheAddr != address(0), "ds-proxy-cache-address-required");
|
require(_cacheAddr != address(0), "User-proxy-cache-address-required");
|
||||||
cache = DSProxyCache(_cacheAddr); // overwrite cache
|
cache = UserProxyCache(_cacheAddr); // overwrite cache
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DSProxyCache
|
// UserProxyCache
|
||||||
// This global cache stores addresses of contracts previously deployed
|
// This global cache stores addresses of contracts previously deployed
|
||||||
// by a proxy. This saves gas from repeat deployment of the same
|
// by a proxy. This saves gas from repeat deployment of the same
|
||||||
// contracts and eliminates blockchain bloat.
|
// contracts and eliminates blockchain bloat.
|
||||||
|
@ -156,7 +156,7 @@ contract DSProxy is DSAuth, DSNote {
|
||||||
// contracts in the same cache. The cache a proxy instance uses can be
|
// contracts in the same cache. The cache a proxy instance uses can be
|
||||||
// changed. The cache uses the sha3 hash of a contract's bytecode to
|
// changed. The cache uses the sha3 hash of a contract's bytecode to
|
||||||
// lookup the address
|
// lookup the address
|
||||||
contract DSProxyCache {
|
contract UserProxyCache {
|
||||||
mapping(bytes32 => address) cache;
|
mapping(bytes32 => address) cache;
|
||||||
|
|
||||||
function read(bytes memory _code) public view returns (address) {
|
function read(bytes memory _code) public view returns (address) {
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
pragma solidity ^0.4.23;
|
pragma solidity ^0.4.23;
|
||||||
|
|
||||||
contract DSAuthority {
|
contract UserAuthority {
|
||||||
function canCall(address src, address dst, bytes4 sig) public view returns (bool);
|
function canCall(address src, address dst, bytes4 sig) public view returns (bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
contract DSAuthEvents {
|
contract UserAuthEvents {
|
||||||
event LogSetAuthority (address indexed authority);
|
event LogSetAuthority (address indexed authority);
|
||||||
event LogSetOwner (address indexed owner);
|
event LogSetOwner (address indexed owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
contract DSAuth is DSAuthEvents {
|
contract UserAuth is UserAuthEvents {
|
||||||
DSAuthority public authority;
|
UserAuthority public authority;
|
||||||
address public owner;
|
address public owner;
|
||||||
|
|
||||||
constructor() public {
|
constructor() public {
|
||||||
|
@ -26,7 +26,7 @@ contract DSAuth is DSAuthEvents {
|
||||||
emit LogSetOwner(owner);
|
emit LogSetOwner(owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setAuthority(DSAuthority authority_)
|
function setAuthority(UserAuthority authority_)
|
||||||
public
|
public
|
||||||
auth
|
auth
|
||||||
{
|
{
|
||||||
|
@ -44,7 +44,7 @@ contract DSAuth is DSAuthEvents {
|
||||||
return true;
|
return true;
|
||||||
} else if (src == owner) {
|
} else if (src == owner) {
|
||||||
return true;
|
return true;
|
||||||
} else if (authority == DSAuthority(0)) {
|
} else if (authority == UserAuthority(0)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return authority.canCall(src, this, sig);
|
return authority.canCall(src, this, sig);
|
||||||
|
@ -52,7 +52,7 @@ contract DSAuth is DSAuthEvents {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract DSNote {
|
contract UserNote {
|
||||||
event LogNote(
|
event LogNote(
|
||||||
bytes4 indexed sig,
|
bytes4 indexed sig,
|
||||||
address indexed guy,
|
address indexed guy,
|
||||||
|
@ -77,13 +77,13 @@ contract DSNote {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DSProxy
|
// UserProxy
|
||||||
// Allows code execution using a persistant identity This can be very
|
// Allows code execution using a persistant identity This can be very
|
||||||
// useful to execute a sequence of atomic actions. Since the owner of
|
// useful to execute a sequence of atomic actions. Since the owner of
|
||||||
// the proxy can be changed, this allows for dynamic ownership models
|
// the proxy can be changed, this allows for dynamic ownership models
|
||||||
// i.e. a multisig
|
// i.e. a multisig
|
||||||
contract DSProxy is DSAuth, DSNote {
|
contract UserProxy is UserAuth, UserNote {
|
||||||
DSProxyCache public cache; // global cache for contracts
|
UserProxyCache public cache; // global cache for contracts
|
||||||
|
|
||||||
constructor(address _cacheAddr) public {
|
constructor(address _cacheAddr) public {
|
||||||
setCache(_cacheAddr);
|
setCache(_cacheAddr);
|
||||||
|
@ -114,7 +114,7 @@ contract DSProxy is DSAuth, DSNote {
|
||||||
payable
|
payable
|
||||||
returns (bytes memory response)
|
returns (bytes memory response)
|
||||||
{
|
{
|
||||||
require(_target != address(0), "ds-proxy-target-address-required");
|
require(_target != address(0), "User-proxy-target-address-required");
|
||||||
|
|
||||||
// call contract in current context
|
// call contract in current context
|
||||||
assembly {
|
assembly {
|
||||||
|
@ -141,13 +141,13 @@ contract DSProxy is DSAuth, DSNote {
|
||||||
note
|
note
|
||||||
returns (bool)
|
returns (bool)
|
||||||
{
|
{
|
||||||
require(_cacheAddr != address(0), "ds-proxy-cache-address-required");
|
require(_cacheAddr != address(0), "User-proxy-cache-address-required");
|
||||||
cache = DSProxyCache(_cacheAddr); // overwrite cache
|
cache = UserProxyCache(_cacheAddr); // overwrite cache
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DSProxyCache
|
// UserProxyCache
|
||||||
// This global cache stores addresses of contracts previously deployed
|
// This global cache stores addresses of contracts previously deployed
|
||||||
// by a proxy. This saves gas from repeat deployment of the same
|
// by a proxy. This saves gas from repeat deployment of the same
|
||||||
// contracts and eliminates blockchain bloat.
|
// contracts and eliminates blockchain bloat.
|
||||||
|
@ -156,7 +156,7 @@ contract DSProxy is DSAuth, DSNote {
|
||||||
// contracts in the same cache. The cache a proxy instance uses can be
|
// contracts in the same cache. The cache a proxy instance uses can be
|
||||||
// changed. The cache uses the sha3 hash of a contract's bytecode to
|
// changed. The cache uses the sha3 hash of a contract's bytecode to
|
||||||
// lookup the address
|
// lookup the address
|
||||||
contract DSProxyCache {
|
contract UserProxyCache {
|
||||||
mapping(bytes32 => address) cache;
|
mapping(bytes32 => address) cache;
|
||||||
|
|
||||||
function read(bytes memory _code) public view returns (address) {
|
function read(bytes memory _code) public view returns (address) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user