Código Fuente del Contrato
Archivo 1 de 1: Proxy.sol
pragma solidity 0.8.7;
contract Proxy {
bytes32 private constant IMPLEMENTATION_SLOT = bytes32(0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc);
bytes32 private constant ADMIN_SLOT = bytes32(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103);
constructor(address impl) {
require(impl != address(0));
_setSlotValue(IMPLEMENTATION_SLOT, bytes32(uint256(uint160(impl))));
_setSlotValue(ADMIN_SLOT, bytes32(uint256(uint160(msg.sender))));
}
function setImplementation(address newImpl) public {
require(msg.sender == _getAddress(ADMIN_SLOT));
_setSlotValue(IMPLEMENTATION_SLOT, bytes32(uint256(uint160(newImpl))));
}
function setAdmin(address newAdmin) public {
require(msg.sender == _getAddress(ADMIN_SLOT));
_setSlotValue(ADMIN_SLOT, bytes32(uint256(uint160(newAdmin))));
}
function implementation() public view returns (address impl) {
impl = address(uint160(uint256(_getSlotValue(IMPLEMENTATION_SLOT))));
}
function _getAddress(bytes32 key) internal view returns (address add) {
add = address(uint160(uint256(_getSlotValue(key))));
}
function _getSlotValue(bytes32 slot_) internal view returns (bytes32 value_) {
assembly {
value_ := sload(slot_)
}
}
function _setSlotValue(bytes32 slot_, bytes32 value_) internal {
assembly {
sstore(slot_, value_)
}
}
function _delegate(address implementation__) internal virtual {
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), implementation__, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
receive() external payable {}
fallback() external payable virtual {
_delegate(_getAddress(IMPLEMENTATION_SLOT));
}
}
{
"compilationTarget": {
"contracts/Proxy.sol": "Proxy"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}