编译器
0.8.18+commit.87f61d96
文件 1 的 3:OwnedUpgradeabilityProxy.sol
pragma solidity ^0.8.18;
import "./UpgradeabilityProxy.sol";
contract OwnedUpgradeabilityProxy is UpgradeabilityProxy {
event ProxyOwnershipTransferred(address previousOwner, address newOwner);
bytes32 private constant PROXY_OWNER_POSITION = keccak256("org.govblocks.proxy.owner");
constructor(address _implementation) {
_setUpgradeabilityOwner(msg.sender);
_upgradeTo(_implementation);
}
modifier onlyProxyOwner() {
require(msg.sender == proxyOwner());
_;
}
function proxyOwner() public view returns (address owner) {
bytes32 position = PROXY_OWNER_POSITION;
assembly {
owner := sload(position)
}
}
function transferProxyOwnership(address _newOwner) public onlyProxyOwner {
require(_newOwner != address(0));
_setUpgradeabilityOwner(_newOwner);
emit ProxyOwnershipTransferred(proxyOwner(), _newOwner);
}
function upgradeTo(address _implementation) public onlyProxyOwner {
_upgradeTo(_implementation);
}
function _setUpgradeabilityOwner(address _newProxyOwner) internal {
bytes32 position = PROXY_OWNER_POSITION;
assembly {
sstore(position, _newProxyOwner)
}
}
}
文件 2 的 3:Proxy.sol
pragma solidity ^0.8.18;
abstract contract Proxy {
function _delegate() internal {
address _impl = implementation();
require(_impl != address(0));
assembly {
let ptr := mload(0x40)
calldatacopy(ptr, 0, calldatasize())
let result := delegatecall(gas(), _impl, ptr, calldatasize(), 0, 0)
let size := returndatasize()
returndatacopy(ptr, 0, size)
switch result
case 0 {revert(ptr, size)}
default {return (ptr, size)}
}
}
fallback() external payable {
_delegate();
}
receive() external payable {
_delegate();
}
function implementation() virtual public view returns (address);
}
文件 3 的 3:UpgradeabilityProxy.sol
pragma solidity ^0.8.18;
import "./Proxy.sol";
contract UpgradeabilityProxy is Proxy {
event Upgraded(address indexed implementation);
bytes32 private constant IMPLEMENTATION_POSITION = keccak256("org.govblocks.proxy.implementation");
constructor() {}
function implementation() public override view returns (address impl) {
bytes32 position = IMPLEMENTATION_POSITION;
assembly {
impl := sload(position)
}
}
function _setImplementation(address _newImplementation) internal {
bytes32 position = IMPLEMENTATION_POSITION;
assembly {
sstore(position, _newImplementation)
}
}
function _upgradeTo(address _newImplementation) internal {
address currentImplementation = implementation();
require(currentImplementation != _newImplementation);
_setImplementation(_newImplementation);
emit Upgraded(_newImplementation);
}
}
{
"compilationTarget": {
"contracts/modules/governance/external/OwnedUpgradeabilityProxy.sol": "OwnedUpgradeabilityProxy"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_implementation","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":false,"internalType":"address","name":"newOwner","type":"address"}],"name":"ProxyOwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"impl","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"proxyOwner","outputs":[{"internalType":"address","name":"owner","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferProxyOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_implementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]