编译器
0.8.14+commit.80d49f37
文件 1 的 11:Address.sol
pragma solidity 0.8.14;
library Address {
function isContract(address account) internal view returns (bool) {
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}
文件 2 的 11:ClaimManager.sol
pragma solidity 0.8.14;
import "../GovernanceManager/PVPOwnable.sol";
import "./IClaimManager.sol";
import "../lib/TransferHelper.sol";
import "../lib/Address.sol";
import "../GameMasterclass/IGame.sol";
import "../House/IHouseManager.sol";
contract ClaimManager is PVPOwnable, IClaimManager {
struct UserInfo {
uint256 pendingClaim;
uint256 totalClaimed;
mapping ( uint256 => mapping ( address => uint256 ) ) totalWonByGame;
}
mapping ( address => UserInfo ) private userInfo;
modifier onlyCreditor() {
require(
manager.isGame(msg.sender) ||
msg.sender == manager.house() ||
IHouseManager(IProjectTokensManager(manager.projectTokens()).houseManager()).isHouse(msg.sender),
'UnAuthorized'
);
_;
}
function credit(
uint256 GAME_ID,
address user
) external payable override onlyCreditor {
unchecked {
userInfo[user].pendingClaim += msg.value;
userInfo[user].totalWonByGame[GAME_ID][address(0)] += msg.value;
}
}
function creditToken(
address user,
address token,
uint256 GAME_ID,
uint256 amount
) external override onlyCreditor {
unchecked {
userInfo[user].totalWonByGame[GAME_ID][token] += amount;
}
}
function claimFor(address[] calldata users) external onlyOwner {
for (uint256 i = 0; i < users.length;) {
_claim(users[i]);
unchecked { ++i; }
}
}
function claim() external {
_claim(msg.sender);
}
function claimAndCall(address to, uint256 amount, bytes calldata data) external payable {
require(
manager.isGame(to),
'Can Only Call Games'
);
uint256 pending = userInfo[msg.sender].pendingClaim;
require(pending > 0, 'Zero Claimable Amount');
if (amount > pending) {
amount = pending;
}
unchecked {
userInfo[msg.sender].totalClaimed += amount;
userInfo[msg.sender].pendingClaim -= amount;
}
if (userInfo[msg.sender].pendingClaim > 0) {
_claim(msg.sender);
}
IGame(to).play{value: ( amount + msg.value )}(msg.sender, address(0), 0, data);
}
function _claim(address user) internal {
uint256 pending = userInfo[user].pendingClaim;
if (pending == 0) {
return;
}
unchecked {
userInfo[user].totalClaimed += pending;
}
delete userInfo[user].pendingClaim;
TransferHelper.safeTransferETH(user, pending);
}
function getTotalWonByGame(address user, uint256 GAME_ID, address token) external view returns (uint256) {
return userInfo[user].totalWonByGame[GAME_ID][token];
}
function pendingClaim(address user) external view returns (uint256) {
return userInfo[user].pendingClaim;
}
function totalClaimed(address user) external view returns (uint256) {
return userInfo[user].totalClaimed;
}
function totalValueEarned(address user) external view returns (uint256) {
return userInfo[user].pendingClaim + userInfo[user].totalClaimed;
}
function totalWonForToken(address user, address token, uint256[] calldata GAME_IDs) external view returns (uint256[] memory) {
uint256[] memory wonByGames = new uint256[](GAME_IDs.length);
for (uint i = 0; i < GAME_IDs.length; i++) {
wonByGames[i] = userInfo[user].totalWonByGame[GAME_IDs[i]][token];
}
return wonByGames;
}
}
文件 3 的 11:IClaimManager.sol
pragma solidity 0.8.14;
interface IClaimManager {
function credit(
uint256 GAME_ID,
address user
) external payable;
function creditToken(
address user,
address token,
uint256 GAME_ID,
uint256 amount
) external;
}
文件 4 的 11:IFeeRecipient.sol
pragma solidity 0.8.14;
interface IFeeRecipient {
function takeFee(address token, uint256 amount, uint256 partner, address ref) external payable;
}
文件 5 的 11:IGame.sol
pragma solidity 0.8.14;
interface IGame {
function fulfillRandomWords(
uint256 requestId,
uint256[] calldata randomWords
) external;
function play(address user, address token, uint256 amount, bytes calldata gameData) external payable;
}
文件 6 的 11:IGovernanceManager.sol
pragma solidity 0.8.14;
interface IGovernanceManager {
function RNG() external view returns (address);
function owner() external view returns (address);
function chainlinkFeeReceiver() external view returns (address);
function chainlinkSubscriptionOwner() external view returns (address);
function referralManager() external view returns (address);
function projectTokens() external view returns (address);
function feeReceiver() external view returns (address);
function claimManager() external view returns (address);
function house() external view returns (address);
function isGame(address game) external view returns (bool);
function userInfoTracker() external view returns (address);
}
文件 7 的 11:IHouseManager.sol
pragma solidity 0.8.14;
interface IHouseManager {
function isHouse(address house) external view returns (bool);
function houseFor(address token) external view returns (address);
function createHouse(address token) external returns (address house);
}
文件 8 的 11:IProjectTokensManager.sol
pragma solidity 0.8.14;
interface IProjectTokensManager {
function isValidPartner(uint256 partnerNonce) external view returns (bool);
function getFundReceiver(uint256 partner) external view returns (address);
function isListedToken(address token) external view returns (bool);
function getWrapper(address token) external view returns (address);
function getHouse(address token) external view returns (address);
function getViewer(address token) external view returns (address);
function isWrappedAsset(address wrapper) external view returns (bool);
function canPlayForOthers(address addr) external view returns (bool);
function wrappedAssetManager() external view returns (address);
function houseManager() external view returns (address);
}
文件 9 的 11:IRNG.sol
pragma solidity 0.8.14;
interface IRNG {
function requestRandom(uint32 gas, uint32 numResults) external returns (uint256 requestId);
}
文件 10 的 11:PVPOwnable.sol
pragma solidity 0.8.14;
import "./IFeeRecipient.sol";
import "./IGovernanceManager.sol";
import "../ProjectTokens/IProjectTokensManager.sol";
import "../RNGTracker/IRNG.sol";
contract PVPOwnable {
IGovernanceManager public constant manager = IGovernanceManager(0x22164a57446aD5dE1DBE831784D8029773941678);
modifier onlyOwner() {
require(
msg.sender == manager.owner(),
'Only Owner'
);
_;
}
modifier onlyGame() {
require(
manager.isGame(msg.sender),
'UnAuthorized'
);
_;
}
modifier onlyRNG() {
require(
msg.sender == manager.RNG(),
'Only RNG Contract'
);
_;
}
modifier onlyValidToken(address token_) {
require(
IProjectTokensManager(manager.projectTokens()).isWrappedAsset(token_),
'Invalid Token'
);
_;
}
modifier validGameToken(address token_) {
require(
token_ == address(0) || IProjectTokensManager(manager.projectTokens()).isWrappedAsset(token_),
'Invalid Token'
);
_;
}
modifier validatePlayer(address player) {
if (player != msg.sender) {
require(
IProjectTokensManager(manager.projectTokens()).canPlayForOthers(msg.sender),
'UnAuthorized To Play For Others'
);
}
_;
}
}
文件 11 的 11:TransferHelper.sol
pragma solidity 0.8.14;
library TransferHelper {
function safeApprove(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeApprove: approve failed'
);
}
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::safeTransfer: transfer failed'
);
}
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
require(
success && (data.length == 0 || abi.decode(data, (bool))),
'TransferHelper::transferFrom: transferFrom failed'
);
}
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'TransferHelper::safeTransferETH: ETH transfer failed');
}
}
{
"compilationTarget": {
"contracts/ClaimManager/ClaimManager.sol": "ClaimManager"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"claimAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address[]","name":"users","type":"address[]"}],"name":"claimFor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"GAME_ID","type":"uint256"},{"internalType":"address","name":"user","type":"address"}],"name":"credit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"GAME_ID","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"creditToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"GAME_ID","type":"uint256"},{"internalType":"address","name":"token","type":"address"}],"name":"getTotalWonByGame","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"manager","outputs":[{"internalType":"contract IGovernanceManager","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"pendingClaim","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"totalClaimed","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"totalValueEarned","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256[]","name":"GAME_IDs","type":"uint256[]"}],"name":"totalWonForToken","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"}]