pragma solidity ^0.8.0;
contract DailyTreasureEvent {
address public owner;
mapping(address => uint256) public lifetimeChestCount;
mapping(address => uint256) public lifetimePremiumChestCount;
mapping(address => bool) public premiumUsers;
event ChestOpened(address indexed user, uint256 timestamp);
event PremiumChestOpened(address indexed user, uint256 timestamp);
event PremiumUserAdded(address user);
event PremiumUserRemoved(address user);
constructor(address[] memory initialPremiumUsers) {
owner = msg.sender;
for (uint256 i = 0; i < initialPremiumUsers.length; i++) {
premiumUsers[initialPremiumUsers[i]] = true;
}
}
function openChest() public {
lifetimeChestCount[msg.sender]++;
emit ChestOpened(msg.sender, block.timestamp);
}
function openPremiumChest() public {
require(isPremiumUser(msg.sender), "Only premium users can open premium chests");
lifetimePremiumChestCount[msg.sender]++;
emit PremiumChestOpened(msg.sender, block.timestamp);
}
function isPremiumUser(address user) public view returns (bool) {
return premiumUsers[user];
}
function addPremiumUser(address user) public {
require(msg.sender == owner, "Only the owner can add premium users");
premiumUsers[user] = true;
emit PremiumUserAdded(user);
}
function removePremiumUser(address user) public {
require(msg.sender == owner, "Only the owner can remove premium users");
premiumUsers[user] = false;
emit PremiumUserRemoved(user);
}
}
{
"compilationTarget": {
"DailyTreasureEvent.sol": "DailyTreasureEvent"
},
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address[]","name":"initialPremiumUsers","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"ChestOpened","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"timestamp","type":"uint256"}],"name":"PremiumChestOpened","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"}],"name":"PremiumUserAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"}],"name":"PremiumUserRemoved","type":"event"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"addPremiumUser","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"isPremiumUser","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lifetimeChestCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lifetimePremiumChestCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"openChest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"openPremiumChest","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"premiumUsers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"removePremiumUser","outputs":[],"stateMutability":"nonpayable","type":"function"}]