Created
July 2, 2019 22:53
-
-
Save tinchoabbate/14aa747aae7c3e18e17fabc1ee1af785 to your computer and use it in GitHub Desktop.
Simple proxy contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.5.0; | |
contract Proxy { | |
address public proxyOwner; | |
address public implementation; | |
constructor(address implementation) public { | |
proxyOwner = msg.sender; | |
_setImplementation(implementation); | |
} | |
modifier onlyProxyOwner() { | |
require(msg.sender == proxyOwner); | |
_; | |
} | |
function upgrade(address implementation) external onlyProxyOwner { | |
_setImplementation(implementation); | |
} | |
function _setImplementation(address imp) private { | |
implementation = imp; | |
} | |
function () payable external { | |
address impl = implementation; | |
assembly { | |
calldatacopy(0, 0, calldatasize) | |
let result := delegatecall(gas, impl, 0, calldatasize, 0, 0) | |
returndatacopy(0, 0, returndatasize) | |
switch result | |
case 0 { revert(0, returndatasize) } | |
default { return(0, returndatasize) } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment