编译器
0.8.18+commit.87f61d96
文件 1 的 3:IMapleTokenProxy.sol
pragma solidity 0.8.18;
interface IMapleTokenProxy {
event ImplementationSet(address indexed implementation);
function setImplementation(address newImplementation) external;
}
文件 2 的 3:Interfaces.sol
pragma solidity 0.8.18;
interface IERC20Like {
function burn(address from, uint256 value) external;
function mint(address to, uint256 value) external;
function totalSupply() external view returns (uint256 totalSupply);
}
interface IGlobalsLike {
function governor() external view returns (address governor);
function isInstanceOf(bytes32 instanceKey, address instance) external view returns (bool isInstance);
function isValidScheduledCall(
address caller,
address target,
bytes32 functionId,
bytes calldata callData
) external view returns (bool isValidScheduledCall);
function mapleTreasury() external view returns (address mapleTreasury);
function unscheduleCall(address caller, bytes32 functionId, bytes calldata callData) external;
}
interface IMapleTokenInitializerLike {
function initialize(address migrator, address treasury) external;
}
interface IMapleTokenLike is IERC20Like {
function globals() external view returns (address globals);
}
文件 3 的 3:MapleTokenProxy.sol
pragma solidity 0.8.18;
import { IMapleTokenInitializerLike, IGlobalsLike } from "./interfaces/Interfaces.sol";
import { IMapleTokenProxy } from "./interfaces/IMapleTokenProxy.sol";
contract MapleTokenProxy is IMapleTokenProxy {
bytes32 internal constant GLOBALS_SLOT = bytes32(uint256(keccak256("eip1967.proxy.globals")) - 1);
bytes32 internal constant IMPLEMENTATION_SLOT = bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1);
constructor(address globals_, address implementation_, address initializer_, address tokenMigrator_) {
_setAddress(GLOBALS_SLOT, globals_);
_setAddress(IMPLEMENTATION_SLOT, implementation_);
( bool success_, ) = initializer_.delegatecall(abi.encodeWithSelector(
IMapleTokenInitializerLike(initializer_).initialize.selector,
tokenMigrator_,
IGlobalsLike(globals_).mapleTreasury()
));
require(success_, "MTP:INIT_FAILED");
}
function setImplementation(address newImplementation_) override external {
IGlobalsLike globals_ = IGlobalsLike(_globals());
require(msg.sender == globals_.governor(), "MTP:SI:NOT_GOVERNOR");
bool isScheduledCall_ = globals_.isValidScheduledCall(msg.sender, address(this), "MTP:SET_IMPLEMENTATION", msg.data);
require(isScheduledCall_, "MTP:SI:NOT_SCHEDULED");
globals_.unscheduleCall(msg.sender, "MTP:SET_IMPLEMENTATION", msg.data);
_setAddress(IMPLEMENTATION_SLOT, newImplementation_);
emit ImplementationSet(newImplementation_);
}
function _globals() internal view returns (address globals_) {
globals_ = _getAddress(GLOBALS_SLOT);
}
function _implementation() internal view returns (address implementation_) {
implementation_ = _getAddress(IMPLEMENTATION_SLOT);
}
function _setAddress(bytes32 slot_, address value_) internal {
assembly {
sstore(slot_, value_)
}
}
function _getAddress(bytes32 slot_) internal view returns (address value_) {
assembly {
value_ := sload(slot_)
}
}
fallback() external {
address implementation_ = _implementation();
require(implementation_.code.length != 0, "MTP:F:NO_CODE_ON_IMPLEMENTATION");
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())
}
}
}
}
{
"compilationTarget": {
"contracts/MapleTokenProxy.sol": "MapleTokenProxy"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":address-registry/=modules/address-registry/contracts/",
":contract-test-utils/=modules/globals/modules/contract-test-utils/contracts/",
":ds-test/=modules/forge-std/lib/ds-test/src/",
":erc20-helper/=modules/migrator/modules/erc20-helper/src/",
":erc20/=modules/erc20/",
":forge-std/=modules/forge-std/src/",
":globals/=modules/globals/",
":migrator/=modules/migrator/",
":mpl-migration/=modules/xmpl/modules/mpl-migration/modules/erc20-helper/src/",
":non-transparent-proxy/=modules/globals/modules/non-transparent-proxy/",
":ntp/=modules/ntp/",
":revenue-distribution-token/=modules/xmpl/modules/revenue-distribution-token/contracts/",
":xmpl/=modules/xmpl/"
]
}
[{"inputs":[{"internalType":"address","name":"globals_","type":"address"},{"internalType":"address","name":"implementation_","type":"address"},{"internalType":"address","name":"initializer_","type":"address"},{"internalType":"address","name":"tokenMigrator_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"ImplementationSet","type":"event"},{"stateMutability":"nonpayable","type":"fallback"},{"inputs":[{"internalType":"address","name":"newImplementation_","type":"address"}],"name":"setImplementation","outputs":[],"stateMutability":"nonpayable","type":"function"}]