编译器
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:MicroGatewayV2.sol
pragma solidity ^0.8.13;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "../MicroUtilityV4.sol";
interface MicroNFT {
struct SaleConfiguration {
uint64 editionSize;
uint16 profitSharing;
address payable fundsRecipient;
uint256 publicSalePrice;
uint32 maxSalePurchasePerAddress;
uint64 publicSaleStart;
uint64 publicSaleEnd;
bytes32 presaleMerkleRoot;
bool cancelable;
}
function saleConfig() external view returns (SaleConfiguration memory);
function purchase(
address minter,
uint256 quantity
) external returns (uint256);
function purchasePresale(
address minter,
uint256 quantity,
bytes32[] calldata merkleProof
) external returns (uint256);
}
contract MicroGatewayV2 is Ownable, ReentrancyGuard, MicroUtilityV4 {
using SafeMath for uint256;
bool private _initialized;
uint256 private percenPerDiscount = 1000;
uint256 private percentCreator = 2000;
uint256 private percenPerRef = 2000;
uint256 private feeDenominator = 10000;
error PurchaseWrongPrice(uint256 correctPrice);
error Unauthorized();
event NewCollectionMinted(
address indexed sender,
address indexed contractAddress,
uint256 quantity
);
event FundsWithdrawn(
address indexed sender,
address indexed fundsRecipient,
uint256 fund
);
function init(bytes memory initPayload) external returns (bool) {
if (_initialized) {
revert Unauthorized();
}
(address _owner, address _manager) = abi.decode(
initPayload,
(address, address)
);
transferOwnership(_owner);
_setManager(_manager);
_initialized = true;
return true;
}
function requestPurchase(
address nftAddress,
uint256 quantity,
address referral
) external payable nonReentrant {
address minter = msg.sender;
_isMinting(minter, nftAddress, quantity, referral);
MicroNFT(nftAddress).purchase(minter, quantity);
emit NewCollectionMinted(minter, nftAddress, quantity);
}
function requestPresale(
address nftAddress,
uint256 quantity,
bytes32[] calldata merkleProof,
address referral
) external payable nonReentrant {
address minter = msg.sender;
_isMinting(minter, nftAddress, quantity, referral);
MicroNFT(nftAddress).purchasePresale(minter, quantity, merkleProof);
emit NewCollectionMinted(minter, nftAddress, quantity);
}
function _payoutFundingRaise(
uint256 totalPurchase,
address fundsRecipient
) internal returns (bool) {
if (fundsRecipient == address(0) || totalPurchase == 0) {
return false;
}
_payoutRemainder(fundsRecipient, totalPurchase);
emit FundsWithdrawn(msg.sender, fundsRecipient, totalPurchase);
return true;
}
function _isMinting(
address minter,
address nftAddress,
uint256 quantity,
address referral
) internal {
if (minter == referral) {
revert Unauthorized();
}
MicroNFT.SaleConfiguration memory saleConfig = MicroNFT(nftAddress)
.saleConfig();
uint256 salePrice = saleConfig.publicSalePrice.mul(quantity);
uint256 protocolFee = getMicroFeeWei(quantity);
uint256 totalFee = salePrice.add(protocolFee);
uint256 creatorFee = protocolFee.mul(percentCreator).div(
feeDenominator
);
if (msg.value < totalFee) {
revert PurchaseWrongPrice(totalFee);
}
if (referral == address(0)) {
_payoutMicroFee(protocolFee.sub(creatorFee));
_payoutFundingRaise(
salePrice.add(creatorFee),
saleConfig.fundsRecipient
);
_payoutRemainder(minter, msg.value.sub(totalFee));
} else {
uint256 refProtocolFee = protocolFee.mul(percenPerRef).div(
feeDenominator
);
uint256 discountProtocolFee = protocolFee
.mul(percenPerDiscount)
.div(feeDenominator);
uint256 profitSharing = salePrice.mul(saleConfig.profitSharing).div(
100
);
uint256 treasuryFee = protocolFee
.sub(refProtocolFee)
.sub(discountProtocolFee)
.sub(creatorFee);
_payoutMicroFee(treasuryFee);
_payoutFundingRaise(
salePrice.add(creatorFee).sub(profitSharing),
saleConfig.fundsRecipient
);
_payoutRemainder(referral, refProtocolFee.add(profitSharing));
_payoutRemainder(
minter,
msg.value.sub(totalFee).add(discountProtocolFee)
);
}
}
function configFee(
uint256 _creator,
uint256 _discount,
uint256 _referral
) external onlyOwner {
percentCreator = _creator;
percenPerDiscount = _discount;
percenPerRef = _referral;
}
function editManager(address _manager) external onlyOwner {
_setManager(_manager);
}
}
文件 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/minter/MicroGatewayV2.sol": "MicroGatewayV2"
},
"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":"fundsRecipient","type":"address"},{"indexed":false,"internalType":"uint256","name":"fund","type":"uint256"}],"name":"FundsWithdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"contractAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"quantity","type":"uint256"}],"name":"NewCollectionMinted","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":"uint256","name":"_creator","type":"uint256"},{"internalType":"uint256","name":"_discount","type":"uint256"},{"internalType":"uint256","name":"_referral","type":"uint256"}],"name":"configFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_manager","type":"address"}],"name":"editManager","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":"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":"nftAddress","type":"address"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"bytes32[]","name":"merkleProof","type":"bytes32[]"},{"internalType":"address","name":"referral","type":"address"}],"name":"requestPresale","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"nftAddress","type":"address"},{"internalType":"uint256","name":"quantity","type":"uint256"},{"internalType":"address","name":"referral","type":"address"}],"name":"requestPurchase","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]