账户
0x27...2c0a
0x27...2c0A

0x27...2c0A

$500
此合同的源代码已经过验证!
合同元数据
编译器
0.8.27+commit.40a35a09
语言
Solidity
合同源代码
文件 1 的 6:Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)

pragma solidity ^0.8.20;

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
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;
    }
}
合同源代码
文件 2 的 6:IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.20;

/**
 * @dev Interface of the ERC-20 standard as defined in the ERC.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the value of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the value of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves a `value` amount of tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 value) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets a `value` amount of tokens as the allowance of `spender` over the
     * caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 value) external returns (bool);

    /**
     * @dev Moves a `value` amount of tokens from `from` to `to` using the
     * allowance mechanism. `value` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}
合同源代码
文件 3 的 6:IInfiniteGame.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/**
 * @title IInfiniteGame
 * @notice Interface for the Infinite Game
 */
interface IInfiniteGame {
    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       EVENTS                               */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /**
     * @notice Emitted when a player participates in a round
     * @param player Address of the player
     * @param paid Amount of tokens paid to play
     * @param round Current round number
     */
    event Played(address indexed player, uint256 paid, uint256 round);

    /**
     * @notice Emitted when a round is completed and prizes are distributed
     * @param winner Address of the round winner
     * @param winnerPrize Amount of tokens awarded to the winner
     * @param miscAmount Amount of tokens for the misc recipient
     * @param retainedAmount Amount of tokens retained for next round
     */
    event RoundCompleted(
        address indexed winner,
        uint256 winnerPrize,
        uint256 miscAmount,
        uint256 retainedAmount
    );

    /**
     * @notice Emitted when ERC20 tokens (except game token) are withdrawn
     * @param token Address of the withdrawn token
     * @param amount Amount of tokens withdrawn
     */
    event ERC20Withdrawn(address indexed token, uint256 amount);

    /**
     * @notice Emitted when prize distribution shares are updated
     * @param winnerShare New percentage for winner
     * @param miscShare New percentage for miscellanous recipient
     */
    event SharesSet(uint256 winnerShare, uint256 miscShare);

    /**
     * @notice Emitted when initial countdown duration is updated
     * @param newDuration New initial countdown duration in seconds
     */
    event InitialCountdownSet(uint256 newDuration);

    /**
     * @notice Emitted when target plays per hour is updated
     * @param newTarget New target number of plays per hour
     */
    event PlaysPerHourTargetSet(uint16 newTarget);

    /**
     * @notice Emitted when play fee is updated
     * @param newFee New fee amount in tokens
     */
    event FeeUpdated(uint256 newFee);

    /**
     * @notice Emitted when cooldown time between rounds is updated
     * @param newCooldownTime New cooldown duration in seconds
     */
    event CooldownTimeSet(uint256 newCooldownTime);

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                       ERRORS                               */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @notice Thrown when trying to interact with the game before start time
    error GameNotStarted();
    /// @notice Thrown when trying to set start time after game has already started
    error GameIsStarted();
    /// @notice Thrown when trying to play after round deadline has passed
    error NextRoundPending();
    /// @notice Thrown when trying to perform actions during an active round
    error NotAllowedDuringRound();
    /// @notice Thrown when trying to play during cooldown period
    error AwaitingCooldown();
    /// @notice Thrown when trying to set countdown duration below minimum
    error DurationTooLow();
    /// @notice Thrown when invalid parameters are provided for adjustments
    error InvalidAdjustment();
    /// @notice Thrown when attempting to update shares more than once per round
    error SharesAlreadyUpdatedThisRound();
    /// @notice Thrown when trying to update parameters before allowed timeframe
    error CannotUpdateYet();
    /// @notice Thrown when an address that isn't the admin or owner tries to make changes
    error NotAuthorized();

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                     MUTATION FUNCTIONS                     */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /**
     * @notice Allows a player to participate in the current round
     * @dev Transfers play fee from player and updates game state
     */
    function play() external;

    /**
     * @notice Finalizes the current round and distributes prizes
     * @dev Can only be called after round deadline has passed
     */
    function completeRound() external;

