Skip to content

Latest commit

 

History

History
567 lines (449 loc) · 12.2 KB

DSProxyFactory.md

File metadata and controls

567 lines (449 loc) · 12.2 KB

DSProxyFactory.sol

View Source: contracts/TestContracts/DappSys/proxy.sol

↗ Extends: DSAuthEvents

DSProxyFactory

Contract Members

Constants & Variables

//public members
contract DSAuthority public authority;
address public owner;
contract DSProxyCache public cache;
mapping(address => bool) public isProxy;
contract DSProxyCache public cache;

//internal members
mapping(bytes32 => address) internal cache;

Events

event LogSetAuthority(address indexed authority);
event LogSetOwner(address indexed owner);
event LogNote(bytes4 indexed sig, address indexed guy, bytes32 indexed foo, bytes32 indexed bar, uint256  wad, bytes  fax);
event Created(address indexed sender, address indexed owner, address  proxy, address  cache);

Modifiers

auth

modifier auth() internal

note

modifier note() internal

Functions


canCall

function canCall(address src, address dst, bytes4 sig) public view
returns(bool)

Arguments

Name Type Description
src address
dst address
sig bytes4
Source Code
function canCall(
        address src, address dst, bytes4 sig
    ) virtual public view returns (bool);

constructor

function () public nonpayable
Source Code
constructor() public {
        owner = msg.sender;
        emit LogSetOwner(msg.sender);
    }

setOwner

function setOwner(address owner_) public nonpayable auth 

Arguments

Name Type Description
owner_ address
Source Code
function setOwner(address owner_)
        public
        auth
    {
        owner = owner_;
        emit LogSetOwner(owner);
    }

setAuthority

function setAuthority(DSAuthority authority_) public nonpayable auth 

Arguments

Name Type Description
authority_ DSAuthority
Source Code
function setAuthority(DSAuthority authority_)
        public
        auth
    {
        authority = authority_;
        emit LogSetAuthority(address(authority));
    }

isAuthorized

function isAuthorized(address src, bytes4 sig) internal view
returns(bool)

Arguments

Name Type Description
src address
sig bytes4
Source Code
function isAuthorized(address src, bytes4 sig) internal view returns (bool) {
        if (src == address(this)) {
            return true;
        } else if (src == owner) {
            return true;
        } else if (authority == DSAuthority(0)) {
            return false;
        } else {
            return authority.canCall(src, address(this), sig);
        }
    }

constructor

function (address _cacheAddr) public nonpayable

Arguments

Name Type Description
_cacheAddr address
Source Code
constructor(address _cacheAddr) public {
        require(setCache(_cacheAddr));
    }

constructor

function () external payable
Source Code
fallback() external payable {
    }

constructor

function () external payable
Source Code
receive() external payable {
    }

execute

function execute(bytes _code, bytes _data) public payable
returns(target address, response bytes32)

Arguments

Name Type Description
_code bytes
_data bytes
Source Code
function execute(bytes calldata _code, bytes calldata _data)
        public
        payable
        returns (address target, bytes32 response)
    {
        target = cache.read(_code);
        if (target == address(0x0)) {
            // deploy contract & store its address in cache
            target = cache.write(_code);
        }

        response = execute(target, _data);
    }

execute

function execute(address _target, bytes _data) public payable auth note 
returns(response bytes32)

Arguments

Name Type Description
_target address
_data bytes
Source Code
function execute(address _target, bytes memory _data)
        public
        auth
        note
        payable
        returns (bytes32 response)
    {
        require(_target != address(0x0));

        // call contract in current context
        assembly {
            let succeeded := delegatecall(sub(gas(), 5000), _target, add(_data, 0x20), mload(_data), 0, 32)
            response := mload(0)      // load delegatecall output
            switch iszero(succeeded)
            case 1 {
                // throw if delegatecall failed
                revert(0, 0)
            }
        }
    }

setCache

function setCache(address _cacheAddr) internal nonpayable auth note 
returns(bool)

Arguments

Name Type Description
_cacheAddr address
Source Code
function setCache(address _cacheAddr)
        internal
        auth
        note
        returns (bool)
    {
        require(_cacheAddr != address(0x0));        // invalid cache address
        cache = DSProxyCache(_cacheAddr);  // overwrite cache
        return true;
    }

build

function build() public nonpayable
returns(proxy contract DSProxy)
Source Code
function build() public returns (DSProxy proxy) {
        proxy = build(msg.sender);
    }

build

function build(address owner) public nonpayable
returns(proxy contract DSProxy)

Arguments

Name Type Description
owner address
Source Code
function build(address owner) public returns (DSProxy proxy) {
        proxy = new DSProxy(address(cache));
        emit Created(msg.sender, owner, address(proxy), address(cache));
        proxy.setOwner(owner);
        isProxy[address(proxy)] = true;
    }

read

function read(bytes _code) public view
returns(address)

Arguments

Name Type Description
_code bytes
Source Code
function read(bytes calldata _code) public view returns (address) {
        bytes32 hash = keccak256(_code);
        return cache[hash];
    }

write

function write(bytes _code) public nonpayable
returns(target address)

Arguments

Name Type Description
_code bytes
Source Code
function write(bytes memory _code) public returns (address target) {
        assembly {
            target := create(0, add(_code, 0x20), mload(_code))
            switch iszero(extcodesize(target))
            case 1 {
                // throw if contract failed to deploy
                revert(0, 0)
            }
        }
        bytes32 hash = keccak256(_code);
        cache[hash] = target;
    }

Contracts