编译器
0.8.16+commit.07a7930e
文件 1 的 16:IAccessControl.sol
pragma solidity ^0.8.0;
interface IAccessControl {
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address account) external;
}
文件 2 的 16:IAuctionManager.sol
pragma solidity ^0.8.0;
interface IAuctionManager {
struct CreateAuction {
uint104 reservePrice;
uint16 winners;
uint64 endsAt;
}
struct Auction {
uint104 reservePrice;
uint104 lowestWinningBid;
uint16 winners;
uint64 endsAt;
}
function get(uint256 id) external view returns (Auction memory);
function getBid(uint256 id, address sender) external view returns (uint104);
function isWinner(uint256 id, address sender) external view returns (bool);
function create(uint256 id, CreateAuction calldata auction) external;
function close(uint256 id, uint104 lowestWinningBid, address[] calldata _tiebrokenWinners) external;
function bid(uint256 id, uint104 value, address sender) external returns (uint104);
function settle(uint256 id, address sender) external returns (uint104);
}
文件 3 的 16:IDoorbusterManager.sol
pragma solidity ^0.8.0;
interface IDoorbusterManager {
struct Doorbuster {
uint32 supply;
}
function get(uint256 id) external view returns (Doorbuster memory);
function create(uint256 id, uint32 supply) external;
function purchase(uint256 id, uint32 amount) external;
function purchase(
uint256 id,
uint32 amount,
uint256 nonce,
bytes memory signature
) external;
}
文件 4 的 16:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 5 的 16:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(
address from,
address to,
uint256 amount
) external returns (bool);
}
文件 6 的 16:IERC721.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function setApprovalForAll(address operator, bool _approved) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
文件 7 的 16:IKaijuMart.sol
pragma solidity ^0.8.0;
import "./IKingzInTheShell.sol";
import "./IMutants.sol";
import "./IScientists.sol";
import "./IScales.sol";
import "./IRWaste.sol";
import "./IKaijuMartRedeemable.sol";
import "./IAuctionManager.sol";
import "./IDoorbusterManager.sol";
import "./IRaffleManager.sol";
import "./IKaijuMart.sol";
interface IKaijuMart {
enum LotType {
NONE,
AUCTION,
RAFFLE,
DOORBUSTER
}
enum PaymentToken {
RWASTE,
SCALES,
EITHER
}
struct Lot {
uint104 rwastePrice;
uint104 scalesPrice;
LotType lotType;
PaymentToken paymentToken;
IKaijuMartRedeemable redeemer;
}
struct CreateLot {
PaymentToken paymentToken;
IKaijuMartRedeemable redeemer;
}
struct KaijuContracts {
IKingzInTheShell kaiju;
IMutants mutants;
IScientists scientists;
IRWaste rwaste;
IScales scales;
}
struct ManagerContracts {
IAuctionManager auction;
IDoorbusterManager doorbuster;
IRaffleManager raffle;
}
event Create(
uint256 indexed id,
LotType indexed lotType,
address indexed managerContract
);
event Bid(
uint256 indexed id,
address indexed account,
uint104 value
);
event Redeem(
uint256 indexed id,
uint32 indexed amount,
address indexed to,
IKaijuMartRedeemable redeemer
);
event Refund(
uint256 indexed id,
address indexed account,
uint104 value
);
event Purchase(
uint256 indexed id,
address indexed account,
uint64 amount
);
event Enter(
uint256 indexed id,
address indexed account,
uint64 amount
);
function isKing(address account) external view returns (bool);
function setKaijuContracts(KaijuContracts calldata _kaijuContracts) external;
function setManagerContracts(ManagerContracts calldata _managerContracts) external;
function getAuction(uint256 auctionId) external view returns (IAuctionManager.Auction memory);
function getBid(uint256 auctionId, address account) external view returns (uint104);
function createAuction(
uint256 lotId,
CreateLot calldata lot,
IAuctionManager.CreateAuction calldata auction
) external;
function close(
uint256 auctionId,
uint104 lowestWinningBid,
address[] calldata tiebrokenWinners
) external;
function bid(uint256 auctionId, uint104 value) external;
function refund(uint256 auctionId) external;
function redeem(uint256 auctionId) external;
function getRaffle(uint256 raffleId) external view returns (IRaffleManager.Raffle memory);
function createRaffle(
uint256 lotId,
CreateLot calldata lot,
uint104 rwastePrice,
uint104 scalesPrice,
IRaffleManager.CreateRaffle calldata raffle
) external;
function draw(uint256 raffleId, bool vrf) external;
function enter(uint256 raffleId, uint32 amount, PaymentToken token) external;
function getDoorbuster(uint256 doorbusterId) external view returns (IDoorbusterManager.Doorbuster memory);
function createDoorbuster(
uint256 lotId,
CreateLot calldata lot,
uint104 rwastePrice,
uint104 scalesPrice,
uint32 supply
) external;
function purchase(
uint256 doorbusterId,
uint32 amount,
PaymentToken token,
uint256 nonce,
bytes calldata signature
) external;
}
文件 8 的 16:IKaijuMartExtended.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/access/IAccessControl.sol";
import "./IKaijuMart.sol";
interface IKaijuMartExtended is IKaijuMart, IAccessControl {
function managerContracts() external view returns (ManagerContracts memory);
function lots(uint256 lotId) external view returns (Lot memory);
}
文件 9 的 16:IKaijuMartRedeemable.sol
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
pragma solidity ^0.8.0;
interface IKaijuMartRedeemable is IERC165 {
function kmartRedeem(uint256 lotId, uint32 amount, address to) external;
}
文件 10 的 16:IKingzInTheShell.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
interface IKingzInTheShell is IERC721 {
function isHolder(address) external view returns (bool);
}
文件 11 的 16:IMutants.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
interface IMutants is IERC721 {}
文件 12 的 16:IRWaste.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IRWaste is IERC20 {
function burn(address, uint256) external;
function claimLaboratoryExperimentRewards(address, uint256) external;
}
文件 13 的 16:IRaffleManager.sol
pragma solidity ^0.8.0;
interface IRaffleManager {
struct CreateRaffle {
uint64 scriptId;
uint64 winners;
uint64 endsAt;
}
struct Raffle {
uint256 seed;
uint64 scriptId;
uint64 winners;
uint64 endsAt;
}
function get(uint256 id) external view returns (Raffle memory);
function isDrawn(uint256 id) external view returns (bool);
function create(uint256 id, CreateRaffle calldata raffle) external;
function enter(uint256 id, uint32 amount) external;
function draw(uint256 id, bool vrf) external;
}
文件 14 的 16:IScales.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IScales is IERC20 {
function spend(address, uint256) external;
function credit(address, uint256) external;
}
文件 15 的 16:IScientists.sol
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
interface IScientists is IERC721 {}
文件 16 的 16:KaijuMartEtherPurchaseProcessor.sol
pragma solidity ^0.8.0;
import "./interfaces/IKaijuMartExtended.sol";
import "./interfaces/IKaijuMartRedeemable.sol";
error KaijuMartEtherPaymentProcessor_InsufficientPermissions();
error KaijuMartEtherPaymentProcessor_InvalidLotState();
error KaijuMartEtherPaymentProcessor_InvalidValue();
error KaijuMartEtherPaymentProcessor_MustBeAKing();
error KaijuMartEtherPaymentProcessor_WithdrawFailed();
contract KaijuMartEtherPurchaseProcessor {
IKaijuMartExtended public immutable KMART;
event Purchase(
uint256 indexed id,
address indexed account,
uint64 amount
);
struct Processor {
uint104 price;
bool enabled;
bool isRedeemable;
bool requiresKing;
bool requiresSignature;
}
IDoorbusterManager public doorbusterManager;
mapping(uint256 => Processor) public lotProcessors;
constructor(IKaijuMartExtended kmart) {
KMART = kmart;
doorbusterManager = KMART.managerContracts().doorbuster;
}
modifier onlyKMartAdmin() {
if (!KMART.hasRole(bytes32(0), msg.sender))
revert KaijuMartEtherPaymentProcessor_InsufficientPermissions();
_;
}
function refreshDoorbusterManager() public payable onlyKMartAdmin {
doorbusterManager = KMART.managerContracts().doorbuster;
}
function setLotProcessor(
uint256 _lotId,
Processor calldata _processor
)
public
payable
onlyKMartAdmin
{
IKaijuMartExtended.Lot memory lot = KMART.lots(_lotId);
if (uint8(lot.lotType) == 0) revert KaijuMartEtherPaymentProcessor_InvalidLotState();
lotProcessors[_lotId] = _processor;
lotProcessors[_lotId].isRedeemable = address(lot.redeemer) != address(0);
}
function purchase(uint256 _lotId, uint32 _amount) public payable {
Processor memory processor = lotProcessors[_lotId];
if (!processor.enabled || processor.requiresSignature) revert KaijuMartEtherPaymentProcessor_InvalidLotState();
if (msg.value != processor.price * _amount) revert KaijuMartEtherPaymentProcessor_InvalidValue();
if (processor.requiresKing && !KMART.isKing(msg.sender)) revert KaijuMartEtherPaymentProcessor_MustBeAKing();
doorbusterManager.purchase(_lotId, _amount);
if (processor.isRedeemable)
KMART.lots(_lotId).redeemer.kmartRedeem(_lotId, _amount, msg.sender);
emit Purchase(_lotId, msg.sender, _amount);
}
function purchase(
uint256 _lotId,
uint32 _amount,
uint256 _nonce,
bytes calldata _signature
)
public
payable
{
Processor memory processor = lotProcessors[_lotId];
if (!processor.enabled || !processor.requiresSignature) revert KaijuMartEtherPaymentProcessor_InvalidLotState();
if (msg.value != processor.price * _amount) revert KaijuMartEtherPaymentProcessor_InvalidValue();
if (processor.requiresKing && !KMART.isKing(msg.sender)) revert KaijuMartEtherPaymentProcessor_MustBeAKing();
doorbusterManager.purchase(_lotId, _amount, _nonce, _signature);
if (processor.isRedeemable)
KMART.lots(_lotId).redeemer.kmartRedeem(_lotId, _amount, msg.sender);
emit Purchase(_lotId, msg.sender, _amount);
}
function withdraw(address _receiver) public payable onlyKMartAdmin {
(bool success, ) = _receiver.call{ value: address(this).balance }("");
if (!success) revert KaijuMartEtherPaymentProcessor_WithdrawFailed();
}
}
{
"compilationTarget": {
"contracts/KaijuMartEtherPurchaseProcessor.sol": "KaijuMartEtherPurchaseProcessor"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"contract IKaijuMartExtended","name":"kmart","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"KaijuMartEtherPaymentProcessor_InsufficientPermissions","type":"error"},{"inputs":[],"name":"KaijuMartEtherPaymentProcessor_InvalidLotState","type":"error"},{"inputs":[],"name":"KaijuMartEtherPaymentProcessor_InvalidValue","type":"error"},{"inputs":[],"name":"KaijuMartEtherPaymentProcessor_MustBeAKing","type":"error"},{"inputs":[],"name":"KaijuMartEtherPaymentProcessor_WithdrawFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"uint64","name":"amount","type":"uint64"}],"name":"Purchase","type":"event"},{"inputs":[],"name":"KMART","outputs":[{"internalType":"contract IKaijuMartExtended","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"doorbusterManager","outputs":[{"internalType":"contract IDoorbusterManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"lotProcessors","outputs":[{"internalType":"uint104","name":"price","type":"uint104"},{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"bool","name":"isRedeemable","type":"bool"},{"internalType":"bool","name":"requiresKing","type":"bool"},{"internalType":"bool","name":"requiresSignature","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_lotId","type":"uint256"},{"internalType":"uint32","name":"_amount","type":"uint32"},{"internalType":"uint256","name":"_nonce","type":"uint256"},{"internalType":"bytes","name":"_signature","type":"bytes"}],"name":"purchase","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_lotId","type":"uint256"},{"internalType":"uint32","name":"_amount","type":"uint32"}],"name":"purchase","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"refreshDoorbusterManager","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_lotId","type":"uint256"},{"components":[{"internalType":"uint104","name":"price","type":"uint104"},{"internalType":"bool","name":"enabled","type":"bool"},{"internalType":"bool","name":"isRedeemable","type":"bool"},{"internalType":"bool","name":"requiresKing","type":"bool"},{"internalType":"bool","name":"requiresSignature","type":"bool"}],"internalType":"struct KaijuMartEtherPurchaseProcessor.Processor","name":"_processor","type":"tuple"}],"name":"setLotProcessor","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_receiver","type":"address"}],"name":"withdraw","outputs":[],"stateMutability":"payable","type":"function"}]