    /**
     * @notice Sets the initial countdown duration for new rounds
     * @dev Must be greater than minimum reset time
     * @param newDuration New initial countdown duration in seconds
     */
    function setInitialCountdown(uint16 newDuration) external;

    /**
     * @notice Updates the target number of plays per hour
     * @dev Can only be updated once per day and within bounds
     * @param newTarget New target number of plays per hour
     */
    function setPlaysPerHourTarget(uint16 newTarget) external;

    /**
     * @notice Updates the distribution shares for prizes
     * @dev Can only be called during cooldown and once per round
     * @param newWinnerShare Percentage for winner
     * @param newMiscShare Percentage for miscellanous recipient
     */
    function setShares(uint8 newWinnerShare, uint8 newMiscShare) external;

    /**
     * @notice Sets the cooldown time between rounds
     * @dev Must be between 1 minute and 1 week
     * @param newCooldownTime New cooldown duration in seconds
     */
    function setCooldownTime(uint16 newCooldownTime) external;

    /**
     * @notice Updates the miscellanous recipient address
     * @param newRecipient Address of the new recipient
     */
    function setMiscRecipient(address newRecipient) external;

    /**
     * @notice Updates the fee required to play
     * @param newFee New fee amount in tokens
     * @dev This is included as an emergency override
     *       in case the economics get off-kilter.
     */
    function setPlayFee(uint256 newFee) external;

    /**
     * @notice Allows owner to withdraw any ERC20 tokens except game token
     * @dev Cannot withdraw the game token
     * @param tokenAddress Address of token to withdraw
     */
    function withdrawERC20(address tokenAddress) external;

    /**
     * @notice Sets a new admin address
     * @param newAdmin The address of the new admin
     */
    function setNewAdmin(address newAdmin) external;

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                        VIEWS                               */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @notice Returns minimum time that a round's countdown can be reset to
    function MINIMUM_RESET_TIME() external pure returns (uint16);
    /// @notice Returns amount of time subtracted from countdown after each play
    function TIME_SUBTRACTION() external pure returns (uint256);
    /// @notice Returns the admin period in seconds
    function ADMIN_PERIOD() external pure returns (uint256);
    /// @notice Returns the current prize pool amount
    function currentPrize() external view returns (uint256);
    /// @notice Returns the timestamp when the round or cooldown period will end
    function roundDeadline() external view returns (uint256);
    /// @notice Returns the timestamp when the game started
    function startTime() external view returns (uint256);
    /// @notice Returns the timestamp when the current round started
    function roundStartTime() external view returns (uint256);
    /// @notice Returns the timestamp of the last play
    function lastPlayedAt() external view returns (uint256);
    /// @notice Returns the timestamp until which the game is in cooldown
    function cooldownUntil() external view returns (uint256);
    /// @notice Returns the timestamp of the last fee update
    function lastFeeUpdate() external view returns (uint256);
    /// @notice Returns the current fee required to play
    function playFee() external view returns (uint256);
    /// @notice Returns the initial countdown duration for new rounds
    function initialCountdown() external view returns (uint256);
    /// @notice Returns the current countdown value
    function countDown() external view returns (uint256);
    /// @notice Returns the number of plays in the current round
    function roundPlayCount() external view returns (uint256);
    /// @notice Returns the total number of plays across all rounds
    function totalPlayCount() external view returns (uint256);
    /// @notice Returns the number of completed rounds
    function finalizedRounds() external view returns (uint256);
    /// @notice Returns the target number of plays per hour
    function playsPerHourTarget() external view returns (uint16);
    /// @notice Returns the timestamp of the last plays per hour update
    function lastPlaysPerHourUpdate() external view returns (uint256);
    /// @notice Returns the round after which shares were last updated
    function lastShareUpdateRound() external view returns (uint256);
    /// @notice Returns the duration of cooldown between rounds
    function cooldownTime() external view returns (uint256);
    /// @notice Returns the percentage of prize pool allocated to winner
    function winnerShare() external view returns (uint8);
    /// @notice Returns the percentage of prize pool allocated to miscellaneous recipient
    /// This is is included in case the DAO decides to allocate a portion to treasury, charity, etc.
    function miscShare() external view returns (uint8);
    /// @notice Returns the address of the most recent player
    function latestPlayer() external view returns (address);
    /// @notice Returns the address where the miscellaneous portion is sent
    function miscRecipient() external view returns (address);
    /// @notice Returns the address of the ERC20 token used for the game
    function gameToken() external view returns (IERC20);
    /// @notice Returns the number of times a player has participated
    /// @param player Address of the player to check
    function playerPlayCount(address player) external view returns (uint256);
    /// @notice Returns the address of the admin
    function admin() external view returns (address);
}
合同源代码
文件 4 的 6:InfiniteGame.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IInfiniteGame.sol";

