编译器
0.5.17+commit.d19bba13
文件 1 的 3:Address.sol
pragma solidity ^0.5.5;
library Address {
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
function toPayable(address account) internal pure returns (address payable) {
return address(uint160(account));
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call.value(amount)("");
require(success, "Address: unable to send value, recipient may have reverted");
}
}
文件 2 的 3:BrokerProxy.sol
pragma solidity ^0.5.13;
import "../common/Proxy.sol";
contract BrokerProxy is Proxy {
}
文件 3 的 3:Proxy.sol
pragma solidity ^0.5.13;
import "openzeppelin-solidity/contracts/utils/Address.sol";
contract Proxy {
bytes32 private constant OWNER_POSITION = bytes32(uint256(keccak256("eip1967.proxy.admin")) - 1);
bytes32 private constant IMPLEMENTATION_POSITION = bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1);
event OwnerSet(address indexed owner);
event ImplementationSet(address indexed implementation);
constructor() public {
_setOwner(msg.sender);
}
modifier onlyOwner() {
require(msg.sender == _getOwner(), "sender was not owner");
_;
}
function() external payable {
bytes32 implementationPosition = IMPLEMENTATION_POSITION;
address implementationAddress;
assembly {
implementationAddress := sload(implementationPosition)
}
require(implementationAddress != address(0), "No Implementation set");
require(Address.isContract(implementationAddress), "Invalid contract address");
assembly {
let newCallDataPosition := mload(0x40)
mstore(0x40, add(newCallDataPosition, calldatasize))
calldatacopy(newCallDataPosition, 0, calldatasize)
let delegatecallSuccess := delegatecall(gas, implementationAddress, newCallDataPosition, calldatasize, 0, 0)
let returnDataSize := returndatasize
let returnDataPosition := mload(0x40)
mstore(0x40, add(returnDataPosition, returnDataSize))
returndatacopy(returnDataPosition, 0, returnDataSize)
switch delegatecallSuccess
case 0 {
revert(returnDataPosition, returnDataSize)
}
default {
return(returnDataPosition, returnDataSize)
}
}
}
function _transferOwnership(address newOwner) external onlyOwner {
_setOwner(newOwner);
}
function _setAndInitializeImplementation(address implementation, bytes calldata callbackData)
external
payable
onlyOwner
{
_setImplementation(implementation);
bool success;
bytes memory returnValue;
(success, returnValue) = implementation.delegatecall(callbackData);
require(success, "initialization callback failed");
}
function _getImplementation() external view returns (address implementation) {
bytes32 implementationPosition = IMPLEMENTATION_POSITION;
assembly {
implementation := sload(implementationPosition)
}
}
function _setImplementation(address implementation) public onlyOwner {
bytes32 implementationPosition = IMPLEMENTATION_POSITION;
require(Address.isContract(implementation), "Invalid contract address");
assembly {
sstore(implementationPosition, implementation)
}
emit ImplementationSet(implementation);
}
function _getOwner() public view returns (address owner) {
bytes32 position = OWNER_POSITION;
assembly {
owner := sload(position)
}
}
function _setOwner(address newOwner) internal {
require(newOwner != address(0), "owner cannot be 0");
bytes32 position = OWNER_POSITION;
assembly {
sstore(position, newOwner)
}
emit OwnerSet(newOwner);
}
}
{
"compilationTarget": {
"lib/mento-core/contracts/proxies/BrokerProxy.sol": "BrokerProxy"
},
"evmVersion": "istanbul",
"libraries": {
"AddressLinkedList": "0x6200f54d73491d56b8d7a975c9ee18efb4d518df",
"AddressSortedLinkedListWithMedian": "0xed477a99035d0c1e11369f1d7a4e587893cc002b"
},
"optimizer": {
"enabled": true,
"runs": 10000
},
"remappings": [
":celo-foundry/=lib/celo-foundry/src/",
":contracts/=contracts/",
":ds-test/=lib/celo-foundry/lib/forge-std/lib/ds-test/src/",
":forge-std/=lib/celo-foundry/lib/forge-std/src/",
":mento-core/=lib/mento-core/",
":openzeppelin-contracts/=lib/mento-core/lib/openzeppelin-contracts/contracts/",
":openzeppelin-solidity/=lib/mento-core/lib/openzeppelin-contracts/",
":script/=script/",
":test/=lib/mento-core/test/"
]
}
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"ImplementationSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"owner","type":"address"}],"name":"OwnerSet","type":"event"},{"payable":true,"stateMutability":"payable","type":"fallback"},{"constant":true,"inputs":[],"name":"_getImplementation","outputs":[{"internalType":"address","name":"implementation","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"_getOwner","outputs":[{"internalType":"address","name":"owner","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"implementation","type":"address"},{"internalType":"bytes","name":"callbackData","type":"bytes"}],"name":"_setAndInitializeImplementation","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"_setImplementation","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"_transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]