编译器
0.8.13+commit.abaa5c0e
文件 1 的 8:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 2 的 8:IMicroManager.sol
pragma solidity >=0.5.0;
interface IMicroManager {
function microBridge(address _address) external view returns (bool);
function treasuryAddress() external view returns (address);
function microProtocolFee() external view returns (uint256);
function oracleAddress() external view returns (address);
}
文件 3 的 8:IPriceOracle.sol
pragma solidity >=0.5.0;
interface IPriceOracle {
function convertUsdToWei(uint256 usdAmount) external view returns (uint256 weiAmount);
}
文件 4 的 8:MicroMinimal.sol
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "../MicroUtilityV4.sol";
contract MicroMinimal is Ownable, ReentrancyGuard, MicroUtilityV4 {
address public microERC721;
bool private _initialized;
mapping(address => bool) public dropInfos;
error PurchaseWrongPrice(uint256 correctPrice);
error Unauthorized();
event NewCollectionDeployed(
address indexed sender,
address indexed contractAddress
);
function init(bytes memory initPayload) external returns (bool) {
if (_initialized) {
revert Unauthorized();
}
(address _owner, address _manager, address _microERC721) = abi.decode(
initPayload,
(address, address, address)
);
transferOwnership(_owner);
microERC721 = _microERC721;
_setManager(_manager);
_initialized = true;
return true;
}
function deployWithPayload(bytes12 saltHash, bytes memory initCode)
external
payable
nonReentrant
{
uint256 protocolFee = getMicroFeeWei(uint256(1));
if (msg.value < protocolFee) {
revert PurchaseWrongPrice(protocolFee);
}
address sender = msg.sender;
bytes32 _salt = keccak256(abi.encodePacked(sender, saltHash));
address proxyAddress = deployMinimal(
microERC721,
abi.encodeWithSignature("init(bytes)", initCode),
_salt
);
_payoutMicroFee(protocolFee);
_payoutRemainder(sender, msg.value - protocolFee);
dropInfos[proxyAddress] = true;
emit NewCollectionDeployed(sender, proxyAddress);
}
function editMicro(address _microERC721) onlyOwner external {
microERC721 = _microERC721;
}
function editManager(address _manager) onlyOwner external {
_setManager(_manager);
}
function deployMinimal(
address _logic,
bytes memory _data,
bytes32 salt
) internal returns (address proxy) {
bytes20 targetBytes = bytes20(_logic);
assembly {
let clone := mload(0x40)
mstore(
clone,
0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000000000000000000000
)
mstore(add(clone, 0x14), targetBytes)
mstore(
add(clone, 0x28),
0x5af43d82803e903d91602b57fd5bf30000000000000000000000000000000000
)
proxy := create2(0, clone, 0x37, salt)
}
if (_data.length > 0) {
(bool success, ) = proxy.call(_data);
require(success);
}
}
}
文件 5 的 8:MicroUtilityV4.sol
pragma solidity ^0.8.4;
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {IPriceOracle} from "./interfaces/IPriceOracle.sol";
import {IMicroManager} from "./interfaces/IMicroManager.sol";
error PaymentFailed();
contract MicroUtilityV4 {
using SafeMath for uint256;
IMicroManager public microManager;
uint256 private constant STATIC_GAS_LIMIT = 210_000;
event FeePayout(
uint256 MicroMintFeeWei,
address MicroFeeRecipient,
bool success
);
function getMicroFeeWei(uint256 quantity) public view returns (uint256) {
if (quantity == 0) {
return 0;
}
return
IPriceOracle(microManager.oracleAddress()).convertUsdToWei(
microManager.microProtocolFee().mul(quantity)
);
}
function _payoutMicroFee(uint256 microProtocolFee) internal {
address treasury = microManager.treasuryAddress();
_payoutRemainder(treasury, microProtocolFee);
emit FeePayout(microProtocolFee, treasury, true);
}
function _setManager(address _manager) internal {
microManager = IMicroManager(_manager);
}
function _payoutRemainder(address recipient, uint256 value) internal {
if (value > 0) {
(bool success, ) = payable(recipient).call{
value: value,
gas: gasleft() > STATIC_GAS_LIMIT ? STATIC_GAS_LIMIT : gasleft()
}("");
if (!success) {
revert PaymentFailed();
}
}
}
}
文件 6 的 8:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_setOwner(_msgSender());
}
function owner() public view virtual returns (address) {
return _owner;
}
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 7 的 8:ReentrancyGuard.sol
pragma solidity ^0.8.0;
abstract contract ReentrancyGuard {
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
modifier nonReentrant() {
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
_status = _ENTERED;
_;
_status = _NOT_ENTERED;
}
}
文件 8 的 8:SafeMath.sol
pragma solidity ^0.8.0;
library SafeMath {
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}
{
"compilationTarget": {
"contracts/proxy/MicroMinimal.sol": "MicroMinimal"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"name":"PaymentFailed","type":"error"},{"inputs":[{"internalType":"uint256","name":"correctPrice","type":"uint256"}],"name":"PurchaseWrongPrice","type":"error"},{"inputs":[],"name":"Unauthorized","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"MicroMintFeeWei","type":"uint256"},{"indexed":false,"internalType":"address","name":"MicroFeeRecipient","type":"address"},{"indexed":false,"internalType":"bool","name":"success","type":"bool"}],"name":"FeePayout","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"}],"name":"NewCollectionDeployed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"bytes12","name":"saltHash","type":"bytes12"},{"internalType":"bytes","name":"initCode","type":"bytes"}],"name":"deployWithPayload","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"dropInfos","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_manager","type":"address"}],"name":"editManager","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_microERC721","type":"address"}],"name":"editMicro","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"quantity","type":"uint256"}],"name":"getMicroFeeWei","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"initPayload","type":"bytes"}],"name":"init","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"microERC721","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"microManager","outputs":[{"internalType":"contract IMicroManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]