/**
 * @title The Infinite Game
 * @notice
 *
 * "A finite game is played for the purpose of winning,
 *    an infinite game for the purpose of continuing the play."
 *    - James P. Carse
 *
 * The Infinite Game is played using the ∞ (infinite) token over an endless number of rounds. Each round
 * starts a countdown that resets whenever someone plays. The latest player when the countdown reaches
 * zero is the winner of that round. The countdown reduces by one second each play until it reaches
 * the final reset time of one minute.
 *
 * Playing fees are added to the prize pool. The fee readjusts every hour, increasing during high activity
 * and decreasing during low activity. The winner of the round receives 50% of the prize pool, while
 * the rest remains to bootstrap the next round.
 *
 * The game is owned and controlled by the game's players via InfiniteDAO. The DAO also controls the
 * InfiniteTreasury, which collects LP fees from the initial liquidity pool.
 */
contract InfiniteGame is ReentrancyGuard, Ownable, IInfiniteGame {
    /// @notice Minimum time that a round's countdown can be reset to
    uint16 public constant MINIMUM_RESET_TIME = 1 minutes;

    /// @notice Amount of time subtracted from countdown after each play
    uint256 public constant TIME_SUBTRACTION = 1 seconds;

    /// @notice admin period during which the admin can adjust _playsPerHourTarget and _playFee
    uint256 public constant ADMIN_PERIOD = 60 days;

    address internal _miscRecipient;
    address internal _latestPlayer;
    address internal _admin;

    uint256 internal _launchTime;
    uint256 internal _startTime;
    uint256 internal _roundStartTime;
    uint256 internal _lastPlayedAt;
    uint256 internal _cooldownUntil;
    uint256 internal _lastFeeUpdate;
    uint256 internal _playFee;
    uint256 internal _countDown;
    uint256 internal _roundPlayCount;
    uint256 internal _totalPlayCount;
    uint256 internal _finalizedRounds;
    uint256 internal _lastOverride;
    uint256 internal _lastShareUpdateRound;
    uint16 internal _initialCountdown = 1 hours;
    uint16 internal _cooldownTime = 10 minutes;
    uint16 internal _playsPerHourTarget = 100;
    uint8 internal _winnerShare = 50;
    uint8 internal _miscShare = 0;

    IERC20 internal immutable _gameToken;

    mapping(address => uint256) internal _playCounts;

    /// @notice Initializes the game contract
    /// @param gameToken_ Address of the ERC20 token used for playing the game
    /// @param startTime_ Timestamp when the game starts
    constructor(
        address gameToken_,
        uint256 startTime_,
        address admin_
    ) Ownable(msg.sender) {
        _gameToken = IERC20(gameToken_);
        _launchTime = block.timestamp;
        _countDown = _initialCountdown;
        _startTime = startTime_;
        _roundStartTime = startTime_;
        _lastFeeUpdate = startTime_;
        _playFee = _gameToken.totalSupply() / 200_000;
        _admin = admin_;
    }

    /// @notice Ensures function can only be called during cooldown period
    /// @dev Reverts if called outside the cooldown window
    modifier onlyDuringCooldown() {
        uint256 timeSinceCooldownStart = _cooldownUntil - _cooldownTime;
        if (
            block.timestamp <= timeSinceCooldownStart ||
            block.timestamp >= _cooldownUntil
        ) {
            revert NotAllowedDuringRound();
        }
        _;
    }

    modifier onlyOncePerDay() {
        // Only allow one economics change per day
        if (block.timestamp < _lastOverride + 1 days) {
            revert CannotUpdateYet();
        }
        _;
    }

    modifier onlyOwnerOrAdmin() {
        bool isOwner = msg.sender == owner();
        bool isValidAdmin = msg.sender == _admin &&
            block.timestamp < _launchTime + ADMIN_PERIOD;

        if (!isOwner && !isValidAdmin) {
            revert NotAuthorized();
        }
        _;
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                     MUTATION FUNCTIONS                     */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev See {IInfiniteGame-play}
    function play() external nonReentrant {
        if (block.timestamp < _startTime) {
            revert GameNotStarted();
        }

        if (block.timestamp < _cooldownUntil) {
            revert AwaitingCooldown();
        }

        if (block.timestamp >= roundDeadline()) {
            revert NextRoundPending();
        }

        require(
            _gameToken.transferFrom(msg.sender, address(this), _playFee),
            "Transfer failed"
        );

        if (_roundPlayCount == 0) {
            _roundStartTime = block.timestamp;
        }

        _lastPlayedAt = block.timestamp;
        _latestPlayer = msg.sender;

        unchecked {
            _roundPlayCount++;
            _totalPlayCount++;
            _playCounts[msg.sender]++;
        }

        if (_countDown > MINIMUM_RESET_TIME) {
            unchecked {
                _countDown = _countDown > MINIMUM_RESET_TIME + TIME_SUBTRACTION
                    ? _countDown - TIME_SUBTRACTION
                    : MINIMUM_RESET_TIME;
            }
        }

        if (block.timestamp >= _lastFeeUpdate + 1 hours) {
            _updateFee();
        }

        emit Played(msg.sender, _playFee, _finalizedRounds + 1);
    }

    /// @dev See {IInfiniteGame-completeRound}
    function completeRound() external nonReentrant {
        uint256 deadline = roundDeadline();

        if (block.timestamp < deadline) {
            revert NotAllowedDuringRound();
        }

        if (_latestPlayer != address(0)) {
            uint256 currentBalance = _gameToken.balanceOf(address(this));

            uint256 winnerPrize = (currentBalance * _winnerShare) / 100;
            uint256 miscAmount = (currentBalance * _miscShare) / 100;
            uint256 retainedAmount = currentBalance - winnerPrize - miscAmount;

            _cooldownUntil = block.timestamp + _cooldownTime;
            _lastPlayedAt = _cooldownUntil;
            _countDown = _initialCountdown;
            _roundPlayCount = 0;
            _finalizedRounds++;

            require(
                _gameToken.transfer(_latestPlayer, winnerPrize),
                "Prize transfer failed"
            );

            if (_miscRecipient != address(0) && miscAmount > 0) {
                require(
                    _gameToken.transfer(_miscRecipient, miscAmount),
                    "Misc transfer failed"
                );
            }

            emit RoundCompleted(
                _latestPlayer,
                winnerPrize,
                miscAmount,
                retainedAmount
            );

            _latestPlayer = address(0);
        }
    }

    /// @dev See {IInfiniteGame-setInitialCountdown}
    function setInitialCountdown(uint16 newDuration) external onlyOwner {
        if (newDuration < MINIMUM_RESET_TIME) revert DurationTooLow();

        _initialCountdown = newDuration;

        emit InitialCountdownSet(newDuration);
    }

    /// @dev See {IInfiniteGame-setPlaysPerHourTarget}
    function setPlaysPerHourTarget(
        uint16 newTarget
    ) external onlyOwnerOrAdmin onlyOncePerDay {
        // Constrains target to be within 1/4 and 4 times the current target
        if (
            newTarget < _playsPerHourTarget / 4 ||
            newTarget > _playsPerHourTarget * 4
        ) {
            revert InvalidAdjustment();
        }

        _playsPerHourTarget = newTarget;
        _lastOverride = block.timestamp;

        emit PlaysPerHourTargetSet(newTarget);
    }

    /// @dev See {IInfiniteGame-setShares}
    function setShares(
        uint8 newWinnerShare,
        uint8 newMiscShare
    ) external onlyOwner onlyDuringCooldown {
        if (_lastShareUpdateRound == _finalizedRounds) {
            revert SharesAlreadyUpdatedThisRound();
        }

        if (
            newWinnerShare + newMiscShare == 0 ||
            newWinnerShare + newMiscShare > 100
        ) {
            revert InvalidAdjustment();
        }

        _winnerShare = newWinnerShare;
        _miscShare = newMiscShare;

        _lastShareUpdateRound = _finalizedRounds;

        emit SharesSet(newWinnerShare, newMiscShare);
    }

    /// @dev See {IInfiniteGame-setCooldownTime}
    function setCooldownTime(uint16 newCooldownTime) external onlyOwner {
        if (newCooldownTime < 1 minutes || newCooldownTime > 12 hours)
            revert InvalidAdjustment();

        _cooldownTime = newCooldownTime;

        emit CooldownTimeSet(newCooldownTime);
    }

    /// @dev See {IInfiniteGame-setMiscRecipient}
    function setMiscRecipient(address newRecipient) external onlyOwner {
        _miscRecipient = newRecipient;
    }

    /// @dev See {IInfiniteGame-setPlayFee}
    function setPlayFee(
        uint256 newFee
    ) external onlyOwnerOrAdmin onlyOncePerDay {
        // Constrain new fee to be within 10% and 1000% of the current fee
        if (newFee < _playFee / 10 || newFee > _playFee * 10) {
            revert InvalidAdjustment();
        }

        _playFee = newFee;
        _lastOverride = block.timestamp;

        emit FeeUpdated(_playFee);
    }

    /// @dev See {IInfiniteGame-withdrawERC20}
    function withdrawERC20(address tokenAddress) external onlyOwner {
        require(
            tokenAddress != address(_gameToken),
            "Cannot withdraw game token"
        );
        IERC20 token = IERC20(tokenAddress);
        uint256 balance = token.balanceOf(address(this));
        require(balance > 0, "No tokens to withdraw");
        require(token.transfer(msg.sender, balance), "Transfer failed");
        emit ERC20Withdrawn(tokenAddress, balance);
    }

    /// @dev See {IInfiniteGame-setNewAdmin}
    function setNewAdmin(address newAdmin) external {
        if (
            msg.sender != _admin ||
            // Admin can't do anything after admin period
            // but including this for completeness
            block.timestamp >= _launchTime + ADMIN_PERIOD
        ) revert NotAuthorized();
        _admin = newAdmin;
    }

    /// @dev Absolute value helper
    function _abs(int256 x) internal pure returns (uint256 z) {
        unchecked {
            z = (uint256(x) + uint256(x >> 255)) ^ uint256(x >> 255);
        }
    }

    /// @dev Updates play fee based on activity
    function _updateFee() private {
        uint256 secsSinceRoundStart = block.timestamp - _roundStartTime;

        if (secsSinceRoundStart == 0) {
            return;
        }

        uint256 playsPerHour = (_roundPlayCount * 3600) / secsSinceRoundStart;

        if (playsPerHour < _playsPerHourTarget) {
            _playFee = (_playFee * 80) / 100;
        } else {
            _playFee = (_playFee * 120) / 100;
        }

        _lastFeeUpdate = block.timestamp;

        emit FeeUpdated(_playFee);
    }

    /*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
    /*                        VIEWS                               */
    /*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/

    /// @dev See {IInfiniteGame-currentPrize}
    function currentPrize() public view returns (uint256) {
        return (_gameToken.balanceOf(address(this)) * _winnerShare) / 100;
    }

    /// @dev See {IInfiniteGame-roundDeadline}
    function roundDeadline() public view returns (uint256) {
        if (_cooldownUntil > block.timestamp) {
            return _cooldownUntil;
        }

        uint256 startingPoint = _roundStartTime < _lastPlayedAt
            ? _lastPlayedAt
            : _roundStartTime;
        return startingPoint + _countDown;
    }

    /// @dev See {IInfiniteGame-startTime}
    function startTime() external view returns (uint256) {
        return _startTime;
    }

    /// @dev See {IInfiniteGame-roundStartTime}
    function roundStartTime() external view returns (uint256) {
        return _roundStartTime;
    }

    /// @dev See {IInfiniteGame-lastPlayedAt}
    function lastPlayedAt() external view returns (uint256) {
        return _lastPlayedAt;
    }

    /// @dev See {IInfiniteGame-cooldownUntil}
    function cooldownUntil() external view returns (uint256) {
        return _cooldownUntil;
    }

    /// @dev See {IInfiniteGame-lastFeeUpdate}
    function lastFeeUpdate() external view returns (uint256) {
        return _lastFeeUpdate;
    }

    /// @dev See {IInfiniteGame-playFee}
    function playFee() external view returns (uint256) {
        return _playFee;
    }

    /// @dev See {IInfiniteGame-initialCountdown}
    function initialCountdown() external view returns (uint256) {
        return _initialCountdown;
    }

    /// @dev See {IInfiniteGame-countDown}
    function countDown() external view returns (uint256) {
        return _countDown;
    }

    /// @dev See {IInfiniteGame-roundPlayCount}
    function roundPlayCount() external view returns (uint256) {
        return _roundPlayCount;
    }

    /// @dev See {IInfiniteGame-totalPlayCount}
    function totalPlayCount() external view returns (uint256) {
        return _totalPlayCount;
    }

    /// @dev See {IInfiniteGame-finalizedRounds}
    function finalizedRounds() external view returns (uint256) {
        return _finalizedRounds;
    }

    /// @dev See {IInfiniteGame-playsPerHourTarget}
    function playsPerHourTarget() external view returns (uint16) {
        return _playsPerHourTarget;
    }

    /// @dev See {IInfiniteGame-lastPlaysPerHourUpdate}
    function lastPlaysPerHourUpdate() external view returns (uint256) {
        return _lastOverride;
    }

    /// @dev See {IInfiniteGame-lastShareUpdateRound}
    function lastShareUpdateRound() external view returns (uint256) {
        return _lastShareUpdateRound;
    }

    /// @dev See {IInfiniteGame-cooldownTime}
    function cooldownTime() external view returns (uint256) {
        return _cooldownTime;
    }

    /// @dev See {IInfiniteGame-winnerShare}
    function winnerShare() external view returns (uint8) {
        return _winnerShare;
    }

    /// @dev See {IInfiniteGame-miscShare}
    function miscShare() external view returns (uint8) {
        return _miscShare;
    }

    /// @dev See {IInfiniteGame-latestPlayer}
    function latestPlayer() external view returns (address) {
        return _latestPlayer;
    }

    /// @dev See {IInfiniteGame-miscRecipient}
    function miscRecipient() external view returns (address) {
        return _miscRecipient;
    }

    /// @dev See {IInfiniteGame-gameToken}
    function gameToken() external view returns (IERC20) {
        return _gameToken;
    }

    /// @dev See {IInfiniteGame-playerPlayCount}
    function playerPlayCount(address player) external view returns (uint256) {
        return _playCounts[player];
    }

    /// @dev See {IInfiniteGame-admin}
    function admin() external view returns (address) {
        return _admin;
    }
}
合同源代码
文件 5 的 6:Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)

pragma solidity ^0.8.20;

import {Context} from "../utils/Context.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * The initial owner is set to the address provided by the deployer. This can
 * later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract Ownable is Context {
    address private _owner;

    /**
     * @dev The caller account is not authorized to perform an operation.
     */
    error OwnableUnauthorizedAccount(address account);

    /**
     * @dev The owner is not a valid owner account. (eg. `address(0)`)
     */
    error OwnableInvalidOwner(address owner);

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the address provided by the deployer as the initial owner.
     */
    constructor(address initialOwner) {
        if (initialOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(initialOwner);
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (owner() != _msgSender()) {
            revert OwnableUnauthorizedAccount(_msgSender());
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        if (newOwner == address(0)) {
            revert OwnableInvalidOwner(address(0));
        }
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
合同源代码
文件 6 的 6:ReentrancyGuard.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)

pragma solidity ^0.8.20;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
 * consider using {ReentrancyGuardTransient} instead.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant NOT_ENTERED = 1;
    uint256 private constant ENTERED = 2;

    uint256 private _status;

    /**
     * @dev Unauthorized reentrant call.
     */
    error ReentrancyGuardReentrantCall();

    constructor() {
        _status = NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be NOT_ENTERED
        if (_status == ENTERED) {
            revert ReentrancyGuardReentrantCall();
        }

        // Any calls to nonReentrant after this point will fail
        _status = ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == ENTERED;
    }
}
设置
{
  "compilationTarget": {
    "src/InfiniteGame.sol": "InfiniteGame"
  },
  "evmVersion": "paris",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": [
    ":@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    ":@uniswap/v3-core/=lib/v3-core/",
    ":@uniswap/v3-periphery/=lib/v3-periphery/",
    ":ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
    ":erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    ":forge-std/=lib/forge-std/src/",
    ":halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
    ":openzeppelin-contracts/=lib/openzeppelin-contracts/",
    ":v3-core/=lib/v3-core/",
    ":v3-periphery/=lib/v3-periphery/contracts/"
  ]
}
ABI
[{"inputs":[{"internalType":"address","name":"gameToken_","type":"address"},{"internalType":"uint256","name":"startTime_","type":"uint256"},{"internalType":"address","name":"admin_","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AwaitingCooldown","type":"error"},{"inputs":[],"name":"CannotUpdateYet","type":"error"},{"inputs":[],"name":"DurationTooLow","type":"error"},{"inputs":[],"name":"GameIsStarted","type":"error"},{"inputs":[],"name":"GameNotStarted","type":"error"},{"inputs":[],"name":"InvalidAdjustment","type":"error"},{"inputs":[],"name":"NextRoundPending","type":"error"},{"inputs":[],"name":"NotAllowedDuringRound","type":"error"},{"inputs":[],"name":"NotAuthorized","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[],"name":"SharesAlreadyUpdatedThisRound","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newCooldownTime","type":"uint256"}],"name":"CooldownTimeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ERC20Withdrawn","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"FeeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"newDuration","type":"uint256"}],"name":"InitialCountdownSet","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":"player","type":"address"},{"indexed":false,"internalType":"uint256","name":"paid","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"round","type":"uint256"}],"name":"Played","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"newTarget","type":"uint16"}],"name":"PlaysPerHourTargetSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"winner","type":"address"},{"indexed":false,"internalType":"uint256","name":"winnerPrize","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"miscAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"retainedAmount","type":"uint256"}],"name":"RoundCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"winnerShare","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"miscShare","type":"uint256"}],"name":"SharesSet","type":"event"},{"inputs":[],"name":"ADMIN_PERIOD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MINIMUM_RESET_TIME","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TIME_SUBTRACTION","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"completeRound","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cooldownTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cooldownUntil","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"countDown","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentPrize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"finalizedRounds","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gameToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"initialCountdown","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastFeeUpdate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastPlayedAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastPlaysPerHourUpdate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastShareUpdateRound","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"latestPlayer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"miscRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"miscShare","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"play","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"playFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"player","type":"address"}],"name":"playerPlayCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"playsPerHourTarget","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"roundDeadline","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"roundPlayCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"roundStartTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"newCooldownTime","type":"uint16"}],"name":"setCooldownTime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"newDuration","type":"uint16"}],"name":"setInitialCountdown","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newRecipient","type":"address"}],"name":"setMiscRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"setNewAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"setPlayFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"newTarget","type":"uint16"}],"name":"setPlaysPerHourTarget","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint8","name":"newWinnerShare","type":"uint8"},{"internalType":"uint8","name":"newMiscShare","type":"uint8"}],"name":"setShares","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"startTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalPlayCount","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":[],"name":"winnerShare","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"}]