Skip to content
Verified contractExactMIT

ClickRegistry

Address0xda47fbc8dcbeef8069859416e0fdc2ac62bdd576
Balance

0 ETH

 

Transactions

3

 

Compiler

solc 0.8.20

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.20+commit.a1b79de6
Language
solidity
Optimization
Yes, 200 runs
EVM version
paris
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,421,121
Creation transaction
0xa87601709a…044931b246

contracts/ClickRegistry.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/access/Ownable.sol";

/**
 * @title ClickRegistry
 * @notice Permanent, canonical record of ALL clicks across ALL Clickstr seasons.
 * @dev This contract is designed to be deployed once and never replaced.
 *      It serves as the single source of truth for:
 *      - Lifetime clicks per user (for NFT eligibility)
 *      - Per-season clicks (for historical records)
 *      - Global click statistics
 *
 *      Only authorized game contracts can write to this registry.
 *      Anyone can read from it.
 */
contract ClickRegistry is Ownable {
    // ============ State ============

    /// @notice Lifetime clicks per user (across all seasons)
    mapping(address => uint256) public totalClicks;

    /// @notice Clicks per user per season
    mapping(address => mapping(uint256 => uint256)) public clicksPerSeason;

    /// @notice Global total clicks across all seasons
    uint256 public globalTotalClicks;

    /// @notice Lifetime tokens earned per user (across all seasons)
    mapping(address => uint256) public totalEarned;

    /// @notice Tokens earned per user per season
    mapping(address => mapping(uint256 => uint256)) public earnedPerSeason;

    /// @notice Global total tokens earned across all seasons
    uint256 public globalTotalEarned;

    /// @notice Highest season number that has been registered
    uint256 public totalSeasons;

    /// @notice Authorized game contracts that can record clicks
    mapping(address => bool) public authorizedGames;

    /// @notice Maps game contract address to its season number
    mapping(address => uint256) public gameToSeason;

    /// @notice Maps season number to its game contract address
    mapping(uint256 => address) public seasonToGame;

    /// @notice Whether historical data for a season has been seeded (one-time migration)
    mapping(uint256 => bool) public historicalSeeded;

    // ============ Events ============

    event ClicksRecorded(
        address indexed user,
        uint256 indexed season,
        uint256 clicks,
        address indexed gameContract
    );

    event EarningsRecorded(
        address indexed user,
        uint256 indexed season,
        uint256 amount,
        address indexed gameContract
    );

    event GameAuthorized(
        address indexed game,
        uint256 indexed season
    );

    event GameRevoked(address indexed game);

    event HistoricalClicksSeeded(
        uint256 indexed season,
        uint256 userCount,
        uint256 totalClicksSeeded
    );

    event HistoricalEarningsSeeded(
        uint256 indexed season,
        uint256 userCount,
        uint256 totalEarningsSeeded
    );

    // ============ Errors ============

    error NotAuthorizedGame();
    error ZeroAddress();
    error ZeroClicks();
    error SeasonAlreadyHasGame();
    error AlreadySeeded();
    error ArrayLengthMismatch();
    error SeasonMismatch();

    // ============ Constructor ============

    constructor() Ownable(msg.sender) {}

    // ============ Modifiers ============

    modifier onlyAuthorizedGame() {
        if (!authorizedGames[msg.sender]) revert NotAuthorizedGame();
        _;
    }

    // ============ Game Functions ============

    /**
     * @notice Record clicks for a user (called by authorized game contracts)
     * @param user The user who earned the clicks
     * @param season The season number
     * @param clicks Number of clicks to record
     * @dev Clicks are additive - multiple calls for the same user/season accumulate
     */
    function recordClicks(
        address user,
        uint256 season,
        uint256 clicks
    ) external onlyAuthorizedGame {
        if (user == address(0)) revert ZeroAddress();
        if (clicks == 0) revert ZeroClicks();

        // Verify game is recording to its authorized season
        if (season != gameToSeason[msg.sender]) revert SeasonMismatch();

        // Update user's lifetime total
        totalClicks[user] += clicks;

        // Update user's per-season total
        clicksPerSeason[user][season] += clicks;

        // Update global total
        globalTotalClicks += clicks;

        emit ClicksRecorded(user, season, clicks, msg.sender);
    }

    /**
     * @notice Record token earnings for a user (called by authorized game contracts)
     * @param user The user who earned the tokens
     * @param season The season number
     * @param amount Amount of tokens earned (in wei)
     * @dev Earnings are additive - multiple calls for the same user/season accumulate
     */
    function recordEarnings(
        address user,
        uint256 season,
        uint256 amount
    ) external onlyAuthorizedGame {
        if (user == address(0)) revert ZeroAddress();
        if (amount == 0) return; // Silent return for zero - not an error

        // Verify game is recording to its authorized season
        if (season != gameToSeason[msg.sender]) revert SeasonMismatch();

        // Update user's lifetime total
        totalEarned[user] += amount;

        // Update user's per-season total
        earnedPerSeason[user][season] += amount;

        // Update global total
        globalTotalEarned += amount;

        emit EarningsRecorded(user, season, amount, msg.sender);
    }

    // ============ Admin Functions ============

    /**
     * @notice Authorize a game contract for a specific season
     * @param gameContract Address of the game contract
     * @param season Season number (must not already have a game)
     */
    function authorizeGame(
        address gameContract,
        uint256 season
    ) external onlyOwner {
        if (gameContract == address(0)) revert ZeroAddress();
        if (seasonToGame[season] != address(0)) revert SeasonAlreadyHasGame();

        authorizedGames[gameContract] = true;
        gameToSeason[gameContract] = season;
        seasonToGame[season] = gameContract;

        // Track highest season number
        if (season > totalSeasons) {
            totalSeasons = season;
        }

        emit GameAuthorized(gameContract, season);
    }

    /**
     * @notice Revoke a game contract's authorization (emergency only)
     * @param gameContract Address of the game contract to revoke
     * @dev Use with caution - should only be used for compromised contracts
     */
    function revokeGame(address gameContract) external onlyOwner {
        if (gameContract == address(0)) revert ZeroAddress();

        authorizedGames[gameContract] = false;
        // Note: We don't clear gameToSeason/seasonToGame to preserve history

        emit GameRevoked(gameContract);
    }

    /**
     * @notice Seed historical clicks from a previous season (one-time migration)
     * @param users Array of user addresses
     * @param clicks Array of click counts (parallel to users array)
     * @param season Season number being migrated
     * @dev Can only be called once per season. Used to migrate V1 data.
     */
    function seedHistoricalClicks(
        address[] calldata users,
        uint256[] calldata clicks,
        uint256 season
    ) external onlyOwner {
        if (historicalSeeded[season]) revert AlreadySeeded();
        if (users.length != clicks.length) revert ArrayLengthMismatch();

        historicalSeeded[season] = true;

        uint256 totalSeeded = 0;
        for (uint256 i = 0; i < users.length; i++) {
            if (users[i] == address(0)) continue;
            if (clicks[i] == 0) continue;

            totalClicks[users[i]] += clicks[i];
            clicksPerSeason[users[i]][season] += clicks[i];
            totalSeeded += clicks[i];
        }

        globalTotalClicks += totalSeeded;

        // Track highest season number
        if (season > totalSeasons) {
            totalSeasons = season;
        }

        emit HistoricalClicksSeeded(season, users.length, totalSeeded);
    }

    /**
     * @notice Seed historical earnings from a previous season (one-time migration)
     * @param users Array of user addresses
     * @param amounts Array of earned amounts in wei (parallel to users array)
     * @param season Season number being migrated
     * @dev Uses same historicalSeeded flag as clicks - call after seedHistoricalClicks
     */
    function seedHistoricalEarnings(
        address[] calldata users,
        uint256[] calldata amounts,
        uint256 season
    ) external onlyOwner {
        if (users.length != amounts.length) revert ArrayLengthMismatch();

        uint256 totalSeeded = 0;
        for (uint256 i = 0; i < users.length; i++) {
            if (users[i] == address(0)) continue;
            if (amounts[i] == 0) continue;

            totalEarned[users[i]] += amounts[i];
            earnedPerSeason[users[i]][season] += amounts[i];
            totalSeeded += amounts[i];
        }

        globalTotalEarned += totalSeeded;

        emit HistoricalEarningsSeeded(season, users.length, totalSeeded);
    }

    // ============ View Functions ============

    /**
     * @notice Get a user's lifetime click total
     * @param user Address to check
     * @return Total clicks across all seasons
     */
    function getTotalClicks(address user) external view returns (uint256) {
        return totalClicks[user];
    }

    /**
     * @notice Get a user's clicks for a specific season
     * @param user Address to check
     * @param season Season number
     * @return Clicks for that season
     */
    function getSeasonClicks(
        address user,
        uint256 season
    ) external view returns (uint256) {
        return clicksPerSeason[user][season];
    }

    /**
     * @notice Get a user's lifetime earnings total
     * @param user Address to check
     * @return Total tokens earned across all seasons (in wei)
     */
    function getTotalEarned(address user) external view returns (uint256) {
        return totalEarned[user];
    }

    /**
     * @notice Get a user's earnings for a specific season
     * @param user Address to check
     * @param season Season number
     * @return Tokens earned for that season (in wei)
     */
    function getSeasonEarned(
        address user,
        uint256 season
    ) external view returns (uint256) {
        return earnedPerSeason[user][season];
    }

    /**
     * @notice Get a user's click history across multiple seasons
     * @param user Address to check
     * @param fromSeason Starting season (inclusive)
     * @param toSeason Ending season (inclusive)
     * @return seasons Array of season numbers
     * @return clickCounts Array of click counts (parallel)
     */
    function getClickHistory(
        address user,
        uint256 fromSeason,
        uint256 toSeason
    ) external view returns (
        uint256[] memory seasons,
        uint256[] memory clickCounts
    ) {
        require(toSeason >= fromSeason, "Invalid range");
        uint256 count = toSeason - fromSeason + 1;

        seasons = new uint256[](count);
        clickCounts = new uint256[](count);

        for (uint256 i = 0; i < count; i++) {
            uint256 season = fromSeason + i;
            seasons[i] = season;
            clickCounts[i] = clicksPerSeason[user][season];
        }
    }

    /**
     * @notice Check if an address is an authorized game
     * @param gameContract Address to check
     * @return True if authorized
     */
    function isAuthorizedGame(address gameContract) external view returns (bool) {
        return authorizedGames[gameContract];
    }

    /**
     * @notice Get the game contract for a specific season
     * @param season Season number
     * @return Game contract address (address(0) if none)
     */
    function getSeasonGame(uint256 season) external view returns (address) {
        return seasonToGame[season];
    }
}

@openzeppelin/contracts/access/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);
    }
}

@openzeppelin/contracts/utils/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;
    }
}
Compiler settingsShow
{
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "paris"
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.