编译器
0.8.21+commit.d9974bed
文件 1 的 9:AccessControl.sol
pragma solidity ^0.8.20;
import {IAccessControl} from "./IAccessControl.sol";
import {Context} from "../utils/Context.sol";
import {ERC165} from "../utils/introspection/ERC165.sol";
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
mapping(bytes32 role => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
function hasRole(bytes32 role, address account) public view virtual returns (bool) {
return _roles[role].hasRole[account];
}
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
function getRoleAdmin(bytes32 role) public view virtual returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
if (!hasRole(role, account)) {
_roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
if (hasRole(role, account)) {
_roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}
文件 2 的 9:Context.sol
pragma solidity ^0.8.20;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
文件 3 的 9:CrappyAchievements.sol
pragma solidity ^0.8.21;
import {ICrappsToken} from "./interfaces/ICrappsToken.sol";
import {ICrappyAchievements} from "./interfaces/ICrappyAchievements.sol";
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
contract CrappyAchievements is AccessControl, ICrappyAchievements {
bytes32 constant public OWNER = keccak256("OWNER");
bytes32 constant public NOTIFIER = keccak256("NOTIFIER");
ICrappsToken private _crapps;
mapping(address => mapping(RewardType => uint256)) private _userData;
mapping(uint256 rewardIndex => mapping(address => bool)) private _redeemedRewards;
Reward[] private _rewards;
constructor(address initialCrapps) {
_crapps = ICrappsToken(initialCrapps);
_setRoleAdmin(NOTIFIER, OWNER);
_grantRole(OWNER, _msgSender());
}
function transferOwnership(address newOwner) public override onlyRole(OWNER) {
_transferOwnership(_msgSender(), newOwner);
}
function setCrapps(address newCrapps) public override onlyRole(OWNER) {
if (address(_crapps) == newCrapps) {
return;
}
address previousCrapps = address(_crapps);
_crapps = ICrappsToken(newCrapps);
emit CrappyAchievementsCrappsChanged(previousCrapps, newCrapps);
}
function addReward(Reward calldata rewardData) external override onlyRole(OWNER) {
_rewards.push() = rewardData;
emit CrappyAchievementsRewardAdded(rewardData, _rewards.length - 1);
}
function redeemReward(uint256 rewardIndex) public override {
if (_rewards.length <= rewardIndex) {
revert CrappyAchievementsRewardDoesNotExist();
}
if (_redeemedRewards[rewardIndex][_msgSender()]) {
revert CrappyAchievementsRewardAlreadyRedeemed();
}
mapping(RewardType => uint256) storage thisUserData = _userData[_msgSender()];
Reward storage rewardData = _rewards[rewardIndex];
if (rewardData.requirement > thisUserData[rewardData.rewardType]) {
revert CrappyAchievementsRewardRequirementNotSatisfied(rewardData.requirement);
}
_redeemedRewards[rewardIndex][_msgSender()] = true;
_crapps.mint(_msgSender(), rewardData.rewardAmount);
_notify(_msgSender(), RewardType.TotalCrappsRedeemed, rewardData.rewardAmount);
emit CrappyAchievementsRewardRedeemed(rewardIndex, _msgSender());
}
function notify(address user, RewardType rewardType, uint256 value) public override onlyRole(NOTIFIER) {
_notify(user, rewardType, value);
}
function batchNotify(address user, RewardType[] memory rewardTypes, uint256[] memory values) public override onlyRole(NOTIFIER) {
require(rewardTypes.length == values.length, "Reward types and values must match length.");
for (uint256 i = 0; i < rewardTypes.length; ++i) {
_notify(user, rewardTypes[i], values[i]);
}
}
function rewardCount() public view override returns (uint256) {
return _rewards.length;
}
function rewards(uint256 start, uint256 count) public view override returns (Reward[] memory batch) {
batch = new Reward[](count);
for (uint256 i = start; i < start + count; ++i) {
batch[i] = _rewards[i];
}
}
function rewards() public view override returns (Reward[] memory) {
return _rewards;
}
function reward(uint256 rewardIndex) public view override returns (Reward memory) {
return _rewards[rewardIndex];
}
function betsPlaced(address user) public view override returns (uint256) {
return _userData[user][RewardType.BetsPlaced];
}
function totalCrappsEarned(address user) public view override returns (uint256) {
return _userData[user][RewardType.TotalCrappsEarned];
}
function totalCrappsRedeemed(address user) public view override returns (uint256) {
return _userData[user][RewardType.TotalCrappsRedeemed];
}
function totalCrappsSpent(address user) public view override returns (uint256) {
return _userData[user][RewardType.TotalCrappsSpent];
}
function totalCrappySkins(address user) public view override returns (uint256) {
return _userData[user][RewardType.TotalCrappySkins];
}
function totalCrushWins(address user) public view override returns (uint256) {
return _userData[user][RewardType.TotalCrushWins];
}
function totalCrushWinnings(address user) public view override returns (uint256) {
return _userData[user][RewardType.TotalCrushWinnings];
}
function highestCrushWin(address user) public view override returns (uint256) {
return _userData[user][RewardType.HighestCrushWin];
}
function highestCrushMultiplier(address user) public view override returns (uint256) {
return _userData[user][RewardType.HighestCrushMultiplier];
}
function crapps() public view returns (ICrappsToken) {
return _crapps;
}
function userData(address user, RewardType rewardType) public view override returns (uint256) {
return _userData[user][rewardType];
}
function redeemedRewards(uint256 rewardIndex, address user) public view override returns (bool) {
return _redeemedRewards[rewardIndex][user];
}
function _transferOwnership(address previousOwner, address newOwner) private {
if (newOwner == address(0)) {
revert CrappyAchievementsInvalidOwner();
}
_revokeRole(OWNER, previousOwner);
_grantRole(OWNER, newOwner);
}
function _notify(address user, RewardType rewardType, uint256 value) private {
uint256 previousValue = _userData[user][rewardType];
uint256 newValue;
if (rewardType == RewardType.HighestCrushWin || rewardType == RewardType.HighestCrushMultiplier) {
if (previousValue >= value) {
return;
}
newValue = value;
} else {
newValue = _userData[user][rewardType] + value;
if (previousValue == newValue) {
return;
}
}
_userData[user][rewardType] = newValue;
emit CrappyAchievementsNotify(user, rewardType, previousValue, newValue);
}
}
文件 4 的 9:ERC165.sol
pragma solidity ^0.8.20;
import {IERC165} from "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 5 的 9:IAccessControl.sol
pragma solidity ^0.8.20;
interface IAccessControl {
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
error AccessControlBadConfirmation();
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 callerConfirmation) external;
}
文件 6 的 9:ICrappsToken.sol
pragma solidity ^0.8.21;
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface ICrappsToken is IERC20, IAccessControl {
error CrappsTokenInvalidOwner();
error CannotTransferCrapps();
function transferOwnership(address newOwner) external;
function mint(address to, uint256 amount) external;
function burn(address from, uint256 amount) external;
}
文件 7 的 9:ICrappyAchievements.sol
pragma solidity ^0.8.21;
import {ICrappsToken} from "./ICrappsToken.sol";
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
interface ICrappyAchievements is IAccessControl {
event CrappyAchievementsNotify(address indexed user, RewardType rewardType, uint256 previousValue, uint256 newValue);
event CrappyAchievementsRewardAdded(Reward rewardData, uint256 rewardIndex);
event CrappyAchievementsRewardRedeemed(uint256 indexed rewardIndex, address indexed user);
event CrappyAchievementsCrappsChanged(address indexed previousCrapps, address indexed newCrapps);
error CrappyAchievementsInvalidOwner();
error CrappyAchievementsRewardDoesNotExist();
error CrappyAchievementsRewardAlreadyRedeemed();
error CrappyAchievementsRewardRequirementNotSatisfied(uint256 requirement);
enum RewardType {
BetsPlaced,
TotalCrappsEarned,
TotalCrappsRedeemed,
TotalCrappsSpent,
TotalCrappySkins,
TotalCrushWins,
TotalCrushWinnings,
HighestCrushWin,
HighestCrushMultiplier
}
struct Reward {
RewardType rewardType;
uint256 requirement;
uint256 rewardAmount;
}
function transferOwnership(address newOwner) external;
function setCrapps(address newCrapps) external;
function addReward(Reward calldata rewardData) external;
function redeemReward(uint256 rewardIndex) external;
function notify(address user, RewardType rewardType, uint256 value) external;
function batchNotify(address user, RewardType[] memory rewardTypes, uint256[] memory values) external;
function rewardCount() external view returns (uint256);
function rewards(uint256 start, uint256 count) external view returns (Reward[] memory batch);
function rewards() external view returns (Reward[] memory);
function reward(uint256 rewardIndex) external view returns (Reward memory);
function betsPlaced(address user) external view returns (uint256);
function totalCrappsEarned(address user) external view returns (uint256);
function totalCrappsRedeemed(address user) external view returns (uint256);
function totalCrappsSpent(address user) external view returns (uint256);
function totalCrappySkins(address user) external view returns (uint256);
function totalCrushWins(address user) external view returns (uint256);
function totalCrushWinnings(address user) external view returns (uint256);
function highestCrushWin(address user) external view returns (uint256);
function highestCrushMultiplier(address user) external view returns (uint256);
function crapps() external view returns (ICrappsToken);
function userData(address user, RewardType rewardType) external view returns (uint256);
function redeemedRewards(uint256 rewardIndex, address user) external view returns (bool);
}
文件 8 的 9:IERC165.sol
pragma solidity ^0.8.20;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 9 的 9:IERC20.sol
pragma solidity ^0.8.20;
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 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
{
"compilationTarget": {
"contracts/CrappyAchievements.sol": "CrappyAchievements"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"initialCrapps","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[],"name":"CrappyAchievementsInvalidOwner","type":"error"},{"inputs":[],"name":"CrappyAchievementsRewardAlreadyRedeemed","type":"error"},{"inputs":[],"name":"CrappyAchievementsRewardDoesNotExist","type":"error"},{"inputs":[{"internalType":"uint256","name":"requirement","type":"uint256"}],"name":"CrappyAchievementsRewardRequirementNotSatisfied","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousCrapps","type":"address"},{"indexed":true,"internalType":"address","name":"newCrapps","type":"address"}],"name":"CrappyAchievementsCrappsChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"enum ICrappyAchievements.RewardType","name":"rewardType","type":"uint8"},{"indexed":false,"internalType":"uint256","name":"previousValue","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newValue","type":"uint256"}],"name":"CrappyAchievementsNotify","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"enum ICrappyAchievements.RewardType","name":"rewardType","type":"uint8"},{"internalType":"uint256","name":"requirement","type":"uint256"},{"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"indexed":false,"internalType":"struct ICrappyAchievements.Reward","name":"rewardData","type":"tuple"},{"indexed":false,"internalType":"uint256","name":"rewardIndex","type":"uint256"}],"name":"CrappyAchievementsRewardAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"rewardIndex","type":"uint256"},{"indexed":true,"internalType":"address","name":"user","type":"address"}],"name":"CrappyAchievementsRewardRedeemed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NOTIFIER","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OWNER","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"enum ICrappyAchievements.RewardType","name":"rewardType","type":"uint8"},{"internalType":"uint256","name":"requirement","type":"uint256"},{"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"internalType":"struct ICrappyAchievements.Reward","name":"rewardData","type":"tuple"}],"name":"addReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"enum ICrappyAchievements.RewardType[]","name":"rewardTypes","type":"uint8[]"},{"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"batchNotify","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"betsPlaced","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"crapps","outputs":[{"internalType":"contract ICrappsToken","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"highestCrushMultiplier","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"highestCrushWin","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"enum ICrappyAchievements.RewardType","name":"rewardType","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"notify","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"rewardIndex","type":"uint256"}],"name":"redeemReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"rewardIndex","type":"uint256"},{"internalType":"address","name":"user","type":"address"}],"name":"redeemedRewards","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"rewardIndex","type":"uint256"}],"name":"reward","outputs":[{"components":[{"internalType":"enum ICrappyAchievements.RewardType","name":"rewardType","type":"uint8"},{"internalType":"uint256","name":"requirement","type":"uint256"},{"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"internalType":"struct ICrappyAchievements.Reward","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewardCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"start","type":"uint256"},{"internalType":"uint256","name":"count","type":"uint256"}],"name":"rewards","outputs":[{"components":[{"internalType":"enum ICrappyAchievements.RewardType","name":"rewardType","type":"uint8"},{"internalType":"uint256","name":"requirement","type":"uint256"},{"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"internalType":"struct ICrappyAchievements.Reward[]","name":"batch","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"rewards","outputs":[{"components":[{"internalType":"enum ICrappyAchievements.RewardType","name":"rewardType","type":"uint8"},{"internalType":"uint256","name":"requirement","type":"uint256"},{"internalType":"uint256","name":"rewardAmount","type":"uint256"}],"internalType":"struct ICrappyAchievements.Reward[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newCrapps","type":"address"}],"name":"setCrapps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"totalCrappsEarned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"totalCrappsRedeemed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"totalCrappsSpent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"totalCrappySkins","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"totalCrushWinnings","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"totalCrushWins","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"enum ICrappyAchievements.RewardType","name":"rewardType","type":"uint8"}],"name":"userData","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}]