编译器
0.8.13+commit.abaa5c0e
文件 1 的 6: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 的 6:IERC1155.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC1155 is IERC165 {
event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value);
event TransferBatch(
address indexed operator,
address indexed from,
address indexed to,
uint256[] ids,
uint256[] values
);
event ApprovalForAll(address indexed account, address indexed operator, bool approved);
event URI(string value, uint256 indexed id);
function balanceOf(address account, uint256 id) external view returns (uint256);
function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids)
external
view
returns (uint256[] memory);
function setApprovalForAll(address operator, bool approved) external;
function isApprovedForAll(address account, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 id,
uint256 amount,
bytes calldata data
) external;
function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) external;
}
文件 3 的 6:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 4 的 6: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
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function setApprovalForAll(address operator, bool _approved) external;
function isApprovedForAll(address owner, address operator) external view returns (bool);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}
文件 5 的 6: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() {
_transferOwnership(_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 {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 6 的 6:PrimeApeInfector.sol
pragma solidity ^0.8.11;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC1155/IERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
abstract contract IPoisonedBananas is IERC1155 {
function burnSingle(address bananaOwner, uint256 bananaType) external {}
}
contract IInfectedApePlanet {
function mintTo(uint256 amount, address _to) external {}
}
contract PrimeApeInfector is Ownable {
IERC721 public primeApeNFT;
IPoisonedBananas public bananas;
IInfectedApePlanet public infectedApes;
bool public infectingOpen;
uint256 public primeApeOffset = 7979;
uint256 public nextLevelThreeId = 1;
mapping(uint256 => mapping(uint256 => bool)) public apeInfected;
mapping(uint256 => bool) public isLegendary;
event Infect(address infector, uint256 indexed apeId, uint256 indexed bananaType, uint256 indexed infectedApeId);
event ReceivedEther(address indexed sender, uint256 indexed amount);
event WithdrawAllEvent(address indexed to, uint256 amount);
constructor(
address _ape,
address _banana,
address _infected
) Ownable() {
primeApeNFT = IERC721(_ape);
bananas = IPoisonedBananas(_banana);
infectedApes = IInfectedApePlanet(_infected);
}
function _getInfectedApeId(uint256 apeId, uint256 bananaType) internal view returns (uint256) {
if (bananaType == 2) {
return nextLevelThreeId + primeApeOffset * bananaType;
}
return apeId + primeApeOffset * bananaType;
}
function infectApe(uint256 apeId, uint256 bananaType) external {
require(infectingOpen, "Infection closed");
require(primeApeNFT.ownerOf(apeId) == msg.sender, "Sender not owner of ape");
require(bananas.balanceOf(msg.sender, bananaType) > 0, "Sender not owner of banana type");
require(bananaType < 3, "Wrong banana type");
if (isLegendary[apeId]) {
require(!apeInfected[apeId][0] && !apeInfected[apeId][1] && !apeInfected[apeId][2], "Legendary already infected");
nextLevelThreeId++;
} else {
require(!apeInfected[apeId][bananaType], "Ape already infected by banana");
}
apeInfected[apeId][bananaType] = true;
uint256 infectedApeId = _getInfectedApeId(apeId, bananaType);
bananas.burnSingle(msg.sender, bananaType);
infectedApes.mintTo(infectedApeId, msg.sender);
emit Infect(msg.sender, apeId, bananaType, infectedApeId);
}
function getInfectedByLevel(uint256[] calldata apeIds, uint256 bananaType) external view returns (uint256[] memory) {
uint256 length = apeIds.length;
uint256[] memory infectedApesByLevel = new uint256[](length);
uint256 counter;
for (uint256 i = 0; i < apeIds.length; i++) {
uint256 apeId = apeIds[i];
if (apeInfected[apeId][bananaType]) {
infectedApesByLevel[counter] = apeId;
counter++;
}
}
return infectedApesByLevel;
}
function setContracts(address _ape, address _banana, address _infected) external onlyOwner {
primeApeNFT = IERC721(_ape);
bananas = IPoisonedBananas(_banana);
infectedApes = IInfectedApePlanet(_infected);
}
function setLegendaries(uint256[] calldata legendaryIds) external onlyOwner {
for (uint i = 0; i < legendaryIds.length; i++) {
isLegendary[legendaryIds[i]] = true;
}
}
function resetLegendaries(uint256[] calldata legendaryIds) external onlyOwner {
for (uint i = 0; i < legendaryIds.length; i++) {
isLegendary[legendaryIds[i]] = false;
}
}
function setInfectingOpen(bool open) external onlyOwner {
infectingOpen = open;
}
function withdrawAll(address _to) external onlyOwner {
require(_to != address(0), "CANNOT WITHDRAW TO ZERO ADDRESS");
uint256 contractBalance = address(this).balance;
require(contractBalance > 0, "NO ETHER TO WITHDRAW");
payable(_to).transfer(contractBalance);
emit WithdrawAllEvent(_to, contractBalance);
}
receive() external payable {
emit ReceivedEther(msg.sender, msg.value);
}
}
{
"compilationTarget": {
"contracts/PrimeApeInfector.sol": "PrimeApeInfector"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 1000
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"_ape","type":"address"},{"internalType":"address","name":"_banana","type":"address"},{"internalType":"address","name":"_infected","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"infector","type":"address"},{"indexed":true,"internalType":"uint256","name":"apeId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"bananaType","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"infectedApeId","type":"uint256"}],"name":"Infect","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"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ReceivedEther","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"WithdrawAllEvent","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"apeInfected","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bananas","outputs":[{"internalType":"contract IPoisonedBananas","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"apeIds","type":"uint256[]"},{"internalType":"uint256","name":"bananaType","type":"uint256"}],"name":"getInfectedByLevel","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"apeId","type":"uint256"},{"internalType":"uint256","name":"bananaType","type":"uint256"}],"name":"infectApe","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"infectedApes","outputs":[{"internalType":"contract IInfectedApePlanet","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"infectingOpen","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"isLegendary","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextLevelThreeId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"primeApeNFT","outputs":[{"internalType":"contract IERC721","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"primeApeOffset","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"legendaryIds","type":"uint256[]"}],"name":"resetLegendaries","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_ape","type":"address"},{"internalType":"address","name":"_banana","type":"address"},{"internalType":"address","name":"_infected","type":"address"}],"name":"setContracts","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"open","type":"bool"}],"name":"setInfectingOpen","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"legendaryIds","type":"uint256[]"}],"name":"setLegendaries","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"}],"name":"withdrawAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]