编译器
0.8.17+commit.8df45f5f
文件 1 的 8:AbstractProxy.sol
pragma solidity >=0.8.11 <0.9.0;
abstract contract AbstractProxy {
fallback() external payable {
_forward();
}
receive() external payable {
_forward();
}
function _forward() internal {
address implementation = _getImplementation();
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())
}
}
}
function _getImplementation() internal view virtual returns (address);
}
文件 2 的 8:AccessError.sol
pragma solidity >=0.8.11 <0.9.0;
library AccessError {
error Unauthorized(address addr);
}
文件 3 的 8:AddressError.sol
pragma solidity >=0.8.11 <0.9.0;
library AddressError {
error ZeroAddress();
error NotAContract(address contr);
}
文件 4 的 8:AddressUtil.sol
pragma solidity >=0.8.11 <0.9.0;
library AddressUtil {
function isContract(address account) internal view returns (bool) {
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
}
文件 5 的 8:OwnableStorage.sol
pragma solidity >=0.8.11 <0.9.0;
import "../errors/AccessError.sol";
library OwnableStorage {
bytes32 private constant _SLOT_OWNABLE_STORAGE =
keccak256(abi.encode("io.synthetix.core-contracts.Ownable"));
struct Data {
address owner;
address nominatedOwner;
}
function load() internal pure returns (Data storage store) {
bytes32 s = _SLOT_OWNABLE_STORAGE;
assembly {
store.slot := s
}
}
function onlyOwner() internal view {
if (msg.sender != getOwner()) {
revert AccessError.Unauthorized(msg.sender);
}
}
function getOwner() internal view returns (address) {
return OwnableStorage.load().owner;
}
}
文件 6 的 8:ProxyStorage.sol
pragma solidity >=0.8.11 <0.9.0;
contract ProxyStorage {
bytes32 private constant _SLOT_PROXY_STORAGE =
keccak256(abi.encode("io.synthetix.core-contracts.Proxy"));
struct ProxyStore {
address implementation;
bool simulatingUpgrade;
}
function _proxyStore() internal pure returns (ProxyStore storage store) {
bytes32 s = _SLOT_PROXY_STORAGE;
assembly {
store.slot := s
}
}
}
文件 7 的 8:UUPSProxy.sol
pragma solidity >=0.8.11 <0.9.0;
import "./AbstractProxy.sol";
import "./ProxyStorage.sol";
import "../errors/AddressError.sol";
import "../utils/AddressUtil.sol";
contract UUPSProxy is AbstractProxy, ProxyStorage {
constructor(address firstImplementation) {
if (firstImplementation == address(0)) {
revert AddressError.ZeroAddress();
}
if (!AddressUtil.isContract(firstImplementation)) {
revert AddressError.NotAContract(firstImplementation);
}
_proxyStore().implementation = firstImplementation;
}
function _getImplementation() internal view virtual override returns (address) {
return _proxyStore().implementation;
}
}
文件 8 的 8:UUPSProxyWithOwner.sol
pragma solidity >=0.8.11 <0.9.0;
import {UUPSProxy} from "./UUPSProxy.sol";
import {OwnableStorage} from "../ownership/OwnableStorage.sol";
contract UUPSProxyWithOwner is UUPSProxy {
constructor(address firstImplementation, address initialOwner) UUPSProxy(firstImplementation) {
OwnableStorage.load().owner = initialOwner;
}
}
{
"compilationTarget": {
"@synthetixio/core-contracts/contracts/proxy/UUPSProxyWithOwner.sol": "UUPSProxyWithOwner"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"firstImplementation","type":"address"},{"internalType":"address","name":"initialOwner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"contr","type":"address"}],"name":"NotAContract","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"stateMutability":"payable","type":"fallback"},{"stateMutability":"payable","type":"receive"